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.

It is not always clear what productivity experts mean by "nonl<strong>in</strong>ear" th<strong>in</strong>k<strong>in</strong>g, but<br />

when we say that trees are "nonl<strong>in</strong>ear," we are referr<strong>in</strong>g to an organizational<br />

relationship that is richer than the simple "before" <strong>and</strong> "after" relationships between<br />

objects <strong>in</strong> sequences. The relationships <strong>in</strong> a tree are hierarchical, with some objects<br />

be<strong>in</strong>g "above" <strong>and</strong> some "below" others. Actually, the ma<strong>in</strong> term<strong>in</strong>ology for tree data<br />

structures comes from family trees, with the terms "parent," "child," "ancestor," <strong>and</strong><br />

"descendent" be<strong>in</strong>g the most common words used to describe relationships. We show<br />

an example of a family tree <strong>in</strong> Figure 7.1.<br />

Figure 7.1: A family tree show<strong>in</strong>g some<br />

descendents of Abraham, as recorded <strong>in</strong> Genesis,<br />

chapters 25–36.<br />

7.1.1 Tree Def<strong>in</strong>itions <strong>and</strong> Properties<br />

A tree is an abstract data type that stores elements hierarchically. With the<br />

exception of the top element, each element <strong>in</strong> a tree has a parent element <strong>and</strong> zero<br />

or more children elements. A tree is usually visualized by plac<strong>in</strong>g elements <strong>in</strong>side<br />

ovals or rectangles, <strong>and</strong> by draw<strong>in</strong>g the connections between parents <strong>and</strong> children<br />

with straight l<strong>in</strong>es. (See Figure 7.2.) We typically call the top element the root of<br />

the tree, but it is drawn as the highest element, with the other elements be<strong>in</strong>g<br />

connected below (just the opposite of a botanical tree).<br />

Figure 7.2: A tree with 17 nodes represent<strong>in</strong>g the<br />

organization of a fictitious corporation. The root stores<br />

376

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

Saved successfully!

Ooh no, something went wrong!