midterm_702_08_sol

midterm_702_08_sol - Solutions for CAS 702 Midterm 2007...

Info iconThis preview shows pages 1–2. 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: Solutions for CAS 702 Midterm 2007 Problem 1a Let k j and i j be the values of k and i respectively after state- ment i := i i is executed j times. Then we observe that i = 2 , k = 1 and i j = 2 2 j , k j = i 2 j = 2 2 j +1 . The loop ends when k j = 2 2 j +1 n , or j lg lg n- 1. So j = (lg lg n ). Problem 1b Consider a red-black tree with black-height k . If every node is black the total number of internal nodes is 2 k- 1. If only every other nodes is black we can construct a tree with 2 2 k- 1 nodes. Probelm 1c One of the counter example is making changes for 8 cents with coin denominations 1, 4 and 6. Problem 2a Loop invariant : At the start of each iteration of the for loop of lines 1-4, the subarray A [1 ..i- 1] consists of the i- 1 smallest values originally in A [1 ..n ], in sorted order, and A [ i..n ] consists of the n- i + 1 remaining values originally in A [1 ..n ]....
View Full Document

Page1 / 3

midterm_702_08_sol - Solutions for CAS 702 Midterm 2007...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online