20 hard programming quiz questions and answers for expert-level trivia fans on algorithms and data structures.
1. What is a 'B-tree' commonly used for?
💡 B-trees are commonly used in databases and file systems to efficiently manage large amounts of sorted data.
2. What is 'dynamic programming' primarily used to optimize?
💡 Dynamic programming is used to optimize problems that have overlapping subproblems and optimal substructure.
3. What is the time complexity of Dijkstra's algorithm using a binary heap?
💡 Using a binary heap, Dijkstra's algorithm runs in O((V+E) log V) time, where V is vertices and E is edges.
4. What is a 'red-black tree'?
💡 A red-black tree is a self-balancing binary search tree that maintains balanced height for efficient operations.
5. What is the worst-case time complexity of quicksort?
💡 Quicksort's worst-case time complexity is O(n²), which occurs with consistently poor pivot choices.
6. What is a 'self-balancing binary search tree' designed to maintain?
💡 Self-balancing trees maintain a logarithmic height, ensuring efficient search, insertion, and deletion operations.
7. What is the time complexity of inserting an element into a hash table on average?
💡 On average, inserting into a hash table takes O(1) constant time, assuming a good hash function.
8. What is the space complexity of a recursive Fibonacci algorithm without memoization?
💡 The recursive call stack for a naive Fibonacci implementation grows linearly with n, giving O(n) space complexity.
9. What is a 'trie' data structure commonly used for?
💡 A trie is a tree-like data structure optimized for efficiently storing and retrieving strings, especially by prefix.
10. What is a 'topological sort' used for?
💡 Topological sort orders the vertices of a directed acyclic graph such that each edge points forward in the ordering.
11. What is 'memoization'?
💡 Memoization caches the results of expensive function calls, so repeated calls with the same inputs are faster.
12. What is the time complexity of the bubble sort algorithm in the worst case?
💡 Bubble sort's worst-case time complexity is O(n²), due to its repeated nested comparisons and swaps.
13. What is a 'greedy algorithm'?
💡 A greedy algorithm makes the best local choice at each step, which may or may not lead to a globally optimal solution.
14. What is the time complexity of depth-first search on a graph with V vertices and E edges?
💡 Depth-first search visits each vertex and edge once, resulting in O(V+E) time complexity.
15. What does 'amortized time complexity' describe?
💡 Amortized time complexity describes the average performance of an operation over a sequence of operations, even if some are costly.
16. What is the primary advantage of a hash table over a balanced binary search tree for lookups?
💡 Hash tables typically offer faster average-case lookup time, O(1), compared to a balanced tree's O(log n).
17. What data structure is typically used to implement a priority queue efficiently?
💡 A heap data structure is commonly used to implement priority queues efficiently.
18. What is the time complexity of binary search on a sorted array?
💡 Binary search repeatedly halves the search space, resulting in O(log n) time complexity.
19. What algorithm is commonly used to find the shortest path in a weighted graph with non-negative weights?
💡 Dijkstra's algorithm efficiently finds the shortest path between nodes in a graph with non-negative edge weights.
20. What is the time complexity of merge sort in the average and worst case?
💡 Merge sort consistently runs in O(n log n) time in both the average and worst case.