Am I right in thinking this is O(n)? I’m really bad at recursion. Could someone please confirm, or explain to me?
Counter(a)
if hasLeft(a)
return Counter(left(a) + Counter (right(a))
else
return 1
Basically, if there isn’t a left node in the tree, it returns 0. If there are left notes, it returns 1.
Thanks!
If it’s (binary) tree, because there isn’t any loop in graph, it just check each node at most one time so it’s
O(n).