CodeSignal Technical Assessment Data Structures 2 ā Questions and Answers
Question 1: What is a binary heap used for?
- Efficiently finding the minimum or maximum element and implementing priority queues (Correct answer)
- Storing text data
- Binary search
- Network routing
Correct answer: Efficiently finding the minimum or maximum element and implementing priority queues
Binary heaps maintain a partial ordering that allows O(1) access to the min or max element and O(log n) insertion.
Question 2: What is the space complexity of a recursive function with depth n?
- O(n) due to the call stack (Correct answer)
- O(1)
- O(log n)
- O(n²)
Correct answer: O(n) due to the call stack
Each recursive call adds a frame to the call stack, so n levels of recursion use O(n) stack space.
Question 3: What is a trie data structure?
- A tree-like structure for storing strings where each node represents a character (Correct answer)
- A type of array
- A hash table variant
- A balanced binary tree
Correct answer: A tree-like structure for storing strings where each node represents a character
Tries store strings character by character in a tree structure, enabling efficient prefix-based operations.
Question 4: What is the time complexity of mergesort?
- O(n log n) (Correct answer)
- O(n²)
- O(n)
- O(log n)
Correct answer: O(n log n)
Mergesort divides the array in half recursively (log n levels) and merges at each level (n work per level).
Question 5: What is dynamic programming?
- Solving complex problems by breaking them into overlapping subproblems and storing their solutions (Correct answer)
- A programming language
- A type of loop
- Random algorithm design
Correct answer: Solving complex problems by breaking them into overlapping subproblems and storing their solutions
Dynamic programming avoids redundant computation by storing solutions to subproblems for reuse.
Question 6: What is a graph traversal?
- Visiting all vertices in a graph systematically, using BFS or DFS (Correct answer)
- Sorting a list
- Searching an array
- Balancing a tree
Correct answer: Visiting all vertices in a graph systematically, using BFS or DFS
Graph traversal algorithms like BFS and DFS systematically visit all reachable vertices from a starting point.
What is a binary heap used for?