Why the strict comparison keeps ties in order

A teacher sorts three student records by score in ascending order with bubble sort. The records start in the order Lee (85), Kai (72), Mia (72). Bubble sort exchanges two neighbouring records only when the left score is strictly greater than the right score. Pass 1 compares positions 1 and 2, then positions 2 and 3. Pass 2 compares only positions 1 and 2, because the largest record has already settled at the end. The algorithm stops after a pass that makes no exchanges or after 2 passes, whichever comes first. Answer each name blank with the student's name only, without the score.


With this strict test, bubble sort makes swaps in total and the sorted list begins with . If the test is changed to greater than or equal, with the same pass rules, it makes swaps and the sorted list begins with . Because the strict test keeps records with equal keys in their original relative order, bubble sort with that test is called a sort.

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: