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

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

View Full Document Right Arrow Icon
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 TREE-MINIMUM followed by n N 1 calls to TREE-SUCCESSOR performs exactly the same inorder walk of the tree as does the procedure INORDER- TREE-WALK. INORDER-TREE-WALK prints the TREE-MINIMUM first, and by definition, the TREE-SUCCESSOR of a node is the next node in the sorted order determined by an inorder tree walk.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/20/2010 for the course IE ie200 taught by Professor . during the Spring '10 term at 카이스트, 한국과학기술원.

Page1 / 3

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online