3.5.13 · HinglishGraphs

A - algorithm — heuristic, admissibility, consistency — important for GNC

1,954 words9 min readRead in English

3.5.13 · Coding › Graphs


A* exist kyun karta hai?


Kya hain iske pieces?


A* ka Dijkstra aur Greedy se kya relation hai? (80/20 core)

Algorithm Priority key Behaviour
Dijkstra exact, slow, andha
Greedy best-first fast, optimal nahi
A* optimal (agar admissible ho) + fast
Figure — A -  algorithm — heuristic, admissibility, consistency — important for GNC

DERIVATION 1 — Admissibility ⇒ optimal path kyun

Step 1. Maano true optimal cost hai. Maano A* ek goal node ko pop karne wala hai jiska path cost hai (ek suboptimal goal). Hum dikhayenge yeh impossible hai. Yeh step kyun? Agar hum prove kar lein ki A* kabhi pehle bura goal pop nahi kar sakta, toh pehla popped goal optimal hi hoga.

Step 2. Kyunki true optimal path exist karta hai, open list (frontier) par kahin ek node hai jo ek optimal path par baith raha hai. Kyun? Start se goal tak koi bhi path joh poori tarah expand nahi hua, uska kam se kam ek "boundary" node frontier par zaroor hoga.

Step 3. Us ke liye: Yeh step kyun? hi admissibility hai, aur optimal path par hone ki wajah se optimal total cost ke barabar hai.

Step 4. Lekin goal hai isliye , ataḥ . Milaane par: .

Step 5. A* sabse chhota pehle pop karta hai, isliye ko se pehle pop kiya jaata. Contradiction. ∎ Yeh kyun matter karta hai: A* jo pehla goal queue se nikalta hai wo guaranteed optimal hota hai — admissibility bilkul wohi condition hai jo yeh guarantee khareedti hai.


DERIVATION 2 — Consistency ⇒ admissibility (aur kabhi re-expand nahi) kyun

Step A: consistent ⇒ admissible. Koi bhi path lo . Consistency isko along apply karo: se tak sum karo ( terms telescope ho jaate hain), ke saath: Yeh step kyun? Yeh har path ke liye hold karta hai, khaaskar sabse saste ke liye, isliye . Ho gaya — consistency admissibility se zyada strong hai.

Step B: expansions ke along non-decreasing hai. Edge ke liye: consistency use karte hue. Yeh kyun matter karta hai: kabhi decrease nahi karta jab hum deeper jaate hain. Isliye jab koi node pop hota hai uska already final hota hai → A ko koi closed node kabhi re-open nahi karna padta*. Sirf-admissible (par inconsistent) heuristic ke saath tumhe re-expand karna pad sakta hai, jo slower hai.


Worked Example 1 — grid with Manhattan distance

Grid, 4-directional moves cost 1 each. Heuristic Manhattan distance .

  • Admissible kyun? Har move Manhattan distance ko zyada se zyada 1 badalta hai aur cost 1 hai, isliye seedha count kabhi true number of moves ko overestimate nahi karta.
  • Consistent kyun? Neighbours ke liye aur , isliye . ✔

Start , goal :

  • , .
  • ki taraf move karo: , , . Same — A* goal ki taraf badhta rehta hai, ko expand nahi karta jiska hai. Yeh step kyun? Goal se door wale node ka zyada hai, isliye A* simply usse ignore karta hai — yahi Dijkstra se speedup hai.

Worked Example 2 — inadmissible heuristic optimality kaise todni hai

Nodes : (total 2). Aur direct . Ek bura set karo (overestimate; true 1 hai).

  • . .
  • A* direct pehle pop karta hai → cost return karta hai, true optimum 2 miss karke. Yeh kyun matter karta hai: overestimate karne se achha path mahenga dikhne laga. Steel-man fix: ko clamp/lower karo taki ho.

Worked Example 3 — drone ke liye Euclidean heuristic (GNC)

Continuous space, moves along grid lekin real robot diagonally fly kar sakta hai; cost = Euclidean length. Use straight-line (Euclidean) distance.

  • Seedhi line sabse chhota possible path hai ⇒ ⇒ admissible.
  • Yeh triangle inequality bhi satisfy karta hai ⇒ consistent. GNC kyun care karta hai: admissible Euclidean guarantee karta hai ki planner genuinely shortest flyable route return kare, aur target ki taraf ek narrow cone explore kare — on-board compute limited hone par yeh crucial hai.


Recall Feynman: 12-saal ke bachche ko samjhao

Socho tum ek maze mein exit dhundh rahe ho. Dijkstra har direction mein equally explore karta hai — slow. A* smarter hai: har jagah par tum jhankke andaaza lagaate ho "yahan se exit roughly kitni door hai?" (jaise seedhi-line distance dekhna). Tum hamesha us jagah jaate ho jo sabse chhoti total trip deti lage = abhi tak chale steps plus andaaza. Ek rule: tera andaaza kabhi zyada promise mat kare — kabhi mat bolo "exit ekdum paas hai" jab wo ho nahi. Agar tera andaaza hamesha thoda cautious rahe (kabhi zyada rosy nahi), toh A* guaranteed sabse chhota raasta dhundh lega, sirf bahut jaldi.


Flashcards

A* mein f(n) kya hai?
— cost-so-far plus estimated cost-to-go.
Admissible heuristic ki definition
; kabhi true remaining cost ko overestimate nahi karta.
Consistent heuristic ki definition
har edge ke liye, ke saath (triangle inequality).
Kya consistency admissibility imply karti hai?
Haan — kisi bhi path par consistency ko telescope karne se milta hai. (One-way; admissible zarori nahi consistent ho.)
Kaunsi property guarantee karti hai ki A* optimal path return kare?
Admissibility.
Kaunsi property guarantee karti hai ki A* koi closed node kabhi re-expand na kare?
Consistency (yeh ko kisi bhi path par non-decreasing banati hai).
h(n)=0 wala A* kya ban jaata hai?
Dijkstra's algorithm.
Sirf f=h use karna (g ignore karna) kya hai?
Greedy best-first search — fast lekin optimal nahi.
Overestimating heuristic optimality kyun todta hai?
Yeh true cheapest path ko mahenga dikhata hai, isliye A* pehle worse goal pop kar sakta hai.
Weighted A* kya hai?
with : faster, bounded-suboptimal (≤ w × optimal), generally inadmissible.
Continuous space mein Euclidean distance admissible kyun hai?
Seedhi line sabse chhota possible path hai, isliye yeh kabhi overestimate nahi karta.

Connections

  • Dijkstra's Algorithm — A* with .
  • Greedy Best-First Search — A* jab drop ho.
  • Heuristic Functions — Manhattan, Euclidean, Chebyshev.
  • Priority Queue / Min-Heap — data structure jo ke order mein arrange karta hai.
  • Triangle Inequality — consistency ki geometric jadd.
  • Weighted A* and Bounded Suboptimality
  • GNC Path Planning — rovers, drones, spacecraft.
  • Bellman Optimality — relation .

Concept Map

add heuristic

estimates cost to goal

start to n

expand smallest f

never overestimates

guarantees when h admissible

implies

only h gives

fast but not

used by

Dijkstra blind ripples

Heuristic h n

g n cost so far

f n = g + h

A* algorithm

Admissible h ≤ h*

Consistent triangle ineq

Optimal shortest path

Greedy best-first f=h

GNC path planning