undirected

undirected - Robert Sedgewick and Kevin Wayne Copyright 2006

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Robert Sedgewick and Kevin Wayne Copyright 2006 http://www.Princeton.EDU/~cos226 Undirected Graphs Reference: Chapter 17-18, Algorithms in Java, 3 rd Edition, Robert Sedgewick 2 Undirected Graphs Graph. Set of objects with pairwise connections . Why study graph algorithms? ! Interesting and broadly useful abstraction. ! Challenging branch of computer science and discrete math. ! Hundreds of graph algorithms known. ! Thousands of practical applications. 3 Graph Applications communication Graph telephones, computers Vertices Edges fiber optic cables circuits gates, registers, processors wires mechanical joints rods, beams, springs hydraulic reservoirs, pumping stations pipelines financial stocks, currency transactions transportation street intersections, airports highways, airway routes scheduling tasks precedence constraints software systems functions function calls internet web pages hyperlinks games board positions legal moves social relationship people, actors friendships, movie casts neural networks neurons synapses protein networks proteins protein-protein interactions chemical compounds molecules bonds 4 September 11 Hijackers and Associates Reference: Valdis Krebs http://www.firstmonday.org/issues/issue7_4/krebs 5 Power Transmission Grid of Western US Reference: Duncan Watts 6 Protein Interaction Network Reference: Jeong et al, Nature Review | Genetics 8 Graph Terminology 9 Some Graph Problems Path. Is there a path between s to t? Shortest path. What is the shortest path between s and t? Longest path. What is the longest simple path between s and t? Cycle. Is there a cycle in the graph? Euler tour. Is there a cycle that uses each edge exactly once? Hamilton tour. Is there a cycle that uses each vertex exactly once? Connectivity. Is there a way to connect all of the vertices? MST. What is the best way to connect all of the vertices? Biconnectivity. Is there a vertex whose removal disconnects the graph? Planarity. Can you draw the graph in the plane with no crossing edges? Isomorphism. Do two adjacency matrices represent the same graph? 10 Graph Representation Vertex representation. ! This lecture: use integers between and V-1 . ! Real world: convert between names and integers with symbol table. Other issues. Parallel edges, self-loops. A G E C B F D 6 4 2 1 5 3 symbol table 11 Graph API Graph G = new Graph ( V , E ); System . out . println ( G ); for ( int v = ; v < G . V (); v ++) for ( int w : G . adj ( v )) // edge v-w iterate through all edges (in each direction) create an empty graph with V vertices Graph(int V) public class Graph (graph data type) create a random graph with V vertices, E edges Graph(int V, int E) add an edge v-w insert(int v, int w) void return an iterator over the neighbors of v adj(int v) Iterable<Integer> return number of vertices V() int return a string representation toString() String 12 0-1 0-6 0-2 11-12 9-12 9-11 9-10 4-3 5-3 7-8 5-4 0-5 6-4 Set of Edge Representation Set of edge representation. Set of edge representation....
View Full Document

This document was uploaded on 06/10/2011.

Page1 / 12

undirected - Robert Sedgewick and Kevin Wayne Copyright 2006

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

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