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.
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
Compelxity
- Worst Case: n(n-1)/2 = o(n2)
- Best case performance O(n)
- Average case performance o(n2)
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