This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Key[SearchCost]: 3 5 7 9 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
- Winter '09
- search cost, average search cost