Escolar Documentos
Profissional Documentos
Cultura Documentos
ossische
Technische Hochschule
Z
urich
Institut f
ur Theoretische Informatik
Peter Widmayer
Tobias Proger
Thomas Tschager
Exercise Sheet 1
FS 15
There is a definition of the O notation that is different from the one given at the lecture. Namely,
for a function g : N R+ , let
O(g) := {f : N R+ | c R+ , n0 N n n0 : f (n) cg(n)}.
(1)
(2)
A function f grows asymptotically like g when f O(g) and f (g). We denote this by
f (g), or as f = (g).
For these exercises, you can choose to use the definition given at the lecture, or use the above
definition.
Exercise 1.1
Give a definition of the set (g) as compactly as possible (i.e., with the fewest possible parameters and quantifiers), analogously to the above definitions for the sets O(g) and (g).
Exercise 1.2
Sort the following functions from left to right such that: if function f is on the left of g, then
f O(g).
Example: the functions n3 , n7 , n9 are already in the right order since n3 O(n7 ) and n7 O(n9 ).
2n
n
1
11
n
7
n
log(n ), 2 , n!, n , 15 , n, 2 , log(n!),
, , log8 (n)
n
2
n
Please turn over.
Exercise 1.4
Programming Exercise.
if n = 0
A
Rn = B
if n = 1 ,
For every test instance, we want to output a single line containing only the value Ri .
Example
Input:
2
20 0 1 1 1
22 5 10 1 -1
Output:
6765
-10
Notes
1) The values Ri can be very large. You should use the data type long instead of int.
2) To read an input from the console you can import the class java.util.Scanner and use
the following code fragment:
Scanner in = new Scanner(System.in);
int value1 = in.nextInt();
int value2 = in.nextInt();