Tree ASS - 1
Tree ASS - 1
d e
root internal
vertex
descendants of g
ancestor of
d
leaf
parent of f
d
child of
c subtree
sibling of
d
Applications of trees
Decision Trees
Prefix Codes
Game Trees
Binary Search Tree (BST)
A Binary Search Tree (BST) is a special type of binary tree in which the left
child of a node has a value less than the node’s value and the right child
has a value greater than the node’s value.
A Binary Search Tree can be used to store items in its vertices.
Binary Search Tree is a node-based binary tree data structure which has
the following properties:
The left sub tree of a node contains only nodes with keys lesser than the
node’s key.
The right sub tree of a node contains only nodes with keys greater than
the node’s key.
The left and right sub tree each must also be a binary search tree
Binary Search Tree (BST) Example: Insert the elements 6, 3, 4, 2, 10
in that order . The first value to be inserted
is put into the root
Graph Traversal
Graph traversal is the process of visiting and exploring a graph for
processing.
It is also applicable to tree traversal as every graph is a tree, but not vice
versa.
The main focus is on visiting and exploring vertices and their
connections.
Vertex represents a node and edges represent connections between nodes
https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/?ref=lbp
Breadth First Search (BFS)
BFS explores a graph or tree level by level, covering one level
completely before moving to the next.
It follows breadth-wise traversal in a breadth-first manner.
BFS is useful for finding the shortest path, level-order traversal, and web
crawling
It does not involve backtracking and visits neighbors before exploring
deeper levels.
https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/?ref=lbp
Depth First Search (DFS)
DFS explores a graph or tree in depth, exploring all paths of a chosen
direction before backtracking.
It follows depth-wise traversal and involves backtracking to explore
alternative paths.
DFS is useful for finding cycles, minimum spanning trees, and social
network analysis.
It utilizes a stack data structure for efficient traversal and backtracking.
https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/?ref=lbp
BFS Vs DFS
BFS traverses a graph or tree level by level, While DFS explores in depth-first manner.
BFS utilizes a queue data structure for efficient traversal, while DFS uses a stack.
BFS is suitable for finding shortest paths, while DFS is useful for finding cycles.
Both methods have their own applications in various domains.
Web crawlers use BFS for efficient crawling and indexing of web pages.
Social networks use DFS for analyzing network connections and identifying
communities.
Minimum spanning tree algorithms utilize DFS for optimal network design.
https://www.geeksforgeeks.org/breadth-first-search-or-bfs-for-a-graph/?ref=lbp
• BFS explores a graph or tree level by level, covering one level completely before
moving to the next.