Tree: Postorder Traversal

  • + 1 comment

    It already does the if statement you stated but it just does it implicitly on the recursive call. In terms of savings, you aren't really saving anything because the cost of you doing the if statements would be the trade-off for doing those function calls. Which means this really doesn't change the complexity of this algorithm at all which would still be Big-Oh(N).

    The biggest caveat really is if you call root.left or root.right on an None Type root (i.e an empty tree) it would return an AttributeError which the first one would be able to handle.