# Derive the string “00101” using LMD and RMD while using CFG

Data Structure AlgorithmsComputer ScienceComputers

Best Seller

89 Lectures 11.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

#### Data Science and Data Analysis with Python

50 Lectures 3.5 hours

## Problem

Derive the string"00101" for left most derivation (LMD) and right most derivation (RMD) using context free grammar (CFG).

## Solution

The grammar is as follows −

S->A1B
A->0A| ε
B->0B| 1B| ε

## Left Most derivation (LMD)

In the left most derivation, the given input is scanned and then replaced with the production rule from left side to right. So, we have to read that input string from left to right.

The grammar is as follows −

S->A1B rule1
A->0A| ε rule 2
B->0B| 1B| ε rule 3

Hence, the LMD will be as follows −

S->A1B
->0A1B rule2
->00A1B rule2
->001B rule2
->0010B rule3
->00101B rule3
->00101 rule3
Derived the string 00101 using LMD

## Right Most Derivation (RMD)

In Right most derivation, the given input is scanned and then replaced with the production rule right to left. So, we have to read the input string from right to left.

The grammar is as follows −

S->A1B rule1
A->0A| ε rule 2
B->0B| 1B| ε rule 3

Now, the RMD will be as follows −

S->A1B
->A10B rule3
->A101B rule3
->A101 rule3
->0A101 rule2
->00A101 rule2
->00101 rule2
Derived the string 00101 using RMD
Updated on 11-Jun-2021 13:14:42