Explain Dijkstra vs A*.

Dijkstra’s algorithm finds the shortest path in a graph by exploring all possible routes, while A* improves it by using a heuristic to guide the search toward the goal faster.

When to Use

Use Dijkstra when you need a guaranteed shortest path and no heuristic (like GPS routing or network latency mapping). Use A* when you can estimate the distance to the goal—common in game pathfinding, AI navigation, and map search systems.

Example

Imagine navigating a city: Dijkstra explores every street, while A* focuses on those leading closer to your destination using a heuristic like straight-line distance.

To master such algorithms, explore Grokking Data Structures & Algorithms for Coding Interviews, Grokking System Design Fundamentals, Grokking the Coding Interview, or Mock Interviews with ex-FAANG engineers.

Why Is It Important

A strong grasp of Dijkstra vs A* helps you reason about efficiency vs accuracy, critical in interviews and real-world systems like routing engines or logistics optimization.

Interview Tips

Say “A* is Dijkstra plus a heuristic.” Emphasize A*’s performance gain and Dijkstra’s completeness.

Walk through a simple map example to show your understanding.

Trade-offs

Dijkstra is slower but reliable. A* is faster but depends on a good heuristic—if it’s poor, performance drops.

Pitfalls

Avoid assuming A* is always better. If your heuristic overestimates, it can miss the optimal path. Always ensure heuristic admissibility for correctness.

TAGS
Coding Interview
CONTRIBUTOR
Design Gurus Team
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Image
One-Stop Portal For Tech Interviews.
Copyright © 2025 Design Gurus, LLC. All rights reserved.