Computability and Languages - Sample Final Exam | CSE 460, Exams of Computer Science

Material Type: Exam; Professor: Torng; Class: Computability and Languages; Subject: Computer Science & Engineering; University: Michigan State University; Term: Fall 2000;

Typology: Exams

Pre 2010

Uploaded on 07/23/2009

koofers-user-1lu
koofers-user-1lu 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE 460 - Sample Final Exam
Exam #
Fall Semester, 2000
Name
The 1.0 points on this exam sum to 26.
The 2.0 points on this exam sum to 23.
The 3.0 points on this exam sum to 21.
The 4.0 points on this exam sum to 16.
There is one question on Chomsky Normal Form worth a total of 3 extra credit 4.0 points.
1. Draw the computation tree of PDA Mon input string aabb. Is the input string accepted? [4,
1.0]
Q={B, C, D , E, F, G, H }
Σ = {a, b}
Γ = {a, X, Y, Z }
q0=B
Z0=Z
A={E, H }
δ:
Move Current Input Top of Next Stack
Number State Symbol Stack State Update
---------------------------------------------------------
1 B /\ Z C X
2 B /\ Z F Y
3 C a X C aX
4 C a a C aa
5 C b a D /\
6 D b a D /\
7 D /\ X E X
8 F a Y F aaY
9 F a a F aaa
10 F b a G /\
11 G b a G /\
12 G /\ Y H Y
1
pf3
pf4
pf5

Partial preview of the text

Download Computability and Languages - Sample Final Exam | CSE 460 and more Exams Computer Science in PDF only on Docsity!

CSE 460 - Sample Final Exam

Exam

Fall Semester, 2000

Name

The 1.0 points on this exam sum to 26. The 2.0 points on this exam sum to 23. The 3.0 points on this exam sum to 21. The 4.0 points on this exam sum to 16.

There is one question on Chomsky Normal Form worth a total of 3 extra credit 4.0 points.

  1. Draw the computation tree of PDA M on input string aabb. Is the input string accepted? [4, 1.0] - Q = {B, C, D, E, F, G, H} - Σ = {a, b} - Γ = {a, X, Y, Z} - q 0 = B - Z 0 = Z - A = {E, H} - δ: Move Current Input Top of Next Stack Number State Symbol Stack State Update --------------------------------------------------------- 1 B /\ Z C X 2 B /\ Z F Y

3 C a X C aX 4 C a a C aa 5 C b a D /
6 D b a D /
7 D /\ X E X

8 F a Y F aaY 9 F a a F aaa 10 F b a G /
11 G b a G /
12 G /\ Y H Y

  1. Consider the following grammar G 1 defined in abbreviated format. S → SSS | b.

(a) Give the 4 shortest strings in L(G 1 ). [2, 1.0] (b) Draw a leftmost derivation of the string bbbbb. [2, 1.0] (c) Draw the derivation tree that corresponds to your leftmost derivation above. [2, 1.0] (d) Draw the rightmost derivation that corresponds to your leftmost derivation above. [2, 1.0] (e) Prove that G 1 is an ambiguous grammar. [2, 2.0] (f) What is L(G 1 )? [2, 1.0] (g) Give a regular expression r such that L(r) = L(G 1 ). [2, 1.0]

  1. Given the following two grammars G 1 and G 2 , construct a new grammar G 3 such that L(G 3 ) = L(G 1 ) ∪ L(G 1 )L(G 2 ). [2, 2.0] - G 1 : S → SSS | a - G 2 : S → b | bb | bbb
  2. Consider the following grammar G.
    • V = {S, U }
    • Σ = {a, b}
    • Start variable is U
    • Productions
      • U → bbU | S
      • S → aS | λ

Suppose M is the PDA that results from applying the construction given in class so that L(M ) = L(G). List all the transitions in M. [2, 2.0]

  1. Questions about regular language constructions

(a) Suppose we apply the construction covered in class to construct an NFA-λ M 3 from NFA-λ M 1 with 8 accepting states and NFA-λ M 2 with 7 accepting states such that L(M 3 ) = L(M 1 ) ∪ L(M 2 ). How many accepting states does M 3 have? [2, 2.0] (b) Suppose we apply the construction of Theorem 4.1 and construct an FSA M 5 from NFA M 4 with 3 states total, 1 of which is accepting, such that L(M 5 ) = L(M 4 ). How many accepting states does M 5 have counting all states that are unreachable from the initial state? [2,2.0]

  1. C++^ Program P and language Y (P )

(a) For any program P , which of the following represents Y (P ): [2, 1.0]

  • The set of strings P accepts.
  • The set of strings P rejects.
  • The set of strings P loops on. (b) Suppose program P loops on input string aa. Is it possible that Y (P ) is solvable? Why or why not? [2, 3.0]

i. We show L 1 ∩ L = L 2 where L 1 is a context-free language and L 2 is a half-solvable but not solvable language. ii. We show that L 1 ∩ L 2 = L where L 1 is a context-free but not regular language and L 2 is a finite language. iii. We show that L 1 ∩ L = L 2 where L 1 is a context-free language and L 2 is not a context-free language. iv. We show that L 1 ∩ L 2 = L where L 1 is a context-free language and L 2 is a context- free language. v. We show that L 1 ∩L = L 2 where L 1 is a regular language and L 2 is not a half-solvable language.

  1. Consider the language L = {aibj^ | j < i}. Let n be the integer from the pumping lemma. For each of the following strings, state whether or not they can or cannot be used in a pumping lemma proof that L is not regular. For those which can be used, give a value of k that works. For those which cannot be used, describe why they cannot be used. [3, 2.0] and [2, 4.0]

(a) anbn (b) a^11 b^10 (c) a^2 nbn (d) a^2 n+1b^2 n (e) (ab)na

  1. Provide the start of a table which proves that all the strings in aa∗^ are pairwise distinguishable with respect to the language T W OCOP IES = {ww | w ∈ {a, b}∗}. [2, 4.0]
  2. Consider grammar G = ({S}, {a, b}, S, S → ab|aSb) and the language AB = {anbn^ | n ≥ 1 }.

(a) In order to prove that L(G) ⊆ AB, which of the following statements would we try and prove? Circle your answer. [2, 2.0]

  • S ⇒∗ G x implies x ∈ AB
  • x ∈ AB implies S ⇒∗ G x (b) Modify the above statement so that it represents an infinite set of statements parame- terized by n, the number of steps required to derive string x. [2, 2.0] (c) Suppose we prove your answer to part (b) is correct using induction on n. Prove the base case. [2, 2.0] (d) Now consider the inductive case. Is a strong induction hypothesis required? Why or why not? [2, 3.0]
  1. Suppose your are using a debugger to check the correctness of a program P. First describe how debuggers such as ddd and gdb operate on P. Next suppose the halting problem is solvable. Describe how this might change the way a debugger operates on P. [2, 3.0]
  2. Ambiguous grammars

(a) Define what it means for a CFG G to be ambiguous. [2, 1.0] A grammar is ambiguous if there exists some string x ∈ L(G) such that there are two distinct parse trees for string x.

(b) Identify which one of the following statements most accurately represents why we do not like ambiguous grammars. Circle your answer. [2, 3.0]

  • If the grammar for a programming language is ambiguous, there is more than one way to interpret the meaning of some programs.
  • If the grammar for a programming language is ambiguous, there is more than one way to write a program to solve some problems.
  • If the grammar for a programming language is ambiguous, there is more than one way to build a compiler for that programming language.
  1. Let EM P T Y R and EM P T Y G be defined as follows:
  • EM P T Y R
  • Input: regular expression r
  • Question: Is L(r) = {}?
  • EM P T Y G
  • Input: CFG G
  • Question: Is L(G) = {}?

Suppose f is a function that shows that EM P T Y R ≤ EM P T Y G.

(a) Give a specification for f. That is, state what its input and output should be and how they should be related to each other. [2, 2.0] (b) Give an algorithm f that shows that EM P T Y R ≤ EM P T Y G. You do not need to specify all the details of your algorithm, but your answer should be fairly complete. One possibility is to describe this algorithm in terms of another algorithm we have seen in class highlighting where this algorithm is different from the previous construction. [2, 4.0]

  1. For program P ′′′, assume that the input alphabet is { 0 , 1 }. Consider the following program P 3
    • Input: A program P ′^ and an integer x which is input for program P ′
    • Output: A program P ′′′^ as follows: bool main(string z) { P’(x); if ((|z| % 2) == 0) return(no); else return(yes); } bool P’(int x) /* Details unspecified */

(a) If P ′^ halts on x, what is Y (P ′′′)? [2, 1.0] (b) If P ′^ loops on x, what is Y (P ′′′)? [2, 1.0] (c) This program P 3 can be used to prove that the halting problem transforms to some of the following problems. Identify all such problems, and for those which this does not apply, state whether or not there is a Yes→No violation or a No→Yes violation. You must get at least 5 correct to receive any credit. [2, 4.0] i. Input: Program P. Yes/No Question: Is Y (P ) nonempty?

  1. To receive any credit for the following problem, you must use the algorithm described in the textbook. Consider the following grammar with start variable S.

S → T U V, T → λ | bT, U → λ | aU, V → λ | ccV

(a) Show the grammar that results after eliminating null productions. [1, extra credit 4.0] (b) Show the grammar that results after eliminating unit productions. [1, 4.0] (c) Show the grammar in Chomsky Normal Form. [1, 4.0]