87
A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Co UCT Algorithm Circle: An Introduction to Graph Theory Peter Faul 16 August 2012 Peter Faul Graph Theory

UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

  • Upload
    others

  • View
    37

  • Download
    0

Embed Size (px)

Citation preview

Page 1: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

UCT Algorithm Circle: An Introduction toGraph Theory

Peter Faul

16 August 2012

Peter Faul Graph Theory

Page 2: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Outline

1 A quick puzzle

2 Terminology

3 Revisiting Konigsberg

4 Onto some specifics

5 Applications in computer science

6 Simple searches

7 Conclusion

Peter Faul Graph Theory

Page 3: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

The bridges of Konigsberg

Can you follow a path, walking over each bridge exactlyonce?

Peter Faul Graph Theory

Konigsberg Diagram [1]

Page 4: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Outline

1 A quick puzzle

2 Terminology

3 Revisiting Konigsberg

4 Onto some specifics

5 Applications in computer science

6 Simple searches

7 Conclusion

Peter Faul Graph Theory

Page 5: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Some terminology

Node: The fundamental unit out of which graphs areformed.Edge: Connects two nodes.Graph: Collection of Nodes and Edges.

Peter Faul Graph Theory

Page 6: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Some terminology

Node: The fundamental unit out of which graphs areformed.Edge: Connects two nodes.Graph: Collection of Nodes and Edges.

Peter Faul Graph Theory

Page 7: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Some terminology

Node: The fundamental unit out of which graphs areformed.Edge: Connects two nodes.Graph: Collection of Nodes and Edges.

Peter Faul Graph Theory

Page 8: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Example of a graph

Peter Faul Graph Theory

Graph Diagram[2]

Page 9: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

More Terminology

Walk: An alternating sequence of nodes and edges, with abeginning and end node. Each node is connected to thenode that came before it, and the node that comes after it.Trail: A walk where all edges are distinct.Path: A trail where all nodes (except maybe the first andlast) are distinct.

Peter Faul Graph Theory

Page 10: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

More Terminology

Walk: An alternating sequence of nodes and edges, with abeginning and end node. Each node is connected to thenode that came before it, and the node that comes after it.Trail: A walk where all edges are distinct.Path: A trail where all nodes (except maybe the first andlast) are distinct.

Peter Faul Graph Theory

Page 11: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

More Terminology

Walk: An alternating sequence of nodes and edges, with abeginning and end node. Each node is connected to thenode that came before it, and the node that comes after it.Trail: A walk where all edges are distinct.Path: A trail where all nodes (except maybe the first andlast) are distinct.

Peter Faul Graph Theory

Page 12: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Example of a path

Peter Faul Graph Theory

Page 13: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Example of a path

Peter Faul Graph Theory

Page 14: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Example of a path

Peter Faul Graph Theory

Page 15: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Example of a path

Peter Faul Graph Theory

Page 16: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Example of a path

Peter Faul Graph Theory

Page 17: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Example of a path

Peter Faul Graph Theory

Page 18: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Even more terminology

Eulerian Path: A trail where each edge is visited once.Hamiltonian path: A path where each node is visited once.Degree of node: The number of edges attached to thenode.

Peter Faul Graph Theory

Page 19: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Even more terminology

Eulerian Path: A trail where each edge is visited once.Hamiltonian path: A path where each node is visited once.Degree of node: The number of edges attached to thenode.

Peter Faul Graph Theory

Page 20: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Even more terminology

Eulerian Path: A trail where each edge is visited once.Hamiltonian path: A path where each node is visited once.Degree of node: The number of edges attached to thenode.

Peter Faul Graph Theory

Page 21: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Outline

1 A quick puzzle

2 Terminology

3 Revisiting Konigsberg

4 Onto some specifics

5 Applications in computer science

6 Simple searches

7 Conclusion

Peter Faul Graph Theory

Page 22: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Konigsberg

How can we simplify this problem?

Peter Faul Graph Theory

Page 23: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Turn it into a graph

Konigsberg bridges in the form of a graph.

Peter Faul Graph Theory

Page 24: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

What now?

So how has this helped?We can restate the problem now; perhaps it will be easierto prove in this form.

Peter Faul Graph Theory

Page 25: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

What now?

So how has this helped?We can restate the problem now; perhaps it will be easierto prove in this form.

Peter Faul Graph Theory

Page 26: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Restating the problem

Does the following graph have an Eulerian path?

Peter Faul Graph Theory

Page 27: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Euler’s proposition

Any graph with more than two nodes of odd degree doesnot have an Eulerian path.The bridges of Konigsberg graph, has 4 nodes of odddegree.Hence it has no Eulerian path

Peter Faul Graph Theory

Page 28: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Euler’s proposition

Any graph with more than two nodes of odd degree doesnot have an Eulerian path.The bridges of Konigsberg graph, has 4 nodes of odddegree.Hence it has no Eulerian path

Peter Faul Graph Theory

Page 29: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Euler’s proposition

Any graph with more than two nodes of odd degree doesnot have an Eulerian path.The bridges of Konigsberg graph, has 4 nodes of odddegree.Hence it has no Eulerian path

Peter Faul Graph Theory

Page 30: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Outline

1 A quick puzzle

2 Terminology

3 Revisiting Konigsberg

4 Onto some specifics

5 Applications in computer science

6 Simple searches

7 Conclusion

Peter Faul Graph Theory

Page 31: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Classification of graphs

Graphs may have the following attributes:Connected: From any one node, there is a walk to anyother node.Cyclic: A graph that contains some number of nodesconnected in a closed chain.Directed: A graph in which the edges have a directionassociated with them.Tree: An undirected graph where any two nodes areconnected by one unique path.

Peter Faul Graph Theory

Page 32: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Classification of graphs

Graphs may have the following attributes:Connected: From any one node, there is a walk to anyother node.Cyclic: A graph that contains some number of nodesconnected in a closed chain.Directed: A graph in which the edges have a directionassociated with them.Tree: An undirected graph where any two nodes areconnected by one unique path.

Peter Faul Graph Theory

Page 33: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Classification of graphs

Graphs may have the following attributes:Connected: From any one node, there is a walk to anyother node.Cyclic: A graph that contains some number of nodesconnected in a closed chain.Directed: A graph in which the edges have a directionassociated with them.Tree: An undirected graph where any two nodes areconnected by one unique path.

Peter Faul Graph Theory

Page 34: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Classification of graphs

Graphs may have the following attributes:Connected: From any one node, there is a walk to anyother node.Cyclic: A graph that contains some number of nodesconnected in a closed chain.Directed: A graph in which the edges have a directionassociated with them.Tree: An undirected graph where any two nodes areconnected by one unique path.

Peter Faul Graph Theory

Page 35: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Classification of graphs

Graphs may have the following attributes:Connected: From any one node, there is a walk to anyother node.Cyclic: A graph that contains some number of nodesconnected in a closed chain.Directed: A graph in which the edges have a directionassociated with them.Tree: An undirected graph where any two nodes areconnected by one unique path.

Peter Faul Graph Theory

Page 36: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Disconnected Graph

A graph that is not connected:

Peter Faul Graph Theory

Page 37: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Cyclic Graph

A cyclic graph, note the part in red:

Peter Faul Graph Theory

Page 38: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Directed Graph

Up until now we have been considering undirected graphswhere you are traverse edges in both directions. Edgesmay also be directed, in which case edges may only betraversed along the direction in which they point

Peter Faul Graph Theory

Page 39: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Tree Graph

An example of a tree:

Peter Faul Graph Theory

Page 40: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Outline

1 A quick puzzle

2 Terminology

3 Revisiting Konigsberg

4 Onto some specifics

5 Applications in computer science

6 Simple searches

7 Conclusion

Peter Faul Graph Theory

Page 41: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Justification

So why is this being taught in a computer science lecture?Many problems in computer science can be modelled interms of graphs

Peter Faul Graph Theory

Page 42: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Justification

So why is this being taught in a computer science lecture?Many problems in computer science can be modelled interms of graphs

Peter Faul Graph Theory

Page 43: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Examples:

Path finding in video games.The link structure of a website.Notorious travelling salesman problem.Many more...

Peter Faul Graph Theory

Page 44: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Examples:

Path finding in video games.The link structure of a website.Notorious travelling salesman problem.Many more...

Peter Faul Graph Theory

Page 45: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Examples:

Path finding in video games.The link structure of a website.Notorious travelling salesman problem.Many more...

Peter Faul Graph Theory

Page 46: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Examples:

Path finding in video games.The link structure of a website.Notorious travelling salesman problem.Many more...

Peter Faul Graph Theory

Page 47: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Representing a graph

How do we represent a graph on a computer?Adjacency ListAdjacency Matrix

Peter Faul Graph Theory

Page 48: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Representing a graph

How do we represent a graph on a computer?Adjacency ListAdjacency Matrix

Peter Faul Graph Theory

Page 49: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Representing a graph

How do we represent a graph on a computer?Adjacency ListAdjacency Matrix

Peter Faul Graph Theory

Page 50: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency List

A representation of a graph of n nodes, using an array of nlinked lists.List A contains node b if node a is connected to node b.

Peter Faul Graph Theory

Page 51: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency List

A representation of a graph of n nodes, using an array of nlinked lists.List A contains node b if node a is connected to node b.

Peter Faul Graph Theory

Page 52: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency List

Peter Faul Graph Theory

Page 53: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency List

Peter Faul Graph Theory

Page 54: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency Matrix

A matrix representation of the graph (Use nested arrays).The entry aij in the matrix A is equal to the number ofedges from node i to node j

Peter Faul Graph Theory

Page 55: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency Matrix

A matrix representation of the graph (Use nested arrays).The entry aij in the matrix A is equal to the number ofedges from node i to node j

Peter Faul Graph Theory

Page 56: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency Matrix

Peter Faul Graph Theory

Page 57: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Adjacency Matrix

0 1 0 0 1 01 0 1 0 1 00 1 0 1 0 00 0 1 0 1 11 1 0 1 0 00 0 0 1 0 0

Peter Faul Graph Theory

Page 58: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

An interesting property

Let A be the adjacency matrix for some graph G.Then the entry kij in An represents the number of differentwalks from node i to node j.Remember how matrix multiplication is defined to makesense of this.

Peter Faul Graph Theory

Page 59: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

An interesting property

Let A be the adjacency matrix for some graph G.Then the entry kij in An represents the number of differentwalks from node i to node j.Remember how matrix multiplication is defined to makesense of this.

Peter Faul Graph Theory

Page 60: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

An interesting property

Let A be the adjacency matrix for some graph G.Then the entry kij in An represents the number of differentwalks from node i to node j.Remember how matrix multiplication is defined to makesense of this.

Peter Faul Graph Theory

Page 61: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

A comparison

So which representation is best?That depends.Adjacency Matrices take up O(n2) space, however thereare constant time lookups, insertions and deletions.Adjacency Lists take up O(n+e) space, however they haveslower lookup times etc.So really your choice should depend on your requirementsand on the graph.

Peter Faul Graph Theory

Page 62: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

A comparison

So which representation is best?That depends.Adjacency Matrices take up O(n2) space, however thereare constant time lookups, insertions and deletions.Adjacency Lists take up O(n+e) space, however they haveslower lookup times etc.So really your choice should depend on your requirementsand on the graph.

Peter Faul Graph Theory

Page 63: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

A comparison

So which representation is best?That depends.Adjacency Matrices take up O(n2) space, however thereare constant time lookups, insertions and deletions.Adjacency Lists take up O(n+e) space, however they haveslower lookup times etc.So really your choice should depend on your requirementsand on the graph.

Peter Faul Graph Theory

Page 64: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

A comparison

So which representation is best?That depends.Adjacency Matrices take up O(n2) space, however thereare constant time lookups, insertions and deletions.Adjacency Lists take up O(n+e) space, however they haveslower lookup times etc.So really your choice should depend on your requirementsand on the graph.

Peter Faul Graph Theory

Page 65: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

A comparison

So which representation is best?That depends.Adjacency Matrices take up O(n2) space, however thereare constant time lookups, insertions and deletions.Adjacency Lists take up O(n+e) space, however they haveslower lookup times etc.So really your choice should depend on your requirementsand on the graph.

Peter Faul Graph Theory

Page 66: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Outline

1 A quick puzzle

2 Terminology

3 Revisiting Konigsberg

4 Onto some specifics

5 Applications in computer science

6 Simple searches

7 Conclusion

Peter Faul Graph Theory

Page 67: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Searching Algorithms

Often we might want to see if one node is attached toanother nodeOr find the shortest path from one node to anotherWe use searching algorithms to accomplish this.We will look at two simple searching algorithms.

Peter Faul Graph Theory

Page 68: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Searching Algorithms

Often we might want to see if one node is attached toanother nodeOr find the shortest path from one node to anotherWe use searching algorithms to accomplish this.We will look at two simple searching algorithms.

Peter Faul Graph Theory

Page 69: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Searching Algorithms

Often we might want to see if one node is attached toanother nodeOr find the shortest path from one node to anotherWe use searching algorithms to accomplish this.We will look at two simple searching algorithms.

Peter Faul Graph Theory

Page 70: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Searching Algorithms

Often we might want to see if one node is attached toanother nodeOr find the shortest path from one node to anotherWe use searching algorithms to accomplish this.We will look at two simple searching algorithms.

Peter Faul Graph Theory

Page 71: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Breadth First Search

Systematically searches through all nodesDoes so by inspecting node then adding all nodes linked,to a queue.

Peter Faul Graph Theory

Page 72: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Breadth First Search

Systematically searches through all nodesDoes so by inspecting node then adding all nodes linked,to a queue.

Peter Faul Graph Theory

Page 73: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Breadth First Properties

Breadth First search guarantees the shortest path.However it uses more memory than a depth first search onaverage.

Peter Faul Graph Theory

Page 74: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Breadth First Properties

Breadth First search guarantees the shortest path.However it uses more memory than a depth first search onaverage.

Peter Faul Graph Theory

Page 75: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Depth First Search

Also searches through all nodesDoes so by inspecting node then adding all nodes linked,to a stack.

Peter Faul Graph Theory

Page 76: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Depth First Search

Also searches through all nodesDoes so by inspecting node then adding all nodes linked,to a stack.

Peter Faul Graph Theory

Page 77: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Depth First properties

For tree traversal, depth first uses less memory generallyas it need only store the nodes on the current path.While you shouldn’t count on it, you may hit the targethaving only explored a fraction of the tree.This however is not necessarily the best solution.There is also the potential for the search to get stuckexploring an infinite path.

Peter Faul Graph Theory

Page 78: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Depth First properties

For tree traversal, depth first uses less memory generallyas it need only store the nodes on the current path.While you shouldn’t count on it, you may hit the targethaving only explored a fraction of the tree.This however is not necessarily the best solution.There is also the potential for the search to get stuckexploring an infinite path.

Peter Faul Graph Theory

Page 79: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Depth First properties

For tree traversal, depth first uses less memory generallyas it need only store the nodes on the current path.While you shouldn’t count on it, you may hit the targethaving only explored a fraction of the tree.This however is not necessarily the best solution.There is also the potential for the search to get stuckexploring an infinite path.

Peter Faul Graph Theory

Page 80: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Depth First properties

For tree traversal, depth first uses less memory generallyas it need only store the nodes on the current path.While you shouldn’t count on it, you may hit the targethaving only explored a fraction of the tree.This however is not necessarily the best solution.There is also the potential for the search to get stuckexploring an infinite path.

Peter Faul Graph Theory

Page 81: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Summary

So your choice of algorithm largely depends on your graphAnd on your own requirements.

Peter Faul Graph Theory

Page 82: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Summary

So your choice of algorithm largely depends on your graphAnd on your own requirements.

Peter Faul Graph Theory

Page 83: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Outline

1 A quick puzzle

2 Terminology

3 Revisiting Konigsberg

4 Onto some specifics

5 Applications in computer science

6 Simple searches

7 Conclusion

Peter Faul Graph Theory

Page 84: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Conclusion

So there you have it, an introduction to graphs.Very important in many disciplinesAny Questions?

Peter Faul Graph Theory

Page 85: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Conclusion

So there you have it, an introduction to graphs.Very important in many disciplinesAny Questions?

Peter Faul Graph Theory

Page 86: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Conclusion

So there you have it, an introduction to graphs.Very important in many disciplinesAny Questions?

Peter Faul Graph Theory

Page 87: UCT Algorithm Circle: An Introduction to Graph Theory · 2012-09-15 · A quick puzzleTerminologyRevisiting KonigsbergOnto some specificsApplications in computer scienceSimple searchesConclusion

A quick puzzle Terminology Revisiting Konigsberg Onto some specifics Applications in computer science Simple searches Conclusion

Licensing

These lecture slides were created by Peter Faul for UCTAlgorithm Circle and are licensed under the Creative CommonsAttribution-ShareAlike 3.0 Unported License.

I made use of the following third-party content also licensed underCC-BY-SA 3.0:

1 Konigsberg Diagram: http://en.wikipedia.org/wiki/File:Red-black_tree_example.svg.

2 Tree Diagram:http://en.wikipedia.org/wiki/File:Tree_graph.svg

3 Graph Diagram:http://en.wikipedia.org/wiki/File:6n-graf.svg

Peter Faul Graph Theory