I want you to visualize a tree …

By | October 4, 2013

Ha! No this isn’t a zen exercise in focusing the mind. With my new blog I thought I’d refactor my binary search tree code. This post includes the page for my binary search tree code and the description.

I thought I’d combine my interest in the KineticJS HTML5 Canvas framework with a refactored version of my binary search tree code. I implemented some operations on a binary search tree in JavaScript a while back and thought I should refactor it for the new blog.

Since the last time I looked on Wikipedia for Binary Search Tree information it seems there have been some very decent updates. My refactored code has both iterative and recursive versions of pre-order, in-order, and post-order traversal methods. I used the Wikipedia traversal pseudo code as a model for my methods.

This first link is general information about binary search tress.

Wikipedia: Binary Search Tree

The second link is specifically about traversing trees.

Wikipedia: Tree Traversal

I used the information on Bill Mill’s site for displaying the tree view, specifically Donald Knuth’s algorithm.

BillMill.org: Drawing Trees

I provided a text field to enter an integer value as a node value. Adding successive values will build the tree and update its properties. Clicking the “Add Node” button or just pressing enter will add the new node to the tree. Of course the “Reset” button clears the tree. In any event have a look at the code if you like. There is a good bit of code there and it could stand to be cleaned up which I may get around to but maybe this may be of help to someone.

Update: I recently had a request to make the source code available via GitHub. You can now access the source code via the following link.

BinarySearchTree Source Code Via GitHub

Leave a Reply