In his last post David Anson wrote about Charting's use of a custom binary tree implementation and outlined some limitations of that algorithm and the particular implementation of it. In this post, he is going to explain how to address those limitations for the next release of Charting and share the general purpose code he's using to do it!
The fundamental problem with our current BinaryTree implementation is that offers no guarantee of balance, and can devolve into linear performance even when dealing with fairly typical data. And this isn't an implementation problem - it's an algorithmic one: if you want balancing behavior, you should really use a data structure that balances. (Duh...) One of the most popular data structures for implementing a balanced binary tree is the red-black tree.