Graphs April 20 2009 Graph A graph is

  • Slides: 16
Download presentation
Graphs April 20, 2009

Graphs April 20, 2009

Graph • A “graph” is a collection of “nodes” that are connected to each

Graph • A “graph” is a collection of “nodes” that are connected to each other • Graph Theory: This novel way of solving problems was invented by a Swiss mathematician, Leonhard Euler

Königsberg Bridge Problem • Euler was considering the layout of the bridges in the

Königsberg Bridge Problem • Euler was considering the layout of the bridges in the city Königsberg. The city was unusual in that it was built on an island in the river Pregel • The problem Euler was considering was to determine if it was possible for one to walk over all seven bridges exactly once and end up exactly where one started.

Graph of Bridges of Königsberg a b d c

Graph of Bridges of Königsberg a b d c

Graph Notation • A graph is a set of nodes or vertices V that

Graph Notation • A graph is a set of nodes or vertices V that are joined by a set of edges E. V = {A, B, C} E={e 1, e 2, e 3} Graph G = (V, E) A e 1 C e 2 B e 3

Directed and Undirected Graphs • A graph is called a directed graph if the

Directed and Undirected Graphs • A graph is called a directed graph if the edge from vertex v 1 to vertex v 2 can only be traveled in that specific direction, and not in the reverse direction. • Directed edges are represented as an ordered pair (v 1, v 2)

Directed Graph Vertex Set Edge Set V = {u, r, w} E = {(r,

Directed Graph Vertex Set Edge Set V = {u, r, w} E = {(r, u), (u, r), (w, r), (u, w)}

Complete Graph • A graph in which every vertex is connected by an edge

Complete Graph • A graph in which every vertex is connected by an edge to every other vertex • A complete graph on n vertices has n vertices and n(n − 1) / 2 edges

a d f c b e 1. 2. 3. 4. 5. How many vertices

a d f c b e 1. 2. 3. 4. 5. How many vertices are there? How many edges are there? Is this a directed or undirected graph? Is this a complete graph? What are the set of vertices V and the set of edges E?

Walks, Trails, and Circuits • A walk is any sequence of vertices and edges

Walks, Trails, and Circuits • A walk is any sequence of vertices and edges starting at some vertex v 0 and ending at a vertex vn. • A trail is a walk in which no edge is traversed more than once. • A circuit is a walk that begins and ends at the same vertex. • A graph is connected if there is a walk from any vertex v 1 to any other vertex v 2.

Euler Circuits • Euler trail is a trail that includes every vertex in the

Euler Circuits • Euler trail is a trail that includes every vertex in the graph. • An Euler circuit is an Euler trail that begins and ends at the same vertex. If any vertex in a graph is of odd degree (odd number of edges), the graph does not have an Euler circuit.

Weighted Graphs Philadelphia 82 127 266 Washington DC New York 209 392 220 Boston

Weighted Graphs Philadelphia 82 127 266 Washington DC New York 209 392 220 Boston

Spanning Tree • A spanning tree is a special kind of subgraph of graph

Spanning Tree • A spanning tree is a special kind of subgraph of graph G that includes all the vertices that are in G (not necessarily all the edges) and in which there are no cycles or loops possible.

Minimum Spanning Tree (MST) • A spanning tree that has the least weight of

Minimum Spanning Tree (MST) • A spanning tree that has the least weight of all the spanning trees of G. Prim's Algorithm for the Minimum Spanning Tree 1. Write all the edges in the graph in order from smallest to biggest weight. 2. Working from smallest to biggest, add each edge into the MST only if it does not make a cycle. Stop when all the vertices are in the graph and the graph is connected (there are no isolated vertices).