惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
雷峰网
雷峰网
量子位
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
博客园 - Franky
罗磊的独立博客
宝玉的分享
宝玉的分享
博客园_首页
腾讯CDC
The GitHub Blog
The GitHub Blog
D
DataBreaches.Net
IT之家
IT之家
D
Docker
Microsoft Security Blog
Microsoft Security Blog
博客园 - 司徒正美
V
V2EX
月光博客
月光博客
N
Netflix TechBlog - Medium
爱范儿
爱范儿
I
InfoQ
P
Proofpoint News Feed

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How Heuristics Make Search Algorithms Smarter
zeromathai · 2026-05-10 · via DEV Community

Search gets expensive when every path looks equally possible.

That is the real problem.

A heuristic gives the algorithm a sense of direction.

It does not solve the problem by itself.

But it tells the search what looks worth exploring first.

Core Idea

A heuristic function estimates how close a state is to the goal.

In search algorithms, that estimate becomes a decision signal.

Instead of exploring blindly, the algorithm can prioritize promising states.

That is why heuristics matter.

They turn search from “try everything” into “try the most promising thing first.”

The Key Structure

A simple search decision looks like this:

Current State → Heuristic Estimate → Priority → Next State

For A*, the structure is:

f(n) = g(n) + h(n)

Where:

  • g(n) = cost from the start to the current node
  • h(n) = estimated cost from the current node to the goal
  • f(n) = total estimated cost

The heuristic is h(n).

It is the part that points the search toward the goal.

Implementation View

At a high level, heuristic search works like this:

start from the initial state

while there are states to explore:
    estimate how promising each state is

    choose the state with the best score

    if it is the goal:
        return the solution

    expand the next states

return failure

Enter fullscreen mode Exit fullscreen mode

This is why heuristic quality matters in implementation.

A weak heuristic barely improves search.

A bad heuristic can guide the algorithm in the wrong direction.

A good heuristic reduces wasted exploration.

Concrete Example

Imagine pathfinding on a grid.

You want to move from Start to Goal.

If movement is only up, down, left, and right, Manhattan distance often fits well.

It estimates distance like this:

Manhattan distance = |x1 - x2| + |y1 - y2|

If movement can happen freely in straight lines, Euclidean distance may fit better.

Euclidean distance = straight-line distance

The point is not that one is always better.

The point is that the heuristic should match the structure of the problem.

Blind Search vs Heuristic Search

Blind search has no sense of direction.

It explores based only on the search rule.

For example, BFS expands level by level.

DFS goes deep first.

Heuristic search adds an estimate.

Blind search:

  • explores without goal guidance
  • can waste time on irrelevant paths
  • works well for small or simple state spaces

Heuristic search:

  • uses a goal-directed signal
  • prioritizes promising states
  • becomes much more useful when the state space is large

This is why heuristics are so important in AI search.

They do not just make the search faster.

They change the order of exploration.

Greedy Search vs A*

Greedy Search and A* both use heuristics.

But they use them differently.

Greedy Search uses only:

h(n)

A* uses:

f(n) = g(n) + h(n)

Greedy Search asks:

“Which state looks closest to the goal?”

A* asks:

“Which state has the best total estimated path cost?”

That difference matters.

Greedy Search can be fast.

But it can ignore the cost already paid.

A* is more balanced because it combines actual cost with estimated future cost.

Why Admissibility Matters

A heuristic is admissible if it never overestimates the true cost to the goal.

In simple terms:

h(n) <= true remaining cost

This condition matters because A* depends on the heuristic.

If the heuristic overestimates too much, A* may skip the optimal path.

Admissibility keeps the estimate safe.

It helps A* preserve the optimality guarantee.

Why Consistency Matters

Consistency is also called monotonicity.

It means the heuristic behaves smoothly as the search moves from one node to another.

Conceptually:

The estimated cost should not suddenly contradict the cost of moving between nodes.

Consistency helps A* behave cleanly during expansion.

In many implementations, it also avoids reopening already processed nodes.

So the difference is:

Admissibility protects optimality.

Consistency keeps the search process stable.

They are related, but not identical.

Recommended Learning Order

If heuristics feel abstract, learn them in this order:

  1. Heuristic Function
  2. Manhattan Distance vs Euclidean Distance
  3. Admissibility
  4. Consistency
  5. Greedy Search
  6. A* Algorithm

This order works because you first understand the estimate.

Then you see concrete distance examples.

Then you understand the conditions that make heuristic search reliable.

Takeaway

A heuristic is a search shortcut.

But not a random shortcut.

It is a structured estimate that tells the algorithm what looks promising.

The shortest version is:

Heuristic = estimated remaining cost

In A*:

f(n) = g(n) + h(n)

The better h(n) matches the problem, the less unnecessary search you do.

If you remember one idea, remember this:

A heuristic makes search smarter by giving it direction before the full answer is known.

Discussion

When designing a heuristic, do you prefer a simple safe estimate like Manhattan distance, or a more aggressive estimate that may guide the search faster?

Originally published at zeromathai.com.
Original article: https://zeromathai.com/en/heuristic-function-ai-search-hub-en/

GitHub Resources
AI diagrams, study notes, and visual guides:
https://github.com/zeromathai/zeromathai-ai