{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

chap12-solutions

# chap12-solutions - Selected Solutions for Chapter 12 Binary...

This preview shows pages 1–2. Sign up to view the full content.

Selected Solutions for Chapter 12: Binary Search Trees Solution to Exercise 12.1-2 In a heap, a node’s key is ± both of its children’s keys. In a binary search tree, a node’s key is ± its left child’s key, but ² its right child’s key. The heap property, unlike the binary-searth-tree property, doesn’t help print the nodes in sorted order because it doesn’t tell which subtree of a node contains the element to print before that node. In a heap, the largest element smaller than the node could be in either subtree. Note that if the heap property could be used to print the keys in sorted order in O.n/ time, we would have an O.n/ -time algorithm for sorting, because building the heap takes only O.n/ time. But we know (Chapter 8) that a comparison sort must take .n lg n/ time. Solution to Exercise 12.2-7 Note that a call to T REE -M INIMUM followed by n NUL 1 calls to T REE -S UCCESSOR performs exactly the same inorder walk of the tree as does the procedure I NORDER - T REE -W ALK . I NORDER -T REE -W ALK prints the T REE -M INIMUM first, and by definition, the T REE -S UCCESSOR of a node is the next node in the sorted order determined by an inorder tree walk.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

chap12-solutions - Selected Solutions for Chapter 12 Binary...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online