0% found this document useful (0 votes)
5 views4 pages

FinalExam Handout

The document outlines the final exam details for CS 2500: Algorithms at Missouri University of Science & Technology, scheduled for May 11, 2023. It includes sample questions covering various topics such as asymptotic notation, recursion, divide and conquer, sorting algorithms, dynamic programming, greedy algorithms, graph search, minimum spanning trees, and shortest-path algorithms. The exam will consist of 6 questions, and the handout serves as a review guide for students.

Uploaded by

ritaberrada06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

FinalExam Handout

The document outlines the final exam details for CS 2500: Algorithms at Missouri University of Science & Technology, scheduled for May 11, 2023. It includes sample questions covering various topics such as asymptotic notation, recursion, divide and conquer, sorting algorithms, dynamic programming, greedy algorithms, graph search, minimum spanning trees, and shortest-path algorithms. The exam will consist of 6 questions, and the handout serves as a review guide for students.

Uploaded by

ritaberrada06
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Missouri University of Science & Technology Department of Computer Science

Spring 2023 CS 2500: Algorithms


Sample Questions for Final Exam
Name: Sid Nadendla Email: [email protected]

Final exam will be a 2-hour long in-class exam on Thursday, May 11, 2023 at 7:30AM-9:30AM in
CS 220. You may have 6 questions to solve, depending on the size of the questions. This handout
presents a few review questions for the final examination.

Section 1 Asymptotic Notation


1. Definitions for Θ, O, Ω, o and ω notations.
n
X n
X
2
2. Prove (a) i = Θ(n ), and (b) i2 = Θ(n3 ).
i=1 i=1

3. If f1 (n) = Θ(g1 (n)) and f2 (n) = Θ(g2 (n)), prove that

f (n) = f1 (n) + f2 (n) = Θ(g1 (n) + g2 (n)).

Section 2 Recursion
1. Using substitution method, prove that the recurrence relation f (n) = 2f (n/2) + n results in
f (n) = O(n log n).

2. Solve T (n) = 2 T (n/3) + n2 using recursion trees, and verify the result using Master’s
theorem.

Section 3 Divide & Conquer


1. Our goal is to find both maximum and minimum elements of a given input array A of size
n efficiently. A naive approach is to find the maximum using n − 1 comparisons and then
find the minimum element over the remaining entries using n − 2 comparisons. Therefore,
this algorithm takes about 2n − 3 comparisons. If you were to adopt a divide-and-conquer
approach, what is the order of improvement in terms of the number of comparisons?

2. The problem is to compute the product of two n-bit input arrays A and B, where n is signif-
icantly larger than the register size in your processor (e.g. Consider the product of 256-bit
arrays over a 64-bit processor). In such a case, it is infeasible to run the traditional method
for finding the product of two arrays. How would you solve this problem?

1
Section 4 Comparison Sorting
1. Write the pseudocode for I NSERTION -S ORT and prove its correctness.

2. Given two sorted input arrays A and B, how can we merge them into a sorted array? Write
the pseudocode for your approach and prove its correctness.

3. Prove that the worst-case run time for H EAP -S ORT is Θ(n log n).

4. If we were to employ divide and conquer approach to design a comparison sort, demonstrate
various sorting algorithms when the pivot element q is always chosen to be

(a) mid-point of the array in each , i.e. M ERGE -S ORT,


(b) such that A[1 : q − 1] ≤ A[q] ≤ A[q + 1 : n], i.e. Q UICK -S ORT,

for a given input array A = [1, 4, 7, 6, 3, 9, 5, 2, 4, 6].

Section 5 Sorting in Linear Time


1. Prove that the running time for comparison sorts is Ω(n log n).

2. Demonstrate C OUNTING -S ORT for the input array A = [1, 4, 2, 5, 3, 1, 2, 4, 3, 1, 4].

Section 6 Dynamic Programming


1. Consider a 0-1 Knapsack problem with n indivisible items, where vi and wi are the value and
weight of the ith item respectively. If the size of the Knapsack is W , show that the Bellman
equation is

V [i, j] = min vi xi + V [i − 1, j − xi wi ], for all i = 1, · · · , n and j = 0, 1, · · · , W,


xi ∈{0,1}

and write the pseudocode for the dynamic programming solution to 0-1 Knapsack problem.

2. Consider a matrix chain multiplication A1 · A2 · · · An , where Ai is a pi−1 × pi matrix. IF the


cost of computing the product of k × ℓ and ℓ × m matrices is kℓm, show that the Bellman
equation is (
m[i, k] + m[k + 1, j] + pi−1 pk pj , if i < j
m[i, j] =
0, otherwise.
Using the above Bellman equation, write a pseudocode for the dynamic programming algo-
rithm for matrix-chain multiplication problem.

2
Section 7 Greedy Algorithms
1. When can a greedy algorithm produce an optimal solution?

2. Demonstrate on the following example, how to find an optimal solution to the Fractional
Knapsack problem using a greedy algorithm?

Figure 1: Fractional Knapsack

Section 8 Graph Search/Traversal


1. Demonstrate Breadth-first search (BFS) on a graph, such as the one shown in Figure 2.

2. Demonstrate Depth-first search (DFS) on a graph, such as the one shown in Figure 2.

3. What is the main difference between the implementation of BFS and DFS algorithms?

Figure 2: Graph Search

Section 9 Minimum Spanning Trees


1. Demonstrate Kruskal’s algorithm on the graph, such as the one shown in Figure 3.

2. Demonstrate Prim’s algorithm on the graph, such as the one shown in Figure 3.

3. Explain why dynamic programming is not a good approach to find minimum spanning trees?

4. State the primary difference between Kruskal’s and Prim’s algorithms?

3
Figure 3: Minimum Spanning Trees

Section 10 Single-Source Shortest-Path Algorithms


1. Demonstrate Bellman-Ford algorithm on the graph, such as the one shown in Figure 4.

2. Demonstrate Dijkstra’s algorithm on the graph, such as the one shown in Figure 4.

3. Explain how Bellman-Ford algorithm can be used to identify negative-weight cycless?

Figure 4: Directed Graph

You might also like