Download presentation

Presentation is loading. Please wait.

Published byIsiah Mews Modified over 2 years ago

1
Bubble Sort Algorithm It is so named because numbers (or letters) which are in the wrong place “bubble-up” to their correct positions (like fizzy lemonade) You can “bubble” from bottom to top, right to left, top to bottom or left to right as long as you “bubble” in the same direction. Assuming you are “bubbling” from right to left: Step 1 Compare the last two numbers on the extreme right. If the smaller number is on the right, swap the two numbers and reorder the list, if not, leave them. Step 2 Move one step back in the list (to the left) and compare the two numbers. If the smaller is on the right swap the two numbers and reorder the list, if not, leave them. Step 3 Repeat Step 2 until the two numbers on the extreme left have been compared, then return to Step 1. Step 4 Repeat Step 3 until all the numbers are in order (i.e. no more swaps are performed in a pass)

2
Sort the following numbers into ascending order: 27 15 2 38 16 1 27152381611 13812115271 This is the result of the first pass – the smallest number is now in the right position – record this! 1 152 1 27 15 2 38 16 No swap 215272 This is the result of the second pass - the 2 is now in the correct position – record this! 1 2 27 15 16 38 12 1516382715 This is the result of the third pass - the 15 is now in the correct position – record this! 1 2 15 27 16 38 12 271638 No swap 1627 This is the result of the fourth pass - the 16 is now in the correct position – record this! 1 2 15 16 27 38 1215162738 The final pass yields no change but you should still record this! 1 2 15 16 27 38 STOP 38163816

3
Now try sorting this list: Bubble from right to left 253617941375711 925361711413757 911253617374157 911172536374157 STOP Now try sorting the list: Bubble from left to right 253617941375711 251793637411157 179253637114157 917253611374157 917251136374157 917112536374157 911172536374157 STOP

Similar presentations

OK

Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.

Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt online ticket Ppt on electricity generation from solar energy Ppt on polarisation of light Download ppt on statistics for class 10th Placenta anatomy and physiology ppt on cells Ppt on limits and derivatives calculator Water saving tips for kids ppt on batteries Ppt on population census 2011 india Ppt on ministry of corporate affairs mumbai Ppt on types of charts in ms excel