Code to create the histogram in a tree structure