0% found this document useful (0 votes)
8 views105 pages

Graphs Etc

Uploaded by

drokz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views105 pages

Graphs Etc

Uploaded by

drokz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 105

Today

The mathematical underpinning of networks: graph


theory
• Nodes and links
• Adjacency matrix
• Common types of graphs

1
Announcements
• Homework 1 is now available online.
• It is due on Monday.

• Please don’t forget to post an introduction to the


discussion thread on Orbund.
• For those of you who have done so already, look
back over the thread and think about who you
would like to form a group with.

2
Python
• Python is a programming language
• There are lots of ways to use it on your computer,
in the same way that there are lots of ways to
access Netflix - via your phone, your TV, on a
laptop with Chrome, on a desktop with Firefox,
etc.
• (Note: We’re going to use Python 3.)

3
How you might want to use Python
Two main options:
1. Download and install the Anaconda scientific
computing distribution, which comes with the
program Spyder for doing Python coding.
2. Use an online Python interpreter such as
https://repl.it/languages/python3
But you can do whatever works for you. There are
lots of other IDEs or online interpreters, or maybe
you’re hardcore and don’t even want an IDE?

4
What is a graph?
A graph is a mathematical object consisting of
nodes and links between the nodes.

5-1
What is a graph?
A graph is a mathematical object consisting of
nodes and links between the nodes.
Nodes are sometimes called vertices (singular:
vertex) and links are sometimes called edges.

5-2
What is a graph?
A graph is a mathematical object consisting of
nodes and links between the nodes.
Nodes are sometimes called vertices (singular:
vertex) and links are sometimes called edges.

5-3
Why is it called a graph?
• ‘Graph’ is a strange name as we usually associate
that word with pictures (e.g. a scatterplot).
• The term originally comes from graphs of chemical
molecules!
• It’s been suggested that ‘network’ would be a
better word!
• We’re stuck with the terminology that we have,
though.

6
These are all the same graph

7-1
These are all the same graph

7-2
These are all the same graph

7-3
These are all the same graph

7-4
These are all the same graph

7-5
These are all the same number
• FOUR • 4
• 4 • 22
• 4 • 7−3
• IV • dπe
• cuatro • 1002
• “the smallest composite
number”

8
Representing graphs
The only important parts of the structure of a graph
are the nodes and the links.

9-1
Representing graphs
The only important parts of the structure of a graph
are the nodes and the links.
A B

C D

9-2
Representing graphs
The only important parts of the structure of a graph
are the nodes and the links.
A B The adjacency matrix
A B C D
A 0 1 1 0
C D
B 1 0 1 0
C 1 1 0 1
D 0 0 1 0

9-3
Representing graphs
The only important parts of the structure of a graph
are the nodes and the links.
A B The adjacency matrix
A B C D
A 0 1 1 0
C D
B 1 0 1 0
1: a link exists C 1 1 0 1
0: no link D 0 0 1 0

9-4
Isomorphism
These graphs are all isomorphic with
each other. They have the same
adjacency matrix.

10 - 1
Isomorphism
These graphs are all isomorphic with
each other. They have the same
adjacency matrix.

A B C D E
A 0 1 0 0 0
B 1 0 1 1 0
C 0 1 0 1 0
D 0 1 1 0 1
E 0 0 0 1 0
10 - 2
Beyond the ‘simple graph’
• Everything so far has been ‘simple graphs’.
• (This is a technical term.)
• By thinking about ways to modify the adjacency
matrix we can come up with other kinds of graph
phenomena.
• Namely:
– Self-loops
– Multiple links
– Weighted links
– Directed links

11
What if...
What if we have ‘1’ one of the diagonal cells?

12 - 1
What if...
What if we have ‘1’ one of the diagonal cells?
The adjacency matrix
A B C D
A 1 1 1 0
B 1 0 1 0
C 1 1 0 1
D 0 0 1 0

12 - 2
What if...
What if we have ‘1’ one of the diagonal cells?
The adjacency matrix
A B A B C D
A 1 1 1 0
B 1 0 1 0
C D C 1 1 0 1
D 0 0 1 0
We get a (self-)loop!
This graph is called a simple graph with loops.

12 - 3
What if...
What if we have numbers bigger than one?

13 - 1
What if...
What if we have numbers bigger than one?
The adjacency matrix
A B C D
A 0 2 1 0
B 2 0 1 0
C 1 1 0 3
D 0 0 3 0

13 - 2
What if...
What if we have numbers bigger than one?
The adjacency matrix
A B A B C D
A 0 2 1 0
B 2 0 1 0
C D C 1 1 0 3
D 0 0 3 0
We get multiple (or parallel) links!
This kind of graph is called a multigraph.

13 - 3
What if...
What if we have numbers that aren’t integers?

14 - 1
What if...
What if we have numbers that aren’t integers?
The adjacency matrix
A B C D
A 0 1 0.5 0
B 1 0 1 0
C 0.5 1 0 2.3
D 0 0 2.3 0

14 - 2
What if...
What if we have numbers that aren’t integers?
The adjacency matrix
A 1 B A B C D
A 0 1 0.5 0
0.5 1 B 1 0 1 0
C 2.3 D C 0.5 1 0 2.3
D 0 0 2.3 0
We get weighted links!
This kind of graph is called a weighted graph.

14 - 3
What if...
What if the adjacency matrix is not symmetrical?

15 - 1
What if...
What if the adjacency matrix is not symmetrical?
The adjacency matrix
A B C D
A 0 1 1 0
B 1 0 0 0
C 0 1 0 0
D 0 0 1 0

15 - 2
What if...
What if the adjacency matrix is not symmetrical?
The adjacency matrix
A B A B C D
A 0 1 1 0
B 1 0 0 0
C D C 0 1 0 0
D 0 0 1 0
We get directed links!
This kind of graph is called a directed graph.

15 - 3
What if...
What if we wanted a directed multigraph with loops?

16 - 1
What if...
What if we wanted a directed multigraph with loops?
The adjacency matrix
A B C D
A 2 1 1 0
B 3 0 0 0
C 0 1 0 0
D 0 0 3 0

16 - 2
What if...
What if we wanted a directed multigraph with loops?
The adjacency matrix
A B A B C D
A 2 1 1 0
B 3 0 0 0
C D C 0 1 0 0
D 0 0 3 0

16 - 3
What kinds of graphs would we use for
these networks?
• Facebook friendships
• Instagram/twitter friends
• Food web
• Electric grid
• Co-authorship network
• OT constraint ranking
• Semantic similarity
• ... what other kinds of
networks can you think of?

17 - 1
What kinds of graphs would we use for
these networks?
• Facebook friendships • Simple graph
• Instagram/twitter friends
• Food web
• Electric grid
• Co-authorship network
• OT constraint ranking
• Semantic similarity
• ... what other kinds of
networks can you think of?

17 - 2
What kinds of graphs would we use for
these networks?
• Facebook friendships • Simple graph
• Instagram/twitter friends • Directed graph
• Food web
• Electric grid
• Co-authorship network
• OT constraint ranking
• Semantic similarity
• ... what other kinds of
networks can you think of?

17 - 3
What kinds of graphs would we use for
these networks?
• Facebook friendships • Simple graph
• Instagram/twitter friends • Directed graph
• Food web • Directed graph with loops
• Electric grid
• Co-authorship network
• OT constraint ranking
• Semantic similarity
• ... what other kinds of
networks can you think of?

17 - 4
What kinds of graphs would we use for
these networks?
• Facebook friendships • Simple graph
• Instagram/twitter friends • Directed graph
• Food web • Directed graph with loops
• Electric grid • Multigraph
• Co-authorship network
• OT constraint ranking
• Semantic similarity
• ... what other kinds of
networks can you think of?

17 - 5
What kinds of graphs would we use for
these networks?
• Facebook friendships • Simple graph
• Instagram/twitter friends • Directed graph
• Food web • Directed graph with loops
• Electric grid • Multigraph
• Co-authorship network • Multigraph
• OT constraint ranking
• Semantic similarity
• ... what other kinds of
networks can you think of?

17 - 6
What kinds of graphs would we use for
these networks?
• Facebook friendships • Simple graph
• Instagram/twitter friends • Directed graph
• Food web • Directed graph with loops
• Electric grid • Multigraph
• Co-authorship network • Multigraph
• OT constraint ranking • Directed graph
• Semantic similarity
• ... what other kinds of
networks can you think of?

17 - 7
What kinds of graphs would we use for
these networks?
• Facebook friendships • Simple graph
• Instagram/twitter friends • Directed graph
• Food web • Directed graph with loops
• Electric grid • Multigraph
• Co-authorship network • Multigraph
• OT constraint ranking • Directed graph
• Semantic similarity • Simple or weighted graph
• ... what other kinds of
networks can you think of?

17 - 8
What are your questions?

18
Common graph concepts and kinds of
graphs
Concepts Graph types
• Components • Disconnected graphs
• Paths • Trees
• Cyclicity • Planar graphs

19
Connected and disconnected graphs
connected

20 - 1
Connected and disconnected graphs
disconnected

20 - 2
Connected and disconnected graphs
disconnected

these are
components

20 - 3
Connected and disconnected graphs
disconnected Definition: A
connected graph
has only one
component

these are
components

20 - 4
Path
• In 1739, Leonard Euler
wanted to know if it was
possible to do a walking
tour of Königsberg.
• This tour would cross
each bridge once and
only once. Image credit: Wikipedia
• Is this possible?

21
The seven bridges of Königsberg
If we exhaustively list out all possible paths, we will
find that it this tour is impossible.

22 - 1
The seven bridges of Königsberg
If we exhaustively list out all possible paths, we will
find that it this tour is impossible.
Can we solve this without trial and error, though?

22 - 2
The seven bridges of Königsberg
If we exhaustively list out all possible paths, we will
find that it this tour is impossible.
Can we solve this without trial and error, though?

22 - 3
Alternative reality Königsbergs, 1
Euler’s walk: impossible

23 - 1
Alternative reality Königsbergs, 1
Euler’s walk: impossible If we destroy some
bridges...

Possible:

23 - 2
Alternative reality Königsbergs, 1
Euler’s walk: impossible If we destroy some
bridges...

Possible:

Impossible:

23 - 3
Alternative reality Königsbergs, 2
Euler’s walk: impossible

24 - 1
Alternative reality Königsbergs, 2
Euler’s walk: impossible If we build some
bridges...

Possible:

24 - 2
Alternative reality Königsbergs, 2
Euler’s walk: impossible If we build some
bridges...

Possible:

Impossible:

24 - 3
The solution
• Euler noticed a pattern relating to the degree of
each node.
• A node’s degree is how many links it has.

25 - 1
The solution
• Euler noticed a pattern relating to the degree of
each node.
• A node’s degree is how many links it has.
3

5 3

25 - 2
The solution
• Euler noticed a pattern relating to the degree of
each node.
• A node’s degree is how many links it has.
All of our graphs which allow Euler walks have 0 or
2 nodes with odd degree. 4
2

4 2 5 3

2 4

25 - 3
The solution
• Euler noticed a pattern relating to the degree of
each node.
• A node’s degree is how many links it has.
All of our graphs which allow Euler walks have 0 or
2 nodes with odd degree. 4
2

4 2 5 3

2 4
All of the graphs which disallow Euler walks
are either disconnected or have more than 2
nodes with odd degree.
25 - 4
The intuition
• It is impossible to visit all the nodes on a
disconnected graph!

26 - 1
The intuition
• It is impossible to visit all the nodes on a
disconnected graph!
• If a node has an odd number of links,
• Then that node must be the beginning or the end
of the tour.
• (Every time you enter a node, you need another
link to be able to leave it — you need an even
number.)

26 - 2
The intuition
• It is impossible to visit all the nodes on a
disconnected graph!
• If a node has an odd number of links,
• Then that node must be the beginning or the end
of the tour.
• (Every time you enter a node, you need another
link to be able to leave it — you need an even
number.)
• You can only have one beginning and one end, so
having more than two nodes of odd degree makes
the route impossible.

26 - 3
Modern Königsberg (Kaliningrad)

27 - 1
Modern Königsberg (Kaliningrad)

27 - 2
Modern Königsberg (Kaliningrad)

27 - 3
Modern Königsberg (Kaliningrad)

27 - 4
Paths and cycles
• Often we’re interested in the shortest path
between two nodes,
• or the longest path that doesn’t use any link more
than once,
• or something like that.

28 - 1
Paths and cycles
• Often we’re interested in the shortest path
between two nodes,
• or the longest path that doesn’t use any link more
than once,
• or something like that.
• A cycle is a path that uses each link only once
and starts and ends on the same nodes.
• A graph with a cycle is a cyclic graph; a graph
without is an acyclic graph.

28 - 2
Trees
• Every linguist loves a good tree.
• In graph theory, a tree is any connected
undirected acyclic graph.

29 - 1
Trees
• Every linguist loves a good tree.
• In graph theory, a tree is any connected
undirected acyclic graph.

29 - 2
Trees
• Every linguist loves a good tree.
• In graph theory, a tree is any connected
undirected acyclic graph.

29 - 3
Trees
• Every linguist loves a good tree.
• In graph theory, a tree is any connected
undirected acyclic graph.

29 - 4
Trees
• Every linguist loves a good tree.
• In graph theory, a tree is any connected
undirected acyclic graph.

29 - 5
Trees, continued
• Another way to think about trees:
• For any pair of nodes, there is exactly one possible
path between them
• (Add or remove a single link anywhere and it will
cease to be a tree!)

30 - 1
Trees, continued
• Another way to think about trees:
• For any pair of nodes, there is exactly one possible
path between them
• (Add or remove a single link anywhere and it will
cease to be a tree!)
• In cyclic graphs there are multiple possible paths
A B From A to C:
• A—C
C • A—B—C

30 - 2
Trees, continued
• Another way to think about trees:
• For any pair of nodes, there is exactly one possible
path between them
• (Add or remove a single link anywhere and it will
cease to be a tree!)
• In disconnected graphs there are no possible paths
between some nodes
A B No path possible from A to C!

30 - 3
Trees, continued
• Another way to think about trees:
• For any pair of nodes, there is exactly one possible
path between them
• (Add or remove a single link anywhere and it will
cease to be a tree!)
• In trees there is exactly one path between any pair
of nodes
A B From A to C:
• A—B—C
C

30 - 4
Planar graphs
• Can we draw graphs without crossing any links?

31 - 1
Planar graphs
• Can we draw graphs without crossing any links?

31 - 2
Planar graphs
• Can we draw graphs without crossing any links?

31 - 3
Planar graphs
• Can we draw graphs without crossing any links?

31 - 4
Planar graphs
• Can we draw graphs without crossing any links?

31 - 5
Planar graphs
• Can we draw graphs without crossing any links?

This is impossible,
unfortunately.

31 - 6
Planar graphs, continued
• A planar graph is one that can be drawn on a 2
dimensional surface with no links crossing each
other.
• (I.e. it can be drawn on a ‘plane’ surface.)

32 - 1
Planar graphs, continued
• A planar graph is one that can be drawn on a 2
dimensional surface with no links crossing each
other.
• (I.e. it can be drawn on a ‘plane’ surface.)

• Several real-world graph applications are planar


• E.g. circuit board design, water pipe layout
• E.g. graphs representing physical maps (such as
the counties of California)
• However, most complex networks are non-planar

32 - 2
What are your questions?

33
Graphs as sets
• The adjacency matrix is, for many practical
purposes, the most useful representation of a
graph.
• Some mathematicians prefer a set representation,
however.

34 - 1
Graphs as sets
• The adjacency matrix is, for many practical
purposes, the most useful representation of a
graph.
• Some mathematicians prefer a set representation,
however.
• A set is a collection of things (usually other sets).
• A graph G is usually considered to consist of
{V, E}
• V is the set of vertices (nodes) and E is the set
of edges (links).

34 - 2
Examples of graphs as sets
A B

C D
V = {A, B, C, D}
E = {{A, B}, {A, C}, {B, C}, {C, D}}

35 - 1
Examples of graphs as sets
A B

C D
V = {A, B, C, D}
E = {{A, B}, {A, C}, {B, C}, {C, D}}

The elements of a set have no intrinsic order so


{A, B} is the same as {B, A}.

35 - 2
Common classes of graphs in math
• Graph theorists like to have a common vocabulary
for sets of simple graphs.
• These graphs aren’t all that common as networks
in the real world, but they’re often used in
describing network measures or descriptions.
• I’m listing them here as a useful reference.

36
Null graphs, Nv
Nv has v nodes and no links.

N1
N2 N4
N3

37
Complete graphs, Kv
Kv has v nodes and every possible link between each
node.

K1
K2 K3 K4

K5 K6

38 - 1
Complete graphs, Kv
Kv has v nodes and every possible link between each
node.

K1
K2 K3 K4

K5 K6

(Note that N1 = K1 )

38 - 2
Path graphs, Pv
Pv has the set of nodes {1, 2, 3, ..., v} and edge set
{{1, 2}, {2, 3}, {3, 4}, ..., {(v − 1), v}}.
(It’s a line.)

P3
P4 P5 P6

39
Circle graphs, Cv
Cv has the set of nodes {1, 2, 3, ..., v} and edge set
{{1, 2}, {2, 3}, {3, 4}, ..., {(v − 1), v}, {v, 1}}.
(It’s a circle.)

C1 and C2 are not defined.

C3
C4 C5 C6

40 - 1
Circle graphs, Cv
Cv has the set of nodes {1, 2, 3, ..., v} and edge set
{{1, 2}, {2, 3}, {3, 4}, ..., {(v − 1), v}, {v, 1}}.
(It’s a circle.)

C1 and C2 are not defined.

C3
C4 C5 C6

(Note that K3 = C3 )

40 - 2
What are your questions?

41
Summary / list of terms
• Node (vertex) • Tree
• Link (edge) • Multigraph
• Isomorphism • Planar graph
• Directed / undirected • Complete graph
• Weighting • Null graph
• Loops • Path graph
• Cyclicity • Circle graph
• Connectivity

42
For Monday
• Read Barabási (2016) chapter 3 ‘Random
Networks’
• Get python working on your computer — either by
downloading, online, or whatever works
• Do the homework!
• Let me know when you’ve formed your group for
the final project and what (approximate) area
you’re going to work on.

43

You might also like