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
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started