0

I have written some python code that will take an unbalanced binary tree and balance it, however this has proven to take a long time with very large trees so I'm looking for an easier way...

I was just wondering if it is possible to maintain the trees balance WHILE its being built, so I don't have to waste resources balancing trees after they've already been built.

Thanks

clay
  • 65
  • 2
  • 6
  • Are you looking for AVL tree or `B/B+` – Grijesh Chauhan May 11 '13 at 05:31
  • 2
    Search for AVL or Red-Black trees. – Sukrit Kalra May 11 '13 at 05:31
  • Yes, AVL/red-black trees are what you're looking for. Unfortunately, there seems to be [no balanced binary tree in the Python standard library](http://stackoverflow.com/questions/2298165/pythons-standard-library-is-there-a-module-for-balanced-binary-tree), so you either need to find a third-party module or code your own. – Anubhav C May 11 '13 at 05:36
  • Ah yes, AVL trees are exactly what I was looking for, thanks. – clay May 11 '13 at 05:42
  • try [bintrees](https://pypi.python.org/pypi/bintrees), it's a good implementation of various tree algorithms. – mata May 11 '13 at 06:47

0 Answers0