Login
Register
Dark Mode
Brightness
Profile
Edit Profile
Messages
My favorites
My Updates
Logout
Recent questions tagged loop-invariants
0
votes
1
answer
1
Made Easy Test Series 2024
How many times is the comparison $i >= n$ performed in the following program? int i = 200 n = 80; main() { while (i >= n) { i = i - 2 n = n + 1 } }
How many times is the comparison $i >= n$ performed in the following program?int i = 200 n = 80; main() { while (i >= n) { i = i - 2 n = n + 1 } }
Ray Tomlinson
424
views
Ray Tomlinson
asked
Aug 9, 2023
Algorithms
algorithms
algorithm-design
loop-invariants
loop
time-complexity
+
–
12
votes
2
answers
2
TIFR CSE 2019 | Part B | Question: 9
Consider the following program fragment: var x, y: integer; x := 1; y := 0; while y < x do begin x := 2*x; y := y+1 end; For the above fragment , which of the following is a loop invariant ? $x=y+1$ $x=(y+1)^2$ $x=(y+1)2^y$ $x=2^y$ None of the above, since the loop does not terminate
Consider the following program fragment:var x, y: integer; x := 1; y := 0; while y < x do begin x := 2*x; y := y+1 end;For the above fragment , which of the following is ...
Arjun
3.4k
views
Arjun
asked
Dec 18, 2018
Programming in C
tifr2019
programming
loop-invariants
+
–
0
votes
1
answer
3
Loop Invariant -CLR
What is loop invariant in general term ? PS: Insertion Sort has loop invariant . We have three things in loop invariant : a. Initialization b.Maintenance c.Termination
What is loop invariant in general term ? PS: Insertion Sort has loop invariant . We have three things in loop invariant :a. Initializationb.Maintenancec.Termination
dragonball
825
views
dragonball
asked
Jun 19, 2017
Algorithms
algorithms
loop-invariants
+
–
36
votes
6
answers
4
GATE CSE 2017 Set 2 | Question: 37
Consider the C program fragment below which is meant to divide $x$ by $y$ using repeated subtractions. The variables $x$, $y$, $q$ and $r$ are all unsigned int. while (r >= y) { r=r-y; q=q+1; } Which of the following conditions on the variables $x, y, q$ and $r$ ... $(q==0) \ \&\& \ (y>0)$
Consider the C program fragment below which is meant to divide $x$ by $y$ using repeated subtractions. The variables $x$, $y$, $q$ and $r$ are all unsigned int.while (r >...
Arjun
14.0k
views
Arjun
asked
Feb 14, 2017
Programming in C
gatecse-2017-set2
programming
loop-invariants
+
–
20
votes
5
answers
5
TIFR CSE 2017 | Part B | Question: 5
Consider the following psuedocode fragment, where $y$ is an integer that has been initialized. int i=1 int j=1 while (i<10): j=j*i i=i+1 if (i==y): break end if end while Consider the following statements: $(i==10)$ or $(i==y)$ If ... the end of the while loop? Choose from the following options. i only iii only ii and iii only i, ii, and iii None of the above
Consider the following psuedocode fragment, where $y$ is an integer that has been initialized.int i=1 int j=1 while (i<10): j=j*i i=i+1 if (i==y): break end if end whileC...
go_editor
3.0k
views
go_editor
asked
Dec 23, 2016
Programming in C
tifr2017
programming
loop-invariants
+
–
4
votes
2
answers
6
GATE CSE 1988 | Question: 8ii
Consider the two program segments below: for i:=1 to f(x) by 1 do S end i:=1; While i<=f(x) do S i:=i+1 end Under what conditions are these two programs equivalent? Treat $S$ as any sequence of statements and $f$ as a function.
Consider the two program segments below:for i:=1 to f(x) by 1 do S endi:=1; While i<=f(x) do S i:=i+1 endUnder what conditions are these two programs equivalent? Treat $S...
go_editor
2.2k
views
go_editor
asked
Dec 19, 2016
Programming in C
gate1988
programming
descriptive
loop-invariants
+
–
8
votes
1
answer
7
GATE CSE 1988 | Question: 6ii
Below figure is the flow-chart corresponding to a program to calculate the $\gcd$ of two integers, $M$ and $N$ respectively, $(M, N >0).$ Use assertions at the cut point $C_1$, $C_2$ and $C_3$ to prove that the flow-chart is correct.
Below figure is the flow-chart corresponding to a program to calculate the $\gcd$ of two integers, $M$ and $N$ respectively, $(M, N >0).$ Use assertions at the cut point ...
go_editor
1.5k
views
go_editor
asked
Dec 19, 2016
Programming in C
gate1988
normal
descriptive
loop-invariants
+
–
15
votes
1
answer
8
GATE CSE 1987 | Question: 7a
List the invariant assertions at points $A, B, C, D$ and $E$ in program given below: Program division (input, output) Const dividend = 81; divisor = 9; Var remainder, quotient:interger begin (*(dividend >= 0) AND (divisor > 0)*) remainder := dividend; ... = remainder - divisor; (*C*) end; (*D*) quotient := quotient - 1; remainder := remainder + divisor; (*E*) end
List the invariant assertions at points $A, B, C, D$ and $E$ in program given below:Program division (input, output) Const dividend = 81; divisor = 9; Var remainder, quot...
makhdoom ghaya
2.4k
views
makhdoom ghaya
asked
Nov 14, 2016
Programming in C
gate1987
programming
loop-invariants
descriptive
+
–
8
votes
3
answers
9
ISRO2007-15
Consider the following pseudo-code x:=1; i:=1; while (x <= 1000) begin x:=2^x; i:=i+1; end; What is the value of i at the end of the pseudo-code? 4 5 6 7
Consider the following pseudo-codex:=1; i:=1; while (x <= 1000) begin x:=2^x; i:=i+1; end;What is the value of i at the end of the pseudo-code?4567
go_editor
15.8k
views
go_editor
asked
Jun 10, 2016
Programming in C
isro2007
loop-invariants
+
–
50
votes
7
answers
10
GATE CSE 2016 Set 2 | Question: 35
The following function computes $X^{Y}$ for positive integers $X$ and $Y$. int exp (int X, int Y) { int res =1, a = X, b = Y; while (b != 0) { if (b % 2 == 0) {a = a * a; b = b/2; } else {res = res * a; b = b - 1; } } return res; } Which one of the following ... $X^{Y} = a^{b}$ $(res * a)^{Y} = (res * X)^{b}$ $X^{Y} = res * a^{b}$ $X^{Y} = (res * a)^{b}$
The following function computes $X^{Y}$ for positive integers $X$ and $Y$.int exp (int X, int Y) { int res =1, a = X, b = Y; while (b != 0) { if (b % 2 == 0) {a =...
Akash Kanase
13.8k
views
Akash Kanase
asked
Feb 12, 2016
Programming in C
gatecse-2016-set2
programming
loop-invariants
normal
+
–
23
votes
3
answers
11
TIFR CSE 2010 | Part B | Question: 37
Consider the program where $a, b$ are integers with $b > 0$. x:=a; y:=b; z:=0; while y > 0 do if odd (x) then z:= z + x; y:= y - 1; else y:= y % 2; x:= 2 * x; fi Invariant of the loop is a condition which is ... terminate for some values of $a, b$ but when it does terminate, the condition $z = a * b$ will hold. The program will terminate with $z=a^{b}$
Consider the program where $a, b$ are integers with $b 0$.x:=a; y:=b; z:=0; while y 0 do if odd (x) then z:= z + x; y:= y - 1; else y:= y % 2; x:= 2 * x; fiInvariant of...
makhdoom ghaya
3.3k
views
makhdoom ghaya
asked
Oct 10, 2015
Programming in C
tifr2010
programming
loop-invariants
+
–
16
votes
2
answers
12
TIFR CSE 2010 | Part B | Question: 30
Consider the following program for summing the entries of the array $b$: array $[0 .. N-1]$ of integers, where $N$ is a positive integer. (The symbol '$<>$' denotes 'not equal to'). var i, s: integer; Program i:= 0; s:= 0; [*] while i <> N ... $s = \sum\limits^{i-1}_{j=0}b[j] \;\&\; 0 \leq i \leq N$
Consider the following program for summing the entries of the array $b$: array $[0 .. N-1]$ of integers, where $N$ is a positive integer. (The symbol '$<>$' denotes 'not ...
makhdoom ghaya
2.7k
views
makhdoom ghaya
asked
Oct 8, 2015
Programming in C
tifr2010
programming
loop-invariants
+
–
54
votes
7
answers
13
GATE CSE 2015 Set 1 | Question: 33
Consider the following pseudo code, where $x$ and $y$ are positive integers. begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end end The post condition that needs to be satisfied after the program terminates is $\{ r = qx + y \wedge r < y\}$ ... $\{ y = qx + r \wedge 0 < r < y\}$ $\{ q + 1 < r - y \wedge y > 0\}$
Consider the following pseudo code, where $x$ and $y$ are positive integers.begin q := 0 r := x while r ≥ y do begin r := r - y q := q + 1 end endThe post condition tha...
makhdoom ghaya
15.4k
views
makhdoom ghaya
asked
Feb 13, 2015
Programming in C
gatecse-2015-set1
programming
loop-invariants
normal
+
–
32
votes
5
answers
14
GATE CSE 2004 | Question: 32
Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let $n = d_1\, d_2\, \ldots\, d_m$. int n, rev; rev = 0; while(n > 0) { rev = rev * 10 + n%10; n = n/10; } The loop invariant condition at the end ... $n=d_1\, d_2 \,\ldots\, d_m \qquad \mathbf{or} \qquad \text{rev} =d_m \,\ldots\, d_2\, d_1$
Consider the following program fragment for reversing the digits in a given integer to obtain a new integer.Let $n = d_1\, d_2\, \ldots\, d_m$.int n, rev; rev = 0; while(...
Kathleen
12.0k
views
Kathleen
asked
Sep 18, 2014
Programming in C
gatecse-2004
programming
loop-invariants
normal
+
–
24
votes
3
answers
15
GATE CSE 1991 | Question: 1,vi
Consider the following PASCAL program segment: if i mod 2 = 0 then while i >= 0 do begin i := i div 2; if i mod 2 < > 0 then i := i - 1; else i := i – 2; end; An appropriate loop-invariant for the while-loop is ________
Consider the following PASCAL program segment:if i mod 2 = 0 then while i >= 0 do begin i := i div 2; if i mod 2 < 0 then i := i - 1; else i := i – 2; end;An appropria...
Kathleen
4.4k
views
Kathleen
asked
Sep 12, 2014
Programming in C
gate1991
programming
loop-invariants
normal
fill-in-the-blanks
+
–
To see more, click for the
full list of questions
or
popular tags
.
Email or Username
Show
Hide
Password
I forgot my password
Remember
Log in
Register