What is the best data structure (container) for quickly inserting / deleting items by index?

What is the best data structure (container) for quickly inserting / deleting items by index?

+2
source share
3 answers

You can get O (log n) performance using a binary tree with a node structure like this:

struct Node<T>
    T value
    Node left
    int left_count
    Node right
    int right_count
end

left_count left . , , . count. .

, , ; !

+1

, - . - B-, ( , node ).

+1

Try a hash table dynamically resized at fixed intervals.

Assuming a pretty good uniform distribution, you should have basically constant access time [O (1)].

http://www.cs.cornell.edu/courses/cs312/2006fa/lectures/lec14.html

This link seems to give a good explanation.

+1
source

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


All Articles