Introduction to Graphs

Similar documents
Introduction to Graphs

Master Theorem, Introduction to Graphs

Graphs and Puzzles. Eulerian and Hamiltonian Tours.

Eulerian tours. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. April 20, 2016

Encoding/Decoding, Counting graphs

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

Encoding/Decoding. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. May 9, 2016

Eulerian Tours and Fleury s Algorithm

Eulerian Tours and Fleury s Algorithm

DEFINITION OF GRAPH GRAPH THEORY GRAPHS ACCORDING TO THEIR VERTICES AND EDGES EXAMPLE GRAPHS ACCORDING TO THEIR VERTICES AND EDGES

Binomial Coefficients

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

Trees. Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck. April 29, 2016

Graphs. Introduction To Graphs: Exercises. Definitions:

An Introduction to Graph Theory

Graphs. Pseudograph: multiple edges and loops allowed

CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism

Introduction to Graphs

Graphs & Digraphs Tuesday, November 06, 2007

Section 8.2 Graph Terminology. Undirected Graphs. Definition: Two vertices u, v in V are adjacent or neighbors if there is an edge e between u and v.

Section 10.1: Graphs and Graph Models. Introduction to Graphs Definition of a Graph Types of Graphs Examples of Graphs

Graphs. The ultimate data structure. graphs 1

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory

Graphs. The ultimate data structure. graphs 1

Ma/CS 6b Class 13: Counting Spanning Trees

Lecture 22 Tuesday, April 10

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

CMSC 380. Graph Terminology and Representation

CPCS Discrete Structures 1

2. CONNECTIVITY Connectivity

Foundations of Discrete Mathematics

Varying Applications (examples)

Information Science 2

The vertex set is a finite nonempty set. The edge set may be empty, but otherwise its elements are two-element subsets of the vertex set.

(5.2) 151 Math Exercises. Graph Terminology and Special Types of Graphs. Malek Zein AL-Abidin

CS200: Graphs. Prichard Ch. 14 Rosen Ch. 10. CS200 - Graphs 1

CSC Intro to Intelligent Robotics, Spring Graphs

Lecture 10. Graphs Vertices, edges, paths, cycles Sparse and dense graphs Representations: adjacency matrices and adjacency lists Implementation notes

Figure 2.1: A bipartite graph.

Graphs. The ultimate data structure. graphs 1

CS4800: Algorithms & Data Jonathan Ullman

Parallel development II 11/5/18

Elements of Graph Theory

Discrete Mathematics (2009 Spring) Graphs (Chapter 9, 5 hours)

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

CSE 100: GRAPH ALGORITHMS

Computer Science 280 Fall 2002 Homework 10 Solutions

DO NOT RE-DISTRIBUTE THIS SOLUTION FILE

implementing the breadth-first search algorithm implementing the depth-first search algorithm

Introduction to Algorithms. Lecture 11. Prof. Patrick Jaillet

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

Graph Coloring. Margaret M. Fleck. 3 May This lecture discusses the graph coloring problem (section 9.8 of Rosen).

Chapter 11: Graphs and Trees. March 23, 2008

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

Graphs II: Trailblazing

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

Network Basics. CMSC 498J: Social Media Computing. Department of Computer Science University of Maryland Spring Hadi Amiri

March 20/2003 Jayakanth Srinivasan,

context. (Similarly, we write ν for ν(g), etc. if there is no risk of confusion.) For a subset A V we write N G (A) = {v V ( w A)(v w)} (the set of

Discrete Mathematics, Spring 2004 Homework 8 Sample Solutions

Basic Graph Algorithms (CLRS B.4-B.5, )

Graph Theory S 1 I 2 I 1 S 2 I 1 I 2

Graphs. Data Structures and Algorithms CSE 373 SU 18 BEN JONES 1

Graph definitions. There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs. An undirected graph

ECE 242 HOMEWORK 5. In the figure below, one can go from node B to A but not from A to B.

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

Assignment 4 Solutions of graph problems

The inverse of a matrix

Graph Theory Part Two

UCSD CSE 101 MIDTERM 1, Winter 2008

This course is intended for 3rd and/or 4th year undergraduate majors in Computer Science.

Math 776 Graph Theory Lecture Note 1 Basic concepts

Introduction to Computer Science and Programming for Astronomers

Graph Theory. Part of Texas Counties.

CS 206 Introduction to Computer Science II

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

Pre-Calculus Matrices

Problem 1. Which of the following is true of functions =100 +log and = + log? Problem 2. Which of the following is true of functions = 2 and =3?

Graphs (MTAT , 6 EAP) Lectures: Mon 14-16, hall 404 Exercises: Wed 14-16, hall 402

Counting the number of spanning tree. Pied Piper Department of Computer Science and Engineering Shanghai Jiao Tong University

New Jersey Center for Teaching and Learning. Progressive Mathematics Initiative

Pre-Calculus. Introduction to Matrices. Slide 1 / 192 Slide 2 / 192. Slide 3 / 192. Slide 4 / 192. Slide 6 / 192. Slide 5 / 192. Matrices

A. Petr and a calendar

Solving problems on graph algorithms

Chapter 2 Graphs. 2.1 Definition of Graphs

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

11/26/17. directed graphs. CS 220: Discrete Structures and their Applications. graphs zybooks chapter 10. undirected graphs

Homework #5 Algorithms I Spring 2017

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Math 778S Spectral Graph Theory Handout #2: Basic graph theory

MC302 GRAPH THEORY SOLUTIONS TO HOMEWORK #1 9/19/13 68 points + 6 extra credit points

CS302 - Data Structures using C++

CSE 101, Winter Discussion Section Week 1. January 8 - January 15

CS61BL. Lecture 5: Graphs Sorting

Artificial Intelligence

Graph Algorithms (part 3 of CSC 282),

CSE 21 Summer 2017 Homework 4

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

A graph is finite if its vertex set and edge set are finite. We call a graph with just one vertex trivial and all other graphs nontrivial.

Today. Types of graphs. Complete Graphs. Trees. Hypercubes.

Transcription:

Introduction to Graphs Russell Impagliazzo and Miles Jones Thanks to Janine Tiefenbruck http://cseweb.ucsd.edu/classes/sp16/cse21-bd/ April 18, 2016 1

What is a graph? A (directed) graph G is A nonempty set of vertices V, also called nodes and A set of edges E, each pointing from one vertex to another (denoted with an arrow) 2

Variants of graphs Undirected graph: don't need arrows on edges if there's an edge from v to w then there's an edge from w to v. Rosen p. 644 Multigraph: undirected graph that may have multiple edges between a pair of nodes. Such edges are called parallel edges. Simple graph: undirected graph with no self-loops (edge from v to v) and no parallel edges. Mixed graph: directed graph that may have multiple edges between a pair of nodes and self loops. 3

Graphs are everywhere 4

Graphs are everywhere The internet graph 5

Graphs are everywhere Map coloring 6

Graphs are everywhere Path planning for robots 7

Graphs are everywhere 8

Are these the same graph? A. Yes: the set of vertices is the same. B. Yes: we can rearrange the vertices so that the pictures look the same. C. No: the pictures are different. D. No: the left graph has a crossing and the right one doesn't. E. None of the above. 9

Representing directed graphs J Diagrams with vertices and edges How many vertices? For each ordered pair of vertices (v,w) how many edges go from v to w? 10

Representing directed graphs J Diagrams with vertices and edges How many vertices? n For each ordered pair of vertices (v,w) how many edges go from v to w? How many ordered pairs of vertices are there? A. n B. n(n-1) C. n 2 D. n(n-1)/2 E. 2 n 11

Representing directed graphs J Diagrams with vertices and edges How many vertices? n For each ordered pair of vertices (v,w) how many edges go from v to w? Need to store n(n-1) ints 12

Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j Rosen p. 669 13

Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j What can you say about the adjacency matrix of a loopless graph? A. It has all zeros. B. All the elements below the diagonal are 1. C. All the elements are even. D. All the elements on the diagonal are 0. E. None of the above. Rosen p. 669 14

Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j What can you say about the adjacency matrix of a graph with no parallel edges? A. It has no zeros. B. It is symmetric. C. All the entries above the diagonal are 0. D. All entries are either 0 or 1. E. None of the above. Rosen p. 669 15

Representing directed graphs Adjacency matrix n x n matrix: entry in row i and column j is the number of edges from vertex i to vertex j What can you say about the adjacency matrix of an undirected graph? A. It has no zeros. B. It is symmetric. C. All the entries above the diagonal are 0. D. All entries are either 0 or 1. E. None of the above. Rosen p. 669 16

Representing undirected graphs Simple undirected graph: * Only need to store the adjacency matrix above diagonal. What's the maximum number of edges a simple undirected graph with n vertices can have? A. n 2 B. n 2 /2 C. n(n-1)/2 D. n(n+1)/2 E. n 17

Efficiency? When is an adjacency matrix an inefficient way to store a graph? High density of edges compared to number of vertices Low density of edges compared to number of vertices 18

Representing directed graphs Adjacency list (list of lists): for each vertex v, associate list of all neighbors of v. Rosen p. 668 19

Neighbors The neighbors of a vertex v are all the vertices w for which there is an edge whose endpoints are v,w. If two vertices are neighbors then they are called adjacent to one another. Rosen p. 651

Degree The degree of a vertex in an undirected graph is the total number of edges incident with it, except that a loop contributes twice. What's the maximum degree of a vertex in this graph? A. 0. B. 1 C. 2 D. 3 E. None of the above. Rosen p. 652 21

Degree The degree of a vertex in an undirected graph is the total number of edges incident with it, except that a loop contributes twice. What's the maximum degree of a vertex in this graph? A. 0. B. 1 C. 2 D. 3 E. None of the above. Rosen p. 652 22

Degree What's the degree of vertex 5? A. 5 B. 3 C. 2 D. 1 E. None of the above. 23

Degree What's the degree of vertex 0? A. 5 B. 3 C. 2 D. 1 E. None of the above. 24

Handshakes If there are n people in a room, and each shakes hands with d people, how many handshakes take place? A. n B. d C. nd D. (nd)/2 E. None of the above. 25

Handshakes If there are n people in a room, and each shakes hands with d people, how many handshakes take place? A. n B. d C. nd D. (nd)/2 E. None of the above. Don't double-count each handshake! 26

Handshakes "in" graphs If a simple graph has n vertices and each vertex has degree d, how many edges are there? 2 E = n*d 27

Handshakes "in" graphs If any graph has n vertices, then 2 E = sum of degrees of all vertices 28

Handshakes "in" graphs If any graph has n vertices, then 2 E = sum of degrees of all vertices What can we conclude? A. Every degree in the graph is even. B. The number of edges is even. C. The number of vertices with odd degree is even. D. The number self loops is even. E. None of the above. 29

Puzzles 30

Tartaglia's Pouring Problem Large cup: contains 8 ounces, can hold more. Medium cup: is empty, has 5 ounce capacity. Small cup: is empty, has 3 ounce capacity You can pour from one cup to another until the first is empty or the second is full. Can we divide the coffee in half? How? A. Yes B. No 31

Tartaglia's Pouring Problem Large cup: contains 8 ounces, can hold more. Medium cup: is empty, has 5 ounce capacity. Small cup: is empty, has 3 ounce capacity You can pour from one cup to another until the first is empty or the second is full. Can we divide the coffee in half? How? Hint: configurations (l,m,s) code # ounces in each cup A. Yes B. No 32

Die Hard with a vengeance https://youtu.be/5_monu9mkm4 33

Tartaglia's Pouring Problem 34

Tartaglia's Pouring Problem Rephrasing the problem: Looking for path from (8,0,0) to (4,4,0) 35

Path Sequence (v 0, e 1, v 1, e 2, v 2,, e k, v k ) describes a route through the graph from to start vertex v 0 end vertex v k 36

Tartaglia's Pouring Problem Rephrasing the problem: (1) Is there a path from (8,0,0) to (4,4,0)? (2) If so, what's the best path? "Best" means "shortest length" 37

Tartaglia's Pouring Problem What's the shortest length of a path from (8,0,0) to (4,4,0)? A. 7 B. 8 C. 14 D. 16 E. None of the above. 38

Algorithmic questions related to paths Reachability: Is there a path from vertex v to vertex w? Path: Find a path from vertex v to vertex w. Distance: What's the length of the shortest path from vertex v to vertex w? 39

Reminders HW 4 due tonight 11:59pm via Gradescope. Midterm 1: this Friday, Jan 29 in class covers through Monday s class * Practice midterm on website/piazza. * Review session tonight: see website/piazza. * Seating chart on website/piazza. * One double-sided handwritten note sheet allowed. * If you have AFA letter, see me as soon as possible.