简体   繁体   English

哈希表与AVL树链接

[英]Hash table chaining with avl tree

i am hashing strings.. and then i have to sort second strings alphabetically. 我正在对字符串进行哈希处理。然后我必须按字母顺序对第二个字符串进行排序。 I have to be able to delete,insert or get number of position in my sorted tree of second strings. 我必须能够删除,插入或获得第二个字符串排序树中的位置数。 So, for example i have hash table based on type of animals (cat,dog..) and each bucket has AVL tree with names sorted aplhabetically. 因此,例如,我有一个基于动物(猫,狗..)类型的哈希表,每个存储桶都有AVL树,其名称按字母顺序排序。

insert("cat","Garfield"); insert(“ cat”,“ Garfield”); insert("cat","Zoro"); insert(“ cat”,“ Zoro”);

garfield and zoro would have same hash key because they are both cats but garfield would be root and zoro right child.. so when i would want to delete garfield i have to sort the tree again.. garfield和zoro将具有相同的哈希键,因为它们都是猫,但是garfield将会是root和zoro的正确子代。。所以当我要删除garfield时,我必须再次对树进行排序。

My question is, if hash table + avl tree is the fastest option? 我的问题是,如果哈希表+ avl树是最快的选择? also like i said i need to be able to get name of animal base on type(hash key) plus index. 也像我说的那样,我需要能够基于类型(哈希键)加上索引来获取动物的名称。

edit:This is just an example everything is variable and inserted through function so number of spieces can be 1million and names too 编辑:这只是一个例子,一切都是可变的,并通过函数插入,因此片段数可以是100万,名称也可以

In general, if your requirement has lot of traversals that covers the entire table and also if there are lot of deletions or insertions than seach operations, then AVL trees are preferred. 通常,如果您的需求具有遍历整个表的大量遍历,并且与seach操作相比有很多删除或插入,那么AVL树是首选。 However, if your requirement needs lot of search operations relatively (relative to insertion or deletion), then Hash table is a very good option.. 但是,如果您的需求相对(相对于插入或删除)需要大量搜索操作,则哈希表是一个很好的选择。

In case if you are going in for hashing in which collision resolution is by chaining then the array is used to hold the key and a pointer to a tree / linked list ( Here its a tree). 如果要进行散列处理(其中冲突解决方案是通过链接实现),则使用数组来保存键和指向树/链接列表(此处为树)的指针。 In that case, the disadvantage is that the memory overhead will be high and less locality of reference. 在那种情况下,缺点是存储器开销将很高并且引用的局部性较小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM