Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 54

Nondeterministic Turing Machines: Definition and Tracing

Recommended resources

Hello! Welcome back to our course on the Theory of Computation.

In our last lesson, we explored variations of the standard Turing Machine, like multi-tape and two-way infinite tape models. We established a crucial principle: these variations add convenience and efficiency, but not fundamental computational power. They all recognize the same class of languages, which we proved through simulation.

Today, we'll introduce another, more profound variation: nondeterminism. You'll recall from our study of finite automata how nondeterminism allowed a machine to be in multiple states at once, exploring many paths in parallel. What happens when we grant this "power of choice" to a Turing Machine? This lesson will answer that question by focusing on our learning outcome: to define Nondeterministic Turing Machines (NTMs) and trace their computation.

1. What is a Nondeterministic Turing Machine?

In a Deterministic Turing Machine (DTM), for any given state and tape symbol, there is exactly one possible next move. A Nondeterministic Turing Machine (NTM) relaxes this constraint, allowing for multiple possible moves at each step.

To get a clear initial picture of this difference, let's watch a short video.

Nondeterministic Turing Machine (Part 1)

This video from Neso Academy provides an excellent introduction to NTMs. It contrasts the transition functions of DTMs and NTMs and introduces the key idea that an NTM's computation can branch into multiple possibilities.

Please watch from the beginning to 03:24. Pay close attention to: How the transition function for an NTM differs from that of a DTM. The example transition diagram that shows a single state (q) having three different possible transitions for the same input symbol (B).

Formal Definition of an NTM

As the video highlighted, the core difference lies in the transition function. Formally, a Nondeterministic Turing Machine is a 7-tuple , where all components are the same as in a DTM, except for .

The transition function for a DTM is:

In contrast, the transition function for an NTM is:

Let's break this down:

  • : The input to the function is still the current non-halting state and the symbol under the tape head.
  • : This is the crucial part. denotes the power set. This means the function's output is not a single triple, but a set of triples. This set can contain zero, one, or multiple possible transitions.

This formal definition captures the "choice" an NTM has. If returns a set of three transitions, the machine can choose any one of them to follow.

For a more rigorous look at this definition, you can refer to the following text.

Lecture 22 - Non-deterministic Turing machines and NP

These lecture notes from the University of Waterloo provide a concise, formal definition of an NTM, which will solidify the concepts from the video.

Read the first section, '22.1 Non-deterministic Turing machines', up to subsection 22.1.1. Focus on the formal 7-tuple definition and the signature of the transition function δ.


2. Tracing NTM Computation

Since an NTM can have multiple possible moves at each step, its computation is no longer a linear sequence of configurations. Instead, it's a computation tree, where the root is the starting configuration and the children of any node are all the configurations that can be reached in one step.

A visual representation of an NTM's computation. The root I₀ is the initial configuration. Each path from the root represents one possible sequence of choices the NTM can make.

Configurations and the "Yields" Relation

As a quick refresher, a configuration (or instantaneous description) is a snapshot of the TM's state, tape content, and head position, often written as uqv.

  • q is the current state.
  • u is the portion of the tape to the left of the head.
  • v is the portion of the tape starting from the head position to the right.

The moves in the computation tree are formally described by the yields relation, denoted by ⊢. We write if configuration can be reached from in a single step according to one of the choices in the NTM's transition function.

Acceptance and Rejection in NTMs

The existence of multiple computation paths changes how we define acceptance. The rule is simple and analogous to that of NFAs:

  • Accept: An NTM accepts an input string w if at least one branch of its computation tree leads to the accept state, .
  • Reject: The NTM rejects w if all branches of the computation halt, and none of them reach the accept state.
  • Loop: The NTM loops on w if there is no accepting branch and at least one branch continues forever.

Notice the asymmetry: a single accepting path is enough for the entire machine to accept, even if other paths reject or loop.

The following video segment explains this tree-based computation and the outcomes very clearly.

Nondeterministic Turing Machine (Part 1)

Let's return to the Neso Academy video to see how configurations are used to build the computation tree and how the final result (accept, reject, or loop) is determined.

Watch from 03:24 to 05:15 and from 08:02 to 15:04. Focus on: The definition of a configuration. The visual comparison between a DTM's linear computation history and an NTM's tree-like history. The definitions of accept, reject, and loop for NTMs.


3. A Worked Example: L = {ww | w ∈ {a, b}*}

Let's see how nondeterminism can be a powerful design tool. Consider the language L consisting of all strings that are a word w repeated, like abab or bbaabbaa.

Designing a DTM for this is tricky. You'd have to shuttle back and forth, marking symbols to check for equality. An NTM, however, can solve this much more elegantly by "guessing."

Here's the high-level strategy for an NTM:

  1. Guess: Nondeterministically move a second tape head (or a marker on a single tape) to the right, "guessing" where the midpoint of the input string is. For each possible midpoint, a new branch of computation is created.
  2. Verify: Once a midpoint is chosen, deterministically compare the substring before the midpoint with the substring after it.
  3. Accept/Reject: If the two substrings match perfectly, that computation branch accepts. If they don't match, that branch rejects.

If the input string is indeed in the form ww, then one of the "guesses" for the midpoint will be correct, and that corresponding computation branch will lead to acceptance. Therefore, the NTM as a whole accepts the string.

The following resource provides a sketch and a computation tree for this exact problem.

Module 8 - Turing machines

This document from the University of Waterloo illustrates the design of an NTM for the language L = {ww}. It's a perfect example of nondeterminism in action.

Read sections '8.55 Details for nondeterminism' through '8.60 An example computation tree'. This will walk you through: The formal details of NTM acceptance. The high-level idea for an NTM recognizing ww. A state diagram implementing this idea. A concrete computation tree for the input abab.

Test your understanding!

Consider the partial NTM computation tree shown in the image below for the input string abb. The notation on the edges is (read)/(write, move, new_state).

  1. What is the full configuration of the node at address 2? (Assume the tape starts with the input and is otherwise blank.)
  2. Follow the path from the root (address ε) to the node at address 21. What is the final configuration of this node?
  3. If q3 were the accept state, would the NTM accept the input abb based on the partial tree shown? Why or why not?
Show answer
  1. The node at address 2 is reached from the root q0abb by the transition a / (X, R, q2). The head reads a, writes X, and moves Right. The configuration is Xq2bb.

  2. Let's trace the path to 21:

    • Root (ε): q0abb
    • Move 2: Apply a / (X, R, q2). Configuration becomes Xq2bb.
    • Move 1: From state q2 reading b, apply b / (b, R, q3). The head reads b, writes b (no change), and moves Right. The final configuration is Xbq3b.
  3. Yes, the NTM would accept. The definition of acceptance only requires that one computational path reaches an accept state. Since the path to node 21 ends in state q3, this branch accepts, and therefore the entire machine accepts the input abb, regardless of what happens on other branches.


Conclusion

In this lesson, we formally introduced Nondeterministic Turing Machines. We saw that their power comes from the ability to explore multiple computational paths simultaneously, represented as a computation tree.

Key Takeaways:

  • Formal Definition: An NTM's transition function maps a state-symbol pair to a power set of possible moves, .
  • Computation as a Tree: An NTM's execution on an input w generates a tree of configurations, where each branch is a possible sequence of choices.
  • Acceptance Condition: An NTM accepts if any branch of its computation tree reaches an accepting state.
  • Nondeterminism as a Tool: Nondeterminism allows us to design machines that "guess" a solution (e.g., the midpoint of a string) and then deterministically "verify" it. This can simplify the design process for certain languages significantly.

Preview of the Next Lesson:
We've defined NTMs and seen their utility. A critical question remains: are they more powerful than DTMs? Can they recognize languages that DTMs cannot? Following the pattern we saw with finite automata, the answer is no. In our next lesson, we will prove that NTMs and DTMs are equivalent in computational power. The proof involves a clever simulation where a DTM systematically explores the NTM's entire computation tree. Given your background in algorithms, you might appreciate that the simulation strategy is analogous to a breadth-first search.