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.

Electronics R'Us. The children of the root store R&D,<br />

Sales, Purchas<strong>in</strong>g, <strong>and</strong> Manufactur<strong>in</strong>g. The <strong>in</strong>ternal<br />

nodes store Sales, International, Overseas, Electronics<br />

R'Us, <strong>and</strong> Manufactur<strong>in</strong>g.<br />

Formal Tree Def<strong>in</strong>ition<br />

Formally, we def<strong>in</strong>e a tree T as a set of nodes stor<strong>in</strong>g elements such that the nodes<br />

have a parent-child relationship, that satisfies the follow<strong>in</strong>g properties:<br />

• If T is nonempty, it has a special node, called the root of T, that has no<br />

parent.<br />

• Each node v of T different from the root has a unique parent node w;<br />

every node with parent w is a child of w.<br />

Note that accord<strong>in</strong>g to our def<strong>in</strong>ition, a tree can be empty, mean<strong>in</strong>g that it doesn't<br />

have any nodes. This convention also allows us to def<strong>in</strong>e a tree recursively, such<br />

that a tree T is either empty or consists of a node r, called the root of T, <strong>and</strong> a<br />

(possibly empty) set of trees whose roots are the children of r.<br />

Other Node Relationships<br />

377

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

Saved successfully!

Ooh no, something went wrong!