Halting problem(停机问题)

1.Introduction

In computability theory, the halting problem is the problem of determining, from a description of an arbitrary computer program and an input, whether the program will finish running or continue to run forever.

The halting problem is a decision problem about properties of computer programs on a fixed Turing-complete model of computation, i.e., all programs that can be written in some given programming language that is general enough to be equivalent to a Turing machine. The problem is to determine, given a program and an input to the program, whether the program will eventually halt when run with that input. In this abstract framework, there are no resource limitations on the amount of memory or time required for the program’s execution; it can take arbitrarily long, and use arbitrarily as much storage space, before halting. The question is simply whether the given program will ever halt on a particular input.

停机问题是用于判断这个程序是否会自动退出或者会一直运行下去。例如一个死循环,在内存没有限制的条件下,这个程序不能自动退出,即它会一直运行下去。对于普通正常的程序,举一个非常简单的例子,如helloworld,在运行结束后会自动退出。你会发现, 这是一个很值得研究的问题。因为计算机的资源是有限的,如果一个程序不会自动停止,它便会消耗大量资源与时间,大大降低了效率。假如我们能够设计一个范型算法,适用于对所有程序进行测试,对不能自动退出的程序发出警告,那么这便会大大提高我们的工作效率。可惜的是,目前并不存在这种算法。

Alan Turing proved in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist. A key part of the proof was a mathematical definition of a computer and program, which became known as a Turing machine; the halting problem is undecidable over Turing machines. It is one of the first examples of a decision problem.

对于这个问题,图灵本人便做过验证,发现并不存在一种通用的算法能实现这一功能,他认为这是图灵机上仍不能解决的一个问题,同时他也给出了证明:Halting_problem-Sketch_of_proof

更多的细节详见:Halting problem

那么,我们能不能通过一些条件限制,如时间限制,内存限制来大约估计程序是否会停机?

显然是可以的。虽然停机问题是无法解决的,但是我们可以通过条件限制,即根据它的趋势来预测是否会出现停机,以达到我们测试的目的。

下面我通过讲解一道例题,帮助读者进一步了解停机问题!

2.Example

In this project, the rule is:
TIME LIMIT: 1 second
MEMORY LIMIT: 8 MB
FUNCTION INPUT: 5

What should you do in this project:
1. Define the function “Decide()”;
2. In “Decide()”, different functions will be as input;
3. The program you write should stop the unstopable function;
4. The program you write should run through the stopable function;

Simple

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值