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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
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

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 Right Arrow Icon
Ask a homework question - tutors are online