Section 13  Questions  Graphs. Graphs  A graph representation: –Adjacency matrix. Pros:? Cons:? –Neighbor lists. Pros:? Cons:?

Slides:



Advertisements
Similar presentations
Chapter 9 Graphs.
Advertisements

Chapter 9: Graphs Topological Sort
22C:19 Discrete Math Graphs Fall 2010 Sukumar Ghosh.
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Graph-02.
Section 14.1 Intro to Graph Theory. Beginnings of Graph Theory Euler’s Konigsberg Bridge Problem (18 th c.)  Can one walk through town and cross all.
Graph Algorithms: Topological Sort The topological sorting problem: given a directed, acyclic graph G = (V, E), find a linear ordering of the vertices.
Graphs Intro G.Kamberova, Algorithms Graphs Introduction Gerda Kamberova Department of Computer Science Hofstra University.
Discrete Structures Chapter 7B Graphs Nurul Amelina Nasharuddin Multimedia Department.
Connected Components, Directed Graphs, Topological Sort COMP171.
Representing Graphs Wade Trappe. Lecture Overview Introduction Some Terminology –Paths Adjacency Matrix.
Chapter 11 Graphs and Trees This handout: Terminology of Graphs Eulerian Cycles.
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.
GRAPH Learning Outcomes Students should be able to:
Graph Theory Chapter 6 from Johnsonbaugh Article(6.1, 6.2)
Data Structures Using C++ 2E
1 Graphs Algorithms Sections 9.1, 9.2, and Graphs v1v1 v2v2 v5v5 v7v7 v8v8 v3v3 v6v6 v4v4 A graph G = (V, E) –V: set of vertices (nodes) –E: set.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Chapter 2 Graph Algorithms.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 10.
Graph Algorithms Mathematical Structures for Computer Science Chapter 6 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesGraph Algorithms.
CS 200 Algorithms and Data Structures
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 Structures & Algorithms Graphs
1 Chapter 22 Elementary Graph Algorithms. 2 Introduction G=(V, E) –V = vertex set –E = edge set Graph representation –Adjacency list –Adjacency matrix.
Introduction to Graph Theory
CS 61B Data Structures and Programming Methodology Aug 5, 2008 David Sun.
Eulerian Paths and Cycles. What is a Eulerian Path Given an graph. Find a path which uses every edge exactly once. This path is called an Eulerian Path.
MAT 2720 Discrete Mathematics Section 8.2 Paths and Cycles
Lecture 11: 9.4 Connectivity Paths in Undirected & Directed Graphs Graph Isomorphisms Counting Paths between Vertices 9.5 Euler and Hamilton Paths Euler.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Topological Sort: Definition
Chapter 6: Graphs 6.1 Euler Circuits
Review Euler Graph Theory: DEFINITION: A NETWORK IS A FIGURE MADE UP OF POINTS (VERTICES) CONNECTED BY NON-INTERSECTING CURVES (ARCS). DEFINITION: A VERTEX.
CSE 421 Algorithms Richard Anderson Winter 2009 Lecture 5.
Graphs Rosen, Chapter 8. NOT ONE OF THESE! One of these!
1 GRAPH Learning Outcomes Students should be able to: Explain basic terminology of a graph Identify Euler and Hamiltonian cycle Represent graphs using.
1 Lecture 5 (part 2) Graphs II (a) Circuits; (b) Representation Reading: Epp Chp 11.2, 11.3
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
David Stotts Computer Science Department UNC Chapel Hill.
Topological Sorting.
Graphs Chapter 20.
Chapter 22 Elementary Graph Algorithms
Graphs Representation, BFS, DFS
CSE 373 Topological Sort Graph Traversals
GRAPHS Lecture 16 CS2110 Fall 2017.
Graphs Rosen, Chapter 8.
Discrete Structures – CNS2300
Graphs: As a mathematics branch
CS120 Graphs.
More Graph Algorithms.
Lecture 15 CSE 331 Sep 29, 2014.
Can you draw this picture without lifting up your pen/pencil?
Graphs Representation, BFS, DFS
Graphs Chapter 13.
Lecture 14 CSE 331 Sep 30, 2016.
"Learning how to learn is life's most important skill. " - Tony Buzan
Graphs: As a mathematics branch
Lectures on Graph Algorithms: searching, testing and sorting
A path that uses every vertex of the graph exactly once.
CSE 373 Graphs 4: Topological Sort reading: Weiss Ch. 9
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSCI2100 Data Structures Tutorial
Lecture 14 CSE 331 Sep 29, 2017.
Lecture 16 CSE 331 Oct 8, 2012.
Euler and Hamilton Paths
CSE 417: Algorithms and Computational Complexity
Euler circuit Theorem 1 If a graph G has an Eulerian path, then it must have exactly two odd vertices. Theorem 2 If a graph G has an Eulerian circuit,
GRAPHS Lecture 17 CS2110 Spring 2018.
Presentation transcript:

Section 13  Questions  Graphs

Graphs  A graph representation: –Adjacency matrix. Pros:? Cons:? –Neighbor lists. Pros:? Cons:?

Graphs  A graph representation: –Adjacency matrix. Pros: O(1) check if u is a neighbor of v. Cons:Consumes lots of memory for sparse graphs. Slow in finding all neighbors. –Neighbor lists. Pros:Consume little memory, easy to find all neighbors. Cons:Check if u is a neighbor of v can be expensive.

Graphs  In practice, usually neighbor lists are used.

Some graphs we often meet.  Acyclic - no cycles.  Directed, undirected.  Directed, acyclic graph = dag.

Topological sorting  A problem: Given a dag G determine the ordering of the vertices such that v precedes u iff there is an edge (v, u) in G.  Algorithm: Take out the vertice with no incoming edges along with its edges, put in the beginning of a list, repeat while necessary.  Implementation?

Topological sorting  More descriptive description:  1. For each vertice v compute count[v] - the number of incoming edges.  2. Put all the vertices with count[v] = 0 to the stack  3. repeat: Take top element v from the stack, decrease count[u] for its neighbors u.

Topological sorting  Implementation:  1. Use DFS/BFS to compute count.  2. Complexity?  O(E + V) - 1. takes E, the loop is executed V times, the number of operations inside loop sums up to E.

Topological sorting  Applications: –Job scheduling.

The bridges of Konigsberg

 In 1735 Leonard Euler asked himself a question.  Is it possible to walk around Konigsberg walking through each bridge exactly once?

The brid(g)es of Konigsberg

The bridges of Konigsberg  It’s not possible!  It’s a graph problem!

Euler’s theorem  The Euler circuit passes through each edge in the graph only once and returns to the starting point.  Theorem: The graph has an Euler circuit iff every vertice has even degree. (the number of adjacent vertices)

Euler’s circuit  How to check if there’s one?

Hamiltonian’s circuit  A cycle which passes through vertice only once.  How to find one efficiently?

Hamiltonian’s cycle  Nobody knows!!!

REWARD!!! $ is offered to anyone who finds an efficient algorithm for finding Hamiltonian cycle in a graph. DEAD OR ALIVE