Question 1
What is time complexity of fun()?
int fun(int n)
{
int count = 0;
for (int i = n; i > 0; i /= 2)
for (int j = 0; j < i; j++)
count += 1;
return count;
}
Question 2
What is the time complexity of fun()?
int fun(int n)
{
int count = 0;
for (int i = 0; i < n; i++)
for (int j = i; j > 0; j--)
count = count + 1;
return count;
}
Question 3
The recurrence relation capturing the optimal time of the Tower of Hanoi problem with n discs is. (GATE CS 2012)
Question 4
O( n2 ) is the worst case time complexity, so among the given options it can represent :-
Question 5
Which of the given options provides the increasing order of asymptotic complexity of functions f1, f2, f3, and f4?
f1(n) = 2n f2(n) = n(3/2) f3(n) = n*log(n) f4(n) = nlog(n)
Question 6
What is the time complexity of the below function?
void fun(int n, int arr[])
{
int i = 0, j = 0;
for (; i < n; ++i)
while (j < n && arr[i] < arr[j])
j++;
}
Question 7
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:
A) for(i = 0; i < n; i++)
B) for(i = 0; i < n; i += 2)
C) for(i = 1; i < n; i *= 2)
D) for(i = n; i <= n; i /= 2)
If n is the size of input(positive), which function is most efficient(if the task to be performed is not an issue)?
Question 8
What does it mean when we say that an algorithm X is asymptotically more efficient than Y?
Question 9
Consider the following functions:
f(n) = 2n g(n) = n! h(n) = nlog(n)
Which 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) = [Tex]\\Omega [/Tex](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) = [Tex]\\Omega [/Tex](f(n))
Question 10
In the following C function, let n >= m.
int gcd(n, m)
{
if (n % m == 0)
return m;
n = n % m;
return gcd(m, n);
}
How many recursive calls are made by this function?
(A) [Tex]\\theta [/Tex](log(n))
(B) [Tex]\\Omega [/Tex](n)
(C) [Tex]\\theta [/Tex](log(log(n)))
(D) [Tex]\\theta [/Tex](sqrt(n))
There are 118 questions to complete.