{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

sol-quiz2 - CMPT 307 Solutions to Midterm#2[3 1 True or...

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

View Full Document Right Arrow Icon
CMPT 307 Solutions to Midterm #2 November 13, 2008 1. True or False? (Below, Pr [ X ] stands for the probability of an event X .) [3] (a) For any random events A and B , Pr [ A & B ] = Pr [ A ] · Pr [ B | A ]. (b) For any random events A 1 , A 2 , . . . , A n , Pr [ A 1 A 2 ∨ · · · ∨ A n ] = n i =1 Pr [ A i ]. (c) For independent random events A 1 , . . . , A n , n i =1 Pr [ A i ] 1. Solution: (a) and (c) are True; (b) is False. 2. Explain very briefly why any comparison-based sorting algorithm will take time at [5] least Ω( n log n ) to sort n items. Solution: There are n ! possible orderings of n elements. A correct comparison-based algorithm must be able to produce any one of these orderings. Viewing the comparison- based algorithm as a decision tree, this means that the tree has n ! leaves. But then it must have at least log( n !) = Θ( n log n ) height (= running time of the algorithm). 1
Background image of page 1

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

View Full Document Right Arrow Icon
3. Dynamic Programming (a) Recall the string matching problem from HW 3: Given n, m N and binary [20] strings s, t 1 , . . . , t m , where n is the length of s , decide whether s can be expressed
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}