27

Is there a data structure to maintain an ordered list that supports the following operations in $O(1)$ amortized time?

  • GetElement(k): Return the $k$th element of the list.

  • InsertAfter(x,y): Insert the new element y into the list immediately after x.

  • Delete(x): Remove x from the list.

For the last two operations, you can assume that x is given as a pointer directly into the data structure; InsertElement returns the corresponding pointer for y. InsertAfter(NULL, y) inserts y at the beginning of the list.

For example, starting with an empty data structure, the following operations update the ordered list as shown below:

  • InsertAfter(NULL, a) $\implies$ [a]
  • InsertAfter(NULL, b) $\implies$ [b, a]
  • InsertAfter(b, c) $\implies$ [b, c, a]
  • InsertAfter(a, d) $\implies$ [b, c, a, d]
  • Delete(c) $\implies$ [b, a, d]

After these five updates, GetElement(2) should return d, and GetElement(3) should return an error.

JeffE
  • 8,703
  • 1
  • 36
  • 47
A T
  • 968
  • 9
  • 21
  • 2
    In Optimal Algorithms for List Indexing and Subset Rank (1989) I found a $\Omega{(\frac{log\ n}{log\ log\ n})}$ solution to this problem. – A T May 21 '12 at 07:57
  • By "position" you mean you have reference/pointer to an element in the structure and want to insert next to it? By "$k$-th element" you mean the $k$-largest element, or the one $k$-th inserted? It seems to me that you think of both in terms of arrays, but not all data structures have "positions" in that sense. Please clarify. – Raphael May 21 '12 at 08:32
  • 2
    @Raphael: I think he means the element that would be called $A[k]$ if the data structure were an array. Arrays support the first operation in $O(1)$ time but not the second; linked lists support the second operation in $O(1)$ time but not the first. – JeffE May 21 '12 at 08:51
  • 2
    Also, balanced binary trees support both operations in $O(\log n)$ time. – JeffE May 21 '12 at 08:56
  • @JeffE: Sure, but how does this translate to non-linear data structures, i.e. what is the input? Or, in other words, should the required data structures maintain the other of elements, or is it possible to model a set? The question does not specify the desired structure's interface clearly. – Raphael May 21 '12 at 08:57
  • 1
    @Raphael: Edited to clarify. – JeffE May 21 '12 at 09:13
  • 2
    @JeffE the dynamic array supports the first two in $O(1)$ amortized time (http://www.cs.uwaterloo.ca/research/tr/1999/09/CS-99-09.pdf) – didest May 21 '12 at 21:11
  • 1
    @Diego: Read the abstract more carefully: Their data structure only supports inserts and deletions at the ends of the array, not anywhere in the middle. (Still, a cool result.) – JeffE May 22 '12 at 07:31

2 Answers2

36

NO.

Fredman and Saks proved that any data structure that supports these operations requires at least $\Omega(\log n/\log\log n)$ amortized time per operation. (This is reference [1] in the paper by Dietz that you mention in your first comment.) The lower bound holds in the very powerful cell probe model of computation, which only considers the number of distinct memory addresses accessed by the update and query algorithms.

Without some additional assumptions about the update and query operations, Dietz's data structure is the best possible (at least up to constant factors).

JeffE
  • 8,703
  • 1
  • 36
  • 47
  • 3
    @AT: That bound was never "proved wrong". There are situations where it does not apply, but that is an entirely different statement! – Raphael May 21 '12 at 15:22
  • 5
    @AT: The sorting lower bound was proved in a much weaker model of computation, namely binary decision trees. The bound was "proved wrong" by developing faster algorithms that cannot be described as binary decision trees. In order to prove Fredman and Saks' lower bound wrong, you'll have to design a faster algorithm that doesn't access memory. Best of luck. – JeffE May 21 '12 at 17:51
  • @JeffE and Raphael; please review my other answer and confirm/deny my result when you get the chance. Thanks. – A T Jan 07 '13 at 04:27
7

Looks like the $\Omega(\dfrac{\log n}{\log\log n})$ barrier has been overcome by modifying the analysis from the chronogram technique.

The new [lower] $\Omega(\log n)$ bound has been proved for similar problems in the cell-probe model [1]. From reading that article; it is my understanding that that bound applies to the list representation problem also.


[1] Patrascu, Mihai, and Erik D. Demaine. “Logarithmic Lower Bounds in the Cell-Probe Model.” SIAM J. Comput. 35, no. 4 (April 2006): 932–963. doi:10.1137/S0097539705447256.

Juho
  • 22,554
  • 7
  • 62
  • 115
A T
  • 968
  • 9
  • 21
  • 1
    This lower bound holds for constant-sized words, whereas the earlier $\Omega(\log n/\log\log n)$ lower bound is for logarithmically-sized words. – Yuval Filmus Jan 08 '13 at 01:00
  • Indeed. Also, can you confirm that this bound applies to the list representation problem with constant-sized words? – A T Jan 11 '13 at 06:26
  • 1
    I can confirm that, because of the Dietz bound (http://hdl.handle.net/1802/5694) that you yourself mentioned. This makes the complexity exactly $\Theta(\log n/\log \log n)$, and therefore not $\Omega(\log n)$. – jbapple Mar 16 '15 at 06:05