在O(n)时间复杂度中仅针对正整数计算阵列中任何n

编程入门 行业动态 更新时间:2024-10-26 14:40:02
本文介绍了在O(n)时间复杂度中仅针对正整数计算阵列中任何n-1个元素的最大乘积的算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

算法以O(n)时间复杂度计算数组中任何n-1个元素的最大乘积仅为正整数 我是什么尝试过: 我尝试使用Brute force方法解决。复杂性是o(n ^ 2)

Algorithm to calculate the maximum product of any n-1 elements in the array in O(n) time complexity for only positive integers What I have tried: I have tried solving using Brute force method. The complexity comes out to be o(n^2)

推荐答案

Quote:

算法以O(n)时间复杂度计算数组中任何n-1个元素的最大乘积仅为正整数

Algorithm to calculate the maximum product of any n-1 elements in the array in O(n) time complexity for only positive integers

这是您找到/创建解决的算法的工作问题,家庭作业是为了练习。 你的任务是找到一个有效的算法。

This is your job to find/create algorithms that solve problems, homeworks is made for practicing. Your task is to find an efficient algorithm.

引用:

我试过了用蛮力法解决。复杂性是o(n ^ 2)

I have tried solving using Brute force method. The complexity comes out to be o(n^2)

暴力是最低效的算法,但至少你做了一个解决方案。 但是整个事情是让你使用你的大脑,并从不同方面探索问题,直到你找到有用的东西。 - 首先学习/掌握主题乘法,我希望你已经掌握了一些几年前。 - 想出不同的方式来提问。 我必须从列表中删除哪个整数才能获得最大产品? - 拿一张纸和一支铅笔,然后从小样本开始。手工解决。 我应该删除哪个整数才能获得最大的产品? 1 2 3 4 5 为什么删除这个整数是解决方案? 您是否需要计算所有5个产品才能找到答案? 如果列表是1 2 3 4 ... 96 97 98 99怎么办? 到目前为止,您应该发现解决方案非常简单以至于您想知道为什么你没有找到一个人。 - 学习一种或多种分析方法,EW Djikstra / N. Wirth Stepwize Refinement / top-Down方法是一个良好的开端。 Structured Programming.pdf [ ^ ] https://en.wikipedia。 org / wiki / Top-down_and_bottom-up_design [ ^ ] en.wikipedia/wiki/Structured_programming [ ^ ] en.wikipedia/wiki/Edsger_W._Dijkstra [ ^ ] www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF [ ^ ]

Brute force is the most inefficient algorithm, but at least you did a solution. But the whole thing is about making you using your brain, and explorer the problem from different aspects until you find something useful. - First study/master the subject "multiplication", I hope you have mastered it a few years ago. - think of different ways to ask the question. Which integer do I have to remove from the list to get maximum product? - Take a sheet of paper and a pencil and start with a small sample. Solve by hand. Which integer should I remove to get maximum product? 1 2 3 4 5 Why removing this integer is the solution? Do you need to calculate all 5 five products to find the answer? What if list is 1 2 3 4 ... 96 97 98 99. by this point, you should have found that the solution is so simple that you wonder why you didn't find alone. - Learn one or more analyze methods, E.W. Djikstra/N. Wirth Stepwize Refinement/top-Down method is a good start. Structured Programming.pdf[^] en.wikipedia/wiki/Top-down_and_bottom-up_design[^] en.wikipedia/wiki/Structured_programming[^] en.wikipedia/wiki/Edsger_W._Dijkstra[^] www.cs.utexas.edu/users/EWD/ewd03xx/EWD316.PDF[^]

更多推荐

在O(n)时间复杂度中仅针对正整数计算阵列中任何n

本文发布于:2023-11-30 12:19:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649923.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复杂度   阵列   时间   正整数

发布评论

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

>www.elefans.com

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