Q1 Solve any three
a) Explain different knowledge representations with example.
Ans:
b) Write a short note on Bayesian Theorem.
Ans:
c) Explain Wumpus world environment giving its PEAS description.
Ans:
d) Explain Modus ponens with suitable examples.
Ans:
Q2 Solve any one.
a) Formulate the state space search problems for 8 puzzle problems.
Ans:
🧠 What is Hierarchical Planning?
b) Explain the real time application of hierarchical planning.
Ans:
Hierarchical planning is a type of AI planning where complex tasks are broken down
into smaller sub-tasks in a top-down structure, like a tree.
It’s commonly used in areas where decisions and actions must happen in real time, and
where plans can change dynamically based on conditions.
🏗️ Example of Hierarchical Planning Structure:
Goal: Prepare dinner
→ Sub-goal 1: Cook rice
→ Sub-goal 2: Make curry
→ Sub-tasks: Chop veggies, boil water, etc.
This way, each big task is divided into manageable steps — and the system can react
quickly if something changes.
⚙️ Real-Time Applications of Hierarchical Planning:
1. 🚗 Autonomous Vehicles (Self-Driving Cars)
● High-level plan: Reach destination.
● Mid-level plans: Follow route, obey traffic rules.
● Low-level actions: Turn, accelerate, stop, avoid obstacles.
● Hierarchical planning helps cars adapt quickly to changes (e.g., sudden traffic,
roadblocks).
2. 🕹️ Robotics
● Used in robot assistants, factory robots, or cleaning bots.
● Top level: Complete a task (e.g., clean room).
● Sub-tasks: Move to room → Detecting dirt → Vacuum → Return to base.
● Hierarchical planning makes robots flexible and efficient in dynamic
environments.
3. 🎮 Video Games & Game AI
● NPCs (non-player characters) use hierarchical planning to make decisions.
● Example: A guard NPC
○ Goal: Patrol area
○ Sub-goals: Walk to points → Check surroundings → Engage intruders
● Makes characters appear intelligent and responsive.
4. ✈️ Military and Defense Systems
● For mission planning and execution in drones or combat simulations.
● Top level: Secure area
● Sub-tasks: Fly route → Monitor targets → Report back
● Enables real-time decision making during missions.
5. 🚑 Healthcare Assistive Systems
● AI agents assist doctors or elderly patients.
● Top goal: Monitor patient’s health
● Sub-tasks: Collect vitals → Detect anomalies → Notify caregiver
● Helps in real-time health monitoring and alerts.
6. 🏭 Industrial Automation
● In smart factories, machines plan and adjust tasks in real time.
● Example: Manufacturing a product
○ Sub-tasks: Fetch part → Assemble → Test → Pack
✅ Why is Hierarchical Planning Good for Real-Time Applications?
● Faster decision-making by simplifying complex tasks.
● Modularity – each layer can be handled separately.
● Reactivity – if a sub-task fails, it can re-plan locally without restarting the whole
plan.
● Great for systems that need to adapt on the fly.
Q3 Solve any one.
🧠 What is NLP?
a) Write a short note : Steps in Natural Language Processing.
Ans:
Natural Language Processing (NLP) is a branch of AI that allows computers to
understand, interpret, and generate human language.
🪜 Main Steps in Natural Language Processing:
Here are the typical steps followed in an NLP pipeline:
1. Text Preprocessing 🧹
This step cleans and prepares the text data for further analysis.
Key tasks:
● Tokenization – Splitting text into words, sentences, or phrases.
E.g., "I love NLP" → ["I", "love", "NLP"]
● Lowercasing – Converting all words to lowercase to avoid case sensitivity.
● Stop Word Removal – Removing common words that don’t carry much meaning
(like “is”, “the”, “a”).
● Stemming – Reducing words to their base/root form.
E.g., “running” → “run”
● Lemmatization – Similar to stemming but more accurate, considers the word’s
context.
E.g., “better” → “good”
● Removing punctuation, numbers, etc.
2. Part-of-Speech (POS) Tagging 🏷️
Assigns grammatical tags to each word in the sentence.
● Example:
“Cats sit on the mat.” → [Cats/NNS, sit/VBP, on/IN, the/DT, mat/NN]
Helps the system understand sentence structure.
3. Named Entity Recognition (NER) 🏙️
Identifies names, places, dates, organizations, etc., in the text.
● Example:
“Elon Musk founded SpaceX in 2002.” → Elon Musk (Person), SpaceX (Organization),
2002 (Date)
4. Syntactic Analysis (Parsing) 🌲
Analyzes grammar and structure of the sentence using parse trees.
● Helps in understanding how words are related.
● Dependency parsing shows which words depend on others.
5. Semantic Analysis 💬
Extracts meaning from the text.
Includes:
● Word Sense Disambiguation – Choosing the correct meaning of a word (e.g.,
"bank" as a river or a financial institution).
● Semantic Role Labeling – Finding who did what to whom, when, and where.
6. Coreference Resolution 🔄
Identifies when different words refer to the same entity.
● Example:
“John went to the park. He was happy.” → “He” refers to “John”.
7. Sentiment Analysis 😊😐😠
Determines the emotional tone of the text.
● Is the sentence positive, negative, or neutral?
8. Text Classification / Intent Detection 🗂️
Assigns categories or labels to the text.
● Used in spam detection, topic modeling, or chatbots.
9. Language Generation (Optional) ✍️
In some applications (like chatbots or translation), the system also generates human-like
text based on understanding.
📌 Summary Diagram of NLP Pipeline:
Raw Text
↓
Preprocessing (tokenization, stop words, stemming)
↓
POS Tagging
↓
Named Entity Recognition
↓
Parsing (Syntax)
↓
Semantic Analysis
↓
Coreference Resolution
↓
Sentiment/Intent Analysis
↓
(Optional) Text Generation
b) Explain Al applications.
Ans: Artificial Intelligence (AI) refers to machines or software that can simulate human intelligence
— such as learning, reasoning, problem-solving, and decision-making.
🧠
Field Applications
1. Healthcare ● Medical diagnosis (e.g., AI detects tumors in X-rays or MRIs)
● Virtual health assistants and chatbots
● Drug discovery and personalized treatment plans
🚗 Transportation
● Remote patient monitoring
2. ● Self-driving cars (e.g., Tesla Autopilot)
● Traffic prediction and route optimization
🛒 E-commerce & Retail
● Fleet management and logistics automation
3. ● Product recommendations (like on Amazon)
● Chatbots for customer support
📱 Smart Assistants
● Inventory management and dynamic pricing
4. ● Voice assistants like Siri, Alexa, Google Assistant
5. 💬 Natural Language
● Understand voice commands, schedule events, answer questions
● Language translation (e.g., Google Translate)
Processing (NLP) ● Text summarization, sentiment analysis
🧾 Finance
● Speech-to-text, text-to-speech
6. ● Fraud detection
● Automated trading algorithms
● Credit scoring & risk assessment
🎮 Gaming
● Customer support bots
7. ● Game AI opponents (adaptive difficulty)
● Procedural content generation
🏭
● Realistic behavior in NPCs (non-player characters)
8. Manufacturing & ● Robotics for automation
Industry ● Predictive maintenance (anticipate equipment failure)
🎥 Entertainment & Media
● Quality control using computer vision
9. ● Content recommendation (e.g., Netflix, YouTube)
● Deepfake generation
🔐
● AI-driven content creation (music, writing, video)
10. Security & ● Face recognition
Surveillance ● Intrusion detection
● AI-based cybersecurity tools
AI Assignment 2
Unit 4
1. What is a knowledge Based Agent?
Ans: A Knowledge-Based Agent (KBA) is an intelligent agent that makes decisions based on
knowledge stored in a structured format. It uses logical reasoning and inference to interpret data, solve
problems, and make informed decisions.
Key Components of a Knowledge-Based Agent:
1. Knowledge Base (KB) – A structured repository containing facts and rules about the
world.
2. Inference Engine – A system that applies logical reasoning to the knowledge base to
derive new knowledge or make decisions.
3. Perception Module – Gathers new information from the environment.
4. Learning Mechanism – Updates the knowledge base with new information.
How It Works:
1. The agent perceives the environment.
2. It updates its knowledge base with new information.
3. The inference engine analyzes the knowledge and derives conclusions.
4. The agent makes decisions and takes actions based on reasoning.
Examples of Knowledge-Based Agents:
● Expert Systems (e.g., Medical diagnosis systems)
● Chatbots with Rule-Based Logic
● AI Assistants that use Logical Reasoning
● Game-playing AI that uses stored knowledge
2 Explain the various methods of Knowledge representation techniques ?
Ans: Knowledge representation (KR) is the way artificial intelligence (AI) stores and manipulates
knowledge to make intelligent decisions. The four main techniques of knowledge representation are:
1. Logical Representation
Uses formal logic to represent facts and relationships.
Types:
● Propositional Logic (PL): Uses simple statements (e.g., "It is raining").
● First-Order Logic (FOL): Uses objects, relations, and quantifiers (e.g., "All humans are
mortal").
✅✅
Advantages:
Precise and unambiguous representation
Allows inference using rules
❌❌
Disadvantages:
Computationally expensive
Difficult to handle uncertainty
2. Semantic Network Representation
Represents knowledge as a graph with nodes (concepts) and edges (relationships).
Example:
● "A dog is a mammal" → Represented as a node Dog linked to a node Mammal with an
"is-a" relation.
✅✅
Advantages:
Human-like representation
Easy to visualize
❌❌
Disadvantages:
Difficult to handle complex or uncertain relationships
Inefficient for large databases
3. Frame Representation
Uses structured templates (frames) to store knowledge about objects, events, or situations.
Example (Car Frame):
Frame: Car
- Type: Sedan
- Color: Red
- Owner: John
✅✅
Advantages:
Organizes knowledge in an easy-to-access way
Can include default values for missing information
❌❌
Disadvantages:
Not suitable for dynamic knowledge
Can become complex for large systems
4. Production Rules Representation
Uses if-then rules to represent actions and conditions.
Example:
● Rule: If it is raining, then take an umbrella.
○ IF (condition) → THEN (action)
✅✅
Advantages:
Easy to understand and implement
Good for decision-making
❌❌
Disadvantages:
Can become large and difficult to manage
Slower due to sequential rule evaluation
Comparison Table
Method Strengths Weaknesses
Logical Representation Precise, allows inference Computationally expensive
Semantic Networks Intuitive, human-like Inefficient for large knowledge bases
Frames Structured, easy retrieval Not suitable for dynamic knowledge
Production Rules Simple, decision-making Hard to manage large rule sets
3. Write a short note on predicate logic.
Ans: Predicate Logic, also known as First-Order Logic (FOL), is a powerful knowledge representation
technique used in Artificial Intelligence (AI) to express complex relationships between objects. It
extends Propositional Logic by introducing quantifiers, predicates, and variables, making it more
expressive.
Key Components of Predicate Logic
1. Constants – Represent specific objects.
○ Example: John, Apple, Car
2. Variables – Represent general entities.
○ Example: x, y, z
3. Predicates – Define relationships or properties of objects.
○ Example: Loves(John, Mary) → "John loves Mary."
4. Functions – Return a specific object related to input.
○ Example: Father(John) → David
5. Quantifiers – Specify the scope of variables.
○ Universal ( ∀ ): "For all" → ∀x Loves(x, IceCream)
○ Existential ( ∃ ): "There exists" → ∃x Loves(John, x)
Example in AI
● Fact: "All humans are mortal."
○ Predicate Logic: ∀x (Human(x) → Mortal(x))
● Fact: "Socrates is a human."
○ Predicate Logic: Human(Socrates)
● Inference: Since Socrates is a human and all humans are mortal, we infer:
○ Mortal(Socrates)
✅✅
Advantages of Predicate Logic in AI
More expressive than propositional logic
✅ Can handle variables and relationships
Enables inference and automated reasoning
❌❌
Disadvantages
Computationally expensive
Hard to implement in large AI systems
4. Explain forward chaining & Backward chaining Algorithm with example.
Ans: Forward chaining and backward chaining are two inference techniques used in rule-based
systems to derive conclusions from given facts and rules. These methods are widely used in Expert
Systems, AI Planning, and Automated Reasoning.
1. Forward Chaining Algorithm
Forward chaining is a data-driven reasoning approach that starts with known facts and applies
rules to derive new facts until a goal is reached.
Steps in Forward Chaining:
1. Start with initial facts.
2. Apply rules that match the facts.
3. Derive new facts from the applied rules.
4. Repeat until the goal is achieved or no more rules apply.
Example:
Knowledge Base (Rules):
1. IF (It rains) → THEN (The ground is wet)
2. IF (The ground is wet) → THEN (People carry umbrellas)
Given Fact:
● "It is raining."
Forward Chaining Process:
● Step 1: It rains → The ground is wet (Rule 1)
✅
● Step 2: The ground is wet → People carry umbrellas (Rule 2)
● Conclusion: People carry umbrellas.
✅
Use Cases:
Expert Systems (Medical Diagnosis)
✅
✅ Automated Decision Making
AI Planning (Robot Path Planning)
2. Backward Chaining Algorithm
Backward chaining is a goal-driven reasoning approach that starts with a goal and works
backward to find supporting facts.
Steps in Backward Chaining:
1. Start with a goal (hypothesis).
2. Check if the goal is directly known. If not, find a rule that can lead to the goal.
3. Recursively prove the conditions of the rule using known facts.
4. If all conditions are met, the goal is confirmed.
Example:
Goal: "Do people carry umbrellas?"
Knowledge Base (Rules):
1. IF (The ground is wet) → THEN (People carry umbrellas)
2. IF (It rains) → THEN (The ground is wet)
Backward Chaining Process:
● Step 1: To prove "People carry umbrellas," check if the ground is wet (Rule 1).
● Step 2: To prove "The ground is wet," check if it is raining (Rule 2).
✅
● Step 3: If it is known that "It is raining," then "People carry umbrellas" is confirmed.
✅✅
Use Cases:
Medical Diagnosis (Proving a disease based on symptoms)
✅ Expert Systems (Legal Reasoning)
AI Chatbots (Logical Question Answering)
Comparison Table:
Feature Forward Chaining Backward Chaining
Approach Data-driven (Starts from facts) Goal-driven (Starts from hypothesis)
Usage Generating new facts Proving a given goal
Best for Large knowledge bases, AI Planning Diagnosis, Expert Systems
Example Weather forecasting, AI Planning Medical Diagnosis, Chatbots
5. Why uncertainty occurs in the AI system. How to apply probability to a toothache
problem?
Ans: Uncertainty in AI arises when the system lacks complete, exact, or reliable information to make
decisions. This happens due to several reasons:
Causes of Uncertainty in AI:
1. Incomplete Knowledge: AI does not have all facts about the environment.
2. Noisy or Inaccurate Data: Sensors and inputs may provide incorrect or partial information.
3. Ambiguity: Different interpretations of the same data (e.g., natural language understanding).
4. Unpredictable Environments: Real-world systems change dynamically.
5. Probabilistic Events: Some events occur with a certain likelihood rather than certainty.
To handle uncertainty, AI uses probabilistic reasoning, especially Bayesian Probability.
Applying Probability to the Toothache Problem
Problem Statement:
We want to determine the probability that a person has a cavity (C) given that they have a
toothache (T).
6. Write a short note on belief Networks.
Ans: A Belief Network, also called a Bayesian Network (BN), is a probabilistic graphical model that
represents dependencies among random variables using a directed acyclic graph (DAG). It is widely
used in AI for reasoning under uncertainty.
Key Components of a Belief Network:
1. Nodes: Represent random variables (e.g., diseases, symptoms, sensor readings).
2. Edges: Directed connections between nodes, showing causal relationships.
3. Conditional Probability Tables (CPTs): Define the probability of a node given its parent
nodes.
Example: Medical Diagnosis
Consider a belief network for diagnosing a cavity (C) based on symptoms like toothache (T) and
catching food between teeth (F):
Cavity (C)
/ \
Toothache (T) Food Caught (F)
● The probability of Toothache depends on the presence of a Cavity.
● The probability of Food getting caught also depends on Cavity.
● The model uses Bayesian Probability to compute the likelihood of a cavity given
symptoms.
✅✅
Advantages of Belief Networks:
Efficient reasoning under uncertainty
✅ Models complex relationships in a structured way
Supports probabilistic inference
🔹🔹
Applications:
Medical Diagnosis (Identifying diseases based on symptoms)
🔹 Spam Filtering (Determining email spam likelihood)
Autonomous Systems (Self-driving cars predicting road conditions)
Unit5
1. What is planning in AI?
Ans: Planning in AI is the process of determining a sequence of actions that an intelligent agent should
take to achieve a specific goal. It is a fundamental area of Artificial Intelligence (AI) that enables
autonomous systems to make decisions and execute tasks efficiently.
Key Aspects of AI Planning:
1. Initial State – The starting condition of the system.
2. Goal State – The desired outcome that the agent wants to achieve.
3. Actions – The set of possible operations that can change the state.
4. Constraints – Rules or limitations on the actions.
5. Plan – A sequence of actions leading from the initial state to the goal state.
Types of AI Planning:
1. Classical Planning – Assumes a fully known and deterministic environment.Example: A chess-playing
AI planning moves.
2. Hierarchical Planning (HTN) – Breaks the problem into subgoals to simplify planning.Example: A
robot breaking a complex task (e.g., making coffee) into smaller steps.
3. Conditional Planning – Handles uncertain environments by considering possible future
scenarios.Example: A self-driving car considering different traffic conditions.
4. Probabilistic Planning – Uses probability models to deal with unpredictable outcomes.Example: A
weather prediction AI planning evacuation strategies.
Example of AI Planning: Robot Navigation
Problem: A robot must move from Point A to Point B in a grid.
1. Initial State: Robot is at Point A.
2. Goal State: Robot reaches Point B.
3. Actions: Move Up, Down, Left, Right.
4. Constraints: Avoid obstacles.
5. Plan: The AI finds the best path using algorithms like A Search* or Dijkstra’s Algorithm.
✅✅
Applications of AI Planning:
Robotics (Autonomous robots planning movement)
✅
✅
Game AI (AI planning strategies in video games)
Healthcare (AI planning treatment plans for patients)
Supply Chain Management (Optimizing logistics and scheduling)
2. Compare and Contrast problem solving agent planning agent.
Ans:
Feature Problem-Solving Agent Planning Agent
Definition An agent that searches for a sequence of actions
An agent that constructs a detailed plan before
to reach a goal using search algorithms. executing actions.
Approach Uses search algorithms (e.g., BFS, DFS, A*). Uses structured planning techniques (e.g.,
STRIPS, PDDL, Hierarchical Planning).
Representation Actions are implicitly defined through a search Actions are explicitly represented in a structured
of Actions space. format.
Execution Style Generates a solution on-the-fly using search. Constructs a plan before execution and then
follows it.
Flexibility Can handle unknown or dynamic Works best in well-defined, predictable
environments through reactive search. environments.
Efficiency Can be inefficient for complex problems since it More efficient for structured tasks as it optimizes
explores many possibilities. sequences of actions.
Eg Algorithm A* Search, DFS, BFS, Greedy Search STRIPS, Hierarchical Task Networks (HTN)
Example Use Solving a maze, playing chess, or pathfinding Robot navigation, autonomous vehicles, logistics
Case in games. planning.
3. Explain partial order planning, Hierarchical planning.
Ans:
1. Partial Order Planning (POP)
Partial Order Planning (POP) is a type of planning algorithm that generates a flexible sequence
🔹of actions where some actions are ordered, but others remain unordered until needed.
Key Idea: Unlike sequential planning (where actions are strictly ordered), POP allows
actions to be performed in any order as long as dependencies are met.
How Partial Order Planning Works:
1. Define the initial state and goal state.
2. Identify actions needed to achieve the goal.
3. Establish constraints (dependencies between actions).
4. Generate a partial order of actions where only necessary dependencies are enforced.
Example: (Making Tea)
● Goal: Prepare a cup of tea.
● Actions:
1. Boil water.
2. Add a tea bag to a cup.
3. Pour hot water into the cup.
🔹 4. Stir and serve.
Partial Order Plan:
● "Boil water" must happen before "Pour hot water into the cup."
● "Add tea bag" can happen before or after boiling water, as long as it is done before
pouring.
✔ Flexible Execution → The exact sequence depends on available resources.
✅✅
Advantages of Partial Order Planning:
More flexible than total order planning.
✅ Efficient for parallel execution of independent tasks.
Avoids unnecessary constraints in task ordering.
🔹🔹
Applications:
Multi-agent systems (e.g., robots working together).
🔹 AI planning in unpredictable environments.
Task scheduling and workflow automation.
2. Hierarchical Planning (Hierarchical Task Network - HTN)
Hierarchical Planning (also called Hierarchical Task Network - HTN) breaks down a complex
🔹goal into smaller subgoals.
Key Idea: Decomposing a high-level goal into smaller tasks makes planning more structured
and manageable.
How Hierarchical Planning Works:
1. Start with a high-level goal.
2. Break it into subgoals (smaller tasks).
3. Continue decomposing until the tasks are simple enough to execute.
4. Execute the plan step by step.
Example: (Planning a Trip)
● High-Level Goal: Travel from City A to City B
● Decomposition:
○ Book a flight.
■ Search for available flights.
■ Compare ticket prices.
■ Purchase a ticket.
○ Pack bags.
○ Arrange transportation to the airport.
✔ Structured Execution → Each subgoal must be completed before moving to the next stage.
✅✅
Advantages of Hierarchical Planning:
More organized and structured than flat planning.
✅ Improves efficiency by solving smaller problems first.
Allows for reusability of subplans in different scenarios.
🔹🔹
Applications:
Robotics (Breaking down complex tasks like cooking or cleaning).
🔹 Game AI (Managing character behaviors with structured decision-making).
Enterprise Workflows (Automating business processes with multiple steps).
Comparison: POP vs. Hierarchical Planning
Feature Partial Order Planning (POP) Hierarchical Planning (HTN)
Approach Defines a set of loosely ordered actions Breaks down tasks into subgoals
Execution Flexibility High (actions can be done in different orders) Low (follows a structured sequence)
Best for Parallel tasks with dependencies Complex problems that need decomposition
Example Scheduling parallel robot tasks Planning a multi-step journey
4. Explain various methods of learning.
Ans: Learning in AI refers to the process by which an artificial intelligence system improves its
performance over time by gaining experience from data. AI learning is classified into four main types:
🔹
1. Supervised Learning
Definition: The AI model learns from labeled training data, where each input has a
🔹corresponding correct output.
How it works:
1. The model is trained on input-output pairs.
2. It makes predictions and adjusts based on errors.
🔹 3. After sufficient training, the model can generalize to new data.
Example:
● Email Spam Detection: Given emails labeled as spam or not spam, the model learns to
classify new emails.
● Face Recognition: AI is trained with images labeled with people’s names to recognize
🔹✅ faces.
Popular Algorithms:
✅
✅
Decision Trees
Support Vector Machines (SVM)
✅ Neural Networks (Deep Learning)
Random Forest
🔹🔹
2. Unsupervised Learning
Definition: The AI model learns patterns from unlabeled data without predefined categories.
How it works:
1. The model identifies hidden structures in the data.
2. It groups similar data points together (clustering) or finds relationships (association).
🔹 3. No explicit correct output is given.
Example:
● Customer Segmentation: Grouping customers based on buying behavior for targeted
marketing.
● Anomaly Detection: Detecting fraud in banking transactions by finding unusual
🔹✅ patterns.
Popular Algorithms:
✅
✅
K-Means Clustering
Hierarchical Clustering
Principal Component Analysis (PCA)
🔹
3. Semi-Supervised Learning
Definition: A combination of supervised and unsupervised learning, where a small amount
🔹
of labeled data is used along with a large set of unlabeled data.
How it works:
1. The model learns from labeled data first.
2. It generalizes the learned patterns to label the unlabeled data.
🔹 3. This method is useful when labeling large datasets is costly.
Example:
● Medical Diagnosis: AI is trained on a small dataset of labeled X-rays and then applies its
learning to detect diseases in unlabeled X-rays.
● Speech Recognition: A few transcribed audio files help AI improve automatic
🔹✅ transcription for vast amounts of untranscribed speech.
Popular Algorithms:
✅ Self-training models
Graph-based algorithms
🔹
4. Reinforcement Learning (RL)
Definition: The AI model learns by trial and error, receiving rewards or penalties based on
🔹
its actions.
How it works:
1. The AI (agent) interacts with an environment.
2. It takes actions and observes the outcome.
3. If the action leads to success, it gets rewarded; if not, it gets penalized.
🔹 4. The goal is to maximize cumulative rewards over time.
Example:
● Game Playing: AI like AlphaGo and DeepMind’s AlphaZero learns strategies by playing
millions of games.
● Autonomous Cars: AI learns to drive by making decisions and improving based on
🔹✅ traffic conditions.
Popular Algorithms:
✅
✅
Q-Learning
Deep Q-Networks (DQN)
Policy Gradient Methods
Comparison Table
Feature Supervised Learning Unsupervised Learning Semi-Supervised Learning Reinforcement Learning
Training Labeled Unlabeled Mix of labeled & unlabeled Rewards & penalties
Data
Goal Predict output from Find hidden patterns Improve learning with less Learn best actions over
input data time
Example Image classification, Customer Segmentation, Medical Diagnosis, Speech Robotics, Game AI
Speech Recognition Anomaly Detection Analysis
Algos Neural Networks, SVM, K-Means, PCA, DBSCAN Self-training, Graph-based Q-Learning, DQN
Decision Trees methods
5. Explain supervised, unsupervised and reinforcement learning with examples.
Ans: These are the three primary types of learning paradigms in Artificial Intelligence (AI), each with
different applications and use cases. Let’s break each down with examples.
1. Supervised Learning
Definition:
In supervised learning, the AI model is trained using a labeled dataset, meaning that each
training example includes both the input and the correct output (or label). The model learns to
map inputs to outputs, using this information to predict outcomes for new, unseen data.
How it works:
1. The model is trained on labeled data (input-output pairs).
2. It makes predictions based on new inputs and compares the predictions to the actual
outcomes.
3. The model adjusts itself to minimize the difference (error) between predictions and
actual results using an optimization process (e.g., gradient descent).
Examples:
● Image Classification: Given a set of images labeled with categories (e.g., cat, dog, etc.), a
model learns to classify new images into one of these categories.
○ Application: An AI system classifies images of animals in a zoo as either "cat" or "dog."
● Email Spam Detection: The model is trained on a dataset of emails labeled as spam or
not spam. It then learns to predict whether new incoming emails are spam.
○ Application: Gmail uses supervised learning to classify new emails into spam and non-spam
categories.
● Medical Diagnosis: The model is trained with patient data labeled with conditions (e.g.,
“Healthy,” “Diabetic,” “Hypertensive”) and learns to classify new patient data into one
of those conditions.
○ Application: AI systems that help diagnose diseases based on medical records.
Algorithms:
● Linear Regression
● Logistic Regression
● Decision Trees
● Support Vector Machines (SVM)
● Neural Networks
2. Unsupervised Learning
Definition:
In unsupervised learning, the model is trained using data that does not have labels. The goal is
to find underlying patterns or structures in the data. The model explores the data on its own
and tries to group similar data points together or reduce dimensionality.
How it works:
1. The model is provided with input data that doesn't have corresponding labels.
2. It identifies patterns, clusters, or relationships in the data.
3. The model then groups similar data points or reduces the complexity of the data (dimensionality
reduction).
Examples:
● Customer Segmentation: In marketing, companies use unsupervised learning to group
customers based on purchasing behavior (e.g., high spenders, low spenders).
○ Application: An e-commerce platform groups customers into segments to target
with specific ads or promotions.
● Anomaly Detection: Unsupervised learning can detect outliers or unusual patterns in
data, such as fraud detection in financial transactions.
○ Application: Banks use unsupervised learning models to detect fraudulent
transactions that deviate from normal patterns.
● Clustering: Grouping data points into clusters where the points in a cluster are more
similar to each other than to points in other clusters (e.g., K-Means clustering).
○ Application: Organizing customer behavior data into different segments for
personalized marketing.
Algorithms:
● K-Means Clustering
● Hierarchical Clustering
● DBSCAN (Density-Based Spatial Clustering)
● Principal Component Analysis (PCA)
3. Reinforcement Learning (RL)
Definition:Reinforcement learning is a type of learning where an agent learns to make sequences of
decisions by interacting with an environment and receiving feedback in the form of rewards or
penalties. The goal is to maximize cumulative rewards over time by selecting actions that lead to
favorable outcomes.
How it works:
1. The agent interacts with the environment and performs actions.
2. After each action, the agent receives feedback (reward or penalty) based on the outcome.
3. The agent adjusts its strategy to maximize rewards over time using an exploration-exploitation
balance.
Examples:
● Game Playing (e.g., AlphaGo, Chess): The AI learns to play games by receiving rewards
for winning moves and penalties for losing moves. Over time, the AI learns strategies to
win.
○ Application: AlphaGo, an RL system, learned to play the game Go by playing millions of games
against itself and improving based on the outcomes.
● Self-Driving Cars: The car learns to drive by interacting with the environment, taking
actions (e.g., accelerating, turning), and receiving feedback (e.g., avoiding obstacles or
staying on the road).
○ Application: An autonomous vehicle uses RL to navigate roads safely while learning from
experience.
● Robotics: Robots can learn how to perform complex tasks (e.g., picking up objects,
assembling parts) through trial and error, receiving rewards for successful actions.
○ Application: A robotic arm in a factory learns to assemble parts efficiently by practicing and
adjusting based on feedback.
Algorithms:
● Q-Learning
● Deep Q-Networks (DQN)
● Policy Gradient Methods
● Actor-Critic Methods
Summary of Key Differences:
Feature Supervised Learning Unsupervised Learning Reinforcement Learning
Training Data Labeled data (input - output Unlabeled data (no output No labeled data, learns from
pairs) labels) interaction with environment
Goal Learn to map inputs to Find hidden patterns or Learn to make sequences of
correct outputs structures in data decisions to maximize rewards
Example Use Image classification, email Customer segmentation, Game playing, autonomous
Cases spam detection, medical anomaly detection, clustering driving, robotics
diagnosis
Algorithms Logistic Regression, SVM, K-Means, PCA, DBSCAN Q-Learning, Deep Q-Networks,
Neural Networks Policy Gradient Methods
6. What is a decision tree? Explain the decision tree with an example.
Ans: A decision tree is a supervised learning algorithm used for both classification and regression
tasks. It models decisions and their possible consequences, including chance event outcomes, resource
costs, and utility. The decision tree breaks down a complex decision-making process into simpler
decision steps, represented in the form of a tree structure. Each node of the tree represents a decision
rule or a test on an attribute, and each branch represents the outcome of the test.
Structure of a Decision Tree:
1. Root Node: The top node in the tree, which represents the entire dataset or problem. It is
split based on an attribute that gives the best classification.
2. Internal Nodes: These nodes represent decisions or tests based on certain attributes of
the dataset.
3. Branches: The branches represent the outcome of a test (e.g., yes/no, true/false).
4. Leaf Nodes: These represent the final decision or class label (in classification problems)
or a numeric value (in regression problems).
How a Decision Tree Works:
1. Select an Attribute for Splitting: The root node is selected based on the attribute that best
separates the data. This is typically done using measures like Gini Index (for
classification) or Variance Reduction (for regression).
2. Splitting the Data: Based on the attribute chosen, the data is split into subsets.
3. Recursive Splitting: The process of splitting the data continues recursively at each node,
creating a new branch.
4. Stopping Criterion: The tree-building process stops when:
○ A predefined depth is reached.
○ All data points in a node belong to the same class.
○ No further improvement can be made by splitting.
Example of a Decision Tree (Classification):
Problem: Predict whether a person will play tennis based on weather conditions.
Here’s the dataset with features like Outlook, Temperature, Humidity, and Wind:
Outlook Temperature Humidity Wind Play Tennis?
Sunny Hot High Weak No
Sunny Hot High Strong No
Overcast Hot High Weak Yes
Rainy Mild High Weak Yes
Rainy Cool Normal Weak Yes
Rainy Cool Normal Strong No
Overcast Cool Normal Strong Yes
Sunny Mild High Weak No
Sunny Cool Normal Weak Yes
Rainy Mild Normal Weak Yes
Steps to Build a Decision Tree:
1. Root Node (First Split):
○ Look at the attribute that best separates the data.
○ If we use the Outlook attribute (Sunny, Overcast, Rainy), it splits the data well,
with clear distinctions between "Play Tennis?" = Yes and No.
2. Splitting by Outlook:
○ Sunny: No (3 examples), Yes (2 examples)
○ Overcast: Yes (4 examples)
○ Rainy: Yes (3 examples), No (2 examples)
3. Further Splitting:
○ For Sunny Outlook: Look at Humidity to split.
■ High Humidity: No (3 examples)
■ Normal Humidity: Yes (2 examples)
○ For Rainy Outlook: Look at Wind.
■ Weak Wind: Yes (3 examples)
■ Strong Wind: No (2 examples)
4. Final Tree:
How to Interpret the Decision Tree:
● If the Outlook is Sunny and Humidity is High, the decision is No (won’t play tennis).
● If the Outlook is Rainy and Wind is Weak, the decision is Yes (will play tennis).
● If the Outlook is Overcast, the decision is Yes, regardless of other conditions.
✅✅
Advantages of Decision Trees:
Easy to understand and interpret — decision trees are simple to visualize and interpret.
Handle both categorical and continuous data — they can handle both types of data in
✅
classification and regression tasks.
✅ No need for feature scaling — decision trees do not require normalization of data.
Can be used for both classification and regression.
❌
Disadvantages of Decision Trees:
Overfitting: Decision trees can easily overfit the training data, especially if the tree is too
❌❌
deep.
Instability: Small changes in the data can lead to a completely different tree.
Bias towards certain features: If a feature has many levels, the tree may prioritize it over
others.
Applications of Decision Trees:
● Medical Diagnosis: Identifying whether a patient has a particular disease based on
symptoms.
● Finance: Deciding whether to approve a loan based on applicant data.
● Retail: Predicting customer behavior or product recommendations.
Unit 6
1.Explain different Components of NLP.
Ans: Natural Language Processing (NLP) is a subfield of AI that focuses on enabling computers to
understand, interpret, and generate human language in a way that is meaningful. NLP has a variety of
components that work together to process natural language data effectively. These components can be
broadly divided into several categories:
🔹
1. Tokenization
Definition: Tokenization is the process of splitting text into smaller units, such as words,
🔹phrases, or sentences, known as tokens.
Purpose: Tokenization helps break down a large text into manageable pieces for further
🔹analysis.
Example:
● Input text: "I love programming."
● Output tokens: ["I", "love", "programming"]
🔹
2. Part-of-Speech (POS) Tagging
Definition: POS tagging involves labeling each token (word) in a sentence with its
🔹
appropriate part of speech (noun, verb, adjective, etc.).
Purpose: It helps in understanding the grammatical structure of a sentence and
🔹disambiguates meanings of words depending on context.
Example:
● Input: "She runs fast."
● Output: [("She", "PRP"), ("runs", "VBZ"), ("fast", "RB")]
(Here, PRP is a pronoun, VBZ is a verb, and RB is an adverb.)
🔹
3. Named Entity Recognition (NER)
Definition: NER is the process of identifying and classifying named entities in text into
🔹predefined categories such as persons, organizations, locations, dates, etc.
Purpose: NER helps in extracting valuable information from unstructured text, like finding
🔹people's names or location mentions.
Example:
● Input: "Apple Inc. is based in Cupertino, California."
● Output: [("Apple Inc.", ORGANIZATION), ("Cupertino", LOCATION), ("California",
LOCATION)]
🔹
4. Syntax Parsing
Definition: Syntax parsing involves analyzing the sentence structure to determine the
grammatical relationships between words. This is done through parse trees or dependency
🔹trees.
Purpose: It allows the system to understand how words are related and how they combine
🔹to form meaning in a sentence.
Example:
● Input: "The cat sat on the mat."
● Output: (Parse tree with "The cat" as the subject, "sat" as the verb, "on the mat" as the
prepositional phrase.)
🔹
5. Lemmatization and Stemming
Definition:
● Stemming reduces words to their root form by chopping off prefixes or suffixes (e.g.,
"running" → "run").
● Lemmatization is more sophisticated and reduces words to their dictionary form (e.g.,
"running" → "run", but "better" → "good").
🔹 Purpose: These techniques help to group different forms of a word into a single item,
●
🔹 Example:
improving matching and analysis.
Input: "The cats are running."
● Stemming output: ["The", "cat", "are", "run"]
● Lemmatization output: ["The", "cat", "are", "run"]
🔹
6. Sentiment Analysis
Definition: Sentiment analysis is the process of determining the emotional tone or opinion
🔹expressed in a piece of text (positive, negative, or neutral).
Purpose: This helps in understanding the sentiment behind a piece of text, which is useful
🔹in applications like social media analysis or customer reviews.
Example:
● Input: "I love this new phone!"
● Output: Positive sentiment.
🔹
7. Machine Translation
Definition: Machine translation is the process of automatically translating text or speech
🔹from one language to another.
Purpose: To break down language barriers and make information accessible across different
🔹languages.
Example:
● Input: "Hola, ¿cómo estás?" (Spanish)
● Output: "Hello, how are you?" (English)
🔹
8. Coreference Resolution
Definition: Coreference resolution is the process of determining which words in a text refer
to the same entity. This involves resolving pronouns and noun phrases to the entities they refer
🔹to.
Purpose: It helps improve understanding by associating pronouns like "he", "she", or "it"
🔹with their proper referents in a sentence.
Example:
● Input: "John went to the store. He bought milk."
● Output: "He" refers to "John."
🔹
9. Word Sense Disambiguation (WSD)
Definition: WSD is the process of determining which meaning of a word is being used in a
🔹given context, as many words have multiple meanings.
Purpose: It helps in correctly interpreting words with multiple meanings depending on
🔹their context.
Example:
● Input: "The bank was located by the river." (meaning a riverbank or a financial
institution?)
● Output: "bank" refers to a riverbank.
🔹
10. Text Generation
Definition: Text generation involves creating coherent and contextually relevant text based
on a prompt or previous text. This is commonly used in chatbots, content creation, and
🔹
🔹
automatic summarization.
Purpose: It is used to generate human-like text based on learned patterns and knowledge.
Example:
● Input: "Once upon a time..."
● Output: "There was a brave knight who embarked on a great adventure."
🔹
11. Information Retrieval
Definition: Information retrieval refers to the process of searching for relevant information
within large datasets or databases. It typically involves ranking documents based on their
🔹
🔹
relevance to a query.
Purpose: It helps in quickly retrieving useful information from a large corpus of text.
Example:
● Input: "Best pizza places in New York"
● Output: Relevant documents or web pages with the list of top pizza places.
🔹🔹
12. Speech Recognition
Definition: Speech recognition is the process of converting spoken language into text.
Purpose: It is used in applications like voice assistants (Siri, Alexa) and transcription
🔹
services.
Example:
● Input: "What's the weather like today?"
● Output: "What's the weather like today?" (converted into text).
2. Explain level knowledge used in NLP.
Ans: Natural Language Processing (NLP) involves various levels of knowledge to understand and
generate human language effectively. These levels range from the most basic, such as individual words
and sentence structures, to higher levels like context and meaning. Let’s explore the key levels of
knowledge used in NLP:
🔹
1. Lexical Knowledge (Word Level)
Definition: Lexical knowledge refers to the knowledge about words, their meanings, and
how they combine to form sentences. It includes information about word morphology, syntax,
🔹and semantics.
Components of Lexical Knowledge:
● Word Meanings: Understanding the definition or sense of words (e.g., “bank” could
mean a financial institution or the side of a river).
● Morphology: Understanding the structure of words and their inflections (e.g., "run" and
"running" are related).
● Word Relationships: Understanding relationships between words like synonyms,
🔹 antonyms, hypernyms, and hyponyms (e.g., "dog" is a hyponym of "animal").
Example:
● Word: "cat"
● Lexical knowledge would include understanding that "cat" is a noun, it refers to a type
of animal, and it has a synonym like "kitty."
🔹
2. Syntactic Knowledge (Sentence Level)
Definition: Syntactic knowledge deals with the rules and structures that govern how words
combine to form valid sentences. This involves the grammar of a language, focusing on word
🔹order, sentence structure, and syntax trees.
Components of Syntactic Knowledge:
● Word Order: The arrangement of words in a sentence according to grammatical rules
(e.g., subject-verb-object in English).
● Phrase Structure: How words group together to form phrases (e.g., noun phrases, verb
phrases).
● Sentence Parsing: Analyzing sentence structure using syntax trees or dependency trees
🔹 to determine grammatical relationships.
Example:
● Sentence: "The cat sat on the mat."
○ The subject ("The cat") and predicate ("sat on the mat") are connected
syntactically.
○ The phrase “on the mat” is a prepositional phrase providing additional context.
🔹
3. Semantic Knowledge (Meaning Level)
Definition: Semantic knowledge is concerned with the meaning of words, phrases, and
sentences. It involves interpreting the literal meaning and understanding the context in which
🔹the words are used.
Components of Semantic Knowledge:
● Word Sense Disambiguation (WSD): Determining which meaning of a word is being
used based on context (e.g., "bank" meaning a riverbank vs. a financial institution).
● Lexical Semantics: Understanding relationships between words in terms of their
meanings (e.g., synonyms, antonyms, hypernyms).
● Compositional Semantics: Understanding how word meanings combine in sentences
🔹 (e.g., "The dog chased the ball" vs. "The ball chased the dog").
Example:
● Sentence: "I went to the bank to fish."
○ The word "bank" here refers to the side of a river (disambiguated based on
context).
○ The meaning of the sentence involves understanding that the action is related to
fishing at a riverbank.
🔹
4. Pragmatic Knowledge (Context Level)
Definition: Pragmatic knowledge deals with understanding language in context, beyond
literal meaning. It involves recognizing implicatures, presuppositions, and the intentions
🔹behind a speaker’s words.
Components of Pragmatic Knowledge:
● Context: Understanding the situation, social setting, and intentions behind the utterance.
● Speech Acts: Recognizing the purpose of a sentence, whether it is a statement, question,
request, or command.
● Conversational Implicature: Understanding indirect meanings that arise in conversation
🔹 (e.g., "Can you pass the salt?" implies a request for the salt).
Example:
● Sentence: "Can you open the window?"
○ Pragmatically, this is not just a question about ability but a request for action.
○ It may imply that the speaker wants the window opened, and the context of the
conversation determines the appropriate response.
🔹
5. Discourse Knowledge (Extended Context)
Definition: Discourse knowledge is concerned with how multiple sentences in a text or
conversation relate to each other, forming coherent and consistent discourse. It helps in
understanding the flow of ideas and maintaining consistency across a conversation or
🔹document.
Components of Discourse Knowledge:
● Coherence: Ensuring that ideas in a text or conversation are logically connected.
● Coreference Resolution: Identifying when different words (e.g., pronouns) refer to the
same entity or object in the text.
● Topic Segmentation: Dividing a text into meaningful segments based on changes in topic
🔹 or theme.
Example:
● Text: "John went to the store. He bought some milk."
○ Discourse knowledge involves recognizing that "He" refers to John, ensuring
coherence in understanding the text.
🔹
6. World Knowledge (External Knowledge)
Definition: World knowledge is external, real-world knowledge that is used to enhance
understanding and resolve ambiguity in language. It includes factual information about the
world and common sense knowledge that helps NLP systems make sense of real-world
🔹situations.
Components of World Knowledge:
● Common Sense Knowledge: Knowledge about the world’s everyday scenarios, such as
understanding that "people need to eat to survive."
● Factual Knowledge: Facts about the world that help interpret language correctly (e.g.,
"The sun rises in the east").
● Cultural and Social Knowledge: Understanding the norms, customs, and social contexts
🔹 that influence language use.
Example:
● Sentence: "The man was cold and hungry, so he went to the restaurant."
○ World knowledge informs us that restaurants serve food, which addresses the
man’s hunger, and that coldness may prompt him to seek warmth.
Summary of the Levels of Knowledge in NLP
Level of Knowledge Focus Key Components
Lexical Knowledge Words, meanings, and relationships between Word meanings, morphology, synonyms,
them antonyms
Syntactic Knowledge Sentence structure and grammatical Word order, sentence parsing, syntax trees
relationships
Semantic Knowledge Literal meaning of words, phrases, and Word sense disambiguation, lexical
sentences semantics
Pragmatic Knowledge Understanding language in context Speech acts, conversational implicature,
intentions
Discourse Knowledge Coherence and flow between multiple Coreference resolution, topic segmentation
sentences
World Knowledge Real-world knowledge used to understand Common sense, factual knowledge, cultural
language accurately understanding
3. Explain application of NLP.
Ans: Natural Language Processing (NLP) has a wide range of applications in various fields, from
enhancing communication between humans and machines to improving decision-making processes.
Here are some prominent applications of NLP:
🔹
1. Machine Translation (MT)
Definition: Machine Translation (MT) is the automatic translation of text from one language
🔹to another using NLP techniques.
Applications:
● Google Translate: Converts text between hundreds of languages, allowing users to
communicate across language barriers.
● Real-Time Translation: Some platforms use NLP to translate spoken language in
real-time, such as during international video calls.
● Localization: Adapting products, websites, or content to different languages and
🔹 cultures.
Example:
● Input: "Hola, ¿cómo estás?" (Spanish)
● Output: "Hello, how are you?" (English)
🔹
2. Sentiment Analysis
Definition: Sentiment analysis is the process of detecting subjective information from text,
🔹such as opinions, emotions, or attitudes, and classifying it as positive, negative, or neutral.
Applications:
● Social Media Monitoring: Companies track public sentiment regarding products,
services, or events (e.g., analyzing tweets or reviews).
● Brand Monitoring: Detecting the sentiment behind customer feedback to improve
marketing strategies.
🔹 ● Political Analysis: Analyzing public sentiment towards political figures or policies.
Example:
● Input: "I love the new iPhone! It's amazing."
● Output: Positive sentiment.
🔹
3. Chatbots and Virtual Assistants
Definition: Chatbots and virtual assistants use NLP to interact with users in natural
🔹language, answering queries, providing assistance, and performing tasks.
Applications:
● Customer Service: Many businesses deploy chatbots on their websites to answer FAQs
and provide assistance 24/7.
● Voice Assistants: Assistants like Siri, Google Assistant, and Alexa use NLP to
understand and respond to voice commands.
● Personal Assistants: Tools like Cortana and Google Assistant help with tasks like
🔹 scheduling, reminders, and providing information.
Example:
● Input: "What's the weather like today?"
● Output: "The weather is sunny with a high of 75°F."
🔹
4. Information Retrieval and Search Engines
Definition: NLP is used to improve search engines' ability to understand and retrieve the
🔹most relevant documents based on user queries.
Applications:
● Search Engines: Google, Bing, and other search engines use NLP to improve the
relevance of search results based on user intent.
● Document Classification: Automatically classifying and indexing documents based on
their content to make information retrieval more efficient.
● Question Answering Systems: Providing direct answers to user queries based on large
🔹 datasets (e.g., Google’s featured snippets).
Example:
● Input: "Best places to visit in Paris"
● Output: A list of popular tourist spots, including the Eiffel Tower and Louvre Museum.
🔹
5. Text Summarization
Definition: Text summarization is the process of generating a concise and coherent summary
🔹of a long text while preserving its key information.
Applications:
● Automatic News Summarization: Providing quick summaries of news articles or reports
to give users the gist of the story.
● Legal Document Summarization: Reducing lengthy legal texts into easily
understandable summaries, saving time for lawyers and clients.
🔹 ● Medical Summaries: Summarizing patient records or medical research articles.
Example:
● Input: A long medical research paper about cancer treatment.
● Output: A summary highlighting the key findings and conclusions of the research.
🔹
6. Named Entity Recognition (NER)
Definition: Named Entity Recognition (NER) is the process of identifying and classifying
🔹entities (e.g., names, dates, locations, organizations) in text.
Applications:
● Information Extraction: Automatically extracting structured data from unstructured text
(e.g., news articles or financial reports).
● Business Intelligence: Identifying key entities like company names, products, or people
in business documents.
● Search Enhancement: Improving search results by recognizing and tagging important
🔹 entities.
Example:
● Input: "Apple Inc. was founded by Steve Jobs in Cupertino in 1976."
● Output: [("Apple Inc.", ORGANIZATION), ("Steve Jobs", PERSON), ("Cupertino",
LOCATION), ("1976", DATE)]
🔹
7. Speech Recognition
Definition: Speech recognition converts spoken language into text, allowing users to interact
🔹with devices via voice commands.
Applications:
● Voice Assistants: Virtual assistants like Siri, Alexa, and Google Assistant rely on speech
recognition to perform tasks like setting alarms or controlling smart devices.
● Transcription Services: Automatically transcribing audio recordings into written text for
meetings, lectures, or podcasts.
● Voice-controlled Applications: In cars, smart homes, or phones, where users can perform
🔹 actions with voice commands.
Example:
● Input: Spoken sentence "Call John at 5 PM."
● Output: Text command for the system to make the call.
🔹
8. Text Classification
Definition: Text classification involves categorizing text into predefined categories based on
🔹
its content.
Applications:
● Email Filtering: Automatically classifying emails into spam and non-spam categories.
● Topic Categorization: Classifying articles, blog posts, or papers into topics such as
sports, politics, technology, etc.
● Content Moderation: Identifying inappropriate content in forums, social media posts, or
🔹 reviews.
Example:
● Input: A news article about climate change.
● Output: Category “Environment.”
🔹
9. Coreference Resolution
Definition: Coreference resolution is the process of identifying when different expressions
🔹
(like pronouns) refer to the same entity.
Applications:
● Text Understanding: Helps systems maintain consistency by resolving pronouns and
noun phrases that refer to the same object or person in a document.
● Chatbots and Assistants: Improving the understanding of conversations by maintaining
🔹 context between different turns in dialogue.
Example:
● Input: "John went to the store. He bought milk."
● Output: "He" refers to "John."
🔹
10. Question Answering Systems
Definition: Question Answering (QA) systems use NLP to provide direct answers to
🔹
questions posed by users.
Applications:
● Customer Support: Answering customer queries automatically based on a knowledge
base.
● Virtual Assistants: Google Assistant, Siri, and Alexa all use QA techniques to answer
questions from users.
● Healthcare Systems: Providing answers to medical questions based on patient records or
🔹 medical literature.
Example:
● Input: "What is the capital of France?"
● Output: "The capital of France is Paris."
🔹
11. Document Clustering
Definition: Document clustering involves grouping similar documents together based on
🔹
their content, making it easier to analyze large datasets.
Applications:
● Content Recommendation: Grouping similar content together (e.g., movies, articles, or
products) to suggest relevant items to users.
● News Categorization: Automatically grouping news articles into topics or themes (e.g.,
🔹 politics, sports, entertainment).
Example:
● Input: Multiple news articles.
● Output: Groups of articles about sports, politics, health, etc.
4. Explain the role of Robotics in AI with examples.
Ans: Robotics is a field that involves the design, construction, operation, and use of robots. When
combined with Artificial Intelligence (AI), robotics becomes more advanced and capable of performing
complex tasks autonomously. AI enhances robots' ability to make decisions, learn from their
environment, and improve performance over time. Here's an exploration of how AI is integrated into
robotics and its impact on the field:
🔹
1. Autonomous Navigation and Path Planning
Role in Robotics:
AI algorithms, particularly machine learning and computer vision, enable robots to navigate
through complex environments autonomously. This involves detecting obstacles, finding paths,
🔹and adjusting movements in real-time based on environmental changes.
Example:
● Self-driving Cars: A prominent example of AI-driven robotics. Self-driving cars, such as
those developed by Tesla and Waymo, use AI-powered sensors (like cameras, radar, and
LiDAR) to recognize objects, map the environment, and make navigation decisions
without human input.
● Delivery Robots: Companies like Starship Technologies use autonomous delivery robots
that navigate sidewalks and streets to deliver food and packages, avoiding obstacles and
pedestrians in real-time.
🔹
2. Machine Learning and Adaptability
Role in Robotics:
AI enables robots to learn from experience and improve their performance over time.
Reinforcement learning allows robots to interact with their environment, receive feedback, and
🔹adjust their behavior to maximize efficiency and effectiveness.
Example:
● Industrial Robots: In manufacturing, robots like Fanuc’s robotic arms use AI to adapt to
different tasks and optimize production processes. These robots improve through trial
and error, adjusting their movements and actions based on the performance feedback.
● Robotic Prosthetics: AI-driven prosthetic limbs, such as those from Ottobock, use
machine learning to learn a user's movement patterns and provide more natural and
responsive motion.
🔹
3. Object Recognition and Manipulation
Role in Robotics:
AI allows robots to identify and manipulate objects in their environment, which is essential for
performing tasks like picking up items, sorting, or assembling parts. Computer vision,
combined with deep learning, enables robots to recognize shapes, sizes, textures, and other
🔹object characteristics.
Example:
● Amazon Robotics: In Amazon warehouses, robots like Kiva use AI to navigate the
warehouse and pick up products. AI-powered vision systems identify items on shelves,
allowing robots to pick and deliver products with precision.
● Robotic Surgery: AI-powered robotic surgical systems, such as the da Vinci Surgical
System, use object recognition to perform complex surgeries with high precision and
minimal invasiveness. They recognize human anatomy and perform delicate tasks based
on real-time data.
🔹
4. Human-Robot Interaction (HRI)
Role in Robotics:
AI enables robots to communicate and collaborate effectively with humans. This involves
understanding natural language, gestures, facial expressions, and emotions. Natural language
processing (NLP) and emotion recognition help robots understand human intentions and
🔹respond appropriately.
Example:
● Personal Assistants: Robots like Pepper, developed by SoftBank Robotics, are designed
to interact with humans using AI-driven speech recognition, facial expression analysis,
and contextual understanding. These robots are used in customer service, healthcare,
and entertainment.
● Robot Companions: AI-powered robots such as Buddy or Jibo are designed to interact
with users, understand their commands, and provide emotional support or assist with
daily tasks in a social setting.
🔹
5. Multi-Robot Systems
Role in Robotics:
AI enables multiple robots to collaborate and communicate with each other to achieve common
goals. Swarm robotics involves a group of robots that work together autonomously, often
inspired by natural systems like ant colonies or bee hives.
🔹 Example:
● Agricultural Robots: Robots used in agriculture, such as RoboBees or agricultural
drones, can operate together to plant seeds, water crops, or monitor fields. AI allows
them to work in coordination, maximizing efficiency and reducing the need for human
labor.
● Search and Rescue Robots: In emergency scenarios, robots like the Squad robot
developed by NASA can be deployed to perform search and rescue operations. AI
enables these robots to communicate with each other, plan paths together, and share
environmental data to locate survivors.
🔹
6. AI in Robot Perception and Sensory Systems
Role in Robotics:
AI is essential for processing sensory data collected by robots, such as images, sounds, or tactile
feedback. Computer vision, speech recognition, and touch sensing allow robots to perceive and
🔹understand the world around them in a human-like manner.
Example:
● Robotic Vacuum Cleaners: AI-powered robots like Roomba use sensors and computer
vision to map out a room, detect dirt, and clean effectively. They adapt their cleaning
paths to ensure complete coverage and avoid obstacles.
● AI in Agricultural Robots: AI-powered robots like Naio Technologies’ agricultural robots
use cameras, sensors, and computer vision to detect weeds, distinguish between crops
and pests, and autonomously manage farming tasks.
🔹
7. Autonomous Decision-Making
Role in Robotics:
AI enables robots to make autonomous decisions based on data from their environment. By
using AI-driven algorithms, robots can analyze their surroundings, predict potential outcomes,
🔹and choose the best course of action.
Example:
● Warehouse Robots: In fulfillment centers like Amazon, robots such as Kiva robots decide
on their own how to navigate the warehouse, select items, and deliver them to human
workers or other systems for packing.
● Autonomous Drones: DJI drones and other delivery drones equipped with AI can make
decisions regarding navigation, obstacle avoidance, and package delivery, enabling them
to fly autonomously and perform tasks without human intervention.
🔹
8. Ethics and Safety in Robotics
Role in Robotics:
AI plays a crucial role in ensuring robots operate ethically and safely around humans. This
involves programming robots with moral decision-making capabilities, ensuring they follow
🔹ethical guidelines, and ensuring their safety in dynamic environments.
Example:
● AI-powered Social Robots: Robots like Sophia, developed by Hanson Robotics, are
designed to interact with humans and exhibit human-like behaviors. AI ensures that
these robots adhere to ethical standards when engaging with people and making
decisions.
● Robots in Hazardous Environments: Robots used in dangerous jobs, such as bomb
disposal robots or robots used in nuclear facilities, must be able to make safe decisions
and avoid harming humans.
AI Assignment 1
1. Explain Turing test designed for satisfactory operational definition of AI.
Ans: Turing Test: An Operational Definition of AI
The Turing Test, proposed by Alan Turing in 1950 in his paper "Computing Machinery and
Intelligence," is a fundamental method to assess whether a machine exhibits human-like
intelligence. It provides an operational definition of AI by evaluating whether a machine can
mimic human responses convincingly.
1. Concept of the Turing Test
The test is based on a simple imitation game, where:
● A human judge interacts with a human and a machine via text-based communication (to
eliminate voice and appearance biases).
● If the judge cannot reliably distinguish between the human and the machine based on
their responses, the machine is said to have passed the Turing Test.
2. Key Elements of the Turing Test
1. Interrogator (Judge): A human who asks questions.
2. Human Participant: Provides human-like responses.
3. AI (Machine): Tries to generate responses indistinguishable from a human.
4. Communication Medium: Typically text-based to avoid speech recognition biases.
3. Purpose of the Turing Test
● Provides a behavioral benchmark for AI.
● Defines AI as a system capable of intelligent conversation.
● Emphasizes human-like interaction rather than the underlying mechanism of
intelligence.
4. Criticism of the Turing Test
● Focuses only on deception: A machine could pass by tricking the judge without being
truly intelligent.
● Limited scope: Intelligence involves learning, reasoning, perception, and action, not just
conversation.
● Chinese Room Argument (John Searle): Suggests that a machine can manipulate
symbols (syntax) without understanding meaning (semantics).
5. Modern AI and the Turing Test
● AI chatbots like ELIZA, PARRY, and ChatGPT can sometimes pass the test for short
conversations.
● The Loebner Prize is an annual competition where AI programs attempt to pass the
Turing Test.
● However, AI research today goes beyond the Turing Test, focusing on general
intelligence, learning, and reasoning.
2. Explain different definitions of AI according to different categories.
Ans: Different Definitions of AI Based on Categories
Artificial Intelligence (AI) has been defined in various ways, depending on the perspective or
goal of AI research. These definitions can be classified into four broad categories, as proposed
by Stuart Russell and Peter Norvig in Artificial Intelligence: A Modern Approach.
1. Thinking Humanly (Cognitive Modeling Approach)
● AI is defined as machines that think like humans, replicating human cognitive processes
such as reasoning, learning, and decision-making.
● Example Definition:
"AI is the science of making machines do things that would require intelligence if done
by humans." — Marvin Minsky
● Applications:
○ Cognitive architectures (SOAR, ACT-R)
○ Neural networks that stimulate brain activity
○ AI-based psychology research
Limitation:
● Understanding human cognition is complex, and AI may work differently from
biological brains.
2. Thinking Rationally (Logic-Based Approach)
● AI is defined as machines that follow logical reasoning and mathematical models to
derive conclusions.
● Example Definition:
"AI is the study of computations that make it possible to perceive, reason, and act." —
Winston
● Applications:
○ Expert systems (e.g., MYCIN for medical diagnosis)
○ Logical reasoning (Prolog, theorem proving)
○ Automated planning and decision-making
Limitation:
● Human reasoning is often not purely logical; it involves heuristics and emotions.
● Logical systems struggle with uncertainty and incomplete data.
3. Acting Humanly (Turing Test Approach)
● AI is defined as a system that behaves like a human, regardless of how it works
internally.
● Example Definition:
"AI is the ability of machines to perform tasks that, if done by humans, would require
intelligence."
● Applications:
○ Chatbots (e.g., Siri, ChatGPT, Google Assistant)
○ Turing Test-based AI competitions (Loebner Prize)
○ AI in customer service and human interaction
Limitation:
● Passing the Turing Test does not guarantee real intelligence—just an illusion of
intelligence.
4. Acting Rationally (Intelligent Agent Approach)
● AI is defined as an autonomous agent that takes optimal actions to achieve its goals in
any environment.
● Example Definition:
"AI is concerned with designing intelligent agents that take the best possible action in
any given situation." — Russell & Norvig
● Applications:
○ Reinforcement learning (e.g., AlphaGo, DeepMind)
○ Robotics and autonomous systems (self-driving cars, drones)
○ AI-driven decision-making (finance, healthcare, recommendation systems)
Advantage:
● This is the most practical and widely accepted definition today, as it focuses on
problem-solving and goal achievement rather than mimicking human cognition.
3. Define Rationality and rational agent. Give an example of rational action performed by any
intelligent agent. ####
Ans: Definition of Rationality and Rational Agent
1. What is Rationality?
Rationality refers to the ability to make decisions that maximize performance based on available
information, knowledge, and expected outcomes. A rational system follows logical reasoning,
makes optimal choices, and adapts to different environments effectively.
A rational action is one that achieves the best possible outcome given the agent’s goals and
perceptual inputs.
2. What is a Rational Agent?
A rational agent is an entity (machine, program, or robot) that acts optimally to achieve its goals
by:
● Perceiving its environment using sensors.
● Taking actions using actuators.
● Maximizing performance based on its knowledge and goals.
● Adapting to dynamic situations.
Example Definition:
"An agent is rational if it selects actions that maximize its expected performance measure, given its
perceptual history and knowledge of the environment." — Russell & Norvig
3. Example of Rational Action by an Intelligent Agent
🔹 Example: Self-Driving Car (Autonomous Vehicle)
● Agent: AI-powered self-driving car (e.g., Tesla Autopilot).
● Perception: Uses sensors (cameras, LiDAR) to detect traffic, pedestrians, and road
conditions.
● Rational Action:
○ Stops at a red traffic light to avoid accidents.
○ Adjusts speed based on nearby vehicles.
💡 ○ Takes a detour when GPS detects a traffic jam to minimize travel time.
Why is this action rational?
● The AI agent chooses an action that maximizes safety and efficiency while adhering to
traffic laws.
4. Describe different types of environments application to AI agents.
Ans: Types of Environments Applicable to AI Agents
An AI agent operates in an environment, which defines the conditions under which it perceives,
makes decisions, and takes actions. The nature of the environment impacts how an agent
functions and determines the complexity of AI solutions required.
AI environments can be classified based on different properties:
1. Fully Observable vs. Partially Observable
● Fully Observable: The agent has complete information about the environment at all
times.
○ Example: Chess (all pieces are visible on the board).
● Partially Observable: The agent has limited or incomplete information and must make
decisions under uncertainty.
🔹 ○ Example: Self-driving cars (cannot see behind obstacles).
Application: Robotics, autonomous systems, game AI.
2. Deterministic vs. Stochastic
● Deterministic: The next state of the environment is completely predictable from the
current state and action taken.
○ Example: Tic-Tac-Toe (the game state follows fixed rules).
● Stochastic: There is uncertainty in outcomes due to randomness or unknown factors.
🔹 ○ Example: Poker (depends on probability and opponents' actions).
Application: Financial AI (stock market prediction), robotics in dynamic environments.
3. Static vs. Dynamic
● Static: The environment does not change while the agent is making a decision.
○ Example: Crossword puzzles.
● Dynamic: The environment keeps changing, requiring real-time adaptation.
🔹 ○ Example: Self-driving cars (traffic conditions change constantly).
Application: Autonomous vehicles, real-time strategy games, robotics.
4. Discrete vs. Continuous
● Discrete: The agent makes decisions in finite steps or predefined states.
○ Example: Chess (finite number of moves).
● Continuous: The agent operates in a continuous space with infinite possibilities.
🔹 ○ Example: Drone navigation (movement is fluid).
Application: Robotics, control systems, AI in physics simulations.
5. Single-Agent vs. Multi-Agent
● Single-Agent: Only one AI agent operates in the environment.
○ Example: A chess-playing bot against a human.
● Multi-Agent: Multiple AI agents interact and may cooperate or compete.
○ Example: Autonomous traffic systems where multiple self-driving cars
🔹 coordinate.
Application: Multi-agent systems in gaming, autonomous drones, and trading algorithms.
6. Episodic vs. Sequential
● Episodic: Actions are independent and do not affect future actions.
○ Example: Image classification (each image is classified separately).
● Sequential: Past actions influence future decisions.
🔹 ○ Example: Chess (each move affects future possibilities).
Application: Decision-making AI, reinforcement learning, robotics.
7. Known vs. Unknown
● Known: The agent has a predefined model of the environment.
○ Example: Solving a Sudoku puzzle (fixed rules).
● Unknown: The agent must learn the environment through exploration.
🔹 ○ Example: Reinforcement Learning in a new game.
Application: AI learning systems, autonomous exploration.
5. Give PEAS description for a robot soccer player. Characterize its environment.
Ans: PEAS Description for a Robot Soccer Player
The PEAS (Performance Measure, Environment, Actuators, Sensors) framework is used to
define an AI agent’s functionality in a structured way. Here’s how it applies to a robot soccer
player:
1. PEAS Description
Component Description for Robot Soccer Player
Performance - Scoring goals, preventing opponent goals.
Measure - Passing accuracy, ball control, and positioning.
- Energy efficiency and teamwork.
Environment - Soccer field with goalposts, boundaries, and obstacles.
- Teammates and opponents (multi-agent system).
- Dynamic environment (changing ball and player positions).
Actuators - Motors to move wheels/legs. - Kicking mechanism to strike the ball.
- Arms (if humanoid) for balance and motion.
Sensors - Cameras for vision (detecting ball, goal, teammates, and opponents).
- GPS/Inertial sensors for positioning and movement tracking.
-Proximity sensors to avoid collisions. - Microphones for sound-based commands (if applicable).
2. Characterization of the Environment
Property Type for Robot Soccer Player
Fully/Partially Observable Partially Observable (limited field of view, occlusions by players).
Deterministic/ Stochastic Stochastic (opponent strategies and ball movement introduce randomness).
Static/ Dynamic Dynamic (players, ball, and strategies change continuously).
Discrete/ Continuous Continuous (player movement and ball motion are fluid).
Single-Agent/ Multi-Agent Multi-Agent (multiple robots collaborate and compete).
Episodic/ Sequential Sequential (past actions affect future gameplay).
Known/ Unknown Partially Known (field is known, but opponents’ actions are unpredictable).
6. What is the PEAS descriptor? Give PEAS descriptors for part-parking robots.
Ans: The PEAS (Performance Measure, Environment, Actuators, Sensors) descriptor is a framework
used to define the key components of an AI agent. It helps in designing intelligent agents by specifying:
1. Performance Measure (P) – Criteria for evaluating the agent’s success.
2. Environment (E) – The surroundings in which the agent operates.
3. Actuators (A) – The mechanisms through which the agent interacts with the environment.
4. Sensors (S) – Devices that collect information from the environment.
PEAS Descriptors for a Parking Robot
Component Description for a Parking Robot
Performance - Successfully parking the car in the designated spot. - Avoiding obstacles and collisions. -
Measure (P) Minimizing parking time and maximizing accuracy.
Environment (E) - Parking lot (open or multi-story). - Static obstacles (walls, curbs) and dynamic obstacles
(pedestrians, other vehicles). - Parking lines, road signs, and markings.
Actuators (A) - Steering mechanism to turn the wheels. - Accelerator and brake system for speed control. -
Gear system for forward and reverse movement.
Sensors (S) - Cameras for detecting parking spaces, lane markings, and obstacles. - Ultrasonic/radar
sensors for distance measurement. - GPS for location tracking. - LIDAR for 3D mapping of
surroundings.
7. Explain model based reflex agent with block diagram.
Ans:A Model-Based Reflex Agent is an intelligent agent that maintains an internal model of the
environment to make decisions. Unlike simple reflex agents, which rely only on current perceptions,
model-based agents remember past states and infer missing information to handle partially observable
environments effectively.
✅✅
1. Characteristics of a Model-Based Reflex Agent
Uses a model of the world to track state changes.
✅
✅
Can handle partially observable environments by maintaining a belief about the state.
Uses condition-action rules to select the best action.
More powerful than simple reflex agents but still lacks long-term planning.
2. Block Diagram of a Model-Based Reflex Agent
Below is the block diagram representation of a Model-Based Reflex Agent:
+--------------------------------------+
|Perceptual History (Sensors)|
+------------------+------------------+
|
v
+----------------------------------------------+
| Internal Model (Maintains State) |
+-----------------------------------------------+
|
v
+-------------------------------------+
| Condition-Action Rules |
+-------------------------------------+
|
v
+--------------------------------------+
| Actuators (Perform Action) |
+--------------------------------------+
3. Working of Model-Based Reflex Agent
1️⃣ Perception: The agent receives sensory input from the environment.
2️⃣ Internal Model: It updates its internal state to track the environment.
3️⃣ Condition-Action Rules: The agent applies pre-defined rules to choose an action.
4️⃣ Action Execution: The agent performs the action using actuators.
5️⃣ Feedback Loop: The agent continuously updates its state based on new perceptions.
🔹
4. Example of a Model-Based Reflex Agent
Example: Self-Driving Car
● Sensors: Cameras, LiDAR, GPS, and radar detect surroundings.
● Internal Model: Tracks road conditions, vehicle position, and obstacles.
● Condition-Action Rules:
○ If an obstacle is detected, slow down.
○ If the traffic light is red, stop.
○ If another car is merging, adjust speed.
💡 ● Actuators: Steering, acceleration, braking system.
Why Model-Based?
The car remembers past sensor readings to track moving objects and make better driving
decisions in partially observable environments.
✅✔️
5. Advantages and Limitations
Advantages:
✔️ Works well in complex and dynamic environments.
❌✔️
Can predict unseen conditions using an internal model.
More powerful than simple reflex agents.
❌
❌
Limitations:
Cannot handle long-term planning (needs goal-based or learning agents).
Requires a well-defined model of the environment.
8. Explain a utility-based agent with the help of a neat diagram.
Ans: Utility-Based Agent
A Utility-Based Agent is an intelligent agent that chooses actions based on a utility function,
which measures the desirability of different states. The agent doesn't simply aim to achieve a
goal, but rather aims to maximize the overall satisfaction or utility of its actions, considering
multiple factors and trade-offs. This type of agent is more advanced than goal-based agents
because it provides quantitative values to evaluate different possible actions and their
outcomes.
✅✅
1. Characteristics of a Utility-Based Agent
Uses a utility function to evaluate the desirability of different states.
✅
✅
Can handle multiple conflicting goals by comparing their utilities.
More flexible than goal-based agents as it considers trade-offs between goals.
Makes decisions based on maximizing overall satisfaction (not just achieving a single goal).
2. Block Diagram of a Utility-Based Agent
Below is the block diagram of a Utility-Based Agent:
+--------------------------------------+
|Perceptual History (Sensors)|
+------------------+------------------+
|
v
+---------------------------------------------+
| Internal Model (Current State) |
+---------------------------------------------+
|
v
+--------------------------------------------------+
| Utility Function (Evaluates Actions) |
+--------------------------------------------------+
|
v
+------------------------------------------------+
| Action Selection (Decision Making) |
+------------------------------------------------+
|
v
+--------------------------------------+
| Actuators (Perform Action) |
+--------------------------------------+
3. Components of a Utility-Based Agent
● Perceptual History (Sensors): The agent receives sensory inputs that represent the
current state of the environment.
● Internal Model (State Representation): The agent maintains an internal model to keep
track of the environment and its own state.
● Utility Function: The agent evaluates the desirability of potential actions or states using
the utility function. This function assigns a numeric value to each possible state,
reflecting how "good" or "bad" that state is.
● Action Selection (Decision Making): Based on the utility values, the agent selects the
action that maximizes its overall utility.
● Actuators: The actuators carry out the selected action in the environment.
4. Working of a Utility-Based Agent
1️⃣ Perception: The agent senses the environment (via sensors) and updates its internal model
with current information.
2️⃣ Utility Calculation: The utility function assigns a numeric utility value to each potential state
the agent could move into, considering its goals and preferences.
3️⃣ Decision Making: The agent compares the utility values and selects the action that maximizes
utility.
4️⃣ Action Execution: The agent performs the selected action using actuators (e.g., moving,
speaking, etc.).
5️⃣ Feedback Loop: After performing the action, the agent receives new percepts from the
environment and adjusts its behavior accordingly.
🔹
5. Example of a Utility-Based Agent
Example: Self-Driving Car
The self-driving car is not just trying to reach its destination (as a goal-based agent would), but
also aims to maximize safety, efficiency, and comfort.
● Sensors: Cameras, LiDAR, GPS, radar, etc., provide information about the environment
(road conditions, traffic, pedestrians).
● Internal Model: The car keeps track of its current location, speed, obstacles, and
potential hazards.
● Utility Function:
○ +10 Utility for maintaining a safe distance from other vehicles.
○ +5 Utility for driving in the fastest lane.
○ -20 Utility for speeding.
○ -30 Utility for braking harshly.
● Decision Making: The car selects actions (e.g., changing lanes, braking) that maximize its
overall utility considering safety and efficiency.
💡 ● Actuators: The car's steering, brakes, and accelerator perform the selected action.
Why Utility-Based?
A goal-based agent would focus solely on reaching the destination, but the utility-based agent
will optimize the overall driving experience by balancing speed, safety, and comfort.
✅✔️
6. Advantages and Limitations
Advantages:
✔️ Handles multiple conflicting goals effectively by balancing priorities.
❌✔️
Provides a flexible and adaptive approach to decision-making.
Can make more nuanced decisions than goal-based agents.
❌
❌
Limitations:
Requires a well-designed utility function, which can be challenging to define.
❌ Can be computationally expensive to evaluate all possible actions.
May not always perfectly model the environment, leading to suboptimal decisions.
9. Explain a learning-based agent with the help of a neat diagram.
Ans: Learning-Based Agent
A Learning-Based Agent is an intelligent agent that improves its performance over time by
learning from past experiences and adapting to its environment. Unlike reflex or utility-based
agents, learning-based agents continuously refine their decision-making process using feedback
mechanisms.
✅✅
1. Characteristics of a Learning-Based Agent
Uses experience to improve decision-making.
✅
✅
Can work in unknown or dynamic environments.
Uses a learning element to adapt over time.
Incorporates techniques like machine learning and reinforcement learning.
2. Block Diagram of a Learning-Based Agent
+--------------------------------------------+
| Perceptual History (Sensors) |
+------------------+------------------------+
|
v
+--------------------------------------------------+
| Learning Element (Improves Model)|
+--------------------------------------------------+
|
v
+---------------------------------------------------------+
| Performance Element (Decision Making) |
+--------------------------------------------------------+
|
v
+-------------------------------------------+
| Critic (Evaluates Performance) |
+-------------------------------------------+
|
v
+-------------------------------------+
| Feedback (Adjusts Model) |
+-------------------------------------+
|
v
+--------------------------------------+
| Actuators (Perform Action) |
+--------------------------------------+
3. Components of a Learning-Based Agent
1️⃣ Learning Element: Improves the agent’s model based on new experiences.
2️⃣ Performance Element: Executes decisions using current knowledge.
3️⃣ Critic: Evaluates the agent’s actions and provides feedback.
4️⃣ Feedback Mechanism: Adjusts the model to enhance future performance.
🔹🔹
4. Working of a Learning-Based Agent
Step 1: Perception – The agent observes the environment through sensors.
🔹
🔹🔹
Step 2: Decision Making – The performance element selects an action.
Step 3: Execution – The agent performs the action using actuators.
Step 4: Feedback Collection – The critic evaluates performance.
Step 5: Learning & Adaptation – The learning element updates the agent’s model for future
decisions.
🔹
5. Example of a Learning-Based Agent
Example: AI Chess Player
● Perception: Tracks board positions.
● Performance Element: Selects the best move based on current knowledge.
● Critic: Evaluates whether the move was good or bad.
● Learning Element: Updates strategy based on game results.
💡 ● Feedback Loop: Learns from wins/losses to improve future moves.
Why Learning-Based?
Unlike a fixed-rule chess bot, a learning-based agent improves over time by recognizing
patterns and adjusting strategies.
✅✔️
6. Advantages and Limitations
Advantages:
✔️ Works well in dynamic and unknown environments.
❌✔️
Can self-improve without human intervention.
Useful for complex AI applications like self-driving cars and robotics.
❌
❌
Limitations:
Requires a lot of data to learn effectively.
❌ Can be computationally expensive.
May take time to adapt to new situations.
Or
Explain the structure learning agent architecture. What is the role of a critic in learning? Or
What are the basic building blocks of learning agents? Explain each of them with a neat diagram
10. Explain how you will formulate a search problem.
Ans: A search problem in AI refers to the process of exploring possible states or configurations in order
to reach a desired goal. The formulation of a search problem involves defining the problem in terms of
its initial state, actions, transition model, goal state, and path cost. Here’s a step-by-step breakdown of
how to formulate a search problem:
1. Define the Initial State (S₀)
The initial state represents the starting point of the agent’s journey in the environment. It
contains all the information required to begin solving the problem.
● Example: In a maze-solving problem, the initial state is the starting position of the agent
in the maze.
2. Define the State Space
The state space is the set of all possible configurations or states the agent can reach, starting
from the initial state and applying actions.
● Example: In the case of the maze, the state space consists of all possible positions in the
maze the agent can move to.
3. Define Actions (Operators)
The actions are the possible moves or operations that can be applied in each state. They
transform the current state into a new state.
● Example: In the maze, the actions might include moving up, down, left, or right from the
current position.
4. Define the Transition Model (T)
The transition model describes how the state changes after an action is applied. This is usually
expressed as a function:
T(s,a)→s′T(s, a) \rightarrow s'
Where:
● ss is the current state,
● aa is the action, and
● s′s' is the resulting state after action aa is applied to state ss.
● Example: If the agent is at a given position in the maze and moves up, the transition
model describes the new position after the move.
5. Define the Goal State (G)
The goal state is the state that the agent is trying to reach. It could be a specific configuration,
such as reaching a particular position or achieving some objective.
● Example: In the maze problem, the goal state might be the exit position or the
destination.
6. Define the Path Cost (C)
The path cost is a function that assigns a numerical value to the path from the initial state to the
goal state. This helps in evaluating different solutions based on the cost of reaching the goal.
● Example: In a maze, the path cost might be the number of steps the agent takes or a
weighted cost based on difficulty (e.g., moving through harder terrain).
7. Define the Solution (or Goal Test)
The goal test checks whether the agent has reached a state that satisfies the conditions for the
problem’s success.
● Example: In the maze, the goal test would check whether the agent has reached the exit
position.
8. Example of Search Problem Formulation
Problem: Find the shortest path in a maze.
● Initial State (S₀): The agent’s initial position in the maze (e.g., coordinates (x₀, y₀)).
● State Space: All possible positions in the maze.
● Actions (Operators): Move up, down, left, or right.
● Transition Model: Each action results in the agent moving to an adjacent square (e.g., moving up
from position (x₀, y₀) to (x₀, y₀+1)).
● Goal State (G): Reaching the exit position of the maze.
● Path Cost (C): The number of steps taken to reach the goal (or the sum of any weighted costs per
move).
11. Explain steps in problem formulation with examples.
Ans: Problem formulation is the process of defining a problem in terms that an intelligent agent can
understand and solve. It involves structuring the problem in a way that can be tackled using
appropriate algorithms. The steps in problem formulation help break down a complex problem into
manageable components, making it easier to apply AI search techniques. Here are the steps involved in
problem formulation, with examples:
1. Define the Initial State
● The initial state represents the starting point of the agent. It contains all the information
the agent needs to begin solving the problem.
● Example:
○ Problem: Solving a maze.
○ Initial State: The position of the agent at the entrance of the maze, such as
coordinates (0, 0).
2. Define the State Space
● The state space is the set of all possible states that the agent can encounter in the
environment. It includes every configuration the system could potentially be in during
the problem-solving process.
● Example:
○ Problem: Solving a maze.
○ State Space: All possible positions within the maze that the agent can occupy,
represented by a grid of coordinates (x, y).
3. Define the Actions (Operators)
● Actions are the operations that the agent can take to transition from one state to another.
These actions are defined for each possible state.
● Example:
○ Problem: Solving a maze.
○ Actions: Moving up, down, left, or right. Each action corresponds to a movement
between adjacent cells in the maze.
4. Define the Transition Model (T)
● The transition model defines the result of applying an action in a given state. It specifies
how each action leads from one state to another, often represented as a function:
T(s,a)→s′T(s, a) \rightarrow s'
Where:
○ ss is the current state,
○ aa is the action, and
○ s′s' is the resulting state.
● Example:
○ Problem: Solving a maze.
○ Transition Model: If the agent is at position (0, 0) and moves right, it transitions
to position (0, 1). If the agent moves up from position (0, 0), it transitions to (1, 0).
5. Define the Goal State
● The goal state is the state or configuration that the agent is trying to achieve. This is
typically the objective the agent is working towards.
● Example:
○ Problem: Solving a maze.
○ Goal State: The exit of the maze, represented by a specific position in the grid
(e.g., (x_goal, y_goal)).
6. Define the Path Cost (C)
● Path cost refers to the cost associated with the actions the agent takes to reach the goal.
In some problems, each action may have a different cost (e.g., moving across different
terrain types), while in others, all actions may have equal cost (e.g., each move is one
step).
● Example:
○ Problem: Solving a maze.
○ Path Cost: The number of steps taken by the agent to reach the goal (or weighted
costs if some paths are more difficult to traverse).
7. Define the Solution (Goal Test)
● The goal test is a mechanism that checks whether the current state satisfies the goal
conditions. If the agent is in a goal state, the problem is considered solved.
● Example:
○ Problem: Solving a maze.
○ Goal Test: The agent is in the position corresponding to the exit of the maze (e.g.,
if (x_current, y_current) == (x_goal, y_goal)).
8. Example Problem Formulation:
Problem: Find the shortest path in a maze.
1. Initial State: The agent starts at the entrance of the maze, say at position (0, 0).
2. State Space: The state space consists of all positions within the maze that the agent can occupy (all
grid points in the maze).
3. Actions: The agent can move up, down, left, or right to adjacent positions in the maze.
4. Transition Model: If the agent is at position (0, 0) and moves right, it will transition to (0, 1). If it
moves up, it will transition to (1, 0).
5. Goal State: The agent needs to reach the exit position, say at (x_exit, y_exit).
6. Path Cost: The path cost is the number of steps taken by the agent. The agent aims to minimize this
cost.
7. Goal Test: The agent reaches the exit when its current position is equal to (x_exit, y_exit).
12. Formulate 8-Puzzle problem.
Ans: The 8-Puzzle problem is a classic sliding puzzle consisting of a 3x3 grid with 8 numbered tiles and
one empty space. The goal is to move the tiles around the grid to reach a specific goal configuration
(usually the numbers arranged in increasing order, with the empty space at the bottom right).
To solve this problem using AI techniques, we need to formulate the problem in terms of its key
components: initial state, state space, actions, transition model, goal state, path cost, and
solution conditions.
1. Define the Initial State
The initial state represents the starting configuration of the puzzle, where the tiles are arranged
in some random order, and the empty space is placed in a specific location.
● Example: The initial state could be represented as follows (where 0 represents the empty
space):
123
456
780
2. Define the State Space
The state space is the set of all possible configurations of the puzzle. It consists of all the
possible arrangements of the 8 tiles and the empty space, including both valid and invalid
configurations. The state space will have a size of 9!=362,8809! = 362,880 unique configurations
(considering the position of the empty space and the tiles).
● Example: In the state space, there are numerous possible tile configurations, such as:
123 123 123
456 456 465
780 708 078
3. Define the Actions (Operators)
The actions are the possible moves that can be made in each state. The empty space 0 can be
moved in one of the four possible directions (up, down, left, or right), provided that the move
does not go outside the boundaries of the grid.
● Example Actions:
○ If the empty space is at position (2, 2), it can move up to (1, 2), left to (2, 1), or
remain stationary (if no valid moves).
○ Moving the tiles around by swapping them with the empty space.
4. Define the Transition Model (T)
The transition model describes how each action transforms the current state into a new state. It
specifies the new configuration of tiles after an action is applied.
● Example Transition:
○ If the empty space (0) is at position (2, 2) and the action is to move it left, the new
state will be:
123
456
708
The tile 8 moves into the position (2, 2), and the empty space moves to (2, 1).
5. Define the Goal State
The goal state is the desired configuration of the puzzle, where the tiles are arranged in
increasing order, and the empty space is at the bottom-right corner.
● Example Goal State:
123
456
780
6. Define the Path Cost (C)
The path cost is the cost associated with moving from one state to another. For the 8-Puzzle
problem, the path cost is typically defined as the number of moves (or steps) taken from the
initial state to the goal state.
● Example Path Cost: The cost is simply the number of moves made to reach the goal
state. If the agent moves the tiles in 20 moves to reach the goal, the path cost is 20.
7. Define the Goal Test
The goal test checks whether the current state matches the goal state. If it does, the puzzle is
solved.
● Example Goal Test: The agent checks if the current configuration of the tiles matches:
123
456
780
If it matches, the agent has reached the goal.
8. Example of the 8-Puzzle Problem Formulation
Let's summarize the formulation of the 8-Puzzle problem:
Initial State:
Example initial configuration:
123
456
780
● State Space:
All possible configurations of the 8 tiles and the empty space.
● Actions:
Move the empty space up, down, left, or right (if possible).
● Transition Model:
The action applied to the empty space results in swapping the empty space with an
adjacent tile.
Goal State:
The configuration where the tiles are in increasing order:
123
456
780
● Path Cost:
The number of moves made to reach the goal state.
● Goal Test:
Check if the current configuration of tiles is equal to the goal state.
13. Compare different uninformed search strategies.
Ans: Uninformed search strategies, also known as blind search algorithms, are search techniques that
do not use any domain-specific knowledge (heuristics) to guide the search. These algorithms explore
the search space without any information about the goal state, other than the goal test. Below is a
comparison of the most common uninformed search strategies: Breadth-First Search (BFS), Depth-First
Search (DFS), Uniform Cost Search (UCS), and Depth-Limited Search (DLS).
1. Breadth-First Search (BFS)
Description:
BFS explores the search space level by level. It starts at the root node and expands all nodes at
the present depth level before moving on to nodes at the next depth level. It guarantees the
shortest path in an unweighted graph.
Properties:
● Complete: Yes, BFS will always find a solution if one exists (given the graph is finite).
● Optimal: Yes, BFS is optimal for an unweighted graph because it finds the shortest path.
● Time Complexity: O(bd)O(b^d), where bb is the branching factor and dd is the depth of
the shallowest goal.
● Space Complexity: O(bd)O(b^d) because BFS stores all nodes at the current depth level.
● Drawbacks: BFS can be memory-intensive, especially for large state spaces, because it
needs to store all the nodes at each level.
Example Use Case:
Finding the shortest path in a maze or an unweighted graph.
2. Depth-First Search (DFS)
Description:
DFS explores the search space by expanding as far as possible along a branch before
backtracking. It dives deep into the search tree and then moves to another branch when it hits a
dead end.
Properties:
● Complete: No, DFS may get stuck in infinite loops or fail to find a solution if the tree has
an infinite depth.
● Optimal: No, DFS does not guarantee the shortest path.
● Time Complexity: O(bm)O(b^m), where bb is the branching factor and mm is the
maximum depth of the search space.
● Space Complexity: O(b⋅m)O(b \cdot m), because DFS only needs to store a single path
from the root to a leaf, and the backtracking information.
● Drawbacks: DFS may explore unpromising branches and is not guaranteed to find the
shortest path. It can also fail in infinite-depth spaces if there is no limit on the depth.
Example Use Case:
Exploring a maze or game tree where a solution is likely to be found deep in the search space.
3. Uniform Cost Search (UCS)
Description:
UCS is a variant of BFS that expands the node with the lowest path cost (not the shallowest
level). It explores the nodes based on the cumulative cost of reaching them, making it useful
when the problem involves weighted edges or costs associated with actions.
Properties:
● Complete: Yes, UCS is complete as long as the cost of each step is positive.
● Optimal: Yes, UCS is optimal for problems with non-negative costs since it always
expands the least-cost node first.
● Time Complexity: O(bd)O(b^d), where bb is the branching factor and dd is the depth of
the shallowest goal.
● Space Complexity: O(bd)O(b^d), because UCS stores all explored nodes.
● Drawbacks: UCS can be slow and memory-intensive when the solution lies deep in the
search tree, particularly if there are many low-cost paths.
Example Use Case:
Finding the least-cost path in weighted graphs or route planning where each move has a
different cost.
4. Depth-Limited Search (DLS)
Description:
DLS is a modification of DFS that limits the search depth. It explores the search tree depth-first,
but stops if the depth exceeds a given limit. This helps avoid infinite loops in an infinite search
space.
Properties:
● Complete: No, DLS may miss the solution if it is deeper than the depth limit.
● Optimal: No, DLS does not guarantee an optimal solution.
● Time Complexity: O(bl)O(b^l), where bb is the branching factor and ll is the depth limit.
● Space Complexity: O(b⋅l)O(b \cdot l), as DLS only needs to store the current path to
depth ll.
● Drawbacks: DLS can fail to find a solution if the solution lies beyond the specified depth
limit.
Example Use Case:
Searching for solutions in a game tree with a known depth or puzzle with a specific depth.
5. Iterative Deepening Search (IDS)
Description:
IDS combines the strengths of DFS and BFS. It performs DFS with increasing depth limits,
ensuring that it behaves like BFS but with a smaller memory footprint. IDS performs DFS
repeatedly, increasing the depth limit each time, until it finds the goal.
Properties:
● Complete: Yes, IDS is complete.
● Optimal: Yes, IDS is optimal when the cost is uniform (i.e., all actions have the same
cost).
● Time Complexity: O(bd)O(b^d), where bb is the branching factor and dd is the depth of
the goal.
● Space Complexity: O(b⋅d)O(b \cdot d), because it stores only a single path from the root
to a leaf at any given time.
● Drawbacks: Although it avoids the large memory cost of BFS, IDS still performs
repeated work when revisiting nodes.
Example Use Case:
Problems where memory is limited but the solution depth is not known in advance, such as
searching a large tree with unknown depth.
Comparison Table
Strategy Complete Optimal Time Complexity Space Complexity Best Use Case
BFS Yes Yes O(bd)O(b^d) O(bd)O(b^d) Shortest path in unweighted graphs
DFS No No O(bm)O(b^m) O(b⋅m)O(b\cdot m)Exploring deep solutions, small spaces
UCS Yes Yes O(bd)O(b^d) O(bd)O(b^d) Weighted graphs or route planning
DLS No No O(bl)O(b^l) O(b⋅l)O(b \cdot l) Depth-limited search, avoiding infinite depth
IDS Yes Yes O(bd)O(b^d) O(b⋅d)O(b \cdot d) Large search spaces with unknown depth
14. Write a short note on uninformed search.
Ans: Uninformed search, also known as blind search, is a type of search algorithm used in Artificial
Intelligence (AI) where the search strategy explores the search space without any domain-specific
knowledge or heuristic guidance. These algorithms operate solely based on the structure of the
problem and the goal test. They do not use information that can help them directly evaluate the
desirability of a state relative to the goal (such as cost, distance, or probability).
Uninformed search strategies explore all possible states or paths based on the current state,
gradually expanding the search space until the goal is reached. Since these strategies do not rely
on heuristics or additional information about the problem, they tend to explore states in a
systematic, brute-force manner.
Key Characteristics of Uninformed Search:
1. No Domain Knowledge: Uninformed search strategies do not use any additional information about
the goal or the problem's structure beyond the state space and the goal test.
2. Exhaustive Search: These strategies explore all possible states and actions in the search space,
eventually finding a solution if one exists, although they can be inefficient.
3. Complete and Optimal: While some uninformed search strategies are complete (they will find a
solution if one exists) and optimal (they will find the best or shortest path), others may not be.
4. Time and Space Complexity: Uninformed search can be computationally expensive in terms of time
and space, especially when dealing with large state spaces, as they may require storing a large
number of states and may take considerable time to explore.
Common Uninformed Search Strategies:
1. Breadth-First Search (BFS):
○ Explores all nodes at the present depth level before moving to the next level.
○ Complete and Optimal for unweighted problems.
○ Space and time complexity: O(bd)O(b^d), where bb is the branching factor, and
dd is the depth of the shallowest goal.
2. Depth-First Search (DFS):
○ Explores as far down a branch as possible before backtracking.
○ Complete and Optimal only if the state space is finite and there are no infinite
paths.
○ Time complexity: O(bm)O(b^m), where bb is the branching factor, and mm is the
maximum depth.
○ Space complexity: O(b⋅m)O(b \cdot m).
3. Uniform Cost Search (UCS):
○ Expands the node with the least cumulative cost, useful for weighted graphs.
○ Complete and Optimal for problems with non-negative step costs.
○ Time and space complexity: O(bd)O(b^d).
4. Depth-Limited Search (DLS)
○ A version of DFS with a specified depth limit to avoid infinite search in spaces
with infinite depth.
○ Time complexity: O(bl)O(b^l), where ll is the depth limit.
○ Space complexity: O(b⋅l)O(b \cdot l).
5. Iterative Deepening Search (IDS):
○ Performs DFS with increasing depth limits, combining the space efficiency of
DFS with the completeness and optimality of BFS.
○ Time complexity: O(bd)O(b^d), where dd is the depth of the goal state.
○ Space complexity: O(b⋅d)O(b \cdot d).
Advantages of Uninformed Search:
● Simplicity: Uninformed search algorithms are relatively simple to implement as they do
not require problem-specific heuristics or additional knowledge.
● Generality: These algorithms can be applied to a wide variety of problems because they
do not rely on any prior knowledge of the domain.
Disadvantages of Uninformed Search:
● Inefficiency: Due to the exhaustive exploration of the search space, uninformed search
algorithms can be computationally expensive, especially in large and complex state
spaces.
● High Memory Usage: Some uninformed search strategies (like BFS) may require large
amounts of memory, particularly when dealing with a deep search space.
15. Compare between informed and uninformed search techniques.
Ans: In the context of Artificial Intelligence (AI), search algorithms are used to find solutions to
problems by exploring state spaces. The two main categories of search techniques are uninformed
search and informed search. These categories differ in how they explore the search space and the
amount of knowledge they use during the search process.
1. Uninformed Search (Blind Search)
Uninformed search algorithms explore the search space without using any additional
knowledge about the problem, other than the structure of the state space. These techniques rely
solely on the state space and goal test to determine the next state to explore.
Key Characteristics of Uninformed Search:
● No Domain-Specific Knowledge: These algorithms do not use any specific information
about the goal or the state.
● Systematic Exploration: Uninformed search strategies explore the entire search space,
often without any preference or prioritization.
● Complete and Optimal: Some uninformed search algorithms are complete (they will find
a solution if one exists) and optimal (they will find the best solution), while others may
not be.
● Computationally Expensive: These techniques can be inefficient and require a lot of
memory, especially in large state spaces.
Common Uninformed Search Techniques:
1. Breadth-First Search (BFS): Explores level by level, guarantees the shortest path for
unweighted graphs.
2. Depth-First Search (DFS): Explores a branch fully before backtracking, but may not find
the optimal solution.
3. Uniform Cost Search (UCS): Expands the node with the least cumulative cost, ideal for
weighted graphs.
4. Depth-Limited Search (DLS): A variation of DFS that limits the depth to avoid infinite
recursion.
5. Iterative Deepening Search (IDS): Combines the advantages of DFS and BFS, performing
DFS with increasing depth limits.
Advantages:
● Simple and Easy to Implement: Uninformed search algorithms are relatively
straightforward to program and apply.
● General Applicability: They can be used on a wide range of problems without the need
for domain-specific heuristics.
Disadvantages:
● Inefficiency: These algorithms may explore large portions of the state space
unnecessarily, leading to high time and space complexity.
● Memory Intensive: Some uninformed algorithms, such as BFS, require large amounts of
memory to store explored nodes.
2. Informed Search (Heuristic Search)
Informed search algorithms, also known as heuristic search, use additional information (a
heuristic) to guide the search process. The heuristic is a problem-specific function that estimates
the cost or distance from a given state to the goal. This allows informed search algorithms to
prioritize certain states over others, making the search more efficient.
Key Characteristics of Informed Search:
● Heuristic Knowledge: Informed search techniques use a heuristic function h(n)h(n) that
estimates the "goodness" or closeness of a state to the goal.
● Goal-Oriented Exploration: These algorithms explore the search space more efficiently
by prioritizing nodes that seem closer to the goal.
● Not Always Complete or Optimal: While informed search algorithms can be more
efficient, they do not guarantee completeness or optimality unless specific conditions are
met.
Common Informed Search Techniques:
1. Greedy Best-First Search: Expands nodes based on the heuristic that estimates the
distance to the goal, but it may not find the optimal path.
2. A Search:* Uses both the cost to reach a node g(n)g(n) and the heuristic estimate h(n)h(n)
to determine the best node to expand, ensuring both completeness and optimality when
the heuristic is admissible.
3. Hill Climbing: Moves to the neighboring state with the best heuristic value, but it can
get stuck in local minima.
4. Beam Search: A limited version of BFS that uses a heuristic to explore a subset of nodes
at each level.
Advantages:
● Efficient: Informed search algorithms are often much faster and require less memory
than uninformed search, especially in large state spaces, because they prioritize
promising paths.
● Optimal Solutions: Algorithms like A* can guarantee an optimal solution when an
admissible heuristic is used.
Disadvantages:
● Requires a Heuristic: The performance of informed search heavily depends on the
quality of the heuristic function.
● Not Always Complete: Some informed search algorithms may not guarantee that a
solution will be found, depending on the heuristic or problem constraints.
● Complexity in Designing Heuristics: Creating a good heuristic can be difficult, especially
for complex or poorly understood problems.
Comparison Table
Feature Uninformed Search Informed Search
Knowledge of the No domain-specific knowledge or heuristics. Uses a heuristic or domain-specific knowledge.
Problem
Search Strategy Explores the search space blindly (e.g., Guides the search using heuristics to prioritize
level-by-level, depth-first). nodes.
Efficiency Can be inefficient, explores many irrelevant More efficient, prioritizes promising states.
states.
Completeness Some methods (e.g., BFS) are complete; others Some methods (e.g., A*) are complete when the
(e.g., DFS) may not be. heuristic is admissible.
Optimality Some methods (e.g., BFS, UCS) guarantee Some methods (e.g., A*) guarantee optimality
optimality. if the heuristic is admissible.
Time Complexity Generally higher time complexity (e.g., Generally lower time complexity, depending
O(bd)O(b^d)). on heuristic.
Space Complexity Generally higher space complexity (e.g., Generally lower space complexity, depending
O(bd)O(b^d)). on heuristic.
Examples BFS, DFS, UCS, DLS, IDS. A*, Greedy Best-First Search, Hill Climbing.
Use Case Problems with limited or no heuristic Problems where a good heuristic is available.
information.
16. Explain Depth First Search Technique with an example.####
Ans: Depth-First Search (DFS) is one of the most commonly used uninformed search algorithms. It
explores a search space by starting at the root node and exploring as far as possible down one branch
before backtracking. DFS dives deep into a path, visiting child nodes one by one, until it either finds the
goal or reaches a dead end, at which point it backtracks to explore alternative paths.
DFS uses a stack to keep track of the nodes to be explored. It can be implemented either using
an explicit stack or through recursion, which implicitly uses the call stack.
Steps of DFS:
1. Start at the root node: Initialize the stack with the starting node.
2. Explore the node: Pop a node from the stack and visit it.
3. Expand the node: If the node has any children (or unvisited neighbors), push them onto
the stack.
4. Backtrack: If a node has no unvisited children, backtrack by popping from the stack and
continuing the exploration.
5. Goal Test: At each node, check if it is the goal. If it is, terminate the search.
6. Repeat: Continue exploring nodes until the goal is found or there are no nodes left to
explore.
Key Properties of DFS:
● Time Complexity: O(bm)O(b^m), where bb is the branching factor (average number of
child nodes) and mm is the maximum depth of the search space.
● Space Complexity: O(b⋅m)O(b \cdot m), since DFS only needs to store the current path
in memory.
● Complete: No, DFS may fail to find a solution if the search space has infinite depth or
loops.
● Optimal: No, DFS does not guarantee the shortest or least-cost path to the goal.
DFS Example
Let’s take an example of a simple graph to explain the DFS process.
Consider the following undirected graph:
A
/\
B C
/\ \
D E F
\
G
We want to perform a Depth-First Search starting from node A to find node G.
1. Initial State:
○ Stack = [A]
○ Current node = A
○ Mark node A has visited.
2. Step 1: Pop node A from the stack and visit it.
○ Stack = []
○ Explore neighbors of A: B, C
○ Push B and C onto the stack: Stack = [B, C]
3. Step 2: Pop node C from the stack and visit it.
○ Stack = [B]
○ Explore neighbors of C: F
○ Push F onto the stack: Stack = [B, F]
4. Step 3: Pop node F from the stack and visit it.
○ Stack = [B]
○ F has no unvisited neighbors, backtrack.
5. Step 4: Pop node B from the stack and visit it.
○ Stack = []
○ Explore neighbors of B: D, E
○ Push D and E onto the stack: Stack = [D, E]
6. Step 5: Pop node E from the stack and visit it.
○ Stack = [D]
○ Explore neighbors of E: G
○ Push G onto the stack: Stack = [D, G]
7. Step 6: Pop node G from the stack and visit it.
○ Stack = [D]
○ We have found the goal (node G), so the search ends.
Final Result:
● Goal Found: Node G was found after visiting nodes A → C → F → B → E → G.
● Solution Path: The solution path from node A to node G is: A → B → E → G.
DFS Advantages:
● Space-Efficient: DFS only requires memory proportional to the maximum depth of the
search tree, making it more space-efficient than BFS (which may require storing all nodes
at a particular level).
● Simple Implementation: DFS is relatively easy to implement using recursion or a stack.
DFS Disadvantages:
● Not Complete: DFS may fail to find the goal if the goal is deeper in the search space or if
there are infinite loops (if the search space is too large or poorly structured).
● Not Optimal: DFS does not guarantee the shortest path to the goal because it may
explore deeper paths before shallower ones.
● Can Get Stuck in Infinite Loops: If the graph contains cycles or infinite branches, DFS
may enter an infinite loop.
Applications of DFS:
● Puzzle Solving: DFS can be used in problems like the 8-Puzzle where all solutions are
valid.
● Pathfinding: In game AI, DFS can explore possible paths when an optimal solution is not
needed.
● Cycle Detection: DFS is useful in detecting cycles in a graph.
● Topological Sorting: DFS is used in tasks like topological sorting for directed acyclic
graphs (DAGs).
17. Explain Breadth First search algorithm. ####
Ans: Breadth-First Search (BFS) is an uninformed search algorithm that explores all nodes at the
present depth level before moving on to nodes at the next depth level. BFS is a level-order traversal,
meaning it systematically explores nodes level by level, ensuring that all neighbors of a node are
explored before their children. It is particularly useful when you want to find the shortest path to the
goal in an unweighted graph.
BFS uses a queue to keep track of the nodes to be explored. Nodes are added to the queue as
they are encountered, and the algorithm processes nodes by dequeuing them from the front of
the queue.
Steps of BFS:
1. Start at the root node: Initialize the queue with the starting node.
2. Explore the node: Dequeue a node from the front of the queue and visit it.
3. Expand the node: Add all unvisited neighbors (or child nodes) of the current node to the queue.
4. Goal Test: Check if the current node is the goal. If it is, terminate the search.
5. Repeat: Continue the process until the goal is found or there are no nodes left in the queue.
Key Properties of BFS:
● Time Complexity: O(bd)O(b^d), where bb is the branching factor (average number of
child nodes) and dd is the depth of the shallowest goal.
● Space Complexity: O(bd)O(b^d), since BFS needs to store all nodes at the current depth
level in the queue.
● Complete: Yes, BFS is guaranteed to find a solution if one exists, as it explores all
possible nodes level by level.
● Optimal: Yes, BFS is optimal for unweighted graphs, meaning it will always find the
shortest path (in terms of the number of edges) to the goal.
● Memory Intensive: BFS requires a large amount of memory to store the queue, especially
when the search space is large.
BFS Example
Consider the following undirected graph:
A
/\
B C
/\ \
D E F
\
G
We want to perform Breadth-First Search (BFS) starting from node A to find node G.
1. Initial State:
○ Queue = [A]
○ Current node = A
○ Mark node A has visited.
2. Step 1: Dequeue node A and visit it.
○ Queue = []
○ Explore neighbors of A: B, C
○ Add B and C to the queue: Queue = [B, C]
3. Step 2: Dequeue node B and visit it.
○ Queue = [C]
○ Explore neighbors of B: D, E
○ Add D and E to the queue: Queue = [C, D, E]
4. Step 3: Dequeue node C and visit it.
○ Queue = [D, E]
○ Explore neighbors of C: F
○ Add F to the queue: Queue = [D, E, F]
5. Step 4: Dequeue node D and visit it.
○ Queue = [E, F]
○ D has no unvisited neighbors, so backtrack.
6. Step 5: Dequeue node E and visit it.
○ Queue = [F]
○ Explore neighbors of E: G
○ Add G to the queue: Queue = [F, G]
7. Step 6: Dequeue node F and visit it.
○ Queue = [G]
○ F has no unvisited neighbors, so backtrack.
8. Step 7: Dequeue node G and visit it.
○ Queue = []
○ We have found the goal (node G), so the search ends.
Final Result:
● Goal Found: Node G was found after visiting nodes A → B → C → D → E → G.
● Solution Path: The solution path from node A to node G is: A → B → E → G.
Advantages of BFS:
● Complete: BFS guarantees that it will find a solution if one exists, since it explores all
possible paths level by level.
● Optimal for Unweighted Graphs: BFS guarantees the shortest path in an unweighted
graph, as it finds the goal with the minimum number of edges.
● Systematic: BFS ensures that no nodes are skipped, making it a reliable algorithm for
finding solutions.
Disadvantages of BFS:
● Space Complexity: BFS can be very memory-intensive, especially for large search spaces,
since it needs to store all nodes at the current level in memory.
● Inefficiency for Large Search Spaces: In graphs with large branching factors or deep
search spaces, BFS may take considerable time and memory to explore all possible
states.
● Not Suitable for Large, Infinite Graphs: In cases where the search space is infinite (e.g.,
in puzzles with many possible configurations), BFS may never terminate or will
consume excessive resources.
Applications of BFS:
● Shortest Path Problems: BFS is commonly used in unweighted graphs to find the
shortest path between nodes.
● Web Crawlers: BFS is used to explore all the pages on a website level by level.
● Social Network Analysis: BFS can be used to find the degree of separation between users
in a social network.
● Finding Connected Components: BFS can help in finding connected components in an
undirected graph.
18. Explain IDDFS algorithm.
Ans: Iterative Deepening Depth-First Search (IDDFS) is a search algorithm that combines the
advantages of both Depth-First Search (DFS) and Breadth-First Search (BFS). It is particularly useful
when the depth of the goal node is not known in advance, and it is memory-efficient compared to BFS,
but also guarantees completeness and optimality for unweighted graphs, like BFS.
IDDFS performs a series of Depth-First Search (DFS) iterations, each with a progressively deeper depth
limit. In each iteration, it limits the depth of DFS to a specific level (starting from 0 and increasing each
time) and performs a DFS within this limited depth. This process repeats until the goal is found.
Steps of IDDFS:
1. Start with a depth limit of 0: Perform DFS with depth limit L=0L = 0.
2. Increase the depth limit: Increase the depth limit by 1 after each iteration and perform DFS again
until the goal is found or the depth limit exceeds the maximum depth.
3. Repeat DFS at each depth limit: For each depth limit, DFS explores the search tree starting from the
root node, but it stops expanding nodes at the current depth limit.
4. Goal Test: In each DFS iteration, check if the current node is the goal. If it is, terminate the search.
5. Terminate when the goal is found: If the goal is found during any DFS iteration, the search ends.
Otherwise, continue with deeper depth limits.
Key Properties of IDDFS:
● Time Complexity: O(bd)O(b^d), where bb is the branching factor and dd is the depth of the
shallowest goal. Even though DFS is repeated at each level, the total time complexity remains
similar to BFS.
● Space Complexity: O(b⋅d)O(b \cdot d), since each DFS iteration only needs to store a single path,
making the space complexity the same as DFS.
● Complete: Yes, IDDFS is complete and will always find a solution if one exists, as it explores all
nodes up to the maximum depth.
● Optimal: Yes, IDDFS is optimal for unweighted graphs, meaning it will always find the shortest
path to the goal.
● Memory Efficient: Since it only needs to store the current path in memory (unlike BFS, which stores
all nodes at a level), IDDFS is memory-efficient.
Example of IDDFS
Let’s consider the same graph used for BFS and DFS for the explanation:
A
/\
B C
/\ \
D E F
\
G
We want to find node G starting from node A using IDDFS.
Iteration 1 (Depth Limit = 0):
● Start DFS with a depth limit of 0.
● Only visit node A.
● No goal found at this level.
Iteration 2 (Depth Limit = 1):
● Start DFS with a depth limit of 1.
● Visit node A → B → D and backtrack to B.
● Visit node A → B → E, backtrack to B, then to A.
● Visit node A → C.
● No goal found at this level.
Iteration 3 (Depth Limit = 2):
● Start DFS with a depth limit of 2.
● Visit node A → B → D and backtrack to B.
● Visit node A → B → E → G (Goal found).
● Goal found at this depth.
Final Result:
● Goal Found: Node G is found in the third iteration (depth limit = 2).
● Solution Path: The path from A to G is A → B → E → G.
Advantages of IDDFS:
1. Space Efficiency: IDDFS only requires space proportional to the maximum depth of the
search, making it more space-efficient than BFS, which needs to store all nodes at each
level.
2. Complete: Like BFS, IDDFS is guaranteed to find a solution if one exists, as it explores
every level in depth-first order.
3. Optimal for Unweighted Graphs: IDDFS guarantees the shortest path to the goal in
unweighted graphs, similar to BFS.
4. Suitable for Large Depths: IDDFS is useful when the depth of the goal is unknown or
potentially very large.
Disadvantages of IDDFS:
1. Time Overhead: Since DFS is repeated at each level, IDDFS can be less time-efficient than
BFS for finding the shortest path, especially when the depth of the solution is deep.
2. Repeated Work: The algorithm repeats the search for each depth level, leading to
redundant work in terms of revisiting nodes and edges.
Applications of IDDFS:
● State-space search in AI: IDDFS is used in AI when the depth of the goal is unknown,
and you want a solution with minimal memory usage.
● Puzzle Solving: Problems like the 8-puzzle where the depth is unknown and the solution
can vary in depth.
● Pathfinding Problems: In graphs where the goal depth is not known, IDDFS can explore
all possible paths to find the goal.
● Game Tree Search: In decision-making processes for games (e.g., chess or checkers),
where the depth of the tree is unpredictable.
19. Write a short note on informed search.
Ans: Informed Search (also known as heuristic search) refers to a class of search algorithms that use
additional information or heuristics to guide the search process. Unlike uninformed search methods,
which explore the search space blindly, informed search algorithms aim to make intelligent decisions
based on domain-specific knowledge, such as an estimate of the cost or distance to the goal.
In informed search, the search algorithm uses a heuristic function (h(n)), which is a measure of
the "cost" or "distance" from a given node nn to the goal. This additional information helps the
algorithm prioritize which nodes to explore first, potentially leading to faster and more efficient
solutions.
Key Characteristics of Informed Search:
1. Heuristic Function (h(n)):
○ A heuristic function provides an estimate of the cost or distance to the goal state
from any given state in the search space. The more accurate the heuristic, the
more efficient the search.
○ Heuristics do not need to be perfect but should provide some guidance on how
to reach the goal more effectively than random exploration.
2. Use of Domain Knowledge:
○ Informed search algorithms leverage domain-specific knowledge to make
smarter decisions about which path to take.
○ This makes informed search more efficient than uninformed search, particularly
when the state space is large and the goal is far from the starting point.
3. Optimality and Completeness:
○ Depending on the algorithm and the nature of the heuristic, informed search can
be optimal (find the best solution) and complete (guarantee a solution if one
exists).
○ For example, an admissible heuristic (one that never overestimates the true cost
to the goal) ensures that an informed search algorithm like A* is both optimal
and complete.
Popular Informed Search Algorithms:
1. Best-First Search (Greedy Search):
○ This algorithm selects the next node to expand based on the heuristic function h(n)h(n),
which estimates the cost from node nn to the goal.
○ It does not consider the cost it took to get to node nn, making it fast but not optimal.
2. Characteristics:
○ Time complexity: O(bd)O(b^d), where bb is the branching factor and dd is the depth of the
goal.
○ Completeness: Not guaranteed if the search space is infinite or if the heuristic is not
consistent.
○ Optimality: Not guaranteed.
3. A Search:*
○ A* is an optimal and complete informed search algorithm. It uses both the actual cost from
the start node to the current node g(n)g(n) and the heuristic estimate h(n)h(n) to determine
the next node to expand.
○ The total cost function f(n)=g(n)+h(n)f(n) = g(n) + h(n) is used to prioritize the nodes.
4. Characteristics:
○ Time complexity: O(bd)O(b^d), but more efficient than BFS in practice.
○ Completeness: Guaranteed if the heuristic is admissible.
○ Optimality: Guaranteed if the heuristic is admissible and consistent.
5. Hill Climbing:
○ Hill climbing is a local search algorithm that continuously moves in the direction of the
steepest ascent (i.e., the node with the best heuristic value) until it reaches a local maximum
or goal.
○ While simple, hill climbing can suffer from getting stuck in local maxima or plateaus.
6. Characteristics:
○ Time complexity: Depends on the problem.
○ Completeness: Not guaranteed.
○ Optimality: Not guaranteed.
Advantages of Informed Search:
● Efficiency: Informed search algorithms are typically more efficient than uninformed
search methods, as they prioritize nodes closer to the goal, reducing the number of
nodes that need to be explored.
● Faster Solution Finding: By using a heuristic, the algorithm can "focus" the search in the
right direction, allowing faster solution discovery in large search spaces.
Disadvantages of Informed Search:
● Dependence on Heuristic: The efficiency and effectiveness of informed search depend
heavily on the quality of the heuristic function. A poor heuristic can lead to inefficiency
or incorrect results.
● Memory Consumption: Some informed search algorithms (like A*) may require
significant memory to store nodes and their costs, especially when dealing with large
state spaces.
● Complexity of Designing Heuristics: Creating good heuristics can be challenging for
certain problems, particularly when there is little domain-specific knowledge available.
Applications of Informed Search:
● Pathfinding Algorithms: In robotics, games, and navigation systems, informed search
(especially A*) is used for finding the shortest path between two points on a map.
● Game AI: In strategic games like chess, informed search algorithms help evaluate
possible moves by considering heuristics like board control and piece value.
● Optimization Problems: In problems like job scheduling, resource allocation, or machine
learning, informed search techniques can efficiently find optimal or near-optimal
solutions.
20. Explain Heuristic function with example.
Ans: A heuristic function is a function used in search algorithms, particularly in informed search
strategies like A*, to estimate the "cost" or "distance" from a given state or node in the search space to
the goal state. It provides the search algorithm with additional domain-specific knowledge to guide its
exploration of the search space efficiently, often reducing the number of nodes that need to be explored.
In AI, the heuristic function helps the algorithm prioritize which node to explore next, typically
focusing on those that appear to bring the search closer to the goal.
Key Characteristics of Heuristic Functions:
1. Estimate of the Goal Distance:
○ The heuristic function estimates the distance from a given state to the goal. This
estimate does not need to be accurate but should be useful enough to guide the
search efficiently.
2. Problem-Specific:
○ Heuristics are designed based on the nature of the problem being solved. For
instance, in pathfinding problems, heuristics often estimate the straight-line
distance to the goal.
3. Admissibility:
○ A heuristic is admissible if it never overestimates the actual cost to reach the
goal. Admissibility is important for ensuring optimality in algorithms like A*.
4. Consistency (Monotonicity):
○ A heuristic is consistent if, for every node nn and every successor n′n' of nn with
step cost c(n,n′)c(n, n'), the following condition holds: h(n)≤c(n,n′)+h(n′)h(n) \leq
c(n, n') + h(n') Consistency ensures that the heuristic function does not lead the
search to underestimate the cost of reaching the goal.
Example of Heuristic Function:
Let’s consider the 8-Puzzle problem as an example to understand a heuristic function.
The 8-Puzzle Problem:
The goal of the 8-puzzle is to move the tiles on a 3x3 board to reach a goal configuration,
typically with the tiles ordered from 1 to 8, with the blank tile (represented as 0) in the last
position.
Example of an initial configuration:
123
456
780
The goal configuration might be:
123
456
780
The task is to find a sequence of moves to rearrange the tiles from the initial configuration to the
goal configuration.
Heuristic Functions for 8-Puzzle:
1. Misplaced Tiles:
○ One common heuristic is the number of misplaced tiles, which counts how many
tiles are out of place compared to the goal state.
○ Heuristic function h1(n)h_1(n): Count the number of tiles that are not in their
goal positions.
Example: If the current configuration is:
123
456
708
Compare it to the goal configuration:
123
456
780
○ The misplaced tiles are 8. So, the heuristic value for this state would be 1 (since
tile 8 is misplaced).
2. Manhattan Distance:
○ Another common heuristic is Manhattan distance, which calculates the total sum
of the distances each tile is from its goal position, measured in grid units.
○ Heuristic function h2(n)h_2(n): For each tile, calculate the sum of the vertical and
horizontal distances to its goal position.
Example: For the configuration:
123
456
708
3. The Manhattan distances for each tile:
○ Tile 1 is already in the correct position (distance = 0).
○ Tile 2 is already in the correct position (distance = 0).
○ Tile 3 is already in the correct position (distance = 0).
○ Tile 4 is already in the correct position (distance = 0).
○ Tile 5 is already in the correct position (distance = 0).
○ Tile 6 is already in the correct position (distance = 0).
○ Tile 7 is already in the correct position (distance = 0).
○ Tile 8 is 1 step away from its goal position (distance = 1).
4. So, the total Manhattan distance for this configuration is 1 (tile 8's distance).
Choosing Heuristics:
● Misplaced tiles is a simple and easy-to-compute heuristic but is not very accurate
because it only counts misplaced tiles without considering how far each tile is from its
goal.
● Manhattan distance is often more effective because it gives a better estimate of how close
a state is to the goal, considering the spatial relationship between tiles.
Role of Heuristic in Informed Search (A):*
In the A* search algorithm, the heuristic function plays a critical role. A* uses the following cost
function to prioritize which nodes to explore: f(n) = g(n) + h(n)
● g(n): The cost to reach the current node from the start node.
● h(n): The estimated cost to reach the goal from the current node (provided by the
heuristic).
A* combines both the actual cost to reach a node and the heuristic estimate to make decisions
about which node to explore next. The algorithm expands nodes with the lowest f(n)f(n) value,
meaning it balances exploration with heuristic guidance.
Advantages of Heuristic Functions:
● Efficiency: Heuristics can dramatically reduce the search space and speed up the search
process by focusing on the most promising paths.
● Optimality: When used properly (with admissible heuristics), algorithms like A* can
guarantee an optimal solution.
● Applicability: Heuristics can be applied to a wide range of problems, from pathfinding
to game-playing to constraint satisfaction problems.
Disadvantages of Heuristic Functions:
● Domain-Specific: A heuristic function is highly problem-specific, so it may not be easily
transferable to other problems.
● Accuracy: A poor heuristic may lead to inefficiency or incorrect results. The more
accurate the heuristic, the more effective the algorithm will be.
● Computational Overhead: In some cases, computing the heuristic itself may add
overhead, particularly in large or complex search spaces.
21. Find Heuristic value for a particular state of the blocks world problem.
Ans: The Blocks World Problem is a classic AI problem where a set of blocks are stacked on top of each
other on a table, and the task is to move the blocks around to achieve a goal configuration. A state in
the Blocks World represents the current arrangement of blocks, and the goal is typically to arrange the
blocks in a specified order (e.g., stacking blocks in a particular sequence).
In this problem, we often use heuristic functions to estimate how far a particular state is from
the goal state. Heuristic functions help guide the search process in algorithms like A*.
Problem Setup:
Consider there are 3 blocks: A, B, and C. The goal is to arrange the blocks such that:
● Block A is on the table.
● Block B is on top of block A.
● Block C is on top of block B.
Example Goal Configuration:
C
B
A
The state of the blocks in the problem is represented as a configuration, which could be something like:
State 1:
A
B C
This means that Block A is on the table, and Block B is placed on top of Block C.
Heuristic Function for the Blocks World:
A heuristic function for the Blocks World Problem typically involves counting the number of
misplaced blocks or counting how far each block is from its goal position.
Common Heuristic Approaches:
1. Misplaced Blocks Heuristic:
○ This heuristic counts the number of blocks that are not in their correct positions.
○ Heuristic value (h1): Count how many blocks are out of place.
2. Goal Distance Heuristic (Height Difference):
○ This heuristic counts how many blocks are not stacked on their correct blocks.
Each misplaced block contributes to a certain penalty or cost.
○ Heuristic value (h2): The number of blocks that need to be moved to reach the
goal.
3. Stacking Order Heuristic:
○ This heuristic can also take into account how many blocks are placed incorrectly
in terms of their stacking order.
Example Calculation of Heuristic Value for a Particular State:
Let’s calculate the heuristic value for a particular state of the blocks using the misplaced blocks
heuristic.
State Configuration (State 1):
State 1:
A
B C
Goal Configuration:
C
B
A
● In this case, Block A is in the correct position (on the table), so no heuristic penalty for
Block A.
● Block B is not in its correct position. It should be on top of Block A, but it is on the table.
● Block C is not in its correct position. It should be on top of Block B, but it is currently
placed below Block B.
Heuristic Calculation:
● Block A: Correct position (no penalty).
● Block B: Incorrect position (needs to be placed on top of Block A).
● Block C: Incorrect position (needs to be placed on top of Block B).
So, in this case, both Block B and Block C are misplaced.
Thus, the heuristic value for this state, based on the misplaced blocks heuristic, is 2.
Alternative Heuristic: Goal Distance or Height Difference
If we use a more advanced heuristic, such as counting the number of blocks that need to be
moved, we can calculate the number of moves required to place each block in its goal position.
For example, Block B needs to move on top of Block A, and Block C needs to move on top of
Block B.
In this case, we could consider each block's distance from its goal and calculate a heuristic based
on how far each block needs to be moved. This could provide a more accurate estimate of the
cost to reach the goal.
22. Explain search strategy to overcome drawback of BFS and DFS.
Ans: Breadth-First Search (BFS) and Depth-First Search (DFS) are fundamental search algorithms used
in AI, but both have significant drawbacks in certain scenarios. These drawbacks can lead to
inefficiency or even failure to find a solution. Several advanced search strategies have been developed
to overcome these issues.
Let's first examine the drawbacks of BFS and DFS and then discuss the strategies designed to
mitigate them.
Drawbacks of BFS:
1. Memory Consumption:
○ BFS needs to store all nodes at a particular level before moving to the next level.
This can require a lot of memory, especially if the search space is large and the
branching factor is high.
○ Worst-case space complexity: O(bd)O(b^d), where bb is the branching factor and
dd is the depth of the solution.
2. Inefficiency in Large Search Spaces:
○ If the search space is vast, BFS can explore a large number of irrelevant nodes
before reaching the goal, especially in problems with large or infinite state
spaces.
○ This makes BFS slow, even though it is guaranteed to find the shortest path to the
goal.
Drawbacks of DFS:
1. Getting Stuck in Infinite Paths:
○ DFS may go deep into a branch without considering other branches, and if there
is a cycle or an infinitely deep path, the algorithm might never reach the goal.
2. No Guarantee of Optimality:
○ DFS does not guarantee the shortest path to the goal. It can find a solution, but it
may not be the most optimal one.
3. Memory Consumption:
○ While DFS uses less memory than BFS, it can still be inefficient if the search tree
has many deep branches. It may need to backtrack frequently, wasting time and
resources.
Search Strategies to Overcome the Drawbacks:
To address the issues with BFS and DFS, several search strategies have been proposed:
1. Iterative Deepening Depth-First Search (IDDFS):
● IDDFS combines the advantages of both DFS and BFS by performing DFS iteratively
with increasing depth limits. It performs DFS with depth limit 1, then depth limit 2, and
so on, until it finds the goal.
● Benefits:
○ Space Efficiency: It uses less memory than BFS, as it only stores a single path
from the root to the current node.
○ Completeness: Like BFS, it is guaranteed to find the solution if one exists.
○ Optimality: If the step cost is uniform (i.e., each step costs the same), IDDFS is
guaranteed to find the shortest path, just like BFS.
● Drawback Addressed:
○ Memory consumption: IDDFS only stores the nodes along the current path, so it
uses less memory than BFS.
○ Inefficiency: It explores the tree depth by depth, thus avoiding the issue of
getting stuck in deep or infinite branches like DFS.
Example: In an IDDFS, you first explore all nodes at depth 1, then all nodes at depth 2, and so
on. The main idea is that each DFS iteration is progressively deeper, but it doesn't risk infinite
depth or excessive memory usage.
2. A Search (Informed Search):*
● A* is an informed search algorithm that combines the advantages of both BFS and DFS
while using heuristics to guide the search. It uses an evaluation function
f(n)=g(n)+h(n)f(n) = g(n) + h(n), where:
○ g(n)g(n) is the cost from the start node to node nn.
○ h(n)h(n) is the heuristic estimate of the cost from node nn to the goal.
● Benefits:
○ Optimality: If the heuristic is admissible (never overestimates the true cost), A*
guarantees an optimal solution.
○ Efficiency: A* can find the solution faster than BFS and DFS, as it prioritizes
nodes that are more likely to lead to the goal.
● Drawback Addressed:
○ Inefficiency of BFS: A* uses heuristics to prioritize exploring the most promising
paths first, reducing the number of irrelevant nodes explored.
Example: In pathfinding problems (like navigating a robot through a grid), A* uses the
Manhattan distance or Euclidean distance as a heuristic to guide the search and find the shortest
path efficiently.
3. Greedy Best-First Search (GBFS):
● Greedy Best-First Search is similar to A*, but it only uses the heuristic function h(n)h(n)
to guide the search, ignoring the actual cost to reach the node g(n)g(n).
● Benefits:
○ Faster than BFS in some cases because it focuses on the goal, using the heuristic
to prioritize the search.
○ Memory Efficiency: It can potentially reduce memory usage compared to BFS if
the branching factor is large.
● Drawback Addressed:
○ Inefficiency of BFS: GBFS aims to reach the goal faster by prioritizing states closer
to the goal, but it doesn't guarantee optimality.
Example: In a maze-solving problem, GBFS would prioritize exploring nodes that are closer to
the goal based on a heuristic (such as Manhattan distance).
4. Bidirectional Search:
● Bidirectional Search performs two searches: one from the start node and one from the
goal node, meeting in the middle. This approach effectively reduces the search space.
● Benefits:
○ Faster than BFS because it simultaneously searches forward from the start and
backward from the goal.
○ Memory Usage: While it still needs memory for both searches, it can be more
efficient than a single search in some cases.
● Drawback Addressed:
○ Efficiency of BFS: It reduces the number of nodes explored by searching from
both ends toward the middle.
Example: If you're trying to find the shortest path in a large maze, starting both from the start
and the goal will quickly reduce the search space.
5. Depth-Limited Search:
● Depth-Limited Search (DLS) is a variant of DFS that limits the depth of the search. This
avoids infinite depth issues and controls memory consumption.
● Benefits:
○ Memory Efficiency: DLS uses less memory than BFS by avoiding deep recursive
searches.
○ Prevents Infinite Loops: By limiting the depth, it prevents DFS from exploring
infinite branches.
● Drawback Addressed:
○ DFS's Infinite Path Problem: It avoids infinite recursion issues by setting a
predefined depth limit.
Summary of Search Strategies:
Strategy Benefit Drawback Addressed
IDDFS Combines space efficiency of DFS with the Memory consumption and inefficiency of BFS.
completeness of BFS.
A* Search Optimal and efficient due to heuristics. Inefficiency of BFS and DFS by prioritizing
promising nodes.
Greedy BFS Faster than BFS, especially when the heuristic Inefficiency of BFS by guiding the search
is good. toward the goal.
Bidirectional Faster search by exploring from both the start Efficiency issues in BFS, especially in large
Search and goal. search spaces.
Depth-Limited Memory-efficient and avoids infinite Infinite path issue in DFS.
Search recursion.
23. Explain A* Algorithms. What is the drawback of A*? Also shows that A* is optimally efficient.
Ans: A Algorithm*
The A* (A-star) algorithm is one of the most widely used search algorithms for finding the
shortest path in a graph or a grid. It combines the advantages of both Breadth-First Search (BFS)
and Greedy Best-First Search (GBFS) by using heuristics and costs to guide the search towards
the most promising nodes.
A* is especially used in pathfinding and graph traversal problems, like route planning in maps,
robotics, and game AI.
A Algorithm Explanation:*
A* search works by maintaining two sets of nodes:
1. Open Set: This contains nodes that are yet to be evaluated. Initially, it only contains the
start node.
2. Closed Set: This contains nodes that have already been evaluated.
The A* algorithm also uses an evaluation function f(n)f(n), which combines two components:
● g(n): The cost to reach the current node nn from the start node (also known as the actual
cost).
● h(n): A heuristic estimate of the cost to reach the goal from the current node nn (also
called the estimated cost).
Thus, the evaluation function is:
f(n)=g(n)+h(n)f(n) = g(n) + h(n)
Where:
● g(n) is the cost to reach node nn from the start node.
● h(n) is the heuristic estimate of the cost to reach the goal node from nn.
The algorithm selects the node with the lowest f(n)f(n) value for exploration and updates its
neighbors accordingly, adding them to the open set and removing the current node from the
open set once evaluated.
Steps of A Algorithm:*
1. Initialize the open set with the start node.
2. Loop:
○ Select the node nn in the open set with the lowest f(n)f(n) value (i.e., the most
promising node).
○ If nn is the goal node, terminate the search and reconstruct the path.
○ Otherwise:
■ Move node nn from the open set to the closed set (i.e., it’s evaluated).
■ For each neighbor of nn, calculate its f(n)f(n) value:
■ If the neighbor is not in the open or closed set, add it to the open
set with the calculated f(n)f(n).
■ If the neighbor is in the open set but the newly computed f(n)f(n)
is lower, update it.
3. Repeat until the open set is empty or the goal is found.
Drawbacks of A Algorithm:*
While A* is very powerful and efficient, it has some drawbacks:
1. Memory Consumption:
○ A* can be very memory-intensive. It stores every node in the open and closed
sets, which can be a problem in large state spaces. This makes it infeasible for
very large graphs or problems with a high branching factor.
○ The space complexity of A* is O(bd)O(b^d), where bb is the branching factor and
dd is the depth of the solution.
2. Heuristic Dependency:
○ A* relies heavily on the heuristic function h(n)h(n). If the heuristic is not
admissible or informative, the algorithm can become inefficient or even fail to
find an optimal path.
■ An admissible heuristic is one that never overestimates the true cost to
reach the goal.
■ If the heuristic is too optimistic, A* may take suboptimal paths or explore
irrelevant parts of the state space.
3. Expensive Heuristic Calculation:
○ For certain types of problems, the heuristic function h(n)h(n) can be
computationally expensive to calculate, slowing down the overall search.
A Algorithm is Optimally Efficient:*
A is said to be optimally efficient* because it will always find the shortest path to the goal,
provided that the heuristic h(n)h(n) is admissible (i.e., it never overestimates the true cost to
reach the goal). This optimality is guaranteed by the following conditions:
1. Admissibility of the Heuristic:
○ If the heuristic h(n)h(n) is admissible (i.e., it never overestimates the cost to reach the goal), A* will
always find the shortest path.
○ The admissibility ensures that A* doesn’t miss any potential optimal solutions.
2. Consistency (or Monotonicity) of the Heuristic:
○ The heuristic h(n)h(n) is consistent (or monotonic) if, for every node nn and its successor n′n', the
estimated cost h(n)h(n) satisfies the condition:
where c(n,n′)c(n, n') is the actual cost from node nn to n′n'. A heuristic that is both admissible
and consistent ensures that A* will not re-expand any node and will always find the optimal
solution efficiently.
3. Optimal Efficiency:
○ A* is considered optimally efficient because among all algorithms that use an admissible heuristic,
it explores the least number of nodes to find the solution. No other algorithm using an admissible
heuristic can find the optimal solution while exploring fewer nodes than A*.
○ This makes A* optimal in terms of finding the shortest path and efficient in its exploration.
Proof of Optimality (Informal):
● Since A* always selects the node with the lowest f(n)=g(n)+h(n)f(n) = g(n) + h(n), it ensures that it’s
always moving toward the goal in the most cost-effective way. If the heuristic is admissible, it never
overestimates the cost to reach the goal, so the algorithm will never miss an optimal solution.
● Moreover, if there’s a shorter path to the goal, A* will eventually discover it by exploring nodes
with lower f(n)f(n) values.
This guarantees that A* explores the least number of nodes to find the optimal path, and no
other admissible algorithm can perform better.
Example:
Consider a simple grid-based pathfinding problem with a start node at the bottom-left corner
and the goal node at the top-right corner. Let’s assume the grid is uniform (i.e., each step has the
same cost), and we use the Manhattan distance as the heuristic h(n)h(n), which is admissible in
this case. A* will find the shortest path by combining the actual cost to reach a node (from the
start) with the estimated cost to reach the goal (from the node to the goal).
Steps:
1. A* evaluates nodes based on the sum of actual path costs and the heuristic estimate to the goal.
2. It explores nodes along the most promising path based on the heuristic.
3. Once it reaches the goal, it reconstructs the shortest path.
24. What do you mean by an admissible Heuristic function? Explain with examples.
Ans: Admissible Heuristic Function
An admissible heuristic is a heuristic function used in search algorithms, such as A*, that never
overestimates the true cost to reach the goal from a given state or node. In other words, for any
node nn, an admissible heuristic h(n)h(n) satisfies the condition:
h(n)≤true cost to reach the goal from nh(n) \leq \text{true cost to reach the goal from } n
The key property of an admissible heuristic is that it provides a lower bound on the actual cost
to reach the goal, ensuring that it doesn’t overestimate the cost. This ensures that the search
algorithm (like A*) will always find the optimal solution, as it won’t discard paths that might
ultimately lead to the best solution.
Why is Admissibility Important?
Admissibility is crucial because:
● A* algorithm guarantees optimality: If the heuristic is admissible, A* will always find
the shortest path to the goal (if one exists). This is because the admissible heuristic
ensures that A* doesn’t overlook potentially optimal paths in favor of suboptimal ones.
● Avoids overestimation: If the heuristic overestimates the cost, the search may become
misguided and fail to find the optimal solution.
In summary, an admissible heuristic ensures that the search algorithm doesn't explore less
optimal paths, thus making the algorithm more efficient while still guaranteeing the optimal
solution.
Examples of Admissible Heuristic Functions
Here are a few examples of admissible heuristics, mainly in grid-based pathfinding problems or
graph traversal:
1. Manhattan Distance (in Grid-Based Pathfinding):
● Problem: Suppose you have a robot trying to move in a grid, and the goal is to reach a
particular destination. The cost of each movement is uniform (e.g., moving one unit in
any direction costs the same).
● Heuristic: The Manhattan distance between the current node and the goal is the sum of
the absolute differences in the x-coordinates and y-coordinates of the current node and
the goal.
Formula:
where:
● xnx_n and yny_n are the coordinates of the current node.
● xgx_g and ygy_g are the coordinates of the goal.
Admissibility: Manhattan distance is admissible because it never overestimates the true cost to
the goal. This is because, at best, the robot can only move in straight lines along the grid, so the
Manhattan distance provides the shortest possible path that avoids obstacles.
Example:
● Start at (2, 3) and goal at (5, 7).
● Manhattan distance: h=∣2−5∣+∣3−7∣=3+4=7h = |2 - 5| + |3 - 7| = 3 + 4 = 7.
● The true cost (if there are no obstacles) is also at least 7, so this heuristic is admissible.
2. Euclidean Distance (in Grid-Based Pathfinding):
● Problem: Similar to the Manhattan distance, but now the robot can move diagonally,
which introduces more flexibility.
● Heuristic: The Euclidean distance is the straight-line distance between two points, which
is given by:
Formula:
Admissibility: The Euclidean distance is admissible because the straight-line distance is always
the shortest possible distance between two points in the plane. It cannot overestimate the true
cost since diagonal movements are allowed, and this heuristic considers the direct path.
Example:
● Start at (2, 3) and goal at (5, 7).
● Euclidean distance:
● This heuristic underestimates or matches the actual cost in this scenario.
3. Zero Heuristic (in Some Search Problems):
● Problem: In some cases, a simple heuristic that always returns 0 might be used.
● Heuristic: The zero heuristic simply returns 0 for every node:
h(n)=0h(n) = 0
Admissibility: This is trivially admissible because 0 is always less than or equal to the true cost
to reach the goal. While this heuristic provides no information about the distance to the goal, it
still allows the search algorithm to work.
Example:
● In a search problem, even if you don't know anything about the goal, a zero heuristic
would always be admissible, as it cannot overestimate the true cost.
4. Misplaced Tiles (in 8-Puzzle Problem):
● Problem: In the 8-puzzle problem, you need to slide tiles around to arrange them in a
specific order, where each tile has a goal position.
● Heuristic: The misplaced tiles heuristic counts the number of tiles that are not in their
goal position.
Formula:
h(n)=Number of misplaced tiles in the current state compared to the goal stateh(n) = \text{Number of
misplaced tiles in the current state compared to the goal state}
Admissibility: This is admissible because the true cost to reach the goal cannot be less than the
number of misplaced tiles. Each move can at most correct one misplaced tile, so the heuristic
never overestimates the true cost.
Example:
Non-Admissible Heuristic Examples:
A non-admissible heuristic can overestimate the cost, leading to incorrect conclusions. For
example:
● Euclidean Distance in a Grid with Obstacles: If you use Euclidean distance as a heuristic
in a grid with obstacles, it can overestimate the true cost because it does not account for
the blocked cells. For example, in a case where there is a wall between the start and goal,
the heuristic will still calculate a straight-line path, which is impossible to traverse due
to the wall.
● Overestimating Manhattan Distance in a Grid: If a heuristic calculated using Manhattan
distance assumes a perfect path without obstacles but the grid contains obstacles, it will
overestimate the true cost by ignoring obstacles.
Or Write short note on admissibility of A*.
25. Prove that A* is Admissible if it uses Monotone heuristic.
Ans: In this proof, we will show that A* is admissible (i.e., it always finds the optimal path) if the
heuristic used by A* is monotone (also known as consistent). A heuristic is considered monotone or
consistent if it satisfies the following condition:
h(n)≤c(n,n′)+h(n′)h(n) \leq c(n, n') + h(n')
Where:
● h(n)h(n) is the heuristic estimate of the cost to reach the goal from node nn,
● c(n,n′)c(n, n') is the actual cost to reach the successor node n′n' from nn,
● h(n′)h(n') is the heuristic estimate of the cost to reach the goal from the successor node
n′n'.
Key Terminology:
● Admissible Heuristic: A heuristic is admissible if it never overestimates the actual cost to
reach the goal from any given node. Formally, for any node nn, h(n)≤true cost to reach
the goal from nh(n) \leq \text{true cost to reach the goal from } n.
● A* Algorithm: A* uses a function f(n)=g(n)+h(n)f(n) = g(n) + h(n), where:
○ g(n)g(n) is the cost from the start node to the current node nn,
○ h(n)h(n) is the heuristic estimate from node nn to the goal.
To Prove:- If A* uses a monotone heuristic, then it is admissible (i.e., it always finds the optimal
solution).
Proof:
Step 1: Behavior of A* Search with Monotone Heuristic
A* selects nodes for expansion based on the lowest value of f(n)=g(n)+h(n)f(n) = g(n) + h(n).
The key to the proof is understanding the behavior of A* with respect to monotone heuristics.
● Monotonicity ensures that the heuristic function respects the actual cost to move
between nodes and remains consistent as we move through the search space. That is, the
difference between the heuristic values of neighboring nodes never exceeds the actual
cost to move between those nodes.
For any node nn and its successor n′n', monotonicity requires:
h(n)≤c(n,n′)+h(n′)h(n) \leq c(n, n') + h(n')
where c(n,n′)c(n, n') is the actual cost to reach n′n' from nn.
Step 2: Relationship Between f(n)f(n) and Optimal Path
To show admissibility, we must prove that A* will not discard any potential optimal path,
meaning it will always find the path with the lowest total cost.
● The optimal path from the start node to the goal node has a true cost, which we denote
by g∗(n)g^*(n), the minimum cost from the start to node nn.
● A* evaluates the nodes by their f(n)=g(n)+h(n)f(n) = g(n) + h(n), where g(n)g(n) is the
actual cost to reach node nn from the start node, and h(n)h(n) is the heuristic estimate to
the goal from nn.
Step 3: Demonstrating A* with Monotonicity
Let's show that A* will expand nodes in an optimal order, ensuring the optimal solution is
found.
1. Consider a node nn:
○ Suppose nn is on the optimal path and g∗(n)g^*(n) represents the optimal cost
from the start to nn.
○ For a node nn, the cost function is f(n)=g(n)+h(n)f(n) = g(n) + h(n). If the heuristic
is admissible, it means that h(n)≤g∗(n)h(n) \leq g^*(n), because the heuristic can't
overestimate the true cost to the goal.
2. Monotonicity Condition:
○ A key property of the monotonicity condition is that it ensures the total cost
f(n)f(n) reflects the true optimal cost to the goal.
○ Since h(n)≤c(n,n′)+h(n′)h(n) \leq c(n, n') + h(n'), the heuristic doesn't "overshoot"
the actual cost of reaching the goal. Therefore, each node expansion considers all
paths that contribute to the lowest cost.
3. Implication for Optimality:
○ The important point is that, due to monotonicity, the heuristic h(n)h(n) is
guaranteed to follow the true path to the goal without skipping any potentially
optimal paths.
○ Therefore, when A* expands a node, it will never overlook a path that might lead
to a lower-cost solution.
4. Optimal Path Guarantee:
○ Since the monotone heuristic never overestimates the cost to reach the goal, it
guides the search towards the optimal solution by always prioritizing the
least-cost paths.
○ A* will continue expanding nodes until it finds the goal, and due to the
monotonicity of the heuristic, the path it finds will always be the one with the
minimum cost.
Step 4: Conclusion
● Monotonicity ensures A*'s admissibility: Because the heuristic is monotone, A* expands
nodes in the correct order, ensuring that it always finds the optimal path to the goal.
● The heuristic guides the search efficiently, but does not cause A* to overlook any
lower-cost paths. This means that the path found by A* will always be the optimal one.
Thus, we have shown that if A* uses a monotone heuristic, it is admissible, meaning that it will
always find the optimal solution to the problem.
26. Compare following informed search algorithms based on performance measure with
justification: , optimal, time complexity and space complexity.
a) Greedy best first
b) A*
c) recursive best-first-first(RBFS)
Ans:
1. Greedy Best-First Search (GBFS)
Greedy Best-First Search is an informed search algorithm that selects the next node to explore
based on the heuristic function alone, prioritizing nodes that seem closest to the goal.
Optimality:
● Not optimal: Greedy Best-First Search is not guaranteed to find the optimal solution
because it only considers the heuristic function h(n)h(n) and does not account for the
actual cost g(n)g(n) from the start node. Therefore, it may explore paths that look
promising in terms of the heuristic but lead to suboptimal solutions.
Time Complexity:
● Time complexity is generally O(b^d), where:
○ bb is the branching factor (the maximum number of successors for a node),
○ dd is the depth of the solution.
○ In the worst case, the algorithm may need to explore all the nodes in the search
tree, similar to breadth-first search.
Space Complexity:
● Space complexity is also O(b^d) because GBFS must store all nodes in memory at once
(all nodes in the frontier and their children). Since it doesn't keep track of the path costs,
it may need to store a large number of nodes, leading to high memory consumption.
2. A* Search
A* Search is a well-known algorithm that combines the actual cost to reach a node g(n)g(n) and
the estimated cost to the goal h(n)h(n), using a total evaluation function f(n)=g(n)+h(n)f(n) =
g(n) + h(n). A* optimizes for both the path cost and the heuristic.
Optimality:
● Optimal: A* is guaranteed to find the optimal solution as long as the heuristic h(n)h(n) is
admissible (never overestimates the true cost to the goal) and monotonic (consistent). If
both conditions are satisfied, A* will always return the shortest path.
Time Complexity:
● Time complexity is O(b^d) in the worst case, similar to GBFS, where:
○ bb is the branching factor, and
○ dd is the depth of the solution.
○ In some cases, A* may need to explore a large portion of the search space to
guarantee optimality.
Space Complexity:
● Space complexity is also O(b^d) because A* needs to store all nodes in the frontier and
those already explored (expanded). This high space complexity is due to the need to
keep track of both the cost to reach each node and the heuristic value.
3. Recursive Best-First Search (RBFS)
Recursive Best-First Search (RBFS) is a modified version of the best-first search algorithm that
attempts to reduce the memory overhead by using recursion. It is designed to use linear space,
unlike A*, while still providing optimality under certain conditions.
Optimality:
● Optimal: RBFS is optimal if the heuristic h(n)h(n) is admissible and monotonic, just like
A*. It guarantees finding the optimal solution by always expanding the most promising
node (the one with the lowest f(n)=g(n)+h(n)f(n) = g(n) + h(n)).
Time Complexity:
● Time complexity is also O(b^d), but with the additional overhead of recursion. In the
worst case, the algorithm may explore all nodes in the search space, similar to A* and
GBFS.
● The key difference is that RBFS may be more efficient in practice, especially in terms of
memory usage, even though its time complexity is still O(b^d).
Space Complexity:
● Space complexity is O(bd), which is linear in terms of the depth of the search. Unlike A*,
which stores all nodes in memory, RBFS only needs to store the current path from the
root to the current node and its recursive calls. This makes RBFS significantly more
memory-efficient than A* and GBFS, especially for deep search spaces.
Comparison Summary
Algorithm Optimality Time Complexity Space Complexity
Greedy Best-First Search Not optimal O(b^d) O(b^d)
A* Search Optimal (if admissible & O(b^d) O(b^d)
monotonic)
Recursive Best-First Search (RBFS) Optimal (if admissible & O(b^d) O(bd) (linear space)
monotonic)
27. Describe IDA* search algorithm giving suitable examples.
Ans: IDA* Search Algorithm (Iterative Deepening A*)
The IDA* (Iterative Deepening A*) search algorithm is a combination of two techniques:
1. Iterative Deepening Search (IDS): This is a depth-first search (DFS) variant that limits the
depth of exploration and iteratively deepens the search until the goal is found.
2. A* Search: This is an informed search that uses both the actual cost to reach a node
g(n)g(n) and a heuristic estimate h(n)h(n) to estimate the cost of reaching the goal.
IDA* combines the efficiency of depth-first search with the guidance of an admissible heuristic,
allowing it to find optimal solutions while reducing memory usage.
How IDA* Works:
● IDA* Algorithm performs depth-first search (DFS) with an iterative deepening approach, but
instead of just limiting the depth based on the number of nodes, it limits the search based on the
evaluation function f(n)=g(n)+h(n)f(n) = g(n) + h(n), where:
○ g(n)g(n) is the cost from the start node to node nn,
○ h(n)h(n) is the heuristic estimate from node nn to the goal.
● The algorithm starts by performing a DFS where the depth is limited by a threshold f(n)f(n), which
is the sum of g(n)g(n) and h(n)h(n). If the node’s f(n)f(n) exceeds the threshold, the algorithm
backtracks.
● Iterative Deepening: The algorithm iterates by increasing the threshold incrementally, allowing
deeper nodes to be expanded, until the goal is found.
Steps of IDA* Algorithm:
1. Start with an initial threshold T=h(start)T = h(start), which is the heuristic value of the
start node.
2. Perform a Depth-First Search (DFS), exploring nodes that satisfy f(n)≤Tf(n) \leq T, where
f(n)=g(n)+h(n)f(n) = g(n) + h(n).
○ If a node's f(n)f(n) exceeds the current threshold, backtrack.
○ If the goal is found, return the path.
3. If the goal is not found, increase the threshold TT to the minimum f(n)f(n) value of the
nodes that were pruned and repeat the search.
4. Continue this process until the goal is found.
Advantages of IDA* over A*:
● Space Efficiency: Unlike A*, which stores all expanded nodes in memory (requiring
O(bd)O(b^d) space), IDA* only stores nodes along the current search path, reducing
space complexity to O(b⋅d)O(b \cdot d), where bb is the branching factor and dd is the
depth of the solution.
● Optimality: IDA* is optimal if the heuristic h(n)h(n) is admissible (does not overestimate
the cost to reach the goal).
Time Complexity of IDA*:
● Time complexity is generally O(b^d), where bb is the branching factor and dd is the
depth of the solution.
● The search explores nodes in a depth-first manner, so the time complexity depends on
the number of times the threshold needs to be increased and the size of the search tree.
Space Complexity of IDA*:
● Space complexity is O(b \cdot d), which is much better than A* (which has space
complexity of O(bd)O(b^d)) because IDA* only needs to store the current path being
explored.
Example of IDA* Search:
Let’s consider a simple problem where we want to find the shortest path from a start state to a
goal state in a graph:
1. Nodes: A, B, C, D, E, G (where G is the goal node).
2. Edges: (A → B), (A → C), (B → D), (C → D), (D → E), (E → G).
3. Heuristic values:
○ h(A)=4h(A) = 4, h(B)=3h(B) = 3, h(C)=2h(C) = 2, h(D)=1h(D) = 1, h(E)=0h(E) = 0,
h(G)=0h(G) = 0.
Goal: Find the shortest path from A to G.
● Step 1: Start with an initial threshold T=h(A)=4T = h(A) = 4.
● Step 2: Perform DFS:
○ At AA: f(A)=g(A)+h(A)=0+4=4f(A) = g(A) + h(A) = 0 + 4 = 4, which is within the
threshold.
○ Move to BB: f(B)=g(B)+h(B)=1+3=4f(B) = g(B) + h(B) = 1 + 3 = 4, which is within
the threshold.
○ Move to DD: f(D)=g(D)+h(D)=2+1=3f(D) = g(D) + h(D) = 2 + 1 = 3, which is
within the threshold.
○ Move to EE: f(E)=g(E)+h(E)=3+0=3f(E) = g(E) + h(E) = 3 + 0 = 3, which is within
the threshold.
○ Move to GG: f(G)=g(G)+h(G)=4+0=4f(G) = g(G) + h(G) = 4 + 0 = 4, which is
within the threshold.
● Step 3: The goal node GG is found with f(G)=4f(G) = 4, and the optimal path is
A→B→D→E→GA \to B \to D \to E \to G.
Key Points of the Example:
● IDA* incrementally deepens the threshold based on the f(n)f(n) values, allowing it to
expand deeper nodes in subsequent iterations.
● The search stops as soon as the goal node is found, and the path returned is the optimal
one.
Comparison with A*:
● Memory: IDA* is more memory-efficient because it only needs to store nodes along the
current path, whereas A* stores all nodes in memory.
● Optimality: Both IDA* and A* are optimal if the heuristic is admissible.
● Performance: IDA* can be slower than A* in practice because it may require more
iterations and re-expansion of nodes as the threshold increases. However, IDA* can be
very useful when memory is a major constraint.
28. Explain hill climbing algorithm with example. What are its limitations?
Ans: Hill climbing is a simple local search algorithm used for optimization problems. It starts with an
arbitrary solution to the problem and iteratively makes small changes to the current solution. At each
step, it moves to the neighbor that improves the solution, with the goal of reaching the peak
(maximum) or valley (minimum) of the objective function.
Key Concepts:
● Initial State: Start from an arbitrary initial solution.
● Successor Function: Defines the set of possible moves from the current state.
● Objective Function: This function is used to evaluate how good a state is compared to
others. The objective is to find the peak (or valley) of this function.
● Next Move: At each step, choose the neighbor (successor) that improves the solution
(according to the objective function).
Working of Hill Climbing Algorithm:
1. Start: Choose an arbitrary starting solution (state).
2. Evaluate: Evaluate the objective function of the current state.
3. Move: Generate all the neighboring states and evaluate their objective function values.
4. Select: Choose the neighbor that maximizes (or minimizes) the objective function and
move to that neighbor.
5. Repeat: Repeat the process until a stopping condition is met (usually when no neighbor
improves the solution or a predefined number of steps have been reached).
Hill Climbing Variants:
1. Simple Hill Climbing: Evaluates one neighbor at a time. If the neighbor has a better
objective function value, move to that state.
2. Steepest-Ascent Hill Climbing: Evaluates all neighbors and moves to the one with the
best (maximum or minimum) objective function value.
3. Stochastic Hill Climbing: Chooses a random neighbor to evaluate and proceeds with it if
it improves the objective function.
Example:
Consider a simple optimization problem where the objective is to find the maximum value of a
function f(x)f(x), which represents the height of a hill (e.g., maximizing profit, minimizing cost,
etc.). The state space is one-dimensional (the values of xx).
Objective Function:
Let the objective function be:
f(x)=−(x2−10x+25)=−(x−5)2+25f(x) = -(x^2 - 10x + 25) = -(x - 5)^2 + 25
This is a quadratic function with a peak at x=5x = 5 (the maximum value).
Steps of the Algorithm:
1. Start with an initial state: Suppose the initial state is x=2x = 2.
2. Evaluate: Evaluate f(2)=−(2−5)2+25=−9+25=16f(2) = -(2 - 5)^2 + 25 = -9 + 25 = 16.
3. Generate neighbors: Consider two neighbors: x=3x = 3 and x=1x = 1.
4. Evaluate neighbors:
○ f(3)=−(3−5)2+25=−4+25=21f(3) = -(3 - 5)^2 + 25 = -4 + 25 = 21
○ f(1)=−(1−5)2+25=−16+25=9f(1) = -(1 - 5)^2 + 25 = -16 + 25 = 9
5. Move to the best neighbor: Since f(3)=21f(3) = 21 is better than f(1)=9f(1) = 9, move to x=3x = 3.
6. Repeat the process: The algorithm continues in this manner, evaluating neighbors and moving
toward the direction with the highest objective function value.
Eventually, the algorithm will reach x=5x = 5, where no further improvement is possible, and
the algorithm stops.
Limitations of Hill Climbing:
1. Local Maximum: Hill climbing is prone to getting stuck in local maxima (or minima in the case of a
minimization problem). If the algorithm reaches a peak that is higher than its neighbors but is not
the global peak, it will stop there, even though a higher peak might exist elsewhere.
○ Example: If there is a local peak at x=3x = 3, the algorithm will stop there because f(3)>f(2)f(3) > f(2)
and f(4)f(4), even though x=5x = 5 is the global maximum.
2. Plateau: The algorithm can get stuck on a plateau, a flat area where neighboring states have the same
objective function value. Since hill climbing only moves to a better state, it cannot move off the
plateau and may fail to progress.
○ Example: If there are several states with the same objective function value (e.g., all states between
x=4x = 4 and x=6x = 6), the algorithm might not know which direction to go.
3. Ridges: Hill climbing is inefficient when trying to solve problems that require "climbing" along a
ridge (a path that gradually ascends), as it may move off the ridge due to poor neighboring states.
4. Greedy Approach: Hill climbing is a greedy algorithm because it only looks one step ahead and
makes decisions based on local information. This can lead to suboptimal solutions.
5. No Backtracking: Hill climbing does not remember its previous states, which means it does not
backtrack to try alternative solutions. If a path leads to a dead end or local maximum, the algorithm
cannot explore other paths.
6. Sensitive to Initial State: The final solution may depend on the starting state. A poor initial state may
lead to suboptimal results or getting stuck in a local optimum.
Improving Hill Climbing:
To overcome some of the limitations of basic hill climbing, various enhancements can be
applied:
● Simulated Annealing: This algorithm introduces randomness, allowing the possibility of
moving to a worse state temporarily, which can help escape local maxima.
● Genetic Algorithms: These algorithms use populations of solutions and genetic
operations (such as crossover and mutation) to explore a larger part of the search space.
● Random Restart Hill Climbing: This method runs hill climbing multiple times from
different starting points and picks the best solution.
29. What are the problems/frustrations that occur in hill climbing technique? Illustrate with an
example.
Ans: While Hill Climbing is a simple and intuitive optimization algorithm, it has several frustrations or
problems that can limit its effectiveness, especially in complex search spaces. These problems often lead
to suboptimal solutions or a failure to find the global optimum.
Here are some of the key problems/frustrations in Hill Climbing:
1. Local Maximum:
A local maximum occurs when the algorithm reaches a peak where all neighboring states have a
lower objective value, but this peak is not the global maximum. Hill climbing, being a greedy
algorithm, will stop when it reaches a local maximum, even though a higher peak (global
maximum) exists elsewhere.
Example:
Consider the function f(x)=−(x−3)2+10f(x) = -(x - 3)^2 + 10, which has a local maximum at x=3x
= 3 and a global maximum at x=7x = 7.
● The hill climbing algorithm might start at x=2x = 2, and move to x=3x = 3, where the
function value is f(3)=10f(3) = 10.
● However, there is a higher peak at x=7x = 7, but the algorithm will stop at x=3x = 3 since
f(3)=10f(3) = 10 is greater than the function values of its neighbors f(2)=9f(2) = 9 and
f(4)=9f(4) = 9.
The algorithm is stuck at the local maximum and cannot find the global maximum.
2. Plateau:
A plateau is an area in the search space where several neighboring states have the same
objective function value. On a plateau, the algorithm cannot determine which direction to move,
leading to stagnation or lack of progress.
Example:
Consider the function f(x)=−∣x−3∣+5f(x) = -|x - 3| + 5, which has a plateau from x=2x = 2 to
x=4x = 4, where the function value is constant (i.e., f(x)=5f(x) = 5).
● If the algorithm starts at x=3x = 3, it has no way to decide whether to move left or right,
since both neighboring states f(2)f(2) and f(4)f(4) have the same value 55.
● The algorithm will get stuck on the plateau, unable to make progress until it finds a state
with a better objective function value.
Plateaus are common in real-world optimization problems and can frustrate the search for the
optimal solution.
3. Ridge (Basin):
A ridge or basin refers to a path in the search space where the algorithm might make progress in
one direction but can easily stray off the optimal path if it does not have sufficient foresight to
evaluate broader search areas.
Example:
Consider a ridge function, where the optimal solution lies along a narrow "ridge" in the search
space. The hill climbing algorithm may move to a local peak along the ridge, but if it encounters
a side direction with a better function value, it may move away from the ridge and miss the
global optimum.
● Imagine a landscape where the highest peak is narrow and difficult to navigate. If the
algorithm only evaluates the immediate neighbors and doesn't have the global view, it
might miss the optimal solution and end up at a suboptimal peak.
This problem is common when the solution is not a single point but lies along a path or narrow
region.
4. No Solution or Stagnation:
Sometimes, the algorithm may get stuck in a state where no better state exists. This could be
because the initial state is already the best possible state (e.g., the objective function cannot be
improved further), or the algorithm fails to find a path to improvement due to the limited local
information.
Example:
Imagine a problem where the objective function values are fixed, and there are no upward
slopes to climb from the initial state. For example:
● If the starting point is already the global optimum or there are no higher function values
to explore, the algorithm will stop immediately.
● The algorithm might also stagnate in a flat region where all neighboring states have
equal or worse objective function values.
In such cases, the algorithm will terminate without progressing toward an optimal solution.
5. Sensitive to Initial State:
Hill climbing is highly sensitive to the initial state from which it starts the search. Different
starting points may lead to different local maxima, which could prevent finding the global
optimum.
Example:
Consider a function with multiple peaks and valleys, like a multi-modal function. The hill
climbing algorithm may start at a point near a local maximum, which prevents it from
discovering a better solution elsewhere.
● If the algorithm starts at a point near a local maximum, it will only converge to that local
maximum.
● If a different initial state is chosen, the algorithm might find a different, possibly better,
local maximum or even the global optimum.
The initial guess plays a crucial role in determining the success or failure of the algorithm.
6. Lack of Global View:
Hill climbing only considers immediate neighbors and makes decisions based on local
information. It lacks a global view of the search space, so it may miss better solutions that lie
beyond the local neighborhood.
Example:
If the search space is very large or has many local optima, hill climbing may miss areas that are
far from the current state but may offer a better solution. The algorithm will fail to "look ahead"
at solutions that are not in the immediate vicinity.
Summary of Hill Climbing Frustrations:
1. Local Maxima: The algorithm can get stuck at a local peak, unable to find the global optimum.
2. Plateaus: The algorithm may stop moving if it encounters a plateau with no improvement in
neighboring states.
3. Ridges: Narrow peaks or basins may be hard to navigate, causing the algorithm to miss the optimal
solution.
4. No Solution: The algorithm may terminate prematurely if no better states are found, even if a
solution exists elsewhere.
5. Sensitive to Initial State: Different starting points can lead to different results, making the
algorithm's performance unpredictable.
6. Lack of Global View: Hill climbing cannot evaluate the global landscape and may miss better
solutions far from the current state.
Potential Solutions to Hill Climbing Limitations:
1. Random Restart Hill Climbing: Run hill climbing multiple times with different initial states and
take the best result.
2. Simulated Annealing: Allow the algorithm to occasionally move to worse states to escape local
maxima and explore more of the search space.
3. Genetic Algorithms: Use a population of solutions and genetic operators to explore the search space
more thoroughly.
30. Write a short note on genetic algorithms.
Ans: Genetic Algorithms (GAs) are a class of optimization algorithms inspired by the process of natural
selection and evolution in biological organisms. They are part of the evolutionary algorithm family and
are commonly used to find approximate solutions to optimization and search problems, especially
when the search space is large, complex, and poorly understood.
Genetic algorithms simulate the process of natural evolution, where the fittest individuals are
selected for reproduction to produce the offspring of the next generation. Over successive
generations, the population evolves and potentially converges toward an optimal or
near-optimal solution.
Key Concepts of Genetic Algorithms:
1. Population: A set of candidate solutions (individuals) to the problem. Each individual is often
represented as a chromosome (a string of genes).
2. Chromosomes: These represent possible solutions in the search space. A chromosome is usually
represented as a binary string, but other representations (such as real numbers) can also be used.
3. Genes: The elements of the chromosome that represent features or parameters of the solution.
4. Fitness Function: A function that evaluates the quality or fitness of a solution (chromosome). The
goal is to maximize or minimize this function, depending on the problem.
5. Selection: The process of choosing individuals from the population to create the next generation.
The selection is usually based on the fitness of individuals—more fit individuals are more likely to
be selected.
6. Crossover (Recombination): A genetic operator that combines the genetic information of two parent
solutions to produce offspring. The idea is to "mix" the genetic material of two parents to create a
new solution.
7. Mutation: A genetic operator that introduces random changes in an individual's genes to maintain
diversity within the population. Mutation helps prevent premature convergence to suboptimal
solutions.
8. Replacement: The process of replacing the old population with the new generation (offspring).
Working of Genetic Algorithm:
1. Initialization: Start with an initial population of individuals (solutions), which can be generated
randomly or heuristically.
2. Selection: Evaluate the fitness of each individual using the fitness function. Select individuals with
higher fitness to act as parents for the next generation.
3. Crossover: Apply crossover (recombination) to pairs of selected parents to create new offspring.
This step combines the genetic material of the parents.
4. Mutation: Apply mutation to the offspring with a small probability. This introduces small random
changes to ensure diversity in the population and avoid getting stuck in local optima.
5. Replacement: Replace the old population with the new offspring population.
6. Termination: Repeat the process until a stopping condition is met, such as a maximum number of
generations, a satisfactory solution is found, or there is no significant improvement over time.
Example:
Consider an optimization problem where the goal is to maximize a function f(x)f(x), where xx is
a binary string representing the solution. Here's a simplified overview of how GAs would solve
this problem:
1. Initialization: Start with a random population of binary strings (e.g., 101010, 110110, 000111).
2. Fitness Evaluation: Calculate the fitness of each individual (binary string) by evaluating the
function f(x)f(x). For example, if f(x)=f(x) = number of 1s in xx, the fitness of 101010 is 3.
3. Selection: Choose individuals with higher fitness for the next generation.
4. Crossover: Combine two parents to create new offspring. For example, crossover between 101010
and 110110 might produce 111010.
5. Mutation: Apply a mutation to introduce random changes. For example, the binary string 111010
might mutate to 111000 by flipping one bit.
6. Replacement: Replace the old population with the new offspring, and repeat the process for several
generations.
7. Termination: Stop when a solution that satisfies the criteria (such as the maximum number of 1s) is
found, or after a predetermined number of generations.
Advantages of Genetic Algorithms:
● Global Search: GAs are capable of exploring a large search space and can avoid getting stuck in
local optima.
● Adaptability: They can be applied to a wide range of problems, including optimization, machine
learning, and combinatorial problems.
● Parallelism: GAs are naturally parallel, as multiple solutions (individuals) can be evaluated and
evolved simultaneously.
● Flexibility: They can be used for both discrete and continuous optimization problems and work
well even when the problem's structure is unknown.
Limitations of Genetic Algorithms:
● Computationally Expensive: GAs require a large number of evaluations of the fitness function,
which can be computationally costly for complex problems.
● Convergence Time: GAs may take many generations to converge to a good solution, especially for
large search spaces.
● Premature Convergence: Without proper diversity (controlled mutation rates), GAs can converge to
suboptimal solutions early in the search process.
● Parameter Sensitivity: The performance of a GA is sensitive to parameters like population size,
mutation rate, and crossover rate, which need to be tuned for optimal performance.
Applications of Genetic Algorithms:
1. Optimization Problems: GAs are widely used for solving complex optimization problems, such as
the traveling salesman problem, vehicle routing, and job scheduling.
2. Machine Learning: GAs are applied to feature selection, neural network training, and evolving
genetic programs.
3. Engineering Design: GAs are used in structural design, circuit design, and aerodynamic design
problems.
4. Game Playing: GAs are used in evolving strategies for game-playing agents or simulations of
evolutionary processes in artificial life.
5. Robotics: GAs are employed in robot path planning and robot control.
31. Explain how genetic algo can be used to solve a problem by taking a suitable example?
Ans:This problem is a typical optimization problem where the goal is to select a subset of items with
given weights and values to maximize the total value, subject to a constraint on the total weight.
Knapsack Problem:
● Objective: Maximize the total value of selected items.
● Constraint: The total weight of the selected items must not exceed a given capacity of the
knapsack.
Let’s assume we have the following items:
Item Weight Value
A 3 4
B 4 5
C 5 7
D 6 8
E 7 10
And the knapsack capacity is 15.
Steps to Solve Using Genetic Algorithm:
1. Representation of Solutions (Chromosome Design):
Each individual solution will be represented by a binary string (chromosome), where each bit
represents whether an item is selected (1) or not selected (0). For example:
● Chromosome: 10101
This means that items A, C, and E are selected (1) and items B and D are not selected (0).
Each chromosome has a length equal to the number of items, and each gene (bit) corresponds to
a specific item. The value of each bit (1 or 0) indicates whether the item is selected or not.
2. Initialize Population:
We start by randomly generating an initial population of several chromosomes (solutions). For
example, the population might look like this:
Each of these chromosomes represents a potential solution to the problem.
3. Fitness Function:
We define the fitness function based on the total value of the selected items, but we also need to
ensure the weight constraint is satisfied. The fitness function can be defined as:
● Calculate the total weight and total value of the items selected by a chromosome.
● If the total weight exceeds the knapsack capacity, assign a low fitness value (since it's an
invalid solution).
● Otherwise, the fitness value is the total value of the selected items.
Let’s calculate the fitness for each chromosome in the population:
For Chromosome 1 (10101):
● Items selected: A, C, E (weights 3, 5, and 7 respectively; values 4, 7, and 10).
● Total weight = 3 + 5 + 7 = 15 (within capacity).
● Total value = 4 + 7 + 10 = 21.
● Fitness = 21.
For Chromosome 2 (01110):
● Items selected: B, C, D (weights 4, 5, and 6 respectively; values 5, 7, and 8).
● Total weight = 4 + 5 + 6 = 15 (within capacity).
● Total value = 5 + 7 + 8 = 20.
● Fitness = 20.
4. Selection:
We select individuals based on their fitness. The higher the fitness value, the higher the chance
an individual has of being selected to become a parent for the next generation. Several selection
methods can be used, such as roulette wheel selection or tournament selection.
Let’s assume we use roulette wheel selection, where individuals with higher fitness values have
a higher probability of being selected.
5. Crossover (Recombination):
After selection, we apply crossover to generate offspring. Crossover combines the genes of two
parents to create new offspring. A commonly used method is single-point crossover, where two
parent chromosomes exchange genetic material at a randomly chosen crossover point.
For example:
● Parent 1: 10101
● Parent 2: 01110
If we perform single-point crossover at position 3:
● Offspring 1: 10110 (first part from Parent 1, second part from Parent 2).
● Offspring 2: 01101 (first part from Parent 2, second part from Parent 1).
6. Mutation:
To introduce diversity and avoid premature convergence, we apply mutation. Mutation
randomly flips some bits in the chromosome. For example, if an offspring has a chromosome
10110, a mutation might flip the second bit to get 11110.
The mutation rate is typically low (e.g., 1% to 5%), to prevent too much disruption of good
solutions.
7. Replacement:
After generating offspring using crossover and mutation, we replace the old population with
the new one. This can be done using different strategies, such as elitism (keeping the best
individuals) or generational replacement (replacing the entire population).
8. Termination:
The algorithm repeats the selection, crossover, mutation, and replacement steps for several
generations until one of the following stopping criteria is met:
● The fitness reaches an acceptable value (e.g., the maximum value).
● A maximum number of generations is reached.
● There is no significant improvement in the population over multiple generations.
Example Evolution of Population:
Let’s assume the following generations:
● Generation 1 (Initial Population):
○ Chromosome 1: 10101 (Fitness = 21)
○ Chromosome 2: 01110 (Fitness = 20)
○ Chromosome 3: 11100 (Fitness = 18)
○ Chromosome 4: 10011 (Fitness = 16)
● Generation 2 (After Selection, Crossover, and Mutation):
○ Chromosome 1: 10101 (Fitness = 21)
○ Chromosome 2: 01110 (Fitness = 20)
○ Chromosome 3: 11110 (Fitness = 19)
○ Chromosome 4: 10100 (Fitness = 18)
After several generations, the algorithm will converge to the optimal or near-optimal solution.
Solution:
The optimal solution is selecting items A, C, and E, which have the maximum value of 21
without exceeding the knapsack capacity. The final population will likely converge to this
optimal solution after several generations.
32. Draw game tree of Tic-tac-toe problem.
Ans: A game tree is a tree structure used to represent the possible moves in a game. Each node in the
tree represents a possible state of the game, and the edges represent the moves made by the players.
Let’s consider the Tic-Tac-Toe problem, where we have a 3x3 grid and two players: X and O. The
players take turns, starting with X, and the game ends when one player wins or there’s a draw.
We’ll draw a simplified game tree for the first few moves in a Tic-Tac-Toe game.
Step 1: Initial Board State
The game starts with an empty 3x3 board. Player X makes the first move. The root node of the
tree represents this initial state.
Initial State (Empty Board)
----------------
| | | |
| | | |
| | | |
----------------
Step 2: Player X Makes a Move
Player X chooses a position, for example, the center. The child nodes represent all the possible
moves Player O can make in response.
After Player X's Move (Center):
-----------------
| | | |
| |X| |
| | | |
-----------------
Child nodes represent all O's possible moves (remaining empty spots).
Step 3: Player O Makes a Move
Player O now chooses a spot (e.g., top-left corner). The child nodes represent X’s possible moves
in response.
After Player O's Move (Top-left corner):
-----------------------------
|O| | |
| |X | |
| | | |
-----------------------------
Child nodes represent all X's possible moves.
Step 4: Player X Makes a Move
Player X chooses the top-right corner.
After Player X's Move (Top-right corner):
-----------------------------
|O| |X|
| |X| |
| | | |
-----------------------------
Child nodes represent all O's possible moves.
Game Tree Structure
The game tree for Tic-Tac-Toe branches out from the root, with each player making a move in
each level. The tree can grow exponentially, but we will focus only on the initial few moves to
demonstrate its structure.
Here is a simplified representation of the game tree’s structure (showing just the first two
levels):
Key Points in the Game Tree:
● The root represents the initial state of the board.
● X and O alternate turns in the game tree, with each player choosing one of the available
spots.
● Each level represents a player's turn, and the tree expands as each move is made.
● The game tree includes all possible combinations of moves and states, which are
explored until a win condition (three X's or O's in a row) is met, or all moves have been
played (a draw).
● The depth of the game tree corresponds to the number of moves played, and the game
can last a maximum of 9 moves.