150 likes | 298 Views
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.
E N D
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 What is a graph? Basic implementation Answering questions Hash table: Theory and chaining
What is a graph? A graph is a set of elements called nodes, connected via edges. Bowen Island Mayne Island Nanaimo Vancouver Victoria Transportation Network An introduction to graphs
What is a graph? A graph is a set of elements called nodes, connected via edges. Satellite Network An introduction to graphs
What is a graph? Arash Pranil Peter Ibn Phil A graph is a set of elements called nodes, connected via edges. Social Network An introduction to graphs
What is a graph? 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 An introduction to graphs
What is a graph? 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. An introduction to graphs
What is a graph? 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. 4 0 4 2 In weighted graphs, edges have numerical values. 1 1 3 0 2 (length of the road, delay of signal between satellites, how much you like somebody, …) 2 An introduction to graphs
What’s the path to go from Alison Ystma to Marvin Lee? 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. The whole point of representing a problem as a graph is to be able to carry on analysis on the relationships. 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 Lets say that we have some graphs and we want the path from A to B. You can proceed by successive waves. A B An introduction to graphs
Finding a path, simple approach 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). 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 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’. The only thing to be careful about is not to go to the same node twice. So, use flags! An introduction to graphs
Aram Pranil Marvin Andrrea Philippe Behdad Priyam Danish 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 Shivam Robin Jeffrey Go from Shivam to Aram.