# Three Search Algorithm

May 8th, 2015
Studypool Tutor
Price: \$10 USD

Tutor description

* Simple Algorithms: Breadth-first and Depth-first Search Common Graph Algorithms * Two common graph algorithms: * Breadth-first Search (BFS) * Depth-first Search (DFS)

Word Count: 762
Showing Page: 1/5
Tree Search AlgorithmGraphs - BFS and DFSOverview* Simple Algorithms: Breadth-first and Depth-first Search Common Graph Algorithms* Two common graph algorithms: * Breadth-first Search (BFS) * Depth-first Search (DFS) * Search: find a node with a given characteristic * Example: search a call graph to find a call to a particular procedure * Both do more than searching Breadth First Search Algorithm* Common graph algoriths uses a breadth-first approach * Example Problem: Search all nodes for a node containing a given value * Example Problem: Find length of shortest path from node s to all other nodes * Example Problem: Find shortest path from node s to all other nodes* Breadth-first Algorithm: * Depth-first: visit all neighbors before visiting neighbors of your neighbors * Start from node s. * Visit all neighbors of node s. * Then visit all of their neighbors, if not already visited * Continue until all nodes visited * Intuition of Implementation * Keep a queue of nodes to visit * When visiting node u, put neighbors of u on the queue, if neighbor not yet visited * Queue contains all nodes that have been seen, but not yet visited Breadth First Search - Code* Problem: find length of shortest path from s to each node * Let u.d represent length of shortest path from nodes to node u * Remember: length is number of edges from s to u * Code: BFS(V, E, s)-- Initialize all nodes as unvisitedfor each node u loopu.d := -1end loop-- Mark first no

## Review from student

Studypool Student
" Solid work, thanks. "

1824 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors