0% found this document useful (0 votes)
38 views34 pages

Data Structures and Algorithms - Trees

The document discusses tree data structures, including their generic structure, elements like root, child and leaf nodes, and different types of trees like binary trees. It also covers tree traversal algorithms like breadth-first search and depth-first search, and specific traversal methods for binary trees.

Uploaded by

erikalast.acad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views34 pages

Data Structures and Algorithms - Trees

The document discusses tree data structures, including their generic structure, elements like root, child and leaf nodes, and different types of trees like binary trees. It also covers tree traversal algorithms like breadth-first search and depth-first search, and specific traversal methods for binary trees.

Uploaded by

erikalast.acad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

TREE

DATA STRUCTURE
WHAT?
The tree is a nonlinear
hierarchical data
structure and
comprises a collection
of entities known as
nodes.
PRACTICAL APPLICATION
Significant place in the realm of IT education
1] Decision Tree
2] Node Structure in DOM (Document Object Model)
3] File System
4] Chess Engine – Game Playing
THE
ANATOMY OF
TREE
TREE :: The Tree Foundation
GENERIC STRUCTURE
TREE ELEMENTS
Root: Topmost node of a tree
Subtree: Any node of the tree along with its descendant
Parent: The node has an edge-sharing to a child node.
Child: The sub-node of a parent.
Sibling: Nodes with the same parent.
Leaf: The last node which does have any subnode.
Edge: Connecting link between two nodes.
Height: Length of the longest path from root to a leaf node
Depth: Number of edges from the root node to that node
BINARY TREE

A binary tree is a tree data structure in


which each parent node can have at most
two children.
PROPERTIES OF BINARY TREE
 Each node has a maximum of up to two children.
 The value of all the nodes in the left sub-tree is less
than the value of the root.
 The value of all the nodes in the right subtree is
greater than or equal to the value of the root.
 This rule is recursively valid for all the left and right
subtrees of the root
Building a Binary Tree..
Insert: 15
Building a Binary Tree..
Insert: 15 - 10
Building a Binary Tree..
Insert: 15 - 10 - 13
Building a Binary Tree..
Insert: 15 - 10 – 13 - 35
Building a Binary Tree..
Insert: 15 - 10 - 13 - 35 - 67
Building a Binary Tree..
Insert: 15 - 10 - 13 - 35 - 67 - 21
BINARY TREE TRAVERSAL
 Depth-First Search (DFS) Algorithms
 Breadth-First Search (BFS) Algorithms
BFS TREE TRAVERSAL
Level Order - visit nodes level-by-level
and left-to-right fashion at the same
level. 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.
DFS TREE TRAVERSAL
1] Preorder - visit the current node before
visiting any nodes inside the left or right
subtrees. It means that the root node is
traversed first then its left child and
finally the right child.
DFS TREE TRAVERSAL
2] Inorder - visit the current node after
visiting all nodes inside the left subtree
but before visiting any node within the
right subtree. It means that the left child
is traversed first then its root node and
finally the right child.
DFS TREE TRAVERSAL
3] Postorder - visit the current node after
visiting all the nodes of the left and right
subtrees. It means that the left child has
traversed first then the right child and
finally its root node.

You might also like