2c03-review - 00021

2c03-review - 00021 - end procedure PrintPre(T:Tree, m:1....

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
3 Average code length 2 × 0.4 + 2 × 0.2 + 2 × 0.2 + 3 × 0.08 + 4 × 0.08 + 4 × 0.04 = 2.32 The optimal Hoffman code is not unique, however, the average length is unique. 4.[10] a. [6] Pat A b a b a a J 1 2 3 4 5 6 F(j) 0 0 1 2 3 1 b.[4] Same for standard algorithm and KMP. For instance x = abc, pat = ac. 5.[13] a.[10] type Tree = record labels: array[1. .max] of labeltype; n: 1. .max; end; procedure Preorder(T: Tree) begin PrintPre(T, 1)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: end procedure PrintPre(T:Tree, m:1. .max) begin if m>T.n then return; write(T.lables[m]); PrintPre(T, 2*m); PrintPre(T, 2*m+1) end b.[3] O(n). Since every node is visited only one time. 6.[10] The complete tree with 9 nodes is in this shape: a b c d e f g h i j The preorder is a, b, d, h, i, j, e, c, f, g 1, 2, 3, 4, 5,6, 7,8, 9, 10...
View Full Document

This note was uploaded on 12/10/2009 for the course CAS 2c03 taught by Professor Janicki during the Spring '03 term at McMaster University.

Ask a homework question - tutors are online