You are on page 1of 3

Binary tree

Binary Tree

• Definition of Binary Trees in which Binary trees are hierarchical data structures composed of nodes which
each node has at most two children: left child and right child.
• Structure of a Binary Tree is structured in a way that nodes are connected hierarchically starting from the
root node as these nodes can have zero, one, or two children.
• Balance in a binary tree requires more effort. In a balanced binary tree, the height of the left and right
subtrees of any node differ by at most one.
• There is also several applications of Binary Trees such as:
• Binary Search Trees (BSTs) for efficient searching, insertion, and deletion with logarithmic time complexity.
• Expression Trees to represent mathematical expressions.
• Huffman Trees for data compression using Huffman coding.

How it works:
1. As it begin with the search at the root of the tree.
2. Than it will compare the target value with the value of the current node. Where the target is equal to the current
node's value, the search is successful, and the node containing the target is found than if the target is less than the
current node's value, move to the left subtree. And if the target is greater than the current node's value, move to the
right subtree.
3. Than it will repeat steps 2 and 3 for the subtree chosen based on the comparison in which at each step, compare the
target value with the value of the current node and decide whether to move left or right.
4. The process will continue until one of the following conditions is met as the target is found (current node's value
equals the target) as well as the current node is null, indicating that the target is not in the tree.

You might also like