221-13a-A4

# Key[searchcost 3[2 5[1 7[3 9[2 sum of the search cost

This preview shows pages 2–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Key[SearchCost]: 3[2] 5[1] 7[3] 9[2] Sum of the search cost over all the nodes in the tree is: 2+1+3+2 = 8. Average search cost: 8 / 4 = 2. Average search cost is 2 2 3. Download files containing integer data from the course website. (a) The files 1p.dat , 2p.dat , ..., 12p.dat contain 2 1 − 1, 2 2 − 1,..., and 2 12 − 1 integers respectively. The integers make 12 perfect binary trees where all leaves are at the same depth. Calculate and record the average search cost for each perfect binary tree. (b) The files 1r.dat , 2r.dat , ..., 12r.dat contain same number of integers as above. The integers are randomly ordered and make 12 random binary trees . Calculate and record the average search cost for each tree. (c) The files 1l.dat , 2l.dat , ..., 12l.dat contain same number of integers as above. The integers are in increasing order and make 12 linear binary trees . Calculate and record the average search cost for each tree. (d) Make a plot showing the average search cost (y-axis) versus the number of tree nodes (x-axis) of all perfect binary trees, random binary trees and linear binary trees. (e) Provide the output in the text format. The nodes will be printed according to their depth level. Missing nodes will be represented by the symbol X . A possible solution is to fill the missing nodes with fake nodes in the data structure when printing the tree. Example: 5 3 9 X X 7 X 4. Extra credit....
View Full Document

{[ snackBarMessage ]}

### Page2 / 3

Key[SearchCost 3[2 5[1 7[3 9[2 Sum of the search cost over...

This preview shows document pages 2 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online