CS 3343 Homework 3 - Fall 2006, Assignments of Algorithms and Programming

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

Pre 2010

Uploaded on 07/30/2009

koofers-user-9ia
koofers-user-9ia 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework 3
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.
1. (20 pts.) Indicate the order of growth (big theta) of the following sums.
(a)
n
X
i=1
1/i
(b)
n
X
i=1
log2i
(c)
n
X
i=1
i
(d)
n
X
i=1
ilog2i
(e)
n
X
i=1
i2
(f)
n
X
i=1
i3
(g)
n
X
i=1
i4
(h)
n
X
i=1
2i
(i)
n
X
i=1
i2i
(j)
n
X
i=1
i!
2. (20 pts.) Consider the following algorithm.
algorithm Mystery(A[0..n 1])
// Input: An array A
for i0to n1do
for j0to n1do
if A[i]6=A[j]then return false
return true
(a) What does this algorithm compute?
(b) What is its basic operation?
1
pf2

Partial preview of the text

Download CS 3343 Homework 3 - Fall 2006 and more Assignments Algorithms and Programming in PDF only on Docsity!

Homework 3

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.

  1. (20 pts.) Indicate the order of growth (big theta) of the following sums.

(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!

  1. (20 pts.) Consider the following algorithm.

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.

  1. (20 pts.) This is a variation of Exercise 2.4.7.

(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.

  1. (20 pts.) This is a variation of Exercise 2.5.3.

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.

  1. (20 pts.) Do Exercise 2.5.4. For further exercise, perform all the possible ways to climb a staircase on one of the stairways between the 3rd and 4th floor of the Science Building.