The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+19 votes

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;

- 127
- 255
- 129
- 257

+32 votes

Best answer

+10 votes

**OPTION A is the 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

$Y=2^{N}-1$ and here it is asked for $X=7$ so if we put $X$ value then we will get $(2^{7}- 1= 128-1=127)$

Suppose if they asked for $X=128$ then $Y=2^{128}-1$ is the answer.

0

Not sure if this is being monitored. But can you please explain how you are deriving the relation between Mx and My ?

0

when $MX=1$ , $MY=1$ (only 1 term which is equal to the value of $MX$)

when $MX=2$ , $MY=1 + 2$ (total 2 terms which is equal to the value of $MX$)

when $MX=3$ , $MY=1 + 2 + 2^{2}$ (total 3 terms which is equal to the value of $MX$)

when $MX=4$ , $MY=1 + 2 + 2^{2} + 2^{3}$ (total 4 terms which is equal to the value of $MX$)

............

Similarly ,

when $MX=n$ , $MY=1 + 2 + 2^{2} + 2^{3}+......+2^{n-1}$ (total $n$ terms which is equal to the value of $MX$)

So, for $MX=n$ ,

$MY=1 + 2 + 2^{2} + 2^{3}+......+2^{n-1}$ = $2^{n}-1$

when $MX=2$ , $MY=1 + 2$ (total 2 terms which is equal to the value of $MX$)

when $MX=3$ , $MY=1 + 2 + 2^{2}$ (total 3 terms which is equal to the value of $MX$)

when $MX=4$ , $MY=1 + 2 + 2^{2} + 2^{3}$ (total 4 terms which is equal to the value of $MX$)

............

Similarly ,

when $MX=n$ , $MY=1 + 2 + 2^{2} + 2^{3}+......+2^{n-1}$ (total $n$ terms which is equal to the value of $MX$)

So, for $MX=n$ ,

$MY=1 + 2 + 2^{2} + 2^{3}+......+2^{n-1}$ = $2^{n}-1$

- All categories
- General Aptitude 1.5k
- Engineering Mathematics 7.1k
- Digital Logic 2.7k
- Programming & DS 4.9k
- Algorithms 4.2k
- Theory of Computation 5.3k
- Compiler Design 2.1k
- Databases 4k
- CO & Architecture 3.5k
- Computer Networks 4k
- Non GATE 1.4k
- Others 1.5k
- Admissions 556
- Exam Queries 551
- Tier 1 Placement Questions 23
- Job Queries 69
- Projects 18

47,894 questions

52,261 answers

182,169 comments

67,679 users