Arrays questions

Q35

GATE CS 2024 CS-2Linear Data StructuresNAT1 mark
Let AA be an array containing integer values. The distance of AA is defined as the minimum number of elements in AA that must be replaced with another integer so that the resulting array is sorted in non-decreasing order. The distance of the array [2,5,3,1,4,2,6][2, 5, 3, 1, 4, 2, 6] is ___________
Show answer without attempting

Answer: 3

Q34

GATE CS 2016 CS-1Linear Data StructuresMCQ2 marks−2/3 if wrong
The following function computes the maximum value contained in an integer array p[] of size n (n >= 1).
int max(int *p, int n) {
    int a=0, b=n-1;

    while (__________) {
        if (p[a] <= p[b]) { a = a+1; }
        else              { b = b-1; }
    }

    return p[a];
}
The missing loop condition is
Show answer without attempting

Answer: D

Q63

GATE CS 2015 CS-3Linear Data StructuresNAT2 marks
Suppose c=⟨c[0],…,c[k−1]⟩c = \langle c[0], \dots, c[k-1] \rangle is an array of length kk, where all the entries are from the set {0,1}\{0, 1\}. For any positive integers aa and nn, consider the following pseudocode.
DOSOMETHING(c, a, n)
z ← 1
for i ← 0 to k − 1
    do z ← z² mod n
       if c[i] = 1
          then z ← (z × a) mod n
return z
If k=4k = 4, c=⟨1,0,1,1⟩c = \langle 1, 0, 1, 1 \rangle, a=2a = 2 and n=8n = 8, then the output of DOSOMETHING(c,a,nc, a, n) is ____________.
Show answer without attempting

Answer: 0

Q48

GATE CS 2015 CS-2Linear Data StructuresNAT2 marks
A Young tableau is a 2D array of integers increasing from left to right and from top to bottom. Any unfilled entries are marked with ∞\infty, and hence there cannot be any entry to the right of, or below a ∞\infty. The following Young tableau consists of unique entries.

When an element is removed from a Young tableau, other elements should be moved into its place so that the resulting table is still a Young tableau (unfilled entries may be filled in with a ∞\infty). The minimum number of entries (other than 1) to be shifted, to remove 1 from the given Young tableau is _______________.
Question figure
Show answer without attempting

Answer: 5

Q10

GATE CS 2014 CS-3Linear Data StructuresMCQ1 mark−1/3 if wrong
Let AA be a square matrix of size n×nn \times n. Consider the following pseudocode. What is the expected output?
C = 100;
for i = 1 to n do
  for j = 1 to n do
  {
    Temp = A[i][j] + C;
    A[i][j] = A[j][i];
    A[j][i] = Temp - C;
  }
for i = 1 to n do
  for j = 1 to n do
    output (A[i][j]);
Show answer without attempting

Answer: A

Q42

GATE CS 2014 CS-3Linear Data StructuresMCQ2 marks−2/3 if wrong
Consider the C function given below. Assume that the array listA contains n (> 0) elements, sorted in ascending order.
int ProcessArray(int *listA, int x, int n)
{
  int i, j, k;
  i = 0;
  j = n-1;
  do {
    k = (i+j)/2;
    if (x <= listA[k])
      j = k-1;
    if (listA[k] <= x)
      i = k+1;
  }while (i <= j);
  if (listA[k] == x)
    return(k);
  else
    return -1;
}
Which one of the following statements about the function ProcessArray is CORRECT?
Show answer without attempting

Answer: B

0/60 correct0 marks

Related topics in Linear Data Structures