数组递归关系的解决方案
来自墨西哥。真相几乎从来没有被问过或提出新问题,因为真正的论坛不仅如此,如果不以工作代替网络,你可以找到大量有关主题x或y的信息,然而这次我感到很失败。 我有两年的递归。
- 定义以下递归算法。
一个。计算接下来的 n 个整数。
起初没有提到高手的问题是,如果算法返回一个总和,或者一组数字。此外,虽然在原理和算法设计上,第二种情况需要通过其表达为递归关系来解决……这就是我迷失的地方,而不是如何将其表达为 RR。这是可以解决的
b.计算一组整数的最小值
在另一种情况下,假设需要一组整数的最小值。这已经解决了,但事实上并将其传递给 RR 修复,让我完全被淹没了。
感谢任何帮助,谢谢
from Mexico. The truth is almost never asked or open new issues, because really the forum and not only this, if not to work instead of the network, you can find plenty of information about topic x or y, however this time I feel very defeated.
I have two years of recursion.
- Define the following recursive algorithms.
a. Calculate the next n integers.
At first not referred to the master with this is that if the algorithm returns a sum, or set of numbers. Furthermore, although in principle and algorithm design for the second case is asked to resolve by its expression as a recurrence relation ... this is where I am more than lost, not how to express this as a RR. And that can be solved
b. Calculate the minimum of a set of integers
In the other case suppose that calls for the minimum of a set of integers. that's solved, but the fact and pass it to a RR fix, has left me completely flooded.
APPRECIATE ANY HELP, thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答 b)
你有一组整数。你选择一个,你就知道最小元素要么是你已经选择的,要么最小元素仍在集合中。递归地调用函数,除非从集合中选取所有元素,否则假设不包含元素的集合的最小值是无穷大。那么你的循环就是回去更新最小值。
最小值 (S) = min(任何元素, 最小值(S 的其余部分))
如果(S 为空)则最小值(空)= 无穷大。
不是任何语言的实现都肯定依赖于集合的表示。
PS 为什么要递归地这样做?
Answering on b)
You have a set of integers. You pick one and you know that minimal element is either that you've picked or the minimal is still in the set. Recursivly you call function unless you pick all elements from set, you assume that minimum of set that contain no elements is infinity. Then your recurrence is going back updateing the minimal value.
minimum (S) = min(any element, minimum(Rest of S))
if (S is empty) then minimum(empty) = infinity.
Not an implementation in any language cause surely depend on representation of set.
P.S why doing this recursivly?