58 58 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$ Databases gatecse-2011 databases sql normal + – go_editor 19.9k views answer comment Share Follow Print See all 2 Comments 2 2 Comments reply Deepak Poonia commented Jul 22, 2024 i edited by Deepak Poonia Aug 6, 2024 reply Follow flag Detailed Video Solution, with Complete Analysis & Variations: https://youtu.be/zb6vXpZVo1E?t=4186&feature=sharedAssume $n$ new tuples are inserted, & If query asks $sum(X), sum(Y)$, then:$Sum(X) = (n+1)(n+2)/2$$Sum(Y) = 2(2^{n+1}-1) - (n+1)$ 2 2 replyShare ritiksri8 commented Sep 20, 2024 reply Follow flag Simulate acc. to question 1 1 replyShare Please log in or register to add a comment.
Best answer 73 73 votes $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$ Correct Answer: $A$ Arjun answered Nov 19, 2014 • edited May 19, 2019 by Naveen Kumar 3 Arjun comment Share Follow See all 8 Comments 8 8 Comments reply Show 5 previous comments Mayank0343 commented Oct 27, 2019 reply Follow flag @jeet sir, thanks for response. I assume yes is for the first query. regarding the 2nd query, is there any usefulness or significance of "records inserted in table 128 times" 0 0 replyShare `JEET commented Oct 27, 2019 reply Follow flag I think it's just a number. Don't have and such significance. 1 1 replyShare Akash Papnai commented Dec 22, 2019 reply Follow flag @Mayank0343 @`JEET Yes, the number 128 has significance. It tells after X=Y=1, we have to insert 128 times the value of X and Y according to the given formula. If the question were: SELECT Y FROM T WHERE X=129; It would have given an error. 0 0 replyShare Please log in or register to add a comment.
26 26 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. nikunj answered Aug 30, 2017 • edited Nov 28, 2018 by Lakshman Bhaiya nikunj comment Share Follow See all 2 Comments 2 2 Comments reply Sid Mukherj commented Apr 4, 2018 reply Follow flag Not sure if this is being monitored. But can you please explain how you are deriving the relation between Mx and My ? 0 0 replyShare ankitgupta.1729 commented Nov 7, 2018 reply Follow flag 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$ 8 8 replyShare Please log in or register to add a comment.
0 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. Skan answered Jan 6, 2018 Skan comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes After inserting 4 values we can interpret that its forming a series were elements next to it are found by adding powers of 2. Interpreting it as a series is helpful because if the query would ask for any value of x greater than 10 then individual substitution will be time consuming. See the solution below for more understanding Hence option A is Answer (i.e 127) Chirag Shilwant answered Dec 14, 2019 Chirag Shilwant comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes 1 1 1+1 2+1 2+1 2(3)+1 3+1 2(7)+1 4+1 2(15)+1 5+1 2(31)+1 6+1 2(63)+1 so for x=7 y will be 127 Jaimin_Khatri answered Mar 24, 2025 Jaimin_Khatri comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes XY112337When X=3 is inserted, it is 2nd new record after X=1.Just look at corresponding Y value; 7 = 2^0 + 2^1 + 2^2 So, when X=7 is inserted, it is 6th new record. Y = 2^0 + 2^1 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 Sum of n terms of GP = a * (r^n - 1) / (r - 1)Here, a = 2, n =7 Therefore, S_n = 1 * (2^7 - 1) / (2 - 1) = 2^7 - 1 = 127 justanotherguy answered Jul 2, 2025 justanotherguy comment Share Follow 0 reply Please log in or register to add a comment.