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.

C-7.10<br />

Two ordered trees T ′ <strong>and</strong> T ″ are said to be isomorphic if one of the follow<strong>in</strong>g<br />

holds:<br />

• Both T ′ <strong>and</strong> T ″ are empty<br />

• Both T ′ <strong>and</strong> T ″ consist of a s<strong>in</strong>gle node<br />

• Both T ′ <strong>and</strong> T ″ have the same number k ≥ 1 of subtrees, <strong>and</strong> the ith<br />

subtree of T ′ is isomorphic to the ith subtree of T ″, for i = 1, …,k.<br />

Design an algorithm that tests whether two given ordered trees are isomorphic.<br />

What is the runn<strong>in</strong>g time of your algorithm?<br />

C-7.11<br />

Extend the concept of an Euler tour to an ordered tree that is not necessarily a<br />

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

C-7.12<br />

We can def<strong>in</strong>e a b<strong>in</strong>ary tree representation T ′ for an ordered general tree T as<br />

follows (see Figure 7.22):<br />

• For each node u of T, there is an <strong>in</strong>ternal node u ′ of T ′ associated with u.<br />

• If u is an external node of T <strong>and</strong> does not have a sibl<strong>in</strong>g immediately<br />

follow<strong>in</strong>g it, then the children of u ′ <strong>in</strong> T ′ are external nodes.<br />

• If u is an <strong>in</strong>ternal node of T <strong>and</strong> v is the first child of u <strong>in</strong> T, then v is the<br />

left child of u ′ <strong>in</strong> T ′.<br />

• If node v has a sibl<strong>in</strong>g w immediately follow<strong>in</strong>g it, then w ′ is the right<br />

child of v ′ <strong>in</strong> T ′.<br />

Given such a representation T ′ of a general ordered tree T, answer each of the<br />

follow<strong>in</strong>g questions:<br />

a. Is a preorder traversal of T ′ equivalent to a preorder traversal of T?<br />

b. Is a postorder traversal of T ′ equivalent to a postorder traversal of T?<br />

c. Is an <strong>in</strong>order traversal of T ′ equivalent to one of the st<strong>and</strong>ard traversals of<br />

T? If so, which one?<br />

439

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

Saved successfully!

Ooh no, something went wrong!