Chapter 28. Graphs and Applications. Part1. Non-weighted Graphs
|
|
- Gordon Dean
- 5 years ago
- Views:
Transcription
1 Chapter 28 Graphs and Applications Part1. Non-weighted Graphs CIS265/506 Cleveland State University Prof. Victor Matos Adapted from: Introduction to Java Programming: Comprehensive Version, Eighth Edition by Y. Daniel Liang
2 Modeling Using Graphs Seattle Boston Chicago New York Denver San Francisco Kansas City Los Angeles Atlanta Dallas Houston Miami 2
3 Weighted Graph Animation 3
4 Seven Bridges of Königsberg A The city of Konigsberg is connected to two islands through seven bridges. C Island 1 D Island 2 B The city, islands, and bridge could be abstracted as a graph holding vertices and edges (bridges). The problem was to find a walk through the graph that would begin and end at the same vertex crossing each edge exactly once. A C B D 4
5 Seven Bridges of Königsberg No solution!! Def. A path that traverses all bridges once and also has the same starting and ending is called an Eulerian circuit. A, 3 Such a circuit exists if, and only if, the graph is connected, and there are no nodes of odd degree at all. A node degree is the count of edges adjacent to the node. C, 5 B, 3 D, 3 5 Leonhard Euler, 1707
6 Basic Graph Terminology 1. What is a graph? 2. Directed vs. undirected graphs 3. Weighted vs. non-weighted graphs 4. Adjacent vertices 5. Incident 6. Degree 7. Neighbor 8. loop Leonhard Euler,
7 Basic Graph Terminology 1. What is a graph? A graph G(V, E) is a representation of a set of vertices V and edges E. Two vertices v1 and v2 in V are related iff there is and edge e 12 in E connecting v1 and v2. Leonhard Euler,
8 Basic Graph Terminology 1. What is a graph? Seattle Chicago Boston New York Denver San Francisco Kansas City Los Angeles Atlanta Dallas Houston Miami 8
9 Basic Graph Terminology 2. Node, vertice, vertex 3. Parallel edge 4. Loops 5. Complete graph 6. Simple graph (connected, undirected, no loops, no parallel weighted) 9
10 Basic Graph Terminology 7. Spanning tree T of a connected, undirected graph G is a tree composed of all the vertices and some (or perhaps all) of the edges of G. A graph may have several Spanning trees! 10
11 Java: Representing Graphs Representing Vertices Representing Edges: Edge Array Edge Objects (POJO) Adjacency Matrices Adjacency Lists 11
12 Seattle Boston Representing Vertices San Francisco Denver Chicago Kansas City New York A vertex could be an object of any type. Los Angeles Dallas Atlanta Houston Miami String[ ] vertices = { Seattle, San Francisco, ; public class City { private String cityname; private int population;... City[ ] vertices = {city0, city1, ; List<String> vertices; 12
13 Representing Edges: Edge Array int[][] edges = {{0, 1, {0, 3 {0, 5, {1, 0, {1, 2, ; There is an edge between city0 and city1 13
14 Representing Edges: Edge Object public class Edge { int v1, v2; public Edge(int v1, int v2) { this.v1 = v1; this.v 2 = v2; List<Edge> list = new ArrayList<Edge>(); list.add( new Edge(0, 1) ); list.add( new Edge(0, 3) );
15 Representing Edges: Adjacency Matrix int[][] adjacencymatrix = { {0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, // Seattle {1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, // San Francisco {0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, // Los Angeles {1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, // Denver {0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, // Kansas City {1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, // Chicago {0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, // Boston {0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, // New York {0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, // Atlanta {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, // Miami {0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, // Dallas {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0 // Houston ; Entry adjacencymatrix[i][j] is 1 if there is an edge connecting city-i and city-j 15
16 Representing Edges: Adjacency List List<Integer>[ ] neighbors = new LinkedList<Integer>[12]; Seattle San Francisco Los Angeles Denver Kansas City Chicago Boston New York Atlanta Miami Dallas Houston neighbors[0] neighbors[1] neighbors[2] neighbors[3] neighbors[4] neighbors[5] neighbors[6] neighbors[7] neighbors[8] neighbors[9] neighbors[10] neighbors[11]
17 Modeling Graphs In a style similar to the Java Collection Framework we will define 1. an interface named Graph that contains all common operations of graphs and 2. an abstract class named AbstractGraph that partially implements the Graph interface. 3. Many concrete graphs may be added to the design. For example, we will define such graphs named UnweightedGraph and WeightedGraph. UnweightedGraph Graph AbstractGraph WeightedGraph 17 Interface Abstract Class Concrete Classes
18 Modeling Graphs 18
19 Modeling Graphs 19
20 Graph Traversals - Trees Depth-first search (DFS) and breadth-first search (BFS) Both traversals result in a spanning tree, which can be modeled using a class. 20
21 Depth-First Search (DFS) 1. In the case of a tree, DFS search starts from the root (similar to pre-order navigation). 2. In a graph, the search can start from any vertex. 21 dfs(vertex v) { visit v; for each neighbor w of v if (w has not been visited) { dfs(w);
22 DFS Depth-First Search Example Begin at node
23 DFS Depth-First Search Example Seattle Boston Chicago New York Denver San Francisco Kansas City Los Angeles Atlanta Dallas Houston Miami 23
24 Applications of the DFS 1. Detecting whether a graph is connected. Search the graph starting from any vertex. If the number of vertices searched is the same as the number of vertices in the graph, the graph is connected. Otherwise, the graph is not connected 2. Detecting / finding a path between two vertices. 3. Finding all connected components. A connected component is a maximal connected subgraph in which every pair of vertices are connected by a path. 4. Detecting / Finding a cycle in a graph. 24
25 Breadth-First Search (BFS) With breadth-first traversal of a tree, the nodes are visited level by level. 1. First the root is visited, 2. then all the children of the root, 3. then the grandchildren of the root from left to right, 4. and so on. 25
26 BFS Breadth-First Search Algorithm bfs(vertex v) { create an empty queue for storing vertices to be visited; add v into the queue; mark v visited; while the queue is not empty { dequeue a vertex, say u, from the queue process u; for each neighbor w of u if w has not been visited { add w into the queue; mark w visited; 26
27 BFS Breadth-First Search Example Queue: 0 Queue: Queue: isvisited[0] = true isvisited[1] = true isvisited[2] = true isvisited[3] = true isvisited[4] = true 27
28 BFS Breadth-First Search Example Seattle Boston Chicago New York Denver San Francisco Kansas City Los Angeles Atlanta Dallas Houston Miami 28
29 29 Applications of the BFS 1. Detecting whether a graph is connected. A graph is connected if there is a path between any two vertices in the graph. 2. Detecting whether there is a path between two vertices. 3. Finding a shortest path between two vertices. You can prove that the path between the root and any node in the BFS tree is the shortest path between the root and the node 4. Finding all connected components. A connected component is a maximal connected subgraph in which every pair of vertices are connected by a path. 5. Detecting /Finding whether there is a cycle in the graph. 6. Testing whether a graph is bipartite. A graph is bipartite if the vertices of the graph can be divided into two disjoint sets such that no edges exist between vertices in the same set.
30 Programming Excersice Represent the following graph. Traverse using DFS and BFS 30
31 BFS & DFS Programming Exercise public static void main(string[] args) { Graph<String> graph = new Graph<String>(); graph.addvertice("v0"); graph.addvertice("v1"); graph.addvertice("v2"); graph.addvertice("v3"); graph.addvertice("v4"); graph.addvertice("v5"); graph.addedge(0,1); graph.addedge(1,2); graph.addedge(1,3); graph.addedge(1,4); graph.addedge(4,5); graph.addedge(2,5); graph.addedge(3,5); graph.showdata(); System.out.println("\nDFS >>> "); graph.clearvisitedmarkers(); graph.dfs(0); System.out.println("\nBFS >>> "); graph.clearvisitedmarkers(); graph.bfs(0); 31
32 BFS & DFS Programming Exercise public class Graph <E> { private ArrayList<E> vertices; private ArrayList< ArrayList<Integer> > neighbors; private ArrayList<Boolean> visitedmarkers; public Graph() { vertices = new ArrayList<E>(); neighbors = new ArrayList < ArrayList<Integer> >(); visitedmarkers = new ArrayList<Boolean>(); public void addvertice(e newvertice){ vertices.add(newvertice); visitedmarkers.add(false); neighbors.add(new ArrayList<Integer>() ); public void addedge( int v1, int v2){ ArrayList<Integer> adjacent1 = neighbors.get(v1); if (!adjacent1.contains(v2)) neighbors.get(v1).add(v2); ArrayList<Integer> adjacent2 = neighbors.get(v2); if (!adjacent2.contains(v1)) neighbors.get(v2).add(v1); 32
33 BFS & DFS Programming Exercise public void markverticeasvisited(int v){ visitedmarkers.set(v, true); public void clearvisitedmarkers(){ for(int i=0; i<vertices.size(); i++){ visitedmarkers.set(i, false); public void showdata() { for (int i=0; i<vertices.size(); i++){ System.out.printf("\nVertice[%d]= %s", i, vertices.get(i)); for (int i=0; i < vertices.size(); i++){ System.out.printf("\nneighbors[%d]: ", i); ArrayList<Integer> adjacent = neighbors.get(i); //showdata for (int j=0; j<adjacent.size(); j++){ System.out.printf(" %d,", adjacent.get(j) ); 33
34 BFS & DFS Programming Exercise public void dfs(int v) { visitedmarkers.set(v, true); for(int n : neighbors.get(v)){ if (!visitedmarkers.get(n)){ System.out.printf("[v%d-v%d] ", v, n); dfs(n); //dfs 34
35 BFS & DFS Programming Excersice public void bfs(int v){ ArrayList<Integer> queue = new ArrayList<Integer>(); clearvisitedmarkers(); visitedmarkers.set(v, true); System.out.printf("BFS >>> starting at: v%d \n", v); queue.add(v); while(queue.size() > 0){ int currentdequeuedvertice = queue.remove(0); ArrayList<Integer> adjacents = neighbors.get(currentdequeuedvertice); for(int i=0; i<adjacents.size(); i++){ int adjacentnode = adjacents.get(i); if (!visitedmarkers.get(adjacentnode)){ System.out.printf("[v%d-v%d] ", currentdequeuedvertice, adjacentnode); queue.add(adjacentnode); visitedmarkers.set(adjacentnode, true); //if 35 //bfs //while //for
36 Case: The Nine Tail Problem 1. Nine coins are placed in a three by three matrix with some face up and some face down. 2. A legal move is to take any coin that is face up and reverse it, together with the coins adjacent to it (this does not include coins that are diagonally adjacent). 3. Your task is to find the minimum number of the moves that lead to all coins face down. H H H T T T H H H H H H T H T T T T T T T T T T T T T 36
37 Case: The Nine Tail Problem 37 H H H T T T H H H H H H T H T T T T T T T T T T T T T
38 Finding Eulerian Paths An Eulerian path traverses each edge of a connected graph G exactly once. It exists only if there are no more than two odd nodes. 1. Pick an odd vertex to start. 2. From that vertex move to a node using an unvisited edge. 3. Mark that edge as visited (see note) 4. Try to repeat 2-4 until all edges have been traversed Note: DFS algorithm marks nodes as visited. More than two odd nodes no Euler Path
39 The Hamiltonian Path Problem Def. A Hamiltonian path in a graph is a path that visits each vertex in the graph exactly once. Def. A Hamiltonian cycle is a cycle that visits each vertex in the graph exactly once and returns to the starting vertex. Notes: Problem is NP-Complete Many applications such as: Scheduling the Traveling Salesman Itinerary. 39
Chapter 28 Graphs and Applications. Objectives
Chapter 28 Graphs and Applications CS2: Data Structures and Algorithms Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox, Wim Bohm, and Russ Wakefield 1 Objectives
More informationGRAPHS AND APPLICATIONS
CHAPTER 3 GRAPHS AND APPLICATIONS Objectives To model real-world problems using graphs and explain the Seven Bridges of Königsberg problem ( 3.). To describe the graph terminologies: vertices, edges, simple
More informationTo model real-world problems using graphs and explain the Seven Bridges of Königsberg problem
CHAPTER 24 Graphs and Applications Objectives To model real-world problems using graphs and explain the Seven Bridges of Königsberg problem ( 24.1). To describe graph terminologies: vertices, edges, simple
More information1 Copyright 2012 by Pearson Education, Inc. All Rights Reserved.
CHAPTER 22 Graphs and Applications Objectives To model real-world problems using graphs and explain the Seven Bridges of Königsberg problem ( 22.1). To describe the graph terminologies: vertices, edges,
More informationWeighted Graphs and Applications. CSE260, Computer Science B: Honors Stony Brook University
Weighted Graphs and Applications CSE260, Computer Science B: Honors Stony Brook University http://www.cs.stonybrook.edu/~cse260 1 Objectives To represent weighted edges using adjacency matrices and adjacency
More informationKonigsberg Bridge Problem
Graphs Konigsberg Bridge Problem c C d g A Kneiphof e D a B b f c A C d e g D a b f B Euler s Graph Degree of a vertex: the number of edges incident to it Euler showed that there is a walk starting at
More informationWorksheet for the Final Exam - Part I. Graphs
Worksheet for the Final Exam - Part I. Graphs Date and Time: May 10 2012 Thursday 11:50AM~1:50PM Location: Eng 120 Start with the Self-Test Exercises (pp.816) in Prichard. 1. Give the adjacency matrix
More information國立清華大學電機工程學系. Outline
國立清華大學電機工程學系 EE Data Structure Chapter Graph (Part I) Outline The Graph Abstract Data Type Introduction Definitions Graph Representations Elementary Graph Operations Minimum Cost Spanning Trees ch.- River
More informationCrossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)
15-251 Great Ideas in Theoretical Computer Science Lecture 12: Graphs I: The Basics February 22nd, 2018 Crossing bridges Königsberg (Prussia) Now Kaliningrad (Russia) Is there a way to walk through the
More informationOutline. Graphs. Divide and Conquer.
GRAPHS COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges books. Outline Graphs.
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 04 / 06 / 2018 Instructor: Michael Eckmann Today s Topics Questions? Comments? Graphs Definition Terminology two ways to represent edges in implementation traversals
More informationEngineering Software Development in Java
Engineering Software Development in Java Lecture Notes for ENCE 688R, Civil Information Systems Spring Semester, 2016 Mark Austin, Department of Civil and Enviromental Engineering, University of Maryland,
More informationMath 776 Graph Theory Lecture Note 1 Basic concepts
Math 776 Graph Theory Lecture Note 1 Basic concepts Lectured by Lincoln Lu Transcribed by Lincoln Lu Graph theory was founded by the great Swiss mathematician Leonhard Euler (1707-178) after he solved
More informationGraphs and Algorithms
Graphs and Algorithms Graphs are a mathematical concept readily adapted into computer programming. Graphs are not just data structures, that is, they are not solutions to simple data storage problems.
More informationChapter 14. Graphs Pearson Addison-Wesley. All rights reserved 14 A-1
Chapter 14 Graphs 2011 Pearson Addison-Wesley. All rights reserved 14 A-1 Terminology G = {V, E} A graph G consists of two sets A set V of vertices, or nodes A set E of edges A subgraph Consists of a subset
More informationTo represent weighted edges using adjacency matrices and adjacency lists ( 25.2).
CHAPTER Weighted Graphs and Applications Objectives To represent weighted edges using adjacency matrices and adjacency lists (.). To model weighted graphs using the WeightedGraph class that extends the
More informationMa/CS 6a Class 8: Eulerian Cycles
Ma/CS 6a Class 8: Eulerian Cycles By Adam Sheffer The Bridges of Königsberg Can we travel the city while crossing every bridge exactly once? 1 How Graph Theory was Born Leonhard Euler 1736 Eulerian Cycle
More informationPrelim 2. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer
Prelim 2 CS 2110, November 20, 2014, 7:30 PM 1 2 3 4 5 Extra Total Question True/False Short Answer Complexity Induction Trees Graphs Extra Credit Max 20 10 15 25 30 5 100 Score Grader The exam is closed
More informationIntroduction III. Graphs. Motivations I. Introduction IV
Introduction I Graphs Computer Science & Engineering 235: Discrete Mathematics Christopher M. Bourke cbourke@cse.unl.edu Graph theory was introduced in the 18th century by Leonhard Euler via the Königsberg
More informationOutline. Introduction. Representations of Graphs Graph Traversals. Applications. Definitions and Basic Terminologies
Graph Chapter 9 Outline Introduction Definitions and Basic Terminologies Representations of Graphs Graph Traversals Breadth first traversal Depth first traversal Applications Single source shortest path
More informationMystery Algorithm! ALGORITHM MYSTERY( G = (V,E), start_v ) mark all vertices in V as unvisited mystery( start_v )
Mystery Algorithm! 0 2 ALGORITHM MYSTERY( G = (V,E), start_v ) mark all vertices in V as unvisited mystery( start_v ) 3 1 4 7 6 5 mystery( v ) mark vertex v as visited PRINT v for each vertex w adjacent
More informationUnderstand graph terminology Implement graphs using
raphs Understand graph terminology Implement graphs using djacency lists and djacency matrices Perform graph searches Depth first search Breadth first search Perform shortest-path algorithms Disjkstra
More informationChapter 11: Graphs and Trees. March 23, 2008
Chapter 11: Graphs and Trees March 23, 2008 Outline 1 11.1 Graphs: An Introduction 2 11.2 Paths and Circuits 3 11.3 Matrix Representations of Graphs 4 11.5 Trees Graphs: Basic Definitions Informally, a
More informationThe Konigsberg Bridge Problem
The Konigsberg Bridge Problem This is a classic mathematical problem. There were seven bridges across the river Pregel at Königsberg. Is it possible to take a walk in which each bridge is crossed exactly
More informationToday s Outline. CSE 326: Data Structures. Topic #15: Cool Graphs n Pretty Pictures. A Great Mathematician. The Bridges of Königsberg
CSE 326: Data Structures Topic #15: Cool Graphs n Pretty Pictures Ashish Sabharwal Autumn, 2003 Today s Outline Admin Project 3 in-progress checkin due tonight! Graph Algorithms Representation Applications
More informationCS 220: Discrete Structures and their Applications. graphs zybooks chapter 10
CS 220: Discrete Structures and their Applications graphs zybooks chapter 10 directed graphs A collection of vertices and directed edges What can this represent? undirected graphs A collection of vertices
More informationLecture 5: Graphs. Rajat Mittal. IIT Kanpur
Lecture : Graphs Rajat Mittal IIT Kanpur Combinatorial graphs provide a natural way to model connections between different objects. They are very useful in depicting communication networks, social networks
More informationEECS 203 Lecture 20. More Graphs
EECS 203 Lecture 20 More Graphs Admin stuffs Last homework due today Office hour changes starting Friday (also in Piazza) Friday 6/17: 2-5 Mark in his office. Sunday 6/19: 2-5 Jasmine in the UGLI. Monday
More informationPrelim 2 Solutions. CS 2110, November 20, 2014, 7:30 PM Extra Total Question True/False Short Answer
Prelim 2 Solutions CS 2110, November 20, 2014, 7:30 PM 1 2 3 4 5 Extra Total Question True/False Short Answer Complexity Induction Trees Graphs Extra Credit Max 20 10 15 25 30 5 100 Score Grader The exam
More informationGraph Theory CS/Math231 Discrete Mathematics Spring2015
1 Graphs Definition 1 A directed graph (or digraph) G is a pair (V, E), where V is a finite set and E is a binary relation on V. The set V is called the vertex set of G, and its elements are called vertices
More information6.2. Paths and Cycles
6.2. PATHS AND CYCLES 85 6.2. Paths and Cycles 6.2.1. Paths. A path from v 0 to v n of length n is a sequence of n+1 vertices (v k ) and n edges (e k ) of the form v 0, e 1, v 1, e 2, v 2,..., e n, v n,
More informationHow can we lay cable at minimum cost to make every telephone reachable from every other? What is the fastest route between two given cities?
1 Introduction Graph theory is one of the most in-demand (i.e. profitable) and heavily-studied areas of applied mathematics and theoretical computer science. May graph theory questions are applied in this
More informationLecture 3: Graphs and flows
Chapter 3 Lecture 3: Graphs and flows Graphs: a useful combinatorial structure. Definitions: graph, directed and undirected graph, edge as ordered pair, path, cycle, connected graph, strongly connected
More informationEulerian Cycle (2A) Walk : vertices may repeat, edges may repeat (closed or open) Trail: vertices may repeat, edges cannot repeat (open)
Eulerian Cycle (2A) Walk : vertices may repeat, edges may repeat (closed or open) Trail: vertices may repeat, edges cannot repeat (open) circuit : vertices my repeat, edges cannot repeat (closed) path
More informationGraph (1A) Young Won Lim 4/19/18
Graph (1A) Copyright (c) 2015 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version
More information22.1 Representations of graphs
22.1 Representations of graphs There are two standard ways to represent a (directed or undirected) graph G = (V,E), where V is the set of vertices (or nodes) and E is the set of edges (or links). Adjacency
More informationTopics Covered. Introduction to Graphs Euler s Theorem Hamiltonian Circuits The Traveling Salesman Problem Trees and Kruskal s Algorithm
Graph Theory Topics Covered Introduction to Graphs Euler s Theorem Hamiltonian Circuits The Traveling Salesman Problem Trees and Kruskal s Algorithm What is a graph? A collection of points, called vertices
More informationGraph. Vertex. edge. Directed Graph. Undirected Graph
Module : Graphs Dr. Natarajan Meghanathan Professor of Computer Science Jackson State University Jackson, MS E-mail: natarajan.meghanathan@jsums.edu Graph Graph is a data structure that is a collection
More informationCS 310 Advanced Data Structures and Algorithms
CS 31 Advanced Data Structures and Algorithms Graphs July 18, 17 Tong Wang UMass Boston CS 31 July 18, 17 1 / 4 Graph Definitions Graph a mathematical construction that describes objects and relations
More informationQuestions? You are given the complete graph of Facebook. What questions would you ask? (What questions could we hope to answer?)
P vs. NP What now? Attribution These slides were prepared for the New Jersey Governor s School course The Math Behind the Machine taught in the summer of 2011 by Grant Schoenebeck Large parts of these
More informationSpanning Trees 4/19/17. Prelim 2, assignments. Undirected trees
/9/7 Prelim, assignments Prelim is Tuesday. See the course webpage for details. Scope: up to but not including today s lecture. See the review guide for details. Deadline for submitting conflicts has passed.
More information10/31/18. About A6, Prelim 2. Spanning Trees, greedy algorithms. Facts about trees. Undirected trees
//8 About A, Prelim Spanning Trees, greedy algorithms Lecture CS Fall 8 Prelim : Thursday, November. Visit exams page of course website and read carefully to find out when you take it (: or 7:) and what
More informationIntroduction to Graph Theory
Introduction to Graph Theory Tandy Warnow January 20, 2017 Graphs Tandy Warnow Graphs A graph G = (V, E) is an object that contains a vertex set V and an edge set E. We also write V (G) to denote the vertex
More informationSpanning Trees. Lecture 22 CS2110 Spring 2017
1 Spanning Trees Lecture 22 CS2110 Spring 2017 1 Prelim 2, assignments Prelim 2 is Tuesday. See the course webpage for details. Scope: up to but not including today s lecture. See the review guide for
More informationSpanning Trees, greedy algorithms. Lecture 20 CS2110 Fall 2018
1 Spanning Trees, greedy algorithms Lecture 20 CS2110 Fall 2018 1 About A6, Prelim 2 Prelim 2: Thursday, 15 November. Visit exams page of course website and read carefully to find out when you take it
More informationFoundations of Discrete Mathematics
Foundations of Discrete Mathematics Chapter 12 By Dr. Dalia M. Gil, Ph.D. Trees Tree are useful in computer science, where they are employed in a wide range of algorithms. They are used to construct efficient
More informationGRAPHICAL ALGORITHMS. UNIT _II Lecture-12 Slides No. 3-7 Lecture Slides No Lecture Slides No
GRAPHICAL ALGORITHMS UNIT _II Lecture-12 Slides No. 3-7 Lecture-13-16 Slides No. 8-26 Lecture-17-19 Slides No. 27-42 Topics Covered Graphs & Trees ( Some Basic Terminologies) Spanning Trees (BFS & DFS)
More informationGraph Search Methods. Graph Search Methods
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. 0 Graph Search Methods A search method starts at a given vertex v and visits/labels/marks every vertex that is
More informationSpanning Trees, greedy algorithms. Lecture 22 CS2110 Fall 2017
1 Spanning Trees, greedy algorithms Lecture 22 CS2110 Fall 2017 1 We demo A8 Your space ship is on earth, and you hear a distress signal from a distance Planet X. Your job: 1. Rescue stage: Fly your ship
More informationCSC Design and Analysis of Algorithms. Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms. Brute-Force Approach
CSC 8301- Design and Analysis of Algorithms Lecture 4 Brute Force, Exhaustive Search, Graph Traversal Algorithms Brute-Force Approach Brute force is a straightforward approach to solving a problem, usually
More informationElements of Graph Theory
Elements of Graph Theory Quick review of Chapters 9.1 9.5, 9.7 (studied in Mt1348/2008) = all basic concepts must be known New topics we will mostly skip shortest paths (Chapter 9.6), as that was covered
More informationVarying Applications (examples)
Graph Theory Varying Applications (examples) Computer networks Distinguish between two chemical compounds with the same molecular formula but different structures Solve shortest path problems between cities
More informationLecture 10 Graph algorithms: testing graph properties
Lecture 10 Graph algorithms: testing graph properties COMP 523: Advanced Algorithmic Techniques Lecturer: Dariusz Kowalski Lecture 10: Testing Graph Properties 1 Overview Previous lectures: Representation
More informationChapter 14 Section 3 - Slide 1
AND Chapter 14 Section 3 - Slide 1 Chapter 14 Graph Theory Chapter 14 Section 3 - Slide WHAT YOU WILL LEARN Graphs, paths and circuits The Königsberg bridge problem Euler paths and Euler circuits Hamilton
More informationUnweighted Graphs & Algorithms
Unweighted Graphs & Algorithms Zachary Friggstad Programming Club Meeting References Chapter 4: Graph (Section 4.2) Chapter 22: Elementary Graph Algorithms Graphs Features: vertices/nodes/dots and edges/links/lines
More informationChapter 9. Priority Queue
Chapter 9 Priority Queues, Heaps, Graphs Spring 2015 1 Priority Queue Priority Queue An ADT in which only the item with the highest priority can be accessed 2Spring 2015 Priority Depends on the Application
More informationChapter 2 Graphs. 2.1 Definition of Graphs
Chapter 2 Graphs Abstract Graphs are discrete structures that consist of vertices and edges connecting some of these vertices. Graphs have many applications in Mathematics, Computer Science, Engineering,
More informationGraphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph
Graphs and Trees Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) who is connected to whom Web search views web pages as a graph Who points to whom Niche graphs (Ecology):
More informationMath 778S Spectral Graph Theory Handout #2: Basic graph theory
Math 778S Spectral Graph Theory Handout #: Basic graph theory Graph theory was founded by the great Swiss mathematician Leonhard Euler (1707-178) after he solved the Königsberg Bridge problem: Is it possible
More informationNetworks: Lecture 1. General Comments
Networks: Lecture 1 Amedeo R. Odoni November 1, 200 * Thanks to Prof. R.. Larson for some of the slides General omments From continuous to a more discretized travel environment Enormous literature and
More informationDS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV
Sr.No. Question Option A Option B Option C Option D 1 2 3 4 5 6 Class : S.E.Comp Which one of the following is the example of non linear data structure Let A be an adjacency matrix of a graph G. The ij
More informationCS490: Problem Solving in Computer Science Lecture 6: Introductory Graph Theory
CS490: Problem Solving in Computer Science Lecture 6: Introductory Graph Theory Dustin Tseng Mike Li Wednesday January 16, 2006 Dustin Tseng Mike Li: CS490: Problem Solving in Computer Science, Lecture
More informationPATH FINDING AND GRAPH TRAVERSAL
GRAPH TRAVERSAL PATH FINDING AND GRAPH TRAVERSAL Path finding refers to determining the shortest path between two vertices in a graph. We discussed the Floyd Warshall algorithm previously, but you may
More informationAlgorithm Design and Analysis
Algorithm Design and Analysis LECTURE 5 Exploring graphs Adam Smith 9/5/2008 A. Smith; based on slides by E. Demaine, C. Leiserson, S. Raskhodnikova, K. Wayne Puzzles Suppose an undirected graph G is connected.
More informationMaterial handling and Transportation in Logistics. Paolo Detti Dipartimento di Ingegneria dell Informazione e Scienze Matematiche Università di Siena
Material handling and Transportation in Logistics Paolo Detti Dipartimento di Ingegneria dell Informazione e Scienze Matematiche Università di Siena Introduction to Graph Theory Graph Theory As Mathematical
More informationSearching in Graphs (cut points)
0 November, 0 Breath First Search (BFS) in Graphs In BFS algorithm we visit the verices level by level. The BFS algorithm creates a tree with root s. Once a node v is discovered by BFS algorithm we put
More informationCHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/z
CHAPTER 10 GRAPHS AND TREES Alessandro Artale UniBZ - http://www.inf.unibz.it/ artale/z SECTION 10.1 Graphs: Definitions and Basic Properties Copyright Cengage Learning. All rights reserved. Graphs: Definitions
More informationChapter 9 Graph Algorithms
Chapter 9 Graph Algorithms 2 Introduction graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 3 Definitions an undirected graph G = (V, E)
More information11/22/2016. Chapter 9 Graph Algorithms. Introduction. Definitions. Definitions. Definitions. Definitions
Introduction Chapter 9 Graph Algorithms graph theory useful in practice represent many real-life problems can be slow if not careful with data structures 2 Definitions an undirected graph G = (V, E) is
More informationIntroduction To Graphs and Networks. Fall 2013 Carola Wenk
Introduction To Graphs and Networks Fall 2013 Carola Wenk What is a Network? We have thought of a computer as a single entity, but they can also be connected to one another. Internet What are the advantages
More informationIntroduction to Engineering Systems, ESD.00. Networks. Lecturers: Professor Joseph Sussman Dr. Afreen Siddiqi TA: Regina Clewlow
Introduction to Engineering Systems, ESD.00 Lecture 7 Networks Lecturers: Professor Joseph Sussman Dr. Afreen Siddiqi TA: Regina Clewlow The Bridges of Königsberg The town of Konigsberg in 18 th century
More informationGraph Theory. Part of Texas Counties.
Graph Theory Part of Texas Counties. We would like to visit each of the above counties, crossing each county only once, starting from Harris county. Is this possible? This problem can be modeled as a graph.
More informationModule 11: Additional Topics Graph Theory and Applications
Module 11: Additional Topics Graph Theory and Applications Topics: Introduction to Graph Theory Representing (undirected) graphs Basic graph algorithms 1 Consider the following: Traveling Salesman Problem
More informationGraph Traversals. CS200 - Graphs 1
Graph Traversals CS200 - Graphs 1 Tree traversal reminder A Pre order A B D G H C E F I B C In order G D H B A E C F I D E F Post order G H D B E I F C A G H I Level order A B C D E F G H I Connected Components
More informationAlgorithms: Lecture 10. Chalmers University of Technology
Algorithms: Lecture 10 Chalmers University of Technology Today s Topics Basic Definitions Path, Cycle, Tree, Connectivity, etc. Graph Traversal Depth First Search Breadth First Search Testing Bipartatiness
More informationAlgorithms: Graphs. Amotz Bar-Noy. Spring 2012 CUNY. Amotz Bar-Noy (CUNY) Graphs Spring / 95
Algorithms: Graphs Amotz Bar-Noy CUNY Spring 2012 Amotz Bar-Noy (CUNY) Graphs Spring 2012 1 / 95 Graphs Definition: A graph is a collection of edges and vertices. Each edge connects two vertices. Amotz
More information2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.
1. T F: Consider a directed graph G = (V, E) and a vertex s V. Suppose that for all v V, there exists a directed path in G from s to v. Suppose that a DFS is run on G, starting from s. Then, true or false:
More informationGraph Theory: Starting Out
Graph Theory: Starting Out Administrivia To read: Chapter 7, Sections 1-3 (Ensley/Crawley) Problem Set 5 sent out; due Monday 12/8 in class. There will be two review days next week (Wednesday and Friday)
More informationimplementing the breadth-first search algorithm implementing the depth-first search algorithm
Graph Traversals 1 Graph Traversals representing graphs adjacency matrices and adjacency lists 2 Implementing the Breadth-First and Depth-First Search Algorithms implementing the breadth-first search algorithm
More informationHomework Assignment #3 Graph
CISC 4080 Computer Algorithms Spring, 2019 Homework Assignment #3 Graph Some of the problems are adapted from problems in the book Introduction to Algorithms by Cormen, Leiserson and Rivest, and some are
More informationSCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory
SCHOOL OF ENGINEERING & BUILT ENVIRONMENT Mathematics An Introduction to Graph Theory. Introduction. Definitions.. Vertices and Edges... The Handshaking Lemma.. Connected Graphs... Cut-Points and Bridges.
More informationGraphs. Data Structures 1 Graphs
Graphs Graph Applications Definitions Graph Representations(adjacency matrix/list) Graph ADT Graph Traversals: BFS, DFS Shortest Path Algorithms Minimum Spanning Tree Algorithms Data Structures Graphs
More informationUndirected Graphs. Hwansoo Han
Undirected Graphs Hwansoo Han Definitions Undirected graph (simply graph) G = (V, E) V : set of vertexes (vertices, nodes, points) E : set of edges (lines) An edge is an unordered pair Edge (v, w) = (w,
More informationGRAPHS Lecture 17 CS2110 Spring 2014
GRAPHS Lecture 17 CS2110 Spring 2014 These are not Graphs 2...not the kind we mean, anyway These are Graphs 3 K 5 K 3,3 = Applications of Graphs 4 Communication networks The internet is a huge graph Routing
More informationTheory of Computing. Lecture 10 MAS 714 Hartmut Klauck
Theory of Computing Lecture 10 MAS 714 Hartmut Klauck Seven Bridges of Königsberg Can one take a walk that crosses each bridge exactly once? Seven Bridges of Königsberg Model as a graph Is there a path
More informationSome major graph problems
CS : Graphs and Blobs! Prof. Graeme Bailey http://cs.cs.cornell.edu (notes modified from Noah Snavely, Spring 009) Some major graph problems! Graph colouring Ensuring that radio stations don t clash! Graph
More informationGRAPHS (Undirected) Graph: Set of objects with pairwise connections. Why study graph algorithms?
GRAPHS (Undirected) Graph: Set of objects with pairwise connections. Why study graph algorithms? Interesting and broadly useful abstraction. Challenging branch of computer science and discrete math. Hundreds
More informationCS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs
CS/COE 1501 cs.pitt.edu/~bill/1501/ Graphs 5 3 2 4 1 0 2 Graphs A graph G = (V, E) Where V is a set of vertices E is a set of edges connecting vertex pairs Example: V = {0, 1, 2, 3, 4, 5} E = {(0, 1),
More informationLogic: The Big Picture. Axiomatizing Arithmetic. Tautologies and Valid Arguments. Graphs and Trees
Axiomatizing Arithmetic Logic: The Big Picture Suppose we restrict the domain to the natural numbers, and allow only the standard symbols of arithmetic (+,, =, >, 0, 1). Typical true formulas include:
More informationGRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS
GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS DR. ANDREW SCHWARTZ, PH.D. 10.1 Graphs and Graph Models (1) A graph G = (V, E) consists of V, a nonempty set of vertices (or nodes)
More informationPrecept 4: Traveling Salesman Problem, Hierarchical Clustering. Qian Zhu 2/23/2011
Precept 4: Traveling Salesman Problem, Hierarchical Clustering Qian Zhu 2/23/2011 Agenda Assignment: Traveling salesman problem Hierarchical clustering Example Comparisons with K-means TSP TSP: Given the
More informationUndirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1
Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching
More informationGraph Search Methods. Graph Search Methods
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. 0 Graph Search Methods A search method starts at a given vertex v and visits/labels/marks every vertex that is
More informationDiscrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs
CS 70 Discrete Mathematics for CS Spring 2008 David Wagner Note 13 An Introduction to Graphs Formulating a simple, precise specification of a computational problem is often a prerequisite to writing a
More information4. (a) Draw the Petersen graph. (b) Use Kuratowski s teorem to prove that the Petersen graph is non-planar.
UPPSALA UNIVERSITET Matematiska institutionen Anders Johansson Graph Theory Frist, KandMa, IT 010 10 1 Problem sheet 4 Exam questions Solve a subset of, say, four questions to the problem session on friday.
More informationGraphs and Genetics. Outline. Computational Biology IST. Ana Teresa Freitas 2015/2016. Slides source: AED (MEEC/IST); Jones and Pevzner (book)
raphs and enetics Computational Biology IST Ana Teresa Freitas / Slides source: AED (MEEC/IST); Jones and Pevzner (book) Outline l Motivacion l Introduction to raph Theory l Eulerian & Hamiltonian Cycle
More informationHomework 6 Solutions CS330 Discrete Structures, Fall 2017
Homework 6 Solutions CS330 Discrete Structures, Fall 2017 Instructor: Professor Edward Reingold TA: Jiahui Hou, Haohua Du Solutions 1. 10 pts) Algorithm 1 Basic Euler Circuit Algorithm. procedure Euler(G
More informationGraph Algorithms. A Brief Introduction. 高晓沨 (Xiaofeng Gao) Department of Computer Science Shanghai Jiao Tong Univ.
Graph Algorithms A Brief Introduction 高晓沨 (Xiaofeng Gao) Department of Computer Science Shanghai Jiao Tong Univ. 目录 2015/5/7 1 Graph and Its Applications 2 Introduction to Graph Algorithms 3 References
More informationCOT 6405 Introduction to Theory of Algorithms
COT 6405 Introduction to Theory of Algorithms Topic 14. Graph Algorithms 11/7/2016 1 Elementary Graph Algorithms How to represent a graph? Adjacency lists Adjacency matrix How to search a graph? Breadth-first
More informationEulerian Cycle (2A) Young Won Lim 4/26/18
Eulerian Cycle (2A) Copyright (c) 2015 2018 Young W. Lim. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any
More information