Download presentation
Presentation is loading. Please wait.
1
1 CMPUT 412 Search Algorithms Csaba Szepesvári University of Alberta TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA A A A A AA
2
2 Contents Search problems on graphs BFS DFS, IDFS A* Outlook
3
3 Search problems on graphs Single-pair shortest path problem: G=(V,E) g 2 V – goal state s 2 V – start state Note: Graph could be implicit! (nodes generated as needed) Examples: Shortest path on a map Solving logical puzzles Moving troops in a RTS game Finding a plan (AI) Variants: All pairs shortest path problem Single-source shortest path problem Stochastic shortest path Infinite graphs (node=state, transition=move=action) Minimum cost optimal control (~reinforcement learning)..
4
4 Breadth-first search function BFS queue.add (s) while (!queue.empty()) n queue.pop() if (goal(n)) return n; foreach (n,m) 2 E queue.add(m); Space complexity ~ number of nodes at the deepest level; O(b d ) or O(|V|+|E|) Time complexity: Same Guarantees In finite graphs finds an optimal solution Extension: costs; expand node with least cost from start
5
5 Depth-first search function dfs(n, &visited) if (goal(n)) return n; *visited.add(n) foreach (m,n) 2 E *if (!visited.has(m)) dfs(m,visited) Space complexity: #elements visited Time complexity: O(|V|+|E|), O(b d ) Guarantees: Finds the goal (without (*) only in loop-free graphs) Might not find the shortest path Extensions Use a hash-table to store the list of visited nodes (or no list) + iterative deepening Advantage to BFS: Search can be directed
6
6 A* (Hart, Nilsson, Raphael, ’68) function A*(s) closed := ; q.insert([s]) while (!q.empty()) path q.pop_first() n path.last() if closed.has(n) continue if goal(n) return path closed.add(n) foreach (n,m) 2 E queue.add( list(p,m), c(p)+c(n,m)+h(m) ) return failure Special best-first search algorithm Idea: Prioritize node expansion by total estimated cost of the path through the node Total cost = cost-so-far +cost-to-go (often: f=g+h) h:V R, h = h(n) “heuristic function” ~estimated cost-to-go Guarantees Always finds a solution If h is optimistic, A* find the optimal soln when no closed list is used -- or -- when h is monotonic Given h, optimally efficient Time-complexity: O(2 L ), where L is the length of the optimal path |h-h * | = O(log h * ) poly(h) Space-complexity: Might be the same Extensions: IDA*, MA*, RBFS
7
7 Search terminology If an algorithm A always.... finds a solution then A is complete.. finds an optimal solution then A is admissible.. does the least work amongst all admissible algorithm then A is optimally efficient
8
8 Outlook Dijkstra A* with h(n)=0 Bellman-Ford: Computes cost-to-go with “value iteration” for all nodes in |V| iterations. Pruning (beam search, ® - ¯,..) Cost-to-go can be learnt (LRTA*, RL) Problems can be stochastic (RL) Monte-Carlo search; UCT (directed depth- first search, with changing cost-to-go estimates) success in go
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.