AISemester 6

Unit 1: Introduction to AI and Problem Solving

AI fundamentals, search algorithms (DFS, BFS, A*), hill climbing, genetic algorithms, and game playing

Author: Deepak Modi
Last Updated: 2025-06-15

Syllabus:

Introduction: Definition of AI, History of AI, nature of AI problems, examples of AI problems. Problem solving by search: Uninformed Search: Depth First Search (DFS), Breadth First Search (BFS). Informed Search: Best First Search, A*. Local Search: Hill Climbing. Problem Reduction Search: AO*. Population Based Search: Ant Colony Optimization, Genetic Algorithm. Game Playing: Min Max Algorithm, Alpha-Beta Pruning.


Section 1: Introduction to AI

1. Definition of AI

PYQ: Define term Artificial Intelligence. What are applications of AI in various fields? (2021, 7 marks)
PYQ: What is Artificial Intelligence? State examples of AI problems. (2023, 8 marks)

Artificial Intelligence (AI) refers to the ability of machines or computer systems to perform tasks that typically require human intelligence. These tasks can include:

  • Understanding natural language (e.g., chatbots like Siri, Alexa).
  • Recognizing patterns (e.g., facial recognition).
  • Making decisions (e.g., self-driving cars).
  • Learning from experience (e.g., recommendation systems like Netflix).

AI systems are designed to mimic human thinking, reasoning, and decision-making processes. AI aims to create smart machines that can think, learn, and solve problems efficiently.

Key characteristics of Artificial Intelligence (AI):

  1. Automation – AI enables machines to perform tasks without human intervention.
  2. Machine Learning (ML) – AI can learn from data and improve performance over time.
  3. Problem-Solving – AI can analyze complex problems and find optimal solutions.
  4. Data Processing – AI can process and analyze large amounts of data quickly.
  5. Adaptability – AI systems can adapt to changing environments and improve decision-making.
  6. Natural Language Processing (NLP) – AI can understand, interpret, and generate human language.
  7. Perception – AI can process images, sounds, and sensor data to recognize objects and patterns.
  8. Reasoning – AI can make logical deductions and predictions based on available data.
  9. Autonomous Decision-Making – AI can make independent decisions without constant human input.
  10. Continuous Improvement – AI refines its accuracy and efficiency through feedback and new data.

Applications of AI in Various Fields:

  1. Healthcare – AI assists in diagnosing diseases, analyzing medical images, and personalizing treatment plans.
  2. Finance – AI is used for fraud detection, algorithmic trading, and risk assessment.
  3. Transportation – AI powers self-driving cars, traffic management systems, and route optimization.
  4. Manufacturing – AI optimizes production processes, predictive maintenance, and quality control.
  5. Retail – AI enhances customer experience through personalized recommendations, inventory management, and demand forecasting.
  6. Entertainment – AI is used in content recommendation systems, video games, and virtual reality experiences.
  7. Education – AI personalizes learning experiences, automates grading, and provides intelligent tutoring systems.
  8. Agriculture – AI optimizes crop management, pest control, and yield prediction.
  9. Security – AI enhances surveillance systems, threat detection, and cybersecurity measures.
  10. Customer Service – AI chatbots and virtual assistants provide 24/7 support and automate routine inquiries.
  11. Smart Homes – AI powers smart devices for home automation, energy management, and security.
  12. Gaming – AI creates intelligent non-player characters (NPCs) and enhances game design.
  13. Social Media – AI algorithms curate content, detect fake news, and analyze user behavior.

Architecture of Artificial Intelligence (AI)

The AI architecture defines how an AI system is structured, processes data, and makes decisions. It consists of multiple layers, each handling different aspects of AI functionality.

+---------------------+
|   Data Layer        |
| (Knowledge Base)    |
+---------------------+
|   Processing Layer   |
| (AI Algorithms)     |
+---------------------+
| Reasoning & Inference|
| Layer               |
+---------------------+
| Interaction Layer    |
| (User & AI Comm.)   |
+---------------------+
| Deployment Layer     |
| (Integration)       |
+---------------------+
1. Data Layer (Knowledge Base)
  • Stores raw data, knowledge, and facts required for AI processing.
  • Includes:
    • Databases (SQL, NoSQL)
    • Knowledge graphs
    • Ontologies
    • Data warehouses
2. Processing Layer (AI Algorithms & Models)
  • The core of AI where learning, reasoning, and decision-making happen.
  • Includes:
    • Machine Learning (ML) algorithms (Supervised, Unsupervised, Reinforcement Learning)
    • Deep Learning (Neural Networks, CNNs, RNNs, Transformers)
    • Rule-Based Systems (Expert Systems)
    • Search Algorithms (A*, Minimax, Genetic Algorithms)
3. Reasoning & Inference Layer
  • Applies logic, probabilities, and heuristics to derive conclusions from data.
  • Includes:
    • Inference Engine (for rule-based reasoning)
    • Bayesian Networks (for probabilistic reasoning)
    • Fuzzy Logic (for handling uncertainty)
4. Interaction Layer (User & AI Communication)
  • Allows AI to interact with users and the environment.
  • Includes:
    • Natural Language Processing (NLP)
    • Speech Recognition (e.g., Alexa, Siri)
    • Computer Vision (e.g., image processing)
    • Robotics & Sensors (e.g., autonomous systems)
5. Deployment Layer (AI System Integration)
  • Ensures the AI model is deployed and scaled efficiently.
  • Includes:
    • Cloud Platforms (AWS, GCP, Azure)
    • Edge Computing (AI on IoT devices)
    • APIs & Microservices (AI as a service)
AI Architecture Example: Self-Driving Car
  • Data Layer: Collects sensor data (cameras, LiDAR, radar).
  • Processing Layer: Uses ML algorithms to analyze road conditions.
  • Reasoning Layer: Predicts obstacles and makes driving decisions.
  • Interaction Layer: Communicates alerts to the driver or autopilot system.
  • Deployment Layer: Runs AI software on an embedded system inside the vehicle.

2. History of AI

PYQ: History of AI (2022, 2.5 marks)

The development of AI can be divided into several phases:

  1. Early Ideas (1940s-1950s)
    • The concept of AI emerged after World War II.
    • Alan Turing proposed the idea of a "thinking machine" and created the Turing Test to measure machine intelligence.
    • Turing Test: A test to determine if a machine can exhibit intelligent behavior indistinguishable from a human.

PYQ: Define Turing Test. (2024, 1 mark)

  1. Initial Growth (1956)
    • The term "Artificial Intelligence" was first used at the Dartmouth Conference.
    • Early programs were developed to play games like chess and solve mathematical problems.
  2. AI Winter (1970s-1980s)
    • Due to limited technology and high expectations, AI research slowed down.
    • Many projects were abandoned due to lack of funding because AI systems failed to deliver real-world applications.
  3. Resurgence (1990s-2000s)
    • Advances in computer hardware and algorithms led to renewed interest in AI.
    • The development of machine learning and neural networks gained momentum.
  4. Modern AI (2010s-Present)
    • The rise of big data and powerful GPUs enabled deep learning breakthroughs.
    • AI applications expanded into various fields, including healthcare, finance, and autonomous vehicles.
    • Major milestones include IBM's Watson winning Jeopardy! in 2011 and Google's AlphaGo defeating a world champion Go player in 2016.
  5. Current Trends
    • AI is now integrated into everyday applications like virtual assistants (Siri, Alexa), recommendation systems (Netflix, Amazon), and autonomous vehicles (Tesla).
    • It is also being used in advanced fields like natural language processing (NLP), computer vision, and robotics.
    • ChatGPT and other large language models have revolutionized natural language processing, enabling more human-like interactions with machines.

3. Nature of AI Problems

AI problems are often complex and require advanced strategies to solve. They have the following characteristics:

  1. Complexity
    • AI problems often involve large datasets and multiple factors.
    • Example: Diagnosing diseases based on multiple symptoms.
  2. Uncertainty
    • AI must work with incomplete or changing information.
    • Example: Weather prediction, where conditions keep changing.
  3. Decision-Making
    • AI must select the best possible solution from many options.
    • Example: Self-driving cars deciding when to stop or change lanes.
  4. Learning & Adaptation
    • AI systems improve over time by learning from past experiences.
    • Example: Google’s search engine improves based on user behavior.

4. Examples of AI Problems

Here are common problems where AI is applied:

  1. Speech Recognition - AI systems like Siri or Alexa understand and respond to spoken commands.
  2. Image Recognition - AI identifies objects, people, or places in photos and videos (used in face recognition or social media tagging).
  3. Natural Language Processing (NLP) - AI helps computers understand, translate, or generate human language.
  4. Medical Diagnosis - AI assists doctors by analyzing symptoms and suggesting possible conditions.
  5. Robotics - AI-powered robots can perform physical tasks, like assembling products in factories.
  6. Autonomous Vehicles - AI enables self-driving cars to navigate and make decisions on the road.
  7. Fraud Detection - AI analyzes transaction patterns to identify potential fraud in banking and finance.
  8. Game Playing - AI can play complex games like chess or Go and often beat human champions.
  9. Natural Language Processing (NLP) - AI helps computers understand, translate, or generate human language.
  10. Medical Diagnosis - AI assists doctors by analyzing symptoms and suggesting possible conditions.

AI often uses search techniques to find solutions to complex problems. Search involves exploring all possible solutions or paths and selecting the best one. There are different types of search strategies, including uninformed search, informed search, local search, and problem reduction search.

Classification of Search Techniques:

  1. Uninformed Search (Blind Search)
    • Does not use any domain knowledge.
    • Examples: Depth First Search (DFS), Breadth First Search (BFS).
  2. Informed Search (Heuristic Search)
    • Uses heuristics to guide the search.
    • Examples: Best First Search, A* Algorithm.
  3. Local Search (Optimization-Based Search)
    • Focuses on improving a single solution iteratively.
    • Example: Hill Climbing Algorithm.
  4. Problem Reduction Search
    • Breaks down a problem into smaller sub-problems.
    • Example: AO* Algorithm.
  5. Population-Based Search
    • Uses a group of solutions to find the best one.
    • Examples: Ant Colony Optimization (ACO), Genetic Algorithm (GA).
  6. Game Playing Search
    • Used in AI for games to find optimal moves.
    • Examples: Minimax Algorithm, Alpha-Beta Pruning.

PYQ: Uninformed Search (2023, 2.5 marks)

Uninformed search algorithm (also called blind search) does not use any prior knowledge (non-heuristics) about the problem. It explores all possible paths blindly until they find the solution without any guidance or heuristics. These algorithms are simple and easy to implement but can be inefficient for large search spaces.

The two main uninformed search algorithms are Depth First Search (DFS) and Breadth First Search (BFS).

1. Depth First Search (DFS)

PYQ: What are the limitations of Depth-first search? (2024, 1 mark)
PYQ: Differentiate the DFS and BFS with merits and demerits. (2023, 7 marks)

DFS explores as deep as possible along one path before backtracking. It goes down one branch of the search tree until it reaches a dead end, then backtracks to explore other branches.

Example: Solving a maze by going in one direction until hitting a dead end, then backtracking.

How DFS Works:
  1. Start from the initial node.
  2. Expand a node and visit its first child.
  3. Continue expanding the first child of each node until a dead end is reached.
  4. Backtrack to the previous node and explore the next child.
  5. Repeat until the goal is found or all paths are explored.
Implementation:
  • Uses a stack (LIFO - Last In, First Out) for storing nodes.
  • Can be implemented using recursion or an explicit stack.
Example:

For the following graph:

    A  
   / \  
  B   C  
 / \   \  
D   E   F

DFS traversal (starting from A):

A → B → D → E → C → F

Advantages:
  • Uses less memory than BFS.
  • Works well for problems with deep solutions.
Disadvantages and Limitations of DFS:
  • May get stuck in an infinite loop if cycles exist (without a proper visited nodes check).
  • Does not guarantee the shortest path - it finds a path, not necessarily the optimal one.
  • Can be inefficient for wide search spaces - might explore deep paths that lead nowhere.
  • Memory usage can grow linearly with the depth of the search tree.
  • Risk of stack overflow for very deep trees when using recursion.
  • May never terminate if the search space is infinite and contains no solution.

2. Breadth First Search (BFS)

PYQ: Differentiate the DFS and BFS with merits and demerits. (2023, 7 marks)

BFS explores all nodes at the current level before moving to the next level. It is like searching level by level, ensuring that all nodes at a given depth are explored before going deeper.

Example: Finding the shortest route in Google Maps by exploring all possible paths from the starting point.

How BFS Works:
  1. Start from the initial node.
  2. Explore all direct children before moving to their children.
  3. Continue this process until the goal is found or all nodes are visited.
Implementation:
  • Uses a queue (FIFO - First In, First Out) for storing nodes.
Example:

For the same graph:

     A  
    / \
   B   C
  / \   \
 D   E   F

BFS traversal (starting from A):
A → B → C → D → E → F

Advantages:
  • Guarantees the shortest path if all steps have equal cost.
  • Avoids getting stuck in infinite loops.
Disadvantages:
  • Uses more memory than DFS.
  • Can be slow if the search space is large.
Comparison: DFS vs BFS
FeatureDFSBFS
Data StructureStack (LIFO)Queue (FIFO)
Exploration StyleGoes deep firstExplores level by level
Memory UsageLess (only stores path)More (stores all nodes at a level)
Guaranteed Shortest Path?NoYes
Best ForDeep solutionsShortest path problems
ExampleMaze solving, game treesShortest path in graphs, web crawling
  • Use DFS when memory is limited or when a deep solution exists.
  • Use BFS when the shortest path is required.
  • Both DFS and BFS are useful for solving AI problems like maze navigation, web crawling, and pathfinding in graphs.

Water Jug Problem

Water Jug Problem is a classic example of a problem that can be solved using search algorithms. The problem involves two jugs with different capacities and the goal is to measure a specific amount of water using these jugs. This problem can be represented as a state space search problem, where each state represents the amount of water in each jug.

This can be implemented using either DFS or BFS. The search space consists of all possible states of the jugs, and the goal is to find a sequence of actions that leads to the desired state.

Water Jug Problem Example

PYQ: Consider a water jug problem. You are given 2 jugs; a 3-gallon jug and a 4-gallon jug. Neither has any measuring marks on it. There is a pump that can be used to fill the jugs with water. How can you get exactly 2-gallon of water into a 4-gallon jug? State the production rules for the water jug problem. (2024, 10 marks)

Problem Definition:

You have two jugs:

  1. A 3-gallon jug (Jug A)
  2. A 4-gallon jug (Jug B)

Neither jug has any measuring marks on it. You can fill the jugs from a water source, empty them, or pour water from one jug to another.

Goal:

Measure exactly 2 gallons of water in Jug B.

Possible Actions:
  1. Fill Jug A from the water source.
  2. Fill Jug B from the water source.
  3. Empty Jug A.
  4. Empty Jug B.
  5. Pour water from Jug A to Jug B until Jug A is empty or Jug B is full.
  6. Pour water from Jug B to Jug A until Jug B is empty or Jug A is full.
Solution Steps:
StepActionJug A (3-gallon)Jug B (4-gallon)Explanation
1Fill Jug B04Fill the 4-gallon jug completely
2Pour B → A31Pour until Jug A is full
3Empty Jug A01Completely empty the 3-gallon jug
4Pour B → A10Move the remaining water to Jug A
5Fill Jug B14Fill the 4-gallon jug again
6Pour B → A32Pour until Jug A is full (it can only take 2 more gallons)
7Goal reached!32Jug B now contains exactly 2 gallons
Production Rules for Water Jug Problem:
  • Rule 1: If both jugs are empty, fill either jug from the source.
  • Rule 2: If a jug is full, empty it.
  • Rule 3: If one jug is full and the other is empty, pour water from the full jug to the empty jug.
  • Rule 4: If one jug has some water and the other is empty, pour water from one jug to another until one of them is either full or empty.
  • Rule 5: If you need a specific amount of water, check if it's possible with the current state and apply the necessary actions.

PYQ: Informed Search (2022, 2.5 marks)
PYQ: Differentiate between informed and uninformed search. (2021, 3 marks)
PYQ: What do you mean by term Heuristics? (2021, 3 marks)

Informed search (also called heuristic search) uses additional knowledge (heuristics) to find solutions more efficiently than uninformed search. A heuristic function estimates how close a given state is to the goal.

Meaning of Heuristics: - Heuristics are rules of thumb or problem-specific knowledge that helps in estimating the cost or distance to the goal. They guide the search process, making it more efficient.

AspectInformed SearchUninformed Search
KnowledgeUses heuristics to guide searchNo prior knowledge, explores blindly
EfficiencyMore efficient, faster convergenceLess efficient, may explore unnecessary paths
OptimalityMay not guarantee optimal solutionGuarantees optimal solution (if exists)
Memory UsageGenerally uses more memoryGenerally uses less memory
ExamplesA*, Best First SearchDFS, BFS
  • Informed Search uses heuristics to guide the search process, making it more efficient.
  • Uninformed Search explores all possible paths without any guidance, which can be less efficient.
  • Heuristics are problem-specific knowledge or rules of thumb that help estimate the cost or distance to the goal.

Two common informed search algorithms are Best First Search and A* Algorithm.

1. Best First Search (Heuristic Approach)

PYQ: Explain the Best-First-Search Procedure with example. (2023, 8 marks)

Best First Search selects the most promising node based on a heuristic function and expands it first. It uses a heuristic function h(n) to estimate the cost from the current node to the goal. The algorithm explores nodes based on their heuristic values, prioritizing those that seem closest to the goal.

Example: AI finding the best move in a game based on estimated success.

How Best First Search Works:
  1. Start from the initial node.
  2. Use a heuristic function h(n) to evaluate each node.
  3. Select the node with the lowest heuristic value (most promising).
  4. Expand that node and repeat until the goal is found.
Implementation:
  • Uses a priority queue (min-heap) to store nodes, sorted by their heuristic values.
Example:

Consider the following graph where the numbers represent heuristic values (estimated distance to the goal):

     A(10)  
    /   \  
  B(6)   C(8)  
  /  \     \  
D(3)  E(5)  F(7)

If Goal = D, the algorithm explores:
A → B → D (choosing nodes with the smallest heuristic value).

Advantages:
  • Faster than uninformed searches.
  • Uses heuristics to prioritize promising paths.
  • Can find solutions more quickly in large search spaces.
Disadvantages:
  • May not always find the optimal solution.
  • Performance depends on the accuracy of the heuristic function.
  • Can be inefficient if the heuristic is not well-designed.

2. A* Algorithm

PYQ: Explain A* algorithm. (2022, 15 marks)
PYQ: Explain algorithm A* with example. (2023, 7 marks)

A* (A-Star) is an improved version of Best First Search. It combines the cost to reach a node and the estimated cost to reach the goal. A* uses two functions:

  • g(n): The actual cost from the start to the current node.
  • h(n): The estimated cost from the current node to the goal.

It combines them using the formula: f(n) = g(n) + h(n)

Where:

  • f(n): Estimated total cost to reach the goal.
  • g(n): Cost from the start node to the current node.
  • h(n): Estimated cost from the current node to the goal.

Example: GPS navigation systems finding the best route to a destination.

How A* Algorithm Works:
  1. Start from the initial node.
  2. Use the formula f(n) = g(n) + h(n) to evaluate each node.
  3. Select and expand the node with the lowest f(n) value.
  4. Repeat until the goal is found.
Implementation:
  • Uses a priority queue to store nodes, sorted by f(n) values.
Example:

Consider this graph where numbers represent g(n) (cost) and h(n) (heuristic values):

     A  
   (0,4)  
   /   \  
 B(1,2)  C(2,2)  
  |       |  
 D(3,0)   E(5,0) [Goal]

A* Calculation:

  1. A → B: f(B) = g(B) + h(B) = 1 + 2 = 3
  2. A → C: f(C) = g(C) + h(C) = 2 + 2 = 4
  3. Expand B (smallest f): B → D: f(D) = 3 + 0 = 3 (Goal reached).
Advantages:
  • Guarantees the shortest path if the heuristic is admissible (does not overestimate).
  • Uses both cost and heuristic information for better performance.
  • More efficient than Best First Search.
Disadvantages:
  • Can be slow if the search space is very large.
  • Requires a well-designed heuristic function for optimal performance.
  • Memory-intensive due to storing all nodes in the priority queue.
Comparison: Best First Search vs A* Algorithm
FeatureBest First SearchA* Algorithm
Uses Heuristic?Yes (h(n))Yes (h(n) and g(n))
Evaluation Functionf(n) = h(n)f(n) = g(n) + h(n)
Finds Shortest Path?Not alwaysYes (if heuristic is good)
PerformanceFast but not optimalEfficient and optimal
Memory UsageLess memoryMore memory (stores all nodes)
Best ForQuick solutionsOptimal pathfinding
  • Best First Search is faster but does not always guarantee the best solution.
  • A* Algorithm is more reliable as it considers both cost and heuristics.
  • A* is widely used in Google Maps, robotics, and AI pathfinding in games.

Local search is a simple optimization-based search technique that focuses on improving a single solution step by step. Unlike uninformed or informed searches that explore all possible paths, local search starts with an initial solution and continuously moves toward a better solution by making small changes.

How it works:

  • Start with any solution
  • Make small changes to try to improve it
  • Keep the better solution and repeat

Local search is like climbing a hill - you keep moving upward to find the highest point, without looking at the entire landscape at once.

Example: An AI adjusting settings in a recommendation system to make better suggestions.

Hill Climbing Algorithm

PYQ: Why hill climbing algorithm is called greedy local search? (2024, 1 mark)
PYQ: Explain Hill Climbing strategy with example. What are the problems faced while applying this strategy? (2021, 8 marks)
PYQ: What is Hill Climbing? Explain simple Hill Climbing. (2022, 15 marks)

Hill Climbing is a local search algorithm that continuously moves towards the direction of increasing value (uphill) to find the optimal solution. It evaluates neighboring solutions and selects the best one, repeating this process until no better neighbors are found.

Hill Climbing as a Greedy Local Search

Hill climbing is called a greedy local search for two fundamental reasons:

  1. Greedy Nature:

    • It always chooses the immediate best option available
    • It makes the locally optimal choice at each step
    • It never reconsiders previous decisions, even if they lead to suboptimal results
    • It doesn't look ahead beyond the immediate neighbors
  2. Local Focus:

    • It only considers the current state's neighboring solutions
    • It has no global perspective of the entire search space
    • It can't "see" beyond the immediate neighbors
    • It makes decisions based only on local information

These characteristics make hill climbing efficient but also prone to getting trapped in local optima rather than finding the global optimum solution.

How Hill Climbing Works:
  1. Start with an initial solution (random or predefined).
  2. Evaluate its quality using a heuristic function.
  3. Generate neighboring solutions by making small modifications.
  4. Select the best neighboring solution.
    • If the new solution is better, keep it.
    • If not, stop the search (local maximum reached).
  5. Repeat steps 2-4 until no better solution is found.
Types of Hill Climbing:
  1. Simple Hill Climbing – Selects the first better neighbor found.
  2. Steepest-Ascent Hill Climbing – Examines all neighbors and chooses the best one.
  3. Stochastic Hill Climbing – Chooses a random better neighbor rather than the best one.
Example:

Imagine a hiker climbing a mountain but can only see nearby steps (local information). The hiker keeps moving up as long as the path gets higher.

Problems with Hill Climbing:
  • Local Maxima: The algorithm may get stuck in a local maximum, where all neighbors are worse, but a better solution exists elsewhere globally.
  • Plateau: A flat area where all neighbors have the same value, causing the algorithm to get stuck.
  • Ridges: A narrow path where moving in one direction decreases the value, but another path might lead to a better solution.
Solutions to Overcome Problems:
  • Random Restarts: Run the algorithm multiple times from different starting points.
  • Simulated Annealing: Occasionally allow moves to worse solutions to escape local maxima.
  • Using Memory: Keep track of visited states to avoid loops.
Advantages of Hill Climbing:
  • Uses very little memory.
  • Works well for small and continuous optimization problems.
  • Fast and efficient in finding a good solution.
Disadvantages of Hill Climbing:
  • Can get stuck in local maxima or plateaus.
  • Does not always find the best solution (global maximum).
Applications of Hill Climbing:
  • AI and Game Development: Chess move optimization.
  • Robotics: Path planning for robots.
  • Machine Learning: Neural network training optimization.
  • Job Scheduling: Assigning tasks to minimize execution time.

2.4 Problem Reduction Search: AO* Algorithm

PYQ: What is the difference between A* and AO* algorithms? (2024, 5 marks)

Problem Reduction Search is a technique that breaks a large problem into smaller sub-problems, solving them step by step. The AO* (And-Or Star) Algorithm is a widely used search algorithm for solving problems with multiple possible paths and dependencies.

It is particularly useful for problems that can be represented as AND-OR graphs, where some sub-problems must be solved together (AND nodes) while others can be solved independently (OR nodes).

  • AND nodes: All children must be solved together.
  • OR nodes: Only one child needs to be solved.

Example: Solving a complex puzzle by breaking it down into smaller sections.

Differences Between A and AO Algorithms**

AspectA* AlgorithmAO* Algorithm
Graph TypeWorks on regular state-space graphsWorks on AND-OR graphs (hypergraphs)
Problem Solving ApproachFinds a single path from start to goalSolves problems that can be decomposed into subproblems
Node StructureSingle nodes representing statesContains both OR nodes (alternative choices) and AND nodes (required subproblems)
GoalFinding a path to a single goal stateFinding a solution tree/graph that solves the problem
Evaluation Functionf(n) = g(n) + h(n)Similar but applies to solution subtrees
Solution TypeLinear sequence of actionsSolution graph with potential branches
DecompositionDoes not decompose problemsDecomposes complex problems into manageable subproblems
ApplicationsPath finding, route planningProblem reduction, hierarchical planning, theorem proving
Example Use CaseFinding shortest path in a mazeSolving a complex puzzle by dividing it into sub-puzzles

In essence, A* finds paths in simple graphs while AO* handles problems that can be broken down into interdependent subproblems, represented as AND-OR graphs.

AO* Algorithm

The AO* Algorithm is an extension of the A* algorithm used for solving AND-OR Graphs (problems where some sub-problems must be solved together). It selects the best path by considering both cost and heuristic information.

Key Features of AO*
  • Works on AND-OR graphs instead of simple state graphs.
  • Expands nodes based on heuristic values (like A*).
  • Uses backtracking to update costs dynamically.
How AO* Algorithm Works:
  1. Start from the initial node and evaluate its heuristic cost.
  2. Expand the most promising node based on the lowest cost.
  3. Identify AND and OR nodes:
    • OR nodes: Only one path needs to be chosen.
    • AND nodes: All children must be solved together.
  4. Update the cost of the parent node based on its children.
  5. Repeat the process until the goal state is reached.
Example: Solving a Puzzle with AO*

Consider a problem where solving X requires solving either Y or Z, but solving Y requires solving A and B together.

        X  
       / \  
     Y     Z  
    / \  
   A   B
  • The algorithm will first estimate the cost of A, B, and Z.
  • If A and B together have a lower cost than Z, the algorithm will choose Y.
  • If Z is cheaper, it will choose Z directly.
  • The cost of X is updated dynamically based on the selected path.
Advantages of AO*
  • Works well for hierarchical problems.
  • Finds the most cost-effective solution.
  • Dynamically updates solutions based on new information.
Disadvantages of AO*
  • More complex than A*.
  • Requires a well-defined heuristic function.
Applications of AO*
  • Automated Planning: Task scheduling and workflow automation.
  • Expert Systems: Decision-making in AI-based medical diagnosis.
  • Game Development: Planning strategies in AI-driven games.

Population-based search algorithms use a group (population) of possible solutions and improve them over time. These techniques are inspired by natural processes and are commonly used for optimization problems.

The two main types of population-based search algorithms are:

  1. Ant Colony Optimization (ACO) (inspired by ants' behavior)
  2. Genetic Algorithm (GA) (inspired by natural evolution)

1. Ant Colony Optimization (ACO)

PYQ: Ant Colony Optimization (2022, 2.5 marks)

ACO is inspired by the way real ants find the shortest path to food. Ants leave pheromones (chemical signals) on the ground, which guide other ants to the food source. Over time, the paths with more pheromones attract more ants, leading to the discovery of the shortest path.

How ACO Works:
  1. Initialization – A group of ants is placed at the starting point.
  2. Path Exploration – Each ant randomly chooses a path based on probability.
  3. Pheromone Update – Ants deposit pheromones on their chosen paths.
  4. Evaporation – Over time, pheromones on weaker paths fade.
  5. Reinforcement – The best path attracts more ants, strengthening its pheromone trail.
  6. Repeat until the best solution is found.
Example:
  • Finding the shortest route for delivery trucks.
  • Solving the Traveling Salesman Problem (TSP).
Advantages of ACO:
  • Works well for pathfinding and optimization.
  • Adapts dynamically to changes.
  • Can find multiple solutions simultaneously.
Disadvantages of ACO:
  • Can take a long time to converge to the best solution.
  • Requires fine-tuning of parameters.
  • Sensitive to pheromone evaporation rates.
Applications of ACO:
  • Routing Problems: Finding optimal paths in networks (e.g., telecommunications, transportation).
  • Scheduling Problems: Job scheduling in manufacturing and logistics.
  • Combinatorial Optimization: Solving problems like the Traveling Salesman Problem (TSP) and vehicle routing.
  • Bioinformatics: Protein folding and DNA sequencing problems.

2. Genetic Algorithm (GA)

PYQ: Write a short note on genetic algorithms. (2021, 3 marks)
PYQ: Genetic Algorithm (2023, 2.5 marks)

Genetic Algorithms are based on natural evolution. They simulate the process of natural selection where the fittest individuals are selected for reproduction to produce the next generation. GA uses concepts like mutation, crossover, and selection to evolve solutions over generations.

How GA Works:
  1. Initialization – Generate a random population of possible solutions.
  2. Selection – Pick the best solutions (parents) based on their fitness score.
  3. Crossover (Recombination) – Combine two parent solutions to create new solutions (children).
  4. Mutation – Make small random changes to the new solutions to introduce diversity.
  5. Repeat for multiple generations until an optimal solution is found.
Encoding in Genetic Algorithms

PYQ: Define Encoding in Genetic algorithm. Describe the different encoding methods. (2024, 10 marks)

Encoding is the process of representing potential solutions (individuals) in a form that can be manipulated by genetic operators. The choice of encoding is crucial for the success of a genetic algorithm.

Major Types of Encoding Methods:
  1. Binary Encoding

    • Representation: Chromosomes are strings of 0s and 1s
    • Example: 10101101 might represent a solution
    • Advantages:
      • Simple to implement
      • Easy to apply genetic operators
    • Disadvantages:
      • May not be natural for many problems
      • May require more bits for precision
    • Applications: Simple parameter optimization, logical problems
  2. Value/Integer Encoding

    • Representation: Chromosomes are strings of integers or decimal values
    • Example: [4, 2, 7, 9, 5] might represent a solution
    • Advantages:
      • More natural for many problems
      • More compact than binary
    • Disadvantages:
      • Requires specialized genetic operators
    • Applications: Resource allocation, scheduling problems
  3. Permutation Encoding

    • Representation: Chromosomes are ordered sequences where each value appears exactly once
    • Example: [3, 5, 1, 2, 4] might represent an ordering/path
    • Advantages:
      • Natural for ordering problems
    • Disadvantages:
      • Requires special crossover/mutation operators to maintain validity
    • Applications: Traveling Salesman Problem, sequencing, scheduling
  4. Tree Encoding

    • Representation: Chromosomes are tree structures
    • Example: Expression trees for mathematical functions
    • Advantages:
      • Can represent hierarchical solutions
      • Variable length representations
    • Disadvantages:
      • Complex genetic operators
    • Applications: Program evolution, symbolic regression
  5. Real-Value Encoding

    • Representation: Chromosomes are vectors of floating-point numbers
    • Example: [3.14, 2.71, 9.81]
    • Advantages:
      • Natural for continuous optimization
      • High precision
    • Disadvantages:
      • Requires specialized operators
    • Applications: Function optimization, neural network weights
Selection Methods in Genetic Algorithms

PYQ: Write short notes on: (i) Roulette Wheel selection (ii) Tournament selection (2024, 5 marks)

Selection determines which individuals will become parents for the next generation. It's based on the principle that fitter individuals have a higher chance of reproduction.

1. Roulette Wheel Selection
  • How it works:

    • Each individual gets a slice of a circular "roulette wheel"
    • The size of the slice is proportional to the individual's fitness
    • The wheel is spun and the individual where it stops is selected
    • Higher fitness = larger slice = higher chance of selection
  • Mathematical representation:

    • Probability of selection = Individual's fitness / Sum of all fitness values
  • Example:

    • If we have 4 individuals with fitness values [4, 2, 8, 6]:
    • Total fitness = 20
    • Selection probabilities = [20%, 10%, 40%, 30%]
    • A random number generator simulates the wheel spin
  • Advantages:

    • Simple to implement
    • Selection pressure naturally adjusts with fitness distribution
  • Disadvantages:

    • Can be biased if fitness differences are too high or too low.
    • Can lead to premature convergence if one solution is much fitter
    • May lose diversity quickly
2. Tournament Selection
  • How it works:

    • Randomly select k individuals from the population (k is tournament size)
    • Choose the best individual from this group as a parent
    • Repeat to select enough parents
  • Types:

    • Deterministic: Always select the best from the tournament
    • Probabilistic: Select individuals based on probability related to rank
  • Example:

    • With tournament size k=3:
    • Randomly select individuals [5, 2, 9]
    • Choose individual 9 (highest fitness) as parent
  • Advantages:

    • Easy to adjust selection pressure via tournament size
    • Does not require fitness scaling
    • Works well for parallel implementations
  • Disadvantages:

    • May need tuning of tournament size
    • Smaller tournaments can lead to slower convergence
Example:
  • AI designing aircraft wings with optimal aerodynamics.
  • Stock market prediction models optimizing investment strategies.
Advantages of GA:
  • Works well for large, complex problems.
  • Finds good solutions even if an exact solution is unknown.
  • Can handle discontinuous, non-differentiable functions
  • Parallelizable - multiple solutions can be evaluated simultaneously
Disadvantages of GA:
  • Can be slow for real-time applications.
  • Does not guarantee the absolute best solution.
  • Requires careful parameter tuning
  • May converge prematurely to suboptimal solutions
Comparison: ACO vs. GA
FeatureAnt Colony Optimization (ACO)Genetic Algorithm (GA)
Inspired ByAnts finding foodNatural evolution
Best ForPath optimization problemsGeneral optimization problems
Selection StrategyStrongest pheromone trailBest-fit solutions
Improvement MechanismReinforcing best pathsCrossover & mutation
Convergence SpeedCan be slowFaster in many cases
Memory UsageModerate (pheromone trails)High (population of solutions)
ApplicationsRouting, schedulingFunction optimization, machine learning
  • ACO is better for pathfinding and routing problems, while GA is more versatile for various optimization tasks.

Section 3: Game Playing in AI

PYQ: What do you mean by Game playing in AI? (2021, 7 marks)

Game playing is an important area in Artificial Intelligence (AI). It involves developing algorithms that can play games against human players or other AI systems. Game-playing AI is used in various applications, including board games, video games, and simulations.

Game-playing AI uses search algorithms to find the best moves in competitive games like chess, tic-tac-toe, and checkers. Two key algorithms used are:

  1. Min-Max Algorithm (for decision-making in two-player games).
  2. Alpha-Beta Pruning (an optimization of Min-Max).

Applications of Game Playing in AI

  1. Chess and Checkers: AI like IBM's Deep Blue defeated world chess champions using advanced game-playing algorithms.
  2. Tic-Tac-Toe: Simple games are used to teach basic AI concepts and algorithms.
  3. Go: Google's AlphaGo used advanced AI techniques to beat human champions.
  4. Video Games: AI creates intelligent non-player characters (NPCs) that can adapt to player strategies.

3.1 Min-Max Algorithm

The Min-Max Algorithm is used in zero-sum games, where one player’s gain is another’s loss. The algorithm assumes both players play optimally and tries to maximize the chances of winning.

The Min-Max algorithm is used in two-player games where players take turns. It is designed for games with the following characteristics:

  • Deterministic: No randomness in the game, like chess.
  • Zero-sum: One player’s gain is the other player’s loss.

How Min-Max Works:

  1. The game is represented as a tree where:
    • Maximizing player (MAX) tries to get the highest score.
    • Minimizing player (MIN) tries to lower the score.
  2. The algorithm evaluates all possible moves up to a certain depth.
  3. It assigns scores to each move based on a heuristic evaluation function.
  4. MAX chooses the move with the highest value, while MIN chooses the lowest value.
  5. The best move is selected based on the recursive evaluation of all possible moves.

Example (Tic-Tac-Toe):

Consider a game tree where MAX (X) is trying to win, and MIN (O) is trying to block:

         (MAX)  
         /    \  
      (MIN)  (MIN)  
      /   \    /   \  
    (3)   (5) (2)   (9)
  • MIN selects the smallest value from its child nodes → {3,5} → 3 and {2,9} → 2.
  • MAX then picks the largest value {3,2} → 3.

Result: MAX plays the move that leads to score 3.

Advantages of Min-Max:

  • Finds the optimal move if all possibilities are explored.
  • Works well for turn-based strategic games.
  • Guarantees the best outcome for the maximizing player.

Disadvantages of Min-Max:

  • Computationally expensive for deep game trees.
  • Explores unnecessary branches, making it slow.
  • Requires a good evaluation function to assess game states.

3.2 Alpha-Beta Pruning

PYQ: What do you mean by Game Playing: Min-Max Algorithm and Alpha-Beta Pruning? Explain in detail. (2022, 15 marks)
PYQ: Explain Alpha-Beta pruning with example. What is the need of pruning? (2021, 8 marks)

Alpha-Beta Pruning is an optimization algorithm that improves the efficiency of the Min-Max algorithm by ignoring branches that will not affect the final decision. It cuts off unnecessary branches in the search tree, reducing computation time.

Key Idea: If one move is clearly worse than another, there’s no need to explore further moves in that branch.

Need for Pruning:

  • Efficiency: Reduces the number of nodes evaluated in the Min-Max tree.
  • Speed: Allows deeper searches in the same time frame.
  • Memory Usage: Reduces memory requirements by not storing all nodes.
  • Optimality: Still guarantees the best move.
  • Complexity: Reduces the complexity of the search space.
  • Performance: Improves performance in large games like chess and checkers.

How Alpha-Beta Pruning Works:

  1. The algorithm uses two values:
    • Alpha (α): The best score that the Max player can guarantee so far.
    • Beta (β): The best score that the Min player can guarantee so far.
  2. While exploring the game tree:
    • If the Max player finds a move better than the current Beta, the Min player will avoid that branch.
    • If the Min player finds a move worse than the current Alpha, the Max player will avoid that branch.
  3. This "pruning" reduces the number of nodes to evaluate.

If at any point, α ≥ β, the algorithm can stop exploring that branch because it won't affect the final decision.

Example:

  • In a chess game: If one move leads to a checkmate in fewer steps, other longer paths are ignored.

Example of Pruning:

         (MAX)  
         /    \  
      (MIN)  (MIN)  
      /   \    /   \  
    (3)   (5)  (2)   (9)
  1. MIN at the left picks the minimum (3).
  2. MAX sees 3 and knows it’s better than the right branch’s worst possible outcome (≥2).
  3. MAX ignores further calculations in the right branch (pruning).

Advantages of Alpha-Beta Pruning:

  • Speeds up Min-Max by pruning unnecessary branches.
  • Reduces time complexity from O(b^d) to O(b^(d/2)) in the best case.
  • Can reach the best move faster.
  • Reduces memory usage by not storing all nodes.
  • Allows deeper searches in the same time frame.

Disadvantages of Alpha-Beta Pruning:

  • Still slow for large games if not well optimized.
  • Requires careful ordering of moves for maximum pruning.
  • Complexity increases with the number of players.
  • May not work well with non-deterministic games.
Comparison: Min-Max vs Alpha-Beta Pruning
FeatureMin-Max AlgorithmAlpha-Beta Pruning
WorkingExplores all movesPrunes unnecessary moves
EfficiencySlow for deep treesFaster due to pruning
Best ForSmall gamesComplex games (chess, go)
Memory UsageHigh (stores all nodes)Lower (prunes branches)
OptimalityGuarantees optimal moveGuarantees optimal move
ComplexityO(b^d)O(b^(d/2)) (best case)
Use CasesSimple gamesComplex games (AI, robotics)
  • Min-Max explores all possible moves, while Alpha-Beta Pruning optimizes the search by ignoring branches that won't affect the final decision.
  • Min-Max is slower for deep trees, while Alpha-Beta Pruning is faster due to pruning unnecessary branches.

Found an error or want to contribute?

This content is open-source and maintained by the community. Help us improve it!