简体   繁体   English

实现数据结构-Flex词典

[英]Implementing data structure - flex dictionary

I've been asked to devise a data structure that represents a dictionary. 我被要求设计一个代表字典的数据结构。 The dictionary holds items with distinct key number. 该词典包含具有不同键号的项目。 The data structure should support the following operations in O(1) time: insert(x), delete(x), findMin(), findMax(), successor(x), predecessor(x). 数据结构应在O(1)时间内支持以下操作:insert(x),delete(x),findMin(),findMax(),successor(x),predecessor(x)。 Also search(x) operation should be in O(log n) time. search(x)操作也应在O(log n)时间内进行。

The assignment was given on the following subjects: skip list, hash tables and heaps. 分配是在以下主题上进行的:跳过列表,哈希表和堆。 I guess the best structure will be a skip list, but I couldn't find a way implementing insert and delete in O(1) tine. 我想最好的结构将是一个跳过列表,但是我找不到在O(1)例行中实现插入和删除的方法。 Any suggestions? 有什么建议么?

You should use both hash table and skip list data structures. 您应该同时使用哈希表和跳过列表数据结构。 You can update min and max values each time you insert an element. 您可以在每次插入元素时更新minmax Hence, findMin() and findMax() are also O(1) . 因此, findMin()findMax()也是O(1)
insert() and delete() are also in constant time. insert()delete()也处于恒定时间。

By the way, you cannot delete an item before searching for it. 顺便说一句,您无法在搜索之前删除项目。 If you do search in O(logn) , delete() will be O(logn) automatically. 如果确实在O(logn)搜索,则delete()将自动为O(logn)

Hash table provides (if implemented correctly), search, delete and insert in O(1) . 哈希表提供(如果正确实现),搜索,删除和插入O(1) The rest of the operations ( successor() , predecessor() ) are available in skip list. 其余操作( successor()predecessor() )在跳过列表中可用。

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

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