• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Top MCQs on Algorithms in DSA with Answers

Question 11

There are 25 horses among which you need to find out the fastest 3 horses. You can conduct race among at most 5 to find out their relative speed. At no point you can find out the actual speed of the horse in a race. Find out how many races are required to get the top 3 horses.
  • 5
  • 7
  • 8
  • 9

Question 12

Which of the following is the best possible time complexity to get Nth Fibonacci number with O(1) extra space
  • Time complexity T(n) is T(n-1) + T(n-2) which is exponential
  • O(n)
  • O(Logn)
  • O(n^2)

Question 13

You are given an array with even integer elements. You and some other player take turns to pick numbers. Each player can pick either the leftmost element or the rightmost number. Find the maximum possible score (sum of numbers chosen) by you. For example: if array is 5 8 4 2, then player you can choose either 5 or 2. Suppose you choose 2, then the other player can choose 5 or 4. Irrespective of what player 2 chooses, in next round you will have chance to choose 8. Thus, maximum possible score by player you, in this scenario, is (8+2)=10. This problem can efficiently solved using?
  • Greedy Algorithm
  • Dynamic Programming
  • Backtracking
  • Recursion.

Question 14

What is the return value of following function for 484? What does it to in general? C
bool fun(int n)
{
    int sum = 0;
    for (int odd = 1; n > sum; odd = odd+2)
       sum = sum + odd;
    return (n == sum);
}
  • False, it checks whether a given number is power of 3
  • False, it checks whether a given number is even or not
  • False, it checks whether a given number is odd or not
  • True, it checks whether a given number is perfect square.

Question 15

Consider the following C function in which size is the number of elements in the array E: The value returned by the function MyX is the C
int MyX(int *E, unsigned int size)
{
    int Y = 0;
    int Z;
    int i, j, k;
    for(i = 0; i < size; i++)
        Y = Y + E[i];
    for(i = 0; i < size; i++)
        for(j = i; j < size; j++)
        {
            Z = 0;
            for(k = i; k <= j; k++)
                Z = Z + E[k];
            if (Z > Y)
                Y = Z;
        }
    return Y;
}
  • maximum possible sum of elements in any sub-array of array E.
  • maximum element in any sub-array of array E.
  • sum of the maximum elements in all possible sub-arrays of array E
  • the sum of all the elements in the array E.

Question 16

Consider the expression tree shown. Each leaf represents a numerical value, which can either be 0 or 1. Over all possible choices of the values at the leaves, the maximum possible value of the expression represented by the tree is ___. GATECS2014Q38
  • 4
  • 6
  • 8
  • 10

Question 17

Suppose there are ⌈ log n ⌉ sorted lists of ⌊ n/log n ⌋ elements each. The time complexity of producing a sorted list of all these elements is : (Hint : Use a heap data structure)
  • O(n log log n)
  • θ(n log n)
  • Ω(n log n)
  • Ω(n3/2)

Question 18

We are given 9 tasks T1, T2.... T9. The execution of each task requires one unit of time. We can execute one task at a time. Each task Ti has a profit Pi and a deadline di Profit Pi is earned if the task is completed before the end of the dith unit of time.
Task     T1  T2	 T3  T4  T5  T6	 T7 T8  T9
Profit   15  20	 30  18  18  10	 23 16  25
Deadline 7   2 	 5   3 	 4   5 	 2  7   3 
Are all tasks completed in the schedule that gives maximum profit?
  • All tasks are completed
  • T1 and T6 are left out
  • T1 and T8 are left out
  • T4 and T6 are left out

Question 19

We are given 9 tasks T1, T2.... T9. The execution of each task requires one unit of time. We can execute one task at a time. Each task Ti has a profit Pi and a deadline di Profit Pi is earned if the task is completed before the end of the dith unit of time.
Task     T1  T2	 T3  T4  T5  T6	 T7 T8  T9
Profit   15  20	 30  18  18  10	 23 16  25
Deadline 7   2 	 5   3 	 4   5 	 2  7   3 
What is the maximum profit earned?
  • 147
  • 165
  • 167
  • 175

Question 20

Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm C
int n, rev;
rev = 0;
while (n > 0)
{
   rev = rev*10 + n%10;
   n = n/10;
}
The loop invariant condition at the end of the ith iteration is:
  • n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1
  • n = Dm-i+1…Dm-1Dm and rev = Dm-1….D2D1
  • n != rev
  • n = D1D2….Dm and rev = DmDm-1…D2D1

There are 49 questions to complete.

Last Updated :
Take a part in the ongoing discussion