Design a data structure which does the following. solve using Java You have to do all the
Question:
Design a data structure which does the following. solve using Java
You have to do all the operations in O(1) time.
1) Inc(Key) -> Takes a key and increment its value by 1. If the key comes first time then make its value as 1.
2) Dec(Key) -> Takes a key and decrement its value by 1. It is given that its value is minimum 1.
3) Findmaxkey() -> Returns the key which has the maximum value corresponding to it. If there are multiple such keys then you can output any of them.
4) Findminkey() -> Returns the key which has the minimum value corresponding to it. If there are multiple such keys then you can output any of them.
Hint: You can also use a dictionary(hashmap) with a doubly-linked list. Dictionary means java.util.Dictionary
Modern Systems Analysis And Design
ISBN: 9780134204925
8th Edition
Authors: Joseph Valacich, Joey George