Uninformed & Informed State Space Search
State Space Formalism & Uninformed Search Strategies
Open Full Lesson →Uninformed search explores state spaces without domain-specific heuristics. Breadth-First Search (BFS) is complete and optimal for uniform step costs but consumes exponential memory O(b^d). Depth-First Search (DFS) uses minimal memory O(b*m) but is incomplete on infinite graphs. Uniform Cost Search (UCS) is optimal for general non-negative step costs. Iterative Deepening Search (IDS) combines BFS completeness and optimality with DFS linear memory efficiency.
Must-Remember Principles:- —Search Problem Formulation: 5-tuple: Initial State s_0, Actions(s), Transition Model Result(s, a), Goal Test Goal(s), Path Cost c(s, a, s').
- —Branching factor b = maximum number of successors of any node; d = depth of shallowest goal; m = maximum depth of state space.
- —BFS Complexity: Time = O(b^d); Space = O(b^d) (stores entire frontier); Complete = Yes (if b is finite); Optimal = Yes (if step costs are equal).
- —DFS Complexity: Time = O(b^m); Space = O(b*m) (linear space); Complete = No (can loop infinitely on cyclic/infinite paths); Optimal = No.
- —Uniform Cost Search (UCS): Expands node with lowest path cost g(n); Time = O(b^(1 + floor(C* / epsilon))); Space = O(b^(1 + floor(C* / epsilon))); Optimal = Yes (for step costs >= epsilon > 0).
- —Iterative Deepening Search (IDS): Successive depth-limited searches from depth 0, 1, 2, ... d. Time = O(b^d); Space = O(b*d); Complete = Yes; Optimal = Yes (for uniform step costs).
Critical Pitfalls & Exam Traps:- ×In BFS, the Goal Test is applied when a node is GENERATED (placed on frontier), NOT when expanded. In UCS, the Goal Test MUST be applied when a node is EXPANDED (popped from frontier) to guarantee optimality!
- ×Do not assume IDS repeats too much work: the ratio of states generated in IDS compared to BFS is at most b / (b - 1). For b = 10, IDS has only ~11% overhead while saving gigabytes of RAM.
- ×If step costs are zero or negative, UCS can loop indefinitely or fail to find optimal paths.
Uninformed & Informed State Space Search
State Space Search, UCS & A* Heuristic Admissibility
Open Full Lesson →A* Tree Search is optimal if heuristic h(n) is ADMISSIBLE (0 <= h(n) <= h*(n)). A* Graph Search is optimal if h(n) is CONSISTENT / MONOTONIC (h(n) <= c(n, a, n') + h(n')). Consistency implies admissibility, but the converse is not generally true. If h2(n) >= h1(n) for all n and both are admissible, h2 dominates h1 and expands a subset of nodes.
Must-Remember Principles:- —A* Evaluation Function: f(n) = g(n) + h(n), where g(n) is exact cost from start to n, and h(n) is estimated cost from n to goal.
- —Admissibility Condition (Tree Search): 0 <= h(n) <= h*(n) for all n, where h*(n) is the true optimal cost from n to nearest goal.
- —Consistency / Monotonicity Condition (Graph Search): h(n) <= c(n, a, n') + h(n') for every transition from n to n' with action a.
- —Monotonicity of f-values: Consistency implies f(n') = g(n') + h(n') = g(n) + c(n, a, n') + h(n') >= g(n) + h(n) = f(n) (non-decreasing along any path).
- —Heuristic Dominance: If h2(n) >= h1(n) for all states n, then A* using h2 never expands more nodes than A* using h1 (except possibly tie-breaking).
- —Memory-Bounded Variants: IDA* (Iterative Deepening A*, uses f-cost contour cutoffs with O(b*d) space); RBFS (Recursive Best-First Search, tracks alternative backup f-values).
Critical Pitfalls & Exam Traps:- ×A heuristic that overestimates even once (h(n) > h*(n) for a single node n) is NOT admissible and can cause A* to return a strictly sub-optimal path!
- ×Admissibility is SUFFICIENT for Tree Search optimality, but NOT for Graph Search! Graph Search requires Consistency to avoid sub-optimal re-expansion bugs.
- ×Straight-line Euclidean distance h_SLD is always consistent for physical road navigation because Euclidean metric satisfies the triangle inequality.
Local Search & Constraint Satisfaction Problems (CSP)
Local Search Optimization: Hill Climbing & Simulated Annealing
Open Full Lesson →Local search operates using a single current state rather than maintaining frontiers, using minimal O(1) memory. Hill Climbing greedily climbs uphill but gets trapped in local maxima, plateaus, and ridges. Simulated Annealing escapes local maxima by accepting downhill moves with Metropolis probability P = exp(Delta E / T), where temperature T decreases according to an annealing schedule. Genetic Algorithms combine sexual recombination (crossover) with random mutation.
Must-Remember Principles:- —Hill Climbing (Greedy Local Search): s <- argmax_{s' in Neighbors(s)} f(s'). Halts when no neighbor has a higher objective value.
- —Simulated Annealing Metropolis Acceptance Probability: If Delta E = f(s') - f(s) > 0 (improvement), move is accepted unconditionally. If Delta E <= 0 (downhill move), accepted with probability P = exp(Delta E / T).
- —Temperature Schedule T: High T (early) -> P approx 1 (random walk, broad exploration); Low T (late) -> P approx 0 (pure greedy hill climbing, fine convergence).
- —Annealing Convergence Theorem: If schedule lowers T slow enough (e.g. logarithmic cooling T(t) = c / log(1 + t)), Simulated Annealing is guaranteed to converge to the global optimum.
- —Genetic Algorithm Pipeline: Population -> Fitness Function -> Selection (Roulette Wheel / Tournament) -> Crossover (Recombination) -> Mutation (Random bit flip).
Critical Pitfalls & Exam Traps:- ×In Simulated Annealing, Delta E is negative for a bad/downhill move: Delta E = f(neighbor) - f(current) < 0. Thus exp(Delta E / T) is always a probability strictly between 0 and 1.
- ×A Plateau is a flat area where all neighbors have the identical value; a Ridge is an ascending sequence of local maxima where uphill steps require diagonal moves not permitted by single-variable steps.
Local Search & Constraint Satisfaction Problems (CSP)
Constraint Satisfaction Problems & The AC-3 Arc Consistency Algorithm
Open Full Lesson →A Constraint Satisfaction Problem (CSP) represents states as variable-value assignments subject to constraints. Arc Consistency (AC-3) prunes domain values that have no valid support, running in O(c * d^3) time for c binary constraints and maximum domain size d. Backtracking search integrates MRV (Minimum Remaining Values / Most Constrained Variable), Degree heuristic (tie-breaker), and LCV (Least Constraining Value) to solve CSPs efficiently.
Must-Remember Principles:- —CSP Definition: Triplet (X, D, C) where X = {X1, ..., Xn} variables, D = {D1, ..., Dn} domains, C = {C1, ..., Cm} constraints.
- —Arc Consistency Definition: Directed arc Xi -> Xj is consistent if for EVERY value x in Di, there exists at least one value y in Dj that satisfies the binary constraint between Xi and Xj.
- —AC-3 Time Complexity: O(c * d^3), where c is number of binary constraints (edges in constraint graph) and d is maximum domain size.
- —MRV Heuristic (Variable Selection): Choose the variable with the FEWEST remaining legal values in its domain ('fail-first' principle).
- —Degree Heuristic (Tie-breaker): Choose the variable involved in the LARGEST number of constraints with other unassigned variables.
- —LCV Heuristic (Value Selection): Choose the value that rules out the FEWEST choices for neighboring unassigned variables ('fail-last' principle).
Critical Pitfalls & Exam Traps:- ×Arc Consistency is DIRECTIONAL! The arc Xi -> Xj is consistent if every value of Xi has a partner in Xj. This does NOT automatically mean Xj -> Xi is consistent!
- ×When a value is deleted from Di during AC-3, you MUST re-insert all incoming arcs Xk -> Xi (where Xk is a neighbor of Xi, k != j) back into the queue!
- ×AC-3 alone does NOT always find a complete solution: an arc-consistent CSP can still have NO valid solution (e.g. 3-coloring of K4 with 2 colors). Backtracking is still required.
Adversarial Search & Game Theory
Minimax Decision Trees & Alpha-Beta Pruning
Open Full Lesson →Alpha-Beta Pruning returns the identical Minimax value while pruning branches that cannot influence the final decision. A cutoff occurs the moment alpha >= beta. In optimal move ordering, Alpha-Beta evaluates O(b^(d/2)) leaves instead of O(b^d), effectively doubling the reachable search depth.
Must-Remember Principles:- —Minimax Value: V(s) = max_{a} V(Result(s, a)) for MAX node; min_{a} V(Result(s, a)) for MIN node; Utility(s) for terminal leaves.
- —Alpha (alpha): The highest utility choice found so far along the path for MAX (initialized to -infinity).
- —Beta (beta): The lowest utility choice found so far along the path for MIN (initialized to +infinity).
- —Pruning Condition: Prune remaining child subtrees as soon as alpha >= beta.
- —Node Complexity: Standard Minimax = O(b^d); Alpha-Beta with Best Ordering = O(b^(d/2)); Alpha-Beta with Worst Ordering = O(b^d).
- —Heuristic Evaluation Functions: Linearly weighted feature sum: Eval(s) = w1*f1(s) + w2*f2(s) + ... + wn*fn(s).
Critical Pitfalls & Exam Traps:- ×Alpha-Beta pruning changes WHICH nodes are evaluated, but NEVER alters the final Minimax value or root move choice!
- ×Remember that MAX updates alpha, and MIN updates beta. Alpha only increases; Beta only decreases.
- ×Pruned nodes are NEVER visited or evaluated. In numerical exam questions, count carefully which leaves were skipped.
Adversarial Search & Game Theory
Stochastic Games & Expectiminimax Decision Trees
Open Full Lesson →In games with chance (Backgammon, Monopoly, Poker), game trees include Chance Nodes in addition to MAX and MIN nodes. Expectiminimax calculates the expected value sum_{s'} P(s') * V(s') at chance nodes. Because expected value is linear, heuristic evaluation functions MUST be positive linear transformations of true expected utility.
Must-Remember Principles:- —Expectiminimax Value at Chance Node C: V(C) = sum_{s' in Outcomes(C)} P(s') * V(s').
- —Tree Node Sequence: MAX -> Chance -> MIN -> Chance -> MAX ...
- —Time Complexity of Expectiminimax: O(b^d * n^d), where b is branching factor, d is depth, and n is number of distinct chance outcomes.
- —Linearity Invariance: If evaluation function h(s) is transformed by positive affine transformation h'(s) = a * h(s) + b (a > 0), the optimal move choice is PRESERVED. Non-linear monotonic transformations do NOT preserve choices in expectiminimax!
Critical Pitfalls & Exam Traps:- ×In deterministic Minimax, any monotonic transformation preserves move choices. In Expectiminimax with chance nodes, ONLY positive linear (affine) transformations preserve move choices!
- ×Alpha-Beta pruning cannot prune chance nodes unless rigorous mathematical upper and lower bounds on leaf utilities are known.
Propositional & First-Order Logic Reasoning
Propositional Logic: Entailment, CNF & Forward/Backward Chaining
Open Full Lesson →Logical entailment KB |= alpha means that in every model where KB is true, alpha is also true (M(KB) subset of M(alpha)). CNF represents formulas as conjunctions of clauses (disjunctions of literals). A Definite clause has exactly one positive literal; a Horn clause has at most one positive literal. Forward and Backward Chaining determine entailment for Definite clauses in linear O(n) time.
Must-Remember Principles:- —Entailment Definition: KB |= alpha <=> (KB and ~alpha) is unsatisfiable.
- —Implication Equivalence: P -> Q <=> ~P or Q.
- —De Morgan's Laws: ~(P and Q) <=> ~P or ~Q; ~(P or Q) <=> ~P and ~Q.
- —Distributive Laws: P or (Q and R) <=> (P or Q) and (P or R).
- —Definite Clause: A disjunction of literals containing EXACTLY ONE positive literal (e.g., ~A or ~B or C <=> (A and B) -> C).
- —Horn Clause: A disjunction of literals with AT MOST ONE positive literal (includes Goal clauses with zero positive literals: ~A or ~B).
- —Forward Chaining (Data-Driven): Fires rules whose premises are satisfied in KB, adding heads to known facts until query is proven.
- —Backward Chaining (Goal-Driven): Works backwards from query, proving premises recursively; avoids inferring irrelevant facts.
Critical Pitfalls & Exam Traps:- ×Do not confuse Validity and Satisfiability: A sentence is Valid (Tautology) if true in ALL models. A sentence is Satisfiable if true in AT LEAST ONE model.
- ×Forward Chaining and Backward Chaining are complete ONLY for Knowledge Bases consisting entirely of Definite / Horn clauses. For general clauses, Resolution Refutation is required.
Propositional & First-Order Logic Reasoning
CNF Conversion, Skolemization, Unification & Resolution
Open Full Lesson →Resolution Refutation: To prove KB |= alpha, negate alpha (~alpha), add it to KB, convert all sentences to Clausal Normal Form (CNF), and apply the Resolution inference rule until the Empty Clause (box / contradiction) is derived. Unification finds the Most General Unifier (MGU) substitutions theta making two literals identical.
Must-Remember Principles:- —Resolution Rule: From clauses (L1 or C1) and (~L2 or C2), where Subst(theta, L1) == Subst(theta, L2), derive Resolvent: Subst(theta, C1 or C2).
- —CNF 6-Step Conversion: 1. Eliminate <-> and ->; 2. Move ~ inwards (De Morgan); 3. Standardize variables (rename apart); 4. Skolemize existential quantifiers; 5. Drop universal quantifiers; 6. Distribute OR over AND.
- —Skolemization Rule: Replace exists y P(y) with P(C) (Skolem Constant). If exists y lies inside scope of forall x1, ..., xk, replace y with Skolem Function f(x1, ..., xk).
- —Most General Unifier (MGU): The minimal substitution theta such that Subst(theta, p) == Subst(theta, q).
- —Occurs-Check: Variable x CANNOT unify with a term containing x (e.g., cannot unify x with f(x)).
Critical Pitfalls & Exam Traps:- ×Never use a Skolem constant when an existential quantifier is preceded by a universal quantifier! For example, forall x exists y Loves(x, y) becomes Loves(x, f(x)), NOT Loves(x, C).
- ×Resolution is Refutation-Complete (guaranteed to find a contradiction if one exists), but cannot be used to enumerate all valid theorems directly.
- ×Standardize variables apart before unifying clauses from different sentences so that identical variable names do not cause false conflicts.
Probabilistic Reasoning & Bayesian Networks
Bayesian Networks, Conditional Independence & D-Separation
Open Full Lesson →A Bayesian Network is a Directed Acyclic Graph (DAG) whose joint distribution factorizes as P(X1, ..., Xn) = prod_{i=1}^n P(Xi | Parents(Xi)). D-Separation determines conditional independence: A path is blocked if it contains an active non-collider that is conditioned on, OR a collider that is NOT conditioned on (and none of its descendants are conditioned on). A node is conditionally independent of all other nodes given its Markov Blanket (Parents + Children + Spouses).
Must-Remember Principles:- —Joint Distribution Factorization: P(X1, ..., Xn) = prod_{i=1}^n P(Xi | Parents(Xi)).
- —Chain Motif (X -> Y -> Z): X and Z are dependent marginally; INDEPENDENT given Y (P(Z | X, Y) = P(Z | Y)). Blocked when Y is observed.
- —Fork / Common Cause (X <- Y -> Z): X and Z are dependent marginally; INDEPENDENT given Y. Blocked when Y is observed.
- —Collider / V-Structure (X -> Y <- Z): X and Z are INDEPENDENT marginally; DEPENDENT given Y or any descendant of Y ('explaining away'). Blocked when Y and its descendants are NOT observed.
- —Markov Blanket of Node X: MB(X) = Parents(X) union Children(X) union Spouses(X) (other parents of X's children).
- —Parameter Counting: A Boolean node with k parents requires 2^k independent conditional probability parameters in its CPT.
Critical Pitfalls & Exam Traps:- ×Remember the Collider Inversion Rule: Conditioning on a node BLOCKS chains and forks, but OPENS (activates) colliders!
- ×Do not forget Spouses when computing the Markov Blanket: Other parents of X's children MUST be included in MB(X)!
Probabilistic Reasoning & Bayesian Networks
Exact & Approximate Inference in Bayesian Networks
Open Full Lesson →Inference in Bayesian Networks computes posterior probability P(Query | Evidence). Exact inference by Enumeration sums out hidden variables from the joint distribution in O(d^n) exponential time. Variable Elimination speeds this up by dynamic programming, storing intermediate factor products phi(X) and summing out one variable at a time. Approximate inference uses stochastic simulation (Prior Sampling, Rejection Sampling, Likelihood Weighting).
Must-Remember Principles:- —Query Formulation: P(X | E = e) = alpha * P(X, E = e) = alpha * sum_Y P(X, E = e, Y), where Y are hidden unobserved variables, and alpha is normalization constant 1 / P(E = e).
- —Variable Elimination Operations: 1. Factor Product: phi3(X, Y, Z) = phi1(X, Y) * phi2(Y, Z); 2. Factor Marginalization (Summing Out): phi'(X) = sum_Y phi(X, Y).
- —Computational Complexity: Exact inference in general Bayesian networks is NP-Hard (and #P-Hard). On polytrees (singly connected DAGs with no undirected loops), Variable Elimination runs in linear O(n) time.
- —Likelihood Weighting: Fixes evidence variables to their observed values and weights each generated sample by the likelihood of observed evidence: w = prod_{E_i in Evidence} P(E_i = e_i | Parents(E_i)). Avoids discarding samples.
Critical Pitfalls & Exam Traps:- ×Always remember to normalize by alpha = 1 / (P(X=true, e) + P(X=false, e)) at the final step when computing conditional probabilities!
- ×Variable Elimination complexity depends critically on the Elimination Ordering: a poor variable ordering creates giant intermediate factors with exponential state size.