ProgrammingModerate

A program keeps 10^5 small objects in a free list of pointers. Which operation is O(1) per object?

  1. A. Search the free list for a specific pointer before each push
  2. B. Rebuild the whole free list for every allocation
  3. C. Sort the free list after each free
  4. D. Push a freed object onto the free list, and pop one to reuse it

Correct answer: D. Push a freed object onto the free list, and pop one to reuse it

Pushing and popping at the head of the free list touches only one node, which makes both operations constant time.

More C Programming questions

Exams that ask this topic