Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best self-balancing BST for quick insertion of a large number of nodes

I've been able to find details on several self-balancing BSTs through several sources, but I haven't found any good descriptions detailing which one is best to use in different situations (or if it really doesn't matter).

I want a BST that is optimal for storing in excess of ten million nodes. The order of insertion of the nodes is basically random, and I will never need to delete nodes, so insertion time is the only thing that would need to be optimized.

I intend to use it to store previously visited game states in a puzzle game, so that I can quickly check if a previous configuration has already been encountered.

like image 756
Jonesinator Avatar asked Aug 05 '08 15:08

Jonesinator


2 Answers

Red-black is better than AVL for insertion-heavy applications. If you foresee relatively uniform look-up, then Red-black is the way to go. If you foresee a relatively unbalanced look-up where more recently viewed elements are more likely to be viewed again, you want to use splay trees.

like image 157
Louis Brandy Avatar answered Oct 20 '22 12:10

Louis Brandy


Why use a BST at all? From your description a dictionary will work just as well, if not better.

The only reason for using a BST would be if you wanted to list out the contents of the container in key order. It certainly doesn't sound like you want to do that, in which case go for the hash table. O(1) insertion and search, no worries about deletion, what could be better?

like image 23
jmbucknall Avatar answered Oct 20 '22 12:10

jmbucknall