This is an old revision of the document!


Lab 05 - Asymptotic notations

1. Asymptotic notations

1.1 If $ f \in O(n \sqrt n)$ and $ g \in Θ(n)$ then $ f \over g$ in ?

1.2 If $ f \in Θ(n)$ and $ g \in O(\sqrt n)$ then $ f \over g$ in ?

1.3 |$ Θ(n) - Θ(n)$ | in ?

2. Properties of asymptotic notations

2.1 Prove that if $ lim$ $ g(n) \over f(n) = 0$ implies that $ g(n) \in o(f(n))$ , for n reaching infinity. Hint: use the “epsilon” or “Cauchy” limit definition for sequences.

2.2 Prove that $ f(n) \in Ω(log(n))$ and $ g(n) \in O(n)$ implies $ f(n) \in Ω(log(g(n)))$ .

2.3 Prove that $ f(n) \in Ω(g(n))$ and $ g(n) \in O(n ^ 2)$ , then $ g(n) \over f(n)$ $ \in O(n)$ .

2.4 $ O(n) \cap Ω(n) = Θ(n)$ ?

2.5 $ O(n) = Θ(n) \cup o(n)$ ?

3. Execution time vs. Asymptotic growth

3.1 Install gnuplot.

3.2 Use the command set xrange [0:] to set the plotting interval to [0,infty).

Plot the function |$ sin(n)*n$ |, using the command: plot abs(sin(x)*x). abs stands for absolute value.

Use the command plot abs(sin(x)*x), 2*x to compare the two functions.

3.3 Write the following script file:

   ###########################
   # plotting script example
   ###########################
   
   reset
   set xrange [0:]
   
   f(x) = abs(sin(x)*x)
   g(x) = 2*x
   
   plot f(x),g(x)

and save it as “example.plot”.

Run gnuplot, and use the command load “example.plot” to run the script.

3.4 Add the following data file “data.dat” to the directory:

   1 2
   2 3
   3 4
   4 5
   5 6
   6 7
   7 8
   8 9

And modify the last command to:

plot “data.dat”,f(x),g(x)

3.5 Write a function which computes the greatest common divisor of two numbers.

3.6 What is the worst-case for the gcd algorithm?

3.7 Write a function which computes fibonacci numbers.

3.8 Start from the following code:

   from time import time
   
   
   l = [80000, 73201, 66003, 60000, 50000, 40000, 30000, 20000, 10000, 5000] 
   
   
   begin_time = time()
   #[test code]
   duration = time() - begin_time

and write a procedure which determines the running times for gcd, on the x-th and (x-1)th fibonacci numbers, from the list l.

The output of the script should be a list of values: a b

where a is the size of the input, expressed as a natural number and b is the running time for gcd.

For instance, for x = 10000, b will be the running time of gcd, on the 10000th and 9999th fibonacci number. a will be the SIZE of the input, i.e. the number of bits required to store the value $ fibo(x) + fibo(x+1)$ , rounded to a natural number