Array · Data Structures
17 questions · asked in 12 of 27 years (2000–2026)
MCQ 15 · NAT 21-mark 13 · 2-mark 4
2000Questions per year2026
Questions 11–15 of 17
Let a and b be two sorted arrays containing n integers each, in non-decreasing order. Let c be a sorted array containing 2n integers obtained by merging the two arrays a and b. Assuming the arrays are indexed starting from 0, consider the following four statements
I.
II.
III.
IV.
Which of the following is TRUE?
I.
II.
III.
IV.
Which of the following is TRUE?
Answer: (C)
Count positions in the merged array c (indices from 0). Given .
III is true. The elements are all at most , and so are (each is at most ). That is elements that are at most . So the th smallest element, , is at most .
II is true. An element smaller than is either in (at most elements) or in . An element smaller than is also smaller than , so (at most elements). So at most elements are smaller than . Then , the th smallest, cannot be smaller than .
I is false. For and : , but .
IV is false. For and : , but gives .
Only II and III are true.
Answer: (C)
III is true. The elements are all at most , and so are (each is at most ). That is elements that are at most . So the th smallest element, , is at most .
II is true. An element smaller than is either in (at most elements) or in . An element smaller than is also smaller than , so (at most elements). So at most elements are smaller than . Then , the th smallest, cannot be smaller than .
I is false. For and : , but .
IV is false. For and : , but gives .
Only II and III are true.
Answer: (C)
A program P reads in 500 integers in the range [0,100] representing the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?
Answer: (A)
Only the scores above 50 are needed, that is 51, 52, ..., 100. That is different scores, so one counter for each is enough: an array of 50 numbers.
Use as the counter, so counts the score 51 and counts the score 100. After reading each score, if it is above 50, add 1 to its counter. Then print the 50 counters.
An array of 100 or 500 numbers wastes space, and the count of students (500) does not decide the number of counters.
Answer: (A)
Use as the counter, so counts the score 51 and counts the score 100. After reading each score, if it is above 50, add 1 to its counter. Then print the 50 counters.
An array of 100 or 500 numbers wastes space, and the count of students (500) does not decide the number of counters.
Answer: (A)
Two matrices M1 and M2 are to be stored in arrays A and B respectively. Each array can be stored either in row-major or column-major order in contiguous memory locations. The time complexity of an algorithm to compute M1 x M2 will be
Answer: (D)
The question asks about time complexity, which counts basic operations. Reading one array element takes constant time, , whether the array is stored in row-major or column-major order. The algorithm multiplies the same numbers in the same number of steps either way. So the time complexity does not depend on the storage scheme.
The storage order would change only the actual running time, through cache behaviour. For example, row-major A with column-major B reads both arrays one after another in memory, so option (A) could be faster in practice. But that is not a change in time complexity.
Answer: (D)
The storage order would change only the actual running time, through cache behaviour. For example, row-major A with column-major B reads both arrays one after another in memory, so option (A) could be faster in practice. But that is not a change in time complexity.
Answer: (D)
Consider the following algorithm for searching for a given number x in an unsorted
array A[1.....n] having n distinct values :
(1) Choose an i uniformly at random from [1....n]
(2) If A[i] = x then stop else Goto 1;
Assuming that x is present A, What is the expected number of comparisons made by the algorithm before it terminates?
(1) Choose an i uniformly at random from [1....n]
(2) If A[i] = x then stop else Goto 1;
Assuming that x is present A, What is the expected number of comparisons made by the algorithm before it terminates?
Answer: (A)
Each try picks one of the positions at random, so it finds with probability , independent of earlier tries. The expected number of comparisons is the expected number of tries until the first success:
Multiply by :
Subtract the second line from the first:
The right side is a geometric series with first term and ratio , so it sums to . The left side is . So and .
This is the same as the mean of the geometric distribution.
Answer: (A)
Multiply by :
Subtract the second line from the first:
The right side is a geometric series with first term and ratio , so it sums to . The left side is . So and .
This is the same as the mean of the geometric distribution.
Answer: (A)
Consider the following declaration of a two-dimensional array in C :
Char a[100][100]
Assuming that the main memory is byte-addressable and that array is stored starting from memory address 0, the address of a [40] [50] is
Char a[100][100]
Assuming that the main memory is byte-addressable and that array is stored starting from memory address 0, the address of a [40] [50] is
Answer: (B)
C stores arrays in row-major order. The address of is
where BA is the base address, NC is the number of columns and is the size of one element. Here , , byte (char), and indices start from 0.
The value 5040 would come from column-major order (), which C does not use.
Answer: (B)
where BA is the base address, NC is the number of columns and is the size of one element. Here , , byte (char), and indices start from 0.
The value 5040 would come from column-major order (), which C does not use.
Answer: (B)
Keep practising