Data Structures and Algorithms
- Introduction to Data Structures and Algorithms
- Time and Space Complexity Analysis
- Big-O, Big-Theta, and Big-Omega Notations
- Recursion and Backtracking
- Divide and Conquer Algorithm
- Dynamic Programming: Memoization vs. Tabulation
- Greedy Algorithms and Their Use Cases
- Understanding Arrays: Types and Operations
- Linear Search vs. Binary Search
- Sorting Algorithms: Bubble, Insertion, Selection, and Merge Sort
- QuickSort: Explanation and Implementation
- Heap Sort and Its Applications
- Counting Sort, Radix Sort, and Bucket Sort
- Hashing Techniques: Hash Tables and Collisions
- Open Addressing vs. Separate Chaining in Hashing
- DSA Questions for Beginners
- Advanced DSA Questions for Competitive Programming
- Top 10 DSA Questions to Crack Your Next Coding Test
- Top 50 DSA Questions Every Programmer Should Practice
- Top Atlassian DSA Interview Questions
- Top Amazon DSA Interview Questions
- Top Microsoft DSA Interview Questions
- Top Meta (Facebook) DSA Interview Questions
- Netflix DSA Interview Questions and Preparation Guide
- Top 20 DSA Interview Questions You Need to Know
- Top Uber DSA Interview Questions and Solutions
- Google DSA Interview Questions and How to Prepare
- Airbnb DSA Interview Questions and How to Solve Them
- Mobile App DSA Interview Questions and Solutions
DSA Interview Questions
- DSA Questions for Beginners
- Advanced DSA Questions for Competitive Programming
- Top 10 DSA Questions to Crack Your Next Coding Test
- Top 50 DSA Questions Every Programmer Should Practice
- Top Atlassian DSA Interview Questions
- Top Amazon DSA Interview Questions
- Top Microsoft DSA Interview Questions
- Top Meta (Facebook) DSA Interview Questions
- Netflix DSA Interview Questions and Preparation Guide
- Top 20 DSA Interview Questions You Need to Know
- Top Uber DSA Interview Questions and Solutions
- Google DSA Interview Questions and How to Prepare
- Airbnb DSA Interview Questions and How to Solve Them
- Mobile App DSA Interview Questions and Solutions
Introduction to High-Level System Design
System Design Fundamentals
- Functional vs. Non-Functional Requirements
- Scalability, Availability, and Reliability
- Latency and Throughput Considerations
- Load Balancing Strategies
Architectural Patterns
- Monolithic vs. Microservices Architecture
- Layered Architecture
- Event-Driven Architecture
- Serverless Architecture
- Model-View-Controller (MVC) Pattern
- CQRS (Command Query Responsibility Segregation)
Scaling Strategies
- Vertical Scaling vs. Horizontal Scaling
- Sharding and Partitioning
- Data Replication and Consistency Models
- Load Balancing Strategies
- CDN and Edge Computing
Database Design in HLD
- SQL vs. NoSQL Databases
- CAP Theorem and its Impact on System Design
- Database Indexing and Query Optimization
- Database Sharding and Partitioning
- Replication Strategies
API Design and Communication
Caching Strategies
- Types of Caching
- Cache Invalidation Strategies
- Redis vs. Memcached
- Cache-Aside, Write-Through, and Write-Behind Strategies
Message Queues and Event-Driven Systems
- Kafka vs. RabbitMQ vs. SQS
- Pub-Sub vs. Point-to-Point Messaging
- Handling Asynchronous Workloads
- Eventual Consistency in Distributed Systems
Security in System Design
Observability and Monitoring
- Logging Strategies (ELK Stack, Prometheus, Grafana)
- API Security Best Practices
- Secure Data Storage and Access Control
- DDoS Protection and Rate Limiting
Real-World System Design Case Studies
- Distributed locking (Locking and its Types)
- Memory leaks and Out of memory issues
- HLD of YouTube
- HLD of WhatsApp
System Design Interview Questions
- Adobe System Design Interview Questions
- Top Atlassian System Design Interview Questions
- Top Amazon System Design Interview Questions
- Top Microsoft System Design Interview Questions
- Top Meta (Facebook) System Design Interview Questions
- Top Netflix System Design Interview Questions
- Top Uber System Design Interview Questions
- Top Google System Design Interview Questions
- Top Apple System Design Interview Questions
- Top Airbnb System Design Interview Questions
- Top 10 System Design Interview Questions
- Mobile App System Design Interview Questions
- Top 20 Stripe System Design Interview Questions
- Top Shopify System Design Interview Questions
- Top 20 System Design Interview Questions
- Top Advanced System Design Questions
- Most-Frequented System Design Questions in Big Tech Interviews
- What Interviewers Look for in System Design Questions
- Critical System Design Questions to Crack Any Tech Interview
- Top 20 API Design Questions for System Design Interviews
- Top 10 Steps to Create a System Design Portfolio for Developers
Shortest Path Algorithm Tutorial with Problems
In this tutorial, we’ll explore the most widely used shortest path algorithms that are essential in the study of Data Structures and Algorithms. Each algorithm offers unique advantages and limitations depending on the specific requirements of the problem. We’ll also break down their time and space complexities, which are commonly discussed in technical interviews. If you’re eager to start learning these concepts right away, consider signing up for free courses and receive the latest course updates to boost your skills effectively.
What Are the Shortest Path Algorithms?
Shortest path algorithms are designed to determine the minimum travel cost or distance from a source node to a destination node in a graph, while optimizing both time and space complexity.
Types of Shortest Path Algorithms
Given that graphs can vary—such as weighted, unweighted, cyclic, or even containing negative weights—no single algorithm can efficiently solve all types. To manage different scenarios effectively, shortest path algorithms are classified into two main categories:
Single Source Shortest Path Algorithms
In this algorithm type, we determine the shortest path from a single source node to all other nodes in the graph.
Algorithms include:
- Depth-First Search (DFS)
- Breadth-First Search (BFS)
- Multi-Source BFS
- Dijkstra’s Algorithm
- Bellman-Ford Algorithm
- Topological Sort
- A* Search Algorithm
All Pair Shortest Path Algorithms
Contrary to single-source shortest path algorithms, here we determine the shortest path between every possible pair of nodes.
Algorithms include:
- Floyd-Warshall Algorithm
- Johnson’s Algorithm
Let’s discuss these algorithms one by one.
1. Shortest Path Algorithm using Depth-First Search (DFS)
DFS recursively explores adjacent nodes until no more valid recursive calls are possible.
Note: DFS can only be used for shortest path calculation in acyclic graphs (trees). For cyclic graphs, DFS can’t guarantee the shortest path due to multiple possible paths. If there’s no path between source and destination, return -1 as the shortest path.
Algorithm:
- Distance of source to itself is 0.
- Start DFS from the source.
- Update neighbor’s distance = edge weight + parent node’s distance.
- End when all leaf nodes are visited.
Complexity:
- Time: O(N)
- Space: O(N) (due to recursive stack)
Real World Application:
Finding the path between nodes in a hierarchical file‐system (tree) where every folder and subfolder is treated as a node and edges are unweighted—e.g., locating a specific file’s directory path in an operating system’s folder structure.
2. Breadth-First Search (BFS) for Shortest Path Algorithm
BFS works well for unweighted graphs and ensures the shortest path in terms of number of edges. Why it works: BFS explores all nodes at distance d before moving to d+1.
Algorithm:
- Use a queue with {node, distance} pairs.
- Start with {source, 0}.
- While queue is not empty:
- Pop the front node.
- Record its distance.
- Push all unvisited neighbors with distance + 1.
Complexity:
- Time: O(V + E)
- Space: O(V)
Real World Application:
Finding the minimum number of transfers in an unweighted public‐transit network (e.g., subway lines) where each station is a node and each direct ride between stations is an edge—BFS yields the fewest transfers from one station to another.
3. Multi-Source BFS for Shortest Path Algorithm
Multi-Source BFS starts simultaneously from multiple source nodes.
Algorithm:
- Push all source nodes into queue with distance 0.
- While queue is not empty:
- Pop front node.
- Record its distance.
- Push unvisited neighbors with distance + 1.
Complexity:
- Time: O(V + E)
- Space: O(V)
Real World Application:
Modeling the spread of emergency alerts from multiple dispatch centers in a city—each dispatch center is a source, and you want to know how quickly (in number of road‐hops) the alert reaches each neighborhood.
4. Dijkstra’s Algorithm for Shortest Path Algorithm
Dijkstra’s algorithm is used for weighted graphs with non-negative weights using a greedy approach.
Algorithm:
- Initialize distances to all nodes as ∞; source = 0.
- Use a min-heap or priority queue.
- Pick node with the smallest distance.
- Update distances for its neighbors if a shorter path is found.
Complexity:
- Time: O(E * log V)
- Space: O(V)
Real World Application:
GPS navigation systems compute the quickest driving route on a road network where nodes are intersections and edges are road segments weighted by travel time—Dijkstra’s finds the minimum‐travel‐time path from your current location to the destination.
If you want to master this algorithm and many more, check out the DSA course to deepen your understanding.
5. Bellman-Ford Algorithm for Shortest Path Algorithm
Unlike Dijkstra, Bellman-Ford handles negative weights and detects negative cycles.
Algorithm:
- Initialize dist[] with ∞, source = 0.
- Relax all edges V – 1 times:
dist[v] = min(dist[v], dist[u] + weight)
Complexity:
- Time: O(V * E)
- Space: O(V)
Real World Application:
Currency‐exchange arbitrage detection, where each currency pair’s exchange rate can be represented as an edge with weight = –log(rate). Bellman-Ford detects if there’s a cycle whose total weight < 0, indicating a guaranteed profit loop.
6. Topological Sort for Shortest Path in DAGs
Used for shortest paths in Directed Acyclic Graphs (DAGs).
Working:
- Nodes with in-degree 0 are source nodes.
- Use topological sort followed by edge relaxation.
Complexity:
- Time: O(V + E)
- Space: O(V)
Real World Application:
Project scheduling with task dependencies (e.g., building software features where some modules must be completed before others). Each task is a node, directed edges represent “must finish before,” and weights represent time; topological sort plus relaxation finds the minimum completion time for every task.
7. Floyd-Warshall Algorithm for Shortest Path
Solves all-pairs shortest path problem using Dynamic Programming.
Algorithm:
- Initialize dist[][] matrix from input graph.
- For each vertex k, update every dist[i][j]:
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
Complexity:
- Time: O(V³)
- Space: O(V²)
Real World Application:
Computing the shortest travel times between all pairs of major train stations in a national rail network, where the result is used to quickly answer queries like “What’s the fastest route from Station A to Station B via any number of transfers?”
8. A* Search Algorithm for Shortest Path
A* is a heuristic-based algorithm used in games and map services. Key: It combines cost to reach a node + estimated cost to goal.
Complexity:
- Time: O(E * log V)
- Space: O(V)
Real World Application:
Pathfinding for non‐player characters in video games (e.g., a character navigating a 3D environment), where the heuristic is typically Euclidean or Manhattan distance to the goal—A* finds near‐optimal routes very efficiently.
9. Johnson’s Algorithm for Shortest Path
Used for all-pairs shortest paths, including graphs with negative edge weights.
Steps:
- Re-weight all edges to make them non-negative using Bellman-Ford.
- Apply Dijkstra from each vertex.
Complexity:
- Time: O(V² * log V + V * E)
- Space: O(V²)
Real World Application:
Finding all‐pairs shortest routes in a continental airline network where some legs may have negative‐adjusted costs due to rebates or codeshares—Johnson’s scales better than Floyd-Warshall on sparse graphs.
Complexity Comparison of Shortest Path Algorithms
Algorithm | Time Complexity | Space Complexity |
DFS | O(V) | O(V) |
BFS | O(V + E) | O(V) |
Multi-Source BFS | O(V + E) | O(V) |
Dijkstra’s Algorithm | O(E * log V) | O(V) |
Bellman-Ford Algorithm | O(V * E) | O(V) |
Topological Sort (DAG) | O(V + E) | O(V) |
Floyd-Warshall | O(V³) | O(V²) |
A* Search Algorithm | O(E * log V) | O(V) |
Johnson’s Algorithm | O(V² * log V + V * E) | O(V²) |
Real World Applications of Shortest Path Algorithms
1. GPS Navigation
Shortest path algorithms like Dijkstra or A* help GPS systems find the quickest or most efficient route from your location to a destination, considering traffic and road conditions.
2. Network Routing
In computer networks, routers use shortest path algorithms (e.g., OSPF with Dijkstra) to determine the most efficient path for data packets to travel across the internet.
3. Transportation Planning
City planners and logistics companies use these algorithms to optimize traffic flow, reduce travel time, and plan public transportation routes efficiently.
4. Airline Flight Planning
Airlines use shortest path algorithms to determine the most efficient flight paths between cities, minimizing fuel costs and travel time while considering air traffic and regulations.
5. Social Network Analysis
In platforms like Facebook or LinkedIn, shortest path algorithms are used to find degrees of separation between users or suggest connections through mutual friends.
6. Circuit Design
In VLSI and PCB design, shortest path algorithms help in laying out the shortest connections between components to minimize delay and material usage.
Frequently Asked Questions (FAQs)
Which course should I take to learn shortest path algorithms deeply?
To get a thorough understanding of shortest path algorithms and other essential data structures, consider enrolling in the comprehensive DSA course.
Are there courses that combine Data Structures, Web Development, and System Design?
Yes! The Master DSA, Web Dev & System Design course is perfect for learners who want to cover all these topics in one place.
I am interested in web development but want to understand algorithms too. What do you suggest?
The Web Development course also includes essential programming concepts and algorithm basics useful for frontend and backend development.
Can I learn both design and algorithms in a combined course?
Absolutely! The Design and DSA combined course offers a blend of system design and data structure knowledge, great for interview prep.
I want to explore data science along with algorithm skills. Any course recommendations?
For those interested in data science, check out the Data Science course which covers algorithms applied in the data field.
Start learning now and stay ahead with the latest updates by signing up for free courses and notifications today!

DSA, High & Low Level System Designs
- 85+ Live Classes & Recordings
- 24*7 Live Doubt Support
- 400+ DSA Practice Questions
- Comprehensive Notes
- HackerRank Tests & Quizzes
- Topic-wise Quizzes
- Case Studies
- Access to Global Peer Community
Buy for 60% OFF
₹25,000.00 ₹9,999.00
Accelerate your Path to a Product based Career
Boost your career or get hired at top product-based companies by joining our expertly crafted courses. Gain practical skills and real-world knowledge to help you succeed.

Low & High Level System Design
- 20+ Live Classes & Recordings
- 24*7 Live Doubt Support
- Case Studies
- Comprehensive Notes
- HackerRank Tests
- Topic-wise Quizzes
- Access to Global Peer Community
- Interview Prep Material
Buy for 65% OFF
₹20,000.00 ₹6,999.00

Design Patterns Bootcamp
- Live Classes & Recordings
- 24/7 Live Doubt Support
- Practice Questions
- Case Studies
- Access to Global Peer Community
- Topic wise Quizzes
- Referrals
- Certificate of Completion
Buy for 50% OFF
₹2,000.00 ₹999.00

LLD Bootcamp
- 7+ Live Classes & Recordings
- Practice Questions
- 24/7 Live Doubt Support
- Case Studies
- Topic wise Quizzes
- Access to Global Peer Community
- Certificate of Completion
- Referrals
Buy for 50% OFF
₹2,000.00 ₹999.00

Essentials of Machine Learning and Artificial Intelligence
- 65+ Live Classes & Recordings
- 24*7 Live Doubt Support
- 22+ Hands-on Live Projects & Deployments
- Comprehensive Notes
- Topic-wise Quizzes
- Case Studies
- Access to Global Peer Community
- Interview Prep Material
Buy for 65% OFF
₹20,000.00 ₹6,999.00

Fast-Track to Full Spectrum Software Engineering
- 120+ Live Classes & Recordings
- 24*7 Live Doubt Support
- 400+ DSA Practice Questions
- Comprehensive Notes
- HackerRank Tests & Quizzes
- 12+ live Projects & Deployments
- Case Studies
- Access to Global Peer Community
Buy for 57% OFF
₹35,000.00 ₹14,999.00

DSA, High & Low Level System Designs
- 85+ Live Classes & Recordings
- 24*7 Live Doubt Support
- 400+ DSA Practice Questions
- Comprehensive Notes
- HackerRank Tests & Quizzes
- Topic-wise Quizzes
- Case Studies
- Access to Global Peer Community
Buy for 60% OFF
₹25,000.00 ₹9,999.00
Reach Out Now
If you have any queries, please fill out this form. We will surely reach out to you.
Contact Email
Reach us at the following email address.
Phone Number
You can reach us by phone as well.
+91-97737 28034
Our Location
Rohini, Sector-3, Delhi-110085