a - l
DESCRIPTION
Emergency. A - L. • Danny Fan • Peter Hsiao • Eric Joel • Alwin Kwok • Jeremy Lau. • Gabriel Lam • Jeffrey Lee • Marvin Lee • Heedong Park • Andrew Samuel. • Greg Yi • Alison Ystma • Bu Yu. ↑↓ 3 sorted stacks! →. M - Z. An introduction to graphs. - PowerPoint PPT PresentationTRANSCRIPT
A - L
M - Z
Emergency• Danny Fan • Peter Hsiao • Eric Joel • Alwin Kwok • Jeremy Lau
• Gabriel Lam • Jeffrey Lee • Marvin Lee • Heedong Park • Andrew Samuel
• Greg Yi • Alison Ystma • Bu Yu
↑↓ 3 sorted stacks! →
An introduction to graphs
Hash table: Theory and chaining
An introduction to graphs
What is a graph?
Basic implementation
Answering questions
What is a graph?What is a graph?
What is a graph?
An introduction to graphs
A graph is a set of elements called nodes, connected via edges.
Vancouver
Victoria
Mayne IslandBowen Island
Nanaimo
Transportation Network
What is a graph?
An introduction to graphs
A graph is a set of elements called nodes, connected via edges.
Satellite Network
Arash
What is a graph?
An introduction to graphs
A graph is a set of elements called nodes, connected via edges.
Social Network
Ibn Phil
Pranil Peter
What is a graph?
An introduction to graphs
A graph is a set of elements called nodes, connected via edges.
It’s a very common modeling tool: as soon as you have entities and some sort of relationship, you can use it.
Commonly, nodes are represented by and edges byaaaaa
What is a graph?
An introduction to graphs
A graph is a set of elements called nodes, connected via edges.
It’s a very common modeling tool: as soon as you have entities and some sort of relationship, you can use it.
Commonly, nodes are represented by and edges byaaaaa
As it’s a modeling tool, if you need to model more features, just get them in.
The graph can be undirected or directed
(edges have a direction).
Roads have a direction.
What is a graph?
An introduction to graphs
A graph is a set of elements called nodes, connected via edges.
It’s a very common modeling tool: as soon as you have entities and some sort of relationship, you can use it.
Commonly, nodes are represented by and edges byaaaaa
As it’s a modeling tool, if you need to model more features, just get them in.
In weighted graphs, edges have numerical values.
4
4 2
2
2
0
0
1
1 3(length of the road, delay of signal between satellites, how much you like somebody, …)
Starting to answer Starting to answer questionsquestions
The whole point of representing a problem as a graph is to be able to
carry on analysis on the relationships.
A simple question is to find the path between two nodes, i.e. the sequence of
nodes that we have to visit to go from one to the other.
What’s the path to go from Alison Ystma to Marvin Lee?
Alison Ystma → Mike Kubanski → Andreea Says Hi → Priyam Banerjee → Marvin Lee
Now, how would you make that into an algorithm ?
Finding a path, simple approach
An introduction to graphs
A
B
Lets say that we have some graphs and we want the path from A to B.
You can proceed by successive waves.
Finding a path, simple approach
An introduction to graphs
Lets say that we have some graphs and we want the path from A to B.
You can proceed by successive waves.
This is called a breadth-first search (BFS).
At each step, we look if we have found the element. If not, the next nodes to visit are the neighbours of the next ‘wave’ or ‘layer’.
BFS(from, destination): // do we have a path?
Queue ← from
While there is a node C to get from the queue
If C is the destination, return true
Otherwise add C’s neighbours to the queue
Return false
The only thing to be careful about is not to go to the same node twice. So, use flags!
BFS(from, destination): // do we have a path?
Queue ← from
While there is a node C to get from the queue
If C is the destination, return true
Otherwise add C’s neighbours to the queue
Return false
Aram
Pranil Marvin
Philippe Behdad
JeffreyRobin
Priyam
Andrrea
Danish
Shivam
Go from Shivam to Aram.