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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Sec. 6.7 Exercises 217p<strong>at</strong>h the new parent of i. Write a version of FIND th<strong>at</strong> implements p<strong>at</strong>hhalving. Your FIND oper<strong>at</strong>ion should work as you move up the tree, r<strong>at</strong>herthan require the two passes needed by p<strong>at</strong>h compression.6.11 Analyze the fraction of overhead required by the “list of children” implement<strong>at</strong>ion,the “left-child/right-sibling” implement<strong>at</strong>ion, <strong>and</strong> the two linkedimplement<strong>at</strong>ions of Section 6.3.3. How do these implement<strong>at</strong>ions comparein space efficiency?6.12 Using the general tree ADT of Figure 6.2, write a function th<strong>at</strong> takes as inputthe root of a general tree <strong>and</strong> returns a binary tree gener<strong>at</strong>ed by the conversionprocess illustr<strong>at</strong>ed by Figure 6.14.6.13 Use m<strong>at</strong>hem<strong>at</strong>ical induction to prove th<strong>at</strong> the number of leaves in a nonemptyfull K-ary tree is (K − 1)n + 1, where n is the number of internalnodes.6.14 Derive the formulas for computing the rel<strong>at</strong>ives of a non-empty completeK-ary tree node stored in the complete tree represent<strong>at</strong>ion of Section 5.3.3.6.15 Find the overhead fraction for a full K-ary tree implement<strong>at</strong>ion with spacerequirements as follows:(a) All nodes store d<strong>at</strong>a, K child pointers, <strong>and</strong> a parent pointer. The d<strong>at</strong>afield requires four bytes <strong>and</strong> each pointer requires four bytes.(b) All nodes store d<strong>at</strong>a <strong>and</strong> K child pointers. The d<strong>at</strong>a field requires sixteenbytes <strong>and</strong> each pointer requires four bytes.(c) All nodes store d<strong>at</strong>a <strong>and</strong> a parent pointer, <strong>and</strong> internal nodes store Kchild pointers. The d<strong>at</strong>a field requires eight bytes <strong>and</strong> each pointer requiresfour bytes.(d) Only leaf nodes store d<strong>at</strong>a; only internal nodes store K child pointers.The d<strong>at</strong>a field requires four bytes <strong>and</strong> each pointer requires two bytes.6.16 (a) Write out the sequential represent<strong>at</strong>ion for Figure 6.18 using the codingillustr<strong>at</strong>ed by Example 6.5.(b) Write out the sequential represent<strong>at</strong>ion for Figure 6.18 using the codingillustr<strong>at</strong>ed by Example 6.6.6.17 Draw the binary tree representing the following sequential represent<strong>at</strong>ion forbinary trees illustr<strong>at</strong>ed by Example 6.5:ABD//E//C/F//6.18 Draw the binary tree representing the following sequential represent<strong>at</strong>ion forbinary trees illustr<strong>at</strong>ed by Example 6.6:A ′ /B ′ /C ′ D ′ G/EShow the bit vector for leaf <strong>and</strong> internal nodes (as illustr<strong>at</strong>ed by Example 6.7)for this tree.

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

Saved successfully!

Ooh no, something went wrong!