Data structures and algorithms lab8

14
DATA STRUCTURES AND ALGORITHMS LAB 8 Bianca Tesila FILS, April 2014

description

 

Transcript of Data structures and algorithms lab8

Page 1: Data structures and algorithms lab8

DATA STRUCTURES AND ALGORITHMS

LAB 8

Bianca Tesila

FILS, April 2014

Page 2: Data structures and algorithms lab8

OBJECTIVES

Connected Graph Hamiltonian Graph Eulerian Graph

Page 3: Data structures and algorithms lab8

CONNECTED GRAPH

An undirected graph G = (V, A) is said to be connected if, for any vertices u and v of S, there is a chain from u to v.

Page 4: Data structures and algorithms lab8

CONNECTED GRAPH – CONNECTED COMPONENTS

A connected component (or just component) of an undirected graph is a subgraph in which any two vertices are connected to each other by paths, and which is connected to no additional vertices in the supergraph.

Page 5: Data structures and algorithms lab8

CONNECTED GRAPH

Classic problems: Check whether a graph is connected or not Find all the connected components of a graph

!! DFS is used to determine if a graph is connected or not.

Page 6: Data structures and algorithms lab8

CONNECTED GRAPH

!! Exercise:Check whether a graph is connected or not.

Page 7: Data structures and algorithms lab8

HAMILTONIAN GRAPH

 Hamiltonian Path (or traceable path): a path in an undirected or directed graph that visits each vertex exactly once.

Hamiltonian Cycle (or Hamiltonian circuit): a Hamiltonian path that is a cycle. That

is, it begins and ends on the same vertex.

Hamiltonian Graph: a graph that contains a Hamiltonian cycle

!! Any Hamiltonian cycle can be converted to a Hamiltonian path by removing one of its edges.

Page 8: Data structures and algorithms lab8

HAMILTONIAN GRAPH

 

https://sites.google.com/site/poggiolidiscretemath/graph-theory/hamiltonian-graphs

Page 9: Data structures and algorithms lab8

HAMILTONIAN GRAPH

!! Exercise:Check whether a graph is Hamiltonian or not.

Hint:If G is a non-oriented with n> = 3 vertices, such that every vertex of G has the degree greater or equal to N / 2, then G is Hamiltonian graph.

Page 10: Data structures and algorithms lab8

EULERIAN GRAPH

Eulerian Trail (or Eulerian path): a trail in a graph which visits every edge exactly once. It can end on a vertex different from the one on which it began.

Eulerian Cycle: an Eulerian trail which starts and ends on the same vertex.

Eulerian Graph: a graph that contains an Eulerian cycle

Page 11: Data structures and algorithms lab8

EULERIAN GRAPH

A graph G, without isolated vertices, is Eulerian if and only if it is connected and the degrees of all vertices are even numbers.

Classic problem: find the Eulerian cycle in a graph.

https://sites.google.com/site/poggiolidiscretemath/graph-theory/eulerian-graphs

Page 12: Data structures and algorithms lab8

EULERIAN GRAPH

!! Exercise:Check whether a graph is Eulerian or not.

Hint:A connected graph G is an Euler graph if and only if all vertices of G are of even degree.

Page 13: Data structures and algorithms lab8

EULERIAN VS. HAMILTONIAN GRAPHS

!! An Eulerian circuit traverses every edge in a graph exactly once, but may repeat vertices, while a Hamiltonian circuit visits each vertex in a graph exactly once but may repeat edges.

Page 14: Data structures and algorithms lab8

HOMEWORK

Finish all the lab assignments.