CS 6515 FINAL EXAM ACTUAL EXAM COMPLETE 90
QUESTIONS AND CORRECT DETAILED ANSWERS (VERIFIED
ANSWERS) WITH RATIONALES |ALREADY GRADED
A+||BRAND NEW VERSION!!.
QUESTION
Kite Reduction
CORRECT ANS: Prove Kite is in NP by verifying that - check for the clique - O(n²) -
check for the tail of degree <= 2 nodes O(n) - check for that the tail is connected to the
clique with Explore (O(n). Reduce Clique to Kite by adding a tail of length g to each
vertex in graph G O(n²). Transform back to Clique by removing all vertices of degree <=
2 (prune the tails). If there is no solution to Kite then there is no clique in G. If there is a
solution to Kite, removing the tail is then a solution to clique.
Expert Rationale
The Kite problem is proven NP-complete by showing it is in NP (verifiable in polynomial
time) and by reducing Clique to Kite in polynomial time. The reduction adds a tail of
length g to each vertex, creating a graph where a Kite's clique corresponds to a Clique
in the original graph. Removing the degree ≤ 2 vertices (the tails) leaves the Clique. This
demonstrates that the Kite problem is at least as hard as Clique, which is NP-complete.
DIF: Cognitive Level: Analyze (Analysis) TOP: NP-Completeness MSC: N/A
QUESTION
CMM
CORRECT ANS: Chain Matrix Multiply. If your problem needs a windowing check. If
your problem is looking to split an array. Looking to split an array in some way to do
something. Start a window size of 1->n set i to 1->n-window. Set j to i+window.
Calculate T(i,j) using smaller windows between i and j. Let m[i-1] and m[i] be the
dimensions of A[i]. Let T(i,j) = minimum cost for computing A[i] * A[i+1] * .. A[j]. T(i,i) = 0
for 1<=i<=n. For 1<=i<j<=n, T(i,j) = Min {T(i,k) + T(k+1,j) + m[i-1] * m[k] * m[j] |
i<=k<=j-1}.
,Expert Rationale
Chain Matrix Multiplication is a classic dynamic programming problem that finds the
optimal parenthesization of a matrix chain to minimize the number of scalar
multiplications. The recurrence splits the problem at k, combining the cost of
multiplying the left and right subchains plus the cost of multiplying the two resulting
matrices. The windowing approach systematically computes all subproblems from
smaller to larger dimensions.
DIF: Cognitive Level: Apply (Application) TOP: Dynamic Programming MSC: N/A
QUESTION
Quick Sort Runtime
CORRECT ANS: O(n²). O(nlogn) with median of medians.
Expert Rationale
Quicksort has a worst-case time complexity of O(n²) when the pivot selection
consistently results in unbalanced partitions (e.g., already sorted array and choosing the
first element as pivot). With the median of medians selection algorithm, the pivot is
guaranteed to be near the median, ensuring balanced partitions and a runtime of
O(nlogn).
DIF: Cognitive Level: Remember (Knowledge) TOP: Sorting Algorithms MSC: N/A
QUESTION
Merge Sort Runtime
CORRECT ANS: O(nlogn)
Expert Rationale
Merge Sort is a divide-and-conquer algorithm that recursively divides the array in half
and merges the sorted halves. The recurrence T(n) = 2T(n/2) + O(n) resolves to
O(nlogn). This runtime is independent of the input order, making it a stable and reliable
sorting algorithm.
DIF: Cognitive Level: Remember (Knowledge) TOP: Sorting Algorithms MSC: N/A
,QUESTION
Quick Select Runtime
CORRECT ANS: O(n²). O(n) with median of medians (Fast select).
Expert Rationale
Quickselect is a selection algorithm to find the kth smallest element. Its worst-case
runtime is O(n²) when poor pivots are chosen. However, with the median of medians
deterministic pivot selection, it guarantees O(n) time, making it a linear-time selection
algorithm.
DIF: Cognitive Level: Remember (Knowledge) TOP: Selection Algorithms MSC: N/A
QUESTION
Dijkstra's algorithm
CORRECT ANS: An algorithm for finding the shortest paths between nodes in a
weighted graph. For a given source node in the graph, the algorithm finds the shortest
path between that node and every other. It can also be used for finding the shortest
paths from a single node to a single destination node by stopping the algorithm once
the shortest path to the destination node has been determined. Its time complexity is
O(E + VlogV), where E is the number of edges and V is the number of vertices. - uses
min-heap (prio-queue) - O((n+m) log n) - O(m log n) - strongly connected - prev(u)
Expert Rationale
Dijkstra's algorithm is a greedy algorithm for the single-source shortest path problem
on graphs with non-negative edge weights. It uses a priority queue to efficiently select
the vertex with the minimum distance, relaxing its outgoing edges. The prev array stores
the predecessor of each vertex, allowing path reconstruction. The runtime of O(m log n)
is achieved with a binary heap implementation.
DIF: Cognitive Level: Understand (Comprehension) TOP: Graph Algorithms MSC: N/A
QUESTION
Kruskal's Algorithm
, CORRECT ANS: (Minimum Spanning Trees, O(mlogn) with a union find, which is fast for
sparse graphs) Builds up connected components of vertices, repeatedly considering the
lightest remaining edge and tests whether its two endpoints lie within the same
connected component. If not, insert the edge and merge the two components into one.
input: undirected G=(V,E) with weights w(e) 1. sort E by incr weight (O(mlogn)) 2. set X =
empty set 3. for e = (v, w) exists E (go through in order) if x Ue doesnt have a cycle then:
X = X U e(checks if v and w are in different components: O(log n)) 4. return X. returns
MST defined by edges X.
Expert Rationale
Kruskal's algorithm is a greedy algorithm for finding the MST. It sorts all edges by
weight and adds them one by one, provided they don't create a cycle. The cycle check is
efficiently performed using a union-find data structure. The algorithm is particularly
efficient for sparse graphs, with a runtime of O(mlogn) dominated by the sorting step.
DIF: Cognitive Level: Understand (Comprehension) TOP: Graph Algorithms MSC: N/A
QUESTION
Prim's Algorithm for MST
CORRECT ANS: Start with a node and add edge with the lowest weight. Then from the
current existing nodes add the next smallest edge that exists going out from all the
existing nodes. Do this until all vertices are connected. - min spanning tree defined by
array prev[] - O(m log n)
Expert Rationale
Prim's algorithm grows the MST from an arbitrary starting vertex. At each step, it adds
the lightest edge connecting a vertex in the current tree to a vertex outside the tree.
This greedy approach is also optimal for MSTs. The algorithm uses a priority queue,
similar to Dijkstra's, resulting in O(m log n) runtime.
DIF: Cognitive Level: Understand (Comprehension) TOP: Graph Algorithms MSC: N/A
QUESTION
Ford-Fulkerson Algorithm
QUESTIONS AND CORRECT DETAILED ANSWERS (VERIFIED
ANSWERS) WITH RATIONALES |ALREADY GRADED
A+||BRAND NEW VERSION!!.
QUESTION
Kite Reduction
CORRECT ANS: Prove Kite is in NP by verifying that - check for the clique - O(n²) -
check for the tail of degree <= 2 nodes O(n) - check for that the tail is connected to the
clique with Explore (O(n). Reduce Clique to Kite by adding a tail of length g to each
vertex in graph G O(n²). Transform back to Clique by removing all vertices of degree <=
2 (prune the tails). If there is no solution to Kite then there is no clique in G. If there is a
solution to Kite, removing the tail is then a solution to clique.
Expert Rationale
The Kite problem is proven NP-complete by showing it is in NP (verifiable in polynomial
time) and by reducing Clique to Kite in polynomial time. The reduction adds a tail of
length g to each vertex, creating a graph where a Kite's clique corresponds to a Clique
in the original graph. Removing the degree ≤ 2 vertices (the tails) leaves the Clique. This
demonstrates that the Kite problem is at least as hard as Clique, which is NP-complete.
DIF: Cognitive Level: Analyze (Analysis) TOP: NP-Completeness MSC: N/A
QUESTION
CMM
CORRECT ANS: Chain Matrix Multiply. If your problem needs a windowing check. If
your problem is looking to split an array. Looking to split an array in some way to do
something. Start a window size of 1->n set i to 1->n-window. Set j to i+window.
Calculate T(i,j) using smaller windows between i and j. Let m[i-1] and m[i] be the
dimensions of A[i]. Let T(i,j) = minimum cost for computing A[i] * A[i+1] * .. A[j]. T(i,i) = 0
for 1<=i<=n. For 1<=i<j<=n, T(i,j) = Min {T(i,k) + T(k+1,j) + m[i-1] * m[k] * m[j] |
i<=k<=j-1}.
,Expert Rationale
Chain Matrix Multiplication is a classic dynamic programming problem that finds the
optimal parenthesization of a matrix chain to minimize the number of scalar
multiplications. The recurrence splits the problem at k, combining the cost of
multiplying the left and right subchains plus the cost of multiplying the two resulting
matrices. The windowing approach systematically computes all subproblems from
smaller to larger dimensions.
DIF: Cognitive Level: Apply (Application) TOP: Dynamic Programming MSC: N/A
QUESTION
Quick Sort Runtime
CORRECT ANS: O(n²). O(nlogn) with median of medians.
Expert Rationale
Quicksort has a worst-case time complexity of O(n²) when the pivot selection
consistently results in unbalanced partitions (e.g., already sorted array and choosing the
first element as pivot). With the median of medians selection algorithm, the pivot is
guaranteed to be near the median, ensuring balanced partitions and a runtime of
O(nlogn).
DIF: Cognitive Level: Remember (Knowledge) TOP: Sorting Algorithms MSC: N/A
QUESTION
Merge Sort Runtime
CORRECT ANS: O(nlogn)
Expert Rationale
Merge Sort is a divide-and-conquer algorithm that recursively divides the array in half
and merges the sorted halves. The recurrence T(n) = 2T(n/2) + O(n) resolves to
O(nlogn). This runtime is independent of the input order, making it a stable and reliable
sorting algorithm.
DIF: Cognitive Level: Remember (Knowledge) TOP: Sorting Algorithms MSC: N/A
,QUESTION
Quick Select Runtime
CORRECT ANS: O(n²). O(n) with median of medians (Fast select).
Expert Rationale
Quickselect is a selection algorithm to find the kth smallest element. Its worst-case
runtime is O(n²) when poor pivots are chosen. However, with the median of medians
deterministic pivot selection, it guarantees O(n) time, making it a linear-time selection
algorithm.
DIF: Cognitive Level: Remember (Knowledge) TOP: Selection Algorithms MSC: N/A
QUESTION
Dijkstra's algorithm
CORRECT ANS: An algorithm for finding the shortest paths between nodes in a
weighted graph. For a given source node in the graph, the algorithm finds the shortest
path between that node and every other. It can also be used for finding the shortest
paths from a single node to a single destination node by stopping the algorithm once
the shortest path to the destination node has been determined. Its time complexity is
O(E + VlogV), where E is the number of edges and V is the number of vertices. - uses
min-heap (prio-queue) - O((n+m) log n) - O(m log n) - strongly connected - prev(u)
Expert Rationale
Dijkstra's algorithm is a greedy algorithm for the single-source shortest path problem
on graphs with non-negative edge weights. It uses a priority queue to efficiently select
the vertex with the minimum distance, relaxing its outgoing edges. The prev array stores
the predecessor of each vertex, allowing path reconstruction. The runtime of O(m log n)
is achieved with a binary heap implementation.
DIF: Cognitive Level: Understand (Comprehension) TOP: Graph Algorithms MSC: N/A
QUESTION
Kruskal's Algorithm
, CORRECT ANS: (Minimum Spanning Trees, O(mlogn) with a union find, which is fast for
sparse graphs) Builds up connected components of vertices, repeatedly considering the
lightest remaining edge and tests whether its two endpoints lie within the same
connected component. If not, insert the edge and merge the two components into one.
input: undirected G=(V,E) with weights w(e) 1. sort E by incr weight (O(mlogn)) 2. set X =
empty set 3. for e = (v, w) exists E (go through in order) if x Ue doesnt have a cycle then:
X = X U e(checks if v and w are in different components: O(log n)) 4. return X. returns
MST defined by edges X.
Expert Rationale
Kruskal's algorithm is a greedy algorithm for finding the MST. It sorts all edges by
weight and adds them one by one, provided they don't create a cycle. The cycle check is
efficiently performed using a union-find data structure. The algorithm is particularly
efficient for sparse graphs, with a runtime of O(mlogn) dominated by the sorting step.
DIF: Cognitive Level: Understand (Comprehension) TOP: Graph Algorithms MSC: N/A
QUESTION
Prim's Algorithm for MST
CORRECT ANS: Start with a node and add edge with the lowest weight. Then from the
current existing nodes add the next smallest edge that exists going out from all the
existing nodes. Do this until all vertices are connected. - min spanning tree defined by
array prev[] - O(m log n)
Expert Rationale
Prim's algorithm grows the MST from an arbitrary starting vertex. At each step, it adds
the lightest edge connecting a vertex in the current tree to a vertex outside the tree.
This greedy approach is also optimal for MSTs. The algorithm uses a priority queue,
similar to Dijkstra's, resulting in O(m log n) runtime.
DIF: Cognitive Level: Understand (Comprehension) TOP: Graph Algorithms MSC: N/A
QUESTION
Ford-Fulkerson Algorithm