Time complexity versus space complexity in Turing machines

戏子无情 提交于 2020-01-03 20:59:23

问题


I think defenitions of time complexity and space complexity for Turing machines are identical and I can't differentiate between them.

Please help me. Thanks.


回答1:


With regards to a Turing machine, time complexity is a measure of how many times the tape moves when the machine is started on some input. Space complexity refers to how many cells of the tape are written to when the machine runs.

The time complexity of a TM is connected to its space complexity. In particular, if tue space complexity of a TM is f(w) for input w, then its time complexity must be at least f(w), since the tape has to move at least f(w) steps to write out that many cells. Additionally, if the TM has tape alphabet Γ and set of states Q, then if the space complexity of the TM on an input w is f(w) and the TM halts on w, the time complexity must be at most |Q|Γf(n). To see this, note that the configuration of the TM at any point in its execution consists of a string of f(n) tape cells, each of which can contain any tape symbol, and can be in one of any of its |Q| states.

An interesting example of this distinction appears if you look at restricted Turing machines like the linear bounded automaton (LBA), a Turing machine that has its tape restricted to space proportional to the size of the input. Although the TM's space complexity is restricted to O(n), the time complexity of any particular LBA can be exponential in the size of the input.

Hope this helps!




回答2:


Time complexity is the measure of how long the algorithm takes to produce an answer.

Space complexity is the measure of how of much memory the algorithm uses in the process.

As an example, consider the problem of computing the sum of the integers 1..n. A simple algorithm would work something like:

procedure sum(n)
  total := 0
  for i = 1 to n
    total := total + a[n]
  return total

The time complexity of this algorithm is O(n) because the loop clearly goes through n iterations. On the other hand, the space complexity is O(1) because the only memory we need is for total and i, which are independent of n.



来源:https://stackoverflow.com/questions/7137187/time-complexity-versus-space-complexity-in-turing-machines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!