CS261 – Data Structures Graphs. Goals Introduction and Motivation Representations.

Slides:



Advertisements
Similar presentations
CS 261 Reachability Problems. The classic Reachability algorithm findReachable (graph g, vertex start) { create a set of reachable vertices, initially.
Advertisements

CS261 Data Structures Single Source Reachability - Edge List Representation.
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 Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
 Graph Graph  Types of Graphs Types of Graphs  Data Structures to Store Graphs Data Structures to Store Graphs  Graph Definitions Graph Definitions.
CS 206 Introduction to Computer Science II 11 / 11 / Veterans Day Instructor: Michael Eckmann.
Graph & BFS.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
CS 261 – Data Structures Graphs. Used in a variety of applications and algorithms Graphs represent relationships or connections Superset of trees (i.e.,
Introduction to Graphs
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.
Introduction to Graph  A graph consists of a set of vertices, and a set of edges that link together the vertices.  A graph can be: Directed: Edges are.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
CSE 780 Algorithms Advanced Algorithms Graph Algorithms Representations BFS.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
Review of Graphs A graph is composed of edges E and vertices V that link the nodes together. A graph G is often denoted G=(V,E) where V is the set of vertices.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
CS 3343: Analysis of Algorithms Lecture 21: Introduction to Graphs.
Computer Science 112 Fundamentals of Programming II Introduction to Graphs.
1 abstract containers hierarchical (1 to many) graph (many to many) first ith last sequence/linear (1 to 1) set.
Representing and Using Graphs
Introduction to Graphs. Introduction Graphs are a generalization of trees –Nodes or verticies –Edges or arcs Two kinds of graphs –Directed –Undirected.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
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.
Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.
10 Copyright © William C. Cheng Data Structures - CSCI 102 Graph Terminology A graph consists of a set of Vertices and a set of Edges C A B D a c b d e.
CS261 Data Structures Dijkstra’s Algorithm – Edge List Representation.
CSE 373: Data Structures and Algorithms
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.
Topic 12 Graphs 1. Graphs Definition: Two types:
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 10 Prepared by İnanç TAHRALI.
Shahed University Dr. Shahriar Bijani May  A path is a sequence of vertices P = (v 0, v 1, …, v k ) such that, for 1 ≤ i ≤ k, edge (v i – 1, v.
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Graphs and Shortest Paths Using ADTs and generic programming.
Programming Abstractions Cynthia Lee CS106B. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
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.
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.
CS 201: Design and Analysis of Algorithms
Elementary Graph Algorithms
Graphs Representation, BFS, DFS
CS 3343: Analysis of Algorithms
CS202 - Fundamental Structures of Computer Science II
CS120 Graphs.
CSE373: Data Structures & Algorithms Lecture 16: Introduction to Graphs Linda Shapiro Spring 2016.
Refresh and Get Ready for More
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Graphs Representation, BFS, DFS
Graphs Chapter 15 explain graph-based algorithms Graph definitions
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Graphs Chapter 11 Objectives Upon completion you will be able to:
CS223 Advanced Data Structures and Algorithms
Chapter 9: Graphs Basic Concepts
Graph Theory By Amy C. and John M..
Graphs.
CSE 373 Data Structures and Algorithms
Graphs G = (V, E) V are the vertices; E are the edges.
GRAPHS G=<V,E> Adjacent vertices Undirected graph
abstract containers sequence/linear (1 to 1) hierarchical (1 to many)
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Graphs: Definitions How would you represent the following?
Chapter 9: Graphs Basic Concepts
Heaps Chapter 6 Section 6.9.
Introduction to Graphs
For Friday Read chapter 9, sections 2-3 No homework
Presentation transcript:

CS261 – Data Structures Graphs

Goals Introduction and Motivation Representations

Why do we care about graphs?

Many Applications Social Networks – Facebook Video Games - Motion Graphs Machine Learning/AI Delivery Networks/Scheduling – UPS? Computer Vision – Image Segmentation …

Graphs Graphs represent relationships or connections Superset of trees (i.e., a tree is a restricted form of a graph) : – A graph represents general relationships: Each node may have many predecessors There may be multiple paths (or no path) from one node to another Can have cycles or loops Examples: airline flight connections, friends, algorithmic flow, etc. – A tree has more restrictive relationships and topology: Each node has a single predecessor—its parent There is a single, unique path from the root to any node No cycles Example: less than or greater than in a binary search tree

Graphs: Vertices and Edges A graph is composed of vertices and edges Vertices (also called nodes) : – Represent objects, states (i.e., conditions or configurations), positions, or simply just place holders – Set {v 1, v 2, …, v n } : each vertex is unique  no two vertices represent the same object/state Edges (also called arcs) : – An edge (v i, v j ) between two vertices indicates that they are directly related, connected, etc. – Can be either directed or undirected – Can be either weighted (or labeled) or unweighted – If there is an edge from v i to v j, then v j is a neighbor of v i (if the edge is undirected then v i and v j are neighbors or each other)

Graphs: Directed and Undirected – Example: friends – Steve and Alicia are friends – Example: admires – George admires Mary SteveAlicia GeorgeMary

Graphs: Directed and Undirected (cont.) vivi vjvj vivi vjvj vivi vjvj vivi vjvj

Graphs: Types of Edges UndirectedDirected Unweighted Weighted v1v1 v2v2 v4v4 v3v3 v1v1 v2v2 v4v4 v3v3 v1v1 v2v2 v4v4 v3v3 w 1,2 w 2,3 w 1,3 w 3,4 w 4,1 v1v1 v2v2 v4v4 v3v3 w 1-2 w 2-3 w 1-3 w 3-4 w 1-4

Graphs: What kinds of questions can we ask? Is A reachable from B? What nodes are reachable from A? What’s the shortest path from A to B? Is A in the graph? How many arcs between A & B etc…

Graphs: Example Pendleton Pierre Pensacola Princeton Pittsburgh Peoria Pueblo Phoenix

Graphs: Representations (unweighted) City : Pendleton? : Pensacola0? : Peoria00? : Phoenix001?0101 4: Pierre1000?000 5: Pittsburgh01000?00 6: Princeton000001?0 7: Pueblo ? Pendleton:{Pueblo, Phoenix} Pensacola:{Phoenix} Peoria:{Pueblo, Pittsburgh} Phoenix:{Pueblo, Peoria, Pittsburgh} Pierre:{Pendleton} Pittsburgh:{Pensacola} Princeton:{Pittsburgh} Pueblo:{Pierre} Adjacency Matrix O(v 2 ) space Edge List O(v+e) space By convention, a vertex is usually connected to itself (though, this is not always the case) Stores only the edges  more space efficient for sparse graph: O(V + E) where sparse means relatively few edges Pendleton Pensacold Peoria Phoenix Pierre Pittsburgh Princeton Pueblo

Graphs: Representations (weighted) City : Pendleton? : Pensacola0? : Peoria00? : Phoenix0043? : Pierre7000?000 5: Pittsburgh010000?00 6: Princeton000005?0 7: Pueblo ? Pendleton:{(Pueblo,22), (Phoenix,13} Pensacola:{(Phoenix,1)} Peoria:{(Pueblo,13), (Pittsburgh,8)} Phoenix:{(Pueblo,90), (Peoria,43), (Pittsburgh,16)} Pierre:{(Pendleton,7)} Pittsburgh:{(Pensacola,10)} Princeton:{(Pittsburgh,5)} Pueblo:{(Pierre,22)} Adjacency Matrix O(v 2 ) space Edge List O(v+e) space

O(V+E) Dominated by verticesDominated by edges

Your Turn Complete Worksheet #40 Graph Representations