Lecture 10 Graph Algorithms

Slides:



Advertisements
Similar presentations
Cpt S 223 – Advanced Data Structures Graph Algorithms: Introduction
Advertisements

Graph A graph, G = (V, E), is a data structure where: V is a set of vertices (aka nodes) E is a set of edges We use graphs to represent relationships among.
Graphs. Data structures that connect a set of objects to form a kind of a network Objects are called “Nodes” or “Vertices” Connections are called “Edges”
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
CSE 589 Applied Algorithms Spring 1999 Course Introduction Depth First Search.
Graph.
Graph & BFS.
Lecture 14: Graph Algorithms Shang-Hua Teng. Undirected Graphs A graph G = (V, E) –V: vertices –E : edges, unordered pairs of vertices from V  V –(u,v)
Graph & BFS Lecture 22 COMP171 Fall Graph & BFS / Slide 2 Graphs * Extremely useful tool in modeling problems * Consist of: n Vertices n Edges D.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
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.
CISC 235: Topic 9 Introduction to Graphs. CISC 235 Topic 92 Outline Graph Definition Terminology Representations Traversals.
Data Structures and Algorithms in Parallel Computing Lecture 3.
Graphs A graphs is an abstract representation of a set of objects, called vertices or nodes, where some pairs of the objects are connected by links, called.
Graphs Slide credits:  K. Wayne, Princeton U.  C. E. Leiserson and E. Demaine, MIT  K. Birman, Cornell U.
Graphs Upon completion you will be able to:
Graph. Graph Usage I want to visit all the known famous places starting from Seoul ending in Seoul Knowledge: distances, costs Find the optimal(distance.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
CHAPTER 13 GRAPH ALGORITHMS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Graphs David Kauchak cs302 Spring Admin HW 12 and 13 (and likely 14) You can submit revised solutions to any problem you missed Also submit your.
Graphs ORD SFO LAX DFW Graphs 1 Graphs Graphs
CSC 172 DATA STRUCTURES.
Data Structures & Algorithm Analysis lec(8):Graph T. Souad alonazi
Breadth-First Search (BFS)
Graphs Chapter 20.
Graphs Lecture 19 CS2110 – Spring 2013.
Graphs Representation, BFS, DFS
CSE 373 Topological Sort Graph Traversals
Graphs -An abstract way of representing connectivity using nodes (also called vertices) and edges vertices edges directed undirected - weighted.
Chapter 3. Decompositions of Graphs
Lecture 11 Graph Algorithms
CSC317 Graph algorithms Why bother?
CSE 2331/5331 Topic 9: Basic Graph Alg.
Graph Search Lecture 17 CS 2110 Fall 2017.
Lecture 12 Graph Algorithms
Introduction to Graphs
Ellen Walker CPSC 201 Data Structures Hiram College
Unit 3 Graphs.
CC 215 Data Structures Graph Searching
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
CS120 Graphs.
Graph.
Graph Algorithm.
Lecture 15 CSE 331 Oct 5, 2012.
Elementary Graph Algorithms
Graphs A graph G = (V, E) V = set of vertices, E = set of edges
Graph & BFS.
Graphs Representation, BFS, DFS
Modeling and Simulation NETW 707
Graphs Chapter 15 explain graph-based algorithms Graph definitions
Graphs Chapter 11 Objectives Upon completion you will be able to:
Chapter 22: Elementary Graph Algorithms I
Graph Operations And Representation
Chapter 11 Graphs.
Yan Shi CS/SE 2630 Lecture Notes
Lecture 13 CSE 331 Sep 27, 2017.
CSE 373 Data Structures Lecture 16
Depth-First Search D B A C E Depth-First Search Depth-First Search
Lecture 14 CSE 331 Oct 3, 2012.
Graphs G = (V, E) V are the vertices; E are the edges.
Graph Traversal Lecture 18 CS 2110 — Spring 2019.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
CSE 417: Algorithms and Computational Complexity
GRAPHS Lecture 17 CS2110 Spring 2018.
3.2 Graph Traversal.
Lecture 11 Graph Algorithms
Lecture 13 CSE 331 Sep 28, 2016.
Presentation transcript:

Lecture 10 Graph Algorithms

Graphs Vertices connected by edges. Powerful abstraction for relations between pairs of objects. Representation: Vertices: {1, 2, …, n} Edges: {(1, 2), (2, 3), …} Directed vs. Undirected graphs. We will always assume n is the number of vertex, and m is the number of edges.

Graphs in real life and their problems Traffic Networks Vertices = ? Edges = ? Directed? Typical Problems: shortest path Transportation (flows)

Graphs in real life and their problems Electricity Networks Vertices = ? Edges = ? Directed? Typical Problems: Minimum spanning tree Robustness

Graphs in real life and their problems Social Networks Vertices = ? Edges = ? Directed? Typical Problems: Detecting communities Opinion dynamics

Graphs in real life and their problems The Internet Graph Vertices = ? Edges = ? Directed? Typical Problems: Page Rank Routing

Focus Understand the classical graph algorithms Design idea Correctness Data structure and run time. Know how to apply these algorithms Identify the graph in the problem Abstract the problem and relate to the classical ones Tweak the algorithms Apply the algorithms on a different/augmented graph.

Representing Graphs – Adjacency Matrix 𝐴 𝑖,𝑗 ={ 1, 𝑖𝑓 𝑡ℎ𝑒𝑟𝑒 𝑖𝑠 𝑎𝑛 𝑒𝑑𝑔𝑒(𝑖,𝑗) 0,𝑖𝑓 𝑡ℎ𝑒𝑟𝑒 𝑖𝑠 𝑛𝑜 𝑒𝑑𝑔𝑒 (𝑖,𝑗) 0 1 1 0 1 1 0 1 1 0 1 1 0 1 1 0 Space: O(n2) Time: Check if (i,j) is an edge O(1) Enumerate all edges of a vertex O(n) Better for dense graphs. 1 2 3 4

Representing Graphs – Adjacency List Use a linked list for each vertex Linked List store its neighbors 1: [2, 3, 4] 2: [1, 4] 3: [1, 4] 4: [1, 2, 3] Space: O(m) Time: Check if (i,j) is an edge O(n) Enumerate all edges of a vertex O(degree) (degree of a vertex = # edges connected to the vertex) Better for sparse graphs. 1 2 3 4

Representing Graphs Getting faster query time? If you don’t care about space, can store both an adjacency array and an adjacency list. Saving space? Can use a hash table to store the edges (for adjacency array).

Basic Graph Algorithm: Graph Traversal Problem: Given a graph, we want to use its edges to visit all of its vertices. Motivation: Check if the graph is connected. (connected = can go between every pair of vertices) Find a path between two vertices Check other properties (see examples)

Depth First Search Visit neighbor’s neighbor first. DFS_visit(u) Mark u as visited FOR each edge (u, v) IF v is not visited DFS_visit(v) DFS FOR u = 1 to n

Depth First Search Tree IF DFS_visit(u) calls DFS_visit(v), add (u,v) to the tree. “Only preserve an edge if it is used to discover a new vertex” 1 1 2 3 2 3 4 4 5 5

DFS and Stack Recursions are implemented using stacks 1 DFS(5) DFS(4) 2 3 4 5

Pre-Order and Post-Order Pre-Order: The order in which the vertices are visited (entered the stack) Post-Order: The order in which the vertices are last touched (leaving the stack) Pre-Order: (1, 2, 5, 4, 3) Post-Order: (5, 4, 2, 3, 1) 1 DFS(5) DFS(4) DFS(2) DFS(3) DFS(1) 2 3 4 5