0% found this document useful (0 votes)
4 views4 pages

CS601 2010 January FV - Exam-09-10

The document outlines an examination paper for a course on the verification of computer programs, consisting of multiple questions that require students to analyze and verify program segments using concepts such as loop invariants, path analysis, and mathematical induction. Each question includes tasks like drawing flowgraphs, proving correctness, and writing verification schemas. The exam covers various programming constructs and logical reasoning, emphasizing the importance of formal verification in computer science.

Uploaded by

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

CS601 2010 January FV - Exam-09-10

The document outlines an examination paper for a course on the verification of computer programs, consisting of multiple questions that require students to analyze and verify program segments using concepts such as loop invariants, path analysis, and mathematical induction. Each question includes tasks like drawing flowgraphs, proving correctness, and writing verification schemas. The exam covers various programming constructs and logical reasoning, emphasizing the importance of formal verification in computer science.

Uploaded by

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

Institute of Statistical Studies and Research

Department of Computer and Information Sciences


CS601-Verification of Computer Programs
January, 2010 Time permitted: Three Hours
=========================================================
Solve all questions. Write Complete Answer for each question and Justify it
=========================================================
Question #1 (10 Points)
Given the following program segment:

Pre: x> 0, y>=0


1. read(x, y);
2. j :=1;
3. i :=0;
4. while (i < y) do
begin
5. j := j * x;
6. i := i+1;
end;
Invariant: J(x,i)  After iteration i, j contains the ith power of x.

A. Draw the flowgraph of the program. (1.5 points)


B. Analyze the program (use path analysis). (1.5 points)
C. Prove by mathematical induction that J(x, i) is a loop invariant. (3.5 points)
D. Write the verification schema for this program segment. (3.5 Points)
----------------------------------------------------------------------------------------------------

Question #2 (8 Points)
A. Write a well founded formulae that specify the following argument, If here is an
error, identify the type of error. (2 Points)

“If your patient is breathing, she is alive. Your patient is not breathing.
Therefore, your patient is not alive.”
-------------------------------------
B. Show whether the predicates in the following page are a tautology or not in the
given interpretations: (3 Points)

1/4
 α    α =  +/2* √-1
I. α  rational numbers and   irrational numbers
II.   rational numbers, α  imaginary numbers
III. α and  are real variables in a programming language.
-----------------------------------------
C. Rewrite each of these statement so that negation are applied exclusively to
predicate. (3 Points)

i. ~ ( x y ~ P(x,y)  x ~y Q(x,y))


ii. ~ x( y z ~P(x,y,z)  ~z y P(x,y,z))
--------------------------------------------------------------------------------------------
Question #3 (15 Points)
A. Drive the wp() for the following program segment and show if it is correct. State
the initial values that would make {Pre} S {post} a valid predicate. (5 Points)

Pre:{True}
S:[
1 J := 0;
2 m1 := 0;
3 m2 := 1;
4 m3 := 7;
5 m1 := m1 + m3;
6 m2 := m2 + m3;
7 m3 := m3 + m2;
]
Post: { m1 = j  m2 = j + 1  m3 = 8 + j}
--------------------------------------------
B. Prove the correctness of the following program segment, (verification schemas
and proof): State the initial values that would make <Pre> S <post> a valid predicate.
(5 Points)

< Pre: r > 0, a ≥ 0 >


S: [
1 r := r *a;
2 t:= r - a;
3 If (t < a)
4 Then t := t * r
5 Else t := t –ln(a + r)
]
< Post: t ≥ 0 >
2/4
C. Drive the Invariant {I}, then drive VCs for the following program segment: (5 points)

Pre: {z >7, -5<w <0}


1 while(z > w)
2 w = - w+1;
{I}
Post: {w>0}

--------------------------------------------------------------------------------------------
Question 4: (15 points)

Given the following annotated Program segment:

Pre:{ N >0}
1 i := 1;
2 k := N-1;
{INV(I,k,a)}
3 while i ≤ k do
begin

4 if (a[i] < 5)

5 then a[ i] := 5

6 i := i +1

{INV(I,k,a)}
end

Post:{( m1  m  N  a[m] >= 5 )}


A. Draw the flowgraph. (1 point)
B. Analyze the program (use path analysis). (2 points)
C. Write the verification schema for this program segment. (5 points)
D. Given the following predicate, prove that it is an invariant. (5 points)

Inv(I, k, a) {( j| I > j ≥ 1  a[j] ≥ 5), I ≤ k +1}

E. What modification, if any, does {Inv} need to be THE Invariant?(2 points)


--------------------------------------------------------------------------------------------

Question 5: (14 points)


3/4
Pre: { N > p > 0, x positive integer > 0}

1. 1: I:=1;
2. 2: while( I <= p) do
3. begin
4. 3: if (a[I] = x)
5. 4: then I :=p+1;
6. 5: I := I +1;
7. end;
8. 6: if (I = p+1) then
9. begin
10. 7: p := p+1;
11. 8: a[p] := x;
12. end;
13. Exit

Post:{ x  ao  (p= po +1  x = a[p]}

A. Draw the flow graph of the given implementation. (1.5 points)


B. Develop test suites that guarantee that the loop will be executed exactly:
0 time, 1 time, ‘p’ times and ‘x’ times. (1.5 points)
C. State the Def-Use Chain for the variables a, i, p and x. (2 points)
D. Drive the test suite that covers the U-context at 8, in terms of path (U-Context
Constructor). (4 points)
E. Find the static slice for the criteria Cs= <8, a>. (5 points)
--------------------------------------------------------------------------------------------
Question 6: (8 points)
Given the specification of a program, that calculates the wages for Part time hires. The
minimum wage per hour, “MWage”, is given, as well as, a disk file containing records for
the hired individuals. Each record composed of the hire’s name “Hname”, and their
corresponding working hours “WH”.

Pre: MWage > 5, Hname  alphabet letters, WH > 5


Post: { Hname  hired individual,  wage > 25}

A. Provide a formal specification for the functionality of the program. (2 points)


B. Drive Input, output test suites for the program. (2 points)
C. Drive the domain and range test suites for the program. (2 points)
D. Drive a functionality test suite for the program. (2 points)
 GOOD LUCK

4/4

You might also like