Derivation Tree of Context Free Grammar - Automata

Derivation Tree of Context Free Grammar

Derivation tree gives a way to show how a string can be derived from context free grammar. It is also called as parse tree, production tree, and syntax tree. The interior nodes of derivation tree are labeled with variables and leaves of this tree are labeled with terminals. We can also say that left-hand side of production rules is always interior nodes, and the right-hand side of production rules may be exterior nodes. The root of the derivation tree is labeled with start symbol or variable.

Formal Definitions of Derivation Tree

We can define a derivation tree of context free grammar G = (V, T, P, S). A derivation tree satisfies the following properties:

  • The root node of derivation tree is labeled with S.
  • Every vertex of derivation tree is labeled with a variable or terminal or an empty symbol.
  • Every leaf has a label from T U {?}.
  • The label of the interior node is variable V.
  • If any node n has label B, and vertices n1, n2 ……………….,nk are the sum of vertex n with labels X1,X2 ……………..Xk respectively then B -> X1X2…………..Xk is production in P.
  • If the leaf is labeled with ?, then it must be the only child of its parent.

Types of Derivation Tree

  • Left Most Derivation Tree
  • Right Most Derivation Tree
  • Mixed Derivation Tree

Left Most Derivation Tree:

In left most derivation tree, for each step, production rule is applied to the leftmost variable that’s why it is called left most derivation tree.

Example:

Consider the Context Free Grammar:

S -> S * S

S -> S + S

S -> 0

S -> 1

S -> 2

Find string 0 + 1 * 2

Solution:

Let us derive string 0 + 1 * 2 using left most derivation.

S => S * S

   => 0 + S

   => 0 + S * S

   => 0 + 1 * S

   => 0 + 1 * 2

In this, each step of derivation, the production rule is applied to leftmost variable.

Right Most Derivation Tree:

In right most derivation tree each step, production rule is applied to the rightmost variable that’s why it is called right most derivation tree

Example:

Consider the Context Free Grammar:

S -> S * S

S -> S + S

S -> 0

S -> 1

S -> 2

Find string 0 + 1 * 2

Solution:

Let us derive string 0 + 1 * 2 using left most derivation.

S => S + S

   => S + S * S

   => S + S * 2

   => S + 1 * 2

   => 0 + 1 * 2

In this, for each step of derivation the production rule is applied to rightmost variable

Mixed Derivation Tree:

In a derivation, if the production rule is not applied to left most variable in each step or right most variable in each step, then it is called mixed derivation.

Example:

Consider the Context Free Grammar:

S -> S * S

S -> S + S

S -> 0

S -> 1

S -> 2

Find string 0 + 1 * 2

Solution:

Let us derive string 0 + 1 * 2

S => S + S

   => S + S * S

   => 0 + S * S

   => 0 + S * 2

   => 0 + 1 * 2

In each step of derivation, the production rule is applied to both leftmost and rightmost variable.

Let us take some examples of derivation tree

Example:

Consider the context free grammar G = (V, T, P, S)

Where,

S -> 0S1

V = {E, T, F}

T = {a, +,*, (,)}

S is the start symbol.

P is the set of production rules in context free grammar, which are defined as follows:

E -> E + T | T | a

T -> T * F | F | a

F -> (E) | a

Find derivation of string a + a * a

Solution:

Let us see derivation of string a + a * a

E => E + T

   => E + T * F

   => a + T * F

   => a + a* F

   => a + a* a

The derivation for string a + a * a is shown below:

Derivation Tree of Context Free Grammar

Related Topics

Ambiguity in Context Free Grammar - Automata

Ambiguity in Context Free Grammar? Context Free Grammar Context Free Grammar has one condition for production rules, which is, on the left-hand side of each rule, there must be only single variable,...

4 minutes read.

Recursive Language and Recursive Enumerable Language

Recursive Language and Recursive Enumerable Language Before discussing Recursive language and Recursive Enumerable language, let us see what Turing machine responds for some input string. If we have the Turing machine T...

4 minutes read.

Equivalence of Regular Grammar and Finite Automata

Equivalence of Regular Grammar and Finite Automata Regular Grammar / type -3 grammar A regular grammar or type-3 defines the language called regular language that is accepted by finite Automata.A Regular Grammar...

3 minutes read.

Chomsky's Normal Form - Automata

Chomsky's Normal Form (CNF) In context free grammar, the left-hand side of production rules contains only one variable, and right side may contain any number of variables or terminals in production...

4 minutes read.

Converting Finite Automata to Regular Expression using Arden’s Theorem

Converting Finite Automata to Regular Expression using Arden’s Theorem The Arden’s Theorem can be applied to find the regular expression recognized by the given transition diagram. This theorem can be applied...

4 minutes read.

Undecidable Problem of Turing Machine

Automata Undecidable Problem of Turing Machine Undecidable problems areproblems which cannot be solved by any Turing machine. Example: Post Correspondence Problem is the type of undecidable Problem. Post Correspondence Problem Post Correspondence problem is...

7 minutes read.

Non-deterministic Turing Machine - Automata

A non-deterministic Turing machine (NTM) is a theoretical machine used in computability theory to study the extent to which a machine can "guess" at a solution and yet still be...

4 minutes read.

Conversion from NFA to DFA

Conversion from NFA to DFA A Non-deterministic Finite Automata (NFA) is a finite state machine, in which, the move from one state to another is not fully deterministic, i.e., for a...

4 minutes read.

Derivation Tree of Context Free Grammar - Automata

Derivation Tree of Context Free Grammar Derivation tree gives a way to show how a string can be derived from context free grammar. It is also called as parse tree, production...

3 minutes read.

Automata Tutorial

What is Automata? Automata is a mathematical model and abstract model, which is used to detect string in various languages. In Automata, Regular language is recognized by Finite state AutomataContext Free language...

4 minutes read.

Minimization of Finite Automata

Minimization of Finite Automata The term minimization refers to the construction of finite automata with a minimum number of states, which is equivalent to the given finite automata. The number of...

4 minutes read.

Finite Automata with Output

Finite Automata with Output The Finite State machine is similar to Finite Automata, except that it has the additional capacity of producing output. Finite State machine = Finite Automata + Output Capabilities Types...

3 minutes read.

Context Free Grammar - Automata

Context Free Grammar Grammar defines a set of rules, and with the help of these rules valid sentences in a language are constructed. A grammar consists of collection of substitution rules,...

3 minutes read.

What is Automata Theory?

What is Automata Theory? Automata theory is used to study the abstract machine and automata (the self-acting machine).  Abstract machine is a theoretical model of a computer used in Automata theory. Automata...

4 minutes read.

Pumping Lemma for Regular Languages - Automata

Pumping Lemma for Regular Languages The language accepted by the finite automata is called Regular Language. If we are given a language L and asked whether it is regular or not?...

4 minutes read.

Conversion from Mealy Machine to Moore Machine

Conversion from Mealy Machine to Moore Machine In this topic, we will see different ways that are used for the conversion of Mealy Machine to Moore Machine. Moore Machine The output of Moore...

4 minutes read.

Pumping Lemma for Context Free Languages

Pumping Lemma for Context Free Languages The Pumping Lemma is made up of two words, in which, the word pumping is used to generate many input strings by pushing the symbol...

3 minutes read.

Push down Automata Acceptance

Acceptance of Language by Push down Automata Push down Automata accepts the language, which is called context free language. Push down Automata = Finite Automata + Auxiliary Memory (Stack) Auxiliary Memory helps Push...

3 minutes read.

Finite Automata

Finite Automata Finite state Automata or Finite State Machine is the simplest model used in Automata. Finite state automata accepts regular language. In this, the term finite means it has a...

4 minutes read.

Automata Greibach Normal Form

Greibach Normal Form In Greibach Normal Form, there is restriction on the position, in which, terminals and variables can appear on right-hand side of production rules. In Greibach Normal Form, every...

4 minutes read.