Question

Consider a database table TT containing two columns XX and YY each of type integer. After the creation of the table, one record (X=1,Y=1)(X=1, Y=1) is inserted in the table.

Let MXMX and MYMY denote the respective maximum values of XX and YY among all records in the table at any point in time. Using MXMX and MYMY, new records are inserted in the table 128 times with XX and YY values being MX+1MX+1, 2∗MY+12*MY+1 respectively. It may be noted that each time after the insertion, values of MXMX and MYMY 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;
Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2011 answer key

Solution

Formulate recurrences for the sequence of inserted records and compute the value of Y when X equals 7.

  1. The table initially contains the single record (X1=1,Y1=1)(X_1 = 1, Y_1 = 1). Thus initially MX=1,MY=1MX = 1, MY = 1.
  1. Each subsequent insertion creates a record with Xk=MX+1=Xk−1+1X_{k} = MX + 1 = X_{k-1} + 1 and Yk=2×MY+1=2Yk−1+1Y_k = 2 \times MY + 1 = 2 Y_{k-1} + 1.
  1. Solving the recurrence Yk=2Yk−1+1Y_k = 2 Y_{k-1} + 1 with Y1=1Y_1 = 1:
  • k=1k = 1: X=1,Y=1=21−1X = 1, Y = 1 = 2^1 - 1
  • k=2k = 2: X=2,Y=2(1)+1=3=22−1X = 2, Y = 2(1) + 1 = 3 = 2^2 - 1
  • k=3k = 3: X=3,Y=2(3)+1=7=23−1X = 3, Y = 2(3) + 1 = 7 = 2^3 - 1
  • In general, for record kk, Xk=kX_k = k and Yk=2k−1Y_k = 2^k - 1.
  1. For the query WHERE X = 7, we have k=7k = 7:
Y=27−1=128−1=127Y = 2^7 - 1 = 128 - 1 = 127
Final answer

A

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2011 Computer Science and Information Technology (CS)
Question
32 of 65, printed as CS Q.32
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.