Skip to content

ISRO Scientist/Engineer CSE 2023Databases › SQL

ISRO Scientist/Engineer CSE 2023 PYQ: Consider a database table $T$ containing two columns $X$ and $Y$ each of type Integer. After the creation of…

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 $M X+1,2 \times M Y+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
    Correct answer
  2. B
    15
  3. C
    129
  4. D
    257

Answer

(A) $127$

Approach

Track how MX and MY evolve with each insertion. Initially the table has one record (1,1), so MX=1 and MY=1. Each new record is inserted with X = MX+1 and Y = 2*MY+1, using the current maxima before insertion. This makes X increase by exactly 1 each time (so X values are 1,2,3,...), while Y follows the recurrence $Y_new = 2*Y_old + 1. \text{We need the} Y \text{value paired with} X=7.$

Reviewed by ISRO IQ Editorial Team.