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

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.

Automata Regular Expressions

Regular Expressions Regular expressions are also referred as rational expressions, which are used to describe the algebraic description of regular languages. It is generally a sequence of characters that is used...

3 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.

Simplification of Context Free Grammar - Automata

Simplification of Context Free Grammar Context Free Grammar has recursive structure. The languages that are accepted with Context Free Grammar are called Context Free Languages. Context Free Grammar has one condition...

3 minutes read.

Conversion from Moore Machine to Mealy Machine

Conversion from Moore Machine to Mealy Machine Moore Machine The output of Moore machine depends only on the present state. In this, if machine has N number of states, then it will...

6 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.

Minimization of Finite Automata with Output

Minimization of Finite Automata with Output The method to minimize the Moore and Mealy machine is very much similar to the method that we have used to minimize the DFA. Methods to...

3 minutes read.

Conversion of DFA to Regular expression

Conversion of DFA to Regular expression To convert the DFA to Regular Expression (RE), we are going to use a method called converting DFA to regular expression by eliminating states. This...

3 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.

Closure Properties of Regular Languages -Automata

Closure Properties of Regular Languages We use the term “Closure” when we talk about sets of things. If we have two regular languages L1 and L2, and L is obtained by...

3 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.

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.

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.

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.

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.

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.

Automata Chomsky Hierarchy

Chomsky Hierarchy Formal languages: A language with precise syntax and semantics are called formal languages. Noam Chomsky has defined the Chomsky hierarchy in 1956. He is an American scientist and philosopher, and...

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.

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.