Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views3 pages

Stream 1

The document contains three problems related to Mini Java programs, focusing on control flow graphs, loop invariants, and termination analysis. Problem 1 requires constructing a control flow graph and proving program termination, while Problem 2 involves providing a loop invariant and annotations for assertions. Problem 3 asks for an analysis of program termination with various input scenarios.

Uploaded by

Mka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Stream 1

The document contains three problems related to Mini Java programs, focusing on control flow graphs, loop invariants, and termination analysis. Problem 1 requires constructing a control flow graph and proving program termination, while Problem 2 involves providing a loop invariant and annotations for assertions. Problem 3 asks for an analysis of program termination with various input scenarios.

Uploaded by

Mka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Midterm Exam

Problem 1 (12 points). Given the following mini Java program.


Construct the control flow graph and show that the given program
terminates.

int x, y, z;
x = read();
y = read();

if (x > y) {
z = x;
x = y;
y = z;
}

z = 1;
while (x != y) {
x = x + 2;
y = y + 1;
z = z * (y - x);
}

write(z);

Problem 2 (12 points). Given the following Mini Java program.


Construct the control flow graph and prove the assertion Z. In order
to do so, proceed as follows.

 Provide a loop invariant. 6 points


 Construct an annotation of program points with assertions. 3
points
 Prove that your annotation is locally consistent. 3 points
int x, y;
x = 0;
y = 1;

while (y =< 630) {

y = y * 5;
x = x + 5;

}
write(x);
assert (Z ≡ x == 25);
}

Problem 3 (6 points). Given the following Mini Java program. Does


the program always terminate?
 Yes, it terminates always. Give at least 5 inputs for which the
program terminates. 2
 No, it never terminates. Give at least 5 inputs for which the
program does not terminate. 2
 No, it terminates sometimes. Give at least 5 inputs for which
the program does not terminate and at least 5 inputs for which
the program terminates.

int m = 0;
int l = 1;
int t = 0;
int k = 2;
int n = read();

while (l != n) {
t = l + m;
m = l;
l = t;
k = k + 1;
}

You might also like