2c03-review - 00001

# 2c03-review - 00001 - begin p:=L while p ↑.next<>nil...

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

1 SOLUTIONS TO THE MIDTERM TEST 1.[10] a.[5] 6n 3 /(log n + 1) = O(n 3 ) Let c=7, n 0 =2. For all n 2, log n 1, and log n +1 2 Then, 6n 3 /(log n +1) 6n 3 /2 = 3n 3 7n 3 hold. b.[5] 10n 3 +9 = O(n). We have to find such n’ (not necessarily the smallest one) that for every n n’ 10n 3 +9 > C*n. Note that if n C, then 10n 3 + 9 10Cn 2 + 9 C*n holds. 2.[20] a.[10] type celltype = record element: elementtype next: celltype end; procedure ERASE_DUPLICANTS(L: celltype); var p,q: celltype;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: begin p:=L; while p ↑ .next<>nil do begin q:=p ↑ .next; while q ↑ .next<>nil do if q ↑ .next.element=p ↑ .next.element then q ↑ .next:= q ↑ .next ↑ .next else q:= q ↑ .next; p:= p ↑ .next end end O(n 2 ), since 2 nested loops. 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...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online