Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active September 29, 2022 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/702d656ea71217113edd8084f2b61a66 to your computer and use it in GitHub Desktop.
Save McLarenCollege/702d656ea71217113edd8084f2b61a66 to your computer and use it in GitHub Desktop.
Exercise : Bubble Sort Steps

Bubble Sort Algorithm

Stepwise Implementation of the Bubble Sort Algorithm

If the input is [6,2,9,5,1,3] the steps are:

compare 6 and 2 - swap
compare 6 and 9 - no change
compare 9 and 5 - swap
compare 9 and 1 - swap
compare 9 and 3 - swap
REPEAT ITERATION
compare 2 and 6 - no change
compare 6 and 5 - swap 
compare 6 and 1 - swap
compare 6 and 3 - swap
REPEAT ITERATION
compare 2 and 5 - no change
compare 5 and 1 - swap
compare 5 and 3 - swap
REPEAT ITERATION
compare 2 and 1 - swap
compare 2 and 3 - no change
REPEAT ITERATION 
compare 1 and 2 - no change
FINISH

If the input is [1,2,9,3,10,7] steps are:

compare 1 and 2 - no change
compare 2 and 9 - no change
........
  • Your task is to complete the remaining steps for the input [1,2,9,3,10,7].
  • Please Note that you dont need to perform any further iterations if there is no swap made in the current iteration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment