开发者

Most efficient data structure: Fast sorted insertion, closest value searching

开发者 https://www.devze.com 2023-01-25 11:24 出处:网络
Basically: Fast, sorted insert. Returns position of where an item wou开发者_StackOverflow社区ld be inserted if it\'s not found in the data structure.

Basically:

An array with binary search satisfies my second requirement, but it's still prohibitively slow for insertion. What solution might work best?


Red-black trees and skip lists meet your requirements, among others. For an example in C++, look at std::set, std::map, etc. and their lower_/upper_bound and equal_range methods.


Many flavors of search tree fit your requirements. I'd use a 2-3 tree, or maybe a treap if I was feeling lazy.


A binary search tree.

0

精彩评论

暂无评论...
验证码 换一张
取 消