i have created a recursive method that returns the size of a binary search tree, i would like to analyze the running time of my implementation but i dont know how.
I know the best case is O(1) if node is null but what about worst case? my researches online offer conflicting information. One source says to imagine the internal stack which makes me believe O(N^2) and another says to break it up into an equation. I feel like the worst case is O(N) as each of the nodes must be accessed in order to return their value but i have no evidence to support my claim. Any insight would be greatly appreciated. My method is below:
private int rSize(Node node){ //traverses through each left then right node and returns the size count
if(node==null){
return 0;
}
else{
return (rSize(node.left) + rSize(node.right) + 1);
}
}