Binary Tree
Structure of definition.
Here we are creating Binary Tree Node which is generic over Comparable
Parent: It’s a node which will check whether it’s a root or not.
LeftNode: It’s node which is aligned to left side of it’s parent Node.
RightNode: It’s node which is aligned to right side of it’s parent Node.
Write: Adding new node based on input element. If it is greater than current payload it will be appended on left else right of current Node.
READ: Traversal can be done in two ways.
1. Depth First Traversal:
a. Inorder: Left Node — — (Value )— —RightNode
b. PreOrder: (Value ) — — Left Node — — RightNode
c. PostOrder: Left Node — — RightNode — — (Value )
2. Breadth First Traversal
a. Level Order
SEARCH: Searching an element in B-Tree.
DELETE:
We will talk about delete operation later, Since deletion required some sort of rearrangement of B-Tree. (Hopefully in next post)
Some Common problems.
Finding minimum Value in B-Tree:
Minimum value is the value which will be in leftmost node in B-Tree.
Finding maximum Value in B-Tree:
Maximum value is the value which will be in rightmost node in B-Tree.
Finding minimum node in B-Tree:
Minimum node is the node which will be in leftmost node in B-Tree.
Finding maximum node in B-Tree:
Maximum node is the node which will be in rightmost node in B-Tree.
Finding Height of B-Tree:
Height of binary tree.
For Source Code:
https://gist.github.com/Roshankumar350/8d9cbc490391b11afa042af3105b9600
Keep reading..
Keep reading..
Reach me out if you have any doubt, suggestion and feedback.
Roshankumar350@gmail.com