Professional Documents
Culture Documents
Exercise Sheet 1
Hilary 2018
2. Show how to implement a queue with two stacks so that the amortised cost of each Enqueue
and Dequeue operation is O(1).
3. Assuming link-by-rank and path compression, draw the data structure that results from
executing the following program:
1 for i ← 1 to 16
2 do Make-Set(xi )
3 for i ← 1 to 15 by 2
4 do Union(xi , xi+1 )
5 for i ← 1 to 13 by 4
6 do Union(xi , xi+2 )
7 Union(x1 , x5 )
8 Union(x11 , x13 )
9 Union(x1 , x10 )
10 Find-Set(x2 )
11 Find-Set(x9 )
65536 )
4. If n = 65536(65536 , what is log∗ n?
5. Suppose that we implement disjoint-set forests with link-by-rank, but not path compression.
Show that a sequence of m Union and Find-Set operations, starting from n singletons can
take time Ω(m log n).