Download presentation
Presentation is loading. Please wait.
Published byNoreen Francis Modified over 8 years ago
1
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! →
2
An introduction to graphs
3
Hash table: Theory and chaining An introduction to graphs What is a graph? Basic implementation Answering questions
4
What is a graph?
5
An introduction to graphs A graph is a set of elements called nodes, connected via edges. Vancouver Victoria Mayne IslandBowen Island Nanaimo Transportation Network
6
What is a graph? An introduction to graphs A graph is a set of elements called nodes, connected via edges. Satellite Network
7
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
8
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
9
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.
10
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 42 2 2 0 0 1 1 3 (length of the road, delay of signal between satellites, how much you like somebody, …)
11
Starting to answer questions
12
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 ?
13
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.
14
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!
15
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 PhilippeBehdad JeffreyRobin Priyam Andrrea Danish Shivam Go from Shivam to Aram.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.