Midterm MM Co2011 Hk231 en Da
Midterm MM Co2011 Hk231 en Da
Midterm MM Co2011 Hk231 en Da
1. (L.O.1.2)
Which of the following statements is/are true?
(I) All finite languages are regular.
(II) If L is regular so is the reverse language LR = {wR |w ∈ L}.
(III) L = {ww|w ∈ {a, b}∗ } is regular.
c = (Q, Σ, δ, q0 , Q − F ) is a
(IV) If M = (Q, Σ, δ, q0 , F ) is a minimal DFA for a regular language L then M
minimal DFA for L.
A. (I), (II), (III). B. (I), (II), (IV). C. Only (I). D. (II), (III), (IV).
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
7. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ Z ∧ yxz = ab . B. z ∈ N ∧ yxz = ab . C. z ∈ N ∧ y = xz . D. z ∈ Z ∧ y = xz .
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 4. B. 5. C. 6. D. 7.
9. (L.O.2.3) Let L be the language containing all the palindrome words where Σ = {a, b}, Which of the following
regular expressions accepts the words in language L?
A. (a+b)*(b+a)* B. a*b*b*a* C. (abba)*
D. All the other answers are incorrect.
10. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}∗ that the number of occurrences of sub-string
01 and the number of occurrences of sub-string 10 in w are the same. Which choice is CORRECT?
A. A DFA recognizing only L must have at least five states.
B. L is not a regular language.
C. The number of bit 1s and the number of bit 0s of any string of L must be the same.
D. All other choices are incorrect.
11. (L.O.1.2)
Consider the logical formula ϕ : ∀x∃y∃z(P (x, y) ∧ P (z, y) ∧ (P (x, z) → P (z, x))) and the models M1 , M2 and
M3 such that the universal set is the natural numbers set N, P M1 = {(m, n)|n < m}, P M2 = {(m, 2m)|m ∈
N} and P M3 = {(m, n)|m < n + 1} Which of following statement is true?
A. M1 |= ϕ, M2 |̸ = ϕ, M3 |̸ = ϕ. B. M1 |= ϕ, M2 |= ϕ, M3 |= ϕ.
C. M1 |̸ = ϕ, M2 |= ϕ, M3 |= ϕ. D. M1 |̸ = ϕ, M2 ̸|= ϕ, M3 |= ϕ.
12. (L.O.1.3)
(i−1)/2 i/2
X X
A. s = 2k ∧ (i ≤ n + 1). B. s = 2k ∧ (i ≤ n).
k=0 k=0
(i−1)/2 i/2
X X
C. s = 2k. D. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
Question 13– Question 14 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc,
v = cb be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
13. The language Lbc of all strings with b and c alternating, moreover starting with b and ending with c, is
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
14. The language L of all strings with b and c alternating is determined by which of the following regular
expressions?
A. IV B. III C. II D. I
15. Consider the following statement: “A female athlete won every sports prize and her brother also
won some mathematics prize.” We define some predicates below to symbolize the given statement
16. (L.O.1.3)
A. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }. B. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }.
C. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }. D. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }.
19. (L.O.1.1) Let P and Q be binary predicates and S be nullary predicates. Which formulas are valid?
(I) ∀x∀y(P (x) → P (y)) ∧ (P (y) → P (x)) (II) ∃y((∀xP (x)) → P (y))
(III) (∀xP (x) → S) → ∃x(P (x) → S) (IV) ∀x(P (x) ∨ Q(x)) → (∀xP (x)) ∨ (∃xQ(x))
A. Only (II), (III), and (IV) B. Only (II) and (III)
C. Only (I), (II), and (IV) D. Only (III) and (IV)
20. (L.O.2.3) Which of the following languages is accepted by the DFA over Σ = {0, 1, 2} given below?
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . END OF EXAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1. (L.O.1.2)
Which of the following statements is/are true?
(I) All finite languages are regular.
(II) If L is regular so is the reverse language LR = {wR |w ∈ L}.
(III) L = {ww|w ∈ {a, b}∗ } is regular.
c = (Q, Σ, δ, q0 , Q − F ) is a
(IV) If M = (Q, Σ, δ, q0 , F ) is a minimal DFA for a regular language L then M
minimal DFA for L.
A. (II), (III), (IV). B. (I), (II), (III). C. (I), (II), (IV). D. Only (I).
2. (L.O.1.3)
i/2 (i−1)/2
X X
A. s = 2k ∧ (i ≤ n + 1). B. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
i/2 (i−1)/2
X X
C. s = 2k ∧ (i ≤ n). D. s = 2k.
k=0 k=0
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
5. (L.O.1.1) Let P and Q be binary predicates and S be nullary predicates. Which formulas are valid?
(I) ∀x∀y(P (x) → P (y)) ∧ (P (y) → P (x)) (II) ∃y((∀xP (x)) → P (y))
(III) (∀xP (x) → S) → ∃x(P (x) → S) (IV) ∀x(P (x) ∨ Q(x)) → (∀xP (x)) ∨ (∃xQ(x))
A. Only (III) and (IV) B. Only (II), (III), and (IV)
C. Only (II) and (III) D. Only (I), (II), and (IV)
Question 8– Question 9 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc, v = cb
be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
r = u∗ = (bc)∗ and s = v ∗ = (cb)∗ .
8. The language Lbc of all strings with b and c alternating, moreover starting with b and ending with c, is
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
A. I B. IV C. III D. II
10. (L.O.2.3) Which of the following languages is accepted by the DFA over Σ = {0, 1, 2} given below?
A. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }. B. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }.
C. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }. D. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }.
13. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ Z ∧ y = xz . B. z ∈ Z ∧ yxz = ab . C. z ∈ N ∧ yxz = ab . D. z ∈ N ∧ y = xz .
14. (L.O.2.3) Given 4 automata where Σ = {a, b} and λ is the empty string.
15. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}+ that represents a decimal number divisible
by 3. Which choice is CORRECT?
A. The number of bit 1s of any string of L must be divisible by 3.
B. All other choices are incorrect.
C. L is not a regular language.
D. The number of states of a DFA recognizing only L must be divisible by 3.
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 7. B. 4. C. 5. D. 6.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . END OF EXAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1. (L.O.1.3)
A. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }. B. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }.
C. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }. D. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }.
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 4. B. 7. C. 5. D. 6.
5. (L.O.1.2)
Consider the logical formula ϕ : ∀x∃y∃z(P (x, y) ∧ P (z, y) ∧ (P (x, z) → P (z, x))) and the models M1 , M2 and
M3 such that the universal set is the natural numbers set N, P M1 = {(m, n)|n < m}, P M2 = {(m, 2m)|m ∈
N} and P M3 = {(m, n)|m < n + 1} Which of following statement is true?
A. M1 |= ϕ, M2 |̸ = ϕ, M3 |̸ = ϕ. B. M1 ̸|= ϕ, M2 |̸ = ϕ, M3 |= ϕ.
C. M1 |= ϕ, M2 |= ϕ, M3 |= ϕ. D. M1 |̸ = ϕ, M2 |= ϕ, M3 |= ϕ.
6. (L.O.1.2)
Which of the following statements is/are true?
(I) All finite languages are regular.
(II) If L is regular so is the reverse language LR = {wR |w ∈ L}.
(III) L = {ww|w ∈ {a, b}∗ } is regular.
c = (Q, Σ, δ, q0 , Q − F ) is a
(IV) If M = (Q, Σ, δ, q0 , F ) is a minimal DFA for a regular language L then M
minimal DFA for L.
A. (I), (II), (III). B. (II), (III), (IV). C. (I), (II), (IV). D. Only (I).
9. (L.O.2.3) Which of the following languages is accepted by the DFA over Σ = {0, 1, 2} given below?
10. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}+ that represents a decimal number divisible
by 3. Which choice is CORRECT?
A. All other choices are incorrect.
B. The number of bit 1s of any string of L must be divisible by 3.
C. L is not a regular language.
D. The number of states of a DFA recognizing only L must be divisible by 3.
11. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ Z ∧ yxz = ab . B. z ∈ Z ∧ y = xz . C. z ∈ N ∧ yxz = ab . D. z ∈ N ∧ y = xz .
(i−1)/2 i/2
X X
A. s = 2k ∧ (i ≤ n + 1). B. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
i/2 (i−1)/2
X X
C. s = 2k ∧ (i ≤ n). D. s = 2k.
k=0 k=0
Question 16– Question 17 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc,
v = cb be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
r = u∗ = (bc)∗ and s = v ∗ = (cb)∗ .
16. The language Lbc of all strings with b and c alternating, moreover starting with b and ending with c, is
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
A. IV B. I C. III D. II
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
19. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}∗ that the number of occurrences of sub-string
01 and the number of occurrences of sub-string 10 in w are the same. Which choice is CORRECT?
A. A DFA recognizing only L must have at least five states.
B. All other choices are incorrect.
C. L is not a regular language.
D. The number of bit 1s and the number of bit 0s of any string of L must be the same.
20. (L.O.2.3) Let L be the language containing all the palindrome words where Σ = {a, b}, Which of the following
regular expressions accepts the words in language L?
A. (a+b)*(b+a)* B. All the other answers are incorrect. C. a*b*b*a*
D. (abba)*
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . END OF EXAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2. A. 7. C. 12. A. 17. D.
13. A.
3. B. 8. A.
18. C.
14. B.
4. C. 9. A. 19. A.
15. A.
5. C. 10. A. 20. A.
1. (L.O.1.2)
Consider the logical formula ϕ : ∀x∃y∃z(P (x, y) ∧ P (z, y) ∧ (P (x, z) → P (z, x))) and the models M1 , M2 and
M3 such that the universal set is the natural numbers set N, P M1 = {(m, n)|n < m}, P M2 = {(m, 2m)|m ∈
N} and P M3 = {(m, n)|m < n + 1} Which of following statement is true?
A. M1 |= ϕ, M2 |̸ = ϕ, M3 |̸ = ϕ. B. M1 ̸|= ϕ, M2 |= ϕ, M3 |= ϕ.
C. M1 |= ϕ, M2 |= ϕ, M3 |= ϕ. D. M1 |̸ = ϕ, M2 ̸|= ϕ, M3 |= ϕ.
2. (L.O.2.3) Let L be the language containing all the palindrome words where Σ = {a, b}, Which of the following
regular expressions accepts the words in language L?
A. (a+b)*(b+a)* B. (abba)* C. a*b*b*a*
D. All the other answers are incorrect.
3. (L.O.1.3) Given a program finding max for 3 integers a,b,c:
max=0;
if(max<a) max=a;
if(max<b) max=b;
if(max<c) max=c;
Which of the following are the weakest pre-condition ϕ and post-condition ψ for the program to be correct?
4. (L.O.1.2)
Which of the following statements is/are true?
(I) All finite languages are regular.
(II) If L is regular so is the reverse language LR = {wR |w ∈ L}.
(III) L = {ww|w ∈ {a, b}∗ } is regular.
c = (Q, Σ, δ, q0 , Q − F ) is a
(IV) If M = (Q, Σ, δ, q0 , F ) is a minimal DFA for a regular language L then M
minimal DFA for L.
A. (I), (II), (III). B. Only (I). C. (I), (II), (IV). D. (II), (III), (IV).
5. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}∗ that the number of occurrences of sub-string
01 and the number of occurrences of sub-string 10 in w are the same. Which choice is CORRECT?
A. A DFA recognizing only L must have at least five states.
B. The number of bit 1s and the number of bit 0s of any string of L must be the same.
C. L is not a regular language.
D. All other choices are incorrect.
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 4. B. 6. C. 5. D. 7.
Question 7– Question 8 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc, v = cb
be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
r = u∗ = (bc)∗ and s = v ∗ = (cb)∗ .
7. The language Lbc of all strings with b and c alternating, moreover starting with b and ending with c, is
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
8. The language L of all strings with b and c alternating is determined by which of the following regular
expressions?
A. IV B. II C. III D. I
9. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}+ that represents a decimal number divisible
by 3. Which choice is CORRECT?
A. All other choices are incorrect.
B. The number of states of a DFA recognizing only L must be divisible by 3.
C. L is not a regular language.
D. The number of bit 1s of any string of L must be divisible by 3.
11. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ Z ∧ yxz = ab . B. z ∈ N ∧ y = xz . C. z ∈ N ∧ yxz = ab . D. z ∈ Z ∧ y = xz .
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
14. (L.O.1.1) Let P and Q be binary predicates and S be nullary predicates. Which formulas are valid?
(I) ∀x∀y(P (x) → P (y)) ∧ (P (y) → P (x)) (II) ∃y((∀xP (x)) → P (y))
(III) (∀xP (x) → S) → ∃x(P (x) → S) (IV) ∀x(P (x) ∨ Q(x)) → (∀xP (x)) ∨ (∃xQ(x))
A. Only (II), (III), and (IV) B. Only (I), (II), and (IV)
C. Only (II) and (III) D. Only (III) and (IV)
15. (L.O.1.3)
A. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }. B. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }.
C. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }. D. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }.
(i−1)/2 (i−1)/2
X X
A. s = 2k ∧ (i ≤ n + 1). B. s = 2k.
k=0 k=0
i/2 i/2
X X
C. s = 2k ∧ (i ≤ n). D. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
17. (L.O.1.3)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . END OF EXAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2. A. 11. C. 17. A.
7. A. 12. A.
3. D. 18. A.
8. B. 13. C.
4. C. 14. A. 19. C.
5. A. 9. A. 15. C. 20. A.
Question 1– Question 2 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc, v = cb
be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
r = u∗ = (bc)∗ and s = v ∗ = (cb)∗ .
1. The language Lbc of all strings with b and c alternating, moreover starting with b and ending with c, is
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
2. The language L of all strings with b and c alternating is determined by which of the following regular
expressions?
A. I B. IV C. II D. III
3. Consider the following statement: “A female athlete won every sports prize and her brother also
won some mathematics prize.” We define some predicates below to symbolize the given statement
6. (L.O.1.3)
i/2 (i−1)/2
X X
A. s = 2k ∧ (i ≤ n + 1). B. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
(i−1)/2 i/2
X X
C. s = 2k. D. s = 2k ∧ (i ≤ n).
k=0 k=0
7. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}∗ that the number of occurrences of sub-string
01 and the number of occurrences of sub-string 10 in w are the same. Which choice is CORRECT?
A. All other choices are incorrect.
B. A DFA recognizing only L must have at least five states.
C. The number of bit 1s and the number of bit 0s of any string of L must be the same.
D. L is not a regular language.
9. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ Z ∧ y = xz . B. z ∈ Z ∧ yxz = ab . C. z ∈ N ∧ y = xz . D. z ∈ N ∧ yxz = ab .
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 7. B. 4. C. 6. D. 5.
11. (L.O.1.2)
Which of the following statements is/are true?
(I) All finite languages are regular.
(II) If L is regular so is the reverse language LR = {wR |w ∈ L}.
(III) L = {ww|w ∈ {a, b}∗ } is regular.
c = (Q, Σ, δ, q0 , Q − F ) is a
(IV) If M = (Q, Σ, δ, q0 , F ) is a minimal DFA for a regular language L then M
minimal DFA for L.
A. (II), (III), (IV). B. (I), (II), (III). C. Only (I). D. (I), (II), (IV).
12. (L.O.1.2)
Consider the logical formula ϕ : ∀x∃y∃z(P (x, y) ∧ P (z, y) ∧ (P (x, z) → P (z, x))) and the models M1 , M2 and
M3 such that the universal set is the natural numbers set N, P M1 = {(m, n)|n < m}, P M2 = {(m, 2m)|m ∈
N} and P M3 = {(m, n)|m < n + 1} Which of following statement is true?
A. M1 ̸|= ϕ, M2 |̸ = ϕ, M3 |= ϕ. B. M1 |= ϕ, M2 |̸ = ϕ, M3 |̸ = ϕ.
C. M1 |̸ = ϕ, M2 |= ϕ, M3 |= ϕ. D. M1 |= ϕ, M2 |= ϕ, M3 |= ϕ.
13. (L.O.2.3) Let L be the language containing all the palindrome words where Σ = {a, b}, Which of the following
regular expressions accepts the words in language L?
A. All the other answers are incorrect. B. (a+b)*(b+a)* C. (abba)*
D. a*b*b*a*
14. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}+ that represents a decimal number divisible
by 3. Which choice is CORRECT?
A. The number of bit 1s of any string of L must be divisible by 3.
B. All other choices are incorrect.
C. The number of states of a DFA recognizing only L must be divisible by 3.
D. L is not a regular language.
16. Consider a program Prod = P roduct(a, b) calculating the product a · (b − 1) of two naturals a, b where b ≥ 2.
Denote the Hoare triple of a suitable core program P to correctly compute Prod as
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
A. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }. B. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }.
C. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }. D. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }.
18. (L.O.2.3) Given 4 automata where Σ = {a, b} and λ is the empty string.
8. A. 13. B. 18. B.
3. B.
4. B. 9. D. 14. B. 19. D.
1. (L.O.2.3) Let L be the language containing all the palindrome words where Σ = {a, b}, Which of the following
regular expressions accepts the words in language L?
A. (a+b)*(b+a)* B. All the other answers are incorrect. C. (abba)*
D. a*b*b*a*
2. Consider a program Prod = P roduct(a, b) calculating the product a · (b − 1) of two naturals a, b where b ≥ 2.
Denote the Hoare triple of a suitable core program P to correctly compute Prod as
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
3. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ Z ∧ yxz = ab . B. z ∈ Z ∧ y = xz . C. z ∈ N ∧ y = xz . D. z ∈ N ∧ yxz = ab .
8. (L.O.1.2)
Which of the following statements is/are true?
(I) All finite languages are regular.
(II) If L is regular so is the reverse language LR = {wR |w ∈ L}.
(III) L = {ww|w ∈ {a, b}∗ } is regular.
c = (Q, Σ, δ, q0 , Q − F ) is a
(IV) If M = (Q, Σ, δ, q0 , F ) is a minimal DFA for a regular language L then M
minimal DFA for L.
A. (I), (II), (III). B. (II), (III), (IV). C. Only (I). D. (I), (II), (IV).
10. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}+ that represents a decimal number divisible
by 3. Which choice is CORRECT?
A. All other choices are incorrect.
B. The number of bit 1s of any string of L must be divisible by 3.
C. The number of states of a DFA recognizing only L must be divisible by 3.
D. L is not a regular language.
11. (L.O.1.3)
(i−1)/2 i/2
X X
A. s = 2k ∧ (i ≤ n + 1). B. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
(i−1)/2 i/2
X X
C. s = 2k. D. s = 2k ∧ (i ≤ n).
k=0 k=0
13. (L.O.2.3) Which of the following languages is accepted by the DFA over Σ = {0, 1, 2} given below?
14. (L.O.1.3)
A. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }. B. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }.
C. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }. D. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }.
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 4. B. 7. C. 6. D. 5.
16. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}∗
that the number of occurrences of sub-string
01 and the number of occurrences of sub-string 10 in w are the same. Which choice is CORRECT?
A. A DFA recognizing only L must have at least five states.
B. All other choices are incorrect.
C. The number of bit 1s and the number of bit 0s of any string of L must be the same.
D. L is not a regular language.
17. (L.O.1.1) Let P and Q be binary predicates and S be nullary predicates. Which formulas are valid?
(I) ∀x∀y(P (x) → P (y)) ∧ (P (y) → P (x)) (II) ∃y((∀xP (x)) → P (y))
(III) (∀xP (x) → S) → ∃x(P (x) → S) (IV) ∀x(P (x) ∨ Q(x)) → (∀xP (x)) ∨ (∃xQ(x))
A. Only (II), (III), and (IV) B. Only (III) and (IV)
C. Only (I), (II), and (IV) D. Only (II) and (III)
18. (L.O.1.3) Given a program finding max for 3 integers a,b,c:
max=0;
if(max<a) max=a;
if(max<b) max=b;
if(max<c) max=c;
Which of the following are the weakest pre-condition ϕ and post-condition ψ for the program to be correct?
Question 19– Question 20 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc,
v = cb be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
r = u∗ = (bc)∗ and s = v ∗ = (cb)∗ .
19. The language Lbc of all strings with b and c alternating, moreover starting with b and ending with c, is
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
A. IV B. I C. II D. III
5. D. 11. A. 16. A.
6. A. 12. A. 17. A.
1. (L.O.1.3)
(i−1)/2 (i−1)/2
X X
A. s = 2k ∧ (i ≤ n + 1). B. s = 2k.
k=0 k=0
i/2 i/2
X X
C. s = 2k ∧ (i ≤ n + 1). D. s = 2k ∧ (i ≤ n).
k=0 k=0
2. Consider the following statement: “A female athlete won every sports prize and her brother also
won some mathematics prize.” We define some predicates below to symbolize the given statement
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 4. B. 6. C. 7. D. 5.
4. (L.O.2.3) Let L be the language containing all the palindrome words where Σ = {a, b}, Which of the following
regular expressions accepts the words in language L?
A. (a+b)*(b+a)* B. (abba)* C. All the other answers are incorrect.
D. a*b*b*a*
5. (L.O.1.3)
6. (L.O.2.3) Which of the following languages is accepted by the DFA over Σ = {0, 1, 2} given below?
7. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ Z ∧ yxz = ab . B. z ∈ N ∧ y = xz . C. z ∈ Z ∧ y = xz . D. z ∈ N ∧ yxz = ab .
9. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}∗ that the number of occurrences of sub-string
01 and the number of occurrences of sub-string 10 in w are the same. Which choice is CORRECT?
A. A DFA recognizing only L must have at least five states.
B. The number of bit 1s and the number of bit 0s of any string of L must be the same.
C. All other choices are incorrect.
D. L is not a regular language.
10. (L.O.1.3)
A. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }. B. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }.
C. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }. D. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }.
12. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}+ that represents a decimal number divisible
by 3. Which choice is CORRECT?
A. All other choices are incorrect.
B. The number of states of a DFA recognizing only L must be divisible by 3.
C. The number of bit 1s of any string of L must be divisible by 3.
D. L is not a regular language.
Question 14– Question 15 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc,
v = cb be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
r = u∗ = (bc)∗ and s = v ∗ = (cb)∗ .
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
15. The language L of all strings with b and c alternating is determined by which of the following regular
expressions?
A. IV B. II C. I D. III
17. Consider a program Prod = P roduct(a, b) calculating the product a · (b − 1) of two naturals a, b where b ≥ 2.
Denote the Hoare triple of a suitable core program P to correctly compute Prod as
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
18. (L.O.1.2)
Consider the logical formula ϕ : ∀x∃y∃z(P (x, y) ∧ P (z, y) ∧ (P (x, z) → P (z, x))) and the models M1 , M2 and
M3 such that the universal set is the natural numbers set N, P M1 = {(m, n)|n < m}, P M2 = {(m, 2m)|m ∈
N} and P M3 = {(m, n)|m < n + 1} Which of following statement is true?
A. M1 |= ϕ, M2 |̸ = ϕ, M3 |̸ = ϕ. B. M1 ̸|= ϕ, M2 |= ϕ, M3 |= ϕ.
C. M1 |̸ = ϕ, M2 |̸ = ϕ, M3 |= ϕ. D. M1 |= ϕ, M2 |= ϕ, M3 |= ϕ.
20. (L.O.2.3) Given 4 automata where Σ = {a, b} and λ is the empty string.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . END OF EXAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1. (L.O.2.3) Let L be the language containing all the palindrome words where Σ = {a, b}, Which of the following
regular expressions accepts the words in language L?
A. a*b*b*a* B. (a+b)*(b+a)* C. (abba)*
D. All the other answers are incorrect.
2. Consider the following statement: “A female athlete won every sports prize and her brother also
won some mathematics prize.” We define some predicates below to symbolize the given statement
i/2 (i−1)/2
X X
A. s = 2k ∧ (i ≤ n). B. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
(i−1)/2 i/2
X X
C. s = 2k. D. s = 2k ∧ (i ≤ n + 1).
k=0 k=0
4. (L.O.3.2)
Consider the following finite automaton:
a a
A B C a
b b
a
a E b
b
a b
b D G a F
b
What is the number of states in a minimal DFA (equivalent to the above FA)?
A. 5. B. 4. C. 6. D. 7.
{ϕ} P {ψ}
Let E = { u = (b − v) · a} be a “good” invariant of the program Prod, assuming the full format as follows.
{(a ≥ 1) ∧ (b ≥ 2)}
u = 0;
v = b;
{u = 0 ∧ v = b}
E
while ( v != Lb )
{
..
.P
}
{u = a · (b − v)}
6. (L.O.1.3)
A. ϕ = {a ∈ R, b ∈ N}, ψ = {y = xz }. B. ϕ = {a ∈ R, b ∈ N}, ψ = {y = ab }.
C. ϕ = {a ∈ R, b ∈ Z+ }, ψ = {y = ab }. D. ϕ = {a ∈ R, b ∈ Z}, ψ = {y = ab }.
8. (L.O.1.3)
Consider program P with precondition and postcondition as in Question 8. Then the invariant form to prove
the partial correctness of P is
A. z ∈ N ∧ yxz = ab . B. z ∈ Z ∧ yxz = ab . C. z ∈ N ∧ y = xz . D. z ∈ Z ∧ y = xz .
9. (L.O.1.1) Let P and Q be binary predicates and S be nullary predicates. Which formulas are valid?
(I) ∀x∀y(P (x) → P (y)) ∧ (P (y) → P (x)) (II) ∃y((∀xP (x)) → P (y))
(III) (∀xP (x) → S) → ∃x(P (x) → S) (IV) ∀x(P (x) ∨ Q(x)) → (∀xP (x)) ∨ (∃xQ(x))
A. Only (II) and (III) B. Only (II), (III), and (IV)
C. Only (I), (II), and (IV) D. Only (III) and (IV)
11. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}∗ that the number of occurrences of sub-string
01 and the number of occurrences of sub-string 10 in w are the same. Which choice is CORRECT?
A. L is not a regular language.
B. A DFA recognizing only L must have at least five states.
C. The number of bit 1s and the number of bit 0s of any string of L must be the same.
D. All other choices are incorrect.
Question 12– Question 13 use the same description as follows: Denote an alphabet Σ = {b, c}, and let u = bc,
v = cb be strings of length 2 in Σ∗ . Define L(r) and L(s) respectively be languages determined by regular expressions
r = u∗ = (bc)∗ and s = v ∗ = (cb)∗ .
12. The language Lbc of all strings with b and c alternating, moreover starting with b and ending with c, is
(I) L(s); (II) L(r) + L(s); (III) L(r); (IV) L(r) · L(s).
13. The language L of all strings with b and c alternating is determined by which of the following regular
expressions?
A. III B. IV C. II D. I
16. (L.O.2.3) Given 4 automata where Σ = {a, b} and λ is the empty string.
18. (L.O.2.3) Which of the following languages is accepted by the DFA over Σ = {0, 1, 2} given below?
20. (L.O.2.3) Let L be the language consisting of string w ∈ {0, 1}+ that represents a decimal number divisible
by 3. Which choice is CORRECT?
A. L is not a regular language.
B. All other choices are incorrect.
C. The number of states of a DFA recognizing only L must be divisible by 3.
D. The number of bit 1s of any string of L must be divisible by 3.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . END OF EXAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .