CCATPREPARATION AI Module 3
CCATPREPARATION AI Module 3
Explain Hill Climbing Algorithm also Explain What are the limitations of Hill Climbing Search and
how that can be overcome?
Hill Climbing Algorithm is a local search algorithm used for optimization problems. It is called
"hill climbing" because the algorithm tries to climb uphill in the search space by selecting the
best available option at each step.
1) In hill climbing the test function is provided with a heuristic function which provides an
estimate of how close a given state is to goal state.
2) Hill climbing is a mathematical optimization technique which belongs to the family of
local search. It is an iterative algorithm that starts with an arbitrary solution to a problem,
then attempts to find a better solution by incrementally changing a single element of the
solution.
3) If the change produces a better solution, an incremental change is made to the new
solution, repeating until no further improvements can be found.
4) For example, hill climbing can be applied to the travelling salesman problem. It is easy to
find an initial solution that visits all the cities but will be very poor compared to the
optimal solution.
5) The algorithm starts with such a solution and makes small improvements to it, such as
switching the order in which two cities are visited.
6) A node of hill climbing algorithm has two components which are state and value.
7) Hill Climbing is mostly used when a good heuristic is available.
8) In this algorithm, we don't need to maintain and handle the search tree or graph as it only
keeps a single current state
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
Different regions in the state space landscape:
1) Local Maximum: Local maximum is a state which is better than its neighbour
states, but there is also another state which is higher than it.
2) Global Maximum: Global maximum is the best possible state of state space
landscape. It has the highest value of objective function.
3) Current state: It is a state in a landscape diagram where an agent is currently
present.
4) Flat local maximum: It is a flat space in the landscape where all the neighbour
states of current states have the same value. Shoulder: It is a plateau region which
has an uphill edge.
What are the limitations of Hill climbing? And give solutions on problems in
Hill Climbing.
1. Local Maximum: A local maximum is a peak state in the landscape which is better than
each of its neighbouring states, but there is another state also present which is higher than the
local maximum.
Solution: Backtracking technique can be a solution of the local maximum in state space
landscape. Create a list of the promising path so that the algorithm can backtrack the search
space and explore other paths as well.
2. Plateau: A plateau is the flat area of the search space in which all the neighbour states of the
current state contain 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.
Solution: The solution for the plateau is to take big steps or very little steps while searching, to
solve the problem. Randomly select a state which is far away from the current state so it is
possible that the algorithm could find non-plateau region.
\
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.
Solution: With the use of bidirectional search, or by moving in different directions, we can
improve this problem.
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
Overcoming the limitations of Hill Climbing Search:
To overcome these limitations, several variations of the hill climbing algorithm have been
proposed, such as:
1. Random Restart: The algorithm can be restarted from a different initial solution to avoid
getting stuck in a local maximum.
2. Simulated Annealing: This is a modification of the hill climbing algorithm that allows the
algorithm to escape local maxima by accepting worse solutions with a certain probability.
3. Tabu Search: This variation of hill climbing uses a memory structure to avoid revisiting
previously explored solutions.
4. Genetic Algorithms: Genetic algorithms use a population of solutions and apply mutation
and crossover operators to generate new solutions, which can help overcome local
maxima.
Overall, the hill climbing algorithm is a simple and intuitive optimization algorithm, but its
effectiveness can be limited in some cases. By using modifications or other optimization
algorithms, it is possible to improve its performance and overcome its limitations
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
Example: Suppose you want to find the shortest route to travel through all the cities in a given
set. This problem is known as the traveling salesman problem. Simulated Annealing can be used
to find the optimal route.
1. First, you start with an initial solution, such as a random route through all the cities.
2. The algorithm generates a new candidate solution by randomly swapping two cities in the
route.
3. The quality of the candidate solution is evaluated by computing the length of the route.
4. If the candidate solution is better than the current solution, it is accepted as the new current
solution.
5. If the candidate solution is worse than the current solution, it is accepted with a certain
probability, which decreases over time.
6. The algorithm repeats this process, gradually reducing the probability of accepting worse
solutions over time.
7. Eventually, the algorithm converges to an optimal solution, which represents the shortest
possible route through all the cities.
To summarize, Simulated Annealing is an optimization algorithm that iteratively searches for the
best solution among a set of possible solutions by gradually modifying the current solution and
accepting worse solutions with a certain probability. It is useful in solving complex optimization
problems where traditional optimization techniques are not feasible
Genetic algorithm is a type of optimization algorithm that mimics the process of natural selection
to evolve a population of candidate solutions to an optimization problem. It uses techniques such
as selection, crossover, and mutation to evolve better and better solutions over time. Here's a
point wise explanation of genetic algorithm
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
1. Initialization: The algorithm starts by generating an initial population of random candidate
solutions. Each solution is represented by a chromosome, which is a string of genes that encode
the values of the decision variables in the problem.
2. Fitness function: The fitness function is a function that evaluates the quality of each
candidate solution based on the objective function of the optimization problem. The fitness
function assigns a fitness score to each solution, which is used to determine the selection
probability of each individual in the population.
3. Selection: The selection process involves choosing the fittest individuals from the current
population to be parents for the next generation. Selection is typically done using a
fitness-proportionate or rank-based selection scheme, in which individuals with higher fitness
scores are more likely to be selected.
4. Crossover: Crossover is the process of combining two parent chromosomes to create a new
offspring chromosome. This is done by selecting a crossover point in the parent chromosomes
and exchanging the genes to the right of that point between the two parents. This creates two new
offspring chromosomes that are a combination of the parent chromosomes.
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
7. Termination: The algorithm terminates when a stopping criterion is met, such as a maximum
number of generations or a satisfactory fitness score. The best candidate solution found by the
algorithm is then returned as the solution to the optimization problem.
To summarize, genetic algorithm is a type of optimization algorithm that uses techniques such as
selection, crossover, and mutation to evolve a population of candidate solutions to an
optimization problem. The algorithm starts by generating an initial population of random
solutions and then evolves better and better solutions over time through selection, crossover, and
mutation. The algorithm terminates when a stopping criterion is met, and the best candidate
solution found by the algorithm is returned as the solution to the optimization problem.
● A* Algorithm is one of the best and popular techniques used for path finding and graph
traversals.
● A lot of games and web-based maps use this algorithm for finding the shortest path
efficiently.
Working :
Here,
● ‘n’ is the last node on the path
● g(n) is the cost of the path from start node to node ‘n’
● h(n) is a heuristic function that estimates cost of the cheapest path from node ‘n’ to the
goal node
Algorithm :
1. Add the starting node to the open list.
2. While the open list is not empty, select the node with the lowest f-score.
3. If the current node is the goal node, return the path.
4. For each neighbour of the current node, calculate its tentative g-score and f-score.
5. If the neighbour is not in the open list, add it.
6. Otherwise, update the neighbour’s g-score and f-score if the tentative g-score is lower.
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
7. Repeat steps 2 to 6 until the goal node is found or the open list is empty.
8. If the open list is empty and the goal node has not been found, return failure.
Example
Given an initial state of a 8-puzzle problem and final state to be reached-
Find the most cost-effective path to reach the final state from initial state using A* Algorithm.
Consider g(n) = Depth of node and h(n) = Number of misplaced tiles.
Solution-
1. A* Algorithm maintains a tree of paths originating at the initial state.
2. It extends those paths one edge at a time.
3. It continues until final state is reached.
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
Question . Apply A* algorithm on the following graph. Heuristic values are h(S) = 15, h(A) = 14,
h(D) =12, h(B) = 10, h(E) = 10, h(C) = 8, h(F) = 10 , h(G) = 0.
S is the start node and G is the goal node.
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
We start with Note S
X=S
where X is the Current Node
● Open ( A , D )
● f(S-D) = 4 + 12 = 16
● Open ( A , E )
● f(S-D-E) = 6 + 10 = 16
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
Q. Explain Alpha Beta Pruning Algorithm ?
○ Alpha-beta pruning is a modified version of the minimax algorithm. It is an optimization
technique for the minimax algorithm.
○ As we have seen in the minimax search algorithm that the number of game states it has to
examine are exponential in depth of the tree. Since we cannot eliminate the exponent, but
we can cut it to half. Hence there is a technique by which without checking each node of
the game tree we can compute the correct minimax decision, and this technique is called
pruning. This involves two threshold parameter Alpha and beta for future expansion, so
it is called alpha-beta pruning. It is also called as Alpha-Beta Algorithm.
Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not only prune
the tree leaves but also entire sub-tree.
a. Alpha: The best (highest-value) choice we have found so far at any point along
the path of Maximizer. The initial value of alpha is -∞.
b. Beta: The best (lowest-value) choice we have found so far at any point along the
path of Minimizer. The initial value of beta is +∞.
○ The Alpha-beta pruning to a standard minimax algorithm returns the same move as the
standard algorithm does, but it removes all the nodes which are not really affecting the
final decision but making algorithm slow. Hence by pruning these nodes, it makes the
algorithm fast.
Define heuristic function. Give an example heuristics function for Blocks World Problem
HEURISTIC FUNCTION:
1. Heuristic Function is the function that gives an estimation on the Cost of getting from node to
the goal
state.
2. Heuristic Function is used in Informed Search Technique.
3. It is used in a decision process to try to make the best choice of a list of possibilities.
4. Best move is the one with the least cost.
5. Heuristic function helps in implementing goal oriented search.
6. It is usually used to increase the efficiency of the search process
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
EXAMPLE OF HEURISTICS FUNCTION FOR BLOCKS WORLD PROBLEM
As shown below the heuristic value of H(s) = 4. Since we take 4 move to reach from initial state
to Goal State
For the 8-Puzzle Problem, two heuristics are commonly used. i.e. No. of misplaced tiles and
Manhattan Distance.
- For Example:
Consider the example given below. It consists of initial state and goal state
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
∴ Heuristic h (n) = 1
1. Manhattan Distance is the sum of the distances of the tiles from their goal positions.
For Example:
- Consider the example given below. It consists of initial state and goal state.
- In this case, only the “3”, “8” and “1” titles are misplaced by 2, 3 and 3 spaces respectively. So
the heuristic function evaluates to 8.
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com
Join Our Telegram Group to Get Notifications, Study Materials, Practice test & quiz: https://t.me/ccatpreparations
Visit: www.ccatpreparation.com