Graph Theory: Starting Out

Similar documents
Basic Combinatorics. Math 40210, Section 01 Fall Homework 4 Solutions

Lecture 5: Graphs. Rajat Mittal. IIT Kanpur

The Konigsberg Bridge Problem

ASSIGNMENT 4 SOLUTIONS

Week 10: Colouring graphs, and Euler s paths. 14 and 16 November, 2018

An Introduction to Graph Theory

Intermediate Math Circles Wednesday, February 22, 2017 Graph Theory III

Elements of Graph Theory

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:

#30: Graph theory May 25, 2009

CSE 21 Spring 2016 Homework 5. Instructions

Chapter 3: Paths and Cycles

Worksheet for the Final Exam - Part I. Graphs

Instant Insanity Instructor s Guide Make-it and Take-it Kit for AMTNYS 2006

Varying Applications (examples)

CHAPTER 10 GRAPHS AND TREES. Copyright Cengage Learning. All rights reserved.

Fundamental Properties of Graphs

Math 776 Graph Theory Lecture Note 1 Basic concepts

Graphs and trees come up everywhere. We can view the internet as a graph (in many ways) Web search views web pages as a graph

Graph Theory. 1 Introduction to Graphs. Martin Stynes Department of Mathematics, UCC January 26, 2011

EECS 203 Lecture 20. More Graphs

CSE 21 Spring 2016 Homework 5. Instructions

14 More Graphs: Euler Tours and Hamilton Cycles

PSD1A. DESIGN AND ANALYSIS OF ALGORITHMS Unit : I-V

PATH FINDING AND GRAPH TRAVERSAL

Matrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:

6.2. Paths and Cycles

Figure 2.1: A bipartite graph.

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

Introduction to Algorithms

11.2 Eulerian Trails

Week 11: Eulerian and Hamiltonian graphs; Trees. 15 and 17 November, 2017

Section Graphs, Paths, and Circuits. Copyright 2013, 2010, 2007, Pearson, Education, Inc.

INTRODUCTION TO GRAPH THEORY. 1. Definitions

How can we lay cable at minimum cost to make every telephone reachable from every other? What is the fastest route between two given cities?

The Matrix-Tree Theorem and Its Applications to Complete and Complete Bipartite Graphs

Number Theory and Graph Theory

Unit 7 Day 4 Notes: graph coloring, Graph theory review & Quiz

5.1 Min-Max Theorem for General Matching

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. An Introduction to Graph Theory

Packet #6: Counting & Graph Theory. Applied Discrete Mathematics

Characterization of Graphs with Eulerian Circuits

Vertex-Edge Graphs. Vertex-Edge Graphs In the Georgia Performance Standards. Sarah Holliday Southern Polytechnic State University

Algebraic Graph Theory- Adjacency Matrix and Spectrum

1 Definition of Reduction

Brief History. Graph Theory. What is a graph? Types of graphs Directed graph: a graph that has edges with specific directions

CS2 Algorithms and Data Structures Note 10. Depth-First Search and Topological Sorting

Grade 7/8 Math Circles Graph Theory - Solutions October 13/14, 2015

Senior Math Circles November 25, 2009 Graph Theory II

REGULAR GRAPHS OF GIVEN GIRTH. Contents

4. (a) Draw the Petersen graph. (b) Use Kuratowski s teorem to prove that the Petersen graph is non-planar.

Worksheet 28: Wednesday November 18 Euler and Topology

Chapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.

Graph Theory. Part of Texas Counties.

1 Introduction. 1. Prove the problem lies in the class NP. 2. Find an NP-complete problem that reduces to it.

Lecture 3: Recap. Administrivia. Graph theory: Historical Motivation. COMP9020 Lecture 4 Session 2, 2017 Graphs and Trees

Topic 10 Part 2 [474 marks]

Chapter 5: Euler Paths and Circuits The Mathematics of Getting Around

Algorithms and Complexity

An Introduction to Graph Theory

Graphs: Definitions Trails, Paths, and Circuits Matrix Representations Isomorphisms. 11. Graphs and Trees 1. Aaron Tan. 30 October 3 November 2017

Grades 7 & 8, Math Circles 31 October/1/2 November, Graph Theory

8 NP-complete problem Hard problems: demo

Chapter 11: Graphs and Trees. March 23, 2008

Introduction III. Graphs. Motivations I. Introduction IV

14 Graph Theory. Exercise Set 14-1

Mathematics and Statistics, Part A: Graph Theory Problem Sheet 1, lectures 1-4

Week 10: Colouring graphs, and Euler s paths. 14 and 16 November, 2018

Junior Circle Meeting 3 Circuits and Paths. April 18, 2010

Graph theory. Po-Shen Loh. June We begin by collecting some basic facts which can be proved via bare-hands techniques.

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

Outline. Graphs. Divide and Conquer.

Chapter 5: Euler Paths and Circuits The Mathematics of Getting Around

Notebook Assignments

Ma/CS 6a Class 8: Eulerian Cycles

Eulerian Tours and Fleury s Algorithm

a b c d a b c d e 5 e 7

Design and Analysis of Algorithms

Coping with the Limitations of Algorithm Power Exact Solution Strategies Backtracking Backtracking : A Scenario

Combinatorics Summary Sheet for Exam 1 Material 2019

Part II. Graph Theory. Year

MATH 682 Notes Combinatorics and Graph Theory II. One interesting class of graphs rather akin to trees and acyclic graphs is the bipartite graph:

CS 4407 Algorithms Lecture 5: Graphs an Introduction

0.0.1 Network Analysis

Basics of Graph Theory

1 Digraphs. Definition 1

Logic: The Big Picture. Axiomatizing Arithmetic. Tautologies and Valid Arguments. Graphs and Trees

Graph Algorithms (part 3 of CSC 282),

Graph and Digraph Glossary

Graph Theory Problem Ideas

Pre-Calculus. Slide 1 / 192. Slide 2 / 192. Slide 3 / 192. Matrices

Pre-Calculus Matrices

MITOCW watch?v=zm5mw5nkzjg

Graph Theory. Chapter 4.

Discrete Mathematics Course Review 3

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

CMPSCI611: The SUBSET-SUM Problem Lecture 18

MAT 145: PROBLEM SET 4

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Put the following equations to slope-intercept form then use 2 points to graph

Transcription:

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) FCQs this week Final exam Tues. 12/16 10:30-1

Let s Start Where Graph Theory Started

The Königsberg Bridge Problem Is there a walk that you can take in Königsberg such that you go over each bridge exactly once? (Ideally, a walk that ends in the same place that it began.)

The Euler Trail Problem Given a graph of vertices and edges, determine whether there is a trail that will use every edge exactly once. (The Euler trail/circuit problem)

The Euler Trail Problem: An Easy Problem Let s pause to take a deeper look at this problem. Think of it as a little puzzle. You may notice, first of all, that whenever you try to find a trail that uses all edges of this graph, you can t seem to do it. Can we prove there s no solution?

A Brief Pause for Vocabulary There s a lot of specialized vocabulary in graph theory. See especially the definitions on pages 508-511 in the textbook. Here, we ll focus on the following definitions: walk, path, trail; cycle, circuit; degree of a vertex.

Euler Trail, Continued We just showed that some graphs don t have an Euler trail, if they have more than two vertices with an odd degree. What about graphs which don t have this dangerous property? Is there a way of finding an Euler trail for any such graph?

Fleury s Algorithm Start with an odd-degree vertex of the graph (remember there are at most two); if there are no odd-degree vertices, choose any vertex at random. Step 1: If there is a non-bridge edge E to traverse, choose that; if not, choose any edge E; traverse that edge E, and delete it from the graph. Keep doing Step 1 until you re done!

One little matter: What s a Bridge Edge (or Non-Bridge Edge )? A bridge edge is one that, if you subtract it from the graph, separates the graph into two distinct components that can t be reached from one another. (In other words, the bridge edge is the only way to get from some set of vertices to another.)

As an exercise

Addendum: How Many Odd Vertices Can a Graph Have? Remember that our rule is: if a graph has 2 or fewer odd vertices, then it has an Euler trail. In fact, no graph can have only one odd vertex. So to have an Euler trail, we re looking for graphs with either two or zero odd vertices. To have an Euler circuit, only graphs with zero odd vertices will do. A final puzzle: why can t a graph have only one odd vertex? Try to create a graph that does why won t that work?

Say, How Do You Determine if a Graph is Connected or Not? Depth-first Search Define DFS-connected? (currentv othervs done) If (are-all-vertices-accounted-for? currentv done) TRUE If (nullset? othervs) FALSE If (already-in-the-done-set? currentv) ELSE DFS-connected? (first othervs) (rest othervs) done Let new-others (add-to-front-of-list (adjacent-vertices currentv) othervs) DFS-connected? (first new-others) (rest new-others) (add-to-front-of-list currentv done) Start with: DFS-Connected? (vertex1 (adjacent-vertices-to vertex1) {vertex1})

Depth-first search of a tree: a connected graph with no cycles in it.

Current others done A BCDE A B CDE A A DCDE BA D CDE BA A BCFCDE DBA B CFCDE DBA C FCDE DBA A DEFFCDE CDBA D EFFCDE CDBA E FFCDE CDBA A CFFCDE ECDBA C FFCDE ECDBA F FCDE ECDBA à TRUE!

Breadth-first search: an alternative way of searching a graph (in this case, a tree)

Here s a superficially similar problem to the Euler trail problem Given a graph of vertices and edges, determine whether there is a cycle path that will move you from vertex to vertex, visiting each vertex exactly once (except for the final step, which lands you where you began). This is the Hamiltonian cycle problem.

What separates the easy from the apparently hard kinds of problems? One sort is called a polynomial-time problem: you can write a program that will solve the problem in a relatively short amount of time (a polynomial function of the size of the input). The Euler trail problem is polynomial time.

What separates these last two kinds of problems? The other sort is called a non-deterministic polynomial-time problem: you can easily write a program that will solve the problem, but only in exponential time. On the other hand, if you re lucky, you can guess an answer to the problem that can be written and checked in polynomial time. The Hamilton circuit problem is non-deterministic polynomial time.

Another easy (polynomial-time) example: Bipartite matching (the dance-hall problem But compare... the tripartite (men/women/dogs) matching problem!

P and NP P is the name given to the set of all problems that can be reliably solved in polynomial time: that is, the time you need to solve the problem grows as a polynomial function of the input size. NP is the name given to the set of all problems for which you can guess and check a solution in polynomial time: that is, the time you need to solve the problem if you re extremely lucky in your guess grows as a polynomial function of the input size. (NP means non-deterministic polynomial )

A little digression: What s Polynomial Time? We want to know how much time a problem takes to solve as the size of the problem gets larger. How long does it take (say) to sort a list of length N? How long to solve a Tower-of- Hanoi problem of tower-size N? How long to find a Hamiltonian circuit in a graph with N vertices and M edges?...

Polynomial Time (continued) If the time we need to solve the problem grows about as fast as a polynomical function of the problem size (say, N 2 or N 3 or N 50 ) then we have a polynomial-time problem. The Euler path problem is polynomial-time in the number of vertices (or edges) of the graph, for example.

Note: Some Problems are Worse than NP The Tower of Hanoi problem is an example: think of the size of the problem as measured by the number n of discs to move. The only way to solve the problem even to write out a solution requires an exponential number of steps (approximately 2 n ). So you can t guess or check a shorter solution.

Another example of a problem in NP that isn t known to be in P: the graph clique problem.

Some additional topics Notice that P is a subset of NP: any problem that is in P is clearly also in NP. The issue is whether there is any problem that is in NP that is not in P. There are some problems in NP that appear, as far as we know, to require exponential time to solve deterministically. The idea of an NP-Complete problem

Graphs in Computer Science How do you represent a graph? Different representations make certain computations easier or harder to accomplish.

A Typical Graph Data Structure An adjacency matrix: here, row i, column j contains the number of edges linking vertex i to vertex j. 0 1 0 0 1 0! 1 0 1 0 1 0! 0 1 0 1 0 0! 0 0 1 0 1 1! 1 1 0 1 0 0! 0 0 0 1 0 0!

Working with an adjacency matrix Note that you can represent multiple edges and loops with this data structure It s easy to test whether a graph is simple: only 1 s, and all 0 s along the diagonal. It s easy to test (e.g.) for the presence of an Eulerian trail in a simple graph: do more than two rows have an odd number of 1 s? If you multiply the matrix by itself (matrix multiplication), you get a matrix representing the number of walks of length 2 between vertex i and vertex j

An Aside on Matrix Multiplication You have two n x n matrices, A and B. Their product can be written A x B, A B, or just AB. Important note: for matrices, AB does not (in general) equal BA. (That is, matrix multiplication is not commutative.) To get the i, j entry of AB, you take the dot product of the ith row of A and the jth column of B.

Ok, what s the dot product? (a, b, c, d) (e, f, g, h) = ae + bf + cg + dh Note that the dot product multiplies two equal-length rows of numbers (vectors), and returns a single number. That s why it is also called the scalar product. The example here takes the dot product of two 4-vectors.

0 1 0 0 1 0 0 1 0 0 1 0 2 1 1 1 1 0! 1 0 1 0 1 0 1 0 1 0 1 0 1 3 0 2 1 0! 0 1 0 1 0 0 X 0 1 0 1 0 0 = 1 0 2 0 2 1! 0 0 1 0 1 1 0 0 1 0 1 1 1 2 0 3 0 0! 1 1 0 1 0 0 1 1 0 1 0 0 1 1 2 0 3 1! 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1!! This is a two-step adjacency matrix. Each entry (i, j) represents the number of distinct twostep paths between vertex i and vertex J.!

Now we can step back and think about this process Suppose you have an adjacency matrix A for a graph. In a sense, A can be thought of as representing all length-1 walks. If a i,j is 1, there is a length-1 walk (i.e, an edge) between vertices i and j. If a i,j is 0 there are no length-1 walks between vertices i and j.

How many distinct walks of length m between two vertices i and j? You multiply A by itself m times to get A m. Note, by the way, that matrix multiplication, while not commutative, is associative: so you can multiply AAA as (AA)A or as (AA)A. The i, jth entry of A m is just the number of distinct walks of length m from i to j. (If you show this for A A, remembering the meaning of the dot product that produces each entry, you can see how it works for length-2 walks. The general rule is then proved by induction.) So we have solved a combinatorial problem by a simple computational method.

0 1 0 0 1 0 0 1 0 0 1 0 2 1 1 1 1 0! 1 0 1 0 1 0 1 0 1 0 1 0 1 3 0 2 1 0! 0 1 0 1 0 0 X 0 1 0 1 0 0 = 1 0 2 0 2 1! 0 0 1 0 1 1 0 0 1 0 1 1 1 2 0 3 0 0! 1 1 0 1 0 0 1 1 0 1 0 0 1 1 2 0 3 1! 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1!! This is a two-step adjacency matrix. Each entry (i, j) represents the number of distinct twostep paths between vertex i and vertex J.!