11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 6.6 Further Reading 215will use the “)” symbol) to indic<strong>at</strong>e the end of a child list. All leaf nodes are followedby a “)” symbol because they have no children. A leaf node th<strong>at</strong> is also thelast child for its parent would indic<strong>at</strong>e this by two or more successive “)” symbols.Example 6.8 For the general tree of Figure 6.3, we get the sequentialrepresent<strong>at</strong>ionRAC)D)E))BF))) (6.4)Note th<strong>at</strong> F is followed by three “)” marks, because it is a leaf, the last nodeof B’s rightmost subtree, <strong>and</strong> the last node of R’s rightmost subtree.Note th<strong>at</strong> this represent<strong>at</strong>ion for serializing general trees cannot be used for binarytrees. This is because a binary tree is not merely a restricted form of generaltree with <strong>at</strong> most two children. Every binary tree node has a left <strong>and</strong> a right child,though either or both might be empty. For example, the represent<strong>at</strong>ion of Example6.8 cannot let us distinguish whether node D in Figure 6.17 is the left or rightchild of node B.6.6 Further ReadingThe expression log ∗ n cited in Section 6.2 is closely rel<strong>at</strong>ed to the inverse of Ackermann’sfunction. For more inform<strong>at</strong>ion about Ackermann’s function <strong>and</strong> the costof p<strong>at</strong>h compression for UNION/FIND, see Robert E. Tarjan’s paper “On the efficiencyof a good but not linear set merging algorithm” [Tar75]. The article “<strong>D<strong>at</strong>a</strong><strong>Structures</strong> <strong>and</strong> <strong>Algorithm</strong>s for Disjoint Set Union Problems” by Galil <strong>and</strong> Italiano[GI91] covers many aspects of the equivalence class problem.Found<strong>at</strong>ions of Multidimensional <strong>and</strong> Metric <strong>D<strong>at</strong>a</strong> <strong>Structures</strong> by Hanan Samet[Sam06] tre<strong>at</strong>s various implement<strong>at</strong>ions of tree structures in detail within the contextof K-ary trees. Samet covers sequential implement<strong>at</strong>ions as well as the linked<strong>and</strong> array implement<strong>at</strong>ions such as those described in this chapter <strong>and</strong> Chapter 5.While these books are ostensibly concerned with sp<strong>at</strong>ial d<strong>at</strong>a structures, many ofthe concepts tre<strong>at</strong>ed are relevant to anyone who must implement tree structures.6.7 Exercises6.1 Write an algorithm to determine if two general trees are identical. Make thealgorithm as efficient as you can. Analyze your algorithm’s running time.6.2 Write an algorithm to determine if two binary trees are identical when theordering of the subtrees for a node is ignored. For example, if a tree has rootnode with value R, left child with value A <strong>and</strong> right child with value B, thiswould be considered identical to another tree with root node value R, left

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!