EXAM 2 DESIGN

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/81

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 10:33 PM on 4/11/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

82 Terms

1
New cards

Q1. [T/F] In the 0/1 knapsack problem, items can be broken into fractions to maximize profit.

FALSE

2
New cards

Q2. [T/F] Memoization is a top-down approach to dynamic programming that stores results of subproblems.

TRUE

3
New cards

Q3. [T/F] Tabulation converts a recursive solution into an iterative one using a table.

TRUE

4
New cards

Q4. [T/F] The base case for the recursive knapsack(wt[], val[], W, n) function is: if n == 0 or W == 0, return 0.

TRUE

5
New cards

Q5. [T/F] In the subset sum problem, the choice diagram always has exactly two branches: include and exclude.

TRUE

6
New cards

Q6. [T/F] Dynamic programming requires that a problem have both optimal substructure and overlapping subproblems.

TRUE

7
New cards

Q7. [T/F] A recursive function with only one function call is typically a sign of a DP problem.

FALSE

8
New cards

Q8. [T/F] In DP, you should always start by building the table before writing the recursive function.

FALSE

9
New cards

Q9. [T/F] The count of subset sum problem asks for the number of subsets that add up to a given target.

TRUE

10
New cards

Q10. [T/F] Unbounded knapsack allows you to include the same item multiple times.

TRUE

11
New cards

Q11. [MCQ] What is the correct order of steps when solving a DP problem?

B) Recursion→Memoization→Tabulation

12
New cards

In the 0/1 knapsack choice diagram, what happens when the current item's weight > remaining capacity W?

C) If wt[n-1] > W, the item cannot fit, so we must exclude it.

13
New cards

Which of the following is a variation of the 0-1 knapsack problem?

B) Count of Subset Sum is one of the six 0-1 knapsack variations.

14
New cards

Q14. [MCQ] What is the base case for the recursive knapsack function?

C) if n == 0 or W == 0: return

15
New cards

Q15. [MCQ] What distinguishes a DP problem from plain recursion?

B) DP has optimal output and 2+ recursive choices

16
New cards

Q16. [MCQ] In the recursive 0/1 knapsack, if we INCLUDE item n, the recursive call becomes:

C) knapsack(wt,val,W-wt[n-1],n-1)

17
New cards

Q17. [MCQ] In the Count of Subset Sum problem, what are you counting? A) The maximum subset weight B) The number of subsets that sum to a target value C) The minimum number of items needed D) The number of items in the knapsack

B) The number of subsets that sum to a target value

18
New cards

Q18. [T/F] In a complete binary tree array representation (1-indexed), the left child of node i is at index 2i.

TRUE

19
New cards

Q19. [T/F] A full binary tree is one where every node has exactly 0 or 2 children.

TRUE

20
New cards

Q20. [T/F] BFS traversal of a binary tree uses a stack as its underlying data structure.

FALSE

21
New cards

Q21. [T/F] Post-order traversal visits the current node before its left and right children.

FALSE

22
New cards

Q22. [T/F] Pre-order traversal visits nodes in the order: current → left → right.

TRUE

23
New cards

Q23. [T/F] In a max-heap, every parent node is greater than or equal to its children.

TRUE

24
New cards

Q24. [T/F] Heap sort has a worst-case time complexity of O(n log n).

TRUE

25
New cards

Q25. [T/F] Inserting into a heap always requires O(1) time.

FALSE

26
New cards

Q26. [T/F] In a binary heap stored as an array (1-indexed), the parent of node i is at index i // 2.

TRUE

27
New cards

Q27. [T/F] A complete binary tree has all levels fully filled except possibly the last, which is filled left to right.

TRUE

28
New cards
<p>Q28. [MCQ] Pre-order traversal on a tree with root 4, left subtree root 2 (children 1,3), right subtree root 6 (children 5,7)? </p>

Q28. [MCQ] Pre-order traversal on a tree with root 4, left subtree root 2 (children 1,3), right subtree root 6 (children 5,7)?

B) 4,2,1,3,6,5,7

29
New cards
<p>Q29. [MCQ] Post-order traversal on the same tree (root 4, left: 2→1,3; right: 6→5,7)? A) 4,2,1,3,6,5,7 B) 1,2,3,4,5,6,7 C) 1,3,2,5,7,6,4 D) 4,2,6,1,3,5,7</p>

Q29. [MCQ] Post-order traversal on the same tree (root 4, left: 2→1,3; right: 6→5,7)? A) 4,2,1,3,6,5,7 B) 1,2,3,4,5,6,7 C) 1,3,2,5,7,6,4 D) 4,2,6,1,3,5,7

C) 1,3,2,5,7,6,4

30
New cards

Q30. [MCQ] In the array representation of a binary tree (1-indexed), where is the right child of node at index 5?

B) Index 11

31
New cards

Q31. [MCQ] Which traversal visits nodes level by level from top to bottom?

D) BFS (Level-order)

32
New cards

Q32. [MCQ] When inserting a value into a max-heap, what must happen after placing the new element?

B) Bubble up (swap with parent) until heap property is restored

33
New cards

Q33. [MCQ] What is Heap Sort's time complexity?

B) O(n log n)

34
New cards

Q34. [MCQ] Which correctly describes a min-heap?

B) Every parent is less than or equal to its children

35
New cards

Q35. [MCQ] Which binary tree type allows missing nodes (gaps) at any level?

C) Incomplete binary tree

36
New cards

Q36. [T/F] The in-degree of a node in a directed graph is the number of edges coming into that node.

TRUE

37
New cards

Q37. [T/F] A walk in a graph can repeat vertices and edges.

TRUE

38
New cards

Q38. [T/F] A simple path cannot repeat vertices.

TRUE

39
New cards

Q39. [T/F] A strongly connected graph requires that every vertex is reachable from every other vertex.

TRUE

40
New cards

Q40. [T/F] A weakly connected directed graph becomes connected if you ignore edge directions.

TRUE

41
New cards

Q41. [T/F] Triangle inequality in unweighted graphs states: d(u,v) ≤ d(u,w) + d(w,v) for any intermediate vertex w.

TRUE

42
New cards

Q42. [T/F] An adjacency matrix for a graph with n vertices always has n² entries.

TRUE

43
New cards

Q43. [T/F] Single Source Reachability asks for the shortest path from one source to one specific target.

FALSE

44
New cards

Q44. [T/F] A trail is a walk in which no edge is repeated, but vertices may be repeated.

TRUE

45
New cards

Q45. [T/F] A cycle is a path where the first and last vertex are the same.

TRUE

46
New cards

Q46. [MCQ] In an adjacency matrix, which value indicates NO edge between vertex i and vertex j?

A) 1

47
New cards

Q47. [MCQ] What is the time complexity of BFS/DFS using an adjacency list?

B) O(V+E)

48
New cards

Q48. [MCQ] Which graph problem finds the shortest path from one source to ALL other vertices?

B) SPSP

49
New cards

Q49. [MCQ] Which ordering goes from most permissive to most restrictive?

B) Walk→Trail→Path→Simple Path

50
New cards

Q50. [MCQ] What must metric distance satisfy?

B) Satisfies symmetry, triangle inequality, and d(u,u)=0

51
New cards

Q51. [T/F] Prim's algorithm is vertex-heavy — it grows the spanning tree by adding one vertex at a time.

TRUE

52
New cards

Q52. [T/F] Kruskal's algorithm is edge-heavy — it always selects the minimum weight edge that doesn't form a cycle.

TRUE

53
New cards

Q53. [T/F] Kruskal's algorithm can find a minimum spanning forest for a disconnected graph.

TRUE

54
New cards

Q54. [T/F] Prim's algorithm works correctly on a disconnected graph.

FALSE

55
New cards

Q55. [T/F] Dijkstra's algorithm works correctly on graphs with negative edge weights.

FALSE

56
New cards

Q56. [T/F] A minimum spanning tree of a graph with n vertices will always have exactly n-1 edges.

TRUE

57
New cards

Q57. [T/F] A* uses a heuristic function to guide its search and is generally faster than Dijkstra's when a good heuristic exists.

TRUE

58
New cards

Q58. [T/F] The minimum spanning tree of a graph is always unique.

FALSE

59
New cards

Q59. [T/F] Dijkstra's algorithm solves the Single Source Shortest Path (SSSP) problem.

TRUE

60
New cards

Q60. [T/F] A spanning tree of a graph can contain cycles.

FALSE

61
New cards

Q61. [MCQ] Which algorithm is better suited for a dense graph (many edges)?

B) Prim's

62
New cards

Q62. [MCQ] In Dijkstra's algorithm, which node is processed at each step?

B) Unvisited node with smallest current distance

63
New cards

Q63. [MCQ] What is the time complexity of Dijkstra's algorithm using a binary min-heap?

C) O((V+E) log V)

64
New cards

Q64. [MCQ] When is A* preferred over Dijkstra's?

B) When a good heuristic is available that estimates distance to the goal

65
New cards

Q65. [MCQ] What must be true for a subgraph to be a valid spanning tree? A) Include all edges B) Include all vertices, have n-1 edges, and be acyclic C) Have minimum total weight D) Be directed

B) Include all vertices, have n-1 edges, and be acyclic

66
New cards

Q66. [T/F] Floyd-Warshall computes the shortest path between every pair of vertices.

TRUE

67
New cards

Q67. [T/F] Floyd-Warshall uses DP by iteratively checking if a path through an intermediate vertex k is shorter.

TRUE

68
New cards

Q68. [T/F] Floyd-Warshall has a time complexity of O(V³).

TRUE

69
New cards

Q69. [T/F] In Floyd-Warshall, A0 represents the adjacency matrix of the original graph (direct edges only).

TRUE

70
New cards

Q70. [T/F] The triangle inequality check in Floyd-Warshall is: A[i][j] < A[i][k] + A[k][j] — if true, update A[i][j].

TRUE

71
New cards

Q71. [T/F] Floyd-Warshall can detect negative cycles if a diagonal entry becomes negative.

TRUE

72
New cards

Q72. [T/F] Johnson's algorithm only works on graphs without negative edges.

FALSE

73
New cards

Q73. [T/F] Johnson's algorithm runs faster than Floyd-Warshall on sparse graphs.

TRUE

74
New cards

Q74. [T/F] In Floyd-Warshall, the diagonal entries of every matrix Ak are always 0 (assuming no negative cycles).

TRUE

75
New cards

Q75. [T/F] Running Dijkstra's n times is a valid approach to All-Pairs Shortest Path, though complexity varies by graph density.

TRUE

76
New cards

Q76. [MCQ] What does matrix Ak represent in Floyd-Warshall?

B) Shortest paths using only vertices 1 through k as intermediaries

77
New cards

Q77. [MCQ] In Floyd-Warshall, which cells are NOT updated when processing intermediate vertex k?

A) Cells in the same row or column as k

78
New cards

Q78. [MCQ] What is the Floyd-Warshall recurrence relation?

C) Ak[i][j] = min(Ak-1[i][j], Ak-1[i][k] + Ak-1[k][j])

79
New cards

Q79. [MCQ] What is the big-picture purpose of Johnson's algorithm?

B) Reweight graph to remove negative edges, then run Dijkstra's from each vertex

80
New cards

Q80. [MCQ] What is the time complexity of Bellman-Ford (used inside Johnson's)?

C) O(V·E)

81
New cards

Q81. [MCQ] When is Johnson's algorithm a better choice than Floyd-Warshall?

B) Sparse graph (few edges)

82
New cards

Q82. [MCQ] Time complexity of Dijkstra's SSSP (min-heap) vs Floyd-Warshall APSP? A) Both O(V²) B) SSSP: O((V+E) log V); APSP: O(V³) C) SSSP: O(V·E); APSP: O(V²) D) Both O(V log V)

B) SSSP: O((V+E) log V); APSP: O(V³)