You are on page 1of 11

February 2011

Master of Computer Application (MCA) – Semester 5


MC0082 – Theory of Computer Science – 4 Credits
(Book ID: B0970)
Assignment Set – 1 (60 Marks)

Answer the following : 6×10 = 6


1. Define the terms: Graph, finite graph, infinite graph, incidence, degree, isolated vertex,
pendent vertex, null graph.
10 marks

{ }
2. Generate the language L (G) = a n b n c n n ≥ 1 by the following grammar.

G = ({S, B,C},{a, b, c}, S , Φ )

where Φ consists of productions,


S → asBC
S → aBC
CB → BC
aB → ab
bB → bb
bC → bc
cC → cc
10 marks

3. Prove that the sum of the degrees of the vertices of a graph G is twice the number of edges
10 marks

4. Obtain a DFA to accept strings of a’s and b’s starting with the string ab.
10 marks

5. Write briefly about the concept of Deterministic Finite Automata (DFA)


10 marks
6. Convert the Moore machine M1 whose state table is given in table below into an equivalent
Mealy machine
Moore Machine
Next state Output
Present State
Input a = 0 Input a =1
→ q0 q1 q2 1
q1 q3 q2 0
q2 q2 q1 1
q3 q0 q3 1

10 marks

With Lots of Luck 1


February 2011
Master of Computer Application (MCA) – Semester 5
MC0082 – Theory of Computer Science – 4 Credits
(Book ID: B0970)
Assignment Set – 2 (60 Marks)

Answer the following : 6×10 = 6


1. Prove by mathematical induction that
n(n + 1 ) (2n + 1)
12 + 2 2 + 3 2 + .... + n 2 =
6
10 marks

2. Prove the theorem


If L1 and L2 are regular, then the regular language is closed under intersection.

10 marks

3. Construct a grammar for the language.

{
L = ai b j i , j ≥ 1, i≠j } 10 marks

4. Obtain a PDA to accept the language L = {anbn / n ≥ 1} by a final state


10 marks
5. State and prove pumping lemma for Context Free Languages
10 marks

6. Find a Turing machine to accept the language containing string’s of 0’s and 1’s ending with
011 10 marks

With Lots of Luck 2


Assignment Set – 1(ANSWER-1)

Graph theory is the study of graphs, mathematical structures used to model pairwise relations between objects
from a certain collection. A "graph" in this context refers to a collection of vertices or 'nodes' and a collection of
edges that connect pairs of vertices. A graph may be undirected, meaning that there is no distinction between the
two vertices associated with each edge, or its edges may be directed from one vertex to another; see graph
(mathematics) for more detailed definitions and for other variations in the types of graphs that are commonly
considered. The graphs studied in graph theory should not be confused with graphs of functions or other kinds of
graphs.

Graphs are one of the prime objects of study in Discrete Mathematics. Refer to Glossary of graph theory for basic
definitions in graph theory.

Finite and infinite graphs

A finite graph is a graph G = (V, E) such that V and E are finite sets. An infinite graph is one with an infinite set of
vertices or edges or both.

Most commonly in graph theory it is implied that the graphs discussed are finite. If the graphs are infinite, that is
usually specifically stated.
In graph theory, the degree (or valency) of a vertex of a graph is the number of edges incident to the vertex, with
loops counted twice. The degree of a vertex v is denoted deg(v). The maximum degree of a graph G, denoted by
Δ(G), and the minimum degree of a graph, denoted by δ(G), are the maximum and minimum degree of its vertices.
In the graph on the right, the maximum degree is 3 and the minimum degree is 0. In a regular graph, all degrees
are the same, and so we can speak of the degree of the graph.
In one more generalized notion,E is a set together with a relation of incidence that associates with each edge two
vertices.
An isolated vertex is a vertex with degree zero; that is, a vertex that is not an endpoint of any edge.
A leaf vertex (also pendant vertex) is a vertex with degree one. In a directed graph, one can distinguish the
outdegree (number of outgoing edges) from the indegree (number of incoming edges).
In the mathematical field of graph theory, the null graph or the empty graph is either the graph with no vertices
and (hence) no edges, or any graph with no edges.

With Lots of Luck 3


The null graph (in the former sense) is the initial object in the category of graphs, according to some definitions of
a category of graphs. Having no vertices, the null graph therefore also has no connected components. Thus,
although the null graph is a forest (a graph with no cycles), it is not a tree, as trees have one connected component.

Assignment Set – 1(ANSWER-2)

We generate the language for n = 2. That is, we derive the string a2b2c2.

S ⇒ aSBC

⇒ aaBCBC

⇒ aaBBCC

⇒ aabBCC

⇒ aabbCC

⇒ aabbcC

⇒ aabbcc

Assignment Set – 1(ANSWER-3)

Let G is a connected graph.


If G has no circuit, then G is a spanning tree.
If G has a circuit, then delete an edge from this circuit.
If till leaves the graph connected. If there are more circuits, repeat the operation till an edge from the last circuit is
deleted, Leaving the graph connected, circuit less and contain all the vertices of G thus the sub graph obtained a
spanning tree of G.
Hence every connected graph has at least one spanning tree.
Then a graph G is connected if and only if it has a spanning tree is ture.

Assignment Set – 1(ANSWER-4)

It is clear that the string should start with ab and so, the minimum string that can be accepted by the machine is ab.
To accept the string ab, we need three states and the machine can be written as

where q2 is the final or accepting state. In state q0, if the input symbol is b, the machine should reject b (note that
the string should start with a). So, in state q0, on input b, we enter into the rejecting state q3. The machine for this
can be of the form

With Lots of Luck 4


The machine will be in state q1, if the first input symbol is a. If this a is followed by another a, the string aa should
be rejected by the machine. So, in state q1, if the input symbol is a, we reject it and enter into q3 which is the
rejecting state. The machine for this can be of the form

Whenever the string is not starting with ab, the machine will be in state q3 which is the rejecting state. So, in state
q3, if the input string consists of a’s and b’s of any length, the entire string can be rejected and can stay in state q3
only.
The resulting machine can be of the form

The machine will be in state q2, if the input string starts with ab. After the string ab, the string containing any
combination of a’s and b’s, can be accepted and so remain in state q2 only. The complete machine to accept the
strings of a’s and b’s starting with the string ab is shown in figure.
The state q3 is called trap state or rejecting state.

With Lots of Luck 5


Assignment Set – 1(ANSWER-5)
A DFA is a 5-tuple or quintuple M=(Q, ∑, , q0, F)
Q is non-empty, finite set of states.
∑ is non-empty, finite state set of input alphabet.
is transition function, which is mapping from Q X ∑ to Q. for this transition function the parameters to be passed
are state and input symbols. Based on the current state and input symbols, the machine may enter into another
state.
q0 Q is the start state.
F Q is a set of accepting or final state.
Note: for each input symbol a, from a given state there is exactly one transition and we are sure to which state the
machine enters. So the machine is called Deterministic Machine.

Assignment Set – 1(ANSWER-6)

Conversion of Mealy Machine into Moore Machine:


Consider the following steps
Step 1: For a state qi determine the number of outputs that are available in θ state table of the Mealy machine.
Step 2:If the outputs corresponding to state qi in the next state columns are same, then retain state qi as it is. Else,
break qi into different states with the number of new states being equal to the number of different outputs of qi.
Step 3:Rearrange the states and outputs in the format of Moore machine.
The common output of the new state table can be determined by examining the outputs under the next state
columns of the Mealy machine.
Step 4:If the output in the constructed state table corresponding to the initial state is 1, then this specifies the
acceptance of the null string ^ by Mealy machine. Hence, to make both the Mealy and Moore machines equivalent,
we either need to ignore the corresponding to null string or we need to insert a new initial state at beginning whose
output os 0; the other row elements in this case would remain the same.
Let us first transform each column of inputs into the pairs of the next state and the output as shown in the
following table.
Present State Input a = 0 Input a = 1
State Output State Output
q0 q1 0 q2 1
q1 q3 1 q2 1
q2 q2 1 q1 0
q3 q0 1 q3 1
Since there are no two states in the above state table which have identical row elements, the state table as shown
represents the equivalent Mealy machine for the Moore machine depicted above.

With Lots of Luck 6


Assignment Set – 2(ANSWER-1)

Assignment Set – 2(ANSWER-2)

With Lots of Luck 7


Assignment Set – 2(ANSWER-3)

We decompose where

Grammar for L1: Set of production for L1

A → aA

A → aB

B → aBb

B → ab

Where VT = {a, b} , VN = {A, B}

A is a starting symbol.

Grammar for L2 :

VT = {a, b} VN = {C, D}, C is starting symbol.

Productions: C → Cb

C → Db

D → aDb

D → ab

Now by adding the two sets of productions, S → A, S → C with S as the starting symbol, we get the grammar

where : S → A, S → C, A → aA, A → aB, B → aBb, B → ab, C → Cb,


C → Bb.

Assignment Set – 2(ANSWER-4)

General Method: Since n number of a s should be followed by n number of b’s, let us push all the symbols on to
the stack as long as the scanned input symbol is ‘a’. Once we encounter b’s, we should see that for each ‘b’ in the

With Lots of Luck 8


input, there should be corresponding ‘a’ on the stack. When the input pointer reaches the end of the string, the
stack should be empty. If stack is empty, it indicates that the string scanned has n number of a’s followed by n
number of b’s. Step 1: Let q0 be the start and Z0 be the initial symbol the stack. As long as the next input symbol
to the scanned is ‘a’, irrespective of what is there on the stack, keep pushing all the symbols on to the stack and
remain in q0. The transitions defined for this can be of the form
(q0, a, Z0) = (q0, aZ0)
(q0, a, a) = (q0, aa)
Step 2: In state q0, if the next input symbol to be scanned is ‘b’ and if the top of the stack is ‘a’, change the state to
q1 and delete one ‘b’ from the stack. The transition for this can be of the form (q0, b, a) = (q1, )
Step 3: Once the machine is in state q1, the rest of the symbols to be scanned will be only b’s and for each ‘b’
there should be corresponding symbol ‘a’ on the stack. Therefore, as the scanned input symbol is b and if there is a
matching ‘a’ on the stack, remain in q1 and delete the corresponding ‘a’ from the stack. The transitions defined for
this can be of the form
(q1, b, a) = (q1, )
Step 4: In state q1, if the next input symbol to be scanned is and if the top of the stack is Z0, change the state to q2
which is an accepting state. The transition defined for this can be of the form (q1, , Z0) = (q2, Z0)

Assignment Set – 2(ANSWER-5)


Statement: Let L be the context free language and is infinite. Let Z be sufficiently long string and z L so that |z| n
where n is some positive integer. If the string z can be decomposed into combination of strings z = uvwxy.
Such that |vwx| n, |vx| 1, then uvi wiy L for i=0,1,2,…….
Proof of Pumping Lemma:
By pumping lemma, it is assumed that string z L is finite and is context free language. We know that z is string of
terminal which is derived by applying series of productions.
Case 1: To generate a sufficient long string z, one or more variables must be recursive. Let us assume that the
language is finite, the grammar has a finite number of variables and each has finite length. The only way to derive
sufficiently long string using such productions is that the grammar should have one or more recursive variables.
Assume that no variable is recursive.
Since no non terminal is recursive, each variable must be defined. Since those variables are also non recursive,
they to be defined in terms of terminal and other variables and so on.

From this we conclude that there is a limit length of the string that is generated from the start symbol S. this
contradicts our assumption that the language is finite.
Therefore, the assumption that one or more variable are non recursive is incorrect.
This means that this means that one or more variable are non recursive and hence the proof.
Case 2: The string z L implies that after applying some / all production some number of times, we get finally
string of terminal and the derivation stops.
Let z L is sufficiently long string and so the derivation must have involved recursive use of some non terminal A
and the derivation must have the form:
*

Note that any derivation should start from the start symbol S.

Assignment Set – 2(ANSWER-6)

With Lots of Luck 9


The DFA which accepts the language consisting of 0 s and 1 s ending with the string 001 is shown
below

The transition table for the DFA is shown below.


01
q0 q1 q0
q1 q1 q2
q2 q1 q3
q3 (final state) q1 q0
For each scanned input symbol (either 0 or 1), in whichever state the DFA was in, TM also
enters into the same states on same input symbols, replacing 0 by 0 and 1 by 1 and the read-
write head moves towards right. Therefore, the transition table for DFA and TM remains same
(the format may be different. It is evident in both the transition tables). So the transition table
for TM recognizes the language consisting of 0 s and 1 s ending with a substring 001
States
01□
q0 q1, 0, R q0, 1, R
q1 q1, 0, R q2, 1, R
q2 q1, 0, R q3, 1, R
q3 q1, 0, L q0, 1, R q4, □, R
q4 - - -
Therefore, the TM to recognize the given language is given by
Q = {q0, q1, q2, q3}
= {0, 1}
= {0, 1, □}, is defined above.
q0 is the start state
□ is the blank character
F = {q4} is the final character

With Lots of Luck 10

You might also like