bubble sort

8
BUBBLE SORT Muhammad Ahmad Shabbir

Upload: muhammad-ahmad-shabbir

Post on 16-Aug-2015

31 views

Category:

Documents


0 download

TRANSCRIPT

  1. 1. BUBBLE SORT Muhammad Ahmad Shabbir
  2. 2. WHAT IS SORTING? Sorting refers to ordering data in an increasing or decreasing fashion according to some linear relationship among the data items. Sorting can be done on names, numbers and records.
  3. 3. TYPES OF SORT? 1. Insertion sort. 2. Merge Sort. 3. Quick Sort. 4. Radix Sort. 5. Heap Sort. 6. Selection sort. 7. Bubble sort.
  4. 4. WHAT IS BUBBLE SORT? This technique compares last element with the preceding element. If the last element is less than that of preceding element swapping takes place. Then the preceding element is compared with that previous element. This process continuous until the II and I elements are compared with each other. This is known as pass 1. This way the number of passes would be equal to size of array 1.
  5. 5. WHO BUBBLE SORT WORKS?
  6. 6. ALGORITHM OF BUBBLE SORT for i = 1:n, swapped = false for j = n:i+1, if a[j] < a[j-1], swap a[j,j-1] swapped = true end invariant: a[1..i] in final position break if not swapped end Main LoopInner Loop
  7. 7. BUBBLE COMPARISON WITH OTHER SORT?
  8. 8. THANK YOU Any Questions?