Data Structures & AlgorithmsVery hard

In the asteroid collision problem, why does a stack of right-moving asteroids suffice?

  1. A. Only the most recent right-mover can ever collide with the current left-mover, so the stack top is the only candidate.
  2. B. All right-movers collide with every left-mover at once.
  3. C. Left-movers never collide with anything.
  4. D. Stacks sort asteroids by size automatically.

Correct answer: A. Only the most recent right-mover can ever collide with the current left-mover, so the stack top is the only candidate.

A left-moving asteroid meets the nearest surviving right-mover first, which is the top of the stack. Once that one is handled, the next candidate becomes the new top, so a stack models the process exactly.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic