Data Structures and Algorithms Final Exam PDF
Data Structures and Algorithms Final Exam PDF
General rules
1. This test is open book. You may consult the class notes, the recordings of the lectures, your
programs, the textbook, and the Internet. You may not consult any person. You must cite
any sources you consult.
Sources consulted:
2. You may use up to 2 hours for this exam (including any time you spend consulting sources).
If you have a documented disability, you may spend additional time.
Reason for turning in after 12:30pm EDT Thursday, May 13:
3. You must submit this exam via Canvas. You may (1) print the exam, write on it, then scan
or photograph it, or (2) write the answers on paper and scan/photograph them, or (3) enter
the answers into a computer file using Word or something similar, including pictures, and
export the file as PDF. I prefer PDF, but JPEG is also acceptable. You may submit multiple
pages either by multiple submissions or (preferably) as a single ZIP file.
4. You must sign this note (either scan this page or write it on your test:
I have not spoken with other people about this exam, and I will not speak with others
who have not yet finished the exam. I have only used the allowed amount of time on the
exam.
Signature:
CS315 Spring 2021: Final exam 2
1 Graphs
These questions refer to this graph:
4
G D
1
1 5
E 3
A 6
F
2 1
B C
7
(a) Starting at vertex F, list the vertices that are visited in order by Depth-First Search (DFS).
Always follow alphabetical order when there is a choice. Ignore the weights.
(b) Starting at vertex E, list the vertices that are visited in order by Breadth-First Search (BFS).
Always follow alphabetical order when there is a choice. Ignore the weights.
(d) Show the intermediate situation for Prim’s algorithm, starting with vertex A, after 4 edges
have been added. You may draw your answer on this skeleton:
G D
E A F
B C
(e) Show the intermediate situation for Kruskal’s algorithm after 5 edges have been added. You
may draw your answer on this skeleton:
G D
E A F
B C
CS315 Spring 2021: Final exam 3
2 Union-find algorithm
(a) Consider vertices Q, R, S, T, U, V, W, initially disconnected. Draw the directed graph result-
ing from the following calls to union(). When you have a choice (you don’t always have a
choice), follow alphabetical order: earlier vertex points to later one. Do not use path compres-
sion. union(Q,R), union(S,T), union(S,U), union(Q,U), union(V, W).
Q
W R
V S
U T
(b) After all these union operations are finished, is the resulting graph acyclic?
(c) After all these union operations are finished, what is the degree of vertex T?
3 Numerical algorithms
(a) Show the steps in the Euclidean algorithm to find the greatest common divisor (gcd) of 381
and 141.
(b) Consider calculating 1123 . How many multiplications are needed for the brute-force calcula-
tion?
(c) How many multiplications are needed for the fast exponentiation algorithm?
4 String matching
These questions refer to this text: t=abcabcabcacd and to this pattern: p=bcac.
(b) How many character-character comparisons does the brute-force search use?
(c) Assuming no hash collisions, how many character-character comparisons does the Rabin-
Karp (hash-based pre-check) method use?
(d) How many character-character comparisons does the Boyer-Moore algorithm (searching from
the end of p to its start) use, employing only the occurrence heuristic?
5 Edit distance
Complete this chart to compute the edit distance between the string mystery and the string
monster. You don’t need to show the path through the chart leading to the end.
m y s t e r y
0 1 2 3 4 5 6 7
m 1
o 2
n 3
s 4
t 5
e 6
r 7