<p>I've been able to find details on several self-balancing <code>BST</code>s 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).  </p>

<p>I want a <code>BST</code> 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.  </p>

<p>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.</p>

[{'answer_id': 2498, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>The two self-balancing <code>BST</code>s I'm most familiar with are red-black and <code>AVL</code>, so I can't say for certain if any other solutions are better, but as I recall, red-black has faster insertion and slower retrieval compared to <code>AVL</code>. </p>\n\n<p>So if insertion is a higher priority than retrieval, red-black may be a better solution.</p>\n"}, {'answer_id': 2511, 'author': 'Louis Brandy', 'author_id': 2089740, 'author_profile': 'https://Stackoverflow.com/users/2089740', 'pm_score': 3, 'selected': True, 'text': '<p><a href="http://en.wikipedia.org/wiki/Red-black_tree" rel="nofollow noreferrer">Red-black</a> 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 <a href="http://en.wikipedia.org/wiki/Splay_tree" rel="nofollow noreferrer">splay trees</a>.</p>\n'}, {'answer_id': 33692, 'author': 'jmbucknall', 'author_id': 806, 'author_profile': 'https://Stackoverflow.com/users/806', 'pm_score': 2, 'selected': False, 'text': "<p>Why use a <code>BST</code> at all? From your description a dictionary will work just as well, if not better. </p>\n\n<p>The only reason for using a <code>BST</code> 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. <code>O(1)</code> insertion and search, no worries about deletion, what could be better?</p>\n"}, {'answer_id': 500734, 'author': 'Jonas Kölker', 'author_id': 58668, 'author_profile': 'https://Stackoverflow.com/users/58668', 'pm_score': -1, 'selected': False, 'text': "<blockquote>\n  <p>[hash tables have] O(1) insertion and search</p>\n</blockquote>\n\n<p>I think this is wrong.</p>\n\n<p>First of all, if you limit the keyspace to be finite, you could store the elements in an array and do an O(1) linear scan.  Or you could shufflesort the array and then do a linear scan in O(1) expected time.  When stuff is finite, stuff is easily O(1).</p>\n\n<p>So let's say your hash table will store any arbitrary bit string; it doesn't much matter, as long as there's an infinite set of keys, each of which are finite.  Then you have to read all the bits of any query and insertion input, else I insert y0 in an empty hash and query on y1, where y0 and y1 differ at a single bit position which you don't look at.</p>\n\n<p>But let's say the key lengths are not a parameter.  If your insertion and search take O(1), in particular hashing takes O(1) time, which means that you only look at a finite amount of output from the hash function (from which there's likely to <em>be</em> only a finite output, granted).</p>\n\n<p>This means that with finitely many buckets, there must be an infinite set of strings which all have the same hash value.  Suppose I insert a lot, i.e. &omega;(1), of those, and start querying.  This means that your hash table has to fall back on some other O(1) insertion/search mechanism to answer my queries.  Which one, and why not just use that directly?</p>\n"}]
['https://Stackoverflow.com/questions/2481', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/152/']