Equal scores and stable ordering

An event system stores records in arrival order. It sorts them by ascending score using the code below. The expression .score reads a record's score, and assignments move the entire record. Equal scores are possible.


Python
for i in range(1, len(records)):
    key = records[i]
    j = i - 1
    while j >= 0 and records[j].score > key.score:
        records[j + 1] = records[j]
        j -= 1
    records[j + 1] = key


Select all true statements about keeping the strict comparison or changing only > to >=.

Choose an answer

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 Insertion Sort Questions: