简体   繁体   中英

What is the difference between a Turing Machine and an Algorithm?

According to my understanding, the Turing machine is just a machine representation of an algorithm. Is there any difference between an algorithm and a Turing machine?

They are very different.

An algorithm is a procedure. It can be specified in a wide variety of ways, usually by writing down a program in some programming language. By contrast Turing machine describes a procedure adapted to run on a very specific and unrealistic machine.

However the characteristics of the algorithm depend on the machine that it runs on. And Turing machines look nothing like any machine of real-world interest. Therefore while every algorithm can be represented by a Turing machine, Turing machines are not the preferred representation. And the Turing machine representation obscures the most interesting properties of the algorithm.

For example merge sort is widely known to be O(n log(n)) . It scales that way for everything from Donald Knuth's artificial MIX architecture from the 1960s to highly parallelized distributed implementations in the cloud today.

But in a Turing machine, iterating through two arrays in parallel and writing to a third requires constantly seeking back and forth between two distant places in tape to compare them, then seeking again to find where to write the output. Therefore while you can build a Turing machine that implements a recognizable merge sort, but it WON'T be O(n log(n)) . Not by a country mile. And in fact will perform much worse than a bubble sort. (Because bubble sort only compares things close on tape, so spends less time seeking back and forth.)

An algorithm is much broader than a Turing machine. An algorithm is really just consists of some inputs and a set instructions to follow with those inputs. Here's a really simple algorithm:

Algorithm SumNumbers
  Input: A list of numbers L.
  Output: The sum of all numbers in L.
  if L.size = 0 return null
  sum <- 0
  for each item in L, do
    sum <- sum + item
  return sum 

So there, we've defined and algorithm. And haven't even discussed Turing machines yet.

Once the m-tuple is defined, a Turing machine is just an algorithm. The inputs are defined by setting the initial state of the tape. The output of the algorithm is the final state and/or the final state of the tape once the process halts. And the steps for arriving at an output given the input are determined by the m-tuple and the general rules of computation for Turning machines: https://en.wikipedia.org/wiki/Turing_machine#Formal_definition

Now, determining if the Turing machine will ever actually halt and provide you with an "output" is a whole other rabbit-hole: https://en.wikipedia.org/wiki/Halting_problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM