最好的情况下,大O的复杂性

编程入门 行业动态 更新时间:2024-10-11 13:30:38
本文介绍了最好的情况下,大O的复杂性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

问题: 你怎么能限制输入数据,以达到更好的大O的复杂性?描述一个算法来处理这​​有限的数据,以寻找是否有任何重复。什么是大O的复杂性?的(通过限制数据,是指数据的大小/阵列)。

The question: how can you limit the input data to achieve a better Big O complexity? Describe an algorithm for handling this limited data to find if there are any duplicates. What is the Big O complexity? (By limiting data, we mean size of data/ array).

有我需要帮助我实现该任务的解决方案。我已经打消了我答案,我张贴,因为它们不是necessary-感谢您的帮助家伙:)

Got the solutions i needed to help me achieve the task. I've removed my answers that i posted since they weren't necessary- thanks for your help guys :)

推荐答案

可以达到更好的大O的复杂性,如果你知道的最大值的整数数组可以采取。可以说,它为m。 该算法来做到这一点是桶排序的方差。的复杂度为O(N)。 来源$ C ​​$算法的C:

You can achieve a better big O complexity if you know the max value your integer array can take. Lets say it as m. The algorithm to do it is the variance of Bucket Sort. The complexity is O(n). Source code of algorithm:

public boolean HasDuplicates(int [] arr, int m) { boolean bucket[] = new boolean[m]; for (int elem : arr) { if (bucket[elem]) { return true; // a duplicate found } bucket[elem] = true; } return false; }

更多推荐

最好的情况下,大O的复杂性

本文发布于:2023-11-30 22:14:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:最好的   复杂性   情况下

发布评论

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

>www.elefans.com

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