Computer Science I / Integrated Data-Structure Reasoning
Practice question · Put in order

The manager holds 1024 tasks. Order these operations from cheapest to most expensive.

Hints
  1. Attach a growth class to each operation first, then evaluate it at 1024.
  2. The base-2 logarithm of 1024 is 10, so put roughly 1, 10, 1024, 10240 and a million against the five options.
Show the answer
  1. Peek at the heap's root to see the most urgent task
  2. Insert one task into the heap
  3. Scan an unsorted list of all tasks to find the most urgent
  4. Sort all the tasks by deadline
  5. Compare every task against every other task
Why

The costs are about 1, 10, 1024, 10240 and a million steps. The peek is constant because the heap keeps the extreme at the root; the scan is linear; sorting adds a logarithmic factor to that; comparing all pairs is quadratic. The whole argument for the heap is the gap between the second and third entries.

Read the lesson: Integrated Data-Structure Reasoning →

Practise Integrated Data-Structure Reasoning

The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Integrated Data-Structure Reasoning