This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full 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 redblack tree with blackheight 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 14, 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
 Fall '09
 Zera

Click to edit the document details