Tree Lecture 1
Tree Lecture 1
Tree
A tree is a non linear data structure that
simulates a hierarchical tree structure with
a root value and sub trees of children with
parent node, represented as set of linked
nodes.
Real life Example
Tree Terms
• Root – Root is a special node in a tree. The entire tree is
referenced through it. It does not have a parent.
• Parent Node – Parent node is an immediate predecessor of a
node.
• Child Node – All immediate successors of a node are its children.
• Siblings – Nodes with the same parent are called Siblings.
• Leaf – Last node in the tree. There is no node after this node.
• Edge – Edge is a connection between one node to another. It is a
line between two nodes or a node and a leaf.
• Path – Path is a number of successive edges from source node to
destination node.
Tree Term and Properties
Tree can be termed as a RECURSIVE data structure.
• In a valid tree for N Nodes we have N-1 Edges/Links
• Depth of Node – Depth of a node represents the
number of edges from the tree’s root node to the
node.
• Height of Node – Height of a node is the number of
edges on the longest path between that node & a
leaf.
• Height of Tree – Height of tree represents the height
of its root node
Binary Tree
A tree is represented by a pointer to the
topmost node in tree .A Binary Tree node
contains following parts.
• Data
• Pointer to left child
• Pointer to right child
As linkedlist
Implementation View
Binary Tree
Binary Tree
Binary Tree
Tree Implementation as Array
Set Root value/Check if its Empty
Set Left Element Method
Set Right Element Method
Print tree method
Calls in Main method
Must read
https://www.freecodecamp.org/news/all-y
ou-need-to-know-about-tree-data-structure
s-bceacb85490c/