- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Construct the derivation tree for the string aabbabba.
Problem
Derive a derivation tree for the string aabbabba for the given context free grammar (CFG) −
S->aB|bA A->a|aS|bAA B->b|bS|aBB
Solution
Derivation is a sequence of production rules, which is used to get input strings.
Derivation tree
It is a graphical representation for derivation of given production rules for a given CFG. It is also called as a parse tree.
Properties
The derivation tree contains some properties, which are as follows −
- The root node is always a node indicating the start symbol.
- The derivation is read from left to right.
- The leaf node is always terminal nodes.
- The interior nodes are always the non-terminal nodes.
The given CFG is as follows −
S->aB|bA A->a|aS|bAA B->b|bS|aBB
To draw a parse tree first try to obtain derivation for the string aabbabba
Let’s take leftmost derivation as shown below −
S-> aB ->aaBB ->aabSB ->aabbAB ->aabbaB ->aabbabS ->aabbabbA ->aabbabba which is our final string
Now, construct the derivation tree for the given grammar.
If the grammar is generating more than one type of tree, then we call the given grammar ambiguous grammar.
- Related Articles
- Derive the string “abb” for leftmost and rightmost derivation
- Construct Binary Tree from String in C++
- Construct String from Binary Tree in Python
- What is a Derivation tree in TOC?
- C++ Program to Construct an Expression Tree for a Postfix Expression
- C++ Program to Construct an Expression Tree for a given Prefix Expression
- How to construct a decision tree?
- Construct the SLR Parsing table for the following grammar. Also, Parse the input string a * b + a.
- Construct the Regular expression for the given languages.
- Construct the full k-ary tree from its preorder traversal in C++
- Explain the concept of derivation in TOC
- Mechanics of Train Movement and Derivation for Tractive Effort
- Explain the derivation of Snell's Law.
- Explain inverse square rule and its derivation for class 9.
- Construct DFA for strings not ending with "THE"

Advertisements