时间复杂度为搜索和插入操作的排序和不排序的数组,其中包括重复值复杂度、数组、操作、时间

2023-09-11 05:24:10 作者:我非你愛何必曖昧不清

1)对排序的数组我已经使用二进制搜索。 我们知道,在有序数组SEARCH操作最坏的情况下的复杂性是O(LG N)的,如果我们用二进制搜索,其中,N是在一个数组的项数。 这是对于包括重复值,使用二进制搜索数组中的搜索操作的最坏情况下的复杂? 不会是相同O(LG N)?请纠正我,如果我错了!

还有什么是最坏的情况下,使用二进制搜索的排序数组INSERT操作? 我的猜测是O(N)......是这样吗?

2 - )对排序的数组我已经使用线性搜索。 现在我们有一个排序的数组,也可以接受重复的元素/值。  什么是搜索和INSERT操作最好的最坏情况的复杂性。 我认为,我们可以用线性搜索,这将使我们的O(N)最坏情况下的时间为搜索 和删除操作。 我们可以做的比这更好的排序的数组,并执行复杂的变化,如果我们接受了阵列式两份。

解决方案

是的。

最好的情况是无趣的。 (想想为什么,可能是。)最坏的情况是O(N),除了插入。插入到一个排序的数组的速度快,一次操作。 (同样,想想如果你没有看到它。)

在一般情况下,重复进行差别不大,除非特别病理分布。

1-)For sorted array I have used Binary Search. We know that the worst case complexity for SEARCH operation in sorted array is O(lg N), if we use Binary Search, where N are the number of items in an array. What is the worst case complexity for the search operation in the array that includes duplicate values, using binary search?? Will it be the be the same O(lg N)?? Please correct me if I am wrong!!

利用开放定址法实现散列表的创建 插入 删除 查找操作 散列表 中 2

Also what is the worst case for INSERT operation in sorted array using binary search?? My guess is O(N).... is that right??

2-) For unsorted array I have used Linear search. Now we have an unsorted array that also accepts duplicate element/values. What are the best worst case complexity for both SEARCH and INSERT operation. I think that we can use linear search that will give us O(N) worst case time for both search and delete operations. Can we do better than this for unsorted array and does the complexity changes if we accepts duplicates in the array.

解决方案

Yes.

The best case is uninteresting. (Think about why that might be.) The worst case is O(N), except for inserts. Inserts into an unsorted array are fast, one operation. (Again, think about it if you don't see it.)

In general, duplicates make little difference, except for extremely pathological distributions.