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

Create successful ePaper yourself

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

same depth d as the level dof T. In a b<strong>in</strong>ary tree, level 0 has at most one node (the<br />

root), level 1 has at most two nodes (the children of the root), level 2 has at most<br />

four nodes, <strong>and</strong> so on. (See Figure 7.12.) In general, level d has at most 2 d nodes.<br />

Figure 7.12: Maximum number of nodes <strong>in</strong> the levels<br />

of a b<strong>in</strong>ary tree.<br />

We can see that the maximum number of nodes on the levels of a b<strong>in</strong>ary tree grows<br />

exponentially as we go down the tree. From this simple observation, we can derive<br />

the follow<strong>in</strong>g properties relat<strong>in</strong>g the height of a b<strong>in</strong>ary T with its number of nodes.<br />

A detailed justification of these properties is left as an exercise (R-7.15).<br />

Proposition 7.10: Let T be a nonempty b<strong>in</strong>ary tree, <strong>and</strong> let n, n E , n I <strong>and</strong> h<br />

denote the number of nodes, number of external nodes, number of <strong>in</strong>ternal nodes,<br />

<strong>and</strong> height of T, respectively. Then T has the follow<strong>in</strong>g properties:<br />

1. h+1 ≤ n ≤ 2 h+1 −1<br />

2. 1≤n E ≤2 h<br />

3. h≤n I ≤2 h −1<br />

4. log(n+1)−1 ≤h≤n−1.<br />

Also, if T is proper, then T has the follow<strong>in</strong>g properties:<br />

399

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

Saved successfully!

Ooh no, something went wrong!