English 中文(简体)
高效操纵和检索关键和指数的数据结构
原标题:Data structure with efficient manipulation and retrieval by both key and index

I m 寻找一个数据结构,其功能是OrderedDictionary in .NET,也就是说,一种关联性收集(即与key>> 相联的收集(与正常List相同)。

它必须迅速以指数和钥匙进行审视。 它还应当有快速的“申请”操作(在最后添加一个新项目),并迅速清除具有任何指数的物品(根据指数或关键)。

<代码>OrderedDictionary in .NET 既使用散列表,又使用阵列储存其物品,如果I m不错的话。 因此,根据关键(或反之亦然)修改一个指数如下:O(n),当然,从一个阵列的中间移除一个项目为O(n),首先从中选取该指数,如果按钥匙去除,则从中选取该指数。

我的问题是,是否存在一个能满足我条件的更有效的数据结构,或者这确实是我在这里的最佳选择?

最佳回答

我认为,你可以通过两 trees黑树这样做: 一个主要ook树,储存由比较功能订购的钥匙,一个指数-ook树,如清单所示,是任意订购的关键。 每个指数级分校必须有一个面积小的领域,如果每个小点都包含面积面积,那么红黑树可以按指数进行勘测。 See for example the RedBlackTreeSet implementation in the C5 Generic Collection Library

关键ook树的每一条目都需要一个点子,才能进入指数-l树的相应条目。 除了左点和右边点,指数-l树将需要一个母点,以便进行自下而上的至上导航以及从上到下。

每一关键点都需要6个点:每一分点的通常左点和正确点,加上从关键角到指数-指标的点子,加上每个指数-指标的上级点子。 你们还需要每个节点的一位点子来说明储存的价值。

行动:

附录 - 对应行动将把钥匙插入两.树——一次在关键ook树中,一次在比较功能确定的位置上,再一次在指数-l树的最正确位置上。 植入红黑树是一种 log时间运行。

关键——这是在主要ook树上进行的,利用比较功能找到正确的位置——O(log(n))

Lookup by index - this can be done on the index-lookup field, as mentioned above - O(log(n))

关键指标——首先研究关键ook树O(log(n)的关键。 跟踪点对指数ook树。 (O(log(n)))对平方树进行跟踪。 使用面积田来确定钥匙的指数。 - O(log(n))

删除指数-在指数-l树中研究该项目。 删除指数ook树。 审视关键ook树的地基。 删除主要ook树。 所有业务均为O(log(n)) ,因此删除的是O(log(n) 。

Delete by key - use Get index from key to get the index of the key. Delete by index from the index-lookup tree. Delete by key from the key-lookup tree. O(log(n)) overall.

This structure also supports O(log(n)) insertion at any arbitrary position, not just at the end.

储存间接费用显然相当可观,但仍然是O(n)。 时间的复杂性符合所有要求。

不幸的是,我不知道这一结构的执行情况。

最新情况:你可以把树木与一个散板桌结合起来,以便用钥匙进行O(1)的检查。 我上文建议,不要有两 trees树,而是使用一个 has表,用于按地盘 look,并如上所示为平板块 look树,但 has树的分位数则含有平衡树木的子点,用于进行逐个清单的勘测。 现在由主人看的是O(1),其他一切都平均留在O(ln)(n)。 当然,现在,你们有时会得到O(n)的重罚,就像任何 has一样。

问题回答

You can use Balanced binary search tree like the link, just for in definition of TreeNode you should add your keys, but the problem is finding element is not O(1), it s O(log(n)) both by keys and index (in fact index is not part of TreeNode, relatively can be found) but all operations are O(log(n)) and is fastest known way based on comparison methods.





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...