SlideShare a Scribd company logo
1 of 7
Download to read offline
UNIVERSITY TEKNOLOGI MALAYSIA
MIDTERM TEST
SEMESTER I 2013/2014
CODE OF SUBJECT
: SCSJ3203
NAME OF SUBJECT
: Theory of Computer Science
YEAR/COURSE
: 3SCSJ, 3SCSR, 3SCSV, 3SCSI, 3SCSD, 3SCSB
TIME
: 10.15 am – 12.15 pm (2 hours)
DATE
: 31 October 2013
VANUE
: BK1 – BK6 (N28)
_____________________________________________________________________________________
INSTRUCTION TO THE STUDENTS
PART A
PART B

: 10 TRUE/FALSE QUESTIONS (10 MARKS)
: 10 SUBJECTIVE QUESTIONS (90 MARKS)

THIS PAPER CONSIST OF 2 PARTS. ANSWER ALL QUESTION IN THE SPACE PROVIDED IN THIS QUESTION
PAPER. THE MARKS FOR EACH QUESTION IS AS INDICATED.

ANSWER ALL QUESTION IN THE SPACES ALLOCATED IN THIS BOOKLET.

Name
IC (or matric) number
Name of lecturer
Subject code and section

SCJ3203 Section 01 / 02 / 03 / 04 / 05 / 06
(pls. circle tour section)

This examination book consists of 6 printed pages excluding this page.
Part A – True and false questions

[10 marks]

_____________________________________________________________________________________
There are 10 questions in this section. For each question, state whether it is TRUE or FALSE and write your
answer in the space given. Each question carries 1 marks.

Answer
1.

λ is always subset of every set.

___________

2.

L1L2 = {xy | x ϵ L1 and y ϵ L2}, if L1 = {a, aa} and L2 = {λ, b, ab},
thus L1L2 = {a, b, aa, ab, aab, aaab}.

___________

3.

A regular expression for set of strings over {a, b} containing
two or more b’s is (a + b)*b(a + b)*b(a + b).

___________

4.

Two example expressions that represent the same set of
strings are (0 + 1 + λ)* and (0 + 1)*.

___________

5.

R = a* + b* generates any string with the combination of a’s
and b’s.

___________

6.

The following grammar; S → aS; S → baSS; S → b over
alphabet {a, b} is regular.

___________

7.

abab is generated by S → aX; X → bX; X → a;

___________

8.

A regular grammar does not generate the empty string.

___________

9.

A regular grammar is also a context-free grammar.

___________

10.

The following grammar; S → aX; X → bY; Y → aS; X → b;
generates the language of (aba)*ab.

___________

1
PART B – SUBJECTIVE QUESTIONS
[90 MARKS]
_____________________________________________________________________________________
This part consists of 10 structured questions. Answer all questions in the space provided. The marks for
each part of the question is as indicated.

1. Consider the language S* where S = {a, ab, ba}. Write three strings that are IN and NOT IN the
language in Table 1.
[6 marks]
Table 1

IN the language

NOT IN the language

2. For the two regular expression:
[4 marks]
r1 = a* + b*
r2 = ab* + ba* + b*a + (a*b)*
a. Find two strings corresponding to r2 but not r1.
b. Find two strings corresponding to both r1 and r2.

_____________________
_____________________

3. Find a regular expression corresponding to the following languages.
a. The language of all strings over the alphabet {a, b} that do not end with ba.
[4 marks]
___________________________________________________________________
b. The language of all strings over the alphabet {a, b} that contain no more than one
occurrence of the string bb.
[4 marks]
___________________________________________________________________
c. The language of strings of even lengths over the alphabet of {a, b}.
[4 marks]
___________________________________________________________________

2
4. Describe as simply as possible in English the language corresponding to the following regular
expressions
a. (b + aa)(a + b)*

[3 marks]

_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
b. a*b(a*ba*b)*a*

[3 marks]

_________________________________________________________________
_________________________________________________________________
_________________________________________________________________
5. construct a context-free grammar that generate the following language
a. {anbm | n<m}
[4 marks]
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________

b. {a3nb2n | n ≥ 0}
[4 marks]
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________

c. {a3n+1b2n | n ≥ 0}
[4 marks]
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________

3
6. For each of the following context-free grammar, write the equivalent regular grammar and regular
expression.
[18 marks]
Context free grammar

Regular grammar

Regular expression

S → aBa
B → bB | λ
S → abS | λ
S → Aa
A → aA | bA | λ

7. Design a CFG rules for the following regular expression.

[4 marks]

(a + b)*aa(a + b)*
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

8. Consider the following grammar
G1:

S → aSa | aBa
B → bB | b

a. Use the set notations to define the language generated by the grammar, L(G1).
[3 marks]
___________________________________________________________________________

b. What is the shortest string that can be produced from the grammar?
[1 mark]
___________________________________________________________________________

c. Write another possible string that can be generated from the language.
[1 mark]
___________________________________________________________________________

4
9. Let G2 be the grammar
S → AB
A → aA | λ
B → bB | λ
a. Give a leftmost derivation of the string aabbb.
[3 marks]
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

b. Give the rightmost derivation of string abbbb.
[3 marks]
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________

c. Build the derivation tree for the derivations in parts (a) and (b).

[4 marks]

5
d. Give a regular expression for L(G2). _________________________

[3 marks]

10. The following is a CFG to generate a language.
S → A1B
A → 0A | λ
B → 0B | 1B | λ
a. Give leftmost derivations of the following string.

[6 marks]

i. 00101
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________

ii. 10001
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________
____________________________________________________________________

b. What is the regular expression for this CFG.

[4 marks]

___________________________________________________________________________

-END OF QUESTIONS6

More Related Content

Similar to SCSJ3203 - Theory Science Computer - Midterm Paper

0580 w13 qp_21
0580 w13 qp_210580 w13 qp_21
0580 w13 qp_21
King Ali
 
Mid module 1 test review
Mid module 1 test reviewMid module 1 test review
Mid module 1 test review
mlabuski
 
Math 107 Final ExaminationSpring, 20131Math 107 College Algebr.docx
Math 107 Final ExaminationSpring, 20131Math 107 College Algebr.docxMath 107 Final ExaminationSpring, 20131Math 107 College Algebr.docx
Math 107 Final ExaminationSpring, 20131Math 107 College Algebr.docx
andreecapon
 
Fall Semester Review Part A Alg 1 B
Fall Semester Review Part A Alg 1 BFall Semester Review Part A Alg 1 B
Fall Semester Review Part A Alg 1 B
Sedona Red Rock HS
 
G6 m5-b-lesson 8-note sheet
G6 m5-b-lesson 8-note sheetG6 m5-b-lesson 8-note sheet
G6 m5-b-lesson 8-note sheet
mlabuski
 
Mathematics Mid Year Form 4 Paper 2 2010
Mathematics Mid Year Form 4 Paper 2 2010Mathematics Mid Year Form 4 Paper 2 2010
Mathematics Mid Year Form 4 Paper 2 2010
sue sha
 

Similar to SCSJ3203 - Theory Science Computer - Midterm Paper (20)

Math practice
Math practiceMath practice
Math practice
 
Mama march 13
Mama march 13Mama march 13
Mama march 13
 
0580_w14_qp_21
0580_w14_qp_210580_w14_qp_21
0580_w14_qp_21
 
0580_w13_qp_23
0580_w13_qp_230580_w13_qp_23
0580_w13_qp_23
 
apostia
apostia apostia
apostia
 
0580 w13 qp_21
0580 w13 qp_210580 w13 qp_21
0580 w13 qp_21
 
0580_w13_qp_21
0580_w13_qp_210580_w13_qp_21
0580_w13_qp_21
 
Mid module 1 test review
Mid module 1 test reviewMid module 1 test review
Mid module 1 test review
 
Activity 3 (answer key)
Activity 3 (answer key)Activity 3 (answer key)
Activity 3 (answer key)
 
ใบงานที่ 5
ใบงานที่ 5 ใบงานที่ 5
ใบงานที่ 5
 
Pp1 sunieta
Pp1 sunietaPp1 sunieta
Pp1 sunieta
 
Math 107 Final ExaminationSpring, 20131Math 107 College Algebr.docx
Math 107 Final ExaminationSpring, 20131Math 107 College Algebr.docxMath 107 Final ExaminationSpring, 20131Math 107 College Algebr.docx
Math 107 Final ExaminationSpring, 20131Math 107 College Algebr.docx
 
Fall Semester Review Part A Alg 1 B
Fall Semester Review Part A Alg 1 BFall Semester Review Part A Alg 1 B
Fall Semester Review Part A Alg 1 B
 
Modul sept okt tahun 3
Modul sept okt tahun 3Modul sept okt tahun 3
Modul sept okt tahun 3
 
Final exam year 1 paper 2 revision
Final exam year 1 paper 2 revisionFinal exam year 1 paper 2 revision
Final exam year 1 paper 2 revision
 
Final exam year 1 paper 2 revision
Final exam year 1 paper 2 revisionFinal exam year 1 paper 2 revision
Final exam year 1 paper 2 revision
 
11-Plus-Maths.pdf
11-Plus-Maths.pdf11-Plus-Maths.pdf
11-Plus-Maths.pdf
 
G6 m5-b-lesson 8-note sheet
G6 m5-b-lesson 8-note sheetG6 m5-b-lesson 8-note sheet
G6 m5-b-lesson 8-note sheet
 
Mathematics Mid Year Form 4 Paper 2 2010
Mathematics Mid Year Form 4 Paper 2 2010Mathematics Mid Year Form 4 Paper 2 2010
Mathematics Mid Year Form 4 Paper 2 2010
 
Bahasa Inggeris Tahun 1 Kertas 1 Ogos 2016
Bahasa Inggeris Tahun 1 Kertas 1 Ogos 2016Bahasa Inggeris Tahun 1 Kertas 1 Ogos 2016
Bahasa Inggeris Tahun 1 Kertas 1 Ogos 2016
 

More from Abdul Khaliq

ULAB3122 / UHS3022 - Final Exam Paper
ULAB3122 / UHS3022 - Final Exam PaperULAB3122 / UHS3022 - Final Exam Paper
ULAB3122 / UHS3022 - Final Exam Paper
Abdul Khaliq
 
Soalan orienteering
Soalan orienteeringSoalan orienteering
Soalan orienteering
Abdul Khaliq
 
orienteering - saling pandang
orienteering - saling pandangorienteering - saling pandang
orienteering - saling pandang
Abdul Khaliq
 
orienteering - cerun
orienteering - cerunorienteering - cerun
orienteering - cerun
Abdul Khaliq
 
orenteering - mengenal cerun
orenteering - mengenal cerunorenteering - mengenal cerun
orenteering - mengenal cerun
Abdul Khaliq
 
Computational mathematic
Computational mathematicComputational mathematic
Computational mathematic
Abdul Khaliq
 

More from Abdul Khaliq (20)

UHB 3022 / ULAB 3122 - Final Exam Paper
 UHB 3022 / ULAB 3122 - Final Exam Paper UHB 3022 / ULAB 3122 - Final Exam Paper
UHB 3022 / ULAB 3122 - Final Exam Paper
 
SCSJ3553 - Artificial Intelligence Final Exam paper - UTM
SCSJ3553 - Artificial Intelligence Final Exam paper - UTMSCSJ3553 - Artificial Intelligence Final Exam paper - UTM
SCSJ3553 - Artificial Intelligence Final Exam paper - UTM
 
ULAB3122 / UHS3022 - Final Exam Paper
ULAB3122 / UHS3022 - Final Exam PaperULAB3122 / UHS3022 - Final Exam Paper
ULAB3122 / UHS3022 - Final Exam Paper
 
ULAB3122 / UHS3022 - Final Exam Paper (2009)
ULAB3122 / UHS3022 - Final Exam Paper (2009)ULAB3122 / UHS3022 - Final Exam Paper (2009)
ULAB3122 / UHS3022 - Final Exam Paper (2009)
 
UHB2422 / ULAB2112 - Final exam paper with answer sample
UHB2422 / ULAB2112 - Final exam paper with answer sampleUHB2422 / ULAB2112 - Final exam paper with answer sample
UHB2422 / ULAB2112 - Final exam paper with answer sample
 
UHB2422 / ULAB2112 - Final exam paper
UHB2422 / ULAB2112 - Final exam paperUHB2422 / ULAB2112 - Final exam paper
UHB2422 / ULAB2112 - Final exam paper
 
Soalan orienteering
Soalan orienteeringSoalan orienteering
Soalan orienteering
 
Orienteering - titik utara
Orienteering - titik utaraOrienteering - titik utara
Orienteering - titik utara
 
orienteering - saling pandang
orienteering - saling pandangorienteering - saling pandang
orienteering - saling pandang
 
orienteering - cerun
orienteering - cerunorienteering - cerun
orienteering - cerun
 
orenteering - mengenal cerun
orenteering - mengenal cerunorenteering - mengenal cerun
orenteering - mengenal cerun
 
Orienteering - kompas prismatik
Orienteering - kompas prismatikOrienteering - kompas prismatik
Orienteering - kompas prismatik
 
UICI 2022 - Bab 04 teknologi dalam islam (nota)
UICI 2022 - Bab 04 teknologi dalam islam (nota)UICI 2022 - Bab 04 teknologi dalam islam (nota)
UICI 2022 - Bab 04 teknologi dalam islam (nota)
 
UICI 2022 - Bab 03 sains dan islam (nota)
UICI 2022 - Bab 03 sains dan islam (nota)UICI 2022 - Bab 03 sains dan islam (nota)
UICI 2022 - Bab 03 sains dan islam (nota)
 
UICI 2022 - Bab 02 perpindahan ilmu (nota)
UICI 2022 - Bab 02 perpindahan ilmu (nota)UICI 2022 - Bab 02 perpindahan ilmu (nota)
UICI 2022 - Bab 02 perpindahan ilmu (nota)
 
UICI 2022 -Bab 01 manusia dan ilmu (nota)
UICI 2022 -Bab 01 manusia dan ilmu (nota)UICI 2022 -Bab 01 manusia dan ilmu (nota)
UICI 2022 -Bab 01 manusia dan ilmu (nota)
 
Computational mathematic
Computational mathematicComputational mathematic
Computational mathematic
 
A intro uici 2022 sains teknologi dan manusia
A intro uici 2022   sains teknologi dan manusiaA intro uici 2022   sains teknologi dan manusia
A intro uici 2022 sains teknologi dan manusia
 
UICI 2022 - sains dan islam
UICI 2022 - sains dan islamUICI 2022 - sains dan islam
UICI 2022 - sains dan islam
 
UICI 2022 - Perpindahan ilmu
UICI 2022 - Perpindahan ilmuUICI 2022 - Perpindahan ilmu
UICI 2022 - Perpindahan ilmu
 

Recently uploaded

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

SCSJ3203 - Theory Science Computer - Midterm Paper

  • 1. UNIVERSITY TEKNOLOGI MALAYSIA MIDTERM TEST SEMESTER I 2013/2014 CODE OF SUBJECT : SCSJ3203 NAME OF SUBJECT : Theory of Computer Science YEAR/COURSE : 3SCSJ, 3SCSR, 3SCSV, 3SCSI, 3SCSD, 3SCSB TIME : 10.15 am – 12.15 pm (2 hours) DATE : 31 October 2013 VANUE : BK1 – BK6 (N28) _____________________________________________________________________________________ INSTRUCTION TO THE STUDENTS PART A PART B : 10 TRUE/FALSE QUESTIONS (10 MARKS) : 10 SUBJECTIVE QUESTIONS (90 MARKS) THIS PAPER CONSIST OF 2 PARTS. ANSWER ALL QUESTION IN THE SPACE PROVIDED IN THIS QUESTION PAPER. THE MARKS FOR EACH QUESTION IS AS INDICATED. ANSWER ALL QUESTION IN THE SPACES ALLOCATED IN THIS BOOKLET. Name IC (or matric) number Name of lecturer Subject code and section SCJ3203 Section 01 / 02 / 03 / 04 / 05 / 06 (pls. circle tour section) This examination book consists of 6 printed pages excluding this page.
  • 2. Part A – True and false questions [10 marks] _____________________________________________________________________________________ There are 10 questions in this section. For each question, state whether it is TRUE or FALSE and write your answer in the space given. Each question carries 1 marks. Answer 1. λ is always subset of every set. ___________ 2. L1L2 = {xy | x ϵ L1 and y ϵ L2}, if L1 = {a, aa} and L2 = {λ, b, ab}, thus L1L2 = {a, b, aa, ab, aab, aaab}. ___________ 3. A regular expression for set of strings over {a, b} containing two or more b’s is (a + b)*b(a + b)*b(a + b). ___________ 4. Two example expressions that represent the same set of strings are (0 + 1 + λ)* and (0 + 1)*. ___________ 5. R = a* + b* generates any string with the combination of a’s and b’s. ___________ 6. The following grammar; S → aS; S → baSS; S → b over alphabet {a, b} is regular. ___________ 7. abab is generated by S → aX; X → bX; X → a; ___________ 8. A regular grammar does not generate the empty string. ___________ 9. A regular grammar is also a context-free grammar. ___________ 10. The following grammar; S → aX; X → bY; Y → aS; X → b; generates the language of (aba)*ab. ___________ 1
  • 3. PART B – SUBJECTIVE QUESTIONS [90 MARKS] _____________________________________________________________________________________ This part consists of 10 structured questions. Answer all questions in the space provided. The marks for each part of the question is as indicated. 1. Consider the language S* where S = {a, ab, ba}. Write three strings that are IN and NOT IN the language in Table 1. [6 marks] Table 1 IN the language NOT IN the language 2. For the two regular expression: [4 marks] r1 = a* + b* r2 = ab* + ba* + b*a + (a*b)* a. Find two strings corresponding to r2 but not r1. b. Find two strings corresponding to both r1 and r2. _____________________ _____________________ 3. Find a regular expression corresponding to the following languages. a. The language of all strings over the alphabet {a, b} that do not end with ba. [4 marks] ___________________________________________________________________ b. The language of all strings over the alphabet {a, b} that contain no more than one occurrence of the string bb. [4 marks] ___________________________________________________________________ c. The language of strings of even lengths over the alphabet of {a, b}. [4 marks] ___________________________________________________________________ 2
  • 4. 4. Describe as simply as possible in English the language corresponding to the following regular expressions a. (b + aa)(a + b)* [3 marks] _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ b. a*b(a*ba*b)*a* [3 marks] _________________________________________________________________ _________________________________________________________________ _________________________________________________________________ 5. construct a context-free grammar that generate the following language a. {anbm | n<m} [4 marks] ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ b. {a3nb2n | n ≥ 0} [4 marks] ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ c. {a3n+1b2n | n ≥ 0} [4 marks] ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ 3
  • 5. 6. For each of the following context-free grammar, write the equivalent regular grammar and regular expression. [18 marks] Context free grammar Regular grammar Regular expression S → aBa B → bB | λ S → abS | λ S → Aa A → aA | bA | λ 7. Design a CFG rules for the following regular expression. [4 marks] (a + b)*aa(a + b)* ______________________________________________________________________________ ______________________________________________________________________________ ______________________________________________________________________________ 8. Consider the following grammar G1: S → aSa | aBa B → bB | b a. Use the set notations to define the language generated by the grammar, L(G1). [3 marks] ___________________________________________________________________________ b. What is the shortest string that can be produced from the grammar? [1 mark] ___________________________________________________________________________ c. Write another possible string that can be generated from the language. [1 mark] ___________________________________________________________________________ 4
  • 6. 9. Let G2 be the grammar S → AB A → aA | λ B → bB | λ a. Give a leftmost derivation of the string aabbb. [3 marks] ___________________________________________________________________________ ___________________________________________________________________________ ___________________________________________________________________________ ___________________________________________________________________________ b. Give the rightmost derivation of string abbbb. [3 marks] ___________________________________________________________________________ ___________________________________________________________________________ ___________________________________________________________________________ ___________________________________________________________________________ c. Build the derivation tree for the derivations in parts (a) and (b). [4 marks] 5
  • 7. d. Give a regular expression for L(G2). _________________________ [3 marks] 10. The following is a CFG to generate a language. S → A1B A → 0A | λ B → 0B | 1B | λ a. Give leftmost derivations of the following string. [6 marks] i. 00101 ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ ii. 10001 ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ ____________________________________________________________________ b. What is the regular expression for this CFG. [4 marks] ___________________________________________________________________________ -END OF QUESTIONS6