IAE Academy

ISRO CS 2023 Q.30: solution and answer

ISRO 2023 · CSQ.30 · 1 mark · MCQ

Consider a database table T containing two columns X and Y each of type Integer. After the creation of the table, one record (X=1, Y=1) is inserted in the table. Let MX and MY denote the respective maximum values of X and Y among all records in the table at any point in time. Using MX and MY, new records are inserted in the table 128 times with X and Y values being MX+1, 2 × MY+1 respectively. It may be noted that each time after the insertion, values of MX and MY change. What will be the output of the following SQL query after the steps mentioned above are carried out?

SELECT Y FROM T WHERE X=7;

  1. (A)

    127

  2. (B)

    15

  3. (C)

    129

  4. (D)

    257

See the question in the paper

Answer and solution

ANSWER

The query returns 127, option (A).

Official answer: ASource: ISRO's revised and final answer key of 16 February 2024

  1. The table starts with one row . Each new row uses the current maxima: and .

  2. Every new row has larger and than all earlier rows, so the newest row always holds both maxima. Hence the next row is computed from the previous row alone.

  3. Let be the row added by insertion , with . Then , so .

  4. Also . Adding 1 to both sides gives , with . So and .

  5. The query asks for , so and . This is within the 128 insertions, and since strictly increases, occurs in exactly one row.

  6. Then . Check by repeated doubling plus one: . The sixth insertion gives , and the query returns this single value.

KEY IDEA

Each new row is built from the current maxima, which always belong to the latest row. So the values follow , giving , while .

WATCH OUT FOR

Being off by one in the index: the row with is the sixth inserted row, not the seventh, because the starting row already has . Using the wrong index gives 63 or 255 instead of 127. Option (B) 15 is the value for .

From the ISRO CS 2023 paper. Every question of this paper · The full paper (PDF, ISRO) · All 4 ISRO SQL questions, with notes

More ISRO SQL questions