0% found this document useful (0 votes)
29 views

DAA Sheet04

The document contains 25 questions about analyzing the time complexity of algorithms using big-O notation. It asks the reader to determine the asymptotic growth rate of various functions, prove that functions fit certain asymptotic bounds, design algorithms within given time constraints, and more. The questions cover core concepts in algorithm analysis including best/worst-case complexity, orders of growth, and how they apply to problems like searching, sorting, and mathematical operations.

Uploaded by

omar magdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

DAA Sheet04

The document contains 25 questions about analyzing the time complexity of algorithms using big-O notation. It asks the reader to determine the asymptotic growth rate of various functions, prove that functions fit certain asymptotic bounds, design algorithms within given time constraints, and more. The questions cover core concepts in algorithm analysis including best/worst-case complexity, orders of growth, and how they apply to problems like searching, sorting, and mathematical operations.

Uploaded by

omar magdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Faculty of Computers & AI Benha University

1. Use the definitions of O, Θ, and Ω to determine whether the following assertions are true or
false for t (n)  n(n  1) / 2 .

a. t (n)  O (n3 )

b. t (n)  O(n2 )

c. t (n) (n3 )
d. t (n) (n)

2. Determine whether each of these functions is O(n).


a. t (n)  10
b. t (n)  3n  7

c. t (n)  n2  n  1
d. t (n)  5log(n)

3. Determine whether each of these functions is O(n2).


a. t (n)  17n  11

b. t (n)  n 2  1000
c. t (n)  n log(n)

d. t (n)  n4 / 2

e. t (n)  2n

4. Show that n4  9n3  4n  7 is O(n4).

5. Show that (n + 1)5 is O(n5).

6. Show that 2n+1 is O(2n).

7. Show that n is O(nlog n).

8. Show that (n log( n)  n 2 )3 is O(n6).

9. Show that 8n3  12n  100log(n) is O(n3).

10. Show that 2n is O(3n) but that 3n is not O(2n).

Page 1 of 3
Faculty of Computers & AI Benha University

11. Use the definition of big-O notation to prove or disprove that n2  18n  107 is O(n3).

12. Determine whether each of the functions log(n  1) and log( n 2  1) is O(log n).

13. Show that nlog(n) is Ω(n).

14. Show that n2 is Ω(nlog n).

15. Prove that n3  7n  2 is Ω(n3).

16. Let t (n)  3n2  8n  7 . Show that t (n) is Θ(n2).

17. Prove that 5n4  2n3  1 is Θ(n4).

18. Explain what it means for a function t(n) to be Θ(1).

19. Order the following functions by asymptotic growth rate.

n 1000log(n) n log(n) 2n! 2n1 3n n2 /1000000

20. Suppose that you have two different algorithms for solving a problem.
To solve a problem of size n, the first algorithm uses exactly nlog(n) operations and the second
algorithm uses exactly n2 operations.
As n grows, which algorithm uses fewer operations?

21. Suppose that you have two different algorithms for solving a problem.
To solve a problem of size n, the first algorithm uses exactly 2n operations and the second
algorithm uses exactly n! operations.
As n grows, which algorithm uses fewer operations?

22. Suppose that you have two different algorithms for solving a problem.
To solve a problem of size n, the first algorithm uses exactly n n operations and the second
algorithm uses exactly n 2 log( n) operations.
As n grows, which algorithm uses fewer operations?

Page 2 of 3
Faculty of Computers & AI Benha University

23. Find the best big-O notation to describe the complexity of the algorithm.
Choose your answers from the following:
O(1); O(log2(n)); O(n); O(nlog2(n)); O(n2); O(n3); O(2n); O(n!)
a. A linear search to find the smallest number in a list of n numbers.
b. A binary search of n elements.
c. The best-case analysis of a linear search of a list of size n.
d. The worst-case analysis of a linear search of a list of size n.
e. An iterative algorithm to compute n! , (counting the number of multiplications).
f. An algorithm that finds the average of n numbers by adding them and dividing by n.
g. The worst-case complexity of the insertion sort.
h. The definition-based algorithm for adding two n × n matrices.
i. The definition-based algorithm for matrix multiplication.
j. Finding the difference between the largest and smallest elements in a sorted array.

24. Consider the following algorithm.


ALGORITHM Mystery (n)
//Input: A nonnegative integer n
S←0
for i ←1 to n do
S←S+i∗i
return S
a. What does this algorithm compute?
b. What is its basic operation?
c. How many times is the basic operation executed?
d. What is the efficiency class of this algorithm?
e. Suggest an improvement, or a better algorithm, and indicate its efficiency class.

25. Design an algorithm for computing the value of a polynomial at a point x, which runs in time
that is at most O (n) in the worst case.
p ( x)  a0  a1 x  a2 x 2  a3 x 3  ...  an x n

Implement the algorithm using C++, and evaluate the polynomial 1  x  3x2 at x = 2.

Page 3 of 3

You might also like