ProgrammingHard

A linked list is built by appending n nodes one by one, each time walking from the head to the last node. About how many node visits does building a list of N = 10^5 take?

  1. A. About 10^5
  2. B. About 10^10
  3. C. About 5 x 10^9
  4. D. About 5 x 10^4

Correct answer: C. About 5 x 10^9

The i-th append walks i - 1 nodes, so the total is about N^2 / 2 = 5 x 10^9. A tail pointer makes every append O(1).

More C Programming questions

Exams that ask this topic