Hey Benjamin,<br><br>Taking a guess with the information you&#39;ve given perhaps a <a href="http://en.wikipedia.org/wiki/Hash_table">hash table</a> could help?<br><br>Fast lookup/retrieval, but just have to consider what you would enumerate as the key, and loading.<br>
<br>Let me know if you want some help applying this, memories of a uni assignment have just come flooding back.<br><br><br>James.<br><br><br><br><div class="gmail_quote">2009/6/7 Benjamin M. Schwartz <span dir="ltr">&lt;<a href="mailto:bmschwar@fas.harvard.edu">bmschwar@fas.harvard.edu</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I am looking for a fast data structure with the following properties:<br>
<br>
Maintains an indexed list of arbitrary, non-ordered objects (like a python<br>
List or C array)<br>
Allows fast:<br>
Insertion at any location<br>
Deletion at any location<br>
Lookup of an object by its index<br>
Reverse lookup, to determine the index of an object<br>
<br>
Python&#39;s List has O(1) lookup, but O(N) insert, delete, and<br>
reverse-lookup.  To make reverse lookup O(1) I could maintain a separate<br>
Dict mapping objects to indices, but this would cost an additional O(N) on<br>
every insertion and deletion.<br>
<br>
A linked list has O(1) insertion and deletion, but O(N) lookup and O(N)<br>
reverse lookup.  I could maintain a separate Dict for the forward and<br>
reverse mappings, but this would cost O(N) on every insertion and deletion.<br>
<br>
A standard self-balancing tree cannot be used because the objects are not<br>
ordered, and self-balancing trees require ordered keys.  I could use the<br>
index of an object as the sort key, but then insertion and deletion are<br>
O(N) because all subsequent keys must be altered.  I could fabricate new<br>
sort keys to ensure that insertions occur at the desired location, but<br>
then the length of the keys will grow like O(N), making all operations at<br>
least O(N).<br>
<br>
I feel like there should be some kind of standard tree-like data structure<br>
that meets my requirements, but I can&#39;t find one.  Do you know of one?  Am<br>
I on a unicorn hunt?<br>
<br>
--Ben<br>
<br>
<br>_______________________________________________<br>
Sugar-devel mailing list<br>
<a href="mailto:Sugar-devel@lists.sugarlabs.org">Sugar-devel@lists.sugarlabs.org</a><br>
<a href="http://lists.sugarlabs.org/listinfo/sugar-devel" target="_blank">http://lists.sugarlabs.org/listinfo/sugar-devel</a><br>
<br></blockquote></div><br>