A large value at the front versus a small value at the back

An early-exit bubble sort sorts a list of n = 8 values into ascending order. Pass k compares neighbouring positions from the front up to position 8 − k, swapping any pair whose left value is larger. The algorithm stops after a pass that makes no swaps, or after n − 1 = 7 passes, whichever comes first.


The algorithm is run on two lists:

  • List A: 8, 1, 2, 3, 4, 5, 6, 7
  • List B: 2, 3, 4, 5, 6, 7, 8, 1

For each list, give the number of passes performed, the total number of comparisons and the total number of swaps, each as a whole number.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Bubble Sort Questions: