Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Binary Tree

Binary Tree is defined as a Tree data structure with at most 2 children. Since each element in a binary tree can have only 2 children, we typically name them the left and right child.

Classes

Node

Binary Tree node contains the following parts:

  • Value
  • Pointer to left child (has to be less than the value)
  • Pointer to right child (has to be greater than the value)
class node:
    # Constructor
    def __init__(self, val):
        self.value = val
        self.left = None
        self.right = None

Tree

A full Binary tree is a special type of binary tree in which every parent node/internal node has either two or no children.

class Binary_Tree:
    # Constructor
    def __init__(self):
        self.root = None

The binary tree class has the following methods:

  • add_node: Add a node to the tree.
  • in_order: .
  • pre_order:
  • post_order:
  • search:
  • minimum:
  • maximum:
  • print_tree:
  • breadth:

For more details of the code you can check the practice8.py file.