Presentation is loading. Please wait.

Presentation is loading. Please wait.

Bubble sort Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "Bubble sort Please use speaker notes for additional information!"— Presentation transcript:

1 Bubble sort Please use speaker notes for additional information!

2 Bubble sort - PASS #1 Original numbers: 5 6 2 3 4 SUB1 1 SUB2 2 5623456234 Compare 5 which is what SUB1 is pointing to and 6 which is what SUB2 is pointing to. In this instance, 5 < 6 so nothing is done. After numbers: 5 6 2 3 4 HOLDEND-PT 5 FLIP-CT 0

3 Bubble sort - PASS #1 Before numbers: 5 6 2 3 4 SUB1 1 2 SUB2 2 3 5623456234 Compare 6 which is what SUB1 is pointing to and 6 which is what SUB2 is pointing to. In this instance, 6 > 2 so flip and add one to the flip-ct.. After numbers: 5 2 6 3 4 HOLD 6 END-PT 5 FLIP-CT 0 1 5623456234 5223452234 5263452634

4 Bubble sort - PASS #1 Before numbers: 5 2 6 3 4 SUB1 1 2 3 SUB2 2 3 4 5263452634 Compare 6 which is what SUB1 is pointing to and 3 which is what SUB2 is pointing to. In this instance, 6 > 3 so flip and add one to the flip-ct.. After numbers: 5 2 3 6 4 HOLD 6 END-PT 5 FLIP-CT 0 1 2 5263452634 5233452334 5236452364

5 Bubble sort - PASS #1 Before numbers: 5 2 3 6 4 SUB1 1 2 3 4 SUB2 2 3 4 5 5236452364 Compare 6 which is what SUB1 is pointing to and 4 which is what SUB2 is pointing to. In this instance, 6 > 4 so flip and add one to the flip-ct.. After numbers: 5 2 3 4 6 HOLD 6 END-PT 5 FLIP-CT 0 1 2 3 5236452364 5234452344 5234652346

6 Bubble sort - PASS #1 Before numbers: 5 2 3 4 6 SUB1 1 2 3 4 5 SUB2 2 3 4 5 6 5234652346 At this point SUB2 is greater than END-PT so the pass is complete. After numbers: 5 2 3 4 6 HOLDEND-PT 5 FLIP-CT 0 1 2 3

7 Bubble sort - Reset for PASS #2 Before numbers: 5 2 3 4 6 SUB1 1 SUB2 2 HOLDEND-PT 5 4 FLIP-CT 0

8 Bubble sort - PASS #2 Before numbers: 5 2 3 4 6 SUB1 1 SUB2 2 5234652346 Compare 5 which is what SUB1 is pointing to and 2 which is what SUB2 is pointing to. In this instance, 5 >2 so a flip is done and 1 is added to flip-ct. After numbers: 2 5 3 4 6 HOLD 5 END-PT 4 FLIP-CT 0 1 5234652346 2234622346 2534625346

9 Bubble sort - PASS #2 Before numbers: 2 5 3 4 6 SUB1 1 2 SUB2 2 3 2534625346 Compare 5 which is what SUB1 is pointing to and 3 which is what SUB2 is pointing to. In this instance, 5 >3 so a flip is done and 1 is added to flip-ct. After numbers: 2 3 5 4 6 HOLD 5 END-PT 4 FLIP-CT 0 1 2 2534625346 2334623346 2354623546

10 Bubble sort - PASS #2 Before numbers: 2 3 5 4 6 SUB1 1 2 3 SUB2 2 3 4 2354623546 Compare 5 which is what SUB1 is pointing to and 4 which is what SUB2 is pointing to. In this instance, 5 >4 so a flip is done and 1 is added to flip-ct. After numbers: 2 3 4 5 6 HOLD 5 END-PT 4 FLIP-CT 0 1 2 3 2354623546 2344623446 2345623456

11 Bubble sort - PASS #2 Before numbers: 2 3 4 5 6 SUB1 1 2 3 4 SUB2 2 3 4 5 2345623456 At this point SUB2 is greater than END-PT so the pass is complete. After numbers: 2 3 4 5 6 HOLDEND-PT 4 FLIP-CT 0 1 2 3 END-PT signals the end of the pass. We can test either by using SUB2 > END-PT or SUB1 = END-PT.

12 Bubble sort - Reset for PASS #3 Before numbers: 2 3 4 5 6 SUB1 1 SUB2 2 HOLDEND-PT 5 4 3 FLIP-CT 0

13 Bubble sort - PASS #3 Before numbers: 2 3 4 5 6 SUB1 1 SUB2 2 2345623456 Compare 2 which is what SUB1 is pointing to and 3 which is what SUB2 is pointing to. In this instance, 2< 3 so a no flip is done. After numbers: 2 3 4 5 6 HOLDEND-PT 3 FLIP-CT 0

14 Bubble sort - PASS #3 Before numbers: 2 3 4 5 6 SUB1 1 2 SUB2 2 3 2345623456 Compare 3 which is what SUB1 is pointing to and 4 which is what SUB2 is pointing to. In this instance, 3< 4 so a no flip is done. After numbers: 2 3 4 5 6 HOLDEND-PT 3 FLIP-CT 0

15 Bubble sort - PASS #3 Before numbers: 2 3 4 5 6 SUB1 1 2 3 SUB2 2 3 4 At this point SUB2 is greater than END-PT so the pass is complete. AND since there were no flips the sort is complete. After numbers: 23456 HOLDEND-PT 3 FLIP-CT 0 END-PT signals the end of the pass. We can test either by using SUB2 > END-PT or SUB1 = END-PT.


Download ppt "Bubble sort Please use speaker notes for additional information!"

Similar presentations


Ads by Google