+18 votes
1.7k views

Consider a database table T containing two columns $\text{X}$ and $\text{Y}$ each of type $\text{integer}$. After the creation of the table, one record $\text{(X=1, Y=1)}$ is inserted in the table.

Let $\text{MX}$ and $\text{MY}$ denote the respective maximum values of $\text{X}$ and $\text{Y}$ among all records in the table at any point in time. Using $\text{MX}$ and $\text{MY}$, new records are inserted in the table 128 times with $\text{X}$ and $\text{Y}$ values being $\text{MX+1, 2*MY+1}$ respectively. It may be noted that each time after the insertion, values of $\text{MX}$ and $\text{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. 127
2. 255
3. 129
4. 257
asked
edited | 1.7k views

## 3 Answers

+29 votes
Best answer
$X = 1, Y = 1$

$X = 2, Y = 2\times 1 +1 = 3$

$X = 3, Y = 2\times 3 + 1 = 7$

$X = 4, Y = 2\times 7 + 1 = 15$

$X = 5, Y = 2\times 15 + 1 = 31$

$X = 6, Y = 2\times 31+1 = 63$

$X = 7, Y = 2\times 63 + 1 = 127$
answered by Veteran (357k points)
selected by
0
Good explanation
+7 votes

OPTION A is answer

if you do this as mentioned by arjun sir then you will get the answer

X = 1, Y = 1

X = 2, Y = 2*1 +1 = 3

X = 3, Y = 2*3 + 1 = 7

X = 4, Y = 2*7 + 1 = 15

X = 5, Y = 2*15 + 1 = 31

X = 6, Y = 2*31+1 = 63

X = 7, Y = 2*63 + 1 = 127

but if this question will be extended to x= 'N' value then if you observe the pattern then it will come out as

(2^x)-1 and here it is asked for x=7 so if we put x value then we will get (128 - 1= 127)

answered by Active (1.3k points)
0
Not sure if this is being monitored. But can you please explain how you are deriving the relation between Mx and My ?
0 votes

MY is simply doing the shift of the previous number in binary to left and adding 1 in LSB. So, after 6 additions to table, MX will be 7 and there will be seven 1's in MY which is equivalent to 2^8-1 in decimal.

answered by (155 points)
Answer:

+15 votes
1 answer
1
+16 votes
3 answers
2
+23 votes
3 answers
3