SlideShare ist ein Scribd-Unternehmen logo
1 von 57
Downloaden Sie, um offline zu lesen
Introduction to Graphs
Tecniche di Programmazione – A.A. 2012/2013
Summary
A.A. 2012/2013Tecniche di programmazione2
 Definition: Graph
 Related Definitions
 Applications
Definition: Graph
Introduction to Graphs
Definition: Graph
A.A. 2012/2013Tecniche di programmazione4
 A graph is a collection of points and lines connecting
some (possibly empty) subset of them.
 The points of a graph are most commonly known
as graph vertices, but may also be called “nodes” or
simply “points.”
 The lines connecting the vertices of a graph are most
commonly known as graph edges, but may also be called
“arcs” or “lines.”
http://mathworld.wolfram.com/
Big warning: Graph ≠ Graph ≠ Graph
Graph (plot)
(italiano: grafico)
Graph (maths)
(italiano: grafo)
A.A. 2012/2013Tecniche di programmazione5
≠
Graph (chart)
(italiano: grafico)
History
A.A. 2012/2013Tecniche di programmazione6
 The study of graphs is known as graph theory, and was
first systematically investigated by D. König in the 1930s
 Euler’s proof about the walk across all seven bridges of
Königsberg (1736), now known as the Königsberg bridge
problem, is a famous precursor to graph theory.
 In fact, the study of various sorts of paths in graphs has
many applications in real-world problems.
Königsberg Bridge Problem
A.A. 2012/2013Tecniche di programmazione7
 Can the 7 bridges the of
the city of Königsberg
over the river Preger all
be traversed in a single
trip without doubling back,
with the additional
requirement that the trip
ends in the same place it
began?
Today: Kaliningrad, Russia
Königsberg Bridge Problem
A.A. 2012/2013Tecniche di programmazione8
 Can the 7 bridges the of
the city of Königsberg
over the river Preger all
be traversed in a single
trip without doubling back,
with the additional
requirement that the trip
ends in the same place it
began?
Today: Kaliningrad, Russia
Types of graphs: edge cardinality
A.A. 2012/2013Tecniche di programmazione9
 Simple graph:
 At most one edge (i.e.,
either one edge or no
edges) may connect any
two vertices
 Multigraph:
 Multiple edges are allowed
between vertices
 Loops:
 Edge between a vertex and
itself
 Pseudograph:
 Multigraph with loops
loop
Types of graphs: edge direction
A.A. 2012/2013Tecniche di programmazione10
 Undirected
 Oriented
 Edges have one direction
(indicated by arrow)
 Directed
 Edges may have one or
two directions
 Network
 Oriented graph with
weighted edges
Types of graphs: labeling
A.A. 2012/2013Tecniche di programmazione11
 Labels
 None
 OnVertices
 On Edges
 Groups (=colors)
 OfVertices
 no edge connects two
identically colored
vertices
 Of Edges
 adjacent edges must
receive different colors
 Of both
A.A. 2012/2013Tecniche di programmazione12
Directed and Oriented graphs
 A Directed Graph (di-graph) G is a pair (V,E), where
 V is a (finite) set of vertices
 E is a (finite) set of edges, that identify a binary relationship
overV
 𝐸 ⊆ 𝑉 × 𝑉
A.A. 2012/2013Tecniche di programmazione13
Example
4
1
5 6
2 3
A.A. 2012/2013Tecniche di programmazione14
Example
4
1
5 6
2 3
Loop
A.A. 2012/2013Tecniche di programmazione15
Example
4
1
5 6
2 3
V={1,2,3,4,5,6}
E={(1,2), (2,2), (2,5),
(5,4), (4,5), (4,1),
(2,4), (6,3)}
A.A. 2012/2013Tecniche di programmazione16
Undirected graph
 Ad Undirected Graph is still represented as a couple
G=(V,E), but the set E is made of non-ordered pairs of
vertices
A.A. 2012/2013Tecniche di programmazione17
Example
4
1
5 6
2 3
V={1,2,3,4,5,6}
E={(1,2), (2,5), (5,1), (6,3)}
A.A. 2012/2013Tecniche di programmazione18
Example
4
1
5 6
2 3
V={1,2,3,4,5,6}
E={(1,2), (2,5), (5,1), (6,3)}
Edge (1,5) adjacent
(or incident) to
vertices 1 and 5
Vertex 5 is adjacent
to vertices 1 and 2
Vertex 4 is isolated
Related Definitions
Introduction to Graphs
A.A. 2012/2013Tecniche di programmazione20
Degree
 In an undirected graph,
 the degree of a vertex is the number of incident edges
 In a directed graph
 The in-degree is the number of incoming edges
 The out-degree is the number of departing edges
 The degree is the sum of in-degree and out-degree
 A vertex with degree 0 is isolated
A.A. 2012/2013Tecniche di programmazione21
Degree
4
1
5 6
2 3
2 2
20 1
1
A.A. 2012/2013Tecniche di programmazione22
Degree
4
1
5 6
2 3
In: 1
Out: 1
In: 2
Out: 2
In: 1 or 2
Out: 2 or 3
In: 2
Out: 1
In: 1
Out: 0
In: 0
Out: 1
Paths
A.A. 2012/2013Tecniche di programmazione23
 A path on a graph G=(V,E) also called a trail, is
a sequence {v1, v2, …, vn} such that:
 v1, …, vn are vertices: vi V
 (v1, v2), (v2, v3), ..., (vn-1,vn) are graph edges: (vi-1,vi)  E
 vi are distinct (for “simple” paths).
 The length of a path is the number of edges (n-1)
 If there exist a path between vA and vB we say that vB is
reachable from vA
A.A. 2012/2013Tecniche di programmazione24
Example
4
1
5 6
2 3
Path = { 1, 2, 5 }
Length = 2
A.A. 2012/2013Tecniche di programmazione25
Cycles
 A cycle is a path where v1 = vn
 A graph with no cycles is said acyclic
A.A. 2012/2013Tecniche di programmazione26
Example
4
1
5 6
2 3
Path = { 1, 2, 5, 1 }
Length = 3
A.A. 2012/2013Tecniche di programmazione27
Reachability (Undirected)
 An undirected graph is connected if, for every couple of
vertices, there is a path connecting them
 The connected sub-graph of maximum size are called
connected components
 A connected graph has exactly one connected
component
A.A. 2012/2013Tecniche di programmazione28
Connected components
4
1
5 6
2 3
The graph is not
connected.
Connected components =
3
{ 4 } , { 1, 2, 5 }, { 3, 6 }
A.A. 2012/2013Tecniche di programmazione29
Reachability (Directed)
 A directed graph is strongly connected if, for every
ordered pair of vertices (v, v’), there exists at least one
path connecting v to v’
A.A. 2012/2013Tecniche di programmazione30
Example
4
1
5
2
The graph is strongly
connected
A.A. 2012/2013Tecniche di programmazione31
Example
4
1
5
2
The graph is not strongly
connected
Complete graph
A.A. 2012/2013Tecniche di programmazione32
 A graph is complete if, for every pair of vertices, there is
an edge connecting them (they are adjacent)
 Symbol: Kn
A.A. 2012/2013Tecniche di programmazione33
Complete graph: edges
 In a complete graph with n vertices, the number of
edges is
 n(n-1), if the graph is directed
 n(n-1)/2, if the graph is undirected
 If self-loops are allowed, then
 n2 for directed graphs
 n(n-1) for undirected graphs
Density
A.A. 2012/2013Tecniche di programmazione34
 The density of a graph G=(V,E) is the ration of the
number of edges to the total number of edges
𝑑 =
𝐸 𝐺
𝐸 𝐾 𝑉(𝐺)
A.A. 2012/2013Tecniche di programmazione35
Esempio
4
1
3
2
Density = 0.5
Existing: 3 edges
Total: 6 possible edges
A.A. 2012/2013Tecniche di programmazione36
Trees and Forests
 An undirected acyclic graph is called forest
 An undirected acyclic connected graph is called tree
A.A. 2012/2013Tecniche di programmazione37
Example
Tree
A.A. 2012/2013Tecniche di programmazione38
Example
Forest
A.A. 2012/2013Tecniche di programmazione39
Example This is not a tree nor a
forest
(it contains a cycle)
Rooted trees
A.A. 2012/2013Tecniche di programmazione40
 In a tree, a special node may be singled out
 This node is called the “root” of the tree
 Any node of a tree can be the root
Tree (implicit) ordering
A.A. 2012/2013Tecniche di programmazione41
 The root node of a tree induces an ordering of the
nodes
 The root is the “ancestor” of all other nodes/vertices
 “children” are “away from the root”
 “parents” are “towards the root”
 The root is the only node without parents
 All other nodes have exactly one parent
 The furthermost (children-of-children-of-children…)
nodes are “leaves”
A.A. 2012/2013Tecniche di programmazione42
Example
Rooted Tree
A.A. 2012/2013Tecniche di programmazione43
Example
Rooted Tree
A.A. 2012/2013Tecniche di programmazione44
Weighted graphs
 A weighted graph is a graph in which each branch (edge)
is given a numerical weight.
 A weighted graph is therefore a special type of labeled
graph in which the labels are numbers (which are usually
taken to be positive).
Applications
Introduction to Graphs
Graph applications
A.A. 2012/2013Tecniche di programmazione46
 Graphs are everywhere
 Facebook friends (and posts, and ‘likes’)
 Football tournaments (complete subgraphs + binary tree)
 Google search index (V=page, E=link, w=pagerank)
 Web analytics (site structure, visitor paths)
 Car navigation (GPS)
 Market Matching
Market matching
A.A. 2012/2013Tecniche di programmazione47
 H = Houses (1, 2, 3, 4)
 B = Buyers (a, b, c, d)
 V = H  B
 Edges: (h, b)  E if b would like to buy h
 Problem: can all houses be sold and all
buyers be satisfied?
 Variant: if the graph is weighted with a
purchase offer, what is the most
convenient solution?
 Variant: consider a ‘penalty’ for unsold
items
This graph is called
“bipartite”:
H  B = 
Connecting cities
A.A. 2012/2013Tecniche di programmazione48
 We have a water reservoir
 We need to serve many cities
 Directly or indirectly
 What is the most efficient set of inter-city water
connections?
 Also for telephony,
gas, electricity, …
We are searching for
the “minimum
spanning tree”
Google Analytics (Visitors Flow)
A.A. 2012/2013Tecniche di programmazione49
Customer behavior
A.A. 2012/2013Tecniche di programmazione50
User actions encoded
as frequencies
Street navigation
A.A. 2012/2013Tecniche di programmazione51
We must find a
“Hamiltonian cycle”
TSP:The traveling
salesman problem
Train maps
A.A. 2012/2013Tecniche di programmazione52
Chemistry (Protein folding)
A.A. 2012/2013Tecniche di programmazione53
Facebook friends
A.A. 2012/2013Tecniche di programmazione54
A.A. 2012/2013Tecniche di programmazione55
Flow chart
BEGIN
END
Resources
A.A. 2012/2013Tecniche di programmazione56
 Maths Encyclopedia: http://mathworld.wolfram.com/
 Basic GraphTheory with Applications to Economics
http://www.isid.ac.in/~dmishra/mpdoc/lecgraph.pdf
 Application of GraphTheory in real world
http://prezi.com/tseh1wvpves-/application-of-graph-theory-
in-real-world/
 JGraphT Library: http://jgrapht.org/
Licenza d’uso
A.A. 2012/2013Tecniche di programmazione57
 Queste diapositive sono distribuite con licenza Creative Commons
“Attribuzione - Non commerciale - Condividi allo stesso modo (CC
BY-NC-SA)”
 Sei libero:
 di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico,
rappresentare, eseguire e recitare quest'opera
 di modificare quest'opera
 Alle seguenti condizioni:
 Attribuzione — Devi attribuire la paternità dell'opera agli autori
originali e in modo tale da non suggerire che essi avallino te o il modo in
cui tu usi l'opera.
 Non commerciale — Non puoi usare quest'opera per fini
commerciali.
 Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se
la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una
licenza identica o equivalente a questa.
 http://creativecommons.org/licenses/by-nc-sa/3.0/

Weitere ähnliche Inhalte

Was ist angesagt?

Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebragavhays
 
Computational Complexity: Introduction-Turing Machines-Undecidability
Computational Complexity: Introduction-Turing Machines-UndecidabilityComputational Complexity: Introduction-Turing Machines-Undecidability
Computational Complexity: Introduction-Turing Machines-UndecidabilityAntonis Antonopoulos
 
Module-1-Digital-and-Analog-Quantities-PROF (1).pdf
Module-1-Digital-and-Analog-Quantities-PROF (1).pdfModule-1-Digital-and-Analog-Quantities-PROF (1).pdf
Module-1-Digital-and-Analog-Quantities-PROF (1).pdfAnthonyTayong1
 
Sequential circuit multiplier
Sequential circuit multiplierSequential circuit multiplier
Sequential circuit multiplierSubhram
 
Introduction to graph theory (All chapter)
Introduction to graph theory (All chapter)Introduction to graph theory (All chapter)
Introduction to graph theory (All chapter)sobia1122
 
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...IAEME Publication
 
Chapter-4-Combinational Logic.pdf
Chapter-4-Combinational Logic.pdfChapter-4-Combinational Logic.pdf
Chapter-4-Combinational Logic.pdfGetinetGaroma1
 
Logic gates ppt
Logic gates pptLogic gates ppt
Logic gates pptparassini
 
Bezier curve
Bezier curveBezier curve
Bezier curveamiyadash
 
Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms Xin-She Yang
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Dr. Pankaj Agarwal
 
MPMC Microprocessor
MPMC MicroprocessorMPMC Microprocessor
MPMC MicroprocessorA.S. Krishna
 
Numerical methods and its applications
Numerical methods and its applicationsNumerical methods and its applications
Numerical methods and its applicationsHaiderParekh1
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Programmers model of 8086
Programmers model of 8086Programmers model of 8086
Programmers model of 8086KunalPatel260
 
Z80 microprocessor architecture1
Z80 microprocessor architecture1Z80 microprocessor architecture1
Z80 microprocessor architecture1Mohaned Alberah
 

Was ist angesagt? (20)

Boolean Algebra
Boolean AlgebraBoolean Algebra
Boolean Algebra
 
8051 Micro Controller
8051 Micro Controller 8051 Micro Controller
8051 Micro Controller
 
History of calculus and applications
History of calculus and applications History of calculus and applications
History of calculus and applications
 
Computational Complexity: Introduction-Turing Machines-Undecidability
Computational Complexity: Introduction-Turing Machines-UndecidabilityComputational Complexity: Introduction-Turing Machines-Undecidability
Computational Complexity: Introduction-Turing Machines-Undecidability
 
Module-1-Digital-and-Analog-Quantities-PROF (1).pdf
Module-1-Digital-and-Analog-Quantities-PROF (1).pdfModule-1-Digital-and-Analog-Quantities-PROF (1).pdf
Module-1-Digital-and-Analog-Quantities-PROF (1).pdf
 
Sequential circuit multiplier
Sequential circuit multiplierSequential circuit multiplier
Sequential circuit multiplier
 
Introduction to graph theory (All chapter)
Introduction to graph theory (All chapter)Introduction to graph theory (All chapter)
Introduction to graph theory (All chapter)
 
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
DESIGN AND IMPLEMENTATION OF LOW POWER ALU USING CLOCK GATING AND CARRY SELEC...
 
Chapter-4-Combinational Logic.pdf
Chapter-4-Combinational Logic.pdfChapter-4-Combinational Logic.pdf
Chapter-4-Combinational Logic.pdf
 
Logic gates ppt
Logic gates pptLogic gates ppt
Logic gates ppt
 
Bezier curve
Bezier curveBezier curve
Bezier curve
 
Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms Nature-Inspired Optimization Algorithms
Nature-Inspired Optimization Algorithms
 
Group Theory
Group TheoryGroup Theory
Group Theory
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
 
MPMC Microprocessor
MPMC MicroprocessorMPMC Microprocessor
MPMC Microprocessor
 
Numerical methods and its applications
Numerical methods and its applicationsNumerical methods and its applications
Numerical methods and its applications
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Programmers model of 8086
Programmers model of 8086Programmers model of 8086
Programmers model of 8086
 
Z80 microprocessor architecture1
Z80 microprocessor architecture1Z80 microprocessor architecture1
Z80 microprocessor architecture1
 

Ähnlich wie Introduction to Graphs

Representing and visiting graphs
Representing and visiting graphsRepresenting and visiting graphs
Representing and visiting graphsFulvio Corno
 
Graph Introduction.ppt
Graph Introduction.pptGraph Introduction.ppt
Graph Introduction.pptFaruk Hossen
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxasimshahzad8611
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptxARVIND SARDAR
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabatinabati
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - GraphMadhu Bala
 
Map Coloring and Some of Its Applications
Map Coloring and Some of Its Applications Map Coloring and Some of Its Applications
Map Coloring and Some of Its Applications MD SHAH ALAM
 
1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptxswapnilbs2728
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6DrkhanchanaR
 

Ähnlich wie Introduction to Graphs (20)

09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf09_DS_MCA_Graphs.pdf
09_DS_MCA_Graphs.pdf
 
Representing and visiting graphs
Representing and visiting graphsRepresenting and visiting graphs
Representing and visiting graphs
 
Graph Introduction.ppt
Graph Introduction.pptGraph Introduction.ppt
Graph Introduction.ppt
 
Graph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptxGraph terminology and algorithm and tree.pptx
Graph terminology and algorithm and tree.pptx
 
Spanningtreesppt
SpanningtreespptSpanningtreesppt
Spanningtreesppt
 
Graphs
GraphsGraphs
Graphs
 
Basics of graph
Basics of graphBasics of graph
Basics of graph
 
Graph ASS DBATU.pptx
Graph ASS DBATU.pptxGraph ASS DBATU.pptx
Graph ASS DBATU.pptx
 
Graphs.pptx
Graphs.pptxGraphs.pptx
Graphs.pptx
 
Graph theory concepts complex networks presents-rouhollah nabati
Graph theory concepts   complex networks presents-rouhollah nabatiGraph theory concepts   complex networks presents-rouhollah nabati
Graph theory concepts complex networks presents-rouhollah nabati
 
Data structure - Graph
Data structure - GraphData structure - Graph
Data structure - Graph
 
graph ASS (1).ppt
graph ASS (1).pptgraph ASS (1).ppt
graph ASS (1).ppt
 
Map Coloring and Some of Its Applications
Map Coloring and Some of Its Applications Map Coloring and Some of Its Applications
Map Coloring and Some of Its Applications
 
Chapter 1
Chapter   1Chapter   1
Chapter 1
 
1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx1. Graph and Graph Terminologiesimp.pptx
1. Graph and Graph Terminologiesimp.pptx
 
graph theory
graph theorygraph theory
graph theory
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Graphs.pdf
Graphs.pdfGraphs.pdf
Graphs.pdf
 
Graph theory
Graph theoryGraph theory
Graph theory
 
Unit 3 graph chapter6
Unit 3  graph chapter6Unit 3  graph chapter6
Unit 3 graph chapter6
 

Kürzlich hochgeladen

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEaurabinda banchhor
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxruthvilladarez
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsRommel Regala
 

Kürzlich hochgeladen (20)

MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Dust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSEDust Of Snow By Robert Frost Class-X English CBSE
Dust Of Snow By Robert Frost Class-X English CBSE
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
TEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docxTEACHER REFLECTION FORM (NEW SET........).docx
TEACHER REFLECTION FORM (NEW SET........).docx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
The Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World PoliticsThe Contemporary World: The Globalization of World Politics
The Contemporary World: The Globalization of World Politics
 

Introduction to Graphs

  • 1. Introduction to Graphs Tecniche di Programmazione – A.A. 2012/2013
  • 2. Summary A.A. 2012/2013Tecniche di programmazione2  Definition: Graph  Related Definitions  Applications
  • 4. Definition: Graph A.A. 2012/2013Tecniche di programmazione4  A graph is a collection of points and lines connecting some (possibly empty) subset of them.  The points of a graph are most commonly known as graph vertices, but may also be called “nodes” or simply “points.”  The lines connecting the vertices of a graph are most commonly known as graph edges, but may also be called “arcs” or “lines.” http://mathworld.wolfram.com/
  • 5. Big warning: Graph ≠ Graph ≠ Graph Graph (plot) (italiano: grafico) Graph (maths) (italiano: grafo) A.A. 2012/2013Tecniche di programmazione5 ≠ Graph (chart) (italiano: grafico)
  • 6. History A.A. 2012/2013Tecniche di programmazione6  The study of graphs is known as graph theory, and was first systematically investigated by D. König in the 1930s  Euler’s proof about the walk across all seven bridges of Königsberg (1736), now known as the Königsberg bridge problem, is a famous precursor to graph theory.  In fact, the study of various sorts of paths in graphs has many applications in real-world problems.
  • 7. Königsberg Bridge Problem A.A. 2012/2013Tecniche di programmazione7  Can the 7 bridges the of the city of Königsberg over the river Preger all be traversed in a single trip without doubling back, with the additional requirement that the trip ends in the same place it began? Today: Kaliningrad, Russia
  • 8. Königsberg Bridge Problem A.A. 2012/2013Tecniche di programmazione8  Can the 7 bridges the of the city of Königsberg over the river Preger all be traversed in a single trip without doubling back, with the additional requirement that the trip ends in the same place it began? Today: Kaliningrad, Russia
  • 9. Types of graphs: edge cardinality A.A. 2012/2013Tecniche di programmazione9  Simple graph:  At most one edge (i.e., either one edge or no edges) may connect any two vertices  Multigraph:  Multiple edges are allowed between vertices  Loops:  Edge between a vertex and itself  Pseudograph:  Multigraph with loops loop
  • 10. Types of graphs: edge direction A.A. 2012/2013Tecniche di programmazione10  Undirected  Oriented  Edges have one direction (indicated by arrow)  Directed  Edges may have one or two directions  Network  Oriented graph with weighted edges
  • 11. Types of graphs: labeling A.A. 2012/2013Tecniche di programmazione11  Labels  None  OnVertices  On Edges  Groups (=colors)  OfVertices  no edge connects two identically colored vertices  Of Edges  adjacent edges must receive different colors  Of both
  • 12. A.A. 2012/2013Tecniche di programmazione12 Directed and Oriented graphs  A Directed Graph (di-graph) G is a pair (V,E), where  V is a (finite) set of vertices  E is a (finite) set of edges, that identify a binary relationship overV  𝐸 ⊆ 𝑉 × 𝑉
  • 13. A.A. 2012/2013Tecniche di programmazione13 Example 4 1 5 6 2 3
  • 14. A.A. 2012/2013Tecniche di programmazione14 Example 4 1 5 6 2 3 Loop
  • 15. A.A. 2012/2013Tecniche di programmazione15 Example 4 1 5 6 2 3 V={1,2,3,4,5,6} E={(1,2), (2,2), (2,5), (5,4), (4,5), (4,1), (2,4), (6,3)}
  • 16. A.A. 2012/2013Tecniche di programmazione16 Undirected graph  Ad Undirected Graph is still represented as a couple G=(V,E), but the set E is made of non-ordered pairs of vertices
  • 17. A.A. 2012/2013Tecniche di programmazione17 Example 4 1 5 6 2 3 V={1,2,3,4,5,6} E={(1,2), (2,5), (5,1), (6,3)}
  • 18. A.A. 2012/2013Tecniche di programmazione18 Example 4 1 5 6 2 3 V={1,2,3,4,5,6} E={(1,2), (2,5), (5,1), (6,3)} Edge (1,5) adjacent (or incident) to vertices 1 and 5 Vertex 5 is adjacent to vertices 1 and 2 Vertex 4 is isolated
  • 20. A.A. 2012/2013Tecniche di programmazione20 Degree  In an undirected graph,  the degree of a vertex is the number of incident edges  In a directed graph  The in-degree is the number of incoming edges  The out-degree is the number of departing edges  The degree is the sum of in-degree and out-degree  A vertex with degree 0 is isolated
  • 21. A.A. 2012/2013Tecniche di programmazione21 Degree 4 1 5 6 2 3 2 2 20 1 1
  • 22. A.A. 2012/2013Tecniche di programmazione22 Degree 4 1 5 6 2 3 In: 1 Out: 1 In: 2 Out: 2 In: 1 or 2 Out: 2 or 3 In: 2 Out: 1 In: 1 Out: 0 In: 0 Out: 1
  • 23. Paths A.A. 2012/2013Tecniche di programmazione23  A path on a graph G=(V,E) also called a trail, is a sequence {v1, v2, …, vn} such that:  v1, …, vn are vertices: vi V  (v1, v2), (v2, v3), ..., (vn-1,vn) are graph edges: (vi-1,vi)  E  vi are distinct (for “simple” paths).  The length of a path is the number of edges (n-1)  If there exist a path between vA and vB we say that vB is reachable from vA
  • 24. A.A. 2012/2013Tecniche di programmazione24 Example 4 1 5 6 2 3 Path = { 1, 2, 5 } Length = 2
  • 25. A.A. 2012/2013Tecniche di programmazione25 Cycles  A cycle is a path where v1 = vn  A graph with no cycles is said acyclic
  • 26. A.A. 2012/2013Tecniche di programmazione26 Example 4 1 5 6 2 3 Path = { 1, 2, 5, 1 } Length = 3
  • 27. A.A. 2012/2013Tecniche di programmazione27 Reachability (Undirected)  An undirected graph is connected if, for every couple of vertices, there is a path connecting them  The connected sub-graph of maximum size are called connected components  A connected graph has exactly one connected component
  • 28. A.A. 2012/2013Tecniche di programmazione28 Connected components 4 1 5 6 2 3 The graph is not connected. Connected components = 3 { 4 } , { 1, 2, 5 }, { 3, 6 }
  • 29. A.A. 2012/2013Tecniche di programmazione29 Reachability (Directed)  A directed graph is strongly connected if, for every ordered pair of vertices (v, v’), there exists at least one path connecting v to v’
  • 30. A.A. 2012/2013Tecniche di programmazione30 Example 4 1 5 2 The graph is strongly connected
  • 31. A.A. 2012/2013Tecniche di programmazione31 Example 4 1 5 2 The graph is not strongly connected
  • 32. Complete graph A.A. 2012/2013Tecniche di programmazione32  A graph is complete if, for every pair of vertices, there is an edge connecting them (they are adjacent)  Symbol: Kn
  • 33. A.A. 2012/2013Tecniche di programmazione33 Complete graph: edges  In a complete graph with n vertices, the number of edges is  n(n-1), if the graph is directed  n(n-1)/2, if the graph is undirected  If self-loops are allowed, then  n2 for directed graphs  n(n-1) for undirected graphs
  • 34. Density A.A. 2012/2013Tecniche di programmazione34  The density of a graph G=(V,E) is the ration of the number of edges to the total number of edges 𝑑 = 𝐸 𝐺 𝐸 𝐾 𝑉(𝐺)
  • 35. A.A. 2012/2013Tecniche di programmazione35 Esempio 4 1 3 2 Density = 0.5 Existing: 3 edges Total: 6 possible edges
  • 36. A.A. 2012/2013Tecniche di programmazione36 Trees and Forests  An undirected acyclic graph is called forest  An undirected acyclic connected graph is called tree
  • 37. A.A. 2012/2013Tecniche di programmazione37 Example Tree
  • 38. A.A. 2012/2013Tecniche di programmazione38 Example Forest
  • 39. A.A. 2012/2013Tecniche di programmazione39 Example This is not a tree nor a forest (it contains a cycle)
  • 40. Rooted trees A.A. 2012/2013Tecniche di programmazione40  In a tree, a special node may be singled out  This node is called the “root” of the tree  Any node of a tree can be the root
  • 41. Tree (implicit) ordering A.A. 2012/2013Tecniche di programmazione41  The root node of a tree induces an ordering of the nodes  The root is the “ancestor” of all other nodes/vertices  “children” are “away from the root”  “parents” are “towards the root”  The root is the only node without parents  All other nodes have exactly one parent  The furthermost (children-of-children-of-children…) nodes are “leaves”
  • 42. A.A. 2012/2013Tecniche di programmazione42 Example Rooted Tree
  • 43. A.A. 2012/2013Tecniche di programmazione43 Example Rooted Tree
  • 44. A.A. 2012/2013Tecniche di programmazione44 Weighted graphs  A weighted graph is a graph in which each branch (edge) is given a numerical weight.  A weighted graph is therefore a special type of labeled graph in which the labels are numbers (which are usually taken to be positive).
  • 46. Graph applications A.A. 2012/2013Tecniche di programmazione46  Graphs are everywhere  Facebook friends (and posts, and ‘likes’)  Football tournaments (complete subgraphs + binary tree)  Google search index (V=page, E=link, w=pagerank)  Web analytics (site structure, visitor paths)  Car navigation (GPS)  Market Matching
  • 47. Market matching A.A. 2012/2013Tecniche di programmazione47  H = Houses (1, 2, 3, 4)  B = Buyers (a, b, c, d)  V = H  B  Edges: (h, b)  E if b would like to buy h  Problem: can all houses be sold and all buyers be satisfied?  Variant: if the graph is weighted with a purchase offer, what is the most convenient solution?  Variant: consider a ‘penalty’ for unsold items This graph is called “bipartite”: H  B = 
  • 48. Connecting cities A.A. 2012/2013Tecniche di programmazione48  We have a water reservoir  We need to serve many cities  Directly or indirectly  What is the most efficient set of inter-city water connections?  Also for telephony, gas, electricity, … We are searching for the “minimum spanning tree”
  • 49. Google Analytics (Visitors Flow) A.A. 2012/2013Tecniche di programmazione49
  • 50. Customer behavior A.A. 2012/2013Tecniche di programmazione50 User actions encoded as frequencies
  • 51. Street navigation A.A. 2012/2013Tecniche di programmazione51 We must find a “Hamiltonian cycle” TSP:The traveling salesman problem
  • 52. Train maps A.A. 2012/2013Tecniche di programmazione52
  • 53. Chemistry (Protein folding) A.A. 2012/2013Tecniche di programmazione53
  • 55. A.A. 2012/2013Tecniche di programmazione55 Flow chart BEGIN END
  • 56. Resources A.A. 2012/2013Tecniche di programmazione56  Maths Encyclopedia: http://mathworld.wolfram.com/  Basic GraphTheory with Applications to Economics http://www.isid.ac.in/~dmishra/mpdoc/lecgraph.pdf  Application of GraphTheory in real world http://prezi.com/tseh1wvpves-/application-of-graph-theory- in-real-world/  JGraphT Library: http://jgrapht.org/
  • 57. Licenza d’uso A.A. 2012/2013Tecniche di programmazione57  Queste diapositive sono distribuite con licenza Creative Commons “Attribuzione - Non commerciale - Condividi allo stesso modo (CC BY-NC-SA)”  Sei libero:  di riprodurre, distribuire, comunicare al pubblico, esporre in pubblico, rappresentare, eseguire e recitare quest'opera  di modificare quest'opera  Alle seguenti condizioni:  Attribuzione — Devi attribuire la paternità dell'opera agli autori originali e in modo tale da non suggerire che essi avallino te o il modo in cui tu usi l'opera.  Non commerciale — Non puoi usare quest'opera per fini commerciali.  Condividi allo stesso modo — Se alteri o trasformi quest'opera, o se la usi per crearne un'altra, puoi distribuire l'opera risultante solo con una licenza identica o equivalente a questa.  http://creativecommons.org/licenses/by-nc-sa/3.0/