aka.gusu
BAN USER
There are 3 operations - check-in (could be any nth element), check-out, get least check in number. If we use BitSet (arraylist that stores everything in bits), the time complexity to set/get bit at nth location would be constant O(1), since it uses array under-neath and random-access search from array is O(1). So, check-in and check-out could be done by saying bitset.set(n) or bitset.get(n) in O(1). To get the least check-in number - we can do 2 things : sequential search O(n) (based on the application - if lets say least numbers are most likely to be checked-in first thereby hoping to achieve O(1) in most cases) - goal here is that we are mostly expecting the best case scenario. The second thing could be to do binary search O(log n) - worst case to find the least checked-in number.
In terms of space complexity, with Bitset we can store 8 bits in 1 byte. That's like achieving log n with base 8. Which is pretty good.
Repjuliaaperez05, Cloud Support Associate at ABC TECH SUPPORT
I Performed extensive web research to collect pertinent data and gather images related to the assigned articleIts act of writing ...
Repmarthahiggs71, Intern at Achieve Internet
Hi, I am Martha from Toledo, OH. Working with Top NYC consulting engineers by helping them design controls projects. Have ...
Repallisonepollard, Applications Developer at Accenture
I am Allison from Germantown. I work as a Staff manager at The LawnGuru company. But my interest in blogging ...
Repharrylseay, Aghori Mahakal Tantrik at ASAPInfosystemsPvtLtd
I am Harry and I live in the USA but basically I am from Bangor. I live my life very ...
Rep
Repmarywwaldrop7, Computer Scientist at Chelsio Communications
I am Mary ,working in the field of training and development coordinator for three years, focusing on teaching English as ...
We need to track numbers that are distinct, so need to go with Set. We need to check if the next number already exists in the Set and if it does then we need to remove it, so need to have a quick lookup - Hash. Insertion order is important so need to be Linked. So, use LinkedHashSet - add numbers as they arrive but check if it exists already. If it exists then rather than additing to the Set, remove it from the Set. So, O(n) time and O(n) space.
- aka.gusu November 10, 2012