2c03-review - 00002

2c03-review - 00002 - probability average length a 01 2 0.4...

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

View Full Document Right Arrow Icon
2 q:=p+1; while q<>(L.last +1) do if L.elements[q]= L.elements[p] then while q<>(L.last +1) do begin (1) L.elements[q]:= L.elements[q+1] L.last:=L.last-1 end else q:= q+1 p:=p+1 end end O(n 2 ). It looks like 3 nested loops, so O(n 3 ). By more careful investigation, we can see the while loop(1) is same as DELETE. Even there are two outer loops, DELETE can be executed at most n times, and DELETE itself is O(n). Therefore, O(n 2 ). 3. [10] 1.0 0 1 0.6 0.4 0 1 0 1 0.2 0.4 0.2 0.2 0 1 a c b 0.12 0.08 0 1 d 0.04 0.08 f e Char code length
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: probability average length a 01 2 0.4 0.8 b 11 2 0.2 0.4 c 10 2 0.2 0.4 d 001 3 0.08 0.24 e 0001 4 0.08 0.32 f 0000 4 0.04 0.16 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) 1 2 3 1 b.[4] Same for standard algorithm and KMP. For instance x = abc, pat = ac....
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