简体   繁体   中英

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). Also search(x) operation should be in O(log n) time.

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. 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. Hence, findMin() and findMax() are also O(1) .
insert() and delete() are also in constant time.

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.

Hash table provides (if implemented correctly), search, delete and insert in O(1) . The rest of the operations ( successor() , predecessor() ) are available in skip list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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