Skip to content

Activity selection

planning ahead

Level 1 of 3

Also called Interval scheduling and Earliest finish time first.

fresh numbers

The test's questions that a run answers, asked again on new numbers whenever you like. The answer, its working and the reason for every other choice come from activity selection's own run on the numbers shown.

choose one

question 1

These four activities are typed in this order: A from 0 to 1, B from 2 to 3, C from 1 to 2 and D from 3 to 4. The drawing lines them up by end. How many comparisons does the sort make?

012345678ACBDACBD
the answer, and why

the answer is A

Round 1: A with B, then C with D, 1 comparison each. Round 2: ends 1, 3 with 2, 4 compares 1 with 2, 3 with 2 and 3 with 4. That is 3, so 5 in all.

if you chose another

  • 4 is the drawing's order, ends 1, 2, 3, 4; the sort meets them as typed, 1, 3, 2, 4.
  • That counts only the checks after the sort, one for each activity after the first.
  • That counts round 2 as 4, but the last activity follows with no comparison.

new numbers

question 2

Which list makes the sort compare the fewest times?

the answer, and why

the answer is A

Latest end first, every right run is used up first. 2 + 2 + 1, which is 5.

if you chose another

  • In end order, every left run is used up first, and a left run can be the longer. 2 + 2 + 4, which is 8.
  • That is the dearest order, 2 + 3 + 4, which is 9.
  • Round 1 puts each swapped pair in end order, 1 comparison each. That leaves end order's runs, so 2 + 2 + 4, which is 8.

new numbers