next up previous
Next: About this document

Fundamental Algorithms, Spring 1998

Assignment 10. Sets and graphs.

Given April 13, due Monday, April 20.

1.
The binomial tree (related to binomial heap, CLR, chapter 20) of height h+1, tex2html_wrap_inline47 , is defined inductively. tex2html_wrap_inline49 is a single element. We have been saying that a tree with a single element has height 1, although one could make a case for saying height 0. tex2html_wrap_inline51 is made from two copies of tex2html_wrap_inline47 , call them tex2html_wrap_inline55 with root tex2html_wrap_inline57 , and tex2html_wrap_inline59 with root tex2html_wrap_inline61 . In tex2html_wrap_inline51 , none of the pointers is changes except that the parent pointer of tex2html_wrap_inline61 is set to point to tex2html_wrap_inline57 , and a child pointer of tex2html_wrap_inline57 points to tex2html_wrap_inline61 , if there are child pointers.
a.
Show that tex2html_wrap_inline47 has height h+1 and tex2html_wrap_inline77 nodes.
b.
The binomial coefficients, tex2html_wrap_inline79 , satisfy the relation tex2html_wrap_inline81 . From this, find a formula for the number of nodes at depth k in tex2html_wrap_inline47 ,
c.
Show that tex2html_wrap_inline47 has the fewest elements among all trees of height h that can be made using make_set and union operations, assuming that we are using the union by rank heuristic. Hint: Let tex2html_wrap_inline91 be the sparsest tree of height h that can be made. Show that tex2html_wrap_inline95 is made by joining two copies of tex2html_wrap_inline91 , because any other join would either not increase the height, or have more elements than necessary.

2.
Suppose we have a family of disjoint sets represented by trees with parent pointers only. Show that the additional work to perform another m find operations is O(n+m), where n is the number elements, no matter which elements are being found. (The analysis with find and union is harder.)

3.
In an undirected graph, an edge, e, connects e.head to e.tail. A graph, tex2html_wrap_inline105 , is a subgraph of G if every vertex of tex2html_wrap_inline105 us a vertex of G, and every edge of tex2html_wrap_inline105 is an edge of G. A tree is a connected subgraph with no cycles. A spanning tree is a subgraph containing all the vertices of G that is a tree. A spanning forest is a collection of subgraphs, one spanning tree for each connected component. The following algorithm finds connected components:
for ( x in V ) { makeset(x); }
for ( e in E ) {
   if ( ( x = find(e.head)) != ( y = find(e.tail)) )  union(x,y); }
a.
Add a line or two to make a list of edges that forms a spanning tree if G is connected and a spanning forest otherwise.
b.
Write code to make this spanning tree into a tree sense we used before. That is, there should be a root, parent pointers, and child lists.




next up previous
Next: About this document

Jonathan Goodman
Mon Apr 13 20:59:04 EDT 1998