COP 3530 – CS3
Fall 1999
Quiz # 2
Name:__
Sample Quiz
_________
15
1.
Consider the following trees being used to represent equivalence classes (
partitions
) over the set
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
.
Show the resulting combination of the first two trees if we do a
union(2,3)
.
Now show the final tree the results after we do a
union(6,16)
.
In each case, assume that the union starts with two
finds
, each of which uses
path compression
and that the unions use
tree heights to minimize path lengths
.
4
6
2
8
5
1
3
7
9
14
11
13
16
12
15
10
Define the function
lg* N
(also called
log
2
*(N)
).
What is the value of
lg* 2
16
?
How does
lg* N
relate to the management of partition trees by the above algorithms?
10
2.
The following table shows algorithmic costs for
naive
approaches (ones not involving sorts or indices) to relational
operations.
Fill in the columns associated with the use of
indices
.
You may assume constant time index lookup via a
hash table.
Assume
|R| = n
,
|S| = m
,
t = n+m
, and
|Result| = k
Naive
Indexed
R
∪
S
n
×
m
R – S
n
×
m
σ
C
(R)
n
π
–
(R)
n^2
R
∞
S
n
×
m
10
3.
An undirected graph can be checked to see if it’s connected by using a
union/find
algorithm, similar to Kruskal’s tree
spanning algorithm (see
#7
), or by employing
depth first search
.
In words, describe how the depth first search
algorithm solves this problem.
You may assume a graph
G