Consider a database table T containing two columns X and Y each of type…

2023

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

Attempted by 229 students.

Show answer & explanation

Correct answer: A

A recurrence relation defines each new term purely from the previous one via a fixed rule. When a rule such as Y_new = 2 × Y_old + 1 is applied once per insertion alongside X simply incrementing by 1, the value tied to any particular X must be built up step by step from the initial record — it cannot be read off directly. A SELECT ... WHERE query on such a table then just reports the Y stored in the one record whose X matches the target.

Applying this to the table: it starts with the single record (X = 1, Y = 1). Each insertion sets the new X to (current maximum X) + 1 and the new Y to 2 × (current maximum Y) + 1, so the record carrying X = 7 is the 6th record inserted (X goes 1 → 2 → 3 → 4 → 5 → 6 → 7). Tracking Y through each of these six insertions:

  1. X = 2: Y = 2 × 1 + 1 = 3

  2. X = 3: Y = 2 × 3 + 1 = 7

  3. X = 4: Y = 2 × 7 + 1 = 15

  4. X = 5: Y = 2 × 15 + 1 = 31

  5. X = 6: Y = 2 × 31 + 1 = 63

  6. X = 7: Y = 2 × 63 + 1 = 127

So the record with X = 7 carries Y = 127, and SELECT Y FROM T WHERE X = 7; returns 127.

Independent check: every record in this sequence satisfies Y = 2X − 1 (X = 1 gives 21 − 1 = 1; X = 2 gives 22 − 1 = 3; …; X = 7 gives 27 − 1 = 127), matching every step traced above and confirming the answer independently. The remaining options do not belong to this sequence: 15 is the Y value at the earlier step X = 4 rather than X = 7, while 129 and 257 never occur in the sequence generated by this recurrence.

Explore the full course: Isro