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.
Which data structure is the best default for implementing a FIFO queue?
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.
Best default for LRU cache?
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.
Stack or queue for BFS and DFS?
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.
When is a heap the wrong default?
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.
Array versus linked list for index and insert at head?
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