Articles > Binary Tree > This article

Post-order Traversal (Recursive) - Binary Tree

To do a post-order traversal of a binary tree recursively, we just use the definition of post-order traversal: starting at the root, visit the left subtree post-order, then visit the right subtree post-order, then visit root:

void postorder(Node *root) {
  if (root == nullptr) return;
  postorder(root->left);
  postorder(root->right);
  cout << root->value << '\n';
}

Time complexity

The time complexity is O(n) (where n is the number of nodes in the tree) because that's the total work done when we combine the work done by each recursive call. See the video for more detail.

Space complexity

The space complexity is O(h) (where h is the height of the tree) because of the space taken by the call stack. See the video for more detail.

Video with explanation