You are on page 1of 41

Unit I

Introduction
• Artificial Intelligence:
• Introduction,
• Typical Applications.
• State Space Search:
• Depth First Search
• Breadth First Search
• Depth Bounded DFS,
• Depth First Iterative Deepening.
• Heuristic Search:
• Heuristic Functions,
• Best First Search,
• Hill Climbing, Variable Neighborhood Descent, Beam Search, Tabu Search.
• Optimal Search:
• A * algorithm, Iterative Deepening A* ,
• Recursive Best First Search,
• Pruning the CLOSED and OPEN Lists
• Textbook:
1) Deepak Khemani, “A First Course in Artificial Intelligence”, McGraw
Hill Education(India), 2013, ISBN : 978-1-25-902998-1 2.
2) Elaine Rich, Kevin Knight and Nair, “Artificial Intelligence”, TMH,
ISBN-978-0-07- 008770-5
What is AI ?

AI = Artificial + Intelligence
(Non Natural) (Ability to understand, think and learn)

• Artificial Intelligence is the study of how to make computers do things which,


at the moment, people do better.
• Artificial Intelligence is the science and engineering of making intelligent
machines.
• Artificial Intelligence is the branch of computer science that is concerned with
the automation of intelligent behavior.
• Artificial Intelligence is concerned with the design of intelligence in an artificial
device.
• The term was coined by McCarthy in 1956 IN Dartmouth Conference.
Approaches of AI
• Four approaches of AI
1) Acting Humanly
2) Thinking Humanly
3) Acting Rationally
4) Thinking Rationally
1) Acting Humanly ( Turing Test Approach)
Can machine act like human???

The Turing Test, proposed by Alan Turing (1950),


was designed to provide a satisfactory operational
definition of intelligence.

The computer would need to possess the following


capabilities:

1) Natural Language Processing


2) Knowledge Representation
3) Automated Reasoning
4) Machine Learning
2) Thinking humanly: The cognitive modeling approach

• How machine can think like human?


Through introspection + through psychological experiments+ Brain Imaging= Cognitive science

• 3 ways:
• 1. Through Introspection : trying to catch our thoughts as they go by
• 2. Through psychological experiments: observing a person in action
• 3. Brain Imaging: Observing the brain in action.

• By help of cognitive science, we can design a machine which think like human
3) Thinking rationally: The “laws of thought” approach
• What is meant of Rationally?
• The ones on the right measure against an ideal performance measure called rationally.
• In other words thinking rationally means right thinking.
• E.g. 2+2=3 Wrong
2+2=4 Right
• How can machine think rationally?
• If machine is able to develop right logic, then machine can be able to think rationally.
• E.g.
Socrates is a man
All men are mortal.

Is Socrates is mortal?
Answer is Yes

• These laws of thought were supposed to govern the operation of the mind; their study initiated the
field called logic.
4) Acting rationally: The rational agent approach
• All computer programs do something, but computer agents are expected to do
more. They are
• Operate autonomously
• Perceive the environment
• Persist over a prolonged time period
• Adapt to change
• Create and pursue goals

• What is meant Acting Rationally?


• Where Machines likes to do right thing.
• e.g. move right
move left
Types of AI
1) Artificial narrow intelligence (ANI), which has a narrow range of abilities;
2) Artificial general intelligence (AGI) which is on par with human capabilities; or
3) Artificial super intelligence (ASI), which is more capable than a human.
• Artificial Narrow Intelligence (ANI) / Weak AI / Narrow AI:
Narrow AI is goal-oriented, designed to perform singular tasks and is very intelligent at
completing the specific task it is programmed to do. While these machines may seem
intelligent, they operate under a narrow set of constraints and limitations, which is why
this type is commonly referred to as weak AI.
• Artificial General Intelligence (AGI) / Strong AI / Deep AI
AGI can think, understand, and act in a way that is indistinguishable from that of a
human in any given situation. 
• Artificial Superintelligence (ASI)
ASI is where machines become self-aware and surpass the capacity of human
intelligence and ability. 
Applications area of AI

• Perception
–Machine vision
–Speech understanding
–Touch ( tactile or haptic) sensation
• Robotics
• Natural Language Processing
–Natural Language Understanding
–Speech Understanding
–Language Generation
–Machine Translation
• Planning
• Expert Systems
• Machine Learning
• Theorem Proving
• Symbolic Mathematics
• Game Playing
State Space Search
• Aspects of AI:
1) Problem Solving
2) Knowledge representation
3) Learning
4) Planning
• Problem Solving Aspect:

Problem Solution
Decisions, Techniques, methods, steps,

Problem Solving
Knowledge Base Search Techniques
State Space
Memory Based
Tree and Graph Searching Techniques
Rule Based
• State Space:
The state space of a problem is the set of all states reachable from the initial state
by executing any sequence of actions.

• State space search:


Searching in a given space of states.
Problem and Problem Spaces

• A problem can be defined formally by 5 components:


• The initial state that the agent starts in. For example, the initial state is node A.
• Actions: It is the set of actions that can be executed or applicable in all possible states.
• Successor Function: It is a function that returns a state on executing an action on the
current state
• Goal State: It is test to determine whether the current state is a goal state.
• Path cost: It is the cost associated with each step to be taken to reach to the goal state.
Real Life Examples
1. 8 Puzzle Problem
2 8 3 1 2 3
1 6 4 8 - 4
7 - 5 7 6 5

Start State Goal State

Actions: Up, Down. Left and Right

Path Cost: 4
2) Water Jug Problem

You are given two jugs, a 4-gallon one and a 3-gallon one, a pump which has
unlimited water which you can use to fill the jug, and the ground on which water
may be poured. Neither jug has any measuring markings on it. How can you get
exactly 2 gallons of water in the 4-gallon jug?

• Solution:
The state space for this problem can be described as the set of ordered pairs of
integers (x,y) Where,
X represents the quantity of water in the 4-gallon jug X= 0,1,2,3,4
Y represents the quantity of water in 3-gallon jug Y=0,1,2,3
Start State: (0,0)
Goal State: (2,y)
3. Tower of Hanoi Problem
Path Cost : 7
4) Missionaries and Cannibals Problem
Three missionaries   and three cannibals are on one side of a river, along with
a boat that can hold one or two people. Now we have   to find   a   way to  
get everyone   to the   other side,   without ever   leaving a   group of
missionaries in one place outnumbered by the cannibals in another side.
Initial State =>State(3,3,0)
Final State => State(0, 0, 1).

5) Tic Tac Toe Problem


Search Techniques
Informed Search Uninformed Search
It is also called as Guided search or Heuristics search It is also called as Blind search

It uses knowledge for the searching process. It does not uses knowledge for searching process

It finds solution more quickly It find solution slow as compared to informed search

It is highly efficient It is less efficient

Cost is low Cost is high

It consumes less time. It consumes more time

It provides the direction regarding the solution No suggestion is given regarding the solution

It is less lengthy while implementation It is more lengthy while implementation

A* algorithm, Hill Climbing, Steepest Hill climbing Best First Breadth First Search, Depth First Search, uniform cost search,
search, Greedy search Depth limited search
Breadth First Search
• What is the Breadth-First Search Algorithm?
Breadth-First Search algorithm is a graph traversing technique, where you select
a initial node (source or root node) and start traversing the graph layer-wise in
such a way that all the nodes and their respective children nodes are visited and
explored.
• Data Structure:
1) Queue
2) Open : Expanded
3) Closed : Visited
• Algorithm:
1. Begin
1. Open = [start];
2. Closed =[];
3. While open != [] do
4. Begin
1. Remove leftmost state from open(i.e. top of queue element) call it x;
2. If x is a goal then return success
3. Else
1. Begin
1. Generate children of x;
2. Put x on closed;
3. Put children on right end of open;
2. End
5. End
6. Return Failure
2.End
• Advantages:
• BFS will provide a solution if any solution exists.
• If there are more than one solutions for a given problem, then BFS will provide the minimal
solution which requires the least number of steps

• Disadvantages:
• It requires lots of memory since each level of the tree must be saved into memory to expand the
next level.
• BFS needs lots of time if the solution is far away from the root node.

• Time Complexity: O (bd)


• Space Complexity: O (bd)
• Completeness: 
• BFS is complete, which means if the shallowest goal node is at some finite depth, then BFS will
find a solution.
• Optimality: 
• BFS is optimal if path cost is a non-decreasing function of the depth of the node.
Depth First Search
• Depth first search (DFS) algorithm starts with the initial node of the graph G, and
then goes to deeper and deeper until we find the goal node or the node which
has no children. The algorithm, then backtracks from the dead end towards the
most recent node that is yet to be completely unexplored.
• Data Structure:
1) Stack
2) Open : Expanded
3) Closed : Visited
• Algorithm
1. Begin
1. Open = [start];
2. Closed = [];
3. While open != [] do
4. Begin
1. Remove left most state (i.e. top of the stack element) from open call it x;
2. If x is a goal then return success
3. Else
1. Begin
1. Generate children of x;
2. Put x on closed;
3. Put children on left end of open;
2. End
5. End
6. Return (failure)
2. End
• Advantages:
• DFS requires very less memory as it only needs to store a stack of the nodes on the path from
root node to the current node.
• It takes less time to reach to the goal node than BFS algorithm

• Disadvantages:
• There is no guarantee of finding the solution.
• DFS algorithm goes for deep down searching and sometime it may go to the infinite loop.

• Time Complexity: O (bd)


• Space Complexity: O (bd)
• Optimal: 
• DFS search algorithm is non-optimal, as it may generate a large number of steps or high cost to
reach to the goal node.
• Completeness: 
• DFS search algorithm is complete within finite state space as it will expand every node within a
limited search tree.
Uniform Cost Search
• Uniform-cost search is a searching algorithm used for traversing a weighted tree
or graph. This algorithm comes into play when a different cost is available for
each edge.
• The primary goal of the uniform-cost search is to find a path to the goal node
which has the lowest cumulative cost.
• Uniform-cost search expands nodes according to their path costs form the root
node.
• It can be used to solve any graph/tree where the optimal cost is in demand.
• A uniform-cost search algorithm is implemented by the priority queue. It gives
maximum priority to the lowest cumulative cost.
• Uniform cost search is equivalent to BFS algorithm if the path cost of all edges is
the same.
• Algorithm:
• Insert RootNode into the queue.
• Repeat till queue is not empty:
• Remove the next element with the highest priority from the queue.
• if the node is destination node then print the cost and the path and exit
• else insert all the children of removed elements into the queue with their cumulative cost
as their priorities.
• Advantages:
• Uniform cost search is optimal because at every state the path with the least cost is chosen.
• Disadvantages:
• It does not care about the number of steps involve in searching and only concerned about
path cost. Due to which this algorithm may be stuck in an infinite loop.
• Space and Time Complexity: O(b1 + [C*/ε])
Depth-Limited Search
• 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.
• Advantages:
• Depth-limited search is Memory efficient.
• Disadvantages:
• Depth-limited search also has a disadvantage of incompleteness.
• It may not be optimal if the problem has more than one solution.
• Time Complexity: Time complexity of DLS algorithm is O(bℓ).
• Space Complexity: Space complexity of DLS algorithm is O(b×ℓ).
Iterative Deepening Depth First Search (IDDFS)
• The iterative deepening algorithm is a combination of DFS and BFS algorithms. This
search algorithm finds out the best depth limit and does it by gradually increasing the
limit until a goal is found.
• This algorithm performs depth-first search up to a certain "depth limit", and it keeps
increasing the depth limit after each iteration until the goal node is found.
• This Search algorithm combines the benefits of Breadth-first search's fast search and
depth-first search's memory efficiency.
• The iterative search algorithm is useful uninformed search when search space is large,
and depth of goal node is unknown.
• Advantages:
• It combines the benefits of BFS and DFS search algorithm in terms of fast search and memory
efficiency.
• Disadvantages:
• The main drawback of IDDFS is that it repeats all the work of the previous phase.
• Time Complexity:
• Let's suppose b is the branching factor and depth is d then the worst-case
time complexity is O(bd).

• Space Complexity:
• The space complexity of IDDFS will be O(bd).
Bidirectional Search
• Bidirectional search algorithm runs two simultaneous searches, one form initial
state called as forward-search and other from goal node called as backward-
search, to find the goal node. Bidirectional search replaces one single search
graph with two small subgraphs in which one starts the search from an initial
vertex and other starts from goal vertex. The search stops when these two graphs
intersect each other.
• Bidirectional search can use search techniques such as BFS, DFS, DLS, etc.
• Advantages:
• Bidirectional search is fast.
• Bidirectional search requires less memory
• Disadvantages:
• Implementation of the bidirectional search tree is difficult.
• In bidirectional search, one should know the goal state in advance.
• Time Complexity: Time complexity of bidirectional search using BFS
is O(bd).

• Space Complexity: Space complexity of bidirectional search is O(bd).


Heuristic Function
• In heuristic search a node is selected for expansion based on an evaluation
function, f(n).
• Traditionally the node with the lowest evaluation is selected for expansion,
because the evaluation measures the distance to the goal.
• A key component of all these heuristic search algorithms is a heuristic function
denoted by h(n):
• h(n)= estimated cost of cheapest path from node n to the goal node.
• If n is the goal node then h(n)=0.
• For Example: 1. h = Number of tiles out of place
1

2. h2 = the sum of the distances of the tiles from their


goal positions.
Best First Search
• Best First Search is a way of combining the advantages of both depth first search
and breadth first search into a single method.
• One way of combining two is to follow a single path at a time, but switch paths
whenever some competing path looks more promising than the current one
does.
Algorithm:

• Start with OPEN containing just the initial state.


• Until a goal is found or there are no nodes left in OPEN do:
• Pick the best node in OPEN
• Generate its successors
• For each successor do:
• If it has not been generated before, evaluate it, add it to OPEN, and record its parent
• If it has been generated before, change the parent if this new path is better than the previous one. In
that case, update the cost of getting to this node and to any successors that this node may already have.
A* Algorithm
• A search technique that finds minimal cost solutions and is also directed towards
goal states is called "A* (A-star) search".
• g(n) = the cost of getting from the initial node to n
h(n) = the estimate, according to the heuristic function, of the cost of getting
from n to the goal node. That is,
f(n) = g(n) + h(n).
• For Example
Hill Climbing
• Hill climbing algorithm is a local search algorithm which continuously moves in the
direction of increasing elevation/value to find the peak of the mountain or best
solution to the problem. It terminates when it reaches a peak value where no
neighbor has a higher value.
• Hill climbing algorithm is a technique which is used for optimizing the
mathematical problems. One of the widely discussed examples of Hill climbing
algorithm is Traveling-salesman Problem in which we need to minimize the
distance traveled by the salesman.
• It is also called greedy local search as it only looks to its good immediate neighbor
state and not beyond that.
• A node of hill climbing algorithm has two components which are state and value.
• Hill Climbing is mostly used when a good heuristic is available.
• In this algorithm, we don't need to maintain and handle the search tree or graph
as it only keeps a single current state.
Problems in Hill Climbing
1. Local Maximum: A local maximum is a peak state in the landscape which is
better than each of its neighboring states, but there is another state also
present which is higher than the local maximum.
2. Plateau: A plateau is the flat area of the search space in which all the neighbor
states of the current state contains the same value, because of this algorithm
does not find any best direction to move. A hill-climbing search might be lost in
the plateau area.
3. Ridges: A ridge is a special form of the local maximum. It has an area which is
higher than its surrounding areas, but itself has a slope, and cannot be reached
in a single move.

You might also like