Comparative Study and Analysis of Uninformed Search Algorithms
Comparative Study and Analysis of Uninformed Search Algorithms
BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE & ENGINEERING
With Specialization in
Oil and Gas Informatics
by
Department of Informatics
School of Computer Science
University of Petroleum & Energy Studies
i
Bidholi, Via Prem Nagar, Dehradun, UK
December – 2019
CANDIDATE’S DECLARATION
I/We hereby certify that the project work entitled “ Comparative Study and Analysis of
Uninformed search Algorithms” in partial fulfilment of the requirements for the award of the
Degree of BACHELOR OF TECHNOLOGY in COMPUTER SCIENCE AND ENGINEERING
with specialization in OIL AND GAS INFORMATICS and submitted to the Department of
Informatics at School of Computer Science, University of Petroleum & Energy Studies,
Dehradun, is an authentic record of my/ our work carried out during a period from August,2019
to November, 2019 under the supervision of Dr. Kingshuk Shrivastava, Assistance
Professor, Department of Informatics
The matter presented in this project has not been submitted by us for the award of any
other degree of this or any other University.
This is to certify that the above statement made by the candidate is correct to the best of
my knowledge.
ii
School of Computer Science
University of Petroleum & Energy Studies
Dehradun – 248 001 (Uttarakhand)
ACKNOWLEDGEMENT
We wish to express our deep gratitude to our guide Dr Kingshuk Shristava, for all advice,
encouragement and constant support he has given us throughout our project work. This work
would not have been possible without his support and valuable suggestions.
We sincerely thank our respected Head of the Department, Dr Thipendra Pal Singh, for his
great support in doing our minor project in at SoCS.
We are also grateful to Dr Manish Prateek, Dean SoCS, for giving us the necessary facilities to
carry out our project work successfully.
We would like to thank all our friends for their help and constructive criticism during our project
work. Finally, we have no words to express our sincere gratitude to our parents who have
shown us this world and for every support, they have given us.
iii
ABSTRACT
The search process is a basic task in every computer application wherein the state-space
search is one of the approaches to handling the job. It intends to find all possible states for a
given problem with the desired properties which acts upon the given set of states. Informed
search and Uninformed search are the two broad categories of state-space search, this project
is based upon the searching techniques placed under the second category of state-space
search, The Un-Informed search. The two most valuable resources for any optimizing
algorithms are time and memory. This project will be implemented taking these two as the
base and an optimized algorithm will be crafted.
iv
TABLE OF CONTENTS
1. Introduction 1
3. Problem Statement 5
4. Objective 5
5. Design 6-8
5.1 Methodology 6
5.2 Algorithms of the project 7-8
6. Implementation 9-21
6.1 Pseudocode & Flow Chart 9-12
6.2 SWAT Analysis 13-15
6.2 Output Screen 16-17
6.3 Result Analysis p18-21
9. References 31
v
LIST OF FIGURES
1. Chapter 1 1-3
Fig. 1.1 DFS Example 1
Fig. 1.2 BFS Example 2
Fig. 1.3 DLS Example 3
Fig. 1.4 IDDFS Example 3
2. Chapter 6 9 - 12
Fig 6.1 Flow Chart (DFS) 9
Fig 6.2 Flow Chart (BFS) 10
Fig 6.3 Flow Chart (DLS) 11
Fig 6.4 Flow Chart (IDDFS) 12
Fig 6.5 Output DFS (x64 bits) 16
Fig 6.6 Output BFS (x64 bits) 16
Fig 6.7 Output DLS (x64 bits) 16
Fig 6.8 Output IDDFS (x64 bits) 16
Fig 6.9 Output BFS (x32 bits) 26
Fig 6.10 Output DFS (x32 bits) 26
Fig 6.11 Output DlS (x32 bits) 27
Fig 6.12 Output IDDFS (x32 bits) 27
vi
LIST OF TABLES
1. Chapter 6 13 - 15
Table 6.2.1 DFS SWAT Analysis 13
Table 6.2.2 BFS SWAT Analysis 13 - 14
Table 6.2.3 DLS SWAT Analysis 14 - 15
Table 6.2.4 IDDFS SWAT Analysis 15
vii
1. INTRODUCTION
Addressing the aspect of a problem-solving approach, one is under a particular situation and
wants to be in the desired situation, so what comes out as the task is to make a series of
decisions or the series of moves which will transform the given situation into the desired
situation. A search can be performed in many different spaces as the given state and the goal
state likewise, several other states lying in between the two, the given and the goal state. Search
is performed over the state spaces to end up at the desired solution when the series of decision is
not known. There are two types of state-space searches, informed search and uninformed search.
Area of interest of this project lies around uninformed search under state-space search, which is
also known as Blind search as it is unaware of the search space and can only distinguish between
a goal state or a non-goal state. Under some circumstances, however, only a criterion is Goal
which is given as a form of the Boolean objective function. The method other than, that this
approach follows, will then not be able to descend a gradient anymore and degenerate to random
walks
Here, the uninformed search is a viable alternative since they do not require or take into
consideration any knowledge about the special nature of the problem (apart from the knowledge
represented by the expand operation, of course). Such algorithms are very general and can be
applied to a wide variety of problems. Their common drawback is that search spaces are often
very large. Without the incorporation of information in the form of heuristic functions, for
example, the search may take very long and quickly becomes infeasible. Various algorithms
come under uninformed searches like Breadth-First Search, Depth First Search, Depth-Limited
Search, Depth First Iterative Deepening Search, Random Walks, and Bidirectional Search. This
Project takes into consideration, four major algorithms that are Breadth-First Search, Depth First
Search, Depth-Limited Search, and Depth First search with Iterative Deepening.
viii
2. Related Study
Set of all possible states for a given problem is known as State Space of a problem and
searching is performed over those state spaces to obtain the desired solution. State-space search
is implicit that is the goal nodes is not represented as an explicit object but rather are determined
algorithmically from some more concise input.
There are two types of state-space searches, informed search and uninformed search. Area of
interest of this project lies around uninformed search under state-space search.
Uninformed search, which is also known as Blind search as it is unaware of the search space
and can only distinguish between a goal state or a non-goal state. It is a class of general-purpose
search algorithm which operates in brute force-way. Following are the various types of the
uninformed search algorithm.
ix
Figure 1.1
x
Figure 1.2
xi
Figure 1.3
Figure 1.4
3. Problem Statement
Searching is carried out to retrieve information stored within the massive data structures, here
efficiency becomes a major issue. There exist certain problems which tend to hinder the
efficiency of the search algorithms which are taken under consideration in this project. These
Problems are: -
1. The searching of the node in DFS algorithm works well but when the target node lies on
the right side of the tree the result will not be optimal.
2. The searching of the node in the BFS algorithm overcomes the problem faced in the DFS
algorithm but its memory consumption is much greater than DFS.
xii
3. The searching of a node in DLS algorithm overcomes the problem which is faced in both
DFS and BFS algorithm by introducing a limit on the level of search but to find that limit
the tree should be solved manually.
4. Objective
1. Breadth-First Search
3. Depth-Limited Search
The project aims to overcome the above-stated problems by analysis as well as fair
execution. The Iterative Deepening Depth First Search is performed to find the level
which then passed to Depth-Limited Search for optimal search
5. Design
5.1 Methodology
Step 6. Testing
5.2 Algorithms
5.2.1 DFS
5.2.2 BFS
xiv
}
void dequeue () // * DEQUEUE-REMOVING ELEMENTS*
{
if(rear>=front)
{
tree *root=(tree *)(intptr_t)queue[front];
printNode(root);
front++;
enqueue(root->left);
enqueue(root->right);
}
}
void BFS (tree *root) // * BFS Function *
{
If (root! =NULL)
{
enqueue(root);
do
{
Dequeue ();
} while (front<=rear);
}
}
5.2.3 DLS
xv
5.2.4 IDDFS
}
}
}
6. IMPLEMENTATION
6.1 Pseudo Code & Flow Chart
6.1.1 DFS
Function DFS (struct node *root):
IF (root! = NULL):
xvi
Print (root->data);
IF (search==root->data):
Print (The goal is found);
Exit ();
ENDIF
DFS (root->left);
DFS (root->right);
ENDIF
ENDFUNCTION
Fig 6.1
6.1.2 BFS
xvii
DO:
Dequeue (root); // Removing the elements into the queue
WHILE (front <= rear)
ENDIF
ENDFUNCTION
Fig 6.2
6.1.3 DLS
Function DLS (struct node *root,int8_t i, int8_t limit ):
xviii
IF (root! = NULL):
WHILE(i <limit):
Print (root->data);
IF (search==root->data):
Print (The goal is found);
Exit ();
ENDIF
DLS (root->left, i, limit-1);
DLS (root->right, i, limit-1);
BREAK;
ENDWHILE
ENDIF
ENDFUNCTION
Fig 6.3
6.1.4 IDDFS
xix
Function IDDFS (struct node *root,int8_t limit):
IF (root! = NULL):
IF (limit == 1):
Printf(“%d”, root->data);
ENDIF
IF (search == root->data)
Printf(“The goal is found”);
ENDIF
ELSEIF(limit>1)
IDDFS(root->left,limit-1);
IDDFS(root->left,limit-1);
ENDIF
ENDFUNCTION
xx
Fig 6.4
6.2 SWAT Analysis
6.2.1 DFS
INTERNAL FACTORS
STRENGTHS (+) WEAKNESSES (–)
1. The number of nodes to be stored in memory is 1. In some cases, the optimized result is not being
comparatively less. obtained through this algorithm.
2. Less number of nodes are stored so less memory 2. The algorithms start visiting the left child of the tree
is required. and explore them and then come to the right child.
3. The result obtained through this algorithm is
optimized in most of the cases.
4. The algorithm is implemented through the stack.
EXTERNAL FACTORS
Table 6.1
6.2.2 BFS
INTERNAL FACTORS
xxi
STRENGTHS (+) WEAKNESSES (–)
1. The searching style is improvised in this 1. The number of nodes to be stored is increased which
algorithm. will be depending on the branching factor of the tree.
2. This algorithm will always produce the 2. The increase in the number of nodes requires more
optimized result according to the implementation. memory.
3. The algorithm visits right child immediately after
visiting the right child of the tree.
4. The algorithm is implemented through the
Queue.
EXTERNAL FACTORS
Table 6.2
6.2.3 DLS
INTERNAL FACTORS
STRENGTHS (+) WEAKNESSES (–)
1. The number of nodes to be traversed is less. 1. The main problem is to calculate the height of the
graph manually.
2. The whole graph need not be traversed like in-
depth and breadth-first search. 2. The problem should be solved before to execute
3. By introducing a limit to the graph increases the depth limit search.
speed of execution.
xxii
EXTERNAL FACTORS
Table 6.3
6.2.4 IDDLS
INTERNAL FACTORS
STRENGTHS (+) WEAKNESSES (–)
1. It is a composition of both depth and breadth- 1. It re-traverses each node repeatedly, after
first search. incrementing the height.
2. This algorithm has overcome the weakness of
depth limit search by incrementing the height from
start.
3. It takes on advantages of depth and breadth limit
search along with the limit of height.
EXTERNAL FACTORS
Table 6.4
6.3 Output Screen
xxiii
6.3.1 Windows (x64 bit)
6.3.1.1 DFS
(Fig 6.5)
6.3.1.2 BFS
(Fig 6.6)
xxiv
6.3.1.3 DLS
(Fig 6.7)
6.3.1.4 IDDFS
xxv
(Fig 6.8)
6.3.2 Windows (x32 bit)
6.3.2.1 DFS
(Fig 6.9)
6.3.2.2 BFS
xxvi
(Fig 6.10)
6.3.2.3 DLS
(Fig 6.11)
xxvii
6.3.2.4 IDDFS
(Fig 6.12)
Case 1: -When the search algorithms are executed in x64 bits of windows the first set of
the result are obtained. For the total 15 entered values if the value to be searched is ‘96’
the time taken by respective algorithm decreases as we move from BFS to DLS to DFS
and finally to IDDFS.
xxviii
x64 bit
36
35
34
33
32
31
30
29
28
27
BFS DFS DLS IDDFS
Case 2: - When the same search algorithms are executed in x32 bits of windows the
second set of the result are obtained. For the total 15 entered values if the value to be
searched is same as case 1 i.e ‘96’ to provide the same parameter the time taken by
respective algorithm again decreases as we move from DLS to BFS to DFS and finally to
IDDFS.
xxix
x32 bit
35
30
25
20
15
10
0
BFS DFS DLS IDDFS
After studying the above stated two case we can conclude that the time taken by IDDFS in
searching through the tree is always less as compared to the other algorithm. Thus proving us
with an optimized search algorithm to traverse through the tree in minimum period.
xxx
8. Appendix I Project Code
/*
* IMPLEMENTATION OF DFS BFS DLS and IDFS ALGORITHMS *
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h> // We have imported inttypes to lessen the memory
usage as much as possible
#include <stdint.h> // This is imported to type cast the integer to pointer
conversion which vary in 32 bit and 64 bit
// * Variable Declarations *
int queue[10];
int8_t front=0,rear=-1;
int search;
static int8_t n=0,dfs_found=0,dls_found=0,ids_found=0;
static int8_t temp=0;
// * Structure Declaration *
xxxi
// * Function Prototype *
void printNode(searchtree *root); // We have named the structure with name "searchtree" and
will be using this in place of "struct node"
void enqueue(searchtree *root);
void dequeue();
void BFS(searchtree *root);
void DFS(searchtree *root);
void DLS(searchtree *root,int8_t i,int8_t limit);
void IDDS(searchtree *root,int8_t limit);
void height(searchtree *root);
// * Construction of tree *
xxxii
else
{
if(value>root->data)
{
root->right=insert(root->right,value);
}
}
return root;
}
};
xxxiii
bfs_found=0;
}
}
// * Queue *
if(root!=NULL)
{
rear++;
queue[rear]=(uintptr_t)(root);
}
}
xxxiv
{
enqueue(root);
do
{
dequeue();
}while(front<=rear);
}
}
// * DFS Function *
xxxv
{
while(i<limit)
{
printf("%d ",root->data);
if(search==root->data)
{
printf("The Goal node(%d) by DLS algo is found.....",search);
printf("\nThe program is being terminated......");
dls_found=1;
exit(0);
}
DLS(root->left,i,limit-1);
DLS(root->right,i,limit-1);
break;
}
}
}
xxxvi
if(lh>rh)
return (lh+1);
else
return (rh+1);
}
// * IDDFS Function *
xxxvii
}
}
// * Main function *
int main()
{
searchtree *root=NULL;
int8_t select,limit,height;
int i;
int insertnode;
xxxviii
break;
case 2:
printf("Enter the value to be searched with BFS Algorithm....");
scanf("%d",&search);
BFS(root);
break;
case 3:
printf("Enter the value to be searched with DFS Algorithm....");
scanf("%d",&search);
DFS(root);
if(dfs_found==temp)
{
printf("\nThe goal node(%d) is NOT found by DFS
Algorithm.....",search);
printf("\nYou can try again:)");
dfs_found=0;
}
break;
case 4:
printf("\nEnter the value to be searched by DLS Algorithm.....");
scanf("%d",&search);
printf("Enter the limit for the implementation of DLS
Algorithm....");
scanf("%d",&limit);
DLS(root,0,limit);
if(dls_found==0)
{
printf("\nThe goal node(%d) is NOT found by DLS
Algorithm.....",search);
printf("\nYou can try again:)");
dls_found=0;
xxxix
}
break;
case 5:
printf("Enter the value to be searched by IDFS Algorithm.......");
scanf("%d",&search);
height=level(root); // * Height is
been retrieved through this function
for(i=1;i<=height;i++)
{
IDDFS(root,i);
}
if(ids_found==0)
{
printf("\nThe goal node(%d) is NOT found by IDDFS
Algorithm.....",search);
printf("\nYou can try again:)");
ids_found=0;
}
break;
case 6:
printf("Ending the program.......");
exit(0);
default:
printf("* ERROR CASE...... PLEASE TRY AGAIN.....*");
break;
}
}
return 0;
}
xl
9. Reference
9.1 Artificial Intelligence, spring 2013, Peter Ljungl¨of; based on AIMA Slides c Stuart Russel
and Peter Norvig, 2004.
9.2 Columbia University, New York / CS /lectures /Uninformed search
9.3 University of Pennsylvania / CIS /lectures/Uninformed search
9.4 George F Luger. 2008. Artificial Intelligence Structures and Strategies for Complex
Problem Solving. 6 th Ed. Pearson. ISBN: 0321545893.
9.5 https://www.javatpoint.com/ai-uninformed-search-algorithms
9.6 http://intelligence.worldofcomputing.net/ai-search/depth-first-search
9.7 Artificial Intelligence by Saroj Kaushik, Cengage.
xli