Added buildTree(); it will be useful for encode but since it relies on freq it is not useful for decode