CSE 373 Sample Final Exam: Instructions Read The Directions For Each Question Carefully Before Answering. We May
CSE 373 Sample Final Exam: Instructions Read The Directions For Each Question Carefully Before Answering. We May
Instructions Read the directions for each question carefully before answering. We may
give partial credit based on the work you write down, so if time permits, show your
work! Use only the data structures and algorithms we have discussed in class or which
were mentioned in the book so far.
Note: For questions where you are drawing pictures, please circle your final answer for
any credit. There is one extra page at the end of the exam that you may use for extra
space on any problem. If you detach this page it must still be turned in with your exam
when you leave.
Advice You have 110 minutes, do the easy questions first, and work quickly!
Page 1 of 12
1) Short Answer Problems: Be sure to answer all parts of the question!!
a) For large input sizes, mergesort will always run faster than insertion sort
(on the same input). True False
b) You could use an AVL tree to do a sort. Describe how you would do this. What
is the worst-case running time for your sort and why? (Be specific)
c) Suppose we choose the median of five items as the pivot in quicksort. If we have
an N element array, then we find the median of the elements located at the
following positions: left (= 0), right (= N – 1), center (the average of left and
right, rounded down), leftOfCenter (the average of left and center, rounded
down), and rightOfCenter (the average of right and center, rounded down). The
median of these elements is the pivot.
Page 2 of 12
[
2) Minimum spanning tree (MST)
Given a weighted, undirected graph with |V| nodes, answer the following as best as
possible, with a brief explanation. Assume all weights are non-negative.
a) If each edge has weight ≤ w, what can you say about the cost of an MST?
b) If the cost of an MST is c, what can you say about the shortest distances returned
by Dijkstra’s algorithm when run with an arbitrary vertex s as the source?
Page 3 of 12
3) Sorting:
a) Show the steps required to do a radix sort on the following set of values when
using base 10.
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9
b) What is the running time of radix sort? Describe any variables you use other than N.
Page 4 of 12
4) Heaps
a) Draw the binary min heap that results from inserting: 77, 22, 9, 68, 16, 34, 13, 8
in that order into an initially empty binary min heap. You do not need to show the
array representation of the heap. You are only required to show the final heap,
although if you draw intermediate heaps, please circle your final result for ANY
credit.
Page 5 of 12
b) Draw the binary min heap that results from doing 2 deletemins on the heap you
created in part a). You are only required to show the final heap, although if you
draw intermediate heaps please circle your final result for ANY credit.
c) What is the null path length of the root node in the last heap you drew in part b)
above?
Page 6 of 12
5) Graph Manipulations:
Use the following graph for this problem. Where needed and not determined by the
algorithm, assume that any algorithm begins at node A.
73
D
B
10 0
5 C
42
A
6 E
a) Draw both the adjacency matrix and adjacency list representations of this graph.
Be sure to specify which is which.
Page 7 of 12
c) Step through Dijkstra’s Algorithm to calculate the single source shortest path
from A to every other vertex. You only need to show your final table, but you
should show your steps in the table below for partial credit. Show your steps by
crossing through values that are replaced by a new value. Note that the next
question asks you to recall what order vertices were declared known.
f) What is the length (weighted cost) of the shortest path you listed in part (e)?
g) Imagine that the graph were undirected (i.e., ignore the directions of the edges).
Highlight the MST(minimum Spanning Tree) on the graph above or redraw it
here.
Page 8 of 12
6) Splay trees
Imagine that the following operations are performed on an initially empty splay tree:
Insert(1), Insert(10), Insert (5), Insert (3), Insert (7), Insert (13), Find (3).
Show the state of the splay tree after performing each of the above operations. Be sure to
label each of your trees with what operations you have just completed. Circle your final
answer for any credit.
Page 9 of 12
7) Hash Tables: Draw the contents of the hash table in the boxes below given the
following conditions:
What values will be in the hash table after the following sequence of insertions? Draw the
values in the boxes below, and show your work for partial credit.
10
Page 10 of 12
8) Hash Tables:
What is the suggested load factor (according to our text) for a hash table that uses open
addressing?
9) Memory
Pick one of the data structures we have studied so far this quarter and describe
when/whether it has spatial and temporal locality:
Page 11 of 12
10) B-trees
b) Insert the following values in this order, into a B-tree where M = 3 and L =2.
8, 4, 6, 2, 3, 1, 7, 9
Page 12 of 12