Graphs G = (V, E) V are the vertices; E are the edges.

Slides:



Advertisements
Similar presentations
What is a graph ? G=(V,E) V = a set of vertices E = a set of edges edge = unordered pair of vertices
Advertisements

Analysis of Algorithms CS 477/677
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Graphs CSE 331 Section 2 James Daly. Reminders Homework 4 is out Due Thursday in class Project 3 is out Covers graphs (discussed today and Thursday) Due.
Simple Graph Warmup. Cycles in Simple Graphs A cycle in a simple graph is a sequence of vertices v 0, …, v n for some n>0, where v 0, ….v n-1 are distinct,
Graph-02.
CMSC 341 Graphs 3. Adjacency Table Implementation Uses table of size |V|  |V| where each entry (i,j) is boolean –TRUE if there is an edge from vertex.
1 Graph Theory © Dave Bockus. 2 Adjacency Matrix
CS 311 Graph Algorithms. Definitions A Graph G = (V, E) where V is a set of vertices and E is a set of edges, An edge is a pair (u,v) where u,v  V. If.
CSE 326: Data Structures Lecture #19 Graphs I Alon Halevy Spring Quarter 2001.
CSE 326: Data Structures Graphs Ben Lerner Summer 2007.
1 Graph Introduction Definitions. 2 Definitions I zDirected Graph (or Di-Graph) is an ordered pair G=(V,E) such that yV is a finite, non-empty set (of.
CSE 326: Data Structures Graphs Ben Lerner Summer 2007.
CS2420: Lecture 36 Vladimir Kulyukin Computer Science Department Utah State University.
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Chapter 9 Graph Algorithms Real-life graph problems Algorithms for some graph problems Choice of data structures for graph problems.
Graph Algorithms Terminology Topological sort Shortest-path algorithms
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
 What is a graph? What is a graph?  Directed vs. undirected graphs Directed vs. undirected graphs  Trees vs graphs Trees vs graphs  Terminology: Degree.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
Graphs 황승원 Fall 2010 CSE, POSTECH. 2 2 Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
Graphs Upon completion you will be able to:
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Graphs and Shortest Paths Using ADTs and generic programming.
CMSC 341 Graphs. 5/5/20062 Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a finite set of edges, E. Each edge.
1 GRAPHS – Definitions A graph G = (V, E) consists of –a set of vertices, V, and –a set of edges, E, where each edge is a pair (v,w) s.t. v,w  V Vertices.
1 CSE 332: Graphs Richard Anderson Spring Announcements This week and next week – Graph Algorithms Reading, Monday and Wednesday, Weiss
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Graph Algorithms CS 202 – Fundamental Structures of Computer Science.
CMSC 341 Graphs. 2 Basic Graph Definitions A graph G = (V,E) consists of a finite set of vertices, V, and a set of edges, E. Each edge is a pair (v,w)
CS202 - Fundamental Structures of Computer Science II
CS212: Data Structures and Algorithms
CSE 373 Topological Sort Graph Traversals
Special Graphs By: Sandeep Tuli Astt. Prof. CSE.
CMSC 341 Graphs.
CS202 - Fundamental Structures of Computer Science II
Discrete Structures – CNS2300
Introduction to Graphs
Graphs.
CS202 - Fundamental Structures of Computer Science II
CS120 Graphs.
CMSC 341 Lecture 21 Graphs (Introduction)
CHP-7 GRAPH.
Graphs Graph transversals.
CMSC 341 Graphs.
Graphs Chapter 13.
Paul Beame in lieu of Richard Anderson
Graphs CSE 2011 Winter November 2018.
Relations (sections 7.1 – 7.5)
CS223 Advanced Data Structures and Algorithms
CMSC 341 Graphs 3.
CMSC 341 Graphs 3.
Chapter 11 Graphs.
CMSC 341 Lecture 20.
Graphs – Adjacency Matrix
Graphs.
Graphs G = (V, E) V are the vertices; E are the edges.
CE 221 Data Structures and Algorithms
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Chapter 16 1 – Graphs Graph Categories Strong Components
CSC 380: Design and Analysis of Algorithms
GRAPHS Lecture 17 CS2110 Spring 2018.
CE 221 Data Structures and Algorithms
Paths and Connectivity
Paths and Connectivity
GRAPH – Definitions A graph G = (V, E) consists of
Richard Anderson Autumn 2015 Lecture 6
CMSC 341 Graphs.
Introduction to Graphs
Presentation transcript:

Graphs G = (V, E) V are the vertices; E are the edges. Edges are of the form (v, w), where v, w V. ordered pair: directed graph or digraph unordered pair: undirected graph v9 v8 v10 v6 v7 v1 v3 v4 v2 v5 Nov 16, 2001 CSE 373, Autumn 2001

Terminology A weight or cost can be associated with each edge. w is adjacent to v iff (v, w)  E. path: sequence of vertices w1, w2, w3, … , wN such that (wi, wi+1)  E for 1  i < N. length of a path: number of edges in the path. simple path: all vertices are distinct. Nov 16, 2001 CSE 373, Autumn 2001

More terminology cycle: directed graph: path of length  1 such that w1 = wN. undirected graph: same, except all edges are distinct. connected: there is a path from every vertex to every other vertex. loop: (v, v)  E. Nov 16, 2001 CSE 373, Autumn 2001

Digraph terminology directed acyclic graph: no cycles. “DAG” strongly connected: there is a path from every vertex to every other vertex. weakly connected: the underlying undirected graph is connected. D F A C E G B Nov 16, 2001 CSE 373, Autumn 2001

Representation adjacency matrix:  (|V|2) space. adjacency list (sparse graphs): 1 2 3 4 2 3 4 3 1 2 1 2 3 4 Nov 16, 2001 CSE 373, Autumn 2001

Topological Sort Given a directed acyclic graph, construct an ordering of the vertices such that if there is a path from vi to vj, then vj appears after vi in the ordering. indegree of v: # of edges (u, v). v6 v1 v2 v3 v7 v8 v4 v5 Nov 16, 2001 CSE 373, Autumn 2001

void Graph::topsort() { Vertex v, w; for (int counter=0; counter < NUM_VERTICES; counter++) v = findNewVertexOfDegreeZero(); if (v == NOT_A_VERTEX) throw CycleFound(); v.topologicalNum = counter; for each w adjacent to v w.indegree--; } Observation: The only new (eligible) vertices with indegree 0 are the ones adjacent to the vertex just processed. Nov 16, 2001 CSE 373, Autumn 2001

Idea: Use a set data structure to keep track of eligible vertices (Queue or Stack). void Graph::topsort() { Queue q(NUM_VERTICES); int counter = 0; Vertex v, w; q.makeEmpty(); for each vertex v if (v.indegree == 0) q.enqueue(v); while (!q.isEmpty()) v = q.dequeue(); v.topologicalNum = ++counter; for each w adjacent to v if (--w.indegree == 0) q.enqueue(w); } if (counter != NUM_VERTICES) throw CycleFound(); intialize the queue get a vertex with indegree 0 insert new eligible vertices Nov 16, 2001 CSE 373, Autumn 2001