Data structure with O (1) setting and O (log (n)) search complexity?

Is there any data structure that would provide O (1) - that is, a constant - input complexity and search complexity (log (n)) even in the worst case ?

A sorted vector can do an O (log (n)) search, but the insert will take O (n) (given that I don't always insert elements either in front or back). While the list will do O (1), it will not be able to provide O (log (n)) searches.

I wonder if such a data structure can be implemented.

+4
source share
3 answers

Yes, but you have to bend the rules a bit in two ways:

1) , O (1) O (1) (, CritBit , ) , O (log n).

. , (, 32 ) , , ('0') ('1') node. - O (32), O (1).

2) , O (1) , O (1) , (, 32- 64-), .

, O (log n), ​​ . , 16- , , 2 ^ 16 = 65563.

+1

, .

, .

OK, NOT

, , B, Red-black tree AVL, O(log N), , O(log N). , ( ) , .

, NOT

, , O(1), LL O(N), , .

Skiplist, , O(log N) ( , O(1)).

Hashmap , , O(N) .

0

( , , , , ; , ).

, c . (Heck, , n c * n .) , n , . , Omega (n), , , . , . Omega (n).

- . : , . . , , . . , , , - , . - -, ( -, - -). , n/2 2 * c , n/2/3 ^ (2 * c) = Omega (n). , .

0
source

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


All Articles