CARVIEW |
Top MCQs on Algorithms in DSA with Answers
Question 1
Given 8 identical coins out of which one coin is heavy and a pan balance. How many minimum number of measurements are needed to find the heavy coin?
- 2
- 3
- 4
- 7
Question 2
- Brute-force
- Dynamic Programming
- Backtracking
- Divide and Conquer
Question 3
- Insertion sort
- Selection sort
- Merge sort
- Heap sort
Question 4
A set X can be represented by an array x[n] as follows:

Consider the following algorithm in which x,y, and z are Boolean arrays of size n:
algorithm zzz(x[] , y[], z [])
{
int i;
for (i=O; i<n; ++i)
z[i] = (x[i] ^ ~y[i]) V (~x[i] ^ y[i]) }
The set Z computed by the algorithm is:
(X Intersection Y)
(X Union Y)
(X-Y) Intersection (Y-X)
(X-Y) Union (Y-X)
Question 5
An element in an array X is called a leader if it is greater than all elements to the right of it in X. The best algorithm to find all leaders in an array (GATE CS 2006)
- Solves it in linear time using a left to right pass of the array
- Solves it in linear time using a right to left pass of the array
- Solves it using divide and conquer in time 8(nlogn)
- Solves it in time 8(n2)
Question 6
float f(float x, int y)
{
float p, s; int i;
for (s=1, p=1, i=1; i < y; i ++)
{
p*= x/i;
s+=p;
}
return s;
}
- x^y
- e^x
- ln(1 + x)
- x^x
Question 7
do, where 1 < k <= n: reverse (s, 1, k); reverse (s, k + 1, n); reverse (s, 1, n);(GATE CS 2000)
- Rotates s left by k positions
- Leaves s unchanged
- Reverses all elements of s
- None of the above
Question 8
An inversion in a an array A[] is a pair (A[i], A[j]) such that A[i] > A[j] and i < j. An array will have maximum number of inversions if it is:
- Sorted in increasing order
- Sorted in decreasing order
- Sorted in alternate fashion
- Both A and B
Question 9
void find_and_replace(char *A, char *oldc, char *newc) { for (int i = 0; i < 5; i++) for (int j = 0; j < 3; j++) if (A[i] == oldc[j]) A[i] = newc[j]; }The procedure is tested with the following four test cases (1) oldc = "abc", newc = "dab" (2) oldc = "cde", newc = "bcd" (3) oldc = "bca", newc = "cda" (4) oldc = "abc", newc = "bac" The tester now tests the program on all input strings of length five consisting of characters ‘a’, ‘b’, ‘c’, ‘d’ and ‘e’ with duplicates allowed. If the tester carries out this testing with the four test cases given above, how many test cases will be able to capture the flaw?
- Only one
- Only two
- Only three
- All four
Question 10
- None
- 2 only
- 3 and 4 only
- 4 only
There are 49 questions to complete.