SUBJECT: DISCRETE STRUCTURE & APPLICATIONS CODE: BCT2083 FACULTY OF INDUSTRIAL SCIENCES & TECHNOLOGY TOPIC: Chapter 5 Modeling Computation TUTORIAL 5 DURATION: 2 weeks (week 14-15) Week 14 1. Suppose A 01. Describe all strings belonging to A. 2. Suppose a phrase-structure grammar has productions S S0, S A1, A 0. Find a derivation of 01, 0100, and 010. 3. Suppose a phrase-structure grammar has productions S 1S0, S 0A, A 0. Find a derivation of 00, 1000, and 110000. 4. Suppose a phrase-structure grammar has productions S S11, S 0A, S A1, A 0. Find a derivation of 01, 0011 and 011111. 5. Let G be the phrase-structure grammar with vocabulary V ABabS, terminal element set T ab, start symbol S, and production set P S ABaS BaA aBAB bB ab. Which of these are derivable from ABa? a) ba 6. babaa d) b e) aababa f b) aab c) bba Let G be the phrase-structure grammar with vocabulary V ABabS, terminal element set T ab, start symbol S, and production set P S ABaS BaA aBAB bB ab. Which of these are derivable from S? a) ba 8. c) aba Let G be the phrase-structure grammar with vocabulary V ABabS, terminal element set T ab, start symbol S, and production set P S ABaS BaA aBAB bB ab. Which of these are derivable from A? a) 7. b) abb b) ab c) baab d) aababa e) aba Let G be the phrase-structure grammar with vocabulary V AB01S, terminal elements T 01, start symbol S, productions P S AB0AB 1A 0B AB. Which of these are derivable from S? a) 000 b) 11 c) 0000 d) 110 e) Both 010 and 0111 9. The productions of a phrase-structure grammar are S S1, S 0A, A 1. Find a derivation of 0111. 10. What language is generated by the phrase-structure grammar if the productions are S S11, S , where S is the start symbol? 11. What is the language generated by the grammar with productions S SA, S 0, A 1A, and A 1, where S is the start symbol? BCT2083 12. Tutorial 5 In the questions below let V SAB01 and T 01. For each set of productions determine whether the resulting grammar G is (i) (ii) (iii) (iv) a) b) c) d) e) f) type 0 grammar, but not type 1, type 1 grammar, but not type 2, type 2 grammar, but not type 3, type 3 grammar. S A10, AB 0. S B, A B, B A. S AB, A 0B1, 0B1 0. S 1A, A 1, S . S 1AB, AB 0B, B 0, A 1B. S 0B, B 1A, B 0, A 0B. 13. Let G = (V, T, S, P), where V = {a, c, A, B, S}, T = {a, c}, S is a start symbol and productions P = {S → ABc, A → BB, B → ac, A → Bc}. If word w = acacacc belongs to the language generated by this productions, construct the derivation tree for w. Then, write the language of this grammar. 14. The production rules of a grammar for simple arithmetic expression are: ‹ expression › ::= ‹ digit ›| (‹ expression ›) | + (‹ expression ›) | − (‹ expression ›) | ‹ expression › ‹ operator › ‹ expression › ‹ digit › ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ‹ operator › ::= + | − | * | / | ↑ Construct a derivation tree for arithmetic expression 5 2 3 and 8 2 / 3 . 15. Draw the state diagram for the Finite State Machine with the following state table. f input State s0 s1 s2 s3 16. 0 s0 s2 s2 s1 g input 1 s1 s2 s0 s2 0 1 1 0 1 1 0 0 1 1 Construct a state table for the Finite State Machine with the following state diagram x,0 x,1 x,1 y,0 s0 s1 s2 y,0 y,1 2 BCT2083 17. Tutorial 5 Given the finite state machines with the following state table. Determine the output string if the input strings is 01101. f input State 0 s0 s2 s2 s0 s1 s2 g input 1 s1 s2 s0 0 a a b 1 b a a 18. What is the output produced by the following finite-state machine when the input string is 11101? 19. In the questions below determine the output for each input string, using this state table. s0 s1 s2 s3 a) 1111. b) 10111. f input: 0 s1 s2 s1 s3 c) 000. g input: 1 0 s2 1 s0 0 s3 1 s1 0 1 1 0 1 1 d) 11000. Week 15 20. Suppose that A 11101 and B 010. Find AB. 21. Suppose that A 11101 and B 010. Find BA. 22. Let A 110. Which strings belong to A? 23. Let A 011. Find A2 and A3. 24. Find the Kleene closure of A 1. 25. Find the Kleene closure of A 00. 26. Find the Kleene closure of A 012. 3 BCT2083 Tutorial 5 27. Find the set recognized by the following deterministic finite-state machine. 28. Find all strings recognized by the following deterministic finite-state automaton. 29. Find all strings recognized by the following deterministic finite-state automaton. 30. Find the language recognized by the following nodeterministic finite-state automaton. 31. Find the language recognized by the following nodeterministic finite-state automaton. 4 BCT2083 Tutorial 5 ANSWERS CHAPTER 5: Modeling Computation 1. A consists of all strings of 0s and 1s, including the empty string. 5. 6. 7. 8. a and e b a, d, e e 10. The language generated is the set of all strings consisting of an even number of 1s and no other symbols. 11. The set of all bit strings that consist of a 0 followed by an arbitrary number of 1s. 12. a) i. 13. L(G) = { amc4, m positive integers} 17. ababa 18. 10000. 19. The strings in A are those in which each 0 is preceded by at least one 1. 20. AB 1011011100100110. 21. BA 0101100110110111001. 22. a) 1110 b) iii. c) i. d) iv. e) ii. f) iv. b) 11011 c) 101 d) 11000 000111101111and 000001101111011011001101111110111111. 1n n 012…. 02n n 012…. 26. All strings of 0s, 1s, and 2s. 27. The set represented by (01). 28. All bit strings with no 1s. 29. All bit strings with an even number of 1s. 00010. 101n01n0 n 0. 5