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. 5.1 Definitions <strong>and</strong> Properties 147AABB(a)(b)AABEMPTYEMPTYB(c)(d)Figure 5.2 Two different binary trees. (a) A binary tree whose root has a nonemptyleft child. (b) A binary tree whose root has a non-empty right child. (c) Thebinary tree of (a) with the missing right child made explicit. (d) The binary treeof (b) with the missing left child made explicit.(a)(b)Figure 5.3 Examples of full <strong>and</strong> complete binary trees. (a) This tree is full (butnot complete). (b) This tree is complete (but not full).not full. The heap d<strong>at</strong>a structure (Section 5.5) is an example of a complete binarytree. The Huffman coding tree (Section 5.6) is an example of a full binary tree.5.1.1 The Full Binary Tree TheoremSome binary tree implement<strong>at</strong>ions store d<strong>at</strong>a only <strong>at</strong> the leaf nodes, using the internalnodes to provide structure to the tree. More generally, binary tree implement<strong>at</strong>ionsmight require some amount of space for internal nodes, <strong>and</strong> a different amountfor leaf nodes. Thus, to analyze the space required by such implement<strong>at</strong>ions, it isuseful to know the minimum <strong>and</strong> maximum fraction of the nodes th<strong>at</strong> are leaves ina tree containing n internal nodes.Unfortun<strong>at</strong>ely, this fraction is not fixed. A binary tree of n internal nodes mighthave only one leaf. This occurs when the internal nodes are arranged in a chainending in a single leaf as shown in Figure 5.4. In this case, the number of leavesis low because each internal node has only one non-empty child. To find an upperbound on the number of leaves for a tree of n internal nodes, first note th<strong>at</strong> the upper

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

Saved successfully!

Ooh no, something went wrong!