Uninformed Search Alice Gao Lecture 3 Based on work by K. - - PowerPoint PPT Presentation

uninformed search
SMART_READER_LITE
LIVE PREVIEW

Uninformed Search Alice Gao Lecture 3 Based on work by K. - - PowerPoint PPT Presentation

1/34 Uninformed Search Alice Gao Lecture 3 Based on work by K. Leyton-Brown, K. Larson, and P. van Beek 2/34 Outline Learning Goals Uninformed Search Breadth-First Search Depth-First Search Iterative-Deepening Search Comparing the


slide-1
SLIDE 1

1/34

Uninformed Search

Alice Gao

Lecture 3 Based on work by K. Leyton-Brown, K. Larson, and P. van Beek

slide-2
SLIDE 2

2/34

Outline

Learning Goals Uninformed Search Breadth-First Search Depth-First Search Iterative-Deepening Search Comparing the algorithms Revisiting the Learning Goals

slide-3
SLIDE 3

3/34

Learning goals

By the end of the lecture, you should be able to

▶ Describe what it means to expand a node and what is a

frontier in a search tree.

▶ Defjne/trace/implement search algorithms (with/without

cost) (dealing with repeated states)

▶ Defjne completeness, optimality, time complexity and space

complexity.

▶ Determine properties of search algorithms: completeness,

  • ptimality, time and space complexity.

▶ Given a scenario, explain why it is appropriate or not

appropriate to use a particular search algorithm.

slide-4
SLIDE 4

4/34

Learning Goals Uninformed Search Breadth-First Search Depth-First Search Iterative-Deepening Search Comparing the algorithms Revisiting the Learning Goals

slide-5
SLIDE 5

5/34

Terminologies

▶ A search tree: the nodes are the states, the arcs are actions,

and the root is the start state.

▶ Expanding a node means applying every legal action

to the current state to generate a set of new states.

▶ The frontier contains the set of all leaf nodes available for

expansion.

slide-6
SLIDE 6

6/34

Problem Solving by Graph Searching

frontier explored nodes unexplored nodes start node

slide-7
SLIDE 7

7/34

Graph Search Algorithm

Algorithm 1 Generic graph search algorithm

1: put the start state in the frontier 2: while frontier is not empty do 3:

remove a node from the frontier

4:

if the node contains a goal state then

5:

return the solution

6:

end if

7:

generate all the successors of the node

8:

add every successor of the node to the frontier

9: end while 10: return failure

slide-8
SLIDE 8

8/34

The Search Strategy

Search strategy: which node do we remove from the frontier?

▶ Breadth-fjrst search treats the frontier as a queue (FIFO). ▶ Depth-fjrst search treats the frontier as a stack (LIFO). ▶ Informed search treats the frontier as a priority queue.

slide-9
SLIDE 9

9/34

Evaluating an Algorithm’s Performance

Defjnition (complete)

If a solution exists, a complete algorithm is guaranteed to fjnd a solution within a fjnite amount of time.

Defjnition (optimal)

If a solution exists and an algorithm fjnds a solution, then the fjrst solution found by an optimal algorithm is the solution with the lowest cost.

slide-10
SLIDE 10

10/34

Evaluating an Algorithm’s Performance

Defjnition (time complexity)

The time complexity of a search algorithm is an expression for the worst-case amount of time it will take to run, expressed in terms of b, d, and m.

Defjnition (space complexity)

The space complexity of a search algorithm is an expression for the worst-case amount of memory that the algorithm will use, expressed in terms of b, d, and m. Useful defjnitions:

▶ b: the maximum branching factor (may be infjnite). ▶ d: the depth of the shallowest goal node (fjnite). ▶ m: the maximum path length (may be infjnite).

slide-11
SLIDE 11

11/34

Learning Goals Uninformed Search Breadth-First Search Depth-First Search Iterative-Deepening Search Comparing the algorithms Revisiting the Learning Goals

slide-12
SLIDE 12

12/34

Breadth-First Search

Algorithm 2 Breadth-First Search

1: put the start state in the frontier 2: while frontier is not empty do 3:

remove the oldest node added to the frontier

4:

if the node contains a goal state then

5:

return the solution

6:

end if

7:

generate all the successors of the node

8:

add every successor of the node to the frontier

9: end while 10: return failure

slide-13
SLIDE 13

13/34

Breadth-First Search

Treats the frontier as a queue (FIFO). Expands the shallowest node in the frontier.

▶ Complete? ▶ Optimal? Yes if all arc costs are the same. ▶ Time complexity: O(bd) ▶ Space complexity:

slide-14
SLIDE 14

14/34

CQ: Is BFS complete?

CQ: Is BFS complete? (A) Yes. (B) No. (C) The answer depends on the branching factor. (D) The answer depends on whether there are infjnite paths in the search tree.

slide-15
SLIDE 15

15/34

CQ: Space complexity of BFS

CQ: What is the space complexity of BFS? (A) O(bd) (B) O(bd) (C) O(bm) (D) O(bm)

slide-16
SLIDE 16

16/34

Using Breadth-First Search

Would you use Breadth-First Search in any scenario below?

  • 1. Memory is limited.
  • 2. All solutions are deep in the tree.
  • 3. There are infjnite paths in the tree.
  • 4. The branching factor is large.
  • 5. We must fjnd the shallowest goal node.
slide-17
SLIDE 17

17/34

Learning Goals Uninformed Search Breadth-First Search Depth-First Search Iterative-Deepening Search Comparing the algorithms Revisiting the Learning Goals

slide-18
SLIDE 18

18/34

Depth-First Search

Algorithm 3 Depth-First Search

1: put the start state in the frontier 2: while frontier is not empty do 3:

remove the newest node added to the frontier

4:

if the node contains a goal state then

5:

return the solution

6:

end if

7:

generate all the successors of the node

8:

add every successor of the node to the frontier

9: end while 10: return failure

slide-19
SLIDE 19

19/34

Depth-First Search

Treats the frontier as a stack (LIFO). Expands the deepest node in the frontier.

▶ Complete? ▶ Optimal? No. ▶ Time complexity: O(bm) ▶ Space complexity:

slide-20
SLIDE 20

20/34

CQ: Is DFS complete?

CQ: Is DFS complete? (A) Yes. (B) No. (C) The answer depends on the branching factor. (D) The answer depends on whether there are infjnite paths in the search tree.

slide-21
SLIDE 21

21/34

CQ: Space complexity of DFS

CQ: What is the space complexity of DFS? (A) O(bd) (B) O(bd) (C) O(bm) (D) O(bm)

slide-22
SLIDE 22

22/34

Using Depth-First Search

Would you use Depth-First Search in any scenario below? Why?

  • 1. Memory is limited.
  • 2. Some paths have infjnite lengths.
  • 3. The graph contains cycles.
  • 4. Some solutions are very shallow.
slide-23
SLIDE 23

23/34

Handling Repeated States

▶ Store visited states in a hash table. ▶ How would the properties of DFS change if we prune visited

states?

slide-24
SLIDE 24

24/34

Comparing BFS and DFS

▶ What are the advantages of BFS over DFS? ▶ What are the advantages of DFS over BFS?

slide-25
SLIDE 25

25/34

CQ: BFS or DFS?

CQ: Suppose that some solutions are very deep and some solutions are very shallow in the search tree of a problem. Which

  • f BFS and DFS should we use to solve this problem?

(A) BFS (B) DFS (C) Both of BFS and DFS (D) Neither of BFS and DFS

slide-26
SLIDE 26

26/34

CQ: BFS or DFS?

CQ: If we have very limited memory and the search graph of a problem contains cycles, which of BFS and DFS should we use to solve this problem? (A) BFS (B) DFS (C) Both of BFS and DFS (D) Neither of BFS and DFS

slide-27
SLIDE 27

27/34

Learning Goals Uninformed Search Breadth-First Search Depth-First Search Iterative-Deepening Search Comparing the algorithms Revisiting the Learning Goals

slide-28
SLIDE 28

28/34

The best of BFS and DFS

BFS DFS requires lots of space requires little space complete not complete The best of both worlds:

▶ Run DFS until level l. ▶ If no solution found, try level l + 1, l + 2, etc.

slide-29
SLIDE 29

29/34

Iterative Deepening Search

Algorithm 4 Iterative Deepening Search

1: for l = 0 to ∞ do 2:

Perform depth-fjrst search up to maximum depth limit l

3: end for

slide-30
SLIDE 30

30/34

Iterative-Deepening Search

For depth limit l = 0, 1, ... Perform a depth-fjrst search with maximum depth l.

▶ Complete? Yes if the branching factor is fjnite. ▶ Optimal? Yes if all arc costs are the same. ▶ Time complexity: O(bd) ▶ Space complexity: O(bd)

slide-31
SLIDE 31

31/34

Using Iterative-Deepening Search

▶ How is IDS similar to/difgerent from DFS? ▶ How is IDS similar to/difgerent from BFS? ▶ Is it too costly for IDS to generate states in the upper levels

multiple times?

slide-32
SLIDE 32

32/34

Comparing BFS, DFS, and IDS

Algorithm Complete? Optimal? Time Space IDS DFS BFS * if the branching factor is fjnite. ** if the search tree does not have infjnite paths.

slide-33
SLIDE 33

33/34

CQ: Comparing IDS and DFS

CQ: Suppose that the search tree of a problem has no infjnite

  • paths. Which one of DFS and IDS should we use to solve this

problem? (A) DFS is better than IDS. (B) IDS is better than DFS. (C) DFS and IDS are the same.

slide-34
SLIDE 34

34/34

Revisiting the learning goals

By the end of the lecture, you should be able to

▶ Describe what it means to expand a node and what is a

frontier in a search tree.

▶ Defjne/trace/implement search algorithms (with/without

cost) (dealing with repeated states)

▶ Defjne completeness, optimality, time complexity and space

complexity.

▶ Determine properties of search algorithms: completeness,

  • ptimality, time and space complexity.

▶ Given a scenario, explain why it is appropriate or not

appropriate to use a particular search algorithm.