Warning: count(): Parameter must be an array or an object that implements Countable in /home/customer/www/thegatebook.in/public_html/qa/qa-include/qa-theme-base.php on line 177

# DSA - Grand Test -Q22

Warning: count(): Parameter must be an array or an object that implements Countable in /home/customer/www/thegatebook.in/public_html/qa/qa-include/qa-theme-base.php on line 177
+1 vote

Consider the following code fragment.

`y = 0;`

`for ( i = 0; i <= n; i++)`

`{`

`  y += 2^i;`

`}`

Which one of the following conditions is TRUE before every iteration of the loop (where i is the iteration number and ^ is an exponentiation operator)?

(A) $\dpi{100} y_i = 2i - 1$

(B) $\dpi{100} y_i = 2^i - 1$

(C) $\dpi{100} y_i = 2^{i-1}-1$

(D) $\dpi{100} y_i = 2^{i+1}-1$

reshown Sep 10, 2020

When loop runs 3 times,

y = 1 +2 + 4 =7

i.e. $2^{3}-1$

Hence

when loop runs n times ($\leqslant n$)

THen

$2^{n}-1$

And for every iteration of the loop

It is

$2^{i}-1$

answered Sep 26, 2020 by (11,240 points)