Wednesday, March 4, 2009

Bubble Sort Method

In bubble sort element, each element is compared with its adjacent element  and if first element is greater than second element  then elements are interchanged otherwise no change. This process is repeated for all the elements in the list.

Compelxity
  • Worst Case: n(n-1)/2 = o(n2)
  • Best case performance     O(n)
  •  Average case performance     o(n2
Algorithm:  Given array A of N elements.


1. Repeat thru step 2 for STEP=1 to N
2. [Compare adajanct elements]     Repeat for i=1 to N-1
         if a[i]>a[i+1]
         then swap
3. Print Sorted data
4. Exit







No comments:

Post a Comment

Learn Programming online

Started Two months Online Programming Classes for XI, XII (all boards), B.Sc.(CS/IT), BCA, M.Sc.(CS/IT), MCA. Programming Languages 1. C 2. ...