Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

CLO3 Exercises CLO3 With Answers

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

CLO3 Algorithm Analysis Worksheet- 2

1. The following algorithm calculates xn, where x is real and n is an integer:

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

b) What is the total number of operations when


i) n=10 and
total = 3 *10 + 3 = 33

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.

a. Count the number of Operations of the algorithm.

F(n) = 3n + 4
Number of operation = 3 * 7 + 4 = 21+4 = 25

b. What would be the time complexity of the algorithm?


TC: O(n)

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

CIS 2203 Page 2 of 5 ReviewedReviewed- 201930


CLO3 -Algorithm Analysis

b. Write down an equation for the number of operations as a function for an array of n
values.
F(n) = 2n+3

c. What is the time complexity of the Summation algorithm?


TC: O(n)

CIS 2203 Page 3 of 5 ReviewedReviewed- 201930


CLO3 -Algorithm Analysis

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

c. What is the time complexity of this algorithm? O(n)

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 ?

b) What is the time complexity of f(x) and g(x) ?

6. Let f(x)=5x + 1 and g(x)= x2 +1


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

CIS 2203 Page 4 of 5 ReviewedReviewed- 201930


CLO3 -Algorithm Analysis

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

If the function achived both big O, big Ω, the its big ϴ


Since the function is achieved both big O, big Ω, then its big ϴ

7. Let f(x) = x2 + 2 and g(x) = x2 , using a table of values check if f(x) is ϴ (g(x)).

8. X f(x) = x2 + 2 g(x) = x2 2 g(x)


c=1 c=2
1 (1)2+2= 3 (12)= 1 2(12)= 2
2 (2)2+2= 6 (22)= 4 2(22)= 8
3 (3)2+2= 11 (32)= 9 2(32)= 18
4 (4)2+2= 18 (42)= 16 2(42)= 32
5 (5)2+2= 27 (52)= 25 2(52)= 50
6 (6)2+2= 38 (62)= 36 2(62)= 72

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)).

CIS 2203 Page 5 of 5 ReviewedReviewed- 201930

You might also like