Data structure name: combination array/linked list

后端 未结 6 1715
天涯浪人
天涯浪人 2020-12-23 17:43

I have come up with a data structure that combines some of the advantages of linked lists with some of the advantages of fixed-size arrays. It seems very obvious to me, and

相关标签:
6条回答
  • 2020-12-23 18:11

    While I don't know your task, I would strongly suggest you have a look at skip lists.

    As for name, I'm thinking a bucket list would probably be most apropos

    0 讨论(0)
  • 2020-12-23 18:13

    You can call it LinkedArrays.

    Also, I would like to see the pseudo-code for the removeIndex operation.

    0 讨论(0)
  • 2020-12-23 18:19

    What are the advantages of this data structure in terms of insertion and deletion? Ex: What if you want to add an element between 3 and 4? still have to do a shift, it takes O(N) How do you find out the correct bucket for elementAt?

    I agree with jer, you must take a look on skip list. It brings the advantages of Linked List and Arrays. The most of operations are done in O(log N)

    0 讨论(0)
  • 2020-12-23 18:22

    It's called an unrolled linked list. There appear to be a couple of advantages, one in speed and one in space. First, if the number of elements in each node is appropriately sized (e.g., at most the size of one cache line), you get noticeably better cache performance from the improved memory locality. Second, since you have O(n/m) links, where n is the number of elements in the unrolled linked list and m is the number of elements you can store in any node, you can also save an appreciable amount of space, which is particularly noticeable if each element is small. When constructing unrolled linked lists, apparently implementations will try to generally leave space in the nodes; when you try to insert in a full node, you move half the elements out. Thus, at most one node will be less than half full. And according to what I can find (I haven't done any analysis myself), if you insert things randomly, nodes tend to actually be about three-quarters full, or even fuller if operations tend to be at the end of the list.

    And as everyone else (including Wikipedia) is saying, you might want to check out skip lists. Skip lists are a nifty probabilistic data structure used to store ordered data with O(log n) expected running time for insert, delete, and find. It's implemented by a "tower" of linked lists, each layer having fewer elements the higher up it is. On the bottom, there's an ordinary linked list, having all the elements. At each successive layer, there are fewer elements, by a factor of p (usually 1/2 or 1/4). The way it's built is as follows. Each time an element is added to the list, it's inserted into the appropriate place in the bottom row (this uses the "find" operation, which can also be made fast). Then, with probability p, it's inserted into the appropriate place in the linked list "above" it, creating that list if it needs to; if it was placed in a higher list, then it will again appear above with probability p. To query something in this data structure, you always check the top lane, and see if you can find it. If the element you see is too large, you drop to the next lowest lane and start looking again. It's sort of like a binary search. Wikipedia explains it very well, and with nice diagrams. The memory usage is going to be worse, of course, and you're not going to have the improved cache performance, but it is generally going to be faster.

    References

    • “Unrolled Linked List”, http://en.wikipedia.org/wiki/Unrolled_linked_list
    • “Unrolled Linked Lists”, http://blogs.msdn.com/b/devdev/archive/2005/08/22/454887.aspx
    • “Skip List”, http://en.wikipedia.org/wiki/Skip_list
    • The skip list lecture(s) from my algorithms class.
    0 讨论(0)
  • 2020-12-23 18:24

    I would call this a bucket list.

    0 讨论(0)
  • 2020-12-23 18:34

    CDR coding (if you're old enough to remember Lisp Machines).

    Also see ropes which is a generalization of this list/array idea for strings.

    0 讨论(0)
提交回复
热议问题