HW # 2 COP 3530 Spring 11 CISE Dept. UF
TAs for this assignment: Ravi, Ferhat
Instructor: Manu Sethi
Due: Mon, Jan 31, 2011
Instructions:
You have to submit the hardcopy of everything as well as submit all the programs online
via sakai. The hadcopies should be submitted to the instructor in the beginning of the class. Everything
should be typed or legible if handwritten. All the program numbers mentioned are available at the book’s
website, the link to which is mentioned in the top most line of the resources page. You need to write the
codes for
problems 1 and 6. You don’t need to write templatized codes for this assignment. Each of these
questions will have separate header files named hw2
prob1.h
and hw2
prob6.h.
However, there would be
only one makefile that should need to submit. This makefile would compile programs 1 and 6 both and
make a separate binary file for each. The name of the binaries will be:
hw2prob1
and
hw2prob6.
You
will also submit a textfile called
README
in which you can give any instructions to the TAs/graders.
This
README
file will be a text file but does not has any extension to it. No further deadline extensions
will be given this time.
1.
(Chapter 1, Q20, modified)
a.
Write a recursive function to compute Fibonacci number
g1832
g3041
.
b.
Show that your code for part (a) computes the same
g1832
g3036
more that once when it is invoked to
compute
g1832
g3041
for any
g1866
> 2.
c.
Write a non recursive function to compute the Fibonacci number
g1832
g3041
. Your code should
compute each Fibonacci number just once.
d.
Write a function main from which you will call both your functions. Call your functions to
compute the values of
g1832
g3041
for
g1866
=
10,20,30,g1853g1866g1856 40 g1872ℎg1870g1867g1873g1859ℎ 50
. Compare the time
differences in computing these Fibonacci numbers using both your functions. Report the
times in a table.
e.
In class we discussed that the Time complexity
g2286g4666g1866g4667
of calculating the
g1866
th
Fibonacci number
follows the same recursion as the recursion for obtaining the nth Fibonacci number itself.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview.
Sign up
to
access the rest of the document.
 Summer '08
 Davis
 Algorithms, Data Structures, Insertion Sort, Big O notation, Fibonacci number

Click to edit the document details