Data Structures & AlgorithmsEasyCognizant · Capgemini pattern

A stack is implemented with a singly linked list. Where should push and pop operate to keep both O(1)?

  1. A. At the tail – append and remove the tail
  2. B. Push at the head, pop at the tail
  3. C. At the head – insert a new head and remove the head
  4. D. Push at the tail, pop at the head

Correct answer: C. At the head – insert a new head and remove the head

Head insertion and head deletion are both pointer updates. Removing the tail needs the predecessor (O(n)), so any design that pops at the tail is O(n). Push at tail/pop at head is a queue, not a stack.

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

Exams that ask this topic