Java Python CMPSC 465
Data Structures & Algorithms
Spring 2024
Worksheet 2
1. Growth Rate. Sort the following expressions from slowest to fastest growth rate. (You may assume all logarithms have base 2.)
2. Find run time. How long does the recursive multiplication algorithm (given below) take to multiply a non-negative n-bit number by a non-negative m-bit number? Justify your answer.
Algorithm 1 multiply(x,y)
Input: An n-bit integer x and an m-bit integer y, where x, y ≥ 0
Output: Their product x · y
if y = 0 then
return 0
end if
z = multiply(x,⌊2/y⌋)
if y = even then
dai 写CMPSC 465 Data Structures & Algorithms Spring 2024 Worksheet 2Prolog return 2z
else
return x+2z
end if
3. Computing Factorials. Consider the problem of computing N! = 1×2×··· ×N.
1. If N is a b-bit number, how many bits long is N! (Θ notation suffices)?
2. Consider the simple algorithm to compute N! that does the multiplication in sequence, 1×2×3×...×N. Analyze its running time.
4. Fibonacci growth. The Fibonacci numbers F0, F1, F2 ... are defined by the recurrence F0 = 0, F1 = 1, and Fn = Fn−1 + Fn−2. In this problem, we will confirm that this sequence grows exponentially fast and obtain some bounds on its growth.
(a) Use induction to prove that Fn ≥ 2 0.5n for n ≥ 6.
(b) Find a constant c > 0 such that Fn ≥ 2cn for all n ≥ 3. Show that your answer is correct.
(c) Find the maximum constant c > 0 for which Fn = Ω(2cn)

616

被折叠的 条评论
为什么被折叠?



