Reputation: 15
What is the best way to create a method that determines the height of a Binary Search Tree class? For instance: bst.height() would return 1 if it contains only 1 item; return 2 if it contains 3 items and is balanced, or return 3 otherwise; return 3 if it contains 4 items and is balanced, or return 4 otherwise. This may be a somewhat different implementation than usual.
Upvotes: 0
Views: 162
Reputation: 2149
The fastest way would be to update the height while you insert and delete.
Upvotes: 1