Docsity

Algorithms and Data Structures - Assignment 1 Questions | CS 2420, Assignments of Computer Science

Toggle sidebar
bg1
CS 2420 - Written 1
Due September 10
1. Google the web and read about the Fibonacci number. Write down
one interesting fact that you didn’t know.
2. Prove Exercise 1.11.b (page 40) following the example in Section 1.2.5
(page 6).
3. Run the program w1.cpp on your computer. Measure its running times
T(n) in seconds using a stop-watch for increasing values of n. For the
values T(n) that are at least 10 seconds and at most 600 seconds, plot
log2T(n) versus n, then fit it with a straight line. Measure the slope
of the line. (You can plot either by hand or by Excel.)
4. Is the running time of the program w1.cpp exponential or polynomial
in n? Why? Suppose that Dr. Jiang has a super-computer that is
1000 times faster than your computer, and he wants to compute the
Fibonacci number for n= 100 with the program w1.cpp, how long
will it take?
5. Rewrite the function long fib(int n) in the program w1.cpp such
that its running time is linear in n.
1

Partial preview of the text

Download Algorithms and Data Structures - Assignment 1 Questions | CS 2420 and more Assignments Computer Science in PDF only on Docsity!

CS 2420 - Written 1 Due September 10

  1. Google the web and read about the Fibonacci number. Write down one interesting fact that you didn’t know.
  2. Prove Exercise 1.11.b (page 40) following the example in Section 1.2. (page 6).
  3. Run the program w1.cpp on your computer. Measure its running times T (n) in seconds using a stop-watch for increasing values of n. For the values T (n) that are at least 10 seconds and at most 600 seconds, plot log 2 T (n) versus n, then fit it with a straight line. Measure the slope of the line. (You can plot either by hand or by Excel.)
  4. Is the running time of the program w1.cpp exponential or polynomial in n? Why? Suppose that Dr. Jiang has a super-computer that is 1000 times faster than your computer, and he wants to compute the Fibonacci number for n = 100 with the program w1.cpp, how long will it take?
  5. Rewrite the function long fib(int n) in the program w1.cpp such that its running time is linear in n.