Tracing two stable sorting passes

A dispatch system uses a stable sort, which preserves the incoming relative order of records with equal values of the key used in that pass. The records initially appear in this order:


Record

Region

Priority

A

North

2

B

South

1

C

North

1

D

South

2

E

North

1


The system first sorts stably by priority in ascending order. It then sorts that result stably by region, placing North before South.


Records pass through a stable priority sort followed by a stable region sort.


Complete the table with each record's position after the first pass and after the second pass. Use exact integers from 1 to 5, with position 1 at the beginning of the sequence.

RecordPosition after priority passPosition after region pass
A
B
C
D
E

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 Sorting Algorithms Questions: