Is there one type of similar data structure that supports joining in O (logn) time and k-th search in O (logn) time? (N is the size of this set)

Is there one type of similar data structure that supports combining in O (logn) time and the kth element search in O (logn) time? n is the size of this set.

+3
source share
4 answers

If you agree to accept depreciation, you can achieve the desired time limits O (log n) for both meld and search, using the binary search tree to represent each set. Merging two trees of size m and n together requires time O (m log (n / m)), where m <n. If you use amortized analysis and charge the cost of merging with elements of a smaller set, then for all operations each element is not charged more than O (log n). When choosing the kth element of each set, O (log n) time is also executed.

I think you could also use a set of sorted arrays to represent each set, but the depreciation argument is a bit more complicated.

As pointed out in other answers, you can use heaps, but getting O (lg n) for meld and select takes some work.

0

, . , , . , , .

+2

k , meldable heap , , , . , O (1) O (lg n), , O (k lg n).

, , k- , k-1 .

+2

:

http://en.wikipedia.org/wiki/Finger_tree

, - , (, aka "persistent", " ", " " , .)

0

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


All Articles