You are on page 1of 25

1.

Explain different search strategy


2. What is Heuristic Function?
3. Describe Hill climbing search with suitable example. List disadvantage of hill climbing process
4. Differentiate between Blind search and Heuristic search?
5. List steps involved in simple problem solving technique with suitable example?
6. Explain A* algorithm with suitable example?
7. Explain problem solving Agent with suitable example.
8. Differentiate between informed and uninformed search algorithms also explain iterative
deepening search in short.
9. Define state-space search in short.
10. Explain Best First search with an Example
11. Explain n queen problem with suitable example.
12. Explain Uniform Cost search and depth limited search algorithm with suitable example?
13. Explain 8 puzzle problem with suitable example
14. Write short note on Local search algorithm?
15. Describe Hill climbing with suitable example? List Disadvantages of Hill Climbing Process.
16. Describe Travelling salesman problem with an example.

Unit- II:- Problem Solving

Shree
Ramchandra college of Engineering, Lonikand Page 1
1. Explain different search strategy? [ Year 2023 5M] Ans:

Types of search algorithms

Based on the search problems we can classify the search algorithms into uninformed (Blind search) search
and informed search (Heuristic search) algorithms.

Uninformed/Blind Search:

The uninformed search does not contain any domain knowledge such as closeness, the location of the goal.
It operates in a brute-force way as it only includes information about how to traverse the tree and how to
identify leaf and goal nodes. Uninformed search applies a way in which search tree is searched without any
information about the search space like initial state operators and test for the goal, so it is also called blind
search. It examines each node of the tree until it achieves the goal node.

It can be divided into five main types:

-Breadth-first search Uniform cost search


Depth-first search Iterative deepening depth-
first search Bidirectional Search

Informed Search

Informed search algorithms use domain knowledge. In an informed search, problem information is
available which can guide the search. Informed search strategies can find a solution more efficiently than
an uninformed search strategy. Informed search is also called a Heuristic search.

Shree
Ramchandra college of Engineering, Lonikand Page 2
A heuristic is a way which might not always be guaranteed for best solutions but guaranteed to find a good
solution in reasonable time.

Informed search can solve much complex problem which could not be solved in another way.

An example of informed search algorithms is a traveling salesman problem.

1. Greedy Search
2. A* Search

2. What is Heuristic Function? [Year 2023 5 M] Ans:

Heuristic Function

a) A heuristic function in artificial intelligence, also known as a heuristic or simply a heuristic, is an


evaluation function used to estimate the cost or potential of reaching a goal state from a given state
in a problem-solving domain.

b) Heuristics are typically rules of thumb or approximate strategies that guide the search for a solution.
They provide a way to assess the desirability of different options without exhaustively exploring
every possibility.
c) Heuristics are used to make informed decisions in situations where it's computationally expensive
to search through all possible states or actions. They help prioritize the exploration of more
promising paths.

Search Algorithms:
a) In AI, search algorithms are methods for systematically exploring the state space of a problem to
find a solution. The state space represents all possible states that the system can be in, and the search
algorithm tries to navigate this space to reach a goal state.
b) There are various search algorithms, such as depth-first search, breadth-first search, A* search, and
others, which determine how to traverse the state space efficiently and effectively.
c) Heuristic functions are often used in combination with search algorithms to guide the search
process. When a heuristic function is applied to estimate the potential of different states, it can
significantly improve the efficiency and effectiveness of the search.

A* Search:
a) A* search is a widely used search algorithm in AI that combines a heuristic function with a cost
function to determine the next state to explore. It aims to find the optimal path from a start state to
a goal state while considering both the cost incurred so far and the estimated cost to reach the goal.
b) The heuristic function in A* search is crucial in guiding the exploration by providing a heuristic
estimate of the remaining cost. This estimate is often denoted as "h(n)" and, when combined with
the cost incurred so far (denoted as "g(n)"), it forms the function "f(n) = g(n) + h(n)."

Shree
Ramchandra college of Engineering, Lonikand Page 3
3. Describe Hill climbing search with suitable example. List disadvantage of hill climbing process.
[Year 2023 10M] Ans:

o 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. o 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 Travelingsalesman Problem in which we need to
minimize the distance traveled by the salesman.
o It is also called greedy local search as it only looks to its good immediate neighbor state and not
beyond that.
o A node of hill climbing algorithm has two components which are state and value.
o Hill Climbing is mostly used when a good heuristic is available. o In this algorithm, we don't need
to maintain and handle the search tree or graph as it only keeps a single current state.

Features of Hill Climbing:

Following are some main features of Hill Climbing Algorithm:

o Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The
Generate and Test method produce feedback which helps to decide which direction to move in the
search space.
o Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes the cost.
o No backtracking: It does not backtrack the search space, as it does not remember the previous
states.

State-space Diagram for Hill Climbing:

The state-space landscape is a graphical representation of the hill-climbing algorithm which is showing a
graph between various states of algorithm and Objective function/Cost.

On Y-axis we have taken the function which can be an objective function or cost function, and state-space
on the x-axis. If the function on Y-axis is cost then, the goal of search is to find the global minimum and
local minimum. If the function of Y-axis is Objective function, then the goal of the search is to find the
global maximum and local maximum.

Shree
Ramchandra college of Engineering, Lonikand Page 4
Different regions in the state space landscape:

Local Maximum: Local maximum is a state which is better than its neighbor states, but there is also
another state which is higher than it.

Global Maximum: Global maximum is the best possible state of state space landscape. It has the highest
value of objective function.

Current state: It is a state in a landscape diagram where an agent is currently present.

Flat local maximum: It is a flat space in the landscape where all the neighbor states of current states have
the same value.

Shoulder: It is a plateau region which has an uphill edge.

Disadvantages of Hill Climbing algorithm:

1. Hill Climbing can get stuck in local optima, meaning that it may not find the global optimum of the
problem.
2. The algorithm is sensitive to the choice of initial solution, and a poor initial solution may result in a
poor final solution.
3. Hill Climbing does not explore the search space very thoroughly, which can limit its ability to find
better solutions.
4. It may be less effective than other optimization algorithms, such as genetic algorithms or simulated
annealing, for certain types of problems.

Shree
Ramchandra college of Engineering, Lonikand Page 5
4. Differentiate between Blind search and Heuristic search? [ Year 2023 5M] Ans:
Blind search:

• it is totally brute in nature because it doesn't have any domain specific knowledge.
• it is a very lengthy process
• it is also called uninformed or Brute Force search.
• large memory is used.
• the search process remembers all the unwanted nodes which are no use for the search process.
• it doesn't use any special function for searching.
• example: depth first search and breadth first search.

Heuristic search:

• they use domain-specific knowledge to do the search process.


• by the use of heuristic the search process is reduced.
• this is called informed search.
• no time is wasted in this type of search.
• no large memory is used.
• heuristic functions are used for searching.
• example: hill climbing,best first search and A* and AO*.

5. List steps involved in simple problem solving technique with suitable example? Ans:

These are the following steps which require to solve a problem :


• Problem definition: Detailed specification of inputs and acceptable system solutions.
• Problem analysis: Analyse the problem thoroughly.
• Knowledge Representation: collect detailed information about the problem and define all possible
techniques.
• Problem-solving: Selection of best techniques. Components to formulate the associated problem:
• Initial State: This state requires an initial state for the problem which starts the AI agent towards a
specified goal. In this state new methods also initialize problem domain solving by a specific class.
• Action: This stage of problem formulation works with function with a specific class taken from the
initial state and all possible actions done in this stage.
• Transition: This stage of problem formulation integrates the actual action done by the previous
action stage and collects the final stage to forward it to their next stage.
• Goal test: This stage determines that the specified goal achieved by the integrated transition model
or not, whenever the goal achieves stop the action and forward into the next stage to determines the
cost to achieve the goal.
• Path costing: This component of problem-solving numerical assigned what will be the cost to
achieve the goal. It requires all hardware software and human working cost.

Shree
Ramchandra college of Engineering, Lonikand Page 6
6. Explain A* algorithm with suitable example? [Year 2023 4M] Ans:

A* Algorithm-

A* search is the most commonly known form of best-first search. It uses heuristic function h(n), and cost
to reach the node n from the start state g(n). It has combined features of UCS and greedy best-first search,
by which it solve the problem efficiently. A* search algorithm finds the shortest path through the search
space using the heuristic function. This search algorithm expands less search tree and provides optimal
result faster. A* algorithm is similar to UCS except that it uses g(n)+h(n).

Algorithm of A* search:

Step1: Place the starting node in the OPEN list.

Step 2: Check if the OPEN list is empty or not, if the list is empty then return failure and stops.

Step 3: Select the node from the OPEN list which has the smallest value of evaluation function (g+h), if
node n is goal node then return success and stop, otherwise

Step 4: Expand node n and generate all of its successors, and put n into the closed list. For each successor
n', check whether n' is already in the OPEN or CLOSED list, if not then compute evaluation function for
n' and place into Open list.

Step 5: Else if node n' is already in OPEN and CLOSED, then it should be attached to the back pointer
which reflects the lowest g(n') value.

Step 6: Return to Step 2.

o The main drawback of A* is memory requirement as it keeps all generated nodes in the
memory, so it is not practical for various large-scale problems.

Example:
In this example, we will traverse the given graph using the A* algorithm. The heuristic value of all states
is given in the below table so we will calculate the f(n) of each state using the formula f(n)= g(n) + h(n),
where g(n) is the cost to reach any node from start state.
Here we will use OPEN and CLOSED list. Example:
If the heuristic function is admissible, then A* tree search will always find the least cost path.
Shree
Ramchandra college of Engineering, Lonikand Page 7
Time Complexity: The time complexity of A* search algorithm depends on heuristic function, and the
number of nodes expanded is exponential to the depth of solution d. So the time complexity is O(b^d),
where b is the branching factor.

Space Complexity: The space complexity of A* search algorithm is O(b^d)

7) Explain problem solving Agent with suitable example.[ Year 2022 5 M]


Ans:
In Artificial Intelligence, Search techniques are universal problem-solving methods. Rational agents or
Problem-solving agents in AI mostly used these search strategies or algorithms to solve a specific problem
and provide the best result. Problemsolving agents are the goal-based agents and use atomic representation.

 Problems with a readily available formal specification

o initial state
▪ starting point from which the agent sets out o actions
(operators, successor functions)
▪ describe the set of possible actions o state space
▪ set of all states reachable from the initial state by any
sequence of actions o path
▪ sequence of actions leading from one state in the state space
to another o goal test
▪ determines if a given state is the goal state o solution
▪ path from the initial state to a goal state o search cost
▪ time and memory required to calculate a solution o path cost
▪ determines the expenses of the agent for executing the actions
in a path
▪ sum of the costs of the individual actions in a path o total cost
▪ sum of search cost and path costoverall cost for finding a
solution

Shree
Ramchandra college of Engineering, Lonikand Page 8
Example: Holiday in Romania

 On holiday in Romania; currently in Arad


 Flight leaves tomorrow from Bucharest at 12:00
 Let’s configure this to be an AI problem.
 What’s the problem?
 Accomplish a goal

Reach Bucharest by 12:00

 On holiday in Romania; currently in Arad  Formulate goal:


be in Bucharest
 Formulate problem:
states: various cities
actions: drive between cities 
Find solution:
sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest

Problem representation

 A problem is defined by following components:


 initial state e.g., \In(Arad)"
Shree
Ramchandra college of Engineering, Lonikand Page 9
 actions, Actions(s) returns the actions applicable in s.
e.g, In Arad, the applicable actions are
Go(Sibiu), Go(Timisoara), Go(Zerind)
 goal test, can be explicit, e.g., x = \In Bucharest"
implicit, e.g., x = \In a city with an international airport"
 path cost
e.g., sum of distances, number of actions executed, etc.
 A solution is a sequence of actions leading from the initial state to a goal state.

7. Differentiate between informed and uninformed search algorithms also


explain iterative deepening search in short. [ Year 2022 5M] Ans:

Parameters Informed Search Uninformed Search

It is also known as Heuristic It is also known as Blind


Known as
Search. Search.

It uses knowledge for the searching


Using It doesn’t use knowledge for the
process.
Knowledge searching process.

Performance It finds solution slow as


It finds a solution more quickly.
compared to an informed
search.

Completion It may or may not be complete. It is always complete.

Cost Factor Cost is high.


Cost is low.

Time It consumes less time because of It consumes moderate time


quick searching. because of slow searching.

Direction

Shree
Ramchandra college of Engineering, Lonikand Page 10
There is a direction given about the No suggestion is given
solution. regarding the solution in it.

Implementation It is less lengthy It is more lengthy while


while implemented. implemented.

Efficiency It is more efficient as efficiency It is comparatively less


takes into account cost and efficient as incurred cost is
performance. The incurred cost is more and the speed of finding
less and speed of finding solutions the Breadth-Firstsolution is
is quick. slow.

Computational Comparatively higher


Computational requirements are
requirements computational requirements.
lessened.

Size of search Having a wide scope in terms of Solving a massive search task is
problems handling large search problems. challenging.
Parameters Informed Search Uninformed Search

• Greedy Search
Examples of • Depth First Search (DFS)
• A* Search
Algorithms • Breadth First Search
• AO* Search
(BFS)
• Hill Climbing Algorithm
• Branch and Bound

Iterative deepening depth-first Search:

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.

Shree
Ramchandra college of Engineering, Lonikand Page 11
9. Define state-space search in short. [ Year 2022 5 M] Ans:

A state space is a way to mathematically represent a problem by defining all the possible states in
which the problem can be. This is used in search algorithms to represent the initial state, goal
state, and current state of the problem. Each state in the state space i s represented using a set of
variables.

The efficiency of the search algorithm greatly depends on the size of the state space, and it is
important to choose an appropriate representation and search strategy to search the state space
efficiently.

One of the most well-known state space search algorithms is the A algorithm. Other commonly
used state space search algorithms include breadth -first search (BFS) , depth-first search
(DFS), hill climbing, simulated annealing, and genetic algorithms

Steps in State Space Search

To begin the search process, we set the current state to the initial state.
o We then check if the current state is the goal state. If it is, we terminate the algorithm and
return the result.
o If the current state is not the goal state, we generate the set of possible successor states that
can be reached from the current state. o For each successor state, we check if it has already
been visited. If it has, we skip it, else we add it to the queue of states to be visited.
o Next, we set the next state in the queue as the current state and check if it's the goal state.
If it is, we return the result. If not, we repeat the previous step until we find the goal state
or explore all the states.

Shree
Ramchandra college of Engineering, Lonikand Page 12
10. Explain Best First search with an Example.
Ans:
Best-first Search Algorithm (Greedy Search):
Greedy best-first search algorithm always selects the path which appears best at that moment. It is
the combination of depth-first search and breadth-first search algorithms. It uses the heuristic
function and search. Best-first search allows us to take the advantages of both algorithms. With the
help of best-first search, at each step, we can choose the most promising node. In the best first
search algorithm, we expand the node which is closest to the goal node and the closest cost is
estimated by heuristic function, i.e. f(n)= g(n).

Were, h(n)= estimated cost from node n to the goal.

Best first search algorithm:


o Step 1: Place the starting node into the OPEN list. o Step 2: If the OPEN list is
empty, Stop and return failure.
o Step 3: Remove the node n, from the OPEN list which has the lowest value of h(n), and
places it in the CLOSED list.
o Step 4: Expand the node n, and generate the successors of node n.
o Step 5: Check each successor of node n, and find whether any node is a goal node or not.
If any successor node is goal node, then return success and terminate the search, else
proceed to Step 6.
o Step 6: For each successor node, algorithm checks for evaluation function f(n), and then
check if the node has been in either OPEN or CLOSED list. If the node has not been in
both list, then add it to the OPEN list. o Step 7: Return to Step 2.

Advantages:
o Best first search can switch between BFS and DFS by gaining the advantages of both the
algorithms.
o This algorithm is more efficient than BFS and DFS algorithms.

Disadvantages:
o It can behave as an unguided depth-first search in the worst case scenario. o It can
get stuck in a loop as DFS.

o This algorithm is not optimal.

Example:
Shree
Ramchandra college of Engineering, Lonikand Page 13
Consider the below search problem, and we will traverse it using greedy best-first search. At each
iteration, each node is expanded using evaluation function f(n)=h(n) , which is given in the below
table.

n this search example, we are using two lists which are OPEN and CLOSED Lists. Following are
the iteration for traversing the above example.

Expand the nodes of S and put in the CLOSED list

Initialization: Open [A, B], Closed [S]

Iteration 1: Open [A], Closed [S, B]

Iteration 2: Open [E, F, A], Closed [S, B]


: Open [E, A], Closed [S, B, F]

Iteration 3: Open [I, G, E, A], Closed [S, B, F]

Shree
Ramchandra college of Engineering, Lonikand Page 14
11. Explain n queen problem with suitable example.

Ans:

N - Queens problem is to place n - queens in such a manner on an n x n chessboard that no


queens attack each other by being in the same row, column or diagonal.

Given a 4 x 4 chessboard and number the rows and column of the chessboard 1 through
4.

Now, we place queen q1 in the very first acceptable position (1, 1). Next, we put queen q2 so that
both these queens do not attack each other. We find that if we place q2 in column 1 and 2, then the
dead end is encountered. Thus the first acceptable position for q2 in column 3, i.e. (2, 3) but then
no position is left for placing queen 'q3' safely. So we backtrack one step and place the queen 'q2'
in (2, 4), the next best possible solution. Then we obtain the position for placing 'q3' which is (3,
2). But later this position also leads to a dead end, and no place is found where 'q4' can be placed
safely. Then we have to backtrack till 'q1' and place it to (1, 2) and then all other queens are placed
safely by moving q2 to (2, 4), q3 to (3, 1) and q4 to (4, 3). That is, we get the solution (2, 4, 1, 3).
This is one possible solution for the 4-queens problem.

The implicit tree for 4 - queen problem for a solution (2, 4, 1, 3) is as follows:

Shree
Ramchandra college of Engineering, Lonikand Page 15
12. Explain Uniform Cost search and depth limited search algorithm with suitable example?
Ans:

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:

Advantages:

o Uniform cost search is optimal because at every state the path with the least cost is chosen.

Shree
Ramchandra college of Engineering, Lonikand Page 16
Disadvantages: o 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.

Example:

Completeness:

Uniform-cost search is complete, such as if there is a solution, UCS will find it.

Time Complexity:

Let C* is Cost of the optimal solution, and ε is each step to get closer to the goal node. Then the
number of steps is = C*/ε+1. Here we have taken +1, as we start from state 0 and end to C*/ε.

Hence, the worst-case time complexity of Uniform-cost search isO(b1 + [C*/ε])/.

Space Complexity:

The same logic is for space complexity so, the worst-case space complexity of Uniform-cost search
is O(b1 + [C*/ε]).

Optimal:

Uniform-cost search is always optimal as it only selects a path with the lowest path cost.

Shree
Ramchandra college of Engineering, Lonikand Page 17
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.

Depth-limited search can be terminated with two Conditions of failure:

o Standard failure value: It indicates that problem does not have any solution. o Cutoff
failure value: It defines no solution for the problem within a given depth limit.

Algorithm:

Advantages:

Depth-limited search is Memory efficient.

Disadvantages:

o Depth-limited search also has a disadvantage of incompleteness.


o It may not be optimal if the problem has more than one solution.

Example:

Completeness: DLS search algorithm is complete if the solution is above the depth-limit.

Time Complexity: Time complexity of DLS algorithm is O(bℓ).

Space Complexity: Space complexity of DLS algorithm is O(b×ℓ).

Shree
Ramchandra college of Engineering, Lonikand Page 18
13. Explain 8 puzzle problem with suitable example.

Ans:

The 8 puzzle problem solution is covered in this article. A 3 by 3 board with 8 tiles (each
tile has a number from 1 to 8) and a single empty space is provided. The goal is to use the
vacant space to arrange the numbers on the tiles such that they match the final
arrangement. Four neighbouring (left, right, above, and below) tiles can be moved into
the available area.

14. Write short note on Local search algorithm?


Ans:

Local search algorithms are a category of optimization methods that focus on iteratively
moving from one solution to a neighboring solution.

In the context of local search algorithms, the "local" aspect refers to the limited scope of
the search. These algorithms are designed to optimize within a constrained neighborhood
of the current state, as opposed to global optimization methods that attempt to find the
global optimum across the entire solution space.

Component of Local Search Algorithm

Shree
Ramchandra college of Engineering, Lonikand Page 19
a. Initial State: The initial state, also known as the starting point, is where the local search
begins. It represents a possible solution to the problem at hand. Local search algorithms
start with this initial state and iteratively explore neighboring solutions to improve upon it.

b. Neighbors: Neighbors are solutions that are closely related to the current state. They are
obtained by making small modifications to the current state, such as changing one element
or moving to an adjacent node in a search space. Neighbors are essential because local
search algorithms focus on refining the current solution by examining these nearby options.

c. Objective Function: The objective function, also referred to as the evaluation function or
heuristic function, plays a central role in local search algorithms. This function quantifies
the quality or desirability of a solution. It assigns a numerical value to each solution,
reflecting how close it is to the optimal solution. The objective function guides the search
process by helping the algorithm select the most promising neighbors for exploration.

How These Components Work Together


Local search algorithms operate by following a series of steps that involve these key
components:
1. Initialization: The algorithm begins with an initial state, which is often randomly
generated or provided based on problem requirements.
2. Evaluation: The objective function is applied to the initial state, providing a numerical
evaluation of its quality. This evaluation serves as a benchmark for comparison with
neighboring solutions.
3. Exploration: The algorithm explores the neighboring solutions of the current state. It
generates these neighbors by making small, incremental changes to the current solution.
4. Selection: After evaluating the neighboring solutions using the objective function, the
algorithm selects the neighbor with the highest evaluation (indicating better quality) or
other criteria that align with the optimization goal.
5. Update: The selected neighbor becomes the new current state, and the process continues
iteratively. The algorithm repeats the evaluation, exploration, and selection steps until a
termination condition is met. Termination conditions may include reaching a predefined
number of iterations, finding a satisfactory solution, or running out of computational
resources.

Shree
Ramchandra college of Engineering, Lonikand Page 20
15. Describe Hill climbing with suitable example? List Disadvantages of Hill Climbing Process.
Ans:

o 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. o 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 Travelingsalesman Problem in which we need to minimize the distance traveled by the
salesman. o It is also called greedy local search as it only looks to its good immediate
neighbor state and not beyond that.
o A node of hill climbing algorithm has two components which are state and value.

o Hill Climbing is mostly used when a good heuristic is available. o In this algorithm, we
don't need to maintain and handle the search tree or graph as it only keeps a single current
state.

Features of Hill Climbing:

Following are some main features of Hill Climbing Algorithm:

o Generate and Test variant: Hill Climbing is the variant of Generate and Test method. The
Generate and Test method produce feedback which helps to decide which direction to move
in the search space.
o Greedy approach: Hill-climbing algorithm search moves in the direction which optimizes
the cost.
o No backtracking: It does not backtrack the search space, as it does not remember the
previous states.

State-space Diagram for Hill Climbing: o The state-space landscape is a graphical


representation of the hill-climbing algorithm which is showing a graph between various states
of algorithm and Objective function/Cost.
o On Y-axis we have taken the function which can be an objective function or cost function,
and state-space on the x-axis. If the function on Y-axis is cost then, the goal of search is to
find the global minimum and local minimum. If the function of Y-axis is Objective
function, then the goal of the search is to find the global maximum and local maximum.

Shree
Ramchandra college of Engineering, Lonikand Page 21
Different regions in the state space landscape:

Local Maximum: Local maximum is a state which is better than its neighbor states, but there is also
another state which is higher than it.
Global Maximum: Global maximum is the best possible state of state space landscape. It has the highest
value of objective function.
Current state: It is a state in a landscape diagram where an agent is currently present.
Flat local maximum: It is a flat space in the landscape where all the neighbor states of current states have
the same value.
Shoulder: It is a plateau region which has an uphill edge.
Advantages of Hill Climbing algorithm:

1. Hill Climbing is a simple and intuitive algorithm that is easy to understand and implement.
2. It can be used in a wide variety of optimization problems, including those with a large search
space and complex constraints.
3. Hill Climbing is often very efficient in finding local optima, making it a good choice for
problems where a good solution is needed quickly.
The algorithm can be easily modified and extended to include additional heuristics or constraints.

Disadvantages of Hill Climbing algorithm:

1. Hill Climbing can get stuck in local optima, meaning that it may not find the global optimum
of the problem.
2. The algorithm is sensitive to the choice of initial solution, and a poor initial solution may result
in a poor final solution.
3. Hill Climbing does not explore the search space very thoroughly, which can limit its ability to
find better solutions.

Shree
Ramchandra college of Engineering, Lonikand Page 22
16. Describe Travelling salesman problem with an example.
Ans:
The travelling salesman problem is a graph computational problem where the salesman needs to
visit all cities (represented using nodes in a graph) in a list just once and the distances (represented
using edges in the graph) between all these cities are known. The solution that is needed to be
found for this problem is the shortest possible route in which the salesman visits all the cities and
returns to the origin city.

If you look at the graph below, considering that the salesman starts from the vertex ‘a’, they need
to travel through all the remaining vertices b, c, d, e, f and get back to ‘a’ while making sure that
the cost taken is minimum.

There are various approaches to find the solution to the travelling salesman problem: naive
approach, greedy approach, dynamic programming approach, etc. In this tutorial we will be
learning about solving travelling salesman problem using greedy approach.

Algorithm
• Travelling salesman problem takes a graph G {V, E} as an input and declare another graph
as the output (say G’) which will record the path the salesman is going to take from one
node to another.
• The algorithm begins by sorting all the edges in the input graph G from the least distance
to the largest distance.
• The first edge selected is the edge with least distance, and one of the two vertices (say A
and B) being the origin node (say A).
• Then among the adjacent edges of the node other than the origin node (B), find the least
cost edge and add it onto the output graph.
• Continue the process with further nodes making sure there are no cycles in the output graph
and the path reaches back to the origin node A.
• However, if the origin is mentioned in the given problem, then the solution must always
start from that node only. Let us look at some example problems to understand this better.

Examples

Shree
Ramchandra college of Engineering, Lonikand Page 23
Consider the following graph with six cities and the distances between them −

From the given graph, since the origin is already mentioned, the solution must always start from
that node. Among the edges leading from A, A → B has the shortest distance.

Then, B → C has the shortest and only edge between, therefore it is included in the output graph.

There’s only one edge between C → D, therefore it is added to the output graph.

Shree
Ramchandra college of Engineering, Lonikand Page 24
There’s two outward edges from D. Even though, D → B has lower distance than D → E, B is
already visited once and it would form a cycle if added to the output graph. Therefore, D → E is
added into the output graph.

There’s only one edge from e, that is E → F. Therefore, it is added into the output graph.

Again, even though F → C has lower distance than F → A, F → A is added into the output graph
in order to avoid the cycle that would form and C is already visited once.

The shortest path that originates and ends at A is A → B → C → D → E → F → A The

cost of the path is: 16 + 21 + 12 + 15 + 16 + 34 = 114.

Shree
Ramchandra college of Engineering, Lonikand Page 25

You might also like