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!
Explore Answers
What are software developer interviews like?
How many primary keys are in a table?
Negotiating solution scope with interviewer to clarify expectations
Can we use ChatGPT in coding interview?
How successful is Palantir?
What research methods do you use?
Related Courses
Course image
Grokking the Coding Interview: Patterns for Coding Questions
Grokking the Coding Interview Patterns in Java, Python, JS, C++, C#, and Go. The most comprehensive course with 476 Lessons.
4.6
Discounted price for Your Region

$197

Course image
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
3.9
Discounted price for Your Region

$78

Course image
Grokking Data Structures & Algorithms for Coding Interviews
Unlock Coding Interview Success: Dive Deep into Data Structures and Algorithms.
4
Discounted price for Your Region

$78

Image
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.