Theory of Computer Science

13
February 2011 Bachelor of Computer Application (BCA) – Semester 5 BC0052 – Theory of computer science 4 Credits Assignment Set – 1 (60 Marks) Ques1. Show that the relationis a ≡ b(mod m ) equivalence relation. Ans. Ques2. Ans.

description

Sikkim Manipal University BCA 5th sem Assignment.

Transcript of Theory of Computer Science

Page 1: Theory of Computer Science

February 2011Bachelor of Computer Application (BCA) – Semester 5

BC0052 – Theory of computer science – 4 CreditsAssignment Set – 1 (60 Marks)

Ques1. Show that the relationis a ≡ b(mod m ) equivalence relation.

Ans.

Ques2.

Ans.

Page 2: Theory of Computer Science

Ques3. Prove by the method of contradiction that is not a rational number.

Ans. A rational number is of the form p/q where , and p, q are not having any common factors.

Assume that is a rational number. So it can be written as

If p is even, then it can be written as p = 2k. Therefore 4 = 2 . Therefore q is even.

This is a contradiction to our assumption that p and q have no common factors. Therefore is not a rational number.

Ques.4. Prove by mathematical induction

Ans. (i) Base Step: Let n = 0. Then the sum on the left is zero, since there is nothing to add. The expression on the right is also zero.

If n=1, left side = = 1

Right side = = = 1.

Hence the result is true for n = 1.

(ii) Induction Hypothesis: Assume that the result to be true for n = m

Then

Adding the th term i.e. 2 to both sides of the above equation, we get,

=

=

Page 3: Theory of Computer Science

=

=

Therefore the result is true for n= m+1. Hence by mathematical induction the given result is true for all positive integers n.

Ques5. Prove that “The sum of the degrees of the vertices of a graph G is twice the number of edges”

Ans. (The proof is by induction on the number of edges ‘e‘).Case-(i): Suppose e = 1. Suppose f is the edge in G with f = uv.Then d(v) = 1, d(u) = 1. Therefore

= 2 x (number of edges)

Page 4: Theory of Computer Science

Hence by induction we get that “the sum of the degrees of the vertices of the graph G is twice the numbers of edges”.

Ques6. Prove that “T is a tree there is one and only one path between every pair of vertices”

Ans. Part 1: Suppose T is a tree. Then T is a connected graph and contains no circuits.

Since T is connected, there exists at least one path between every pair of vertices in T.

Suppose that between two vertices a and b of T, there are two distinct paths. Now, the union of these two paths will contain a circuit in T, a contradiction (since T contains no circuits).

This shows that there exists one and only one path between a given pair of vertices in T.

Part 2: Let G be a graph.

Assume that there is one and only one path between every pair of vertices in G.

This shows that G is connected.

If possible suppose that G contains a circuit.

Then there is at least one pair of vertices a, b such that there are two distinct paths between a and b. But this is a contradiction to our assumption.

So G contains no circuits. Thus G is a tree.

Page 5: Theory of Computer Science

February 2011Bachelor of Computer Application (BCA) – Semester 5

BC0052 – Theory of computer science – 4 CreditsAssignment Set – 2 (60 Marks)

Ques1. Prove that “A tree G with n vertices has (n–1) edges”

Ans. We prove this theorem by induction on the number vertices n. Basic step: If n = 1, then G contains only one vertex and no edge. So the number of edges in G is n –1 = 1 – 1 = 0. Induction hypothesis: The statement is true for all trees with less than ‘n’ vertices. Induction step: Now let us consider a tree with ‘n’ vertices. Let ‘ek’ be any edge in T whose end vertices are vi and vj. Since T is a tree, by there is no other path between vI and vj. So by removing ek from T, we get a disconnected graph. Furthermore, T- ek consists of exactly two components (say T1 and T2). Since T is a tree, there were no circuits in T and so there were no circuits in T1 and T2. Therefore T1 and T2 are also trees.

It is clear that |V(T1)| + |V(T2)| = |V(T)| where V(T) denotes the set of vertices in T.

Also |V(T1)| and |V(T2)| are less than n.

Therefore by the induction hypothesis, we have

|E(T1)| = |V(T1)| - 1 and |E(T2)| = |V(T2)| - 1.

|E(T1)| = |V(T1)| - 1 and |E(T2)| = |V(T2)| - 1.

.

Ques2.If G= ({S}, {0, 1}, { S 0S1, S }, S) , then find L(G), the language generated by G

Page 6: Theory of Computer Science

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

Ans. 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

Page 7: Theory of Computer Science

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.

In the set notation, the language accepted by DFA can be represented as

Page 8: Theory of Computer Science

L = {ab(a + b)n | n 0} Or L = {ab(a + b)*} Therefore the DFA which accepts strings of a‟s and b‟s 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 :

Therefore the string aabb is not accepted by the machine.

Ques4. Briefly describe Moore and Mealy machines.

Page 9: Theory of Computer Science

Ans. 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 reachability 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).

Ques5.

Ans. i) Consider the string: aaab

Page 10: Theory of Computer Science

Therefore the string „aaab’ is not accepted by M.ii) Consider the string: bbaa

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

Page 11: Theory of Computer Science

Ques6. Obtain a regular expression such that L(R) = {w | w {0, 1}* with at least three consecutive 0‟s.

Ans. string consisting of 0‟s and l‟s can be represented by the regular expression (0 + 1)*

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}.