Time Left - 15:00 mins

GATE 2024 algorithm Rank Booster Quiz 21

Attempt now to get your rank among 38 students!

Question 1

Consider the following recursive function:

int Fun (int array [], int n)

{

           int S=0;

           if(n==0)

           return 0;

           S=Fun (array,n - 1)      

           if (array[n – 1]<=0)

           S=S+100

           return S;

}

What is the worst case time complexity of the above function?

Question 2

Consider a function f(n) defined recursively as f(n) =  f(n-1) + f(n-2). The space complexity for the runtime stack called implicitly for the calculation of f(n) is ?

Question 3

int get (int n)

{

if (n<=0)

return;

get (n - 1);

get (n - 3);

printf ("%d", n);

}

If T(n) = Number of functions calls for get(n) then which of the following is recurrence equation of T(n), for n > 0?

Question 4

Consider an array of n elements with sorted order, if any element i appears more than half the number of element, what is the time complexity to count the number of occurrences of i?

Question 5

Consider the following functions:

f(n) = 2log2n

g(n) = nlog2n

h(n) = n1/log2n

Which of the following statements about the asymptotic behavior of f(n), g(n) and h(n) is true?

Question 6

Consider the following code :
main()
{
for(i=1 ;i<=n; i= 20*i)
 {
for(j=1 j<=n; j++)
  {
if(n%j==0)
   {
k=1
while(k<=n)
    {
a=b+c;
k=k+1;
    }
   }
  }
 }
}
Assuming "n" to be a prime number , find the Time Complexity of the code?

Question 7

The running time of an algorithm is represented by the following recurrence relation:

if n <= 3 then T(n) = n

else T(n) = T(n/3) + cn

Which one of the following represents the time complexity of the algorithm?

  • 38 attempts
  • 0 upvotes
  • 0 comments
Dec 4GATE & PSU CS