23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

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.

10.6 Exercises<br />

For source code <strong>and</strong> help with exercises, please visit<br />

java.datastructures.net.<br />

Re<strong>in</strong>forcement<br />

R-10.1<br />

We def<strong>in</strong>ed a b<strong>in</strong>ary search tree so that keys equal to a node's key can be <strong>in</strong><br />

either the left or right subtree of that node. Suppose we change the def<strong>in</strong>ition so<br />

that we restrict equal keys to the right subtree. What must a subtree of a b<strong>in</strong>ary<br />

search tree conta<strong>in</strong><strong>in</strong>g only equal keys look like <strong>in</strong> this case?<br />

R-10.2<br />

How many different b<strong>in</strong>ary search trees can store the keys {1,2,3}?<br />

R-10.3<br />

How many different b<strong>in</strong>ary search trees can store the keys {1,2,3,4}?<br />

R-10.4<br />

Insert, <strong>in</strong>to an empty b<strong>in</strong>ary search tree, entries with keys 30, 40, 24, 58, 48, 26,<br />

11, 13 (<strong>in</strong> this order). Draw the tree after each <strong>in</strong>sertion.<br />

R-10.5<br />

Suppose that the methods of B<strong>in</strong>arySearchTree (Code Fragments 10.3–<br />

10.5) are used to perform the updates shown <strong>in</strong> Figures 10.3, 10.4, <strong>and</strong> 10.5.<br />

What is the node referenced by action Pos after each update?<br />

R-10.6<br />

Dr. Amongus claims that the order <strong>in</strong> which a fixed set of entries is <strong>in</strong>serted <strong>in</strong>to<br />

a b<strong>in</strong>ary search tree does not matter—the same tree results every time. Give a<br />

small example that proves he is wrong.<br />

R-10.7<br />

Dr. Amongus claims that the order <strong>in</strong> which a fixed set of entries is <strong>in</strong>serted <strong>in</strong>to<br />

an AVL tree does not matter—the same AVL tree results every time. Give a<br />

small example that proves he is wrong.<br />

R-10.8<br />

666

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

Saved successfully!

Ooh no, something went wrong!