排序N元素的数组与O(LOGN)不同的元素在O(nloglogn)最坏情况下的时间

编程入门 行业动态 更新时间:2024-10-11 11:23:42
本文介绍了排序N元素的数组与O(LOGN)不同的元素在O(nloglogn)最坏情况下的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

眼下的问题是什么在标题本身。这是给一个算法进行排序在O(nloglogn)最坏情况下的n元素的数组与O(LOGN)不同的元素。任何想法?

The problem at hand is whats in the title itself. That is to give an algorithm which sorts an n element array with O(logn) distinct elements in O(nloglogn) worst case time. Any ideas?

另外,你如何处理一般的阵列与多个非重复元素?

Further how do you generally handle arrays with multiple non distinct elements?

推荐答案

O(日志(LOG( N 的)))时间足够让你做一个基本操作为O搜索树(日志( N 的))的元素。

O(log(log(n))) time is enough for you to do a primitive operation in a search tree with O(log(n)) elements.

因此​​,保持所有的不同的的,你所看到的,到目前为止元素平衡查找树。树中的每个节点还含有你已经看到与该键的所有元素的列表。

Thus, maintain a balanced search tree of all the distinct elements you have seen so far. Each node in the tree additionally contains a list of all elements you have seen with that key.

漫步输入元素一个接一个。对于每个元素,试图将其插入树(这需要O(log日志的 N 的)时间)。如果你发现你已经看到相同的元素,只是将其插入辅助列表中已经存在的节点。

Walk through the input elements one by one. For each element, try to insert it into the tree (which takes O(log log n) time). If you find you've already seen an equal element, just insert it into the auxiliary list in the already-existing node.

遍历整个列表之后,穿行于树顺序串联辅助列表。 (如果你照顾在恰当的两端辅助列表插入,这甚至是一个稳定的排序)。

After traversing the entire list, walk through the tree in order, concatenating the auxiliary lists. (If you take care to insert in the auxiliary lists at the right ends, this is even a stable sort).

更多推荐

排序N元素的数组与O(LOGN)不同的元素在O(nloglogn)最坏情况下的时间

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

发布评论

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

>www.elefans.com

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