1 Which data structure follows the Last In, First Out (LIFO) rule?
A Array
B Stack
C Queue
D Graph
Answer: B. Stack In a stack the last item pushed is the first item popped, like a pile of plates.
2 Which data structure follows First In, First Out (FIFO)?
A Hash table
B Binary tree
C Queue
D Stack
Answer: C. Queue A queue serves items in the order they arrived, like people in a line.
3 What is the worst-case time of binary search on a sorted array of n items?
A O(n)
B O(n log n)
C O(log n)
D O(1)
Answer: C. O(log n) Each step halves the search range. Binary search only works on sorted data.
4 What is the average time to look up a key in a good hash table?
A O(n)
B O(1)
C O(log n)
D O(n^2)
Answer: B. O(1) A hash function jumps straight to the slot, so lookup takes constant time on average.
5 An inorder traversal of a binary search tree visits the keys in which order?
A Level by level
B Sorted, smallest to largest
C Largest to smallest
D Random order
Answer: B. Sorted, smallest to largest Left subtree, node, then right subtree gives ascending order in a BST.
6 Which data structure does breadth-first search (BFS) use?
A Stack
B Hash table
C Heap
D Queue
Answer: D. Queue BFS explores level by level, so it needs a queue of nodes to visit next.
7 Depth-first search (DFS) is naturally implemented with which structure?
A Queue
B Stack
C Linked list only
D Priority queue
Answer: B. Stack DFS goes deep first and backtracks. A stack, or recursion, gives this behaviour.
8 How long does it take to insert a node at the head of a singly linked list?
A O(1)
B O(log n)
C O(n)
D O(n log n)
Answer: A. O(1) Only a few pointers change, no matter how long the list is.
9 What is the worst-case time complexity of quicksort?
A O(n^2)
B O(log n)
C O(n)
D O(n log n)
Answer: A. O(n^2) A bad pivot choice, such as always the smallest item, gives n^2. The average is n log n.
10 What is the time complexity of merge sort in every case?
A O(n)
B O(log n)
C O(n log n)
D O(n^2)
Answer: C. O(n log n) Merge sort always splits in half (log n levels) and merges in n steps per level.
Turn on JavaScript to check answers as you go. The correct answer to each question is: 1-B, 2-C, 3-C, 4-B, 5-B, 6-D, 7-B, 8-A, 9-A, 10-C.