When and How to Prune Trees