DAA Sheet04
DAA Sheet04
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)
c. t (n) n2 n 1
d. t (n) 5log(n)
b. t (n) n 2 1000
c. t (n) n log(n)
d. t (n) n4 / 2
e. t (n) 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).
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.
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