Category Archives: Theory of Computation

C program to simulate Nondeterministic Finite Automata (NFA)

Background An NFA is typically described using a directed graph. Each edge and vertex is labeled either 0 or 1 representing possible transitions. Vertices represent the states of the NFA. Those labeled 0 are non­ accepting states, and those labeled 1 are accepting states. It takes an input string of finite length. Typically, the input… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

Undecidability and Reducibility

  Decidable Problems A problem is decidable if we can construct a Turing machine which will halt in finite amount of time for every input and give answer as ‘yes’ or ‘no’. A decidable problem has an algorithm to determine the answer for a given input. Examples Equivalence of two regular languages: Given two regular… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

Ambiguity in Context free Grammar and Context free Languages

Prerequisite – Pushdown Automata and Context Free Languages . Suppose we have a context free grammar G with production rules: S->aSb|bSa|SS|ɛ Left most derivation (LMD) and Derivation Tree: Leftmost derivation of a string from staring symbol S is done by replacing leftmost non-terminal symbol by RHS of corresponding production rule. For example: The leftmost derivation… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

Mealy and Moore Machines

Moore Machines: Moore machines are finite state machines with output value and its output depends only on present state. It can be defined as (Q, q0, ∑, O, δ, λ) where: Q is finite set of states. q0 is the initial state. ∑ is the input alphabet. O is the output alphabet. δ is transition function which maps Q×∑ → Q. λ is the output function which maps Q → O.  Figure 1 In the moore machine shown in Figure 1, the output is represented with each input state separated by /. The length of output for a moore machine is greater than input by 1. Input: 11 Transition: δ (q0,11)=> δ(q2,1)=>q2 Output: 000 (0 for q0, 0 for q2 and again 0 for q2)  Mealy Machines: Mealy machines are also finite state machines with output value and its output depends on present state and current input symbol. It can be defined as (Q, q0, ∑, O, δ, λ’) where: Q is finite set of states. q0 is the initial state. ∑ is the input alphabet. O is the output alphabet. δ is transition function which maps Q×∑ → Q. ‘λ’ is the output function which maps Q×∑→ O. Figure 2 In the mealy machine shown in Figure 1, the output is represented with each input symbol for each state separated by /. The length of output for a mealy machine is equal to the length of input. Input:11 Transition: δ (q0,11)=> δ(q2,1)=>q2 Output: 00 (q0 to q2 transition has Output 0 and q2 to q2 transition also has Output 0) Conversion from Mealy to Moore Machine Let us take the transition table of mealy machine shown in Figure 2. Input=0 Input=1 Present State Next State Output Next State Output q0 q1 0 q2 0 q1 q1 0 q2 1 q2 q1 1 q2 0 Table 1… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

Simplifying Context Free Grammars

The definition of context free grammars (CFGs) allows us to develop a wide variety of grammars. Most of the time, some of the productions of CFGs are not useful and are redundant. This happens because the definition of CFGs does not restrict us from making these redundant productions. By simplifying CFGs we remove all these… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.

Theory of Computation | Decidability

Identifying languages (or problems*) as decidable, undecidable or partially decidable is a very common question in GATE. With correct knowledge and ample experience, this question becomes very easy to solve. Lets start with some definitions:-   Recursive language(REC) – A language ‘L’ is said to be recursive if there exists a Turing machine which will… Read More »



See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.