使用divide and-conquer; to divide and-conquer	 to witr	 and algorithm	 algorithM	 x9;项目
使用分界线和争议方法编写一种算法,该算法找到最大的项目
在n个项目列表中。分析您的算法,并按顺序显示结果
Use the divide-and-conquer approach to write an algorithm that finds the largest item
in a list of n items. Analyze your algorithm, and show the results in order notation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用于在数组中找到最大元素的分裂和诱导算法将阵列分为两半,分别求解每个子问题,然后将解决方案的最大值返回到两个子问题上。递归的基本情况是当子问题具有1尺寸1时,在这种情况下,最大值是数组中的元素。运行时间的复发为$ t(n)= 2t(n/2)+c $,由主定理具有解决方案$ t(n)= \ theta(n)$。
这与线性搜索相同的渐近运行时间(但要大于)。这是伪代码:
A divide-and-conquer algorithm for finding the maximum element in an array would split the array into two halves, solve each subproblem separately and return the maximum of the solutions to the two subproblems. The base case of the recursion would be when the subproblem has size 1, in which case the maximum is the element in the array. The recurrence for the running time is $T(n)=2T(n/2)+c$, which has solution $T(n)=\Theta(n)$ by the Master theorem.
This is the same asymptotic running time as (but a constant factor larger than) linear search. Here's the pseudocode: