2c03-review - 00016

2c03-review - 00016 - celltype; begin p:=A; q:=B; while...

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

View Full Document Right Arrow Icon
1 Solutions to the Midterm Test 1. a. f(n) = O(n 3 ), g(n)=O(nlogn). Note, log5n =log5 +logn =O(logn) b. f(n)+g(n) = O(max(f(n), g(n)) =O(n 3 ) c. f(n)g(n) =O(n 4 logn), since n 3 *nlogn= n 4 logn 2. a. O(|A||B|), we have to compare each element of one set with each element of another set. b. O(|A||B|), since the lists are unsorted, the fact that set is ordered does not help. The procedure is the same as for 2a. c. EQUAL(A,B:list): bollean var p,q:
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: celltype; begin p:=A; q:=B; while (p<>nil and q<>nil) do begin if p .next .element<>q .next .element then return (false) p:=p .next, q:=q .next end if (p<>nil or q<>nil) return(false); return(true) end Time complexity is O(min(|A|, |B|)) 3. a. code length Probabilities a 10 2 0.3 0.6 b 11 2 0.3 0.6 c 01 2 0.2 0.4 d 000 3 0.15 0.45 e 001 3 0.05 0.15 average length : 2.2...
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