lecture_10_graph_-_3in1_with_notes

lecture_10_graph_-_3in1_with_notes - Graphs Outline What is...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Graphs 2 Outline b What is a graph? b Graph’s applications b Terminology b Graph’s implementation b Breadth first search b Depth first search b Topological sort 3 Readings b Textbook s [Carrano] ch13
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Linked list 1 parent 1 child 5 Tree 1 parent multiple children 6 Directed graph vertex (node) edge 1 parent 1 child multiple parents multiple children A graph consists of a set of vertices and a set of edges between the vertices. In a tree, there is a unique path between any two nodes. In a graph, there may be more than one path between two nodes.
Background image of page 2
7 Example: travel planning shopping mall direct route 5 cost 8 Weighted directed graph 5 3 -2 5 1 0 In a weighted graph, edges have a weight (or cost) associated with it. Not all weights are labeled in this slides for simplicity. 9 Undirected graph edges are bidirectional In an undirected graph, edges are bidirectional.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Complete graph •every pair of vertices has an edge between them •The number of edges : n(n-1)/2 = O(n 2 ) A graph is complete if every pair of vertices has an edge between them. The number of edges in a complete graph is n(n-1)/2, where n is the number of vertices. (Why is it so?). Therefore, the number of edges is O(n 2 ). A complete graph is also called a clique. 11 Path a c d e b A path between two vertices is a sequence of edges that begin at one vertex and end at another. The length of a path p is the number of edges in p. A simple path never visits the same vertex more than once. A path between two vertices is a sequence of edges that begin at one vertex and end at another. The length of a path p is the number of edges in p. A simple path never visits the same vertex more than once. 12 Cycle a c g d e b f A cycle is a path that begins and ends at the same vertex. Simple cycle is a simple path that is a cycle. Note that the definition of path and cycle applies to directed graph as well . A cycle is a path that begins and ends at the same vertex. Simple cycle is a simple path that is a cycle. Note that the definition of path and cycle applies to directed graph as well.
Background image of page 4
Disconnected graph Connected graph : there is a path between every pair of nodes This graph is Disconnected . It has two connected components . In a connected graph, there is a path between every nodes. A graph does not have to be connected. The above graph has two connected components . Applications 15 Travel Planning shopping mall direct route 5 cost What is the shortest way to travel between A and B? “SHORTEST PATH PROBLEM” How to minimize the cost of visiting n cities such that we visit each city exactly once, and finishing at the city where we start from? “TRAVELING SALESMAN
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 26

lecture_10_graph_-_3in1_with_notes - Graphs Outline What is...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online