Top Banner
Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR 7271, Sophia Antipolis, France Master 1 international, Univ. Nice Sophia Antipolis, September, 2015 Lecture Notes: http://www-sop.inria.fr/members/Frederic.Giroire/teaching/ubinet/ N. Nisse Graph Theory and applications 1/25
77

Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

May 20, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph Theory and OptimizationIntroduction on Graphs

Nicolas Nisse

Inria, France

Univ. Nice Sophia Antipolis, CNRS, I3S, UMR 7271, Sophia Antipolis, France

Master 1 international, Univ. Nice Sophia Antipolis, September, 2015

Lecture Notes:http://www-sop.inria.fr/members/Frederic.Giroire/teaching/ubinet/

N. Nisse Graph Theory and applications 1/25

Page 2: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 2/25

Page 3: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Vertex/Edge)

A graph G = (V ,E)

Vertices: V = V (G) is a finite set circles

Edges: E = V (E)⊆ {{u,v} | u,v ∈ V} is a binary relation on Vlines between two circles

a

b

d

e

h

j

g

c

f

i

Example: G = (V ,E) with V = {a,b,c,d ,e, f ,g,h, i, j} and

E = {{a,b},{a,c},{a, f},{b,g},{b,h},{c, f},{c,d},{d ,g},{d ,e},{e, j},{f ,g},{f , i},{g,h},{h, i},{h, j},{i, j}}.

Exercise: What is the maximum number of edges of a graph with n vertices?

N. Nisse Graph Theory and applications 3/25

Page 4: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Vertex/Edge)

A graph G = (V ,E)

Vertices: V = V (G) is a finite set circles

Edges: E = V (E)⊆ {{u,v} | u,v ∈ V} is a binary relation on Vlines between two circles

a

b

d

e

h

j

g

c

f

i

Example: G = (V ,E) with V = {a,b,c,d ,e, f ,g,h, i, j} and

E = {{a,b},{a,c},{a, f},{b,g},{b,h},{c, f},{c,d},{d ,g},{d ,e},{e, j},{f ,g},{f , i},{g,h},{h, i},{h, j},{i, j}}.

Exercise: What is the maximum number of edges of a graph with n vertices?

N. Nisse Graph Theory and applications 3/25

Page 5: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 4/25

Page 6: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

1st Example: roads’ network

What is the “best" road forreaching Oulu from Helsinki?

Model geographical netowrk bya graph

Use powerful tools that deal withgraphs

N. Nisse Graph Theory and applications 5/25

Page 7: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

1st Example: roads’ network

What is the “best" road forreaching Oulu from Helsinki?

Model geographical netowrk bya graph

Use powerful tools that deal withgraphs

N. Nisse Graph Theory and applications 5/25

Page 8: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

1st Example: roads’ network

What is the “best" road forreaching Oulu from Helsinki?

Model geographical netowrk bya graph

Use powerful tools that deal withgraphs

N. Nisse Graph Theory and applications 5/25

Page 9: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

1st Example: roads’ network

More difficult setting

• traffic jam

• bus/subway schedule

• no-left, no-right and noU-turn signs atintersections.

Again, graph algorithm toolsmay helpThat is how your GPS work !!

N. Nisse Graph Theory and applications 6/25

Page 10: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

2nd Example: the Internet

Internet network (AutonomousSystems)Optical networks (WDM)

• node= IP routers

• links= optical fiber

• capacity on links

- How to compute “best" routes?- Where to put Amplificators?- Which links to be turned off tolimit energy consumption?...

N. Nisse Graph Theory and applications 7/25

Page 11: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

3rd Example: Social Network

Model of social interactiona user = a nodetwo friends = an edge

• structure of socialnetworks?

• communities?

• how to doadvertisement?

• how to preventadvertisement?

N. Nisse Graph Theory and applications 8/25

Page 12: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

More Example: Web (google)

Google PageRank:sort search results

node= web pagelink = hyperlink

1 finding pages withthe word movies in it

2 determining theimportance of apage.

N. Nisse Graph Theory and applications 9/25

Page 13: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

More Example: Web (google)

Google PageRank:sort search results

node= web pagelink = hyperlink

1 finding pages withthe word movies in it

2 • build the graph ofthe Web

• do a randomwalk on a thegraph or computethe eigenvectorof a matrix

N. Nisse Graph Theory and applications 9/25

Page 14: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 10/25

Page 15: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Neighbor/Degree)

a

b

d

e

h

j

g

c

f

i

• two vertices x ∈ V and y ∈ V are adjacent or neighbors if {x ,y} ∈ Ei.e. there is an edge {x ,y}

• N(x): set of neighbors of x ∈ V ex: N(g) = {b,d , f ,h} ⊆ V• degree of x ∈ V : number of neighbors of x i.e., deg(x) = |N(x)|

Exercise: Prove that, for any graph G = (V ,E), ∑x∈V

deg(x) = 2|E |

N. Nisse Graph Theory and applications 11/25

Page 16: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Neighbor/Degree)

a

b

d

e

h

j

g

c

f

i

• two vertices x ∈ V and y ∈ V are adjacent or neighbors if {x ,y} ∈ Ei.e. there is an edge {x ,y}

• N(x): set of neighbors of x ∈ V ex: N(g) = {b,d , f ,h} ⊆ V• degree of x ∈ V : number of neighbors of x i.e., deg(x) = |N(x)|

Exercise: Prove that, for any graph G = (V ,E), ∑x∈V

deg(x) = 2|E |

N. Nisse Graph Theory and applications 11/25

Page 17: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 12/25

Page 18: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

j

g

c

f

i

• Walk: sequence (v1, · · · ,v`) of vertices such that consecutive verticesare adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

ex: W = (a,b,g,h, j, i, f ,g,d ,e)

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

• Length of a path: number of its edges ex: length(P2) = 8• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , there

exists a path from x to y .

N. Nisse Graph Theory and applications 13/25

Page 19: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

j

g

c

f

i

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

ex: P1 = (a,b,g,h, j)

• Length of a path: number of its edges ex: length(P2) = 8

• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3

• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , thereexists a path from x to y .

N. Nisse Graph Theory and applications 13/25

Page 20: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

j

g

c

f

i

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

ex: P1 = (a,b,g,h, j), P2 = (a,c, f ,g,b,h, j, i,e)

• Length of a path: number of its edges ex: length(P2) = 8

• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3

• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , thereexists a path from x to y .

N. Nisse Graph Theory and applications 13/25

Page 21: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

j

g

c

f

i

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

ex: P1 = (a,b,g,h, j), P2 = (a,c, f ,g,b,h, j, i,e)

• Length of a path: number of its edges ex: length(P2) = 8

• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3

• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , thereexists a path from x to y .

N. Nisse Graph Theory and applications 13/25

Page 22: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

j

g

c

f

i

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

ex: P1 = (a,b,g,h, j), P2 = (a,c, f ,g,b,h, j, i,e)

• Length of a path: number of its edges ex: length(P2) = 8

• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3

• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , thereexists a path from x to y .

N. Nisse Graph Theory and applications 13/25

Page 23: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

k

g

c

f

i

a

b

cd

e

f

connected

NOT connected

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

• Length of a path: number of its edges ex: length(P2) = 8

• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3

• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , thereexists a path from x to y .

N. Nisse Graph Theory and applications 13/25

Page 24: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

k

g

c

f

i

a

b

cd

e

f

connected

NOT connected

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

• Length of a path: number of its edges ex: length(P2) = 8• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , there

exists a path from x to y .

Exercise: Let G be a graph and v ∈ V (G)

Prove that G is connected iff, for any y ∈ V , there exists a path from x to y .N. Nisse Graph Theory and applications 13/25

Page 25: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Terminology and notations (Path/Distance/Connectedness)

a

b

d

e

h

k

g

c

f

i

a

b

cd

e

f

connected

NOT connected

• Path: sequence (v1, · · · ,v`) of distinct vertices such that consecutivevertices are adjacent, i.e., {vi ,vi+1} ∈ E for any 1≤ i < `

• Length of a path: number of its edges ex: length(P2) = 8• Distance between 2 vertices: length of a shortest path ex: dist(a, j) = 3• G = (V ,E) is connected if, for any two vertices x ∈ V and y ∈ V , there

exists a path from x to y .

Exercise: Prove that if |E |< |V |−1 then G = (V ,E) is NOT connected

N. Nisse Graph Theory and applications 13/25

Page 26: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 14/25

Page 27: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Trail/Cycle)

a

b

d

e

h

j

g

c

f

i

• Trail: walk (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: Trail = (a,b,g,d ,c,g,h, i, j,d ,e, j,g, f )

• Cycle: path (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: C1 = (d ,e, j, i,h,g), C2 = (a,c, f )

• Eulerian trail: trail passing through all edges

N. Nisse Graph Theory and applications 15/25

Page 28: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Trail/Cycle)

a

b

d

e

h

j

g

c

f

i

• Trail: walk (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: Trail = (a,b,g,d ,c,g,h, i, j,d ,e, j,g, f )

• Cycle: path (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: C1 = (d ,e, j, i,h,g), C2 = (a,c, f )

• Eulerian trail: trail passing through all edges

N. Nisse Graph Theory and applications 15/25

Page 29: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Trail/Cycle)

a

b

d

e

h

j

g

c

f

i

• Trail: walk (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: Trail = (a,b,g,d ,c,g,h, i, j,d ,e, j,g, f )

• Cycle: path (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: C1 = (d ,e, j, i,h,g), C2 = (a,c, f )

• Eulerian trail: trail passing through all edges

N. Nisse Graph Theory and applications 15/25

Page 30: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Trail/Cycle)

a

b

d

e

h

j

g

c

f

i

• Trail: walk (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: Trail = (a,b,g,d ,c,g,h, i, j,d ,e, j,g, f )

• Cycle: path (v1, · · · ,v`) such that `≥ 3 and {v1,v`} ∈ Eex: C1 = (d ,e, j, i,h,g), C2 = (a,c, f )

• Eulerian trail: trail passing through all edges

Exercise: Is this graph Eulerian, i.e., does it have an Eulerian trail?

N. Nisse Graph Theory and applications 15/25

Page 31: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph Theory an old story

Euler 1735: Koenisberg bridges.Existe-t-il un parcours empruntant tous les ponts une fois et une seule ?

Is there a trail going through each bridge exactly once?

N. Nisse Graph Theory and applications 16/25

Page 32: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph Theory an old story

Modeling: city = graph, island = vertex, bridge = edge

Question: can we find an eulerian cycle in this graph?Cycle going through all edges once and only once

N. Nisse Graph Theory and applications 16/25

Page 33: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph Theory an old story

Modeling: city = graph, island = vertex, bridge = edgeQuestion: can we find an eulerian cycle in this graph?

Cycle going through all edges once and only once

N. Nisse Graph Theory and applications 16/25

Page 34: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph Theory an old storyModeling: city = graph, island = vertex, bridge = edgeQuestion: can we find an eulerian cycle in this graph?Solution: Such cycle exists if and only if all nodes have even degree

An intriguing variant: find a cycle going through all vertices once andonly once (Hamiltonian cycle) is very difficult

One million dollar (Clay price) !

N. Nisse Graph Theory and applications 16/25

Page 35: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph Theory an old storyModeling: city = graph, island = vertex, bridge = edgeQuestion: can we find an eulerian cycle in this graph?Solution: Such cycle exists if and only if all nodes have even degreeAn intriguing variant: find a cycle going through all vertices once andonly once (Hamiltonian cycle) is very difficult

One million dollar (Clay price) !

N. Nisse Graph Theory and applications 16/25

Page 36: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 17/25

Page 37: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Tree)

a

b

d

e

h

k

g

c

f

i

• Tree: connected graph without cycles

• Leaf: vertex of degree 1 in a tree

Trees are important because:“simple" structure + “minimum" structure ensuring connectivity

Theorem:T = (V ,E) is a tree⇔ T connected and |V |= |E |+1

N. Nisse Graph Theory and applications 18/25

Page 38: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Tree)

a

b

d

e

h

k

g

c

f

i

• Tree: connected graph without cycles

• Leaf: vertex of degree 1 in a tree

Trees are important because:“simple" structure + “minimum" structure ensuring connectivity

Theorem:T = (V ,E) is a tree⇔ T connected and |V |= |E |+1

N. Nisse Graph Theory and applications 18/25

Page 39: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Tree)

Theorem: T = (V ,E) is a tree⇔ T connected and |V |= |E |+1⇐ By contradiction:

• if T not a tree, then ∃ a cycle (v1, · · · ,v`)

• Let T ′ be obtained from T by removing edge {v1,v`}

• T ′ is connected “technical" part, to be proved

• |E(T ′)|= |E |−1 = |V |−2 = |V (T ′)|−2

• so |E ′|< |V ′|−1 and T ′ is not connected by previous Exercise

A contradiction

N. Nisse Graph Theory and applications 18/25

Page 40: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (Tree)

Theorem: T = (V ,E) is a tree⇔ T connected and |V |= |E |+1

⇒ Induction on |V | OK if |V |= 1

• Let P = (v1, · · · ,v`) be a longest path in T (` max., in particular `≥ 2)

• v1 is a leaf. By contradiction:

• assume deg(v1)> 1, and x ∈ N(v1)\{v2}• x /∈ V (P) otherwise there is a cycle in T• then, (x ,v1, · · · ,v`) path longer than P, a contradiction

• then S = T \{v1} is a tree “technical" part, to be proved

• |V (S)|< |V | so, by induction |V (S)|= |E(S)|+1

• |V |= |V (S)|+1 and |E |= |E(S)|+1, so |V |= |E |−1

N. Nisse Graph Theory and applications 18/25

Page 41: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

b

d

e

h

j

g

c

f

i

• Subgraph of G = (V ,E): any graph H = (V ′,E ′) withV ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}

obtained from G by removing some vertices and edges

N. Nisse Graph Theory and applications 19/25

Page 42: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

b

d

e

h

k

g

c

f

• Subgraph of G = (V ,E): any graph H = (V ′,E ′) withV ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}

obtained from G by removing some vertices and edges

N. Nisse Graph Theory and applications 19/25

Page 43: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

be

h

k

g

c

f

• Subgraph of G = (V ,E): any graph H = (V ′,E ′) withV ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}

obtained from G by removing some vertices and edges

N. Nisse Graph Theory and applications 19/25

Page 44: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

be

h

k

g

c

f

• Subgraph of G = (V ,E): any graph H = (V ′,E ′) withV ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}

obtained from G by removing some vertices and edges

N. Nisse Graph Theory and applications 19/25

Page 45: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

be

h

k

g

c

f

• Subgraph of G = (V ,E): any graph H = (V ′,E ′) withV ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}

obtained from G by removing some vertices and edges

N. Nisse Graph Theory and applications 19/25

Page 46: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

b

d

e

h

j

g

c

f

i

• Subgraph: H = (V ′,E ′) with V ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}• Spanning subgraph of G: subgraph H = (V ′,E ′) where V ′ = V

obtained from G by removing only some edges

N. Nisse Graph Theory and applications 19/25

Page 47: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

b

d

e

h

j

g

c

f

i

• Subgraph: H = (V ′,E ′) with V ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}• Spanning subgraph of G: subgraph H = (V ′,E ′) where V ′ = V

obtained from G by removing only some edges

• Spanning tree of G: spanning subgraph H = (V ,E ′) with H a tree

N. Nisse Graph Theory and applications 19/25

Page 48: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Graph: terminology and notations (subgraph)

a

b

d

e

h

j

g

c

f

i

• Subgraph: H = (V ′,E ′) with V ′ ⊆ V and E ′ ⊆ {{x ,y} ∈ E | x ,y ∈ V ′}• Spanning subgraph of G: subgraph H = (V ′,E ′) where V ′ = V

obtained from G by removing only some edges

• Spanning tree of G: spanning subgraph H = (V ,E ′) with H a tree

Exercise: A graph G is connected if and only if G has a spanning tree

N. Nisse Graph Theory and applications 19/25

Page 49: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 20/25

Page 50: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

N. Nisse Graph Theory and applications 21/25

Page 51: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

ToBeExplored=(a)

0

N. Nisse Graph Theory and applications 21/25

Page 52: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

ToBeExplored=(a,b)

10

N. Nisse Graph Theory and applications 21/25

Page 53: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

ToBeExplored=(a,b,c)

1

1

0

N. Nisse Graph Theory and applications 21/25

Page 54: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

ToBeExplored=(a,b,c,f)

1

1

1

0

N. Nisse Graph Theory and applications 21/25

Page 55: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(b,c,f)

1

1

1

N. Nisse Graph Theory and applications 21/25

Page 56: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(b,c,f)

1

1

1

N. Nisse Graph Theory and applications 21/25

Page 57: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(b,c,f,g)

1

1

12

N. Nisse Graph Theory and applications 21/25

Page 58: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(b,c,f,g,h)

1

1

12

2

N. Nisse Graph Theory and applications 21/25

Page 59: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(c,f,g,h)

1

1

12

2

N. Nisse Graph Theory and applications 21/25

Page 60: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(c,f,g,h,d)

1

1

12

2

2

N. Nisse Graph Theory and applications 21/25

Page 61: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(f,g,h,d)

1

1

12

2

2

N. Nisse Graph Theory and applications 21/25

Page 62: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(f,g,h,d,i)

1

1

12

2

2

2

N. Nisse Graph Theory and applications 21/25

Page 63: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(h,d,i)

1

1

12

2

2

2

N. Nisse Graph Theory and applications 21/25

Page 64: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(h,d,i,j)

1

1

12

2

2

2 3

N. Nisse Graph Theory and applications 21/25

Page 65: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(d,i,j)

1

1

12

2

2

2 3

N. Nisse Graph Theory and applications 21/25

Page 66: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(d,i,j,e)

1

1

12

2

2

2 3

3

N. Nisse Graph Theory and applications 21/25

Page 67: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(d,i,j,e)

1

1

12

2

2

2 3

3

Breadth First Searchinput: unweighted graph G = (V ,E) and r ∈ V

Initially: d(r) = 0, ToBeExplored = (r)and T = (V (T ),E(T )) = ({r}, /0)

While ToBeExplored 6= /0 do

Let v = head(ToBeExplored)

for u ∈ N(v)\ToBeExplored do

d(u)← d(v)+1add u in V (T ) and {v ,u} in E(T )add u at the end of ToBeExplored

remove v from ToBeExplored

N. Nisse Graph Theory and applications 21/25

Page 68: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(d,i,j,e)

1

1

12

2

2

2 3

3

Breadth First Searchinput: unweighted graph G = (V ,E) and r ∈ V

Initially: d(r) = 0, ToBeExplored = (r)and T = (V (T ),E(T )) = ({r}, /0)

While ToBeExplored 6= /0 do

Let v = head(ToBeExplored)

for u ∈ N(v)\ToBeExplored do

d(u)← d(v)+1add u in V (T ) and {v ,u} in E(T )add u at the end of ToBeExplored

remove v from ToBeExplored

Output: for any v ∈ V , d(v) = dist(r ,v).T is a shortest path tree of G rooted in r : i.e., T spanning subtree of G s.t.

for any v ∈ V , the path from r to v in T is a shortest path from r to v in G.

N. Nisse Graph Theory and applications 21/25

Page 69: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(d,i,j,e)

1

1

12

2

2

2 3

3

Breadth First Searchinput: unweighted graph G = (V ,E) and r ∈ V

Initially: d(r) = 0, ToBeExplored = (r)and T = (V (T ),E(T )) = ({r}, /0)

While ToBeExplored 6= /0 do

Let v = head(ToBeExplored)

for u ∈ N(v)\ToBeExplored do

d(u)← d(v)+1add u in V (T ) and {v ,u} in E(T )add u at the end of ToBeExplored

remove v from ToBeExplored

Time-Complexity: # operations = O(|E |) each edge is considered

Exercise: Give an algorithm that decides if a graph is connected

N. Nisse Graph Theory and applications 21/25

Page 70: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(d,i,j,e)

1

1

12

2

2

2 3

3

Breadth First Searchinput: unweighted graph G = (V ,E) and r ∈ V

Initially: d(r) = 0, ToBeExplored = (r)and T = (V (T ),E(T )) = ({r}, /0)

While ToBeExplored 6= /0 do

Let v = head(ToBeExplored)

for u ∈ N(v)\ToBeExplored do

d(u)← d(v)+1add u in V (T ) and {v ,u} in E(T )add u at the end of ToBeExplored

remove v from ToBeExplored

Time-Complexity: # operations = O(|E |) each edge is consideredRmk1: allows to decide whether G is connected

G connected iff dist(r ,v)< ∞ defined for all v ∈ V

N. Nisse Graph Theory and applications 21/25

Page 71: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

0

ToBeExplored=(d,i,j,e)

1

1

12

2

2

2 3

3

Breadth First Searchinput: unweighted graph G = (V ,E) and r ∈ V

Initially: d(r) = 0, ToBeExplored = (r)and T = (V (T ),E(T )) = ({r}, /0)

While ToBeExplored 6= /0 do

Let v = head(ToBeExplored)

for u ∈ N(v)\ToBeExplored do

d(u)← d(v)+1add u in V (T ) and {v ,u} in E(T )add u at the end of ToBeExplored

remove v from ToBeExplored

Time-Complexity: # operations = O(|E |) each edge is consideredRmk2: gives only one shortest path tree, may be more...

depends on the ordering in which vertices are considered

N. Nisse Graph Theory and applications 21/25

Page 72: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Searching algorithms (BFS/DFS)

a

b

d

e

h

j

g

c

f

i

Depth First Searchinput: unweighted graph G = (V ,E) and r ∈ V

Initially: d(r) = 0, ToBeExplored = (r)and T = (V (T ),E(T )) = ({r}, /0)

While ToBeExplored 6= /0 do

Let v = head(ToBeExplored)

for u ∈ N(v)\ToBeExplored do

d(u)← d(v)+1add u in V (T ) and {v ,u} in E(T )add u at the beginning ofToBeExplored

remove v from ToBeExplored

Exercise: Gives a DFS-tree rooted in a in this graph

N. Nisse Graph Theory and applications 21/25

Page 73: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Outline

1 Vertex/Edge

2 Examples of applications

3 Neighbor/Degree

4 Path/Distance/Connectivity

5 Cycle/Eulerian/Hamiltonian

6 Trees/SubGraph

7 Searching algorithms (BFS/DFS)

8 Directed graphsN. Nisse Graph Theory and applications 22/25

Page 74: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Directed graphsDirected graph: D = (V ,A), A : set of arcs, (x ,y) ∈ A ordered pair

arrows

a

b

d

e

h

j

g

c

f

i

D = (V ,A) is strongly connected if, for any two vertices x ∈ V and y ∈ V ,there exists a directed path from x to y AND a directed path from y to x .

N. Nisse Graph Theory and applications 23/25

Page 75: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Directed graphs

Directed graph: D = (V ,A), A : set of arcs, (x ,y) ∈ A ordered pairarrows

a

b

d

e

h

j

g

c

f

i

a

b

d

e

h

j

g

c

f

i

strongly connected not strongly connected

D = (V ,A) is strongly connected if, for any two vertices x ∈ V and y ∈ V ,there exists a directed path from x to y AND a directed path from y to x .

N. Nisse Graph Theory and applications 23/25

Page 76: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Directed graphs strongly connected

Exercise 1: Let D be a digraph and v ∈ V (D)

Prove that D is strongly connected iff, for any y ∈ V , there exist a directedpath from x to y AND a directed path from y to x .

Exercise 2:Give an efficient algorithm that decides if a digraph is strongly connected

N. Nisse Graph Theory and applications 24/25

Page 77: Graph Theory and Optimization Introduction on Graphs · Graph Theory and Optimization Introduction on Graphs Nicolas Nisse Inria, France Univ. Nice Sophia Antipolis, CNRS, I3S, UMR

Vertex/Edge Examples of applications Neighbor/Degree Path/Distance/Connectivity Cycle/Eulerian/Hamiltonian Trees/SubGraph Searching algorithms (BFS/DFS) Directed graphs

Summary: To be remembered

All definitions will be important in next lecturesPlease remember:

• graph, vertex/vertices, edge

• neighbor, degree

• path, distance, cycle (Eulerian,Hamiltonian)

• connected graph

• tree

• subgraph, spanning subgraph

• BFS/DFS

• Directed graph

N. Nisse Graph Theory and applications 25/25