Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data structure with fast indexOf?

I need an ordered data structure with O(1) indexOf operation. I store object pointers in the data structure. Any ideas? Some sort of LinkedHashMap?

See what "indexOf" means: List.indexOf(Object)

like image 770
bittersoon Avatar asked Nov 29 '10 06:11

bittersoon


People also ask

Which data structure is fastest?

With a hash table, you can access objects by the key, so this structure is high-speed for lookups. Hash tables are faster than the arrays for lookups.

Which is the most appropriate data structure for an index at the end of a book?

The data structure should be stored in disk, during or at the end of the indexing procedure. The algorithm should quickly ( O(log(n)) ) find the occurrences of any subset of the text. For instance, if the input is book it should find all occurrences of it, but this should also be true for book is and The book is .

Which data structure is the most efficient for insertion and deletion at only read last position?

arrays - Efficient data structure for fast random access, search, insertion and deletion - Stack Overflow.

In which data structure we can delete insert element easily?

Stack is a linear data structure in which the insertion and deletion operations are performed at only one end. In a stack, adding and removing of elements are performed at single position which is known as "top". That means, new element is added at top of the stack and an element is removed from the top of the stack.


1 Answers

This question is ambiguous to begin with.

  1. It would be nice if you could qualify what you mean by fast indexOf(..) operation.
  2. What kind of objects are you going to store in the collection?
  3. Is finding the indexOf(..) the only responsibility of the collection.

Simply put, one way to do this would be to maintain a that would index each Object or keys with the list of indices.

HashMap<Object, List<Integer>>

Again, this is vague, probably would help if you specify the exact nature of problem you're trying to solve.

like image 145
kuriouscoder Avatar answered Sep 21 '22 08:09

kuriouscoder