Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

NAME: Sajjad Ali.

ROLL NO# 18-IT-022.

SUBJECT: Data Structure & Algorithm


ASSIGNED BY: Sir Manzar Basheer.

Department: School of Information technology .

University: Shaheed Benazir Bhutto University Sanghar campus.

Content:

1. Graph.
2. Isomorphic Graph.
3. Graph traversal Algorithm.
3.1:Depth first search (DFS):
3.2: Breadth first search (BFS) algorithm.

4. Shortest path and Cycle detection.

Graph:
A Graph is a non-linear data structure defined as a
pair of sets (V,E). V is a set of arbitrary objects called vertices or
nodes, and E is a set of pairs of vertices, which we call edges or
(more rarely) arcs. In an undirected graph, the edges are unordered
pairs, or just sets of two vertices. I usually write u v instead of {u,v}
to denote the undirected edge between u and v.

Isomorphic Graphs:

Two graphs which contain the same number of graph vertices


connected in the same way are said to be isomorphic. Formally,
two graphs and with graph vertices are said to be isomorphic if
there is a permutation of such that is in the set of graph edges iff is
in the set of graph edges .

Example of isomorphic Graph:


Traversing a graph:

To visit each node or vertex which is a


connected component, tree-based algorithms are used. You can do
this easily by iterating through all the vertices of the graph,
performing the algorithm on each vertex that is still unvisited when
examined.

Two algorithms are generally used for the traversal of a graph:


Depth first search (DFS) and Breadth first search (BFS).
1.Depth first search (DFS):
Depth-first Search (DFS) is an algorithm for
searching a graph or tree data structure. The algorithm starts at the
root (top) node of a tree and goes as far as it can down a given branch
(path), and then backtracks until it finds an unexplored path, and then
explores it. The algorithm does this until the entire graph has been
explored.
Breadth first search (BFS) algorithm:

It starts at the tree root (or some arbitrary node


of a graph, sometimes referred to as a ‘search key’), and
explores all of the neighbor nodes at the present depth prior
to moving on to the nodes at the next depth level.
Detection cycles in a graph:
An acyclic graph is a graph without
cycles (a cycle is a complete circuit). When following the graph from
node to node, you will never visit the same node twice.

Shortest Path In Graph:


The shortest path problem is about finding
a path between 2 vertices in a graph such that the total sum of the
edges weights is minimum.

You might also like