0% found this document useful (0 votes)
6 views20 pages

Lec15 (Is)

The document discusses search methods for route-finding problems, focusing on algorithms like Breadth-first Search (BFS) and Depth-first Search (DFS). It outlines the structure of search algorithms, performance metrics such as completeness and optimality, and the differences between BFS and DFS. Additionally, it provides pseudo algorithms and examples for both search strategies, illustrating their processes and applications in various contexts.

Uploaded by

Nooraldeen Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views20 pages

Lec15 (Is)

The document discusses search methods for route-finding problems, focusing on algorithms like Breadth-first Search (BFS) and Depth-first Search (DFS). It outlines the structure of search algorithms, performance metrics such as completeness and optimality, and the differences between BFS and DFS. Additionally, it provides pseudo algorithms and examples for both search strategies, illustrating their processes and applications in various contexts.

Uploaded by

Nooraldeen Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Ninevah University

College of Electronics Engineering


Computer and Informatics Engineering Department

Intelligent Systems
Lecture 15
Search Methods for Route-finding Problems

Lecturer
Dr. Faris S. Alghareb
PhD in Computer Engineering @ UCF
email: [email protected]
Copyright © 2020 Faris S. Alghareb. All rights reserved.
Route-finding Problem (1/2)
v Route-finding algorithms are used in a variety of applications, such as routing video
streams in computer networks, military operations planning, airline travel-planning systems,
and other application that involve much more complex specifications

v Search algorithms work by considering various possible action sequences.

v The possible action sequences starting at the initial state from a search tree with the initial
state at the root; the branches are actions, and the nodes correspond to states in the state
space of the problem.

v Expanding the current state is done by applying each legal action to the current state,
thereby generating a new set of states

v In this case, we add some branches from the parent node, leading to generate some new
child nodes.

v Then we need to choose which of the possibilities (new children) to consider further

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 1
Route-finding Problem (2/2)
v When reaching a leaf node, i.e., a node with no children below its level, the next step is to
go back (back track) to choose.

v The process of expanding or exploring nodes on the tree continues until either a
solution is found or there are no more states (nodes) to expand or visit.

v Search algorithms all share this basic structure; however, they vary primarily according to
how they choose which state to expand next–the so-called search strategy.

v In searching problems, the procedure is that the algorithm is systematically


examining the states in the state space, one by one, until it finds a solution.

v Nodes are the data structures from which the search tree is constructed

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 2
Route-finding Problem
v The figure below shows a sequence of search trees generated by a graph search
◆ At each stage, each path is extended by one step.

v The separation property of Graph-Search, illustrated on a rectangular-grid problem.


◆ In (a), the root in the middle has been expanded.
◆ In (b), one leaf node has been explored.
◆ In (c), the remaining adjacent nodes of the root have been expanded in clockwise order.

(a) (b) (c)


EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 3
Measuring Problem-Solving Performance
v Before we get into the design of specific search algorithms, we need to consider the
criteria that might be used to choose among them. We can evaluate an algorithm’s
performance in four ways:
◆ Completeness: Is the algorithm guaranteed to find a solution when there is one?
◆ Optimality: Does the strategy find the optimal solution?
◆ Time complexity: How long does it take to find a solution?
◆ Space complexity: How much memory is needed to perform the search?

v The typical measure is the size of the state space graph, 𝑽 + 𝑬


where
𝑽 is the set of vertices (nodes) of the graph and 𝑬 is the set of edges (links).

v Evaluating the effectiveness of a search algorithm


◆ we can consider just the search cost, which typically depends on the time complexity but can also include
a term for memory usage, or
◆ we can use the total cost, which combines the search cost and the path cost of the solution found.
◆ For the problem of finding a route, the search cost is the amount of time taken by the search
and the solution cost is the total length of the path
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 4
Uninformed Search Strategies
v Uninformed search is also called blind search because it has no additional information
about states beyond that provided in the problem definition.

v All they can do is generating successors and distinguish a goal state from a non-goal state.

v All search strategies are distinguished by the order in which nodes are expanded.

v Breadth-first Search (BFS)


◆ BFS algorithm is a simple strategy in which the root node is expanded first
◆ Then all the successors of the root node are expanded
◆ Next, their successors, and so on.
◆ In general, all the nodes are expanded at a given depth in the search tree before any
nodes at the next level are expanded.
◆ This can be achieved very simply by using a FIFO queue for the data structure.

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 5
Breadth-first Search (BFS) Algorithm
v As show in the figure below, BFS algorithm visit all nodes at a level before moving to visit
and explore the nodes at the lower level.
v At each stage, the node to be expanded next is indicated by a marker.

The progress of the search on a simple binary tree.

v The nodes of a graph problem (tree) need to be stored somewhere

v Theses need to be stored in such a way that the search algorithm can easily choose the
next node to expand according to its preferred strategy.
v The appropriate data structure for this is a queue
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 6
Procedure of Breadth-first Search Algorithm
v Pseudo algorithm of breadth-first search
Queue (FIFO)
Closed Open
......
list list
Begin
1- Place the starting node in a queue;
2- Repeat
delete the visited node in the queue to get a new front node;
if (the new front element of the queue = goal)
return success and stop;
Else
begin
insert the children of the explored node; /* we put them on
the right side in the open list to be visited next */
if (no any nodes remained to visit)
Exit; /* until the queue become empty */
End;
End;

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 7
Breadth-first Search Algorithm ⎼ Example #1
✏ Apply the breadth-first search algorithm on the following graph, where the start state is node (A) and
the desired goal state is node (G), show the successive values of open and closed, and the traversed
path.
ANS: For the next iteration, node (A) replace by its Children [BCD] in the open list, then move it the closed list.
1
Iteration
X Goal Open Closed A
#
0 Ø ⎼ G [A] []
1 Ø A G [BCD] [A]
2 Ø B G [CDEF] [BA] 2 B 3 C 4
D
3 Ø C G [DEFG] [CBA]
4 Ø D G [EFG] [DCBA]
E F G
5 Ø E G [FGHI] [EDCBA] 5 6 7
6 Ø F G [GHIJ] [FEDCBA]
7 Ø G G The goal is achieved I
H J
◆ Open list: contains the successors of a node that is being
visited. Ø Traversed path = ABCDEF à G
◆ Closed list: contains the nodes that have been already Ø Thus, the required data structure here is
explored (visited) a Queue

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 8
Breadth-first Search Algorithm ⎼ Example #2
✏ Apply the breadth-first search algorithm on the following graph, where the start state is node (A) and
the desired goal state is node (O), show the successive values of open and closed, and the traversed
path.
ANS: For the next iteration, node (A) replace by its Children [BCD] in the open list, then move it the closed list.
Iteration 1
X Goal Open Closed
# A
0 Ø ⎼ O [A] []
1 Ø A O [BCD] [A]
2
B 3
C 4 D
2 Ø B O [CDE] [BA]
3 Ø C O [DEGH] [CBA]
4 Ø D O [EGH] [DCBA] E 6
G H
5 7
5 Ø E O [GHKN] [EDCBA]
6 Ø G O [HKNR] [GEDCBA]
7 Ø H O [KNROP] [HGEDCBA] K 9
N 10
R 11 O P
8 12
8 Ø K O [NROP] [KHGEDCBA]
9 Ø N O [ROP] [NKHGEDCBA] J U
10 Ø R O [OP] [RNKHGEDCBA]
Ø Traversed path = ABCDEGHKNR à O
11 Ø O O The goal is achieved Ø Thus, the required data structure here is a Queue
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 9
Depth-first Search (DFS) Algorithm
v Depth first search algorithm generates nodes and compares them to the desired goal
along the largest depth of the tree.

v It moves up (back track) to the parent of the last visited node (child), only when no further
nodes can be generated below the visited last node (a leaf has been reached).

v After moving up to the parent, the algorithm starts generating new nodes (new unvisited
children).

v This concept is repeated recursively to visit each node in the tree until the desired goal
achieved.

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 10
Depth-first Search (DFS) Algorithm
v Applying the depth-first search algorithm on the following graph

1
A
insertion deletion
2
B C D TOS

3
E F G
6

forward
4 H I J track Stack
5 7
back
track

v Insertion and deletion are done at one end (same end); therefore, the new nodes (children)
of a vertex will be added on the left in the open list.
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 11
Procedure of Depth-first Search Algorithm
v Pseudo algorithm of depth-first search

Begin
1- Push the starting node at the stack, pointed to by the top
of stack (TOS);
2- while the stack is not empty do
Begin
pop stack to get TOS element;
if (TOS element = goal)
return success and stop;
Else
push the children of the TOS element (node) in any order
in the stack;
End while;
End;

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 12
Depth-first Search Algorithm ⎼ Example #1
✏ Apply the depth-first search algorithm on the following graph, where the start state is node (A) and the
desired goal state is node (G), show the successive values of open and closed, and the traversed
path.

ANS: 1
A
Iteration
X Goal Open Closed 2
#
0 Ø ⎼ G [A] [] B 8 C D
10
1 Ø A G [BCD] [A]
2 Ø B G [EFCD] [BA] 3
E F G
3 Ø E G [HIFCD] [EBA] 6
9
4 Ø H G [IFCD] [HEBA]
forward back
5 Ø I G [FCD] [IHEBA]
4 H I J track track
6 Ø F G [JCD] [FIHEBA] 7
5
7 Ø J G [CD] [JFIHEBA]
8 Ø C G [GD] [CJFIHEBA] Traversed path = ABEHIFJC à G
9 Ø G G The goal is achieved Ø Thus, the required data structure here is a Stack

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 13
Depth-first Search Algorithm ⎼ Example #2
✏ For the graph tree show on the right, apply the depth-first search algorithm, where the start state is
node (A) and the desired goal state is node (G), show the successive values of open and closed, and
the traversed path.

ANS: 1

A
Iteration Open Closed
X Goal
# (not yet) (visited)
2
0 Ø ⎼ G [A] []
B 6
F C 9
D
1 Ø A G [BFCD] [A]
2 Ø B G [EFCD] [BA]
3 7
3 Ø E G [HIFCD] [EBA]
E J G
4 Ø H G [IFCD] [HEBA] 8
5 Ø I G [FCD] [IHEBA]
6 Ø F G [JGCD] [FIHEBA] I forward back
4 H track
track
7 Ø J G [GCD] [JFIHEBA] 5
8 Ø G G The goal is achieved
Traversed path = ABEHIFJ à G
Ø Thus, the required data structure here is a stack

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 14
Differences between Depth and Breadth Search algorithms

# Depth-first Search Breadth-first Search


Starting at the root, then proceeds to the Explores the search space in fashion of level by
1
depth of tree. level.
Work even in the trees which have infinity deep
2 Bounded by a level.
tree nodes.
Sometimes cannot be used because of time
3 Require more storage (high complexity).
& space consuming.
Not optimal solution since it has exponential Optimal solution, requires less searching time,
4
time complexity. especial when the desired goal is close to the root.
5 Very expensive. Less expensive.
6 Required data structure is stack or LIFO. Required data structure is queue or FIFO.
Not always get the solution with constraints,
7 Guaranteed reach the goal.
the level is bounded.
Preferred when the goal is far away from
8 It is preferred when the goal near the start state.
start.
More efficient for search space with many
branching because it does not have to keep
9 Discard the duplicated states.
all the nodes at a given level on the open
list.
10 Nodes to the left of tree are visited first. All nodes left & right are visited in any level.
11 Backtracking needed. No backtracking required.
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 15
Stack Vs. Queue
v A stack, or Last-In-First-Out (LIFO), is a data structure that supports the operations push
and pop
◆ Push: to save an entry
◆ Pop: to retrieve and remove the entry that was pushed in the stack lastly.

v A queue, or First-In-First-Out (FIFO), is a data structure that supports enqueue and


dequeue operations
◆ Enqueue: to save an entry
◆ Dequeue: unlike the pop of the stack, here dequeue retrieves (removes) the entry that was
pushed in the queue first.

# Stack Queue
1 Last-In-First-Out (LIFO) First-In-First-Out (FIFO)
Items can be added or removed only at
One end is always used to insert data (enqueue)
2 and from one end. Stack instructions are
and the other is used to remove data (dequeue).
push & pop
EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 16
Searching Techniques of Graph Tree ⎼ Classwork #1
✏ In terms of search cost and solution cost, which algorithm the breadth or the depth search
will perform better to search a tree that has so many branches? Elaborate on the answer.

✏ Apply both searching algorithms that have been learned in this lecture on the graph tree
illustrated on the next slide, where the start state is node (A) and the desired goal state is
node (O), show the successive values of open and closed, and the traversed path. Then
compare between the obtained results.

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 17
Searching Techniques of Graph Tree ⎼ Classwork #1
Tree 1:
A

B C D

E F G

K H M N P

L I J
O U

EECIE20-S4305 Intelligence Systems & Software Engineering: Search methods for route-finding problems Slide 18
End of Lecture 15

You might also like