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.

Illustrate the execution of the selection-sort algorithm on the follow<strong>in</strong>g <strong>in</strong>put<br />

sequence: (22,15,36,44,10,3,9,13,29,25).<br />

R-8.6<br />

Illustrate the execution of the <strong>in</strong>sertion-sort algorithm on the <strong>in</strong>put se quence of<br />

the previous problem.<br />

R-8.7<br />

Give an example of a worst-case sequence with n elements for <strong>in</strong>sertion sort,<br />

<strong>and</strong> show that <strong>in</strong>sertion-sort runs <strong>in</strong> Ω(n 2 ) time on such a sequence.<br />

R-8.8<br />

At which nodes of a heap can an entry with the largest key be stored?<br />

R-8.9<br />

In def<strong>in</strong><strong>in</strong>g the relation "to the left of" for two nodes of a b<strong>in</strong>ary tree (Sec tion<br />

8.3.1), can we use a preorder traversal <strong>in</strong>stead of an <strong>in</strong>order traversal? How<br />

about a postorder traversal?<br />

R-8.10<br />

Illustrate the execution of the heap-sort algorithm on the follow<strong>in</strong>g <strong>in</strong>put<br />

sequence: (2,5,16,4,10,23,39,18,26,15).<br />

R-8.11<br />

Let T be a complete b<strong>in</strong>ary tree such that node v stores the entry (p(v), 0), where<br />

p(v) is the level number of v. Is tree T a heap? Why or why not?<br />

R-8.12<br />

Expla<strong>in</strong> why the case where node r has a right child but not a left child was not<br />

considered <strong>in</strong> the description of down-heap bubbl<strong>in</strong>g.<br />

R-8.13<br />

Is there a heap T stor<strong>in</strong>g seven entries with dist<strong>in</strong>ct keys such that a pre order<br />

traversal of T yields the entries of T <strong>in</strong> <strong>in</strong>creas<strong>in</strong>g or decreas<strong>in</strong>g order by key?<br />

How about an <strong>in</strong>order traversal? How about a postorder traversal? If so, give an<br />

example; if not, say why.<br />

R-8.14<br />

Let H be a heap stor<strong>in</strong>g 15 entries us<strong>in</strong>g the array-list representation of a<br />

complete b<strong>in</strong>ary tree. What is the sequence of <strong>in</strong>dices of the array list that are<br />

505

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

Saved successfully!

Ooh no, something went wrong!