Search and delete in O (log n) time using arrays

Suppose we are given a set of n numbers initially. We need to build a data structure that supports Search (), Predecessor (), and Deletion () queries.

The search and predecessor must take the worst time O (log processing n). Upon deletion, the amortized time O (log n) must be made. Early resolution is O (n). First we have an O (n) space. But I want that at any stage, if their m-numbers are in the structure, the used space should be O (m)

This problem can be solved trivially with RBT, but I need a data structure that uses only arrays. I do not want the RBT implementation to use arrays, the data structure should not use algorithms created from trees. Can anyone think of one such data structure?

+4
source share
1 answer

I can offer some tree structure that is simpler than RBT. To simplify its description, let the number of elements in it be 2^k.

. a 2^(k-1) , . a 2^(k-2) , . , 2^(k+1), . , O(N) time. O(N), n, n/2, n/4... .., n + n/2 + n/4 + ... = 2n = O(n). . 1,2,4,6,8,9,12,14:

 1  2  4  7  8  9 12  14 

   2    7     9     14 

      7          14

            14

, . , NULL NULL node. k- ( ) O (log (N)). . 12.

 1  2  4  7  8  9 NULL(12)  14 

   2    7     9     14 

      7          14

            14

7.

 1  2  4  NUll(7)  8  9 NULL(12)  14 

   2    4            9     14 

      4                 14

            14

O (log (N)). . NULL, . NULL , :

  • Node NULL,
  • Node NULL. (- ), .
  • Node , .
0

Source: https://habr.com/ru/post/1615388/


All Articles