Postorder Traversal of a Binary Tree Using Recursion

Visualization

Algorithm Steps

  1. Start at the root of the binary tree.
  2. Recursively traverse the left subtree.
  3. Recursively traverse the right subtree.
  4. Visit (process) the current node.

Postorder Traversal Program in Different Programming Languages Code

Python
Java
JavaScript
C
C++
C#
Kotlin
Swift
Go
Php
class Node:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

def postorder(root):
    if root is not None:
        postorder(root.left)
        postorder(root.right)
        print(root.value, end=' ')

# Example usage:
if __name__ == '__main__':
    root = Node(1)
    root.left = Node(2)
    root.right = Node(3)
    root.left.left = Node(4)
    root.left.right = Node(5)
    postorder(root)