Problem Solving and Heuristic Search Strategies in Artificial Intelligence
Foundations of Heuristic Search and Informed Search Strategies
Informed Search Paradigm:
- Unlike uninformed search algorithms that systematically inspect the state space without domain-specific guidance, informed search algorithms leverage problem-specific knowledge.
- This knowledge encompasses estimates of distance to the goal, accumulated path cost, and optimal traversal strategies, enabling the agent to prune unproductive paths and explore dramatically smaller portions of the search space.
- Informed search is particularly essential for large or infinite state spaces where uninformed exploration becomes computationally intractable.
Heuristic Functions:
- A heuristic function, denoted as , evaluates a state and produces an estimated cost of the cheapest path from state to a goal state.
- The value of the heuristic function is non-negative: for all states , with .
- Admissibility Condition:
- A heuristic is admissible if it never overestimates the true cost to reach the nearest goal state.
- Formally, , where is the heuristic estimate and is the true optimal cost from state to the goal.
- Admissible heuristics are inherently optimistic.
- Pure Heuristic Search:
- Represents the most basic form of heuristic search, expanding nodes solely based on their heuristic estimate , without considering the cost accumulated from the start state.
Greedy Best-First Search:
- Evaluates nodes using the evaluation function , selecting the node that appears closest to the goal state at that immediate moment.
- It combines features of breadth-first and depth-first search, operating with a priority queue prioritized by ascending values of .
- Data Structures:
OPENlist (frontier): contains all generated nodes awaiting expansion, sorted by .CLOSEDlist (explored set): stores all nodes that have already been expanded to prevent infinite loops and repeated work.- Algorithmic Execution Procedure:
- Step 1: Insert the initial start state into the
OPENlist. - Step 2: If the
OPENlist is empty, terminate and return failure. - Step 3: Remove the node from the
OPENlist with the minimal value of and append it to theCLOSEDlist. - Step 4: Expand node , generating all of its successor states.
- Step 5: For each successor, check if it satisfies the goal test. If any successor is a goal, terminate and return the solution path; otherwise, proceed to Step 6.
- Step 6: For each generated successor, compute . If the node is not present in either the
OPENorCLOSEDlist, insert it into theOPENlist. - Step 7: Return to Step 2.
- Theoretical Properties:
- Time Complexity: Worst-case time complexity is , where is the branching factor and is the maximum depth of the search space.
- Space Complexity: Worst-case space complexity is because all generated nodes are retained in memory.
- Completeness: Incomplete, even in finite state spaces, because it can become trapped in infinite loops like unguided depth-first search.
- Optimality: Non-optimal, as it may follow a path with low heuristic values that ultimately incurs a high total path cost.
- Greedy Best-First Search Worked Example:
- Consider the search graph with root state and goal state :

* **State Heuristic Values**:
*
*
*
*
*
*
*
*
*
*
* **Step-by-step Trace**:
* Initialization: `OPEN` = , `CLOSED` =
* Iteration 1: Expand , generating and . `OPEN` = , `CLOSED` =
* Iteration 2: Expand , generating and . `OPEN` = , `CLOSED` =
* Iteration 3: Expand , generating and . `OPEN` = , `CLOSED` =
* Iteration 4: Node has and is identified as the goal state. Terminate with success.
* **Final Path**:
* Resulting trajectory: 
A* Search Algorithm and Optimality Guarantees
- Formulation of A* Search:
- A* search evaluates nodes by integrating both the backward cost already incurred to reach the node and the estimated forward cost to reach the goal.
- Evaluation function:
- : Exact cost incurred to reach node from the initial start state.
- : Heuristic estimate of the cheapest path cost from node to a goal node.
- : Estimated total cost of the cheapest solution passing through node , often termed the fitness number.

A* Algorithmic Procedure:
- Step 1: Place the starting node into the
OPENlist with . - Step 2: If the
OPENlist is empty, terminate and return failure. - Step 3: Select and remove the node from
OPENhaving the minimal value of . If is a goal state, terminate with success and return the constructed path. - Step 4: Expand node , generate all of its successors , and place node into the
CLOSEDlist. - Step 5: For each successor :
- Compute and .
- If is neither in
OPENnor inCLOSED, add it toOPEN. - If already exists in
OPENorCLOSED, check if the newly calculated is strictly lower than its previous cost. If so, update its back-pointer to point to , update its stored and values, and if it was inCLOSED, return it toOPEN. - Step 6: Return to Step 2.
- Step 1: Place the starting node into the
Optimality and Completeness Conditions:
- Completeness: Guaranteed if the branching factor is finite and every step cost is strictly positive (bounded below by a fixed constant ).
- Optimality in Tree Search: Requires that is an admissible heuristic ().
- Optimality in Graph Search: Requires consistency (monotonicity):
- For every node and successor generated by action , .
- Consistency enforces that the -values along any path are monotonically non-decreasing, ensuring that the first time a state is expanded, the path to it is guaranteed to be optimal.
- Complexity Analysis:
- Time Complexity: , where is the depth of the optimal solution.
- Space Complexity: , because A* preserves all generated nodes in memory, which constitutes its principal practical computational bottleneck.
A* Search Worked Example:
- Given the following directed state space graph with action costs and heuristic table:

- State Heuristic Values:
- Edge Costs:
- Trace of Iterations:
- Initialization:
OPEN= ,CLOSED=
- Iteration 1:
- Expand . Successors are and :
- Path : ,
- Path : ,
OPEN= ,CLOSED=
- Iteration 2:
- Expand (lowest ). Successors are and :
- Path : ,
- Path : ,
OPEN= ,CLOSED=
- Iteration 3:
- Expand (lowest ). Successors are and :
- Path : ,
- Path : ,
OPEN= ,CLOSED=
- Iteration 4:
- Select path with minimal .
- State is the goal. Terminate with success.
- Optimal Solution Path:
- with total optimal path cost .
- Initialization:

Local Search and Optimization in Discrete State Spaces
Local Search Foundations:
- In many computational domains, the path to the solution is completely irrelevant; only the final configuration matters (e.g., 8-queens, IC layout, factory floor configuration, portfolio optimization).
- Local search algorithms operate from a single current state (or a small set of states) and move exclusively to neighboring states without tracking traversal history or retaining the path.
- Key Advantages:
- Minimal memory footprint: frequently requires only memory space.
- Capable of finding valid configurations in immense, continuous, or infinite state spaces where systematic frontier-based algorithms fail.
The State-Space Landscape:
- States are mapped across a topological surface where the elevation represents an objective function (for maximization, termed hill climbing) or a cost function (for minimization, termed gradient descent).

Topological Landscape Features:
Global Maximum: The state with the highest absolute objective function value across the entire space.
Local Maximum: A peak whose value is higher than all its immediate neighbors, but lower than the global maximum.
Flat Local Maximum: A flat plateau region with no uphill exit, where all neighboring states have identical elevation.
Shoulder: A horizontal plateau that eventually allows progress uphill.
Ridge: A steep, narrow sequence of local maxima oriented along an angle, where moves aligned with the coordinate axes point downhill.
Hill-Climbing Search (Steepest-Ascent):
Continuously evaluates neighboring states and moves in the direction of the steepest ascent (maximum immediate gain in the objective function).
Terminating condition: halts when reaching a state whose neighbors all have lower or equal value.

- The 8-Queens Problem Formulation:
- Complete-state formulation: All 8 queens are placed on the board, exactly one queen per column.
- State space size: (approximately ) possible board states.
- Successor definition: Move any single queen to any other row within its column, yielding successors per state.
- Heuristic cost function : The total number of pairs of attacking queens (direct or indirect). A valid solution has .

Performance Metrics on 8-Queens:
Starting from random initial states, steepest-ascent hill climbing succeeds only of the time, getting trapped in local maxima or plateaus in of instances.
Rapid runtime: averages steps to find a solution when successful, and steps before becoming trapped.
Introducing a maximum threshold of consecutive sideways moves raises the success rate from to .
Trade-off: Average steps on success increase to approximately , while failed runs average steps.
Pathologies of Hill Climbing:
Local Maxima: The search gets trapped because every single available transition decreases the objective function value.
Ridges: Greedy search oscillates back and forth across the crest, making negligible longitudinal progress because orthogonal moves lead downhill.

Plateaus: Greedy search drifts aimlessly due to zero-gradient evaluation across all neighbors.
- Variants of Hill Climbing:
Stochastic Hill Climbing: Selects randomly among uphill moves, where the probability of selecting an action is proportional to the steepness of the climb.
First-Choice Hill Climbing: Implements stochastic hill climbing by generating successors sequentially at random until one is found that is strictly superior to the current state; advantageous when thousands of successors exist.
Random-Restart Hill Climbing:
- Conducts iterative hill-climbing searches from randomly generated initial states until a goal is attained.
- Complete with probability in finite state spaces.
- Mathematical formulation: If each search instance has probability of success, the expected number of restarts is:
- The total expected cost (in steps) is:
- For 8-queens without sideways moves (), expected restarts are approximately ( failures and success), requiring approximately total steps.
- When sideways moves are permitted (), expected iterations drop to , with expected total steps calculated as:
Stochastic Local Search: Simulated Annealing, Beam Search, and Evolutionary Algorithms
- Simulated Annealing:
- Combines hill climbing with a controlled random walk to escape local extrema while maintaining asymptotic convergence toward the global optimum.
- Inspired by metallurgical annealing, where metals are heated to high temperatures (liquid state) and gradually cooled to form low-energy, defect-free crystalline structures.
- Operates like shaking a bumpy surface to bounce a ball out of local depressions into deeper valleys.

Mathematical Acceptance Criterion:
At each step, a successor state is chosen uniformly at random.
The change in objective value is calculated as (for minimization/cost) or (for maximization).
If the move improves the evaluation (), it is unconditionally accepted.
If the move worsens the evaluation, it is accepted probabilistically according to the Boltzmann distribution factor:
Where is the temperature parameter dictated by an annealing schedule .
High allows frequent downhill transitions; as , downhill probability approaches zero, transforming the process into pure greedy local search.
If the cooling schedule reduces sufficiently slowly, the algorithm converges to the global maximum with probability approaching .
Local Beam Search:
Tracks distinct states concurrently rather than maintaining a single active node.
Begins with randomly initialized states. At each iteration, all successors of all states are generated.
If any successor represents the goal, search halts; otherwise, it retains the best successors from the combined pool of all generated states.
Information Sharing:
- Unlike independent random restarts executed in parallel, beam search facilitates information sharing across parallel threads: search resources dynamically abandon unpromising regions and concentrate around the most fruitful areas.
Clustering Pathology & Stochastic Beam Search:
Standard beam search frequently suffers from rapid diversity loss, as all states quickly converge to the same localized region of the state space.
Stochastic Beam Search: Alleviates clustering by selecting successors probabilistically in proportion to their fitness value, similar to natural selection.
Genetic Algorithms (Evolutionary Algorithms):
Form of stochastic beam search directly inspired by biological evolution and sexual recombination.
Individual states are encoded as finite strings over an alphabet (e.g., binary bit strings, base-10 digit strings).
Key Components:
- Population Size: Number of individual configurations maintained in memory.
- Mixing Number (\rho): Number of parents combined to generate offspring (standard is ; corresponds to asexual stochastic beam search).
- Selection Operator: Parents are chosen probabilistically weighted by their relative fitness scores.
- Crossover (Recombination): Combines genetic material from parents by splitting strings at a chosen crossover point.
- Mutation: Independent bit-flip or digit-replacement applied at each position with a small probability.
- Elitism and Culling: Elitism retains top-performing parents in subsequent generations to guarantee monotonically non-decreasing maximum fitness; culling removes candidates falling below a strict fitness threshold.

- 8-Queens Problem Genetic Encoding:
- States are represented as 8-digit strings where the -th digit denotes the row of the queen in column .
- Maximum possible fitness value (non-attacking pairs) is:
- Example population with fitness scores and selection probabilities:
- Individual 1:
24748552, Fitness = , Selection Probability = - Individual 2:
32752411, Fitness = , Selection Probability = - Individual 3:
24415124, Fitness = , Selection Probability = - Individual 4:
32543213, Fitness = , Selection Probability =
- Individual 1:
- Mating selection: Random crossover points are selected. Parents
32752411and24748552crossed at position 3 yield offspring32748552and24752411.


- Schema Theory:
- A schema is a structural template specifying values at certain string positions while leaving others unspecified using wildcards (e.g.,
246*****). - Strings matching a schema are instances of that schema.
- If the average fitness of instances of a schema exceeds the population mean, the frequency of that schema grows exponentially over successive generations.
- A schema is a structural template specifying values at certain string positions while leaving others unspecified using wildcards (e.g.,
Local Search in Continuous State Spaces and Optimization Techniques
Continuous State Space Foundations:
- Physical real-world problems frequently present continuous action and state spaces, resulting in an infinite branching factor.
- States are represented by an -dimensional vector of continuous variables: .
Airport Placement Example in Romania:
- Task: Situate new airports across Romania such that the cumulative sum of squared Euclidean distances from each city to its closest airport is minimized.

- State Representation:
- 6-dimensional continuous state vector:
- Objective Function:
- Let denote the set of cities whose closest facility is airport :

*
* This formulation holds in the local neighborhood of ; large displacements alter the Voronoi partitioning of cities, changing sets .
Handling Continuous Spaces:
- Discretization: Constrain variables to a grid with step size . In a 6-dimensional space, each variable can change by , reducing an infinite branching factor to exactly successors.
- Empirical Gradient Methods: Measure the empirical slope between adjacent evaluations by perturbing coordinates by small amounts .
- Analytical Gradient Ascent / Descent:
- The gradient vector specifies the magnitude and direction of the steepest ascent:
- For the airport problem, the local partial derivatives are:
- Parameter update rule with learning rate / step size :
- Line search techniques mitigate poor choices of by continually stepping along the gradient direction (e.g., doubling ) until the function value declines.
Newton-Raphson Optimization:
- Root-finding technique for systems of equations . For optimization, we seek points where the gradient vanishes: .
- Second-order matrix-vector update utilizing the Hessian matrix of second derivatives:
Constrained Optimization:
- Imposes hard constraints on candidate variables (e.g., airport coordinates must reside within national borders and on dry land).
- Linear Programming (LP): Solves problems with linear constraints forming convex polyhedral feasible regions and a linear objective function. Time complexity is polynomial in the number of variables.
- Convex Optimization: Generalization of linear programming where the constraint region is convex and the objective function is convex; solvable in polynomial time and scalable to thousands of variables.
Search in Nondeterministic Environments and AND-OR Search Trees
Nondeterministic Search Formalism:
- In nondeterministic environments, actions can yield multiple possible outcomes; agents plan over belief states (sets of possible physical states).
- Rather than generating a linear sequence of actions, solutions take the form of conditional plans (contingency plans) incorporating branching logic based on runtime observations.
The Erratic Vacuum World:
- State space consists of 8 physical states:

Available actions:
Left,Right,Suck.Clean goal states: State 7 and State 8.
Erratic Suck Semantics:
- When applied to a dirty square, it cleans the current square and non-deterministically cleans the adjacent square too.
- When applied to a clean square, it sometimes deposits dirt on the square.
- Generalized transition model function: .
Contingency Plan for State 1:
[Suck, if State = 5 then [Right, Suck] else [ ]]AND-OR Search Trees:
Search trees alternate between two distinct node types:
- OR Nodes: Correspond to agent action choices (
Left,Right,Suck). - AND Nodes: Correspond to environmental nondeterminism where every branching outcome must be handled.
- OR Nodes: Correspond to agent action choices (

- Definition of a Solution Subtree:
- Must contain a goal node at every terminating leaf.
- Must specify exactly one action branch at each of its OR nodes.
- Must include every possible outcome branch at each of its AND nodes.

Cycle Detection in AND-OR Search:
If a state matches an ancestor state along the current path from the root, the path terminates and returns failure.
Prevents infinite recursive loops and guarantees termination in finite state spaces.
Cyclic Plans in Slippery Environments:
In a slippery vacuum world, movement actions non-deterministically fail, leaving the agent in its current position (e.g., executing
Rightin state 1 yields belief state .Acyclic solutions do not exist; plans must incorporate explicit looping constructs:
- Using
whilestatements:[Suck, while State = 5 do Right, Suck] - Using labels:
[Suck, L1: Right, if State = 5 then L1 else Suck]
- Using

Search in Partially Observable Environments and Belief-State Spaces
Sensorless (Conformant) Problems:
- Occur when an agent receives zero perceptual input ().
- In an underlying physical environment with states, the belief-state search space contains possible belief states.
- Solutions consist of open-loop linear action sequences that coerce the world into a goal state regardless of the initial starting state.
- For the deterministic sensorless vacuum world, the initial belief state is the complete set of all states: .
- Coercive sequence:
[Right, Suck, Left, Suck]guarantees arrival at goal state 7 from any initial state.
Belief-State Problem Formulation:
- States: Subsets of the physical state space.
- Initial State: Typically the set of all physical states in the problem.
- Actions: If illegal actions have no adverse side effects, the legal actions are the union of actions across all constituent physical states: . If illegal actions cause catastrophic failures, safe actions are the intersection: .
- Transition Model:
- For deterministic physical actions:
- For nondeterministic physical actions:

Goal Test:
An agent possibly achieves the goal if at least one state in satisfies the goal test.
An agent necessarily achieves the goal if every state in satisfies the goal test.
Reachable Belief Space and Pruning:
In the deterministic sensorless vacuum world, only out of the possible belief states are reachable.

Subset/Superset Pruning:
If a belief state is a superset of an already generated belief state (), can be pruned because solving the larger uncertainty set is strictly harder than solving the smaller one.
If a larger belief state has been solved, any subset is guaranteed to be solved by the same action sequence.
Partially Observable Search with Sensing:
Belief-state transitions occur through three successive stages:
- Prediction Stage: Compute the predicted state distribution following an action:
- Possible Percepts Stage: Compute the set of observations that could be perceived:
- Update Stage: Compute the refined belief state for each specific observation :


- Recursive State Estimation (Filtering / Monitoring):
- Maintains the agent's internal belief state over time as actions are executed and percepts arrive:

- Robot Localization Worked Example:
- Environment: Maze grid with walls and obstacles.
- Sensors: Four sonar sensors outputting a 4-bit percept vector
[North, East, South, West], where1indicates an obstacle. - Initial state: Complete ignorance across all open maze coordinates.
- Step 1: Agent observes percept (obstacles North, South, West). The belief state collapses to exactly matching physical coordinates.
- Step 2: Agent executes
Right, but faulty mobility results in a random nondeterministic move to an adjacent square, causing the predicted belief state to disperse across adjacent cells. - Step 3: Agent receives percept . Applying the update equation collapses the belief state down to exactly single unambiguous location coordinate.

Online Search Agents in Unknown Environments
Online vs. Offline Search Paradigm:
- Offline search algorithms compute a complete end-to-end path in a simulator prior to executing the first physical action.
- Online search interleaves computation, sensing, and execution: the agent acts, observes the resulting state, updates its internal map, and determines its subsequent step.
- Required in dynamic domains, unknown terrains, and nondeterministic environments.
Online Problem Formulation:
- The agent only has access to:
- : Valid actions available in state .
- : Step cost function (usable only after observing transition to ).
- : Goal test function.
- The transition model is entirely unknown prior to physical execution.

- Competitive Ratio:
- The ratio of the actual path cost incurred by the online agent to the optimal path cost computed offline with full prior knowledge of the map.
- Dead Ends and Adversary Arguments:
- Irreversible actions lead to inescapable dead ends where no goal state remains reachable.
- An adversary can construct topologies such that identical prior observation sequences lead to either dead ends or arbitrarily long detours.

Complete exploration guarantees are strictly restricted to safely explorable environments where every state can be reversed.
- Online Depth-First Search Exploration:
Interleaves local node expansion with physical backtracking.
Maintains three persistent lookup tables:
result[s, a]: Stores the observed state resulting from taking action in state .untried[s]: Tracks actions in state not yet executed.unbacktracked[s]: Stack of predecessor states from which the agent entered state , used for physical backtracking.

- Online Local Search and Learning Real-Time A* (LRTA*):
- Standard hill climbing fails in online environments because agents become permanently trapped at local maxima, and teleportation via random restarts is physically impossible.
- Pure random walks escape local traps asymptotically, but can take exponentially many steps in topological traps where backward transitions dominate.

- LRTA* Core Principle:
- Enhances local search with memory rather than randomness.
- Maintains a persistent table of cost estimates, initialized to the admissible heuristic .
- Evaluates untried actions under the optimism-under-uncertainty assumption, presuming untried actions lead directly to the goal with cost .
- Updates the heuristic value of the state just departed () to reflect the observed neighbor costs:
- The agent then moves to the neighbor minimizing this cost estimate.


- Convergence Properties:
- Guaranteed to discover the goal in any finite, safely explorable environment.
- Worst-case exploration complexity across an environment of states is bounded by .
- Learning mechanism: Sequentially updates the environmental map table
result[s, a]while flattening out local heuristic depressions, progressively learning the optimal value function through real-time experience.