You are on page 1of 2

Assignment

Name. MUHAMMAD MAJID

Reg.No. 2021-Gu774

Class. BS IT 3rd (Evening A)

Submitted To. Mr.Muiz- U - Din Sahib

Topic: directed and undirected graph

Directed graph:
A directed graph that has the edges that are unidirectional. A directed graph is also called a
digraph.

B
C

Undirected graph:
An undirected graph has the edges that have no direction. An undirected graph is also called
an un-digraph.
A

B C

Traversing of graph:
Depth- There are two standard ways to traverse a graph.
 Breadth-first search
 Depth-first search

When one of the above method is used than each of the vertices of graph should be in one
of three states during visiting process. These states are also known as status of vertices.
These status are:

Ready state: it is the initial state of the vertex. Its value is 1.

Waiting state: it is the state of vertex when it is in the queue or stack and is waiting to be
processed. Its value is 2.

Breadth-First Search(BFS):

Breath first search searches the graph one edge away from the starting vertex at a time.

The search starts at some arbitrarily chosen vertex. Then all of the v’s neighbors are visited
and processed. then all of v’s neighbors’ s neighbors are visited and processed. For this all
neighbors of first neighbors are visited, than all the neighbors of the second neighbor are
visited, and so on. This process is continued until all vertex in the graph are visited.

Recursion is not used on BFS , because traversing is done one level at a time. To perform a
BFS queues are used. Every time a vertex v’s neighbors are visited v’s neighbors are
dequeued and enqueued in this way the record is kept of which neighbors belong to which
vertex.

Depth-first search:

In depth first search DFS the search can be started from any vertex in the graph for example
a vertex “v” is selected. It is proceed and marked than all unmarked, vertex adjacent to “V”
are recursively traversed. The vertex V will be different with every new method call.

When a vertex is reached in which all of its neighbors have been visited. The control returns
to its calling vertex and one of its unvisited neighbors is visited the recursion is repeated in
the same manner until of the starting vertex neighbors is visited.

In depth first search the stock is used to hold vertices that are waiting to be proceed.

You might also like