1 / 22

Section 9

Section 9. Graph search algorithms. Breadth-first search. Idea: Let |n| denote a distance of node n from the initial node. We visit nodes in order: All nodes n such that |n| = 1 All nodes n such that |n| = 2 All nodes n such that |n| = 3 All nodes n such that |n| = 4

osric
Download Presentation

Section 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Section 9 • Graph search algorithms

  2. Breadth-first search • Idea: Let |n| denote a distance of node n from the initial node. We visit nodes in order: • All nodes n such that |n| = 1 • All nodes n such that |n| = 2 • All nodes n such that |n| = 3 • All nodes n such that |n| = 4 • All nodes n such that |n| = 5 ....

  3. BFS: Water analogy • BFS is similar to pouring water! • We pour the water on the first node. When there is too much water in it, the nodes adjacent to it start to fill. And so on...

  4. BFS

  5. Depth-first search • Idea: We go as deep as possible. • Visit recursively all the adjacent nodes of the source node.

  6. DFS: Labyrinth analogy • DFS is similar to going through labyrinth. • We walk leaving a thread behind us. Whenever we have the choice of path, we choose the leftmost one. If we reach a dead-end or the place already marked, we go back to the first unvisited place.

  7. DFS

  8. BFS + DFS • Stunning fact - we can implement both of them using the same code, changing only the underlying SequenceStructure.

  9. BFS + DFS • initialize toDo with the node we are starting from while (!empty(toDo)) { remove a node n from toDo visit(n) put all unvisited neighbours of n on toDo }

  10. BFS + DFS

  11. Best-first search • In situation when we have a weight function f on nodes, which tells us which node to visit first. • BFS, but visiting neighbours according to the fumction f. • Just use priority queue!

  12. WWW as a graph • Nodes - • Edges -

  13. WWW as a graph • Nodes - webpages • Edges - links

  14. WWW as a graph • How to write a program downloading a whole web page?

  15. WWW as a graph • How to write a program downloading a whole web page? • Use graph search! • Which one?

  16. WWW as a graph • How to write a program downloading a whole web page? • Use graph search! • Which one? • BFS!

  17. WWW as a graph • Interesting questions: • What is the diameter of the graph? (probably about 20) • What is its structure? • What are the efficient search algorithms? - Google, Altavista • What is a „typical” node? • Many more...

  18. Bus/train map as a graph • Nodes - • Edges -

  19. Bus map as a graph • Nodes - bus/train stops/stations • Edges - there’s an edge from one node to the other if there is a bus/train, which takes you from one stop to the other. • www.bahn.de • How to find how to reach a bus stop/city?

  20. Survival skills • How to find a way out in the labyrinth? • Optimistic version: With a thread of string. • Pessimistic version: Without a thread.

  21. With a thread • Use DFS - using a thread to go back to the yet unvisited paths.

  22. Without a thread • A heuristics which often works - always turn left.

More Related