You are on page 1of 13

373 Lecture 9

By
Javed Siddique
Graph
• Graph G=(V,E) is a set with collection of verticies
and a collection of edges.
• Graph can be represented by either adjacency lit or
adjacency matrix.
• sparse graphs—those for which |E| is much less
than |V|*|V|.
• An adjacency-matrix representation may be
preferred, however, when the graph is dense—|E|
is close to |V|* |V|.
Graphs
• Weighted Graph VS Unweighted Graph.
• Directed Graph VS Undirected Graph.
• Degree.
• In degree out degree.
• Path
• Cycle.
Breadth-first search
Runtime Analysis
• Total time devoted to queue is O(V).
• Sum of lengths of all adjacency lists is
O(E).
• Total running time is O(V+E).
Depth First Search
• The strategy followed by depth-first search is, as
its name implies, to search “deeper” in the graph
whenever possible.
• In depth-first search, edges are explored out of the
most recently discovered vertex v that still has
unexplored edges leaving it.
• When all of v’s edges have been explored, the
search “backtracks” to explore edges leaving the
vertex from which v was discovered.
DFS
• Depth First Forest.
• Depth First Tree.
Classification of Edges

You might also like