为什么回溯会使算法变得不确定?

发布于 2024-07-13 04:54:13 字数 98 浏览 6 评论 0原文

因此,至少有两位教授提到回溯使算法变得不确定,但没有给出太多解释为什么会这样。 我认为我理解这是如何发生的,但我很难用语言来表达。 有人能给我一个简洁的解释吗?

So I've had at least two professors mention that backtracking makes an algorithm non-deterministic without giving too much explanation into why that is. I think I understand how this happens, but I have trouble putting it into words. Could somebody give me a concise explanation of the reason for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

池木 2024-07-20 04:54:13

回溯并不是让算法变得不确定的情况。

相反,您通常需要回溯来处理非确定性算法,因为(根据非确定性的定义)您不知道在处理过程中的特定时间采用哪条路径,而是必须尝试多条路径。

It's not so much the case that backtracking makes an algorithm non-deterministic.

Rather, you usually need backtracking to process a non-deterministic algorithm, since (by the definition of non-deterministic) you don't know which path to take at a particular time in your processing, but instead you must try several.

愁以何悠 2024-07-20 04:54:13

我简单引用一下维基百科:

非确定性编程语言是一种可以在程序中的某些点(称为“选择点”)指定程序流的各种替代方案的语言。 与 if-then 语句不同,这些替代方案之间的选择方法不是由程序员直接指定的; 程序必须在运行时通过应用于所有选择点的某种通用方法在替代方案之间做出决定。 程序员指定了有限数量的替代方案,但程序随后必须在它们之间进行选择。 (事实上​​,“选择”是非确定性运算符的典型名称。)可以形成选择点的层次结构,较高级别的选择导致包含较低级别选择的分支。

一种选择方法体现在回溯系统中,其中某些替代方案可能“失败”,导致程序回溯并尝试其他替代方案。 如果所有替代方案在特定选择点都失败,则整个分支都会失败,并且程序将进一步回溯到较旧的选择点。 一个复杂的问题是,由于任何选择都是试探性的并且可能会被重新制定,因此系统必须能够通过消除部分执行最终失败的分支所造成的副作用来恢复旧的程序状态。

摘自非确定性编程文章。

I'll just quote wikipedia:

A nondeterministic programming language is a language which can specify, at certain points in the program (called "choice points"), various alternatives for program flow. Unlike an if-then statement, the method of choice between these alternatives is not directly specified by the programmer; the program must decide at runtime between the alternatives, via some general method applied to all choice points. A programmer specifies a limited number of alternatives, but the program must later choose between them. ("Choose" is, in fact, a typical name for the nondeterministic operator.) A hierarchy of choice points may be formed, with higher-level choices leading to branches that contain lower-level choices within them.

One method of choice is embodied in backtracking systems, in which some alternatives may "fail", causing the program to backtrack and try other alternatives. If all alternatives fail at a particular choice point, then an entire branch fails, and the program will backtrack further, to an older choice point. One complication is that, because any choice is tentative and may be remade, the system must be able to restore old program states by undoing side-effects caused by partially executing a branch that eventually failed.

Out of the Nondeterministic Programming article.

揽月 2024-07-20 04:54:13

考虑一种为世界地图着色的算法。 相邻国家不能使用任何颜色。 该算法任意从一个国家开始,并将其着色为任意颜色。 所以它继续前进,为国家着色,每一步都改变颜色,直到“呃哦”,两个相邻的国家具有相同的颜色。 好吧,现在我们必须回溯,并做出新的颜色选择。 现在我们不会像非确定性算法那样做出选择,这对于我们的确定性计算机来说是不可能的。 相反,我们通过回溯来模拟非确定性算法。 不确定性算法将为每个国家做出正确的选择。

Consider an algorithm for coloring a map of the world. No color can be used on adjacent countries. The algorithm arbitrarily starts at a country and colors it an arbitrary color. So it moves along, coloring countries, changing the color on each step until, "uh oh", two adjacent countries have the same color. Well, now we have to backtrack, and make a new color choice. Now we aren't making a choice as a nondeterministic algorithm would, that's not possible for our deterministic computers. Instead, we are simulating the nondeterministic algorithm with backtracking. A nondeterministic algorithm would have made the right choice for every country.

可爱咩 2024-07-20 04:54:13

确定性计算机上回溯的运行时间是阶乘的,即 O(n!)。

非确定性计算机可以在每个步骤中立即正确猜测,而确定性计算机必须尝试所有可能的选择组合。

由于不可能构建一台非确定性计算机,因此您的教授的意思可能如下:

事实证明,复杂性类别 NP 中的难题(非确定性计算机可以通过始终正确猜测来有效解决的所有问题)在真实计算机上无法比回溯更有效地解决。

如果复杂性类别 P(确定性计算机可以有效解决的所有问题)和 NP 不同,则上述陈述成立。 这就是著名的 P vs. NP 问题。 克莱数学研究所为其解决方案提供了 100 万美元的奖金,但该问题多年来一直无法得到证明。 然而,大多数研究者认为P不等于NP。

一个简单的总结方法是:非确定性计算机可以通过始终正确猜测来有效解决的最有趣的问题是如此困难,以至于确定性计算机可能必须尝试所有可能的选择组合,即使用回溯。

The running time of backtracking on a deterministic computer is factorial, i.e. it is in O(n!).

Where a non-deterministic computer could instantly guess correctly in each step, a deterministic computer has to try all possible combinations of choices.

Since it is impossible to build a non-deterministic computer, what your professor probably meant is the following:

A provenly hard problem in the complexity class NP (all problems that a non-deterministic computer can solve efficiently by always guessing correctly) cannot be solved more efficiently on real computers than by backtracking.

The above statement is true, if the complexity classes P (all problems that a deterministic computer can solve efficiently) and NP are not the same. This is the famous P vs. NP problem. The Clay Mathematics Institute has offered a $1 Million prize for its solution, but the problem has resisted proof for many years. However, most researchers believe that P is not equal to NP.

A simple way to sum it up would be: Most interesting problems a non-deterministic computer could solve efficiently by always guessing correctly, are so hard that a deterministic computer would probably have to try all possible combinations of choices, i.e. use backtracking.

故笙诉离歌 2024-07-20 04:54:13

思想实验:

1)隐藏在视野之外的是一些电荷的分布,您可以感受到其中的力,并测量它们产生的势场。 准确地告诉我所有指控的立场。

2)收取一些费用并安排它们。 准确地告诉我他们创造的势场。

只有第二个问题有唯一的答案。 这是矢量场的非唯一性。 这种情况可能与您正在考虑的一些非确定性算法类似。 进一步考虑数学极限,这些极限并不存在,因为它们根据你接近的方向有不同的答案的不连续性。

Thought experiment:

1) Hidden from view there is some distribution of electric charges which you feel a force from and you measure the potential field they create. Tell me exactly the positions of all the charges.

2) Take some charges and arrange them. Tell me exactly the potential field they create.

Only the second question has a unique answer. This is the non-uniqueness of vector fields. This situation may be in analogy with some non-deterministic algorithms you are considering. Further consider in math limits which do not exist because they have different answers depending on which direction you approach a discontinuity from.

君勿笑 2024-07-20 04:54:13

我编写了一个使用回溯(当然)的迷宫跑步者,我将用它作为示例。

你穿过迷宫。 当您到达路口时,您可以掷硬币来决定要走哪条路线。 如果您选择了死胡同,请追溯到路口并走另一条路。 如果您尝试了所有这些,请返回之前的路口。
这个算法是非确定性的,不是因为回溯,而是因为抛硬币。

现在改变算法:当你到达一个路口时,总是先尝试你还没有尝试过的最左边的路线。 如果这导致了死胡同,请返回路口并再次尝试您尚未尝试过的最左边的路线。
该算法是确定性的。 没有任何机会,这是可以预测的:你将始终在同一个迷宫中遵循同一条路线。

I wrote a maze runner that uses backtracking (of course), which I'll use as an example.

You walk through the maze. When you reach a junction, you flip a coin to decide which route to follow. If you chose a dead end, trace back to the junction and take another route. If you tried them all, return to the previous junction.
This algorithm is non-deterministic, non because of the backtracking, but because of the coin flipping.

Now change the algorithm: when you reach a junction, always try the leftmost route you haven't tried yet first. If that leads to a dead end, return to the junction and again try the leftmost route you haven't tried yet.
This algorithm is deterministic. There's no chance involved, it's predictable: you'll always follow the same route in the same maze.

紧拥背影 2024-07-20 04:54:13

如果允许回溯,则允许程序中出现无限循环,这使得程序具有不确定性,因为所采取的实际路径可能总是包含一个循环。

If you allow backtracking you allow infinite looping in your program which makes it non-deterministic since the actual path taken may always include one more loop.

庆幸我还是我 2024-07-20 04:54:13

非确定性图灵机 (NDTM) 可以在一个步骤中执行多个分支。 另一方面,DTM 遵循试错过程。

您可以将 DTM 视为普通计算机。 相比之下,量子计算机与 NDTM 类似,可以更轻松地解决非确定性问题(例如,查看它们在破解密码学中的应用)。 所以回溯对他们来说实际上是一个线性过程。

Non-Deterministic Turing Machines (NDTMs) could take multiple branches in a single step. DTMs on the other hand follow a trial-and-error process.

You can think of DTMs as regular computers. In contrast, quantum computers are alike to NDTMs and can solve non-deterministic problems much easier (e.g. see their application in breaking cryptography). So backtracking would actually be a linear process for them.

妳是的陽光 2024-07-20 04:54:13

我喜欢迷宫的比喻。 为简单起见,让我们将迷宫想象为一棵二叉树,其中只有一条路径。

现在您想尝试深度优先搜索来找到走出迷宫的正确方法。

非确定性计算机将在每个分支点复制/克隆自身并并行运行每个进一步的计算。 这就好像迷宫中的人会在每个分支点复制/克隆自己(就像电影《Prestige》中一样),并将自己的一个副本发送到树的左子分支,将自己的另一个副本发送到树的右子分支。那个树。

最终陷入死胡同的计算机/人会死亡(没有答案就终止)。

只有一台计算机能够幸存(以答案结束),即走出迷宫的计算机。

回溯和非确定性之间的区别如下。

在回溯的情况下,在任何给定时刻只有一台计算机活着,他会执行传统的迷宫解决技巧,简单地用粉笔标记他的路径,当他到达死胡同时,他只是简单地回溯到一个分支点,其子分支他还没有完全探索,就像深度优先搜索一样。

相比之下:

非确定性计算机可以在每个分支点克隆自己,并通过在子分支中运行并行搜索来检查出路。

所以回溯算法在顺序/非并行/确定性计算机上模拟/仿真非确定性计算机的克隆能力。

I like the maze analogy. Lets think of the maze, for simplicity, as a binary tree, in which there is only one path out.

Now you want to try a depth first search to find the correct way out of the maze.

A non deterministic computer would, at every branching point, duplicate/clone itself and run each further calculations in parallel. It is like as if the person in the maze would duplicate/clone himself (like in the movie Prestige) at each branching point and send one copy of himself into the left subbranch of the tree and the other copy of himself into the right subbranch of the tree.

The computers/persons who end up at a dead end they die (terminate without answer).

Only one computer will survive (terminate with an answer), the one who gets out of the maze.

The difference between backtracking and non-determinism is the following.

In the case of backtracking there is only one computer alive at any given moment, he does the traditional maze solving trick, simply marking his path with a chalk and when he gets to a dead end he just simply backtracks to a branching point whose sub branches he did not yet explore completely, just like in a depth first search.

IN CONTRAST :

A non deteministic computer can clone himself at every branching point and check for the way out by running paralell searches in the sub branches.

So the backtracking algorithm simulates/emulates the cloning ability of the non-deterministic computer on a sequential/non-parallel/deterministic computer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文