




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Question 1. Which data structure is most suitable for implementing a priority queue with efficient decrease-key operations? A) Binary Search Tree B) Binary Heap C) Singly Linked List D) Hash Table Answer: B Explanation: Binary heaps provide efficient insert, delete, and decrease-key operations (O(log n)), making them ideal for priority queues, especially in algorithms like Dijkstra's. Question 2. What is the time complexity for building a binary heap from an unordered array? A) O(n) B) O(n log n) C) O(log n) D) O(n^2) Answer: A Explanation: Building a heap from an unordered array can be done in O(n) time using the heapify process, which is more efficient than inserting elements one by one.
Question 3. Which of the following properties is NOT true for a max-heap? A) The value of each node is greater than or equal to its children B) The root contains the maximum element C) The heap is a complete binary tree D) The parent node is always smaller than its children Answer: D Explanation: In a max-heap, the parent is always greater than or equal to its children; the statement that the parent is smaller is false. Question 4. Heap sort relies on which of the following operations? A) Binary search B) Fusion of sorted lists C) Repeated extraction of the maximum element D) Dynamic programming Answer: C Explanation: Heap sort repeatedly extracts the maximum (or minimum for a min- heap) element from the heap, placing it at the end of the array, leading to a sorted array. Question 5. Which is a disadvantage of using a d-ary heap instead of a binary heap? A) Increased height of the heap
D) Rotations are used during insertion and deletion Answer: B Explanation: Not all leaf nodes need to be at the same depth; balanced trees like AVL or Red-Black trees maintain height constraints but do not require all leaves at the same level. Question 8. Which of the following correctly describes the main difference between AVL trees and Red-Black trees? A) AVL trees are not self-balancing B) Red-Black trees guarantee a strictly balanced tree C) AVL trees require more rotations during insertion than Red-Black trees D) Red-Black trees have stricter balance conditions than AVL trees Answer: C Explanation: AVL trees are more strictly balanced, leading to more rotations during insertion and deletion; Red-Black trees allow more imbalance to reduce rotations. Question 9. In B-trees, what does the 'fan-out' refer to? A) The number of child pointers per internal node B) The total number of leaves C) The height of the tree D) The number of keys stored in the root
Answer: A Explanation: The fan-out in B-trees refers to the maximum number of children each internal node can have, affecting the tree's height and disk I/O efficiency. Question 10. Which graph traversal algorithm is best suited for finding the shortest path in an unweighted graph? A) Depth-First Search (DFS) B) Breadth-First Search (BFS) C) Dijkstra's Algorithm D) Floyd-Warshall Algorithm Answer: B Explanation: BFS finds the shortest path in unweighted graphs because it explores neighbors in layers, ensuring the shortest number of edges. Question 11. Which traversal method can be used to topologically sort a directed acyclic graph? A) BFS B) DFS C) Dijkstra's Algorithm D) Bellman-Ford Algorithm Answer: B
Question 14. Kruskal's algorithm constructs an MST by: A) Growing a tree from a starting vertex B) Repeatedly adding the smallest edge that does not form a cycle C) Repeatedly removing the largest edge in a cycle D) Using dynamic programming to find minimal edges Answer: B Explanation: Kruskal's algorithm sorts edges and adds them in order of increasing weight, avoiding cycles via a DSU structure. Question 15. In the Disjoint Set Union (DSU) data structure, which heuristic helps to optimize union operations? A) Lazy evaluation B) Path compression C) Binary search D) Depth balancing Answer: B Explanation: Path compression flattens the structure of the DSU tree during find operations, speeding up subsequent queries. Question 16. The max-flow min-cut theorem states that: A) The maximum flow in a network equals the capacity of the smallest cut
B) The minimum cut is always smaller than the maximum flow C) The maximum flow and minimum cut are unrelated D) The maximum flow equals the number of edges in the network Answer: A Explanation: The theorem states that the maximum flow from source to sink equals the capacity of the minimum cut separating them. Question 17. Ford-Fulkerson algorithm relies on which concept? A) Augmenting paths in residual graphs B) Shortest path computations C) Dynamic programming D) Cycle detection Answer: A Explanation: It repeatedly finds augmenting paths in the residual graph to increase flow until no more paths exist. Question 18. What is the worst-case time complexity of the Edmonds-Karp algorithm? A) O(V^3) B) O(VE) C) O(VE^2)
Explanation: The potential method defines a potential function to measure stored "credit" that accounts for future costs, providing bounds on amortized costs. Question 21. Which characteristic is essential for a problem to be suitable for dynamic programming? A) Greedy choice property B) Optimal substructure C) Independence of subproblems D) Polynomial-time solution Answer: B Explanation: Dynamic programming requires the problem to exhibit optimal substructure, where optimal solutions can be built from optimal solutions of subproblems. Question 22. Which technique is commonly used in dynamic programming to avoid recomputing subproblems? A) Memoization B) Divide and conquer C) Greedy choice D) Backtracking Answer: A
Explanation: Memoization stores solutions to subproblems, preventing redundant calculations and improving efficiency. Question 23. The Longest Common Subsequence (LCS) problem demonstrates which key property of dynamic programming? A) Overlapping subproblems B) Greedy choice property C) Divide and conquer D) Binary search applicability Answer: A Explanation: LCS involves overlapping subproblems that are solved and stored to build the final solution efficiently. Question 24. In matrix chain multiplication, the goal is to: A) Minimize the number of scalar multiplications B) Maximize the number of multiplications C) Balance the matrices D) Find the shortest multiplication sequence Answer: A Explanation: The problem seeks the optimal parenthesization to minimize total scalar multiplications.
B) Finding the median in expected linear time C) Building a heap D) Detecting cycles in graphs Answer: B Explanation: Quickselect partitions the array similar to quicksort and efficiently finds the kth smallest element, such as the median. Question 28. The median of medians algorithm guarantees: A) Expected linear time B) Worst-case linear time for selection C) Quadratic time complexity D) Logarithmic time complexity Answer: B Explanation: It provides a deterministic linear-time selection algorithm by choosing good pivots via median of medians. Question 29. Universal hashing aims to: A) Minimize the size of hash tables B) Reduce the probability of collisions across a family of hash functions C) Create perfect hash functions for static data D) Store data in sorted order
Answer: B Explanation: Universal hashing ensures that, over a family of hash functions, the probability of collision between any two distinct keys is minimized. Question 30. Perfect hashing is most suitable when: A) The key set is dynamic B) The key set is static and known in advance C) Hash functions are chosen randomly D) Collisions are unavoidable Answer: B Explanation: Perfect hashing constructs a hash function with no collisions for a fixed set of keys, suitable for static datasets. Question 31. Which data structure is most efficient for maintaining a set of elements with quick union and find operations? A) Binary Search Tree B) Disjoint Set Union (Union-Find) C) Hash Table D) Array List Answer: B Explanation: The DSU or Union-Find data structure efficiently supports union and find operations, especially with heuristics like path compression.
Question 34. The main advantage of Fibonacci heaps over binary heaps in graph algorithms is: A) Faster insertions B) Faster decrease-key operations C) Simpler implementation D) Better space efficiency Answer: B Explanation: Fibonacci heaps support decrease-key in amortized O(1), which benefits algorithms like Dijkstra's. Question 35. Which property distinguishes a balanced search tree like an AVL or Red-Black tree from a simple binary search tree? A) All nodes are at the same level B) The height is maintained at O(log n) C) They are not binary trees D) They do not allow duplicate keys Answer: B Explanation: Balanced trees ensure the height remains O(log n), guaranteeing efficient search, insert, and delete operations. Question 36. In a B+-Tree, the actual data records are stored: A) In internal nodes
B) In leaf nodes C) In the root and internal nodes D) In a separate index file Answer: B Explanation: B+-Trees store data only in leaf nodes, with internal nodes containing only keys for routing. Question 37. Which of the following is a key benefit of using B-trees in databases? A) Reduced memory usage B) Fast sequential access C) Minimized disk I/O due to high fan-out D) Simpler implementation than binary trees Answer: C Explanation: High fan-out reduces the height and the number of disk accesses needed for search operations. Question 38. Which graph traversal algorithm can be used to detect cycles in a directed graph? A) Breadth-First Search (BFS) B) Depth-First Search (DFS) C) Dijkstra's Algorithm
Question 41. Which of the following is NOT a property of a minimum spanning tree? A) It connects all vertices B) It has the minimum total edge weight C) It minimizes the maximum edge weight D) It contains no cycles Answer: C Explanation: MST minimizes total weight, not necessarily the maximum edge weight in the tree. Question 42. Prim's algorithm begins with: A) Sorting all edges B) An arbitrary starting vertex and growing the tree C) Repeatedly adding the smallest edge crossing a cut D) Merging disjoint sets Answer: B Explanation: Prim's algorithm starts with an arbitrary vertex and grows the MST by adding the minimum weight edge connecting the tree to a new vertex. Question 43. Which statement accurately describes the cycle property of MSTs?
A) The heaviest edge in any cycle does not belong to the MST B) The lightest edge in any cycle is always in the MST C) Removing any edge from the MST creates a cycle D) The cycle property is unrelated to MSTs Answer: A Explanation: In MSTs, the heaviest edge in any cycle can be removed without disconnecting the graph, ensuring minimal total weight. Question 44. In the context of amortized analysis, what does the potential function represent? A) The total actual cost of operations B) The accumulated "stored energy" that can pay for future operations C) The worst-case cost of an operation D) The average cost over all operations Answer: B Explanation: The potential function captures stored "credit" in the data structure, which can be used to offset future expensive operations. Question 45. Which of the following is an example of a canonical dynamic programming problem? A) Dijkstra's Algorithm B) Longest Common Subsequence