dms notes
dms notes
AAT
Submitted by
2022 – 23
Example 1:
In this example, we have shown whether the following graphs are isomorphism.
Solution: For this, we will check all the four conditions of graph isomorphism, which are
described as follows:
Condition 1:
● In graph 1, there is a total 4 number of vertices, i.e., G1 = 4.
● In graph 2, there is a total 4 number of vertices, i.e., G2 = 4.
Here, There are an equal number of vertices in both graphs G1 and G2. So these graphs satisfy
condition 1. Now we will check the second condition.
Condition 2:
● In graph 1, there is a total 5 number of edges, i.e., G1 = 5.
● In graph 2, there is a total 6 number of edges, i.e., G2 = 6.
Here, There does not have an equal number of edges in both graphs G1 and G2. So these graphs
do not satisfy condition 2. Now we cannot check all the remaining conditions. Since, these
graphs violate condition 2. So these graphs are not an isomorphism. Graph G1 and graph G2
are not isomorphism graphs.
Example 2:
In this example, we have shown whether the following graphs are isomorphism.
Solution: For this, we will check all the four conditions of graph isomorphism, which are
described as follows:
Condition 1:
● In graph 1, there are a total 8 vertices, i.e., G1 = 8.
● In graph 2, there are a total 8 vertices, i.e., G2 = 8.
Here, There are an equal number of vertices in both graphs G1 and G2. So these graphs satisfy
condition 1. Now we will check the second condition.
Condition 2:
● In graph 1, the total number of edges is 10, i.e., G1 = 10.
● In graph 2, the total number of edges is 10, i.e., G2 = 10.
Here, There are an equal number of edges in both graphs G1 and G2. So these graphs satisfy
condition 2. Now we will check the third condition.
Condition 3:
● In graph 1, the degree of sequence s is {2, 2, 2, 2, 3, 3, 3, 3}, i.e., G1 = {2, 2, 2, 2, 3, 3,
3, 3}.
● In graph 2, the degree of sequence s is {2, 2, 2, 2, 3, 3, 3, 3}, i.e., G2 = {2, 2, 2, 2, 3, 3,
3, 3}.
Here, There are an equal number of degree sequences in both graphs G1 and G2. So these
graphs satisfy condition 3. Now we will check the fourth condition.
Condition 4:
● Graph G1 forms a cycle of length 4 with the help of degree 3 vertices.
● Graph G2 is not forming a cycle of length 4 with the help of vertices because vertices
are not adjacent.
Here, Both the graphs G1 and G2 do not form the same cycle with the same length. So these
graphs violate condition 4.
Graphs G1 and G2 violate condition 4. So because of the violation of condition 4, these graphs
will not be an isomorphism.
Graphs G1 and G2 are not an isomorphism.
Example 1:
In the following image, we have a graph with 6 nodes. Now we have to determine whether this
graph contains an Euler path.
Solution:
The above graph will contain the Euler path if each edge of this graph must be visited exactly
once, and the vertex of this can be repeated. So if we begin our path from vertex B and then go
to vertices C, D, F, B, E, D, A, and B, then in this process, each and every edge is visited
exactly once, and it also contains repeated vertices. So the above graph contains an Euler path,
which is described as follows:
Euler path = BCDFBEDAB
Example 2:
In the following image, we have a graph with 4 nodes. Now we have to determine whether this
graph contains an Euler path.
Solution:
The above graph will contain the Euler path if each edge of this graph must be visited exactly
once, and the vertex of this can be repeated. So if we begin our path from vertex B and then go
to vertices C, D, B, A, and D, then in this process, each and every edge is visited exactly once,
and it also contains repeated vertices. So the above graph contains an Euler path, which is
described as follows:
Euler path = BCDBAD
Shortest path
This algorithm maintains a set of vertices whose shortest paths from source are already known.
The graph is represented by its cost adjacency matrix, where cost is the weight of the edge. In
the cost adjacency matrix of the graph, all the diagonal values are zero. If there is no path from
source vertex Vs to any other vertex Vi then it is represented by +∞.In this algorithm, we have
assumed all weights are positive.
2. Include the source vertex Vs in S.Determine all the paths from V s to all other vertices
without going through any other vertex.
3. Now, include that vertex in S which is nearest to V s and find the shortest paths to all the
vertices through this vertex and update the values.
4. Repeat the step until n-1 vertices are not included in S if there are n vertices in the
graph.
After completion of the process, we got the shortest paths to all the vertices from the source
vertex.
Example:
Find the shortest paths between K and L in the graph shown in fig using Dijkstra's Algorithm.
Step1: Include the vertex K is S and determine all the direct paths from K to all other vertices
without going through any other vertex.
Step2: Include the vertex in S which is nearest to K and determine shortest paths to all vertices
through this vertex and update the values. The closest vertex is c.
Since, n-1 vertices are included in S. Hence we have found the shortest distance from K to all
other vertices. Thus, the shortest distance between K and L is 8 and the shortest path is K, c, b,
L.
1. The leftmost side of the leaf node must always be filled first.
2. It isn’t necessary for the last leaf node to have a right sibling.
Example 1:
Full but not complete
● All of the nodes have either 0 or 2 offspring, therefore, it is a Full binary tree.
● It is not a Complete binary tree because node B has no children whereas node C has
children, and according to a complete binary tree, nodes should be filled from the
left side.
Hence, the binary tree shown above is a Full binary tree and it is not a Complete binary tree.
Example 2:
● Node C has just one child therefore, it is not a Full binary tree.
● Node C also has a right child but no left child, therefore it is also not a Complete
binary tree.
Hence, the binary tree shown above is neither complete nor full binary tree.
Weighted Trees
A tree to whose nodes and/or edges labels (usually number) are assigned.
The word "weight" also has a more specific meaning when applied to trees, namely the weight
of a tree at a point a is the maximum number of edges in any branch at a(Harary 1994, p. 35), as
illustrated above. A point having minimal weight for the tree is called a centroid point, and the
tree centroid is the set of all centroid points.
Example 1:
This is the tree that Rick Decker used in his answer. Each node of the tree that isn’t a leaf has
two edges leading down from it; the one to the left is labeled with a red 0 and the one to the
right with a red 1 think of the tree as a road map; a string of red numbers can be used to describe
how to get from the root (85) to one of the leaves. To get from the root to the leaf 13, for
instance, you must go left (0), then right (1), then left (0) again, so the route is 010, and that’s
the code assigned to the weight 13 leaf.
Notice that the most heavily weighted leaves − the two 17’s − are closest to the root and so have
the shortest codes; this is what makes the Huffman encoding efficient.
Example 2:
Input:
Output: 5
Weight of sub-tree for parent 1 = ((-1) + (5) + (-2) + (-1) + (3)) = 4
Weight of sub-tree for parent 2 = ((5) + (-1) + (3)) = 7
Weight of sub-tree for parent 3 = -1
Weight of sub-tree for parent 4 = 3
Weight of sub-tree for parent 5 = -2
Node 5 gives the minimum sub-tree weighted sum.