Skip to content

AhsanRaza05/Search-Algorithms-in-Artificial-Intelligence-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Search Algorithms in Artificial Intelligence

Table of Contents

Overview

Artificial Intelligence is the study of building agents that act rationally. Most of the time, these agents perform some kind of search algorithm in the background in order to achieve their tasks.

The objective of search procedure is to discover a path through a problem spaces from an initial configuration to a goal state.

The Solution to a search problem is a sequence of actions, called the plan that transforms the start state to the goal state.

This plan is achieved through search algorithms.

How to Install and Run the Project

Method # 1: Download 'Executable (exe)' file from 'Portable App Folder' (Easy & Portable)

            No need to install anything but it is for WINDOWS OS  

Method # 2: Load and Execute Project in Eclipse IDE

            Eclipse IDE & JVM will be required.

Types of Searching Algorithms

App Screenshot

User Define Problem Assumption

Assumed Problem

Assume that above Graph will be used by User.

User Interface

1st Window

Fig-A: Selecting Algorithm

2nd Window

Fig-B: Selecting BFS and Defining the Graph

3rd Window

Fig-C: Selecting DFS and Defining the Graph

4th Window

Fig-D: Selecting DLS and Defining the Graph

5th Window

Fig-E: Selecting UCS and Defining the Graph

1) Uninformed Search

Also called as Blind Search or Brute Force Search.

Suitable For very limited Problem Space problems.

A blind search is a search that has no information about its domain. The only thing that a blind search can do is to distinguish a non-goal state from a goal state.

– Breadth-First search

– Depth-First search

– Uniform-Cost search

– Depth-First Iterative Deepening search

i) Breadth-First Search

Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures.

It starts at the tree root and explores the neighbor nodes first, before moving to the next level neighbors.

Breadth First Search explores the state space in a level by level fashion. Only when there are no more states to be explored at a given level then the algorithm move onto the next level.

BFS is complete. If there exists an answer, it will be found (b should be finite).

BFS is optimal (if cost = 1 per step). The path from initial state to goal state is shallow.

Time & Space Complexity = s O(b^d) Where "b" = Branch Factor (Number of nodes from root first expands on a set number of nodes, say b.)

& "d" = depth

Program Output

User Define Problem

Problem # 1

Traversing

Solution # 1_0 Solution # 1_i Solution # 1_ii

Searching

Solution # 1_0 Solution # 1_i

Pre Define Problems

Problem # 1

BFS Example Problem # 1

Problem # 1

Solution # 1_i Solution # 1_ii Solution # 1_iii

BFS Problem # 2

Problem # 2

Solution # 2_i Solution # 2_ii

BFS Problem # 3

Problem # 3

Solution # 3_i Solution # 3_ii Solution # 3_iii Solution # 3_iv

BFS Problem # 4

Problem # 4

Solution # 4_i Solution # 4_ii Solution # 4_iii

BFS Problem # 5

Problem # 5

Solution # 5_i Solution # 5_ii Solution # 5_iii Solution # 5_iv

ii) Depth-First Search

Depth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. One starts at the root and explores as far as possible along each branch before backtracking.

A depth first search begins at the root node (i.e. Initial node) and works downward to successively deeper levels.

An operator is applied to the node to generate the next deeper node in sequence. This process continues until a solution is found or backtracking is forced by reaching a dead end.

If you have deep search trees (or infinite – which is quite possible), DFS may end up running off to infinity and may not be able to recover.

Thus DFS is neither optimal nor complete

Time & Space Complexity = s O(b^d) {In some cases, DFS can be faster than BFS because it does not expand all nodes at a level}

Where "b" = Branch Factor (Number of nodes from root first expands on a set number of nodes, say b.)

& "d" = depth

Program Output

User Define Problem

Problem # 1

Traversing

Solution # 1_i Solution # 1_i Solution # 1_ii

Searching

Solution # 1_i Solution # 1_i

Pre Define Problem

Problem # 1

DFS Example Problem # 1

Problem # 1

Solution # 1_i Solution # 1_ii Solution # 1_iii

DFS Example Problem # 2

Problem # 2

Solution # 2_i Solution # 2_ii

DFS Example Problem # 3

Problem # 3

Solution # 3_i Solution # 3_ii Solution # 3_iii Solution # 3_iv

DFS Example Problem # 4

Problem # 4

Solution # 4_i Solution # 4_ii Solution # 4_iii

DFS Example Problem # 5

Problem # 5

Solution # 5_i Solution # 5_ii Solution # 5_iii Solution # 5_iv

iii) Depth-Limited Search

Depth-first search will not find a goal if it searches down a path that has infinite length. So, in general, depth-first search is not guaranteed to find a solution, so it is not complete.

This problem is eliminated by limiting the depth of the search to some value l. However, this introduces another way of preventing depth-first search from finding the goal: if the goal is deeper than l it will not be found.

Regular depth-first search is a special case, for which l=∞.

Depth limited search is complete but not optimal.

If we choose a depth limit that is too small, then depth limited search is not even complete.

The time and space complexity of depth limited search is similar to depth first search.

Program Output

User Define Problem

Problem # 1

Traversing

Solution # 1_0 Solution # 1_i

Searching

Solution # 1_i Solution # 1_i

Pre Define Problem

Problem # 1

DLS Problem # 1

Problem # 1

Solution # 1_i Solution # 1_ii

DLS Problem # 2

Problem # 2

Solution # 2_i Solution # 2_ii

iii) Uniform-Cost Search

Breadth-first search finds the shallowest goal state, but this may not always be the least-cost solution for a general path cost function.

Uniform cost search modifies the breadth-first strategy by always expanding the lowest-cost node rather than the lowest-depth node.

It maintain a "Priority Queue".

Program Output

User Define Problem

Problem # 1

Searching

Problem # 0 Problem # 1 Problem # 2

Pre Define Problem

Problem # 1

UCS Problem # 1

Problem # 1

Solution # 1_i Solution # 1_ii

UCS Problem # 2

Problem # 2

Solution # 2 Solution # 2

UCS Problem # 3

Problem # 3

Solution # 3_i Solution # 3_ii Solution # 3_iii Solution # 3_iv

2) Informed Search

Uninformed search strategies can find solutions to problems by systematically generating new states and testing them against the goal.

Unfortunately, these strategies are incredibly inefficient in most cases.

Uninformed search uses problem-specific knowledge—can find solutions more efficiently.

Heuristics are "rules of thumb", educated guesses, intuitive judgments or simply common sense.

A heuristic function, h(n), provides an estimate of the cost of the path from a given node to the closest goal state.

Must be zero if node represents a goal state.

– Greedy-Best-First search

– A * search

i) Greedy-Best-First Search

Depth first search is good because it allows a solution to be found without all competing branches to be expanded.

Breadth first search is good because it does not get trapped on dead-end paths.

Best First Search combines the advantages of the two.

At each step of the best first search process, we select the most promising of the nodes we have generated so far.

This is done by applying an appropriate heuristic function to each of them.

Greedy Best-First search tries to expand the node that is closest to the goal assuming it will lead to a solution quickly.

  • f(n) = h(n)

  • f(n) = Function that gives an evaluation of the state.

  • h(n) = The cost of getting from the current state to a goal state.

Features

The Greedy Best-First-Search algorithm works as uniform cost search, except that it has some estimate (called a heuristic) of how far from the goal any node is.

Instead of selecting the node closest to the starting point, it selects the node closest to the goal.

Greedy Best-First-Search is not guaranteed to find a shortest path.

However, it runs much quicker than uniform cost search algorithm because it uses the heuristic function to guide its way towards the goal very quickly

Program Output

User Define Problem

Problem # 1

Searching

Solution # 1_0 Solution # 1_i Solution # 1_i

Pre Define Problems

Problem # 1

GBFS Example Problem # 1

Problem # 1

Solution # 1_i Solution # 1_ii

GBFS Example Problem # 2

Problem # 2

Solution # 2_i Solution # 2_ii

i) A* Search

Greedy Search minimizes a heuristic h(n) which is an estimated cost from a node n to the goal state. However, although greedy search can considerably cut the search time (efficient), it is neither optimal nor complete.

Uniform Cost Search minimizes the cost g(n) from the initial state to n. UCS is optimal and complete but not efficient

** New Strategy: Combine Greedy Search and UCS to get an efficient algorithm which is complete and optimal. **

A search algorithm to find the shortest path through a search space to a goal state using a heuristic.

  • f(n) = g(n) + h(n)
  • f(n) = Function that gives an evaluation of the state.
  • g(n) = The cost of getting from the initial state to the current state.
  • h(n) = The cost of getting from the current state to a goal state.

Features

It is Efficient.

It is complete.

It is Optimal.

Program Output

User Define Problem

Problem # 1

Searching

Solution # 1_0 Solution # 1_i Solution # 1_i

Pre Define Problems

Problem # 1

ASS Example Problem # 1

Problem # 1

Solution # 1_i Solution # 1_ii Solution # 1_iii

ASS Example Problem # 2

Problem # 2

Solution # 1_i Solution # 1_ii Solution # 1_iii

Comparisions of All Algorithms

Comaprision

About

Contains the Programs of Topics study in Artificial Intelligence subject

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages