Skip to main content

Bubble Sort

              Bubble Sort is a sorting algorithm that works by comparing each pair of adjacent items and swapping them if they are in wrong order repeatedly till the list is sorted.

              Bubble sort is also referred to as sinking sort or comparison sort. The algorithm is named for the way smaller or larger elements “bubble“ to the top of the list.

             Bubble sort algorithm is the simplest algorithm for sorting but it is too slow and impractical for most problems.



Bubble Sort Algorithm


Step 1: Enter how many numbers(n) to sort.

Step2: Enter all numbers and store it in array a[].

Step3: Make a key starting with second element of an array a[].

Step4: Now compare the [key-1] element of an array a[] with [key] element of an array a[].

Step5: For ascending order if the [key-1] element of an array a[] is greater than [key] element of an array a[] then swap the
respective elements of an array a[].

Step6:Move the key to right to next element of an array a[].

Step7: Repeat the Step4 till the previous sorted element of array a[].

Step8: Repeat the Step3 till (n-1) times.

Step9: All numbers are now sorted.

Step10: Stop.


Bubble Sort Flowchart









To Understand the working of Bubble Sort Algorithm , 




To Understand the working of Bubble Sort Flowchart  ,



To Write the Program in C ,




Download the Bubble Sort Program







Comments

Popular posts from this blog

Prime Numbers

Prime Number is a natural number greater than 1 that has exactly two distinct natural number divisors: 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number. For example, 13 can only be divided by 1 and  by 13 itself. Here is a list of all the prime numbers up to 100: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47, 53,59,61,67,71,73,79,83,89,97,.. 1 is not a prime number as in definition “For a number to be prime it must have two  d istinct (different) factors. Algorithm Step1: Input the number(n) to check for prime number Step2: If n is below or equal to 1  then go to step 12 Step3: if n is equal to 2 then go to step 11 Step4: Assign variable count =n / 2 Step5: Assign variable a=1 Step6: Add 1 to a and store it to variable a Step7: remainder = n % a Step8: if remainder=0 then go to step 12 Step9: subtract one from count and store it to variable count Step10: if count is not equal to 0 then go to s...

Fibonacci Sequence Flowchart

Fibonacci Sequence Flowchart In the previous video of Fibonacci sequence ,we learned about the Fibonacci series and how to write an algorithm. In this video we will learn how to draw a flowchart for it. First let us write an algorithm for it again. 0,1,1,2,3,5,8,13,21,34,55,89,… Step1: Input the number(n) till which the Fibonacci series will run Step2: Assign the variables a equal to -1 and b equal to 1 Step3: Add the variables a & b and assign it to variable x Step4: Display the value of x Step5: Assign the value of b to variable a Step6: Assign the value of x to variable b Step7: Subtract one from n and store it to variable n Step8: If the value of n is not zero, go back to the Step3 Step9: Fibonacci numbers displayed till n numbers. To see the working of above flowchart,  Click here to Watch on YouTube To write the program in C,   Click here to Watch on YouTube To make the Fibonacci Sequence  And...

Armstrong Number

            An Armstrong number is an  n -digit number that is equal to the sum of the  n th  powers of its digits. For example 153 is an Armstrong Number in 3 digit number 1 3  +  5 3  +  3 3   =  153 1  +125+27  =153 1634 is an Armstrong Number in 4 digit number 1 4  + 6 4  + 3 4  + 4 4  =  1634 1+1296+81+256=1634 And so numbers from 0-9 all are Armstrong Numbers as  0 1 is 0 , 1 1   is 1,   2 1 is 2 , 3 1 is 3 and so on..   Armstrong Algorithm Step1: Read a number.  Step2:  Store all the digits of a number in an array digits[] Step3:  Count all the digits of a number and store in variable   length Step4:  Start a loop till  the length of a number Step5: Raise each digit to a power equal to the number of digits in the number. For ex, each digit of a thre...