2c03-review - 00020

2c03-review - 00020 - b.[10] type List = record elements:...

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

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

Unformatted text preview: b.[10] type List = record elements: array[1..maxlength] of elementtype; last: integer; end; procedure ERASE_DUPLICANTS(L: List); var p,q: integer; begin p:=1; while p<>(L.last + 1) do begin q:=p+1; while q<>(L.last +1) do if L.elements[q]= L.elements[p] then while q<>(L.last +1) do begin L.elements[q]:= L.elements[q+1] L.last:=L.last-1 end else q:= q+1 p:=p+1 end end (1) O(n2). It looks like 3 nested loops, so O(n3). 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(n2). 3. [10] 0 0.6 0 0.2 0 0.12 0 0.04 f Char a b c d e f 1 0.08 e 1 0.4 1 a 0.08 d 0 0.2 c 1.0 1 0.4 1 0.2 b code 01 11 10 001 0001 0000 length 2 2 2 3 4 4 probability 0.4 0.2 0.2 0.08 0.08 0.04 average length 0.8 0.4 0.4 0.24 0.32 0.16 2 ...
View Full Document

Ask a homework question - tutors are online