The document discusses various tree data structures and algorithms. It defines common tree terminology like nodes, roots, leaves. It describes different types of trees like binary trees, binary search trees, and their properties. It explains tree traversal algorithms like preorder, inorder and postorder. It also summarizes minimum spanning tree algorithms like Kruskal's and Prim's, and single source shortest path algorithms like Dijkstra's.
2. TREE
A tree is the data structure that are based on
hierarchical tree structure with set of nodes
It is an acyclic connected graph with one or
more children nodes and at most one root
node
3. TREE TERMINOLOGY
NODE: Each data item in a tree
ROOT: First or top data item in hierarchical
arrangement
DEGREE OF A NODE: Number of subtrees of
a given node
DEGREE OF A TREE: Maximum degree of a
node in a tree
DEPTH OR HEIGHT: Maximum level number
of a node + 1(i.e., level number of farthest leaf
node of a tree + 1)
4. TREE TERMINOLOGY
NON-TERMINAL NODE: Any node except
root node whose degree is not zero
TERMINAL NODE OR LEAF NODES: Nodes
having zero
FOREST: Set of disjoint trees
PATH: Sequence of consecutive edges from
the source node to the destination node
5. BINARY TREE
In this kind of tree, the maximum degree of
any node is at most 2
A binary tree T is defined as a finite set of
elements such that T is empty (called NULL
tree or empty tree) and T contains a
distinguished Node R called the root of T and
the remaining nodes of T form an ordered pair
of disjoint binary trees 𝑇1, and 𝑇2
6. FULL BINARY TREE
A binary tree in which all leaves are t the
same level or at the same depth and in which
every parent has exactly 0 or 2 children
7. COMPLETE BINARY TREE
A binary tree is one which have the following
properties:
i) Which can have 0, 1 or 2 nodes as a child
node
ii) In which first, we need to fill left node, then
right node in a level
iii) In which, we can start putting data item in
next level only when the previous level is
completely filled
8. PREORDER TREE
TRAVERSAL
Process the root R
Traverse the left subtree of R in preorder
Traverse the right subtree of R in preorder
11. BREADTH FIRST TRAVERSAL
(BFT)
The breadth first traversal of a tree visits the
nodes in the order of depth in the tree
BFT first visits all the nodes at depth zero
(i.e., root), then all the nodes at depth one
and so on
At each depth, the nodes are visited from left
to right
12. DEPTH FIRST TRAVERSAL
(DFT)
Depth first traversal is an algorithm for
traversing or searching a tree, tree structure
or graph
One starts at the root and explores as far as
possible along each branch before
backtracking
13. BINARY SEARCH TREE
A binary search tree, also called as an ordered
or sorted binary tree, has following properties:
i) The left subtree of a node contains only
nodes with keys less than the node’s key
ii) The right subtree of a node contains only
nodes with keys greater than the node’s key
iii) Both the left subtrees and right subtrees
must also be binary search trees
14. AVERAGE CASE PERFORMANCE
OF BST OPERATIONS
Internal Path Length (IPL) of a binary tree is
the sum of the depths of its nodes.
Average internal path length T(n) of binary
trees with n nodes is O(n log n)
The average complexity to find or insert
operations is T(n) = O(log n)
15. AVL TREES
An AVL (Adelson-Velskii and Land) is a binary
tree with the following additional balance
properties:
i) For any node in the tree, the height of the
left and right subtrees can differ by atmost
ii) The height of an empty subtree is -1
16. AVL TREES
An AVL is a binary search tree which has the
following properties:
i) The subtrees of every node differ in height
by atmost one
ii) Every subtree is an AVL tree
Balance factor of a node = Height of left
subtree – Height of right subtree
17. GREEDY ALGORITHMS
Greedy algorithms are simple and straight-
forward
They are short sighted in their approach in the
sense they take decisions on the basis of
information at hand without worrying about
the effect of these decisions in the future
They are used to solve optimization problems
18. FEASIBILITY
A feasible set is promising, if it can be
extended to produce not merely as solution,
but an optimal solution to the problem
19. SPANNING TREE
A spanning tree of a graph is any tree that
includes every vertex in the graph
A spanning tree of a graph G is a subgraph of
G that is a tree and contains all vertices of G
The number of spanning trees in the complete
graph 𝐾 𝑛 is 𝑛 𝑛−2
20. MINIMUM SPANNING TREE
A Minimum Spanning Tree (MST) of a
weighted graph G is a spanning tree of G
whose edges sum is minimum weight
There are two algorithms to find the minimum
spanning tree of an undirected weighted
graph
21. KRUSKAL’S ALGORITHM
Kruskal’s algorithm is a Greedy algorithm
In this algorithm, starts with each vertex being
its component. Repeatedly merges two
components into one by choosing the light
edge that connects them, that’s why, this
algorithm is edge based algorithm
22. KRUSKAL’S ALGORITHM
Let G = (V,E) is a connected, undirected,
weighted graph
Scans the set of edges in increasing order by
weight. The edge is selected such that: i)
acyclicity should be maintained, ii) it should
be minimum weight, iii) when tree T contains
n-1 edges, also must terminate
Uses a disjoint set of data structure to
determine whether an edge connects vertices
in different components
23. ANALYSIS OF KRUSKAL’S
ALGORITHM
The total time taken by this algorithm to find the
minimum spanning tree is O(E 𝑙𝑜𝑔2 E) (if edges
are already sorted)
But the time complexity, if edges are not sorted
is O(E 𝑙𝑜𝑔2 V)
24. PRIM’S ALGORITHM
Prim’s algorithm is based on a generic
minimum spanning tree algorithm
The idea of Prim’s algorithm is to find the
shortest path in a given graph
The Prim’s algorithm has the property that the
edges in the set A always form a single
connected tree
25. PRIM’S ALGORITHM
We begin with some vertex V in a given graph G
= (V,E), defining the initial set of vertices A.
Then, in each iteration, we choose a minimum
weight edge (u,v), connecting a vertex v in the
set A to the vertex u outside of set A. Then,
vertex u is brought into A. This tree is repeated,
until a spanning tree is formed
26. DYNAMIC PROGRAMMING
ALGORITHMS
Dynamic programming approach for the
algorithm design solves the problems by
combining the solutions to some problems, as
we do in divide and conquer approach
It is more powerful
It is a stage-wise search method suitable for
optimization problems whose solutions may
be viewed as the result of a sequence of
decisions
27. DIJKSTRA’S ALGORITHM
Dijkstra’s algorithm solves the single source
shortest path problems on a weighted
directed graph
It is Greedy algorithm
Dijkstra’s algorithm starts at the source vertex,
it grows a tree T, that spans all vertices
reachable from S