Tuesday, March 06, 2012

Non-Recursive Binary Tree Traversal Java Implementation

Now that I have more time to think about this, I have finally completed my own solution to the problem... another entry to the long (and hopefully not erroneous) list of "solutions" listed in Google. My inspiration to write my own implementation was when I was Googling for a proper solution, some solutions in the net were actually a bit dodgy and erroneous (especially when it is about the tricky non-recursive post order traversal of a binary tree).

Problem: Given a binary tree, formulate an algorithm to traverse the nodes of the binary tree without using recursion for the following modes:
  • pre-order traversal
  • in-order traversal
  • post-order traversal

Now, before we go any further, you may ask me why is this of paramount importance to find a proper non-recursive solution to this academic problem. And my response is... well it just makes me sleep well tonight blogging about this. ;) (Also hoping that Google would take notice and ahem... check out my CV).

So here goes:





Adding Code Snippets to Blog

Since I have all the time now to play with my blog, I've been experimenting on how to add code snippets into my posts (since I'm a programmer... just comes naturally that I should be posting codes eventually).

However, to my surprise, this feature does not come out of the box for most blogging service. However, it is available as a mash-up.

Good old Google pointed me to this blog:
http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html

The blog details how to integrate SyntaxHighlighter on your blogger template (or any blogging service theoretically).
http://alexgorbatchev.com/SyntaxHighlighter/about.html





public interface Abc {
void method1();
void method2();
}