Quiz 2

⏩ Weighted A* & IDA*

512 words
3 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# ⏩ Weighted A* & IDA* ## 1. 🎯 Learning Objectives - Explain how Weighted A* trades optimality for speed - Trace IDA* with f-cost bounds instead of depth bounds - Explain RBFS and its rollback mechanism - Compare linear-space variants of A* ## 2.

⏩ Weighted A* & IDA*

1. 🎯 Learning Objectives

  • Explain how Weighted A* trades optimality for speed
  • Trace IDA* with f-cost bounds instead of depth bounds
  • Explain RBFS and its rollback mechanism
  • Compare linear-space variants of A*

2. 📖 Core Content

3.1 Weighted A* (wA*)

Formula: f(N)=g(N)+wh(N)f(N) = g(N) + w \cdot h(N) where w>1w > 1
  • w = 1: Standard A* (optimal)
  • w > 1: Biases search toward heuristic promise (faster but potentially suboptimal)
  • w → ∞: Approaches greedy Best First Search Why use wA?* A* can be too slow for large problems. By weighting the heuristic, we focus more on promising directions, finding solutions faster — even if not guaranteed optimal.

3.2 IDA* (Iterative Deepening A*)

IDA* combines the iterative deepening concept of DFID with A*'s f-cost heuristic:
text
IDAStar(initial_state, goal_test, move_gen, heuristic):
    bound = h(initial_state)
    while True:
        result, new_bound = DFS_Contour(initial_state, 0, bound, goal_test, move_gen, heuristic)
        if result != None:
            return result
        if new_bound == infinity:
            return NO_SOLUTION
        bound = new_bound
DFS_Contour(state, g, bound, goal_test, move_gen, heuristic):
    f = g + h(state)
    if f > bound:
        return None, f  // Prune — return new candidate bound
    if goal_test(state):
        return [state], bound
    min_exceeded = infinity
    for child in move_gen(state):
        result, new_bound = DFS_Contour(child, g+1, bound, ...)
        if result != None:
            return [state] + result, bound
        min_exceeded = min(min_exceeded, new_bound)
    return None, min_exceeded
Key difference from DFID:
  • DFID uses depth limit; IDA* uses f-cost limit
  • IDA* prunes when f(N)>boundf(N) > bound
  • Next iteration's bound = minimum f that exceeded current bound
RBFS is a linear-space variant of A* that uses recursion with backtracking:
text
RBFS(state, g, bound, heuristic):
    f = g + h(state)
    if f > bound: return None, f
    if goal_test(state): return [state], f
    successors = sorted by f(child) = g + cost(state,child) + h(child)
    if successors is empty: return None, infinity
    while True:
        best = successors[0]
        if best.f > bound: return None, best.f
        alternative = successors[1].f if len(successors) > 1 else infinity
        result, best.f = RBFS(best.state, best.g, min(bound, alternative), heuristic)
        if result != None: return [state] + result, best.f
        // Re-sort by updated f values
        successors.sort_by_f()
When to use RBFS: When memory is extremely limited but you want the advantages of best-first ordering.

3.4 Comparison of A* Variants

AlgorithmSpaceOptimal?Complete?Best For
A*O(bd)O(b^d)YesYesSmall-medium spaces
wA*O(bd)O(b^d)NoYesSpeed-critical
IDA*O(bd)O(bd)YesYesLarge spaces, good heuristics
RBFSO(bd)O(bd)YesYesLarge spaces, poor heuristics

3. 📝 Practice Questions

Q1: With w=2, how does wA differ from A?**
Answer: wA* uses f=g+2h. It weights the heuristic more heavily, favoring nodes that look close to the goal. This leads to faster search but may miss the optimal solution if the heuristic is imperfect. Q2: Why does IDA use O(bd) space?*
Answer: IDA* performs depth-first search at each iteration (stack-based DFS), storing only the current path (depth d) plus siblings at each level (at most b each). This is O(bd), same as DFID. Join Discord PreviousTSP Branch & BoundNextMonotone Condition
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.