CS120 Graphs.

Slides:



Advertisements
Similar presentations
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Advertisements

Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Chapter 8, Part I Graph Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
CHAPTER 13 Graphs DATA ABSTRACTION AND PROBLEM SOLVING WITH C++ WALLS AND MIRRORS Third Edition Frank M. Carrano Janet J. Prichard Data Abstraction and.
ITEC200 – Week 12 Graphs. 2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study.
Data Structures & Algorithms Graph Search Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
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.
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.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
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.
Graphs Chapter 20 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Graphs Chapter 28 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Data Structures Using C++ 2E
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 Graphs.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
Graphs. What is a graph? A data structure that consists of a set of nodes (vertices) and a set of edges that relate the nodes to each other The set of.
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.
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graphs Upon completion you will be able to:
Graphs Chapter 28 © 2015 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures and Abstractions with Java, 4e Frank Carrano.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Representing Graphs Depth First Search Breadth First Search Graph Searching Algorithms.
BCA-II Data Structure Using C Submitted By: Veenu Saini
Graphs Chapter 20.
Graphs Motivation and Terminology Representations Traversals
Graphs Representation, BFS, DFS
CSE 373 Topological Sort Graph Traversals
Lecture 11 Graph Algorithms
Graphs CS Data Structures Mehmet H Gunes
Csc 2720 Instructor: Zhuojun Duan
Lecture 12 Graph Algorithms
Depth-First Search.
CS202 - Fundamental Structures of Computer Science II
More Graph Algorithms.
Comp 245 Data Structures Graphs.
CS200: Algorithm Analysis
Graph.
Refresh and Get Ready for More
Graph Algorithm.
Graph & BFS.
Graphs Representation, BFS, DFS
Graphs Chapter 13.
Graphs Chapter 15 explain graph-based algorithms Graph definitions
Graph Representation (23.1/22.1)
Graphs.
What is a Graph? a b c d e V= {a,b,c,d,e} E= {(a,b),(a,c),(a,d),
Chapter 11 Graphs.
Yan Shi CS/SE 2630 Lecture Notes
Spanning Trees Longin Jan Latecki Temple University based on slides by
Chapter 14 Graphs © 2006 Pearson Addison-Wesley. All rights reserved.
Ch. 14 Graphs Graph traversals Applications of graphs
GRAPHS G=<V,E> Adjacent vertices Undirected graph
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
Elementary Graph Algorithms
Lecture 10 Graph Algorithms
Lecture 11 Graph Algorithms
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:

CS120 Graphs

GRAPHS

Graph Types Undirected Graphs Weighted undirected graph

Graph Terminology A graph and one of its subgraphs

Graph Terminology

Graph-like, but not Graphs

Running times for graph algorithms; expressed in terms of |V| and |E|. If |E| is  |V2| then the graph is dense. If |E| is  |V| then the graph is sparse.

Graphs as ADTs What data structure would you use? What operations should be supplied?

Graphs as ADTs ADT graph operations Test if empty Get number of vertices, edges in a graph See if edge exists between two given vertices Add vertex to graph whose vertices have distinct, different values from new vertex Add/remove edge between two given vertices Remove vertex, edges to other vertices Retrieve vertex that contains given value

GRAPH REPRESENTATIONS

Adjacency Matrix Representation

Matrix Example 2

Matrix Example 3 A directed unweighted graph and (b) its adjacency matrix

Matrix Example4 A weighted undirected graph and (b) its adjacency matrix

Matrix representation requires too much storage for large graphs that are sparse, but very efficient for small graphs: use 1 bit per edge.

Adjacency List Representation

List Example 2

List Example 3 A directed graph and (b) its adjacency list

List Example 4 A weighted undirected graph and (b) its adjacency list

Adjacency List Representation

Vertex Degree/Indegree/Outdegree What is the degree of vertex a? of vertex c? What is the indegree of vertex 0 ? Vertex 2 ? What is the outdegree of vertex 3? Vertex 1?

Adjacency List Representation

Graph Traversals Visits all vertices it can reach Visits all vertices if and only if the graph is connected Connected component Subset of vertices visited during a traversal that begins at a given vertex

Depth-First Search DFS traversal Goes as far as possible from a vertex before backing up Recursive traversal algorithm or stack based algorithm

Breadth-First Search BFS traversal Visits all vertices adjacent to a vertex before going forward BFS is a first visited, first explored strategy uses a queue based strategy Contrast DFS as last visited, first explored

Depth-First Search The results of a depth-first traversal, beginning at vertex a

Breadth-First Search The results of a breadth-first traversal, beginning at vertex a

Applications of Graphs Topological Sorting – finding an order of precedence relationships Spanning Tree – find a connected component Minimum Spanning Trees – find a minimum weight connected component Shortest Paths – find the shortest path from source to destination, find all pairs shortest paths Circuits – does a graph have a cycle Some Difficult Problems – Traveling Salesman Problem, Hamiltonian Circuit Problem, Euler Circuit Problem, Finding a k-Clique in a graph, etc…..

Topological Sorting A directed graph without cycles

Topological Sorting The graph arranged according to two topological orders

Topological Sorting

Topological Sorting Trace Depth First Search, output node to front of list when all its adjacent vertices have been visited.

Spanning Trees A tree is an undirected connected graph without cycles Detecting a cycle in an undirected graph Connected undirected graph with n vertices must have at least n – 1 edges If it has exactly n – 1 edges, it cannot contain a cycle With more than n – 1 edges, must contain at least one cycle

Spanning Trees A spanning tree for the graph. Dotted edges not in spanning tree.

Spanning Trees FIGURE 20-20 Connected graphs that each have four vertices and three edges

Spanning Trees Another possible spanning tree for the graph in

Spanning Trees The BFS spanning tree rooted at vertex a for the graph

Minimum Spanning Trees A weighted, connected, undirected graph