Introduction to AI with Python
- 33Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
Define the four components of a search problem.
33 questions
- 1
Define the four components of a search problem.
Model answer
A search problem consists of an initial state, actions (a function mapping states to possible actions), a transition model (a function result(s, a) giving the next state), and a goal test.
Explanation
These components formally define the problem: where to start, what moves are possible, how moves change the state, and when a solution is reached.
- 2
Explain the difference between depth-first search and breadth-first search regarding the data structure used for the frontier.
Model answer
DFS uses a stack (LIFO), exploring the deepest node first; BFS uses a queue (FIFO), exploring the shallowest node first.
Explanation
The choice of frontier data structure determines the order in which nodes are expanded, affecting completeness and optimality.
- 3
What is the purpose of the explored set in graph search, and how does it prevent infinite loops?
Model answer
The explored set tracks states that have already been visited. When expanding a node, we only add neighbors that are not already in the frontier or explored set, preventing revisiting states and avoiding cycles.
Explanation
Without an explored set, algorithms could loop indefinitely when the graph contains cycles (e.g., bidirectional edges).
- 4
Under what conditions is A* search guaranteed to find an optimal solution?
Model answer
A* is optimal if the heuristic is admissible (never overestimates true cost) and consistent (satisfies the triangle inequality: h(n) ≤ c(n, n') + h(n')).
Explanation
Admissibility ensures the heuristic doesn't overestimate, and consistency ensures that the estimate doesn't worsen along a path, both necessary for optimality.
- 5
In the context of adversarial search, define the terms utility function and terminal test.
Model answer
Utility function assigns a numerical value to a terminal state (e.g., +1 for win, -1 for loss, 0 for draw). Terminal test checks if a state is terminal (game over).
Explanation
These are needed to evaluate game outcomes and to know when to stop searching in minimax.
- 6
Explain the minimax algorithm for two-player deterministic games.
Model answer
Minimax recursively computes the value of a state: if it's the max player's turn, choose the action with the highest min-value of the resulting state; if it's the min player's turn, choose the action with the lowest max-value.
Explanation
The algorithm assumes both players play optimally and propagates values from terminal states up the game tree.
- 7
What is alpha-beta pruning, and how does it improve minimax?
Model answer
Alpha-beta pruning eliminates branches in the game tree that cannot affect the final decision by maintaining two values: alpha (best for max) and beta (best for min). If a node's value is worse than current alpha or beta, the remaining branches are pruned.
Explanation
Pruning reduces the number of nodes evaluated, making the search more efficient without affecting the final result.
- 8
How does depth-limited minimax handle games with large state spaces?
Model answer
Depth-limited minimax stops searching after a fixed depth and uses an evaluation function to estimate the utility of non-terminal states.
Explanation
This is necessary for computationally intractable games like chess, where full tree search is impossible.
- 9
Define entailment in propositional logic and explain its relationship to inference.
Model answer
Entailment (α ⊨ β) means that in every model where α is true, β is also true. Inference is the process of deriving new sentences from old ones; a correct inference algorithm should only derive sentences that are entailed.
Explanation
Entailment is a semantic notion; inference is a syntactic process. A sound inference algorithm respects entailment.
- 10
What is a truth table and how is it used in model checking?
Model answer
A truth table lists all possible assignments of truth values to propositional symbols and shows the truth value of a sentence under each assignment. Model checking enumerates all models and checks if the knowledge base being true implies the query is true.
Explanation
Model checking is a simple but inefficient inference method; exhaustive enumeration over 2^n models.
- 11
List the five basic logical connectives used in propositional logic and give their symbols.
Model answer
Not (¬), And (∧), Or (∨), Implication (→), Biconditional (↔).
Explanation
These connectives allow the formation of complex logical sentences from propositional symbols.
- 12
Explain the resolution rule in propositional logic.
Model answer
The resolution rule states: if we have two clauses (P ∨ Q) and (¬P ∨ R), we can infer (Q ∨ R). The literals P and ¬P are complementary and are removed, leaving the disjunction of the remaining literals.
Explanation
Resolution is a single inference rule that is complete for refutation in propositional logic when combined with conjunctive normal form.
- 13
What is the Markov assumption in Markov chains?
Model answer
The Markov assumption states that the current state depends only on a finite fixed number of previous states (often just the immediately preceding state).
Explanation
This simplifies the model by assuming that the future is independent of the past given the present.
- 14
Define conditional probability and provide its formula.
Model answer
Conditional probability P(A|B) = P(A ∧ B) / P(B), where P(B) > 0. It is the probability of A given that B is true.
Explanation
This formula is fundamental for updating beliefs based on evidence.
- 15
What is Bayes' rule and why is it useful?
Model answer
Bayes' rule: P(B|A) = P(A|B) * P(B) / P(A). It allows computing the probability of a cause given an effect, which is often easier to estimate in reverse.
Explanation
It is widely used in AI for inference, especially when we have knowledge of the likelihood of evidence given a hypothesis.
- 16
Describe the structure of a Bayesian network.
Model answer
A Bayesian network is a directed acyclic graph where nodes represent random variables and edges represent conditional dependencies. Each node has a conditional probability table given its parents.
Explanation
The network compactly represents a joint probability distribution by exploiting conditional independencies.
- 17
What is the problem of inference in a Bayesian network?
Model answer
Inference is the problem of computing the probability distribution of a query variable given evidence (observed values of some variables). It often involves summing over hidden variables.
Explanation
Exact inference can be expensive; approximate methods like sampling are often used.
- 18
Explain the hill climbing algorithm for optimization.
Model answer
Hill climbing starts with a random state and repeatedly moves to the neighbor with the best value (highest for maximization, lowest for minimization) until no neighbor is better. It stops at a local optimum.
Explanation
It is a simple local search algorithm that can get stuck at local optima; variants include random restart and simulated annealing.
- 19
How does simulated annealing avoid getting stuck in local optima?
Model answer
Simulated annealing occasionally accepts worse moves with a probability that decreases over time (simulating a cooling temperature). This allows the algorithm to escape local optima early on and converge later.
Explanation
The probability of accepting a worse neighbor depends on the magnitude of the change and the current temperature.
- 20
Define a linear programming problem.
Model answer
A linear programming problem involves minimizing (or maximizing) a linear cost function subject to linear inequality and equality constraints, with variables taking real values.
Explanation
The objective and constraints are linear functions of the variables. Algorithms like simplex solve such problems efficiently.
- 21
What is a constraint satisfaction problem (CSP)?
Model answer
A CSP consists of variables, each with a domain of possible values, and constraints that restrict allowable combinations of values. A solution is an assignment of all variables satisfying all constraints.
Explanation
Many real-world problems (scheduling, Sudoku) can be formulated as CSPs.
- 22
Explain the concept of arc consistency and the AC-3 algorithm.
Model answer
Arc consistency for a variable X with respect to Y means that for every value in X's domain, there is some value in Y's domain that satisfies the binary constraint. AC-3 maintains a queue of arcs and repeatedly removes values that have no consistent option, propagating changes.
Explanation
Arc consistency reduces the search space and can sometimes solve a CSP without backtracking.
- 23
What is the difference between supervised and unsupervised learning?
Model answer
Supervised learning uses labeled input-output pairs to learn a function mapping inputs to outputs. Unsupervised learning uses unlabeled data to find patterns like clusters.
Explanation
Supervised tasks include classification and regression; unsupervised tasks include clustering and dimensionality reduction.
- 24
Describe the k-nearest neighbors algorithm for classification.
Model answer
K-nearest neighbors classifies a new data point by looking at the k closest training points (by some distance metric) and assigning the most common class among them.
Explanation
It is a simple, non-parametric method that can be effective with enough data.
- 25
What is a loss function, and give an example for regression.
Model answer
A loss function quantifies the error between predicted and actual values. For regression, the L2 loss (mean squared error) is common: (y_actual - y_pred)^2.
Explanation
Minimizing loss during training aims to improve model accuracy.
- 26
Explain overfitting and how it can be addressed.
Model answer
Overfitting occurs when a model fits the training data too closely, failing to generalize to new data. It can be addressed by regularization (adding complexity penalty), cross-validation, or using simpler models.
Explanation
Overfitting is a common pitfall; techniques like dropout in neural networks help prevent it.
- 27
What is a perceptron and what can it classify?
Model answer
A perceptron is a single artificial neuron that computes a weighted sum of inputs, adds a bias, and passes through an activation function (e.g., step function). It can only classify linearly separable data.
Explanation
Linear separability limits the perceptron; multilayer networks overcome this limitation.
- 28
How does gradient descent train a neural network?
Model answer
Gradient descent repeatedly computes the gradient of the loss function with respect to weights and updates weights in the direction that reduces loss: w = w - α * ∇L, where α is the learning rate.
Explanation
The gradient indicates the direction of steepest ascent; moving opposite minimizes loss.
- 29
What is a convolutional neural network (CNN) and what are its key components?
Model answer
A CNN is a neural network designed for grid-like data (e.g., images). Key components: convolutional layers (apply filters to extract features), pooling layers (reduce dimensionality), and fully connected layers.
Explanation
CNNs exploit spatial structure through local connectivity and weight sharing.
- 30
Explain the purpose of the attention mechanism in sequence-to-sequence models.
Model answer
Attention allows the decoder to focus on relevant parts of the input sequence when generating each output word. It computes a weighted sum of encoder hidden states, where weights reflect relevance.
Explanation
Attention improves performance on long sequences by alleviating the bottleneck of a single context vector.
- 31
What is a context-free grammar and how is it used in NLP?
Model answer
A context-free grammar is a set of rewriting rules that define the syntactic structure of a language. It consists of non-terminal symbols (e.g., NP, VP) and terminal symbols (words). Parsers use it to derive parse trees for sentences.
Explanation
Context-free grammars can model many syntactic structures but require manual rule creation.
- 32
Describe the Naive Bayes classifier for text classification.
Model answer
Naive Bayes applies Bayes' rule with the assumption that word occurrences are conditionally independent given the class. It computes P(class | document) ∝ P(class) ∏ P(word | class) and predicts the most likely class.
Explanation
Despite the naive independence assumption, it works well for tasks like spam detection and sentiment analysis.
- 33
What is the key idea behind word2vec for learning word embeddings?
Model answer
Word2vec learns vector representations of words such that words appearing in similar contexts have similar vectors. It does this by predicting a word from its context (CBOW) or the context from a word (skip-gram).
Explanation
Distributed representations capture semantic similarities; e.g., king - man + woman ≈ queen.

Ask anything
We've read this whole study set, so questions about it get the best answers.