Artificial Intelligence
2. Informed search: heuristics, greedy best-first search, A*
A heuristic function h(n) estimates the cost from state n to the nearest goal, using domain knowledge that uninformed search ignores entirely. Greedy best-first search always expands the frontier node with the lowest h(n) — fast in practice, since it heads straight toward what looks like the goal, but not optimal (a low-h(n) path can still be a long or expensive one overall) and not complete without extra care against loops. A* search instead expands the node with the lowest f(n) = g(n) + h(n), the sum of the cost already paid and the estimated cost still to come, balancing 'how far I've come' against 'how far I have left'.
3. Adversarial search: minimax and alpha-beta pruning
Minimax applies to a two-player, zero-sum, deterministic game of perfect information: it builds the game tree alternating a MAX player's turn and a MIN player's turn, assigns a value to each leaf (win/loss/draw, or a heuristic evaluation if the tree is cut off early), and backs those values up the tree — MAX picks the child of highest value at its turn, MIN the child of lowest value at its turn — so that the value at the root is the outcome both players get under the assumption that each plays optimally against the other.
Alpha-beta pruning explores the same game tree but cuts off any branch that provably cannot change the final decision, using two bounds carried down the search: α, the best value MAX can already guarantee, and β, the best value MIN can already guarantee. It computes exactly the same minimax value as full search while examining fewer nodes — in the best case, with a well-ordered tree, the effective branching factor is roughly halved, reducing the nodes examined from about bᵈ to about b^(d/2).
4. Logic: propositional and predicate
Propositional logic builds sentences from atomic propositions (each either true or false) combined with the connectives ¬, ∧, ∨, → and ↔. For n distinct atoms, a truth table enumerates all 2ⁿ possible assignments, against which a sentence is satisfiable if at least one assignment makes it true, valid (a tautology) if every assignment makes it true, and unsatisfiable if no assignment makes it true. A knowledge base KB entails a sentence α (written KB ⊨ α) exactly when α is true in every model — every assignment — in which KB itself is true.
First-order (predicate) logic adds objects, predicates over those objects, functions and two quantifiers — ∀ (for all) and ∃ (there exists) — letting it state facts propositional logic has no general way to express, such as 'every student passed some exam': propositional logic has only fixed atomic facts with no notion of objects or variables ranging over them, so it can encode one specific instance of that sentence but not the general quantified statement itself. Every propositional sentence is expressible in first-order logic as the special case of a predicate with no arguments, but not every first-order sentence reduces to a propositional one — first-order logic is strictly the more expressive of the two.
5. Reasoning under uncertainty: conditional independence, variable elimination, sampling
X is conditionally independent of Y given Z when P(X | Y, Z) = P(X | Z) — knowing Y adds nothing once Z is already known. This is what lets a joint distribution over many variables be represented compactly instead of as one table with an entry for every combination of every variable's values, which grows exponentially with the number of variables. A Bayesian network represents these independencies directly, as a directed acyclic graph in which each node's distribution is conditioned only on its parents — the graph's structure is itself the statement of which conditional independencies the model assumes, not merely a picture drawn alongside it.
Exact inference by variable elimination answers a probabilistic query by eliminating the non-query, non-evidence variables one at a time in a chosen order: for each variable being eliminated, it multiplies together only the factors (conditional-probability tables) that mention it, and sums (marginalises) that variable out of the product — cheaper, in general, than building and summing the full joint distribution table directly, since it never materialises the whole joint at once.
When exact inference becomes too expensive — which it typically does on large, densely connected networks — approximate inference through sampling estimates the query instead: it draws many samples consistent with the network's distribution and computes the answer from their observed frequencies rather than computing it exactly. Its accuracy improves only in the limit of enough samples, and it trades a guarantee of exactness for the ability to scale to networks where exact methods are simply infeasible.
Key takeaways
- BFS (FIFO queue) is complete and optimal with uniform step costs but exponential in memory; DFS (stack) is memory-linear but neither complete on an infinite space nor optimal; uniform-cost search generalises BFS's optimality to unequal step costs using a priority queue.
- An admissible heuristic (never overestimates) makes A* optimal; a consistent heuristic additionally guarantees A* never re-expands a node — and greedy best-first search, using h(n) alone, is fast but neither guarantee applies to it.
- Alpha-beta pruning computes the identical minimax value while examining fewer nodes — a well-ordered tree roughly halves the effective branching factor — and it never changes the final decision minimax would reach.
- A sentence being satisfiable (true in some model) does not make it valid (true in every model); first-order logic strictly extends propositional logic with quantifiers and objects, so every propositional sentence is a special case of a predicate one but not the reverse.
- Conditional independence is what a Bayesian network's graph structure directly encodes; variable elimination answers a query exactly by summing out variables one at a time in an order that decides its cost, and sampling trades that exactness for the ability to scale to networks exact methods cannot handle.
Practice questions (18)
Attempt each one before opening the answer. Every explanation names the tempting wrong option as well as the right one, because that is where marks are lost.
Breadth-first search holds the search frontier in which data structure?
Show answer
Answer: B — A FIFO queue
BFS expands frontier nodes in the order they were added, which is exactly what a FIFO queue gives — this is what makes it explore level by level.Depth-first search on an infinite state space, run with no depth limit, is
Show answer
Answer: C — neither complete nor optimal
DFS can descend forever down one infinite branch and never reach a goal that exists elsewhere, so it is not complete; even when it does terminate, it offers no guarantee of finding the shortest path.Uniform-cost search always expands the frontier node with the lowest
Show answer
Answer: B — cumulative path cost g(n) so far
Uniform-cost search always expands by lowest g(n) using a priority queue, which is what keeps it optimal even when step costs are unequal.A* search expands nodes in order of lowest
Show answer
Answer: C — f(n) = g(n) + h(n)
A* balances the cost already paid, g(n), against the estimated remaining cost, h(n), by expanding lowest f(n) = g(n) + h(n) first.A* search using tree search is guaranteed to find an optimal solution when its heuristic is
Show answer
Answer: B — admissible
Admissibility — never overestimating the true remaining cost — is the condition that guarantees A*'s optimality under tree search; consistency is a stronger condition needed for graph search's re-expansion guarantee.Greedy best-first search, unlike A*, expands nodes using
Show answer
Answer: B — h(n) alone
Greedy best-first search expands the node that looks closest to the goal by h(n) alone, ignoring the cost already paid to reach it — which is exactly why it can be fast but non-optimal.The minimax algorithm assumes a game that is
Show answer
Answer: B — two-player, zero-sum and deterministic, with perfect information
Minimax is built for exactly this class of game: two opposing players, a zero-sum payoff, deterministic transitions, and full visibility of the state for both players.Alpha-beta pruning, compared with plain minimax search on the same game tree,
Show answer
Answer: B — computes the identical minimax value while examining fewer nodes
Alpha-beta pruning skips only branches proven irrelevant to the final decision, so its result is always identical to full minimax search, just reached by examining fewer nodes.With a well-ordered game tree, alpha-beta pruning reduces the effective number of nodes examined from about bᵈ to about
Show answer
Answer: B — b^(d/2)
A well-ordered tree lets alpha-beta pruning cut the effective branching factor roughly in half, so the node count falls from about bᵈ to about b^(d/2) — a very different reduction from an additive or logarithmic one.A propositional-logic sentence that is true under every possible truth assignment is called
Show answer
Answer: B — valid (a tautology)
True in every model is exactly the definition of valid (a tautology); satisfiable only requires truth in at least one model, which is a weaker claim.Which of the following are true of propositional logic versus first-order (predicate) logic?
Show answer
Answer: A — First-order logic adds quantifiers and predicates over objects that propositional logic lacks; B — Every propositional-logic sentence can be expressed as a special case of a first-order sentence; D — First-order logic is strictly more expressive than propositional logic
Propositional logic has no objects or variables to quantify over, so it cannot state the general quantified fact — only first-order logic can, which is exactly why it is the strictly more expressive of the two.A Bayesian network's directed acyclic graph structure primarily encodes
Show answer
Answer: B — which conditional independence assumptions hold among the variables
The graph's edges (each node depending only on its parents) are themselves the statement of which conditional independencies the model assumes; the numerical probabilities are stored separately, in each node's conditional probability table.Exact inference by variable elimination answers a probabilistic query by
Show answer
Answer: B — marginalizing out non-query, non-evidence variables one at a time, multiplying only the factors that mention each
Variable elimination eliminates one variable at a time, multiplying only the factors that mention it and summing it out of that product — the sampling-based description in option 3 is what approximate inference does instead.Variable elimination's computational cost depends heavily on
Show answer
Answer: B — the elimination order chosen for the variables
A badly chosen elimination order can produce large intermediate factors, making the computation as expensive as the full joint distribution the method is meant to avoid.Approximate inference through sampling becomes preferable to exact inference mainly when
Show answer
Answer: B — exact inference such as variable elimination becomes too expensive on a large, densely connected network
Sampling trades away exactness for scalability, which is worthwhile exactly when exact methods become computationally infeasible on large, densely connected networks.Using A* with graph search and a heuristic that is admissible but NOT consistent, the guarantee that can fail is that
Show answer
Answer: B — a node, once expanded, may still need to be re-expanded after a cheaper path to it is found later
Admissibility alone still gives an optimal final answer, but without consistency graph search can find a cheaper path to an already-expanded node later on, forcing a re-expansion — consistency is exactly the stronger condition that rules this out.Which of the following are true of minimax and alpha-beta pruning?
Show answer
Answer: A — Minimax assumes optimal play from both players at every turn; C — Alpha-beta's best-case node reduction (to roughly b^(d/2)) assumes a well-ordered tree; D — Alpha-beta pruning still needs an evaluation function at cut-off depth, exactly as minimax does
Alpha-beta pruning always reaches the identical decision as full minimax on the same tree — the second option is the false one; the other three are standard, correct properties of the two algorithms.A Bayesian network shaped as a tree, where every variable has at most one parent, allows exact inference such as variable elimination to run in time that is
Show answer
Answer: B — linear in the number of variables
A tree-structured network's sparse, single-parent structure means variable elimination's intermediate factors stay small, giving linear-time inference — exactly the payoff of exploiting the network's actual structure that a badly ordered elimination on a dense network gives up.