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.

Slides:



Advertisements
Similar presentations
BEST FIRST SEARCH - BeFS
Advertisements

CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
CSE 373, Copyright S. Tanimoto, 2001 Graphs Graphs 2 Incidence and Adjacency Representing a graph with an adjacency matrix, an incidence matrix,
GRAPHS Lecture 18 CS2110 – Fall Graph Algorithms 2 Search –depth-first search –breadth-first search Shortest paths –Dijkstra's algorithm Minimum.
Graph Theory, DFS & BFS Kelly Choi What is a graph? A set of vertices and edges –Directed/Undirected –Weighted/Unweighted –Cyclic/Acyclic.
Graphs - II CS 2110, Spring Where did I leave that book?
Graph A graph, G = (V, E), is a data structure where: V is a set of vertices (aka nodes) E is a set of edges We use graphs to represent relationships among.
Graph Searching CSE 373 Data Structures Lecture 20.
1 Section 9.4 Spanning Trees. 2 Let G be a simple graph. A spanning subtree of G is a subgraph of G containing every vertex of G –must be connected; contains.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
CSE 373: Data Structures and Algorithms Lecture 19: Graphs III 1.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Breadth-First and Depth-First Search
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
CS171 Introduction to Computer Science II Graphs Strike Back.
Graphs By JJ Shepherd. Introduction Graphs are simply trees with looser restrictions – You can have cycles Historically hard to deal with in computers.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Data Structures & Algorithms Graph Search Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Spanning Trees.
Spanning Trees. 2 Spanning trees Suppose you have a connected undirected graph Connected: every node is reachable from every other node Undirected: edges.
17-Jun-15 Searching in BeeperHunt (Mostly minor variations on old slides)
CS 206 Introduction to Computer Science II 11 / 10 / 2008 Instructor: Michael Eckmann.
Alyce Brady CS 510: Computer Algorithms Breadth-First Graph Traversal Algorithm.
COMP171 Depth-First Search.
Pathfinding Algorithms Josh Palmer Rachael Beers.
CS 206 Introduction to Computer Science II 11 / 05 / 2008 Instructor: Michael Eckmann.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
Alyce Brady CS 510: Computer Algorithms Depth-First Graph Traversal Algorithm.
Depth-first search COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar to pre-order.
Breadth First Search (BFS) Part 2 COMP171. Graph / Slide 2 Shortest Path Recording * BFS we saw only tells us whether a path exists from source s, to.
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
 Last lesson  Graphs  Today  Graphs (Implementation, Traversal)
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Depth-First Search Lecture 24 COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar.
Dijkstra’s Algorithm and Heuristic Graph Search David Johnson.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
MA/CSSE 473 Day 12 Insertion Sort quick review DFS, BFS Topological Sort.
COSC 2007 Data Structures II Chapter 14 Graphs III.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graph Traversal BFS & DFS. Review of tree traversal methods Pre-order traversal In-order traversal Post-order traversal Level traversal a bc d e f g hi.
Graphs. Definitions A graph is two sets. A graph is two sets. –A set of nodes or vertices V –A set of edges E Edges connect nodes. Edges connect nodes.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
Introduction to Graph Theory Lecture 16: Graph Searching Algorithms.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
COSC 2007 Data Structures II
Search Techniques CS480/580 Fall Introduction Trees: – Root, parent, child, sibling, leaf node, node, edge – Single path from root to any node Graphs:
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Graph Traversal Text Weiss, § 9.6 Depth-First Search Think Stack Breadth-First Search Think Queue.
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
Main Index Contents 11 Main Index Contents Graph Categories Graph Categories Example of Digraph Example of Digraph Connectedness of Digraph Connectedness.
Best-first search is a search algorithm which explores a graph by expanding the most promising node chosen according to a specified rule.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
Brute Force and Exhaustive Search Brute Force and Exhaustive Search Traveling Salesman Problem Knapsack Problem Assignment Problem Selection Sort and Bubble.
Graphs - II CS 2110, Spring Where did David leave that book? 2.
Graphs Part 2 Adjacency Matrix
COMP171 Depth-First Search.
Depth-First Search CSE 2011 Winter April 2019.
Depth-First Search CSE 2011 Winter April 2019.
Presentation transcript:

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 All nodes n such that |n| = 5....

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...

BFS

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

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.

DFS

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

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 }

BFS + DFS MethodtoDo implementation DFSStack BFSQueue Best-first searchPriority queue

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!

WWW as a graph Nodes - Edges -

WWW as a graph Nodes - webpages Edges - links

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

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

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

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...

Bus/train map as a graph Nodes - Edges -

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. How to find how to reach a bus stop/city?

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

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

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