ALGORITHMS
ALGORITHMS
Hill Climbing is a heuristic search algorithm used in AI for optimization problems. It's an
iterative algorithm that starts with an arbitrary solution to a problem and attempts to find a
better solution by making incremental changes to the solution. Ex:- Imagine you're playing a
game where you need to help a little robot climb a mountain to find treasure! Hill Climbing in
AI is just like that - it's a way to help computers solve problems by always trying to go "up"
towards better answers.
Step 1: Initialize with a random solution (starting point). Starting Point: Imagine you put your
robot anywhere on the mountain. That's your starting point!
Step 2: Evaluate all neighboring states . The robot looks around at all the spots it can step to
(just like you would look around before climbing).
Step 3: If a neighbor has a better value than current state, move to that state. Taking Steps:
Just like you would always try to climb up, never down!
1. The Stuck Problem: Sometimes the robot reaches a small hill and thinks it's the highest
point, but there might be a bigger hill nearby! (This is called getting stuck at a local
maximum)
2. The Flat Ground Problem: Sometimes the robot finds flat ground and doesn't know
which way to go (This is called the plateau problem)
3. The Zigzag Problem: Sometimes the robot has to zigzag left and right to go up, which can
be confusing! (This is called the ridge problem).
Real-Life Example (2 marks): Think of playing a video game where you need to get the highest score:
Think of A* like a really smart GPS finding the shortest path from your home to a toy store. It's
smarter than other algorithms because it:
1. Starting Point:
2. Making Decisions:
3. Moving Forward:
Advantages (2 marks):
1. Smart:
2. Complete:
n = current node
Best-First Search finds paths like a hiker who always walks toward the mountain peak they
can see, choosing the most promising direction each time.
b) At each step
Find goal, or
Robot navigation
Alpha-Beta Pruning is a trick to make the Min-Max algorithm smarter and faster when
it’s deciding the best move in games like chess or tic-tac-toe.
Imagine You’re Playing a Game:
1. You (the player) want to make the best move.
2. The computer (your opponent) also wants to make the best move.
But, instead of checking all possible moves (which can take a long time), the computer
uses Alpha-Beta Pruning to skip some moves that it knows won’t help.
How Does It Work?
1. Alpha: This keeps track of the best score that the maximizing player (you) can
guarantee. It starts very low and gets updated as we find better options.
2. Beta: This keeps track of the best score that the minimizing player (the computer)
can guarantee. It starts very high and gets updated as we find worse options.
The Trick:
While going through the game tree (all possible moves), if the computer finds a move
that’s obviously worse than a move it already knows about, it stops looking at the
rest of the moves. It knows those moves can’t be better.
Example:
1. You’re trying to find the best move (maximize score).
2. The computer checks the first few moves and finds a good one for itself.
3. If it finds another move later that’s worse than what it already found, it skips
checking that move further.
Why It’s Useful:
It saves time by not checking every single move.
It still guarantees the best move will be found, just faster.
In simple words: Alpha-Beta Pruning helps the computer skip bad moves and focus only
on the good ones, making the game decisions faster!