CLO3 Exercises CLO3 With Answers
CLO3 Exercises CLO3 With Answers
CLO3 Exercises CLO3 With Answers
a) Count the number of operations of the Power algorithm and write the result
using an algebraic expression in terms of n.
F(n) = 3n + 3
ii) n=100 ?
total = 3*100 + 3 = 303
CLO3 -Algorithm Analysis
2. The following algorithm implementation finds the largest word in an array of strings.
F(n) = 3n + 4
Number of operation = 3 * 7 + 4 = 21+4 = 25
3. Study the following algorithm and answer the question that follows:
a. Count the number of operations in the Summation algorithm for n=10 and n=100
F(n) = 2n+3
n=10 ? = 2*10 +3 = 23
n=100 ? = 2*100 +3 = 203
b. Write down an equation for the number of operations as a function for an array of n
values.
F(n) = 2n+3
4. Study the following Linear search algorithm and answer the questions that follow:
a. Count the number of operation in the Linear Search algorithm for n=10 and n=100.
n=10 21
n=100 201
b. Write down an equation for the number of operations as a function of the size of the
array or n. f(n) = 2n+1
5. Let f(x)=x2 and g(x)=x3 Construct a table to help you answer the following questions
a) For what integer k, will g(x) > f(x) for all x > k ?
X f(x)=5x + 1 g(x)= x2 +1
1 6 2
2 11 5
3 16 10
4 21 17
5 26 26
6 31 37
? k>= 6
b) Is f(x), Ω(g(x))
Asymptotic Analysis notation ( big O, big Ω, big ϴ)
F(x) >= g(x) for k big O
True, F(x) >= g(x) for all k <= 5
F(x) <= g(x) for a K , big Ω
True, F(x) <= g(x) for all k >5
7. Let f(x) = x2 + 2 and g(x) = x2 , using a table of values check if f(x) is ϴ (g(x)).
When c=1
f(x) >= g(x) , where k>=1
So that f(x) big Ω (g(x))
When c=2
f(x) <= g(x) , where k>1
So that f(x) big O (g(x))
è Therefore, f(x) is ϴ (g(x)).