What is time complexity of fun()?
Discuss it
What is the time complexity of fun()?
Discuss it
The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs is. (GATE CS 2012)
Discuss it
Let w(n) and A(n) denote respectively, the worst case and average case running time of an algorithm executed on an input of size n. which of the following is ALWAYS TRUE? (GATE CS 2012)
(A) (B) (C) (D)
Discuss it
Which of the following is not O(n^2)?
Discuss it
Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3 and f4?
f1(n) = 2^n f2(n) = n^(3/2) f3(n) = nLogn f4(n) = n^(Logn)
Discuss it
Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm
Discuss it
What is the time complexity of the below function?
Discuss it
In a competition, four different functions are observed. All the functions use a single for loop and within the for loop, same set of statements are executed. Consider the following for loops:
Discuss it
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
Discuss it
What is the time complexity of Floyd–Warshall algorithm to calculate all pair shortest path in a graph with n vertices?
Discuss it
Consider the following functions:
f(n) = 2^n g(n) = n! h(n) = n^lognWhich of the following statements about the asymptotic behavior of f(n), g(n), and h(n) is true? (A) f(n) = O(g(n)); g(n) = O(h(n)) (B) f(n) = (g(n)); g(n) = O(h(n)) (C) g(n) = O(f(n)); h(n) = O(f(n)) (D) h(n) = O(f(n)); g(n) = (f(n))
Discuss it
In the following C function, let n >= m.
(A) (logn) (B) (n) (C) (loglogn) (D) (sqrt(n))
Discuss it
Consider the following functions Which of the following is true? (GATE CS 2000)
(a) h(n) is 0(f(n)) (b) h(n) is 0(g(n)) (c) g(n) is not 0(f(n)) (d) f(n) is 0(g(n))
Discuss it
Consider the following three claims I (n + k)^m = (n^m), where k and m are constants II 2^(n + 1) = 0(2^n) III 2^(2n + 1) = 0(2^n) Which of these claims are correct? (GATE CS 2003)
Discuss it
Let s be a sorted array of n integers. Let t(n) denote the time taken for the most efficient algorithm to determined if there are two elements with sum less than 1000 in s. which of the following statements is true? (GATE CS 2000)
a) t (n) is 0 (1) b) n < t (n) < n c) n log 2 n < t (n) < d) t (n) =
Discuss it
Consider the following function
int unknown(int n) { int i, j, k = 0; for (i = n/2; i <= n; i++) for (j = 2; j <= n; j = j * 2) k = k + n/2; return k; }What is the returned value of the above function? (GATE CS 2013) (A) (B) (C) (D)
Discuss it
Consider the following two functions. What are time complexities of the functions?
Discuss it
Consider the following segment of C-code:
int j, n; j = 1; while (j <= n) j = j*2;The number of comparisons made in the execution of the loop for any n > 0 is: Base of Log is 2 in all options.
Discuss it
Consider the following C-program fragment in which i, j and n are integer variables.
Discuss it
The minimum number of comparisons required to find the minimum and the maximum of 100 numbers is _________________.
Discuss it
Consider the following pseudo code. What is the total number of multiplications to be performed?
D = 2 for i = 1 to n do for j = i to n do for k = j + 1 to n do D = D * 3
Discuss it
Consider the following C-function:
Discuss it
Consider the following C-function:
Discuss it
Two matrices M1 and M2 are to be stored in arrays A and B respectively. Each array can be stored either in row-major or column-major order in contiguous memory locations. The time complexity of an algorithm to compute M1 × M2 will be
Discuss it
The recurrence equation
T(1) = 1 T(n) = 2T(n - 1) + n, n ≥ 2evaluates to
Question 29
|
Consider the following three claims
1. (n + k)m = Θ(nm), where k and m are constants 2. 2n + 1 = O(2n) 3. 22n + 1 = O(2n)Which of these claims are correct ?
1 and 2
| |
1 and 3
| |
2 and 3
| |
1, 2, and 3
|
Question 30
|
f1(n); f4(n); f2(n); f3(n)
| |
f1(n); f2(n); f3(n); f4(n);
| |
f2(n); f1(n); f4(n); f3(n)
| |
f1(n); f2(n); f4(n); f3(n)
|
1. C
Question 1 Explanation:
For a input integer n, the innermost statement of fun() is executed following times. So time complexity T(n) can be written as T(n) = O(n + n/2 + n/4 + ... 1) = O(n) The value of count is also n + n/2 + n/4 + .. + 1
2. B
Question 2 Explanation:
The time complexity can be calculated by counting number of times the expression "count = count + 1;" is executed. The expression is executed 0 + 1 + 2 + 3 + 4 + .... + (n-1) times. Time complexity = Theta(0 + 1 + 2 + 3 + .. + n-1) = Theta (n*(n-1)/2) = Theta(n^2)
3.D
Question 3 Explanation:
Following are the steps to follow to solve Tower of Hanoi problem recursively.
Let the three pegs be A, B and C. The goal is to move n pegs from A to C. To move n discs from peg A to peg C: move n-1 discs from A to B. This leaves disc n alone on peg A move disc n from A to C move n?1 discs from B to C so they sit on disc nThe recurrence function T(n) for time complexity of the above recursive solution can be written as following. T(n) = 2T(n-1) + 1
4..C
Question 4 Explanation:
The worst case time complexity is always greater than or same as the average case time complexity.
5.C
Question 5 Explanation:
The order of growth of option c is n^2.5 which is higher than n^2.
6.A
7.A
good material
ReplyDeleteVery helpful
ReplyDeleteQ29) A
ReplyDelete