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.

Figure 7.5: The l<strong>in</strong>ked structure for a general tree:<br />

(a) the position object associated with a node; (b) the<br />

portion of the data structure associated with a node<br />

<strong>and</strong> its children.<br />

Table 7.1 summarizes the performance of the implementation of a general tree<br />

us<strong>in</strong>g a l<strong>in</strong>ked structure. The analysis is left as an exercise (C-7.25), but we note<br />

that, by us<strong>in</strong>g a collection to store the children of each node v, we can implement<br />

children(v) simply by return<strong>in</strong>g a reference to this collection.<br />

Table 7.1: Runn<strong>in</strong>g times of the methods of an n-<br />

node general tree implemented with a l<strong>in</strong>ked<br />

structure. We let c v denote the number of children of a<br />

node v. The space usage is O(n).<br />

Operation<br />

Time<br />

size, isEmpty<br />

O(1)<br />

iterator, positions<br />

O(n)<br />

383

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

Saved successfully!

Ooh no, something went wrong!