Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visit for more Learning Resources

Similar presentations


Presentation on theme: "Visit for more Learning Resources"— Presentation transcript:

1 Visit for more Learning Resources
Bubble Sort Visit for more Learning Resources

2 "Bubbling Up" the Largest Element
Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair-wise comparisons and swapping 77 42 35 12 101 5

3 Sorting Sorting takes an unordered collection and makes it an ordered one. 77 42 35 12 101 5 5 12 35 42 77 101

4 "Bubbling Up" the Largest Element
Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair-wise comparisons and swapping Swap 42 77 77 42 35 12 101 5

5 "Bubbling Up" the Largest Element
Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair-wise comparisons and swapping Swap 35 77 42 77 35 12 101 5

6 "Bubbling Up" the Largest Element
Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair-wise comparisons and swapping Swap 12 77 42 35 77 12 101 5

7 "Bubbling Up" the Largest Element
Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair-wise comparisons and swapping Swap 5 101 42 35 12 77 101 5

8 "Bubbling Up" the Largest Element
Traverse a collection of elements Move from the front to the end “Bubble” the largest value to the end using pair-wise comparisons and swapping 101 42 35 12 77 5 Largest value correctly placed

9 “Bubbling” All the Elements
77 12 35 42 5 101 N - 1 5 42 12 35 77 101 42 5 35 12 77 101 42 35 5 12 77 101 42 35 12 5 77 101

10 Reducing the Number of Comparisons
12 35 42 77 101 5 77 12 35 42 5 101 5 42 12 35 77 101 42 5 35 12 77 101 42 35 5 12 77 101

11 Algorithm Start Set i=1 Set j=0 If (a[j] > a[j+1] ) J=j+1
Swap a[j] and a[j+1] J=j+1 If (j< (n-i)), go to step 4 i=i+1 If (i<n) ,go to step 3 stop For more detail contact us


Download ppt "Visit for more Learning Resources"

Similar presentations


Ads by Google