# exam2sol - COP 3502H – Honors Computer Science I Exam#2...

This preview shows pages 1–3. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: COP 3502H – Honors Computer Science I Exam #2 – 3/5/08 (Wednesday) Solutions 1) (12 pts) Determine whether each of the following assertions are true or false: a) ) ( 5 4 3 2 2 n n n Ω = +- TRUE (2 pts each...) b) ) ( lg 499 . n O n n = FALSE c) ) 4 ( 2 2 n n n n Θ = TRUE d) ) ( 10 3 n O n = TRUE e) ) (lg lg 2 100 n n Ω = FALSE f) ) 1 ( lg lg lg Θ = n n FALSE 2) (5 pts) What is the output of a preorder traversal of the following binary search tree? M / \ G P / \ / \ C L O Y / \ / \ B E R Z / \ / \ D F Q V / \ S W \ \ T X M, G, C, B, E, D, F, L, P, O, Y, R, Q, V, S, T, W, X, Z Grading: 1 pt off for each error, up to 5. 3) (15 pts) What is the run-time (Big-Oh) in terms of n of the following code segments? (Assume all variables have been previously declared as integers.) a) sum = 0; for (i=0; i<n; i++) { for (j=0; j<i; j++) { if (j > i) sum++; } } Although the if statement never runs, j<i and j++ run on the order of n 2 times. O(n 2 ) Grading: 1 pt for answer, 4 pts for justification b) sum = 0; while (n > 0) { for (i=0; i<n; i++) sum++; n = n/2; } The for loop runs n times, then n/2, then n/4, etc. This sum is bounded by an infinite geometric series with a sum of 2n....
View Full Document

{[ snackBarMessage ]}

### Page1 / 7

exam2sol - COP 3502H – Honors Computer Science I Exam#2...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online