1 Kingdom of Saudi Arabia
Ministry of Education Umm AlQura University
Adam University College, female branch Computer Science Department
ุฉูุฏูุนุณูุง ุฉูุจุฑุนูุง ุฉููู ู ูุง ู ููุนุชูุง ุฉุฑุงุฒู ุฉุนู ุงุฌ ูุฑููุง ู ุฃ ุชุงุจูุงุทูุง ุฑุทุด ุู ุถุฃุจ ุฉูุนู ุงุฌูุง ุฉููููุง
ูููุขุง ุจุณุงุญูุง ู ููุน ู ุณู
First Semester of 2017-2018 Academic Year
Computation Theory Course, 6803415-3 Homework Two
Ch2
Solutions
Question One: 1 Mark
The following is a CFG (Context-Free-Grammar):
๐ฌ โ ๐ฌ + ๐ป | ๐ป ๐ป โ ๐ป ร ๐ญ | ๐ญ ๐ญ โ (๐ฌ) | ๐ Give parase trees and derivations for each string.
a.a b.a+a+a
The Answer of Question One:
a.
Parse Tree:
E
T
F
a Derivations:
๐ธ โน ๐ โน ๐น โน ๐
2 b.
Parse Tree:
E
E T
E T F
T F
F
+ a
a + a Derivations:
๐ธ โน ๐ธ + ๐ โน ๐ + ๐ โน ๐ + ๐น โน ๐น + ๐ โน ๐ + ๐
Question Two: 1 Mark
Give context-free grammars that generate the following languages. In all parts the alphabet E is {0,1}.
a. ๐ฟ = {๐ค|๐ค ๐ ๐ก๐๐๐ก๐ ๐๐๐ ๐๐๐๐ ๐ค๐๐กโ ๐กโ๐ ๐ ๐๐๐ ๐ ๐ฆ๐๐๐๐}
b. ๐ฟ = {๐ค||๐ค| ๐๐ ๐๐๐}
The Answer of Question Two:
a.
S0 โ 0S10|1S11|ฮต S1 โ 0S1|1S1|ฮต b.
S0 โ 0S1|1S1
S1 โ 00S1|01S1|10S1|11S1|ฮต
3 Question Three: 1 Mark
Answer each part for the following context-free grammar G.
๐น โ ๐ฟ๐น๐ฟ | ๐บ ๐บ โ ๐๐ป๐ | ๐๐ป๐ ๐ป โ ๐ฟ๐ป๐ฟ | ๐ฟ | ๐บ
๐ฟ โ ๐ | ๐
a.What are the terminals of ๐ฎ?
b.True or False: ๐ป โน ๐๐๐.
c. True or False: ๐ป โน ๐ป.
d. Give three strings in ๐ณ(๐ฎ).
The Answer of Question Three a. The terminals of G are: a, b.
b. False.
c. False.
d. ab, ba, aab.
Good Luck my Lovely Students ๐ T.Mariah Sami Ahmed Khayat
Teacher Assistant @ Adam University College [email protected]