You are on page 1of 14

1.

Find the value of T (n) =9T (n/3) +n

a. Θ (n)

b. Θ (n^2)

c. Θ (n^3)

d. None of the above


Answer:

2. For the function f (n) =7n + 5. Find out the order of this function in Big theta notation.
a. θ (n^2)
b. θ (n)
c. θ (n^3)

d. All of the above

Answer: b

3. The master method does not apply to the-

a. Recurrence
b. Iteration
c. Substitution method
d. All of the above

Answer: b. Iteration

4. What is the value of T (n) =T (n/2) +1.


a. Θ (log1)
b. Θ (logn)
c. Θ (log2n)

d. All of the above

Answer: b. Θ (logn)
6. Decide whether these statements are True or False.

If f(n) = Θ(g(n)) and g(n) = Θ(h(n)), then h(n) = Θ(f(n))

Answer: True (Θ is transitive)

7. If f(n) = O(g(n)) and g(n) = O(h(n)), then h(n) = Ω(f(n))

Answer: True. O is transitive, and h(n) = Ω(f(n)) is the same as f(n) = O(h(n))

8. If f(n) = O(g(n)) and g(n) = O(f(n)) then f(n) = g(n)

Answer: False: f(n) = n and g(n) = n + 1

9. n* 100 = Ω(n)

Answer: True. n 100 < c ∗ n for c = 1 200 .

10. f(n) = Θ(n2 ), where f(n) is defined to be the running time of the program A(n):

def A(n): a tuple = tuple(range(0, n)) # a tuple is an immutable version of a

# list, so we can hash it

S = set()

for i in range(0, n):

for j in range(i+1, n):

S.add(atuple[i:j]) # add tuple (i,...,j-1) to set S

Answer: False:

Inside the two for loops, both slicing and hashing take linear time.

11. Write a recurrence for the running time T(n) of f(n). Assume that addition can be done in
constant time.
def f(n):

if n == 1:

return 1

else:

return f(n-1)+f(n-1)

Answer: T(n) = T(n − 1) + T(n − 1) + Θ(1)

If you draw the recurrence tree, in has n levels, where the amount of work done at each of the
levels is 1+2+22+· · ·+2n−1 = Θ(2n )

12. Write a recurrence for the running time of g(n). Assume that addition can be done in constant
time.

def g(n):

if n == 1:

return 1

else:

x = g(n-1)

return x+x

Answer: T(n) = T(n − 1) + Θ(1).

The recurrence tree is just a linked list, were the amount of work done at each level is Θ(1) for a
total of Θ(n) work.

13. Rank these functions according to their growth, from slowest growing (at the top) to fastest
growing (at the bottom).

3n, 3n2 , 2n , (3/2)n, 1000, 1, 2n3

Answer: 1,1000, (3/2)n, 3n, 3n2, 2n3, 2n


14.Rank these functions according to their growth, from slowest growing to fastest growing.

64, 6n3 , 8n2 , 4n, Log8n, Log2n, N Log2n, N Log6n

Answer: 64, Log8n, 4n, N Log2n, N Log6n, 8n2, 6n3

15. Match each function with an equivalent function, in terms of their Θ. Only match a function
if f(n) = Θ(g(n)).

f(n) g(n)

n+30 n^2 + 3n

n2 +2n -10 log2 2x

n3 *3n 3n-1

log2 2x n4

Answer:

n+30 3n-1

n2 +2n -10 n^2 + 3n

n3 *3n n4

log2 2x log2 2x

16. Teams qualified for the 2014 World Cup. If the names of the teams were arranged in sorted
order (an array), how many items in the array would binary search have to examine to find the
location of a particular team in the array, in the worst case?

a. At most 1

b. At most 16

c. At most 6

d. At most 32

Answer: c. At most 6

17. What is lg(32), the base-2 logarithm of 32?

a. 5
b. 32

c. 16

d. 1

Answer: 5

18. In 2013, there were 193 member states in the United Nations. If the names of these states were
sorted alphabetically in an array, about how many names would binary search examine to locate a
particular name in the array, in the worst case?

a. No more than 4

b. No more than 9

c. No more than 64

d. No more than 128

Answer: No more than 9

19. The 2014 "Catalogue of Life" contains about 1580000 names of species. If these names were sorted in an
array, in the worst case, how long would it take to use binary search to find the name of a particular species in
the array?

a. At most, it would look at 6 names

b. At most, it would look at 1580000 names

c. At most, it would look at 790000 names

d. At most, it would look at 22 names

Answer: At most, it would look at 22 names

20. You have an array containing the prime numbers from 2 to 311 in sorted order:[2, 3, 5, 7,
11, 13, ..., 307, 311]. There are 64 items in the array. About how many items of the array
would binary search have to examine before concluding that 52 is not in the array, and therefore not
prime?

a. 11

b. 7

c. 22

d. 32
Answer: 7

21. Say True or False

n 2 = O(n3 + n4 ) // Big Oh

Answer: True

22. Say True or False

n 2 = o(n3 – n 2 ) // Small Oh

Answer: True

23. n log n = O(n1.1 log (log n)) // Big Oh

Answer: True

24. n log n = o(n1.1 log (log n)) // Small Oh

Answer: True

25. log (n!) = O(n log n) // Big Oh

Answer: True

27. The asymptotic notation for defining the average time complexity is
(a) Equivalence
(b) Symmetric
(c) Reflexive
(d) Transitive
(e) Both (c) and (d) above.

Answer : (a)
Reason : This is a theta notation which is Reflexive, Symmetric and Transitive and
hence it is an Equivalence relation.

28. What do you call the selected keys in the quick sort method?
(a)  Outer key
(b)  Inner Key      
(c)  Partition key
(d)  Pivot key

(e)  Recombine key.

Answer : (d)
Reason:  As in quick sort the division is made at an element which is pivotal element.

29. The time complexity of the normal quick sort, randomized quick sort algorithms in
the worst case is
(a)  O(n2), O(n log n)                 
(b)  O(n2), O(n2)
(c)  O(n log n), O(n2)   
(d)  O(n log n), O(n log n)
(e)  O(n log n), O(n2 log n).

Answer : (b)

Reason:  Because, there is no difference between normal quick sort and randomized quick sort
algorithms for their efficiency, except the picking of a pivotal element.

30. Let there be an array of length ‘N’, and the selection sort algorithm is used to
sort it, how many times a swap function is called to complete the execution?
(a)  N log N times 
(b)  log N times
(c)  N2 times
(d)  N-1 times  
(e)  N times
Answer : (d)

Reason:  Because, every time we swap the i th smallest element with the i th position. And we do this for i=1
to n-1 times.

31. The Sorting method which is used for external sort is


(a)  Bubble sort 
(b)  Quick sort 
(c)  Merge sort
(d)  Radix sort  
(e)  Selection sort
Answer : (c)

Reason:  As Merge sort is the only one from the given sorting techniques which is used for the external
sorting.

32. Recursive algorithms are based on


(a)  Divide and conquer approach     
(b)  Top-down approach
(c)  Bottom-up approach
(d)  Hierarchical approach                      
(e)  Heuristic approach.
Answer : (b)

Reason:  As in case of recursions the ARIs are created, and the recursive  function is called by other
function first, then it calls itself util a condition is met.

33. For defining the best time complexity, let f (n) = log n and g (n) = √n,
_________
(a)   f (n) Ω(g(n)), but g(n)  Ω (f(n))              
(b) f (n) Ω(g(n)), but g(n) Ω (f(n))
(c)   f (n) Ω(g(n)), and g(n)  Ω (f(n))
(d) f (n) Ω(g(n)), and g(n) Ω (f(n))
(e)   Can’t be defined for best case
Answer : (b)

Reason : According to the limit rule for the omega notation ( Using the duality rule )

34. For the following two statements, choose the correct answer.
I.     n2O(n3).
II.     n = θ ((n+1)!).

(a)   (I) and (II) are TRUE


(b)   (I), (II) are FALSE
(c)   (I) is FALSE, but (II) is TRUE
(d)   (I) is TRUE and (II) is FALSE
(e)   (I) is TRUE but (II) can’t be defined
Answer : (d)

Reason : According to the limit rule for the big Oh notation and the theta notation

35. For analyzing an algorithm, which is better computing time?


(a)   O (100 Log N)  
(b) O (N)
(c)   O (2N)                                            
(d) O (N log N)                                       
(e)  O (N2).
Answer : (a)

Reason : As this is a very small value when compared with all the other values.

36. Let f, t: N→R  0, and t (n) O (f (n)) iff  t(n) ≤  c. f (n) where c is positive real
constant and  n ≥  no, then no is ___________
(a)   Upper bound                                 
(b) Lower bound
(c)   Duality value                                  

(d) Threshold value                     

(e) Maximum value.

Answer : (d)

Reason : According to the mathematical definition of the big Oh notation, this is the Threshold value
defines the upper limit on the size of the instance.

37. For the bubble sort algorithm, what is the time complexity of the best/worst case?
(assume that the computation stops as soon as no more swaps in one pass)
(a) best case: O(n)      worst case: O(n*n)
(b) best case: O(n)      worst case: O(n*log(n))
(c) best case: O(n*log(n)) worst case: O(n*log(n))
(d) best case: O(n*log(n)) worst case: O(n*n)
(e) best case: O( 1)     worst case: O( n )

Answer : (a)
Reason:  Best Case is the one in which it is already sorted, and hence it takes O(n) time, otherwise it
takes O(n2) time

38. For the quick sort algorithm, what is the time complexity of the best/worst
case?
(a) best case: O(n)      worst case: O(n*n)
(b) best case: O(n)      worst case: O(n*log(n))
(c) best case: O(n*log(n)) worst case: O(n*log(n))
(d) best case: O(n*log(n)) worst case: O(n*n)
(e) best case: O(n*log(n)) worst case: O(n*n*n)

Answer : (d)

Reason:  The worst case here is, if the list is already sorted in descending order and we want to sort it in
ascending order. In this case it takes O(n2) time. Otherwise it takes O( n * log(n) ) time

39. The time complexity of binary search in best, worst cases for an array of size N is
(a) N, N2
(b) 1, Log N
(c) Log N, N2
(d) 1, N log N
(e) N, N

Answer : (b)

Reason:  Best case is; if the element to search is there at mid of he list. Worst case is; if the element we
are searching is either not there in the list or at the beginning of the list or end of the list

40. The mathematical definition for Omega can be defined as, provided
f,g:NR+ and c is a positive constant and n > n0,
(a) f(n) ≥ c. g(n)  n
(b) f(n) = c. g(n)  n
(c) f(n) ≥ c + g(n)  n
(d) f(n) = c + g(n)  n
(e) f(n) =  g(n)  n

Answer : (a)
Reason:  According to the mathematical definition of the Asymptotic notations

41. The  notation is
(a) Symmetric
(b) Reflexive
(c) Transitive
(d) Both (b) and (c) above
(e) (a), (b) and (c) above
Answer : (e)

Reason:  Because  notation is equivalence relationship in nature

42. Identify the name of the sorting in which time is not proportional to n 2.
(a) Selection sort
(b) Bubble sort
(c) Qucik sort
(d) Merge sort
(e) Insertion sort
Answer : (d)

Reason:  Merge Sort is a sort  in which time is not proportional to n2.

43. Find the correct sequence for the Big Oh values for all n > 2
(a) O(1) < O( n) < O( log n) < O(n log n) < O(n2) < O(n3) < O(2n)
(b) O(1) < O(log n) < O(n) < O(n log n) < O(n2) < O(2n) < O(n3)
(c) O(1) < O(log n) < O(n) < O(n log n) < O(n2) < O(n3) < O(2n)
(d) O(1) < O(n) < O(log n) < O(n log n) < O(n2) < O(2n) < O(n3)
(e) O(1) < O(log n) < O(n) < O(n2) < O(n log n) < O(n3) < O(2n)
Answer : (c)
Reason  :       O(1) < O(log n) < O(n) < O(n log n) < O(n2) < O(n3) < O(2n)
44. Which of the following is the correct big-O expression for 1 + 2 + 3 + ... + n?
(a) O(log n)
(b) O(n)
(c) O(n log n)
(d) O(n²)
(e) O(2n)
Answer : (d)
Reason  :       O(n²)

45. Worst case efficiency of binary search is


(a) log2 n + 1
(b) n
(c) N2
(d) 2n
(e) log n
Answer : (a)
Reason  :       log2 n+1

46. Worst case efficiency of which search is O(n)?


(a) Sequential search
(b) Binary search
(c) Indexed search
(d) Hashing
(e) Depth first search
Answer : (a)
Reason  :       Sequential search

47. Which of the following formulas in Omega notation best represent the expression n²+35n+6?

(a)  Ω (n³)                (b)  Ω (n²)                (c)  Ω (n)                 (d)  Ω (35)               (e)  Ω (6)

Answer : (b)
Reason:  As the given expression is a quadratic equation of degree 2, then by ignoring the constants and
lower order terms, the highest term is n2, and hence it is Ω(n2)
48. What term is used to describe an O(n) algorithm?

(a)  Constant                                          (b)  Non Polynomial Deterministic          


(c)  Logarithmic                                      (d)  Quadratic                                        (e)  Linear
Answer : (e)
Reason:  Because it is a single term of degree one. And all the remaining options are wrong

49. Express the formula (n - 2)*(n - 4) using θ notation:

(a)  θ (n2)                 (b)  θ (8)                  (c)  θ (log n)            (d)  θ (n)                  (e)  θ (1)
Answer : (a)
Reason:  Again this is a polynomial of degree 2 i.e. n2 – 6n + 8.

50. When we say an algorithm has a time complexity of O (n), what does it mean?

(a)   The algorithm has ‘n’ nested loops


(b)   The computation time taken by the algorithm is proportional to n
(c)   The algorithm is ‘n’ times slower than a standard algorithm
(d)   There are ‘n’ number of statements in the algorithm
(e)   The computation time taken by the algorithm is less than ‘n’ seconds
Answer : (b)

Reason:  As all the other options are meaning less and are wrong.

51. Can we read a data item at any location of a list within a constant time (i.e. O(1))?

(a)   Yes
(b)   Yes, only if the list is implemented by pointers (i.e. linked-list)
(c)   Yes, only if the list is implemented by an array
(d)   No, we need O(n) computation steps no matter what kind of implementation is used
(e)   No, as constant time is not possible for algorithm
Answer : (c)

Reason:  For an array implementation, we can find the given location straightway with the index value and
hence it takes constant time. But for a linked list, we have to follow the pointers one by one. The cost of
this is proportional to the size of the list
52. Sequential search has a time complexity of O(n), and binary search has a time complexity ofO(log(n)).
What difference will it make when the size n is 1000?

(a)   You would not notice much difference because computers run very fast anyway
(b)   As n is 1000, binary search is twice as fast as sequential search
(c)   As n is 1000, binary search is 10 times as fast as sequential search
(d)   As n is 1000, binary search is 10 times as slow as sequential search
(e)   As n is 1000, binary search is 100 times as fast as sequential search
Answer : (e)
Reason:  log(1024) = 10,  1000/log(1000) is roughly equal to 1000/10 = 100

53. Read the following statements carefully, and choose the correct answer.

I.     The Ω notation is Anti Symmetric.


II.     The big Oh notation is Semi Equivalence.
(a)  (I) is FALSE but (II) is TRUE              (b)  Both (I), (II) are TRUE
(c)  (I) is TRUE but (II) is FALSE              (d)  Both (I), (II) are FALSE
(e)  (II) is TRUE and (I) cannot be defined
Answer : (b)

Reason:  According to the definitions of Omega, Big Oh notations

You might also like