Wednesday, January 14, 2015

Binary Tree Printer

Data Structures are often hard to visualize and understand.  I decided to do my best to create a visual representation of a binary tree.

I wanted it to be fast and easy to implement.  I ended up creating a system for printing a binary tree currently in Java and C#

My Results

Example Trees:

Balanced

         /---  0  ---\             
      /  1  \     /  2  \          
      3     4     5     6          

UnBalanced

           /---0                   
         /-1-\                     
        /2   3                     
        4                          

                           /------------------------------ 2 ------------------------------\                               
           /-------------- 7 --------------\                                               1                               
   /------26 ------\                       3                                                                               
  90 --\          25 --\                                                                                                   
      36              19 \                                                                                                 
                        17                                                                                                 

Huffman Tree

                           /----------------------------nul(13)----------------------------\                               
           /------------nul(5) ------------\                               /------------nul(8) ------------\               
         67(2)                     /----nul(3) ----\                     45(4)                     /----nul(4) ----\       
                                 34(1)         /nul(2) \                                         23(2)         /nul(2) \   
                                             78(1)   89(1)                                                   12(1)   56(1) 

Binary Heap Tree

       /------ 1 ------\           
   /-- 2 --\       /-- 3 --\       
  17      26      19     / 7 \     
                        25  90    
 GitHub

0 comments:

Post a Comment