0% found this document useful (0 votes)
23 views6 pages

AI Exp3

Artificial intelligent experiment implementation

Uploaded by

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

AI Exp3

Artificial intelligent experiment implementation

Uploaded by

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

EXPERIMENT NO.

Aim of the Experiment: -


Program on uninformed search methods.

Lab Outcome: -
CSL604.2: Understand and implement uninformed search algorithms

Date of Performance:

Date of Submission:

Implementation Understanding Punctuality and Total Marks


Discipline (15)
(05) (05)
(05)

______________________________
Practical In charge
EXPERIMENT NO. 03

Aim: Program on uninformed search methods.

Theory:

 Problem solving begins with definition of problems and their solutions.


 Several general-purpose search algorithms can be used to solve these problems.
 Uninformed search algorithms are algorithms that are given no information about
problem other than its definition.
 Informed search algorithms are given some information on where to look for
solutions.
 Based on the search problems we can classify the search algorithms into uninformed
(Blind search) search and informed search (Heuristic search) algorithms.

Uniformed Search

 They don’t have any additional information.


 The information is only provided in the problem definition.
 The goal state can be reached using different order and length of actions.
 Examples of uninformed search include depth first search (DFS) and breadth first
search (BFS).
 It doesn’t use the knowledge in the process of searching.
 It takes more time to show the solution.
 It is always complete.
 It is expensive.
 It consumes moderate time.
 There is no suggestion regarding finding the solution.
 It is lengthy to implement.
Breadth-first Search

 Breadth-first search is the most common search strategy for traversing a tree or graph.
This algorithm searches breadthwise in a tree or graph, so it is called breadth-first
search.
 BFS algorithm starts searching from the root node of the tree and expands all
successor node at the current level before moving to nodes of next level.
 The breadth-first search algorithm is an example of a general-graph search algorithm.
 Breadth-first search implemented using FIFO queue data structure.

Algorithm:

1. Enter starting node on Queue


2. If Queue is empty return fail and stop
3. If first element is goal node then return success and stop ELSE
4. Remove and expand the first element from the queue and place children at the end of
the queue.
5. Goto step 3.

Example:

In the above tree structure, we have shown the traversing of the tree using BFS algorithm
from the root node S to goal node K. BFS search algorithm traverse in layers, so it will follow
the path which is shown by the dotted arrow, and the traversed path will be:
S---> A--->B---->C--->D---->G--->H--->E---->F---->I---->K

Depth-first Search

 Depth-first search is a recursive algorithm for traversing a tree or graph data


structure.
 It is called the depth-first search because it starts from the root node and follows
each path to its greatest depth node before moving to the next path.
 DFS uses a stack data structure for its implementation.
 The process of the DFS algorithm is similar to the BFS algorithm.

Algorithm:
1. Enter the root node on the stack
2. Do until stack is not empty
3. Remove Node
a. if node=goal then stop
4. push all children of the node in stack

Example:

In the below search tree, we have shown the flow of depth-first search, and it will follow the
order as:
Root node--->Left node ----> right node.
It will start searching from root node S, and traverse A, then B, then D and E, after traversing
E, it will backtrack the tree as E has no other successor and still goal node is not found. After
backtracking it will traverse node C and then G, and here it will terminate as it found goal
node.

Depth-Limited Search Algorithm

 A depth-limited search algorithm is similar to depth-first search with a predetermined


limit. Depth-limited search can solve the drawback of the infinite path in the Depth-
first search.
 In this algorithm, the node at the depth limit will treat as it has no successor nodes
further.
 Depth-limited search can be terminated with two Conditions of failure:
 Standard failure value: It indicates that problem does not have any solution.
 Cutoff failure value: It defines no solution for the problem within a given depth limit.

Implementation:

def bfs(graph, start):


visited = set()
queue = [start]
while queue:
vertex = queue.pop(0)
if vertex not in visited:
print(vertex, end=" ")
visited.add(vertex)
queue.extend(graph[vertex])

def dfs(graph, start):


visited = set()
stack = [start]
while stack:
vertex = stack.pop()
if vertex not in visited:
print(vertex, end=" ")
visited.add(vertex)
stack.extend(reversed(graph[vertex]))

def dls(graph, start, depth, max_depth):


if depth <= max_depth:
print(start, end=" ")
for neighbor in graph.get(start, []):
dls(graph, neighbor, depth + 1, max_depth)

graph = {
0: [1, 2, 3],
1: [4, 5],
2: [6],
3: [7, 8],
4: [9],
5: [],
6: [],
7: [10],
8: [],
9: [],
10: []
}

print("BFS Traversal:")
bfs(graph, 0) # Starting from vertex 0

print("\nDFS Traversal:")
dfs(graph, 0) # Starting from vertex 0

print("\nDLS Traversal:")
dls(graph, 0, 0, 2) # Starting from vertex 0 with maximum depth 2

Graph as input:

Output:

Conclusion: Hence BFS, DFS, Depth limited search algorithm implemented successfully.

You might also like