MCQ1 mark
Consider the following functions, where is a positive integer.
Which one of the following options lists the functions in increasing order of asymptotic growth rate?
*Note*: Assume the base of log to be 2.
Single correct
GATE CSE previous year questions · Algorithms
Single correct
Single correct
Single correct
One or more correct
Answer key coming soon
Function 1 Function 2
while n > 1 do for i = 1 to 100 * n do
for i = 1 to n do x = x + 1;
x = x + 1; end for
end for
n = floor(n/2);
end while
Let and denote the number of times the statement "x = x + 1" is executed in Function 1 and Function 2, respectively.
Which of the following statements is/are TRUE?One or more correct
Answer key coming soon
Single correct
Answer key coming soon
Single correct
Answer key coming soon
Single correct
Answer key coming soon
Single correct
unsigned long int fun(unsigned long int n){
unsigned long int i, j = 0, sum = 0;
for (i = n; i > 1; i = i/2) j++;
for ( ; j > 1; j = j/2) sum++;
return(sum);
}
The value returned when we call fun with the input isSingle correct
Single correct
Answer key coming soon
Algorithm Time complexity
(P) Towers of Hanoi with n disks (i) Θ(n²)
(Q) Binary search given n sorted numbers (ii) Θ(n log n)
(R) Heap sort given n numbers at the (iii) Θ(2ⁿ)
worst case
(S) Addition of two n × n matrices (iv) Θ(log n)Single correct
Answer key coming soon
int fun(int n) {
int i, j;
for(i = 1; i <= n; i++) {
for(j = 1; j < n; j += i) {
printf(" %d %d",i,j);
}
}
}
Time complexity of fun in terms of notation isSingle correct
Answer key coming soon
int fun1 (int n){
int i,j,k,p,q=0;
for (i=1; i<n; ++i) {
p=0;
for (j=n; j>1; j=j/2)
++p;
for (k=1; k<p; k=k*2)
++q;
}
return q;
}
Which one of the following most closely approximates the return value of the function fun1?Single correct
Single correct
Single correct
Single correct
D = 2
for i = 1 to n do
for j = i to n do
for k = j + 1 to n do
D = D * 3Single correct
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);
}
The return value of the function isSingle correct
Answer key coming soon
MultiDequeue(Q){
m = k
while (Q is not empty) and (m > 0) {
Dequeue(Q)
m = m - 1
}
}
What is the worst case time complexity of a sequence of queue operations on an initially empty queue?Single correct
Answer key coming soon