Hamster
Hamster

Reputation: 3122

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

Basically:

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

Upvotes: 2

Views: 2042

Answers (3)

Fred Nurk
Fred Nurk

Reputation: 14212

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.

Upvotes: 1

fabmilo
fabmilo

Reputation: 48310

A binary search tree.

Upvotes: 0

xscott
xscott

Reputation: 2420

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

Upvotes: 0

Related Questions