Sunteți pe pagina 1din 34

Artificial Intelligence

Project Presentation
Submitted to :
Husne Farah
Lecturer
Dept. of CSE
The People’s University of Bangladesh, Dkaka-1207.
Submitted by:
Group 11:
Ilias Ahmed, ID #16339202142.
Mohammad Saiful Islam, ID #16339202030.
Mohammad Mosharaaf Hossain, ID #16339202141.
Md. Alauddin, ID #16339202029. 1
Problem Solving by Searching
Search Methods :
 Breadth-First-Search
 Depth-First-Search
 Best-First-Search

2
BFS:- Breadth first search
BFS is a graph search algorithm that begins at the root node and
explores all the neighbouring nodes. Then for each of those nearest
nodes, it explores their unexplored neighbour nodes, and so on, until it
finds the goal. It is implemented by using queue.

B C D

E F
Status=1(ready)
Status=2(waiting)

Status=3(processed)
3
L0 A

L1 B C D

E F
L2
Status=1
Status=2
Status=3
QUEUE
A
OUTPUT

4
L0 A

L1 B C D

E F
L2
Status=1

Status=2
Status=3
QUEUE
B C D
OUTPUT
A 5
L0 A

L1 B C D

E F
L2
Status=1

Status=2

Status=3
QUEUE

C D E
OUTPUT
A B 6
L0 A

L1 B C D

E F
L2
Status=1
Status=2

Status=3
QUEUE
D E F
OUTPUT
A B C 7
L0 A

L1 B C D

E F
L2
Status=1

Status=2

Status=3
QUEUE
E F
OUTPUT
A B C D 8
L0 A

L1 B C D

E F
L2
Status=1
Status=2

Status=3
QUEUE
F
OUTPUT
A B C D E 9
L0 A

L1 B C D

E F
L2
Status=1

Status=2

Status=3
QUEUE

OUTPUT
A B C D E F 10
A

B C D

E F

BFS of the graph

11
Algorithm of BFS:-

STEP 1:- Initialize the status of all nodes to ready


status (status =1).
STEP 2:- Insert the starting node into the queue
and set its status to waiting (status=2).
STEP 3:- Continue step 4 and 5 until the queue is
empty.
STEP 4:- Delete the front node from the queue
and set its status to processed (status=3).
STEP 5:- Insert all the neighboring nodes (whose
status is ready) of the deleted node into the queue
and set their status to waiting (status=2).
STEP 6:- Exit.
12
Features of BFS:-
Space complexity
Space complexity is proportional to the number of nodes at
the deepest level. Given a branching factor b and graph
depth d the space complexity is the number of nodes at the
deepest level, O(bd).
Time complexity
d
Time complexity of breadth-first search is O(b ).
Completeness
Breadth-first search is complete.
Proof of Completeness
If the shallowest goal node is at some finite depth say d,
breadth-first search will eventually find it after expanding all
shallower nodes.
Optimality
For unit-step cost, breadth-first search is optimal.
13
Applications of BFS:-
• Finding all connected components in a graph.

• Finding all nodes within one connected component.

• Finding the shortest path between two nodes u and v in an


unweighted graph.

• Finding the shortest path between two nodes u and v in a


weighted graph..

• Compute a spanning forest of a graph.

14
DFS:- Depth first search
DFS is an uninformed search that progresses by expanding the first
child node of the search tree that appears and thus going deeper and
deeper until a goal node is found, or until it hits a node that has no
children. Then the search backtracks, returning to the most recent node
it has not finished exploring. It is implemented using a stack.

B C D

E F G

I J

15
Stack

B C D

E F G

I J

A
Output

16
Stack

B C D

E F G

B
I J
C
D
Output
A
17
Stack

B C D

E F G E
F
I J
C
D
Output
A B
18
Stack

B C D

E F G I
F
I J
C
D
Output
A B E
19
Stack

B C D

E F G

F
I J
C
D
Output
A B E I
20
Stack

B C D

E F G

J
I J
C
D
Output
A B E I F
21
Stack

B C D

E F G

I J
C
D
Output
A B E I F J
22
Stack

B C D

E F G

I J

D
Output
A B E I F J C
23
Stack

B C D

E F G

I J

G
Output
A B E I F J C D
24
Stack

B C D

E F G

I J

Output
A B E I F J C D G
25
A

B C D

E F G

I J

DFS of the graph

26
Algorithm of DFS:-

STEP 1:- Initialize the status of all nodes to ready


status (status=1).
STEP 2:- Push the starting node into the stack
(status=waiting=2).
STEP 3:- Continue step 4 and 5 until the stack is
empty.
STEP 4:- Pop the top node from the stack and set its
status to processed state (status=3).
STEP 5:- Push all the successors whose status is
ready; of the popped node into the stack and set their
status to waiting (status=2).
STEP 6:- Exit.
27
Features of DFS:-
Space complexity
The space complexity is O(d) where d is the length of the
longest simple path in the graph.

Time complexity
Since in the worst case depth-first search has to consider all
paths to all possible nodes the time complexity of depth-first
search is O(bd).
Completeness
Depth-first search is not complete.

Optimality
Depth-first search is not optimal.

28
Applications of DFS:-

• Finding whether there exists a path between the given


vertices.

• Find the connected components of a graph.

• Topological sorting.

• We can specialize the DFS algorithm to find a simple cycle.

• Solving puzzles with only one solution, such as mazes.


(DFS can be adapted to find all solutions to a maze by only
including nodes on the current path in the visited set.)

29
Best-First Search:-

Best-first search is a search algorithm which explores


a graph by expanding the most promising node chosen
according to a specified rule

best-first search" to refer specifically to a search


with a heuristic that attempts to predict how close
the end of a path is to a solution.

30
Algorithm :-

1.Remove the best node from OPEN, call it n, add it to


CLOSED. 2. If n is the goal state, backtRACK path to n
2.(through recorded parents) and return path.
3. Create n's successors.
4. For each successor do:
a. If it is not in CLOSED and it is not in OPEN: evaluate it, add
it to OPEN, and record its parent.
b. Otherwise, if this new path is better than previous one,
change its recorded parent. i. If it is not in OPEN add it to
OPEN. ii. Otherwise, adjust its priority in OPEN using this new
evaluation.

31
S
5
2
6

C B A
13 10
14 8
7
G F E D
5
H 6
I
1 0 1
6

M L K
J
32
Open : Close :

S {}
A(2),C(5),B(6) s
C(5),B(6),E(8),D(10) S,A
B(6),H(7),E(8),D(10) S,A,C
H(7),E(8(,D(10) ,G(13),G(14) S,A,C,B
I(8),J(6),E(8),D(10),F(13),G(14) S,A,C,B,H
L(0),M(1),K(1),J(6),E(8),D(10),F(13),G(14) S,A,C,B,H,I
M(1),K(1),J(6),…………………..G(14)

33
34

S-ar putea să vă placă și