You are on page 1of 95

Properties of Rooted Trees

• Parent – A vertex other than root is a parent if it has one or


more children.
The parent of c is b
• Children – If A is a vertex with successors B and C, then B and C
are the children of A.
The children of a is b, f and g
• Siblings – Children with the same parent vertex. h, i and j are
siblings
• Level – The length of the unique path from the root to a vertex.
a
• Vertex a is at level 0
• Vertices d and e is at level 3 b g
f
• Height – The maximum level of all the vertices.
• The height of this tree is 3. c h j
i

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

 Binary Search 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.

You might also like