IITP · Semester ISummaries · Quizzes · Assignments

ECS 5101 — Design and Analysis of Algorithms

Quiz 2 — 25 Questions, Verified Answers (30 Nov 2026)

Source: IITP\Sem-1\ECS5101-DAA\Quiz\DAA Quiz2 25 questions_2026-11-30.md

Source: class WhatsApp group, forwarded 30 Nov 2026 00:08 (Sanjay). The set arrived with the answers already ticked; they were not copied — every one was re-derived and checked against the recorded classes.

Topics: Kadane / DP · binary search · BFS & DFS · Kruskal's MST · red-black trees · M-way and B-trees · BST inorder · quick sort worst case · adjacency matrix · divide-and-conquer maximum subarray.

Answer check: ✅ 25 / 25 correct. Nothing needs changing. Two items are exact duplicates: Q6 ≡ Q8 (4-way tree key count) and Q9 ≡ Q22 (definition of DFS).

How it was checked: against the lecture summaries and transcripts for 14 Nov (red-black trees, graphs, adjacency matrix/list), 22 Nov (BFS, DFS, MST, Kruskal, Prim) and 31 Oct / 25 Oct (M-way and B-trees). Items marked 🟡 are true but were never stated in the recorded summaries — see Gaps found in the lecture summaries.


Quick answer key

Q Ans Q Ans Q Ans Q Ans Q Ans
1 d 6 c 11 a 16 a 21 b
2 a 7 d 12 a 17 b 22 a
3 c 8 c 13 a 18 c 23 True
4 d 9 a 14 b 19 b 24 c
5 b 10 c 15 c 20 True 25 b

Detailed check

Q1. Kadane's algorithm — how is the current maximum ending at position i updated?

a. Previous current sum plus A[i] only · b. Minimum of the two values · c. A[i] only · d. Maximum of A[i] and previous current sum plus A[i]

✅ d. current_sum = max(A[i], current_sum + A[i]) — at every position either start a new subarray at A[i] or extend the one ending at i−1. The global answer keeps the largest current_sum seen. Check: [-2, 3, -1, 4, -5] → best is [3, -1, 4] = 6. Lecture: 27 Sep lab gives the same two update lines (current sum = max(array[i], current sum + array[i]), max sum = max(max sum, current sum)).

Q2. Binary search — target smaller than the middle element, which half next?

a. Left half · b. Right half · c. No further search · d. Entire array

✅ a. The array is sorted, so everything right of the middle is ≥ the middle and cannot hold a smaller target. Discard it; continue on the left. Check: [10,20,30,40,50,60,70], search 20 → compare 40 → search [10,20,30].

Q3. BFS from A on edges (A,B), (A,C), (B,D), (C,E), neighbours alphabetical — traversal order?

a. A, D, B, E, C · b. A, C, E, B, D · c. A, B, C, D, E · d. A, B, D, C, E

✅ c. FIFO queue: A → enqueue B, C → process B, enqueue D → process C, enqueue E → D, E. Levels: {A} · {B, C} · {D, E}. Why the others are traps: b (A, C, E, B, D) is the DFS order with the same alphabetical rule — the classic mix-up. d finishes B's branch (D) before C, which is also depth-first. Lecture: 22 Nov — "BFS traversal uses a queue (FCFS) and explores level by level"; the alphabetical BFS example is worked there step by step.

Q4. Kruskal's algorithm uses which approach?

a. Divide and conquer · b. Dynamic programming · c. Backtracking · d. Greedy

✅ d. Repeatedly take the cheapest edge that does not close a cycle — a locally optimal choice at each step. Lecture: 22 Nov, "Kruskal's algorithm builds an MST by greedily adding the smallest edge that doesn't create a cycle."

Q5. Red-black tree — all paths from a node to descendant NIL leaves contain:

a. Same number of edges · b. Same number of black nodes · c. Same number of internal nodes · d. Same number of red nodes

✅ b. This is the black-height property (property 5). It is what bounds the height at 2·log₂(n+1). Lecture: 14 Nov — "a fixed black-height on all root-to-leaf paths", and the worked tree where every path had exactly 2 black nodes.

Q6. 4-way search tree — maximum keys in one node?

a. 5 · b. 4 · c. 3 · d. 2

✅ c. m-way node = at most m children, therefore at most m − 1 keys. 4 − 1 = 3. Lecture: 24 Oct and 31 Oct — "4-way tree — maximum allowed children = 4, maximum number of elements in any node = 3." Duplicated as Q8.

Q7. Which is a valid red-black tree property?

a. All leaves must be red · b. Every node must have two non-null children · c. Every node must be red · d. Every red node must have black children

✅ d. No RED–RED parent–child pair (property 4); NIL leaves count as black. Lecture: 14 Nov — "red nodes cannot have red children", used in the exam-style question "3 black nodes on a path ⇒ at most 3 red nodes".

Q8. 4-way search tree — maximum keys in one node? (repeat of Q6)

a. 2 · b. 4 · c. 3 · d. 5

✅ c. Same as Q6. Note the options are shuffled, so answer by text, not letter.

Q9. DFS explores a graph by:

a. Exploring one path as deeply as possible before backtracking · b. Visiting all immediate neighbours first · c. Visiting vertices in increasing order · d. Selecting vertices randomly

✅ a. DFS = stack/recursion, go deep, backtrack. Option b describes BFS. Lecture: 22 Nov — "DFS uses a stack (LIFO) to explore as far down a branch as possible before backtracking." Duplicated as Q22.

Q10. A B-tree is primarily designed to:

a. Store data only in main memory · b. Implement recursion · c. Efficiently manage data in secondary storage · d. Perform graph traversal

✅ c. A node is sized to one disk block, so a lookup costs a handful of disk reads instead of one per level of a binary tree. Lecture: 31 Oct — "A disk block/sector can hold, e.g., 512 entries … this determines the maximum value stored (node width)"; 25 Oct — secondary storage is organised in sectors/blocks with an index.

Q11. Kruskal's algorithm selects edges in which order?

a. Increasing order of edge weights · b. By vertex degree · c. Decreasing order · d. Random

✅ a. Sort ascending, then add each edge unless it creates a cycle. Lecture: 22 Nov — "Edges are selected in strict ascending weight order from the sorted list."

Q12. Primary objective of Kruskal's algorithm?

a. Find Minimum Spanning Tree · b. Shortest path between two vertices · c. Longest path · d. All connected components using BFS

✅ a. An MST connects all vertices, is acyclic, has exactly V − 1 edges and minimum total weight. Shortest path is Dijkstra/Bellman-Ford — a different problem.

Q13. A red-black tree is a:

a. Self-balancing Binary Search Tree · b. Complete Binary Tree · c. Full Binary Tree · d. Threaded Binary Tree

✅ a. BST + colours + rotations/recolouring ⇒ O(log n) search, insert, delete. Lecture: 14 Nov — "A Red-Black Tree is a self-balancing binary search tree where each node has a color (red or black)."

Q14. B-tree node becomes overfull during insertion — what happens?

a. No operation · b. Split the node and promote the median key · c. Delete the whole tree · d. Always delete the root

✅ b. The median pops up to the parent and the rest splits into two nodes; if the parent overflows the split cascades upward, and if the root splits the tree grows by one level. Lecture: 31 Oct — "the median element of that node pops up into the upper (parent) node; the remaining keys are split into two nodes. The tree grows upward, not downward."

Q15. When should a vertex be marked visited in BFS?

a. After all vertices are processed · b. When removed from the queue · c. When inserted into the queue · d. Only when it becomes a leaf

✅ c. Marking on enqueue stops a vertex being queued twice via different neighbours, and it is what makes the first discovery a shortest path. 🟡 The 22 Nov notes record the three-state scheme (Ready → Waiting when queued → Processed) but never say "mark on enqueue" explicitly — added to that summary on 2026-12-01.

Q16. Which statement about BFS is correct?

a. BFS finds shortest paths in unweighted graphs · b. BFS uses a stack · c. BFS cannot be applied to disconnected graphs · d. BFS explores graph depth-wise

✅ a. Vertices leave the queue in order of edge-distance from the source. Why not the others: b is DFS; c is false — restart BFS from each unvisited vertex to cover every component; d is DFS. 🟡 The summaries give queue + level order but never state the shortest-path property — added.

Q17. An application of DFS:

a. Finding MST using Kruskal · b. Topological sorting of a DAG · c. Finding minimum edge weight · d. Shortest paths in an unweighted graph

✅ b. DFS finishing times give a topological order of a DAG (reverse the finishing order); it also does cycle detection and connected components. 🟡 The 22 Nov notes list expression trees for DFS, not topological sort — added.

Q18. Which BST traversal gives elements in ascending order?

a. Level order · b. Preorder · c. Inorder · d. Postorder

✅ c. Inorder = Left → Root → Right; with the BST property (left < root < right) that is sorted. Lecture: 18 Oct — in-order is "left, root, right".

Q19. Quick sort, first element as pivot — what causes the worst case?

a. Random elements · b. Pivot repeatedly creates highly unbalanced partitions · c. Exactly two elements · d. Approximately equal partitions

✅ b. Splits of 0 and n−1 give T(n) = T(n−1) + Θ(n) = Θ(n²); already-sorted or reverse-sorted input does this when the first element is the pivot. Lecture: 12 Sep / 13 Sep (partition procedure and pivot fixing).

Q20. True or False: BFS can find the shortest path in an unweighted graph.

✅ True. Same fact as Q16 — distance in edges is minimised by level-order exploration.

Q21. Worst-case comparisons for binary search in an array of 127 elements?

a. 127 · b. 7 · c. 6 · d. 8

✅ b. The decision tree has height ⌊log₂ n⌋ + 1 = ⌊log₂ 127⌋ + 1 = 6 + 1 = 7. Equivalently 127 = 2⁷ − 1, so seven halvings reach a single element. Traps: 127 = linear search; 6 = ⌊log₂ 127⌋, i.e. forgetting the final comparison; 8 = one halving too many (2⁸ = 256, the next power of two above 127). 🟡 The summaries state "binary search is order log n" but not the comparison formula — added.

Q22. DFS explores a graph by: (repeat of Q9)

a. Exploring one path as deeply as possible before backtracking · b. Visiting vertices in increasing order · c. Selecting vertices randomly · d. Visiting all immediate neighbours first

✅ a. Identical to Q9 with options reordered.

Q23. True or False: for an undirected graph, the adjacency matrix is symmetric.

✅ True. An undirected edge {i, j} is recorded in both directions, so A[i][j] = A[j][i] and the matrix is symmetric about the main diagonal. 🟡 Not stated anywhere in the recorded summaries (the 14 Nov class built a directed 5×5 matrix) — added to the 14 Nov and 22 Nov summaries on 2026-12-01.

Q24. In an adjacency matrix, an entry in an unweighted graph generally indicates:

a. Vertex is visited · b. Vertex is a leaf · c. An edge exists from vertex i to vertex j · d. Vertex has degree one

✅ c. A[i][j] = 1 means the edge i→j exists, 0 means it does not. Visited status belongs to the traversal algorithm (a separate array), and degree is read off the row/column counts. Lecture: 14 Nov glossary — "entry (i,j) indicates an edge from vertex i to j".

Q25. Which technique does the divide-and-conquer maximum-subarray solution use?

a. Graph traversal · b. Divide into left, right, and crossing subarrays

The forward cuts off after option b — options c and d were never transmitted, so they are not reconstructed here.

✅ b. Three candidates at every level: best wholly in the left half, best wholly in the right half, best crossing the midpoint (a suffix of the left plus a prefix of the right). Recurrence T(n) = 2T(n/2) + Θ(n) ⇒ Θ(n log n). Lecture: 26 Sep — left sum, right sum, cross sum, with a full 16-element trace; the "crossing = suffix + prefix" structural fact is in the Quiz-1 bank Q16.


Gaps found in the lecture summaries

Checked item by item; these five facts are tested by the quiz but were missing from the recorded summaries. They have now been appended to the relevant summary/notes.md files (marked "Quiz cross-check, added 2026-12-01") so a revision pass over the notes covers the whole paper:

# Fact Quiz item Added to
1 Undirected graph ⇒ symmetric adjacency matrix, A[i][j] = A[j][i] Q23 14 Nov, 22 Nov
2 BFS finds shortest paths in unweighted graphs (distance in edges) Q16, Q20 22 Nov
3 Mark a vertex visited on enqueue (Ready → Waiting), not on dequeue Q15 22 Nov
4 DFS applications include topological sort of a DAG (plus cycle detection, components) Q17 22 Nov
5 Binary-search worst case = ⌊log₂ n⌋ + 1 comparisons (127 → 7) Q21 22 Nov

Everything else the quiz asks (Kadane update, MST/Kruskal, red-black properties, M-way key count, B-tree split/median and disk motivation, quicksort worst case, BST inorder) is already stated in the notes with the same wording.

Cross-checks worth remembering

  • BFS vs DFS option trap: Q3 (b) is the DFS order for the same graph — if the question says "queue"/"level by level", the answer is the alphabetical level order; if it says "stack"/"deep", it is the other one.
  • Q6/Q8 and Q9/Q22 are the same question twice with shuffled options — answer by text.
  • "m-way" vs "B-tree": m−1 keys per node is the M-way rule; "all leaves at the same level" is the B-tree rule. The quiz only tests the first.
  • Quiz 2 syllabus was announced as up to 22 Nov (22 Nov notes, follow-ups), which matches this paper exactly — nothing from heaps, hashing or shortest-path algorithms appears.