15-211 Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation.

Slides:



Advertisements
Similar presentations
Lecture 15. Graph Algorithms
Advertisements

IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Graphs: MSTs and Shortest Paths David Kauchak cs161 Summer 2009.
Graphs III (Trees, MSTs) (Chp 11.5, 11.6)
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
Graph Algorithms: Minimum Spanning Tree We are given a weighted, undirected graph G = (V, E), with weight function w:
Chapter 9 Graph algorithms. Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Chapter 9 Graph algorithms Lec 21 Dec 1, Sample Graph Problems Path problems. Connectedness problems. Spanning tree problems.
Graphs G = (V,E) V is the vertex set. Vertices are also called nodes and points. E is the edge set. Each edge connects two different vertices. Edges are.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Chapter 9: Graphs Basic Concepts
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Minimum Spanning Tree in Graph - Week Problem: Laying Telephone Wire Central office.
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Graphs CS /02/05 Graphs Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved Definition.
Lecture 17: Spanning Trees Minimum Spanning Trees.
Midwestern State University Minimum Spanning Trees Definition of MST Generic MST algorithm Kruskal's algorithm Prim's algorithm 1.
1.1 Data Structure and Algorithm Lecture 13 Minimum Spanning Trees Topics Reference: Introduction to Algorithm by Cormen Chapter 13: Minimum Spanning Trees.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures Graph Algorithms: Minimum.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
1 Quantum query complexity of some graph problems C. DürrUniv. Paris-Sud M. HeiligmanNational Security Agency P. HøyerUniv. of Calgary M. MhallaInstitut.
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
Graph Dr. Bernard Chen Ph.D. University of Central Arkansas.
GRAPHS CSE, POSTECH. Chapter 16 covers the following topics Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component,
Spanning Trees Introduction to Spanning Trees AQR MRS. BANKS Original Source: Prof. Roger Crawfis from Ohio State University.
7.1 and 7.2: Spanning Trees. A network is a graph that is connected –The network must be a sub-graph of the original graph (its edges must come from the.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
CPSC 320: Intermediate Algorithm Design & Analysis Greedy Algorithms and Graphs Steve Wolfman 1.
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
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 & Algorithms Graphs Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
GRAPHS. Graph Graph terminology: vertex, edge, adjacent, incident, degree, cycle, path, connected component, spanning tree Types of graphs: undirected,
CSC2100B Tutorial 10 Graph Jianye Hao.
CSCI2100 Data Structures Tutorial 12
Graphs Upon completion you will be able to:
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
Graph Revisited Fei Chen CSCI2100B Data Structures Tutorial 12 1.
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.
1 Data Structures and Algorithms Graphs. 2 Graphs Basic Definitions Paths and Cycles Connectivity Other Properties Representation Examples of Graph Algorithms:
Minimum Spanning Trees
Shortest Paths and Minimum Spanning Trees
Minimum Spanning Tree Chapter 13.6.
Spanning Trees.
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Spanning Trees.
Minimum Spanning Tree.
Minimum Spanning Trees
Connected Components Minimum Spanning Tree
Minimum Spanning Trees
CSE 373 Data Structures and Algorithms
Spanning Trees.
Chapter 9: Graphs Basic Concepts
Graph Operations And Representation
Minimum spanning trees
Shortest Paths and Minimum Spanning Trees
CSE 373: Data Structures and Algorithms
Graphs.
Kruskal’s Algorithm AQR.
CSE 373: Data Structures and Algorithms
Algorithms CSCI 235, Spring 2019 Lecture 32 Graphs I
Chapter 9: Graphs Basic Concepts
For Friday Read chapter 9, sections 2-3 No homework
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Fundamental Data Structures and Algorithms (Spring ’05) Recitation Notes: Graphs Slides prepared by Uri Dekel, Based on recitation notes by David Murray

Definitions

Recitation notes on graphs, Uri Dekel and David Murray 3 What is a graph? G=(V,E)  V: a set of vertices (or “nodes”)  E: a set of edges (or “links”) Every edge has two endpoints In a directed graph, endpoint order matters  i.e., (v1,v2) != (v2, v1) In a weighted graph, every edge (and possibly node) has a weight.

Recitation notes on graphs, Uri Dekel and David Murray 4 Graph Examples Undirected graphs  Computer networks  Highway systems

Recitation notes on graphs, Uri Dekel and David Murray 5 Graph Examples Directed Graphs  Street maps with one-way and two-way streets  Game boards (e.g,”ladders and chutes”)

Recitation notes on graphs, Uri Dekel and David Murray 6 Graph Examples Weighted graphs  Computer networks e.g., Minimal time for packet routing  Highways with distances e.g., “What is the shortest driving distance from Pittsburgh to New York City?”

Recitation notes on graphs, Uri Dekel and David Murray 7 Graph Terms Loop  An edge whose two endpoints are the same Parallel edges  Two different edges with the same endpoints  A “simple graph” has no parallel edges

Recitation notes on graphs, Uri Dekel and David Murray 8 Graph Terms Path  A consecutive path of vertices and edges which starts at an “origin” vertex and ends at a “terminus” vertex Circuit  A path where the origin and terminus are the same Simple path  A path where no vertices are repeated (except origin in a simple circuit)

Recitation notes on graphs, Uri Dekel and David Murray 9 Graph Terms Connected graph  A graph where there is a path from every vertex to any other vertex

Recitation notes on graphs, Uri Dekel and David Murray 10 Trees Tree  A connected graph with no cycles i.e., any connected graph with no cycles is a tree TreeNot a tree

Programmatic Representation

Recitation notes on graphs, Uri Dekel and David Murray 12 Representing graphs Incidence matrix  Every row corresponds to a vertex  Every column corresponds to an edge  Entry is 1 if edge exists, 2 if loop  Use negatives to indicate direction

Recitation notes on graphs, Uri Dekel and David Murray 13 Representing simple graphs Adjacency matrix  Every row and column corresponds to a vertex  Entry corresponds to edges  Can use weights for given edges  Symmetric around diagonal if graph is undirected

Recitation notes on graphs, Uri Dekel and David Murray 14 Representing simple graphs Adjacency list  A set of linked lists or arrays, one for each vertex, listing the connected vertices or edges  Commonly used for sparse graphs

Mazes and Spanning Trees

Recitation notes on graphs, Uri Dekel and David Murray 16 Mazes A maze can be considered as a graph  Every “square” is a vertex  If there is no wall between two adjacent squares, an edge will link the corresponding vertices  There must be a single path from entrance vertex to exit vertex, and no cycle To construct a maze: create a spanning tree from the entrance vertex

Recitation notes on graphs, Uri Dekel and David Murray 17 Spanning tree The spanning of a graph G is a tree containing all vertices of G  More than one possible spanning tree

Recitation notes on graphs, Uri Dekel and David Murray 18 Minimum Spanning Tree A Minimum Spanning Tree of a graph G with weights on the edges  A spanning tree covering all the vertices of G with the lowest possible total weight  Note: there could be more than one MST, but all have the same weight

Recitation notes on graphs, Uri Dekel and David Murray 19 Kruskal’s Algorithm for MSTs Input:  Connected graph G=(V,E) and a set of weights Output:  Minimum spanning tree T=(V,E’) Algorithm: Start with empty T 1. Find edge e with smallest weight 2. If adding e to T does not create cycle, add it. 3. Continue until all vertices of G are in T. NOTE: Intermediate T is not necessarily a tree! (No cycles, but does not cover all of G)

Recitation notes on graphs, Uri Dekel and David Murray 20 Kruskal’s Example Input graph: Step #1: Choose an edge  (we’ll start with A-E although G-H is also 1)

Recitation notes on graphs, Uri Dekel and David Murray 21 Kruskal’s Example Input graph: Step #2: Choose G-H

Recitation notes on graphs, Uri Dekel and David Murray 22 Kruskal’s Example Input graph: Step #3: Choose B-F

Recitation notes on graphs, Uri Dekel and David Murray 23 Kruskal’s Example Input graph: Step #4: Choose B-C

Recitation notes on graphs, Uri Dekel and David Murray 24 Kruskal’s Example Input graph: Step #5: Choose F-G

Recitation notes on graphs, Uri Dekel and David Murray 25 Kruskal’s Example Input graph: Step #6: Choose E-F

Recitation notes on graphs, Uri Dekel and David Murray 26 Kruskal’s Example - Results Step #7 (Choose C-D): or… Step #7 (Choose H-D):

Recitation notes on graphs, Uri Dekel and David Murray 27 Prim’s Algorithm for MSTs Input:  Connected graph G=(V,E) and a set of weights  Vertex V0 to start from Output:  Minimum spanning tree T=(V,E’) rooted at V0 Algorithm: Start with T containing only V0 While there are still vertices not in T: Find minimal edge e between tree vertex and non-tree vertex Add e to T

Questions?