This is a simple implementation of Binary Search Tree Insertion using Python.

An example is shown below:

http://i.stack.imgur.com/3NG0e.gif

Following the code snippet each image shows the execution visualization which makes it easier to visualize how this code works.

class Node:
    def __init__(self, val):
        self.l_child = None
        self.r_child = None
        self.data = val

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1261e595-0223-4efe-8dbf-43f6fe8a6da1/Untitled.png

def insert(root, node):
    if root is None:
        root = node
    else:
        if root.data > node.data:
            if root.l_child is None:
                root.l_child = node
            else:
                insert(root.l_child, node)
        else:
            if root.r_child is None:
                root.r_child = node
            else:
                insert(root.r_child, node)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0b1236df-1131-44b6-8eef-14ab53584cc3/Untitled.png

def in_order_print(root):
    if not root:
        return
    in_order_print(root.l_child)
    print root.data
    in_order_print(root.r_child)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5b232445-0be7-481c-8cd6-ea9dfad5da9d/Untitled.png

def pre_order_print(root):
    if not root:
        return        
    print root.data
    pre_order_print(root.l_child)
    pre_order_print(root.r_child)

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/3261f1ec-f255-4d80-9938-e45ab7bfb351/Untitled.png