

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Homework assignments for cs 3343 class, taught by tom bylander, during the fall 2006 semester. The assignments include problems related to the order of growth of sums, an algorithm analysis, recursive algorithms to compute 2n, and finding the smallest fibonacci number that does not fit in various data types.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


CS 3343 – Fall 2006 assigned September 7, 2006 Tom Bylander, Instructor due September 15, 2006
Your solutions must be submitted as a document to WebCT.
(a)
∑^ n i=
1 /i
(b)
∑^ n i=
log 2 i
(c)
∑^ n i=
i
(d)
∑^ n i=
i log 2 i
(e)
∑^ n i=
i^2
(f)
∑^ n i=
i^3
(g)
∑^ n i=
i^4
(h)
∑^ n i=
2 i
(i)
∑^ n i=
i 2 i
(j)
∑^ n i=
i!
algorithm Mystery(A[0..n − 1]) // Input: An array A for i ← 0 to n − 1 do for j ← 0 to n − 1 do if A[i] 6 = A[j] then return false return true
(a) What does this algorithm compute? (b) What is its basic operation?
1
(c) How many times is the basic operation executed? (worst-case and best-case) (d) What is the efficiency class of this algorithm? (worst-case and best-case) (e) Provide an improvement that improves its worst-case efficiency class and indicate the new worst-case efficiency class.
(a) Provide pseudocode (in the book’s style) for two recursive algorithms that com- pute 2n^ for any integer n ≥ 0 based on the formula 2n^ = 2n−^1 + 2n−^1. One algorithm should have two recursive calls in the code and the other only one. (b) Draw a tree of recursive calls for each algorithm and use the tree to count the number of additions. (c) For both algorithms, set up and solve a recurrence relation for the number of additions made by the algorithm. (d) For each algorithm, comment on whether it is a good algorithm for solving this problem.
Find the smallest n for which the nth Fibonacci number does not fit in varables of type int, long, float, and double. For float and double, I want to know when the number cannot be represented exactly, i.e., when you start losing last digit.