Skip to main content

Posts

Showing posts from January, 2022

bubble sort algorithm in c++ || Bubble sort explained || sinking sort

 Bubble sort- Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. The pass of the list is repeated until the list is sorted. Why bubble sort is called “bubble” sort? The “bubble” sort is called so  because the list elements with greater value than their surrounding elements “bubble” towards the end of the list . For example, after first pass, the largest element is bubbled towards the right most position. Worst complexity :  n^2 Average complexity :  n^2 Best complexity :  n Space complexity :  1 at the end of i th pass, we have the i th largest element placed at its correct place. look the example below. Example:   First Pass:   (  5   1  4 2 8 ) –> (  1   5  4 2 8 ) ( 1  5   4  2 8 ) –>  ( 1  4   5  2 8 ) ( 1 4  5   2 ...

What is an algorithm in computer science ?

 What is an algorithm in computer science ?- You may have heard the term  algorithm  recently, whether it was online or perhaps in some conversation about technology. It's a word that gets thrown around a lot, but what does it mean exactly? suppose your mom gave you a task to prepare a cup of tea for her. How do you prepare a cup of tea for her ? definitely, to prepare a cup of tea you are gonna follow the following steps 1- Boil water. 2- Warm up teapot 3-  Put the tea into a teapot and add hot water. 4- Cover teapot and steep tea 5- Strain tea solids and pour hot tea into tea cups. Basically preparing tea was a problem and you follow some step-by-step procedures to solve this problem.  similarly, in computer science,  An algorithm is simply a  set of steps used to complete a specific task . They're the building blocks for programming, and they allow things like computers, smartphones, and websites to function and make decisions. An algorithm is ...