0% found this document useful (0 votes)
50 views

LECTURE NOTES 1 - Introduction To Graphs To Post

The document provides an overview of graph theory, including its history stemming from Euler's solving of the Königsberg bridge problem in 1736. It then discusses basic graph theory concepts like vertices, edges, paths and cycles. The document outlines several applications of graph theory such as modeling transportation, computer, electrical and other networks. It also provides examples of using graph theory to model scheduling problems, social networks and genetic regulatory networks.

Uploaded by

Ceass Ass
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

LECTURE NOTES 1 - Introduction To Graphs To Post

The document provides an overview of graph theory, including its history stemming from Euler's solving of the Königsberg bridge problem in 1736. It then discusses basic graph theory concepts like vertices, edges, paths and cycles. The document outlines several applications of graph theory such as modeling transportation, computer, electrical and other networks. It also provides examples of using graph theory to model scheduling problems, social networks and genetic regulatory networks.

Uploaded by

Ceass Ass
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Graph Theory

Basic Concepts

DR Karanja
1
Graph Theory - History
Leonhard Euler's paper on
“Seven Bridges of
Königsberg” ,
published in 1736.

02/15/11 2
Bridges of Königsberg

 Is it possible to cross all of


the bridges in the city
without crossing a single
bridge twice?

02/15/11 3
Bridges of Königsberg

 Is it possible to cross all of


the bridges in the city
without crossing a single
bridge twice?
 Euler realised that
this problem could
be represented as
a graph

4
Bridges of Königsberg

 Does this graph have a path


covering every edge without
duplicates? (a Euler walk)
 In order to have such a path,
the graph must have either
zero or two nodes with an odd
number of edges
 It has four, therefore no

5
Famous problems
 “The traveling salesman problem”
 A traveling salesman is to visit a number of cities; how
to plan the trip so every city is visited once and just
once and the whole trip is as short as possible ?

6
Famous problems
In 1852 Francis Guthrie posed the “four color
problem” which asks if it is possible to color,
using only four colors, any map of countries in
such a way as to prevent two bordering
countries from having the same color.

This problem, which was only solved a century


later in 1976 by Kenneth Appel and Wolfgang
Haken, can be considered the birth of graph
theory.
7
Graphs – Basic Concepts
 Basic definitions: vertices and edges
 More definitions: paths, simple paths, cycles,
loops
 Connected and disconnected graphs
 Spanning trees
 Complete graphs
 Weighted graphs and networks
 Graph representation
 Adjacency matrix
 Adjacency lists

8
What is a graph?

 A graph consists of a set of Node Node

nodes and a set of edges that


connect the nodes Edge

 That’s (almost) it
 also directedness, parallel
edges, self-connection,
weighted edges, node values…

Graph
02/15/11 KARANJA EVANS 9
Why are graphs useful?
 The structure of relationships between
system elements provides information about
system properties
 Bridges of Königsberg – the graph structure
demonstrated the lack of the property in
question
 Small world networks – the way in which the
desired property was obtained informed
understanding of the network structure

10
Structures and structural metrics
 Graph structures are used to isolate
interesting or important sections of a graph
 Structural metrics provide a measurement of
a structural property of a graph
 Global metrics refer to a whole graph
 Local metrics refer to a single node in a graph

11
Graph structures
 Identify interesting sections of a graph
 Interesting because they form a significant
domain-specific structure, or because they
significantly contribute to graph properties
 A subset of the nodes and edges in a graph
that possess certain characteristics, or relate
to each other in particular ways
 i.e., a subgraph

12
Some applications of Graph Theory
 Models for communications and electrical
networks
 Models for computer architectures
 Network optimization models for operations
analysis, including scheduling and job
assignment
 Analysis of Finite State Machines
 Parsing and code optimization in compilers

13
Application Examples
 Cost of wiring electronic components
 Shortest route between two cities.
 Shortest distance between all pairs of cities in
a road atlas.
 Matching / Resource Allocation
 Visibility / Coverage

14
more application Examples
 Flow of material
 liquid flowing through pipes
 current through electrical networks
 information through communication networks
 parts through an assembly line

 In Operating systems to model resource


handling (deadlock problems)
 In compilers for parsing and optimizing the
code.

15
Task scheduling

 Lectures to be scheduled ….. Rooms sizes..


Location .. Materials (labs )… timing ….
Student and lecturer availability ….

KARANJA EVANS 16
Scheduling Example

 Lectures need to be assigned classrooms at


University Lecture BIT 115: 9:00-10:15
 Lecture BIT 3203: 10:00-12:00
 etc.
 Conflicting lectures Different rooms
 How many rooms?

17
Scheduling Example (cont.)

18
more examples: Friends of friends
 Social experiments have demonstrated that
the world is a small place after all
 There is a high probability of you having an
indirect connection, through a small number of
friends, to a total stranger
 In fact, it is postulated that a connection can
be drawn between two random people in a
very small number (<6) of links

19
Friends of friends

 In a social network, a
common default
assumption was that
connections were
localised
 Distant nodes take many
links to reach

02/15/11 KARANJA EVANS 20


Friends of friends

 Watts and Strogatz


showed that randomly
rewiring only a few links in
such a network
dramatically reduced the
number of links between
distant nodes
 Small-world networks

21
Communities

Social Networks Metabolic Networks


22
Application to Ad Hoc Networking
 Networks can be represented by graphs
 The mobile nodes are vertices
 The communication links are edges

Vertices

Edges

• Routing protocols often use shortest path algorithms


• This lecture is background material to the routing algorithms

02/15/11 KARANJA EVANS 23


Graphs ↔ Networks
Graph Vertexes Edges Flow
(Network) (Nodes) (Arcs)
Communications Telephones exchanges, Cables, fiber optics, Voice, video,
computers, satellites microwave relays packets

Circuits Gates, registers, Wires Current


processors
Mechanical Joints Rods, beams, springs Heat, energy

Hydraulic Reservoirs, pumping Pipelines Fluid, oil


stations, lakes
Financial Stocks, currency Transactions Money

Transportation Airports, rail yards, Highways, railbeds, Freight,


street intersections airway routes vehicles,
passengers
02/15/11 KARANJA EVANS 24
Elementary Concepts
 A graph G(V,E) is two sets of object
 Vertices (or nodes) , set V
 Edges, set E

 A graph is represented with dots or circles


(vertices) joined by lines (edges)
 The magnitude of graph G is characterized by
number of vertices |V| (called the order of G) and
number of edges |E| (size of G)
 The running time of algorithms are measured in
terms of the order and size
02/15/11 KARANJA EVANS 25
What is graph theory?
 Graph theory provides a set of techniques for
analysing graphs
 Complex systems graph theory provides
techniques for analysing structure in a system
of interacting agents, represented as a graph
 Applying graph theory to a system means
using a graph-theoretic representation

26
What makes a problem graph-like?
 There are two components to a graph
 Nodes and edges
 In graph-like problems, these components
have natural correspondences to problem
elements
 Entities are nodes and interactions between
entities are edges
 Most complex systems are graph-like

02/15/11 KARANJA EVANS 27


Examples of complex systems
 Social networks
 Nodes are actors,
edges are relationships

The social network


for the #java IRC
channel
02/15/11 KARANJA EVANS 28
Examples of complex systems

 Genetic regulatory networks


 Nodes are genes or
proteins, edges are regulatory
interactions

The p53 cancer network 29


Examples of complex systems

 Transportation networks
 Nodes are cities, transfer
points or depots, edges are
roads or transport routes
SEE THIS FOR DETAILED NAIROBI MAP
http://www.traveldodo.com/webmaster/ken
ya/nairobi/
OR GO TO
http://kijabe.org/nairobi/nbimap.gif

30
ROUTING IN NAIROBI
http://kijabe.org/nairobi/nbimap.gif
.

31
Basic Graph Definitions
A graph is a mathematical object that is used to
model different situations – objects and processes:
Linked list
Tree (partial instance of graph)
Flowchart of a program
City map
Electric circuits
Course curriculum 32
Vertices and Edges

Definition: A graph is a collection (nonempty set)


of vertices and edges
Vertices: can have names and properties
Edges: connect two vertices,
can be labeled,
can be directed
Adjacent vertices: there is an edge between
them 33
Degree of a Vertex
Degree of a vertex in an undirected graph is the number of edges
incident on it. In a directed graph, the out degree of a vertex is the
number of edges leaving it and the in degree is the number of edges
entering it

2 2

3 3
1 1

4 4

The degree of vertex 2 is 3 The in degree of vertex 2 is 2 and


the in degree of vertex 4 is 1
34
Example
Graph1

Vertices: A,B,C,D
Edges: AB, AC, BC, CD
C
A B

A
B
C
D D

Two ways to draw the same graph


35
Directed and undirected
graphs
Graph2 Graph3

A B A B

C C

D D

These
02/15/11 are two different KARANJA
graphs EVANS 36
More definitions : Path

A list of vertices in which successive


vertices are connected by edges

ABC A B
BACD
ABCABCABCD
BABAC C
D
37
More definitions :
Simple Path

No vertex is repeated.

ABCD
A B
D CA
DCB
AB
C
ABC D
02/15/11 KARANJA EVANS 38
More definitions : Cycle

Simple path with distinct edges, except


that the first vertex is equal to the last

A B
ABCA
BACB
CBAC
C
D
A graph without cycles is called acyclic graph. 39
More definitions : Loop

An edge that connects the vertex with itself

A B

C
D
40
Walks and Paths …in summary
V2 3
V3
1
2
V1 3
1
V6
4
4

V4 1 V5
A walk is an sequence of nodes (v1, v2,..., vL) such that

{(v1, v2), (v1, v2),..., (v1, v2)} E, e.g. (V2, V3,V6, V5,V3)

A simple path is a walk with no repeated nodes,


e.g. (V1, V4,V5, V2,V3)

A cycle is an walk (v1, v2,..., vL) where v1=vL with no other nodes
repeated and L>3, e.g. (V1, V2,V5, V4,V1)

A graph is called cyclic if it contains a cycle; otherwise it is called 41


acyclic
Connected and Disconnected
graphs
Connected graph: There is a path between each
two vertices

Disconnected graph : There are at least two


vertices not connected by a path.
Examples of disconnected graphs:
A B A B

C
C D
D 42
Graphs and Trees

Tree: an undirected graph with no cycles,


and a node chosen to be the root
A B

Source graph:

C D

E
43
Graphs and Trees
A
C

C
A
B
E
E B

D
Tree1: root A Tree2: root C
D
44
A spanning tree of an
undirected graph
A sub-graph that contains all the vertices, and no cycles.

If we add any edge to the spanning tree, it forms a cycle, and


the tree becomes a graph

A B A B
graph

spanning tree
C C
D D 45
Examples
A B A B

C D C D

A B
All spanning trees
of the graph on
the previous slide
C D
46
Complete graphs
Graphs with all edges present – each vertex is
connected to all other vertices

A B
Dense graphs:
relatively few of
the possible
edges are
C
D missing
Sparse graphs:
E relatively few of
the possible
edges are
A complete graph present 47
Weighted graphs and
Networks
Weighted graphs – weights are assigned to each
edge (e.g. road map)
Networks: directed weighted graphs (some theories
allow networks to be undirected)

B 2
1
C
A 2
4
3
D
48
Graph Representation

 Adjacency matrix
 Adjacency lists

49
Adjacency matrix – undirected
graphs
Vertices: A,B,C,D
Edges: AC, AB, AD, BD
The matrix is symmetrical
A B
A B C D
A 0 1 1 1
B 1 0 0 1
C
C 1 0 0 1
D 1 1 0 0 D

50
Adjacency matrix – directed
graphs
Vertices: A,B,C,D
Edges: AC, AB, BD, DA

A B C D A B

A 0 1 1 0
B 0 0 0 1
C 0 0 0 0 C

D 1 0 0 0 D

02/15/11 KARANJA EVANS 51


Adjacency lists – undirected
graphs
Vertices: A,B,C,D
Edges: AC, AB, AD, BD

Heads lists A B

A BCD
B AD C

C A D
D AB 52
Adjacency lists – directed
graphs
Vertices: A,B,C,D
Edges: AC, AB, BD, DA

A B
Heads lists
A BC
B D C
C =
D
D A
53
SOLVING GRAPH PROBLEMS

 REQUIRE ….. THINKING SMART …. TO


GET OPTIMAL SOLUTIONS …. HERE ARE
SOME BASIC PROBLEMS …..

54
…A Mystery in the Library

Six Scholars had been to the library on the day


that the rare book was stolen.
Each had entered once, stayed for some time
and then left.
If two were in the library at the same time, then
at least one of them saw the other.

Detectives questioned the Scholars and


gathered the following testimony:
55
The Facts:

 Abe said that he saw Burt and Eddie


 Burt reported that he saw Abe and Ida
 Charlotte claimed to have seen
Desmond and Ida
 Desmond said that he saw Abe and Ida
 Eddie testified to seeing Burt and Charlotte
 Ida said that she saw Charlotte and Eddie

One of the Scholars LIED !! Who was it?


56
Solving the Mystery

The Testimony Graph

Clue #1:
Double arrows imply TRUTH

57
Solving the Mystery
Undirected Testimony Graph

cycle

We know there is a lie, since {A, B, I, D} is a chordless 4-cycle.


58
Intersecting Intervals cannot form
Chordless Cycles

Burt Desmond

Abe

No place for Ida’s interval:


It must hit both B and D but cannot hit A.
Impossible!

59
Solving the Mystery
One Scholars from the chordless 4-cycle must be a liar.

There are three chordless 4-cycles:


{A, B, I, D} {A, D, I, E} {A, E, C, D}

Burt is NOT a liar: He is missing from the second


cycle.
Ida is NOT a liar: She is missing from the third
cycle. Charlotte is NOT a liar: She is missing from
the second. Eddie is NOT a liar: He is missing
from the first cycle.

WHO IS THE LIAR? Abe or Desmond ? 60


Solving the Mystery (cont.)
WHO IS THE LIAR? Abe or Desmond ?

If Abe were the liar and Desmond truthful,


then {A, B, I, D} would remain a chordless 4-cycle,
since B and I are truthful.

Therefore:

Desmond is the liar.


61
Was Desmond Stupid or
Just Ignorant?

If Desmond had studied algorithmic graph theory,


he would have known that his testimony to the
police would not hold up.

62
62
2. Nine Dot Problem
Draw no more than 4 straight lines (without lifting the pencil from the paper)
that cross through all nine dots

• • •

• • •

• • •
63
6 Matches Problem

Can yo
u m
ake 4qu
eilat
eral
tria
ngle
s?
64
Duncker’s Candle Problem
Duncker (1945) gave participants a candle, a box of
thumbtacks, and a book of matches, and asked them to
attach the candle to the wall so that it did not drip onto the
table below

65
Duncker’s Candle Problem
Solution is here

66
67

You might also like