You are on page 1of 7

Bachelor of Computer Application (BCA) - Semester 5 BC0052 Theory of computer science

Question 1. Prove that A tree G with n vertices has (n1) edges. Answer 1 Problem: If T is a tree (with two or more vertices), then there exists at least two pendant (a vertex of degree 1) vertices. Solution: Let n = the number of vertices in G. Then G has n-1 edges. Now E deg(vi) = 2E = 201 - 1) = (2n-2). Now if there is only one vertex, say vi of degree 1, then deg(vi) 2 for i = 2, 3, ..., n and E deg(v, ) = 1+ E deg(v,) 1 + 2n 2 = 2n 1.
i=2

But 2n-2 2n-1 or -2 L -1. a contradiction. Therefore there are at least two vertices of degree 1. Note: If two nonadjacent vertices of a tree T are connected by adding an edge, then the resulting graph will contain a cycle. Problem

Question 2. If generated by G. Answer 2 -

then find L(G), the language

1|Page

Question 3. Obtain a DFA to accept strings of as and bs starting with the string ab. Answer 3 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

2|Page

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 as and bs 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 as and bs, can be accepted and so remain in state q2 only. The complete machine to accept the strings of as and bs starting with the string ab is shown in figure. The state q3 is called trap state or rejecting state.

3|Page

In the set notation, the language accepted by DFA can be represented as L = {ab(a + b)n n 0} Or L = {ab(a + b)*} Therefore the DFA which accepts strings of as and bs starting with the string ab is given by M = (Q, , , q0, F), where Q = {q0, q1, q2, q3}, = {a, b}, q0: initial state, F = {q2}, and the transition function is defined as

To accept the string abab: The string is accepted by the machine.

To reject the string aabb:

4|Page

Therefore the string aabb is not accepted by the machine.

Question 4. Briefly describe Moore and Mealy machines

Answer 4 -:
The automation systems we have discussed so far are limited to binary output. That is, the systems can either accept or do not accept a string. In those systems, this acceptability is decided based on the reach ability from the initial state to the final state. This property of the system produces restrictions in choosing outputs from some other alphabet, then output. You can remove this constraint using both the Moore and Mealy machine, which help in generating an output from a certain output alphabet. Let us denote the output function with the symbol . Thus, when the output of an automation system is dependent only on the present state, then, Output = (q(t)), where q(t) is the present state. The above automaton system is called a Moore machine. Alternatively, when the output of the automaton system is dependent on both the present input and the present state, then, Output = (q(t), x(t)), where q(t) is the present state and x(t) is the present input. The above automaton system is called a Mealy machine. Since the output of a Mealy machine is dependent on both the input and the present state, no output is generated when the input is a null string. This implies that when the input is ^, the output is also ^. However, in case of the Moore machine, there is some output of the Moore machine which is only dependent on the present state and not on the present input. Hence, when the input to a Moore machine is ^, the output is (q0).

Question 5. Draw the state diagram for the finite automation


defined by

where

5|Page

Answer 5 i) Consider the string: aaab

Therefore the string aaab is not accepted by M.

ii) Consider the string: bbaa

Therefore bbaa is not accepted by M. iii) State diagram:

6|Page

Question 6. Obtain a regular expression such that


three consecutive 0s. Answer 6 A string consisting of 0s and ls can be represented by the regular expression (0 + 1)*

with at least

This arbitrary string can precede three consecutive zeros and can follow three consecutive zeros. Therefore the regular expression can be written as (0 +1)* 000(0+1)*. The language corresponding to the regular expression can be written as L(R) = { (0 + 1)m000(0+1)n m 0 and n 0}.

7|Page

You might also like