CPA Data Structures & Algorithms 2 ā Questions and Answers
Question 1: Which data structure uses LIFO (Last In, First Out) ordering?
- Queue
- Stack (Correct answer)
- Deque
- Priority Queue
Correct answer: Stack
A stack follows LIFO ordering where the last element pushed is the first one popped.
Question 2: What is the worst-case time complexity of binary search on a sorted array of n elements?
- O(n)
- O(n log n)
- O(log n) (Correct answer)
- O(1)
Correct answer: O(log n)
Binary search halves the search space each step, yielding O(log n) worst-case time.
Question 3: In a singly linked list, inserting a node at the head takes how much time?
- O(n)
- O(log n)
- O(n²)
- O(1) (Correct answer)
Correct answer: O(1)
Head insertion requires only pointer updates regardless of list length, so it is O(1).
Question 4: Which traversal of a binary search tree visits nodes in ascending sorted order?
- Pre-order
- Post-order
- In-order (Correct answer)
- Level-order
Correct answer: In-order
In-order traversal (left ā root ā right) on a BST yields keys in ascending sorted order.
Question 5: What is the space complexity of merge sort?
- O(1)
- O(log n)
- O(n) (Correct answer)
- O(n²)
Correct answer: O(n)
Merge sort requires O(n) auxiliary space for the temporary arrays used during merging.
Question 6: A hash table collision resolution strategy that places all colliding keys in a linked list at the same bucket is called:
- Open addressing
- Linear probing
- Separate chaining (Correct answer)
- Quadratic probing
Correct answer: Separate chaining
Separate chaining stores colliding elements in a linked list (or other structure) at each bucket.
Question 7: Which algorithm is best suited for finding the shortest path in an unweighted graph?
- Dijkstra's algorithm
- Bellman-Ford algorithm
- Breadth-first search (Correct answer)
- Depth-first search
Correct answer: Breadth-first search
BFS explores nodes level by level, guaranteeing the shortest path (fewest edges) in an unweighted graph.
Which data structure uses LIFO (Last In, First Out) ordering?