Data structure for key set with efficient find-missing function

I am looking for a data structure that supports the following operations for integer keys kfrom 0 to M-1.

  • O (1) or O (log n) insert(k), erase(k), lookup(k).
  • O (1) or O (log n) for a special operation find_missing_key()that returns any key that is not currently present in the structure.
  • O (n) or O (n log n). In particular. should not be O (M).

The obvious implementation will be the "list of free keys" structure, implemented as a heap; but it will occupy the space O (M). Is there some kind of data structure that meets all the requirements?

+4
source share
1

.

node [a, b] [a, a], , [a, m] [m + 1, b], m (a + b)/2.

, , root node [0, M-1] ( [0, M), )

node / , .

, x - O (log n): , [x, x] node .

find_missing_key O (log n): , node, , .

(EDIT: , , i_th - .)

+5

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


All Articles