Introduction To Binary Tree
Introduction To Binary Tree
The topmost node in a binary tree is called the root, and the bottom-most nodes
are called leaves. A binary tree can be visualized as a hierarchical structure with
the root at the top and the leaves at the bottom.
Binary trees have many applications in computer science, including data storage
and retrieval, expression evaluation, network routing, and game AI. They can also
be used to implement various algorithms such as searching, sorting, and graph
algorithms.
A binary tree is a tree data structure in which each parent node can have at most
two children. Each node of a binary tree consists of three items:
data item
address of left child
address of right child
Types of Binary Tree
1. Full Binary 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.
Tree Traversal using Depth-First Search (DFS) algorithm can be further classified
into three categories:
Preorder Traversal (current-left-right): Visit the current node before visiting any
nodes inside the left or right subtrees. Here, the traversal is root – left child –
right child. It means that the root node is traversed first then its left child and
finally the right child.
Inorder Traversal (left-current-right): Visit the current node after visiting all nodes
inside the left subtree but before visiting any node within the right subtree. Here,
the traversal is left child – root – right child. It means that the left child is
traversed first then its root node and finally the right child.
Postorder Traversal (left-right-current): Visit the current node after visiting all the
nodes of the left and right subtrees. Here, the traversal is left child – right child –
root. It means that the left child has traversed first then the right child and finally
its root node.
Tree Traversal using Breadth-First Search (BFS) algorithm can be further classified
into one category:
Level Order Traversal: Visit nodes level-by-level and left-to-right fashion at the
same level. Here, the traversal is level-wise. It means that the most left child has
traversed first and then the other children of the same level from left to right
have traversed.
https://tree-visualizer.netlify.app/