Data structures

There is a large stream of numbers coming in the form 5 6 7 2 3 1 2 3 .. What data structure is suitable for this problem, given the restrictions that must be inserted in descending order, and duplicates must be eliminated,

I'm not looking for any code, just ideas? I was thinking of BST self-balancing, where we could add the condition that all nodes <current node on the left and all nodes> current node on the right, this will take care of duplicates .. but I do not think that they are necessarily inserted in descending order. Any ideas what could be a better choice. Of course, this should be effective time and space.

+3
source share
3 answers

. O (log N) time, N - , , O (N log N) . - , .

, , , , .

5 6 7 2 3 1 2 3 :

    A>  5           B>  5           C>  6
                       /               / \
                      6               7   5

    D>  6           E>  6           F>  5
       / \             / \             / \
      7   5           7   3           6   2
           \             / \         /   / \
            2           5   2       7   3   1

2 3 , . (, , ), 7, 6, 5, 3, 2, 1 .


, , . , - 0 9.

10- false. true.

, ( false, t ):

      <booleans>
      0123456789
i  5|      t
n  6|      tt
p  7|      ttt
u  2|   t  ttt
t  3|   tt ttt
|  1|  ttt ttt
|  2|  ttt ttt
V  3|  ttt ttt

7, 6, 5, 3, 2, 1.

, , . O(n), ( , ).

, 0 - . , 100 109, 10- i, i + 100.

, , .

+7

.

( ) ( ).

, , .

+1

, , , ? , , .

0

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


All Articles