Which data structure follows the Last In, First Out (LIFO) principle?
Solution
In a stack, the last element pushed is the first popped.
20 technical questions of moderate difficulty, as asked in campus placement and company tests. Each has a short explanation.
Which data structure follows the Last In, First Out (LIFO) principle?
In a stack, the last element pushed is the first popped.
Which data structure follows the First In, First Out (FIFO) principle?
In a queue, elements leave in the order they arrived.
What is the time complexity of accessing an element by index in an array?
The address is computed directly from the index.
What is the time complexity of searching in a balanced binary search tree?
Each comparison halves the remaining tree in a balanced BST.
Which data structure is used to implement recursion?
Each function call is pushed onto the call stack.
What is the in-order traversal of a binary search tree?
In-order (left, root, right) visits BST keys in sorted order.
Which traversal visits the root first, then the left subtree, then the right subtree?
Pre-order is root, left, right.
What is the maximum number of nodes in a binary tree of height h (a single node has height 0)?
Level i can hold 2i nodes; summing levels 0 to h gives 2h+1 − 1.
Which data structure is best for implementing a priority queue?
A heap gives O(log n) insertion and removal of the highest-priority element.
What is the worst-case time to insert at the beginning of a singly linked list?
Only the head pointer and the new node's next pointer change.
In a hash table, what is it called when two keys map to the same index?
A collision occurs when two keys hash to the same slot; it is handled by chaining or open addressing.
Which data structure is used in breadth-first search (BFS)?
BFS visits nodes level by level using a queue.
Which data structure is used in depth-first search (DFS)?
DFS uses a stack (or recursion, which uses the call stack).
A stack is empty. After push(1), push(2), pop(), push(3), push(4), pop(), what is on top?
Stack after each step: [1], [1,2], [1], [1,3], [1,3,4], [1,3]. Top is 3.
A queue is empty. After enqueue(1), enqueue(2), dequeue(), enqueue(3), dequeue(), what is at the front?
Queue: [1], [1,2], [2], [2,3], [3]. Front is 3.
What is the postfix form of the expression (A + B) * C?
First A + B becomes A B +, then multiply by C.
How many edges does a tree with n nodes have?
A tree is connected and has no cycles, so it has exactly n − 1 edges.
Which of these is a non-linear data structure?
Trees and graphs are non-linear; arrays, stacks and queues are linear.
What is the time complexity of deleting the minimum element from a min-heap of n elements?
The last element replaces the root and is sifted down the height of the heap.
In a doubly linked list, each node contains:
Doubly linked list nodes have next and prev pointers.
Want guided preparation? Placement Papers Prep courses by Dr. Kiran Derle, with video lessons and full-length mocks.
See placement courses ↗