{"id":195,"date":"2026-11-13T12:34:13","date_gmt":"2026-11-13T04:34:13","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-ida-deepens-an-f-cost-bound\/"},"modified":"2026-11-13T21:52:27","modified_gmt":"2026-11-13T13:52:27","slug":"how-ida-deepens-an-f-cost-bound","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-ida-deepens-an-f-cost-bound\/","title":{"rendered":"How IDA* deepens an f-cost bound"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>IDA*<\/strong> applies iterative deepening to <strong>A*<\/strong>. Each pass is a depth-first search that refuses to step onto a vertex whose <strong>f = g + h<\/strong> exceeds the current bound. The next bound is the smallest f that was blocked. With an admissible heuristic, the first time the goal is reached the path is optimal. Memory is the current path, <strong>O(d)<\/strong>, instead of A*&#8217;s frontier.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">A<em> stores every generated vertex so it can pop the best f. In a puzzle or a planning graph that set is too large, while a single path down the tree is not. A depth-first search that prunes any branch whose f already exceeds a threshold explores exactly the vertices A<\/em> would have considered inside that threshold, and it forgets them on the way back.<\/p>\n\n\n<p class=\"wp-block-paragraph\">The thresholds have to increase to the next useful f, not by one, or a real-valued or sparse set of f values produces a pass that expands nothing new. The minimum blocked f is the next threshold at which some new vertex becomes legal.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">If h is admissible and edge weights are positive, the first time a pass reaches the goal, the goal&#8217;s g equals the optimal cost. Consistency of h is not required for that optimality claim, because the search is a tree search over paths and does not settle a vertex forever. Time can still be exponential, and a graph with many paths to the same vertex can re-expand that vertex on every path unless a transposition table is added. The stack uses O(d) memory. A transposition table uses more, up to A*-sized memory if it stores everything.<\/p>\n\n\n<p class=\"wp-block-paragraph\">Each pass expands the vertices with f at or below the bound. The number of passes equals the number of distinct f values along an optimal decision, which for integer weights and an integer heuristic is at most the optimal cost. The last pass dominates when the tree grows geometrically.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Set the bound to h(source). The source has g = 0.<\/li>\n<li>Depth-first search from the source. On entering a vertex, if g+h exceeds the bound, record that f as a candidate for the next bound and backtrack without expanding.<\/li>\n<li>If the vertex is the goal, return the path. Admissibility makes this first success optimal.<\/li>\n<li>If the search returns without a goal, replace the bound by the minimum recorded overflow. If no overflow was recorded, the goal is unreachable.<\/li>\n<li>Repeat. Optional: a transposition table keyed by vertex and g can skip a path that already visited the vertex with an equal or better g in this pass.<\/li>\n<\/ol>\n\n\n<p class=\"wp-block-paragraph\">Optimality needs an admissible heuristic and nonnegative costs. A heuristic that overestimates can return a suboptimal first success. The memory win disappears if the transposition table stores the whole graph. IDA<em> is the memory-tight sibling of A<\/em>, not a faster one on a graph that A* already fits.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails when the next bound is chosen poorly<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Increase the bound by 1 regardless of the blocked f values<\/td>\n<td>Correct when every f is an integer and every integer occurs, and wasteful or non-terminating in its logic when the next real f jumps. The minimum blocked f is the next bound that admits a new vertex.<\/td>\n<\/tr>\n<tr>\n<td>Return the first goal an ordinary DFS finds<\/td>\n<td>That path ignores f. IDA* is optimal because a cheaper goal would have had a smaller f and would have been admitted at an earlier bound.<\/td>\n<\/tr>\n<tr>\n<td>Use an inadmissible h<\/td>\n<td>The pass that first reaches the goal may have pruned the true optimal branch for exceeding a bound it would have survived under a lower estimate.<\/td>\n<\/tr>\n<tr>\n<td>Store every generated vertex and still call the memory O(d)<\/td>\n<td>That store is A*&#8217;s frontier. The O(d) claim is the path stack alone.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">A frontier that fits belongs to A*. No heuristic and a hop limit belongs to iterative deepening DFS. A consistent heuristic with plenty of memory does not need this repeated expansion.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment deepens an f-cost bound. h is the number of hops still required in an unweighted sense, and it is admissible. The first time the goal is reached, the cost is optimal. It prints <code>3<\/code>.<\/p>\n\n<pre><code class=\"language-python\">adj = {0: [(1, 1), (2, 4)], 1: [(2, 1), (3, 5)], 2: [(3, 1)], 3: []}\nh = {0: 2, 1: 1, 2: 1, 3: 0}\n\ndef search(u, g, bound, path):\n    f = g + h[u]\n    if f &gt; bound:\n        return f\n    if u == 3:\n        return True\n    minimum = 10**9\n    for v, w in adj[u]:\n        if v in path:\n            continue\n        path.add(v)\n        t = search(v, g + w, bound, path)\n        if t is True:\n            return True\n        minimum = min(minimum, t)\n        path.remove(v)\n    return minimum\n\nbound = h[0]\nwhile True:\n    t = search(0, 0, bound, {0})\n    if t is True:\n        break\n    bound = t\nassert bound == 3\nprint(bound)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">IDA* solves the 15-puzzle and other memory-tight pathfinding problems by deepening an f-cost bound instead of storing the open set. Game and puzzle solvers use it when A* would run out of memory. A* is the same scoring with a stored frontier.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop IDA<em> when A<\/em>&#8216;s frontier fits in memory. A<em> expands each vertex less often. Keep IDA<\/em> for a large state space with an admissible heuristic, where storing the frontier is the constraint and re-expanding paths is acceptable.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for IDA<em> returns the f-bound, the minimum overflow that sets the next bound, and the admissible heuristic the first success relies on. <\/em><em>IDA<\/em> finds an optimal path with O(d) memory by depth-first searches capped at increasing f values, and the next cap is the smallest f the previous pass refused.**<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: IDA* applies iterative deepening to A*. Each pass is a depth-first search that refuses to step onto a vertex whose f = g + h exceeds the current bound. The next bound is the smallest f that was blocked. With an admissible heuristic, the first time the&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,32],"tags":[],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-graphs"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=195"}],"version-history":[{"count":2,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":594,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/195\/revisions\/594"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}