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.

A Recursive B<strong>in</strong>ary Tree Def<strong>in</strong>ition<br />

Incidentally, we can also def<strong>in</strong>e a b<strong>in</strong>ary tree <strong>in</strong> a recursive way such that a b<strong>in</strong>ary<br />

tree is either empty or consists of:<br />

• A node r, called the root of T <strong>and</strong> stor<strong>in</strong>g an element<br />

• A b<strong>in</strong>ary tree, called the left subtree of T<br />

• A b<strong>in</strong>ary tree, called the right subtree of T.<br />

We discuss some of the specialized topics for b<strong>in</strong>ary trees below.<br />

7.3.1 The B<strong>in</strong>ary Tree ADT<br />

As an abstract data type, a b<strong>in</strong>ary tree is a specialization of a tree that supports three<br />

additional accessor methods:<br />

left(v):<br />

Return the left child of v; an error condition occurs if v has no left child.<br />

right(v):<br />

Return the right child of v; an error condition occurs if v has no right child.<br />

hasLeft(v):<br />

Test whether v has a left child.<br />

397

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

Saved successfully!

Ooh no, something went wrong!