balanced tree-like data structure that resizes to prime sizes

我们两清 提交于 2019-12-25 04:36:11

问题


Relating to this: stack overflow question,

where I found out that .Net dictionaries resize to the next prime size that is at least twice the current size, I was wondering if there is any balanced tree-like data structure that can resize to prime sizes (similar to B-Trees or Binomial trees maybe).

What is the tree-like data structure behind .Net's dictionaries?

Thanks.


回答1:


The Dictionary uses a hash table algorithm, which stores the data in an array, it is this array that is sized/re-sized based on Prime numbers.

.NET SortedDictionary uses a Red-Black tree structure to maintain the Key/Value pairs. Since the red-black tree is not stored in a fixed array, but rather as a series on nodes with left/right child nodes, there is not really a concept of sizing anything, as nodes are added to the tree the tree is rotated to maintain the balance.




回答2:


.Net's dictionaries are implemented as hastables, which is not a tree-like data structure at all. The question you link to explains why hashtables are better resized to a prime number.

As for tree-like structures, I can't imagine a purpose for resizing to a prime. It doesn't make much sense. What does make sense though, is resizing a balanced tree structure to a complete tree, which for a binary tree would be 2n-1.



来源:https://stackoverflow.com/questions/4639122/balanced-tree-like-data-structure-that-resizes-to-prime-sizes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!