What happens when both nodes of a tree have the same weight while constructing a Huffman code? In figure 1.21, e and n2 have same weight. Why do we put n1 on the right and g on the left of the tree.


As mentioned in the comments, the choice is completely arbitrary. Whichever choice you make, the resulting code will be optimal. Any particular algorithm will have a specific kind of behavior. One can speculate why they made this particular choice here — perhaps they had a tie-breaking rule in mind, perhaps they wanted the most aesthetically pleasing tree — but it's not very important.
