1 / 56

Search Strategies

Search Strategies. CMPT 420 / CMPG 720. Uninformed Search Strategies. Uninformed search strategies use only the information available in the problem definition Breadth-first search Uniform-cost search Depth-first search Depth-limited search Iterative deepening search. Breadth-first search.

Télécharger la présentation

Search Strategies

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. Search Strategies CMPT 420 / CMPG 720

  2. Uninformed Search Strategies • Uninformed search strategies use only the information available in the problem definition • Breadth-first search Uniform-cost search Depth-first search • Depth-limited search Iterative deepening search

  3. Breadth-first search • Expand shallowest unexpanded node

  4. Breadth-first search • Expand shallowest unexpanded node

  5. Breadth-first search • Expand shallowest unexpanded node

  6. Breadth-first search • Expand shallowest unexpanded node Examine siblings before children

  7. Breadth-first search • Expand shallowest unexpanded node Implementation: • Frontier is a FIFO queue, i.e., new successors go at end

  8. Example: Romania

  9. Graph Representation 2 1 3 5 4 • Adjacency list representation of G = (V, E) • An array of V lists, one for each vertex in V • Each list Adj[u] contains all the vertices v such that there is an edge between u and v • Adj[u] contains the vertices adjacent to u (in arbitrary order) • Can be used for both directed and undirected graphs 1 2 3 4 5 Undirected graph

  10. Graph Representation 0 1 0 1 0 0 1 1 1 1 2 1 0 1 0 1 0 3 1 0 1 0 1 5 4 1 1 0 0 1 • Adjacency matrix representation of G = (V, E) • Assume vertices are numbered 1, 2, … V  • The representation consists of a matrix A V x V : • aij = 1 if (i, j)  E 0 otherwise 1 2 3 4 5 For undirected graphs matrix A is symmetric: aij = aji A = AT 1 2 3 4 Undirected graph 5

  11. Breadth-first search • Is BFS guaranteed to find a solution if one exists?

  12. Breadth-first search • Is BFS guaranteed to find a solution if one exists? • Problem?

  13. Breadth-first search • Guaranteed to find a solution if one exists • Problem: it might take a very long time to find a solution! • note how much of tree is expanded that doesn't contribute towards goal

  14. Properties of breadth-first search • Complete? • Yes • Optimal? • Time? • Space?

  15. Properties of breadth-first search • Complete? • Yes • Optimal? • Yes (if cost = 1 per step) • Time? • Space?

  16. Properties of breadth-first search • Complete? • Yes • Optimal? • Yes (if cost = 1 per step) • Time? • 1+b+b2+b3+… +bd = O(bd) • exponential in d • Space?

  17. Properties of breadth-first search • Complete? • Yes • Optimal? • Yes (if cost = 1 per step) • Time? • 1+b+b2+b3+… +bd = O(bd) • exponential in d • Space? • O(bd) (O(bd-1) nodes in the explored set and O(bd) nodes in the frontier)

  18. Uniform-cost search • Expand the node with the lowest path cost g(n) • (Cheapest search) Implementation:

  19. Uniform-cost search • Expand the node with the lowest path cost g(n) • (Cheapest search) Implementation: • Frontier = priority queue ordered by path cost g(n)

  20. Example: Romania

  21. Properties of uniform-cost search • Equivalent to breadth-first if step costs all equal • Complete? • Yes • Optimal? • Yes – nodes expanded in increasing order of path cost • Time? • O(bd) • Space? • O(bd)

  22. Depth-first search • Expand deepest unexpanded node

  23. Depth-first search • Expand deepest unexpanded node

  24. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  25. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  26. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  27. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  28. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  29. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  30. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  31. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  32. Depth-first search • Expand deepest unexpanded node Examine children before siblings

  33. Depth-first search • Expand deepest unexpanded node Implementation: • Frontier= LIFO queue

  34. Depth-first search Example

  35. More efficient (in some cases) than breadth-first search • Problem: what if some branch is very long: can spend a lot of time searching useless cases

  36. Properties of depth-first search • Complete? • Yes (if every branch has finite number of states) • Optimal? • No

  37. Properties of depth-first search • Complete? • Yes (if every branch has finite number of states) • Optimal? • No • Time? • O(bm): terrible if m is much larger than d • but if solutions are dense, may be much faster than breadth-first

  38. Comparing Uninformed Search Strategies • Time and space complexity are measured in • b – maximum branching factor of the search tree • m – maximum depth of the state space • d – depth of the least cost solution

  39. Properties of depth-first search • Complete? • Yes (if every branch has finite number of states) • Optimal? • No • Time? • O(bm): terrible if m is much larger than d • but if solutions are dense, may be much faster than breadth-first • Space? • O(bm), i.e., linear space!

  40. Depth-limited search • Depth-first search with depth limit l, • i.e., nodes at depth l have no successors • 20 cities in map of Romania • l =19 • Any city can be reached from any other city in at most 9 steps. • Diameter gives a better depth limit.

  41. Properties of Depth-limited search • Complete? • Yes (if the goal is within the limit) • Optimal? • No • Time? • O(bl) • Space? • O(bl)

  42. Properties of Depth-limited search • Depth-first search can be viewed as a special case with l = infinity • Main advantage that the search process can't descend forever (in a branch without solution). • However, it will not find a solution if all solutions require a depth greater than the limit. • (This is likely when l is unknown.)

  43. How to overcome this and maintain the advantages of depth limited search?

  44. Iterative deepening search • Gradually increases the limit – 0, 1, 2, … • If don't find solution, increase depth and try again • Combines the benefits of depth-first and breadth-first search.

  45. Iterative deepening search l =0

  46. Iterative deepening search l =1

  47. Iterative deepening search l =2

More Related