Aptitude

Data Structures Interview Questions

Which data structure is the best default for implementing a FIFO queue? — spoken sample answer for Indian interviews.

  • 5Questions with answers
  • 3Difficulty levels

Questions (5)

Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.

Question 1
Interview Beginner
Question

Which data structure is the best default for implementing a FIFO queue?

Answer:

FIFO means first in, first out. A queue or deque is the default. Enqueue at the back, dequeue at the front, both O(1) if I use a linked list, a deque, or a circular buffer. A stack is LIFO, so it is the wrong answer. A BST and a hash set are not ordered as a queue. If I used a plain array and unshifted the front, dequeue would be O(n) , which I would not call a proper queue.

Question 2
Interview Intermediate
Question

Best default for LRU cache?

Answer:

Hash map plus doubly linked list. Map lookup O(1) , list move-to-front O(1) . LinkedHashMap can do it in Java. I still describe the two structures.

Question 3
Interview Beginner
Question

Stack or queue for BFS and DFS?

Answer:

BFS queue, DFS stack or recursion. If a snippet uses a queue I say BFS. Deque can be a stack if I push and pop the same end.

Question 4
Interview Intermediate
Question

When is a heap the wrong default?

Answer:

If I need all n sorted, sort or a BST may be clearer. Heap shines for repeated extract-min or kth. I choose by the operations, not by fashion.

Question 5
Interview Beginner
Question

Array versus linked list for index and insert at head?

Answer:

Array O(1) index, costly insert at head. List O(n) index, O(1) insert at head. In practice ArrayList often wins on cache. Interviews still want the big-O table.

Practice with AI mock interviews

Run Aptitude mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.

Free to start · No credit card required