什么是“天真”?算法,以及什么是“封闭形式”?解决方案?

发布于 2024-11-01 16:51:22 字数 168 浏览 4 评论 0原文

我有一些关于描述算法时使用的术语语义的问题。

首先,“朴素”算法是什么意思?这与给定问题的其他解决方案有何不同?解决方案还可以采取哪些其他形式?

其次,我听到很多人提到“封闭式”解决方案。我也不知道这意味着什么 - 但在尝试解决递归关系时经常会出现......

感谢您的时间

I have a few questions regarding the semantics of terminology used when describing algorithms.

Firstly, what is meant by a 'naive' algorithm? How does this differ from other solutions to a given problem? What other forms can solutions take?

Secondly, I have heard much reference to having a 'closed - form' solution. I have no idea what this means either - but often it appears when trying to solve recurrence relations...

Thanks for your time

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

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

发布评论

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

评论(3

匿名的好友 2024-11-08 16:51:22

当有人提出问题时,朴素算法通常是最明显的解决方案。它可能不是一个聪明的算法,但可能会完成工作(......最终。)

例如。尝试在已排序的数组中搜索元素。
朴素算法是使用线性搜索
一个不那么幼稚的解决方案是使用二分搜索。

一个更好的例子是子字符串搜索 Naive Algorithm 远远不够效率低于 Boyer–MooreKnuth–Morris–Pratt 算法

A 封闭式解决方案是一个简单的解决方案,可以立即运行,无需任何循环、函数等。

例如:
1 到 n 整数之和的迭代算法

s= 0
for i in 1 to n
s = s + i
end for
print s

封闭式(针对同一问题)

s = n * (n + 1 ) /2

A Naive algorithm is usually the most obvious solution when one is asked a problem. It may not be a smart algorithm but will probably get the job done (...eventually.)

Eg. Trying to search for an element in a sorted array.
A Naive algorithm would be to use a Linear Search.
A Not-So Naive Solution would be to use the Binary Search.

A better example, would be in case of substring search Naive Algorithm is far less efficient than Boyer–Moore or Knuth–Morris–Pratt Algorithm

A Closed Form Solution is a simple Solution that works instantly without any loops,functions etc..

Eg:
Iterative Algorithm for sum of integer from 1 to n

s= 0
for i in 1 to n
s = s + i
end for
print s

Closed Form (for the same problem)

s = n * (n + 1 ) /2
亣腦蒛氧 2024-11-08 16:51:22

朴素算法是一种非常简单的算法,具有非常简单的规则。有时候第一个想到的就是这个。它可能很愚蠢而且很慢,甚至可能无法解决问题。有时这可能是最好的。下面是一个问题和“简单”算法的示例:

问题:您处于一个(二维)迷宫中。找到出路。 (意思是:到一个带有“EXIT”标志的地点:)

朴素算法 1:开始行走,并在遇到的每个十字路口选择正确的十字路口(直到找到“EXIT”)。

朴素算法 2:开始行走并在遇到的每个十字路口中随机选择一个十字路口(直到找到“出口”)。

算法 1 甚至无法让你走出某些迷宫!

算法 2 会让你走出所有迷宫(尽管这很难证明)。

Naive algorithm is a very simple algorithm, one with very simple rules. Sometimes the first one that comes to mind. It may be stupid and very slow, it may not even solve the problem. It may sometimes be the best possible. Here's an example of a problem and "naive" algorithms:

Problem: You are in a (2-dimensional) maze. Find your way out. (meaning: to a spot with an "EXIT" sign :)

Naive algorithm 1: Start walking and choose the right one in every intersection you meet (until you find "EXIT").

Naive algorithm 2: Start walking and choose a random one in every intersection you meet (until you find "EXIT").

Algorithm 1 will not even get you out of some mazes!

Algorithm 2 will get you out of all mazes (although this is rather hard to prove).

负佳期 2024-11-08 16:51:22

封闭形式意味着您可以给出一个表达式作为解决方案,这确实可以解决它而无需递归/递归。这里应该指出,并不总是能够找到这样一种封闭的形式。

天真的意思就是它所说的:对问题的第一个愚蠢的解决方案,解决了它,但可能不是非常时间/空间效率。人们真正认为什么是“天真”取决于说话者、上下文和第二天的天气。通常它用于区分非常复杂的解决方案(使用某种技巧)和明显的实现。

Closed form means you can give the one expression as solution, that does solve it without recurrence/recursive. Here one should remark, that it is not always possible to find such a closed form.

Naive means just that what it says: A first, stupid solution to the problem, that solves it, but maybe not very time-/space efficient. What one really considers 'naive' depends on the speaker, the context, and the weather of the next day. Often it is used to distinguish a very sophisticated solution (that uses some kind of trick) from the obvious implementation.

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