递归算法找到两个整数求和给定的整数数组

编程入门 行业动态 更新时间:2024-10-25 02:26:42
本文介绍了递归算法找到两个整数求和给定的整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要一种算法,以确定是否一个数组包含两个要素总和到一个给定的整数。

I need an algorithm to determine if an array contains two elements that sum to a given integer.

数组排序。

该算法应该是递归并为O(N)。

The algorithm should be recursive and runs in O(n).

递归步骤应基于总和,这意味着该方法进入的总和,并返回真或假根据最终结果(如果两个元件发现 - 返回true,否则 - 返回false)

The recursive step should be based on the sum, meaning the method passes the sum and return true or false depending on the end result (if two elements are found - return true, else - return false)

仅线性数据结构都可以使用。

Only linear data structures can be used.

任何想法是AP preciated ..

Any ideas are appreciated..

推荐答案

您可以将任何迭代算法为递归其用(例如)的尾递归。我会更广阔,如果不是功课。我想你会明白它的其他职位。

You can convert any iterative algorithm into a recursive one by using (for instance) tail recursion. I'd be more expansive, if it weren't homework. I think you'll understand it from the other post.

更多推荐

递归算法找到两个整数求和给定的整数数组

本文发布于:2023-11-29 22:02:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   递归   数组   算法   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!