DSA Explorer
QuicksortMerge SortBubble SortInsertion SortSelection SortHeap SortCounting SortRadix SortBucket SortShell SortTim SortCocktail Shaker SortComb SortGnome SortPancake SortPatience SortCycle SortStrand SortWiggle Sort (Wave Sort)Bead Sort (Gravity Sort)Binary Insertion SortBitonic SortBogo Sort (Stupid Sort)Stooge SortOdd-Even Sort (Brick Sort)Pigeonhole SortIntro Sort (Introspective Sort)Tree Sort (BST Sort)Dutch National Flag (3-Way Partitioning)
Binary SearchLinear SearchJump SearchInterpolation SearchExponential SearchTernary SearchFibonacci SearchQuick Select (k-th Smallest)Median of Medians (Deterministic Select)Hill climbingSimulated AnnealingTabu SearchBinary Tree DFS SearchSentinel Linear SearchDouble Linear SearchTernary Search (Unimodal Function)Search in 2D Matrix
Binary Search Tree (BST)StackQueueHash Table (Hash Map)Heap (Priority Queue)Linked ListTrie (Prefix Tree)Binary TreeTrie (Prefix Tree)Floyd's Cycle Detection (Tortoise and Hare)Merge Two Sorted Linked ListsCheck if Linked List is PalindromeFind Middle of Linked ListBalanced Parentheses (Valid Parentheses)Next Greater ElementInfix to Postfix ConversionMin Stack (O(1) getMin)Largest Rectangle in HistogramDaily Temperatures (Monotonic Stack)Evaluate Reverse Polish NotationInfix Expression Evaluation (Two Stacks)Min Heap & Max HeapSliding Window MaximumTrapping Rain WaterRotate Matrix 90 DegreesSpiral Matrix TraversalSet Matrix ZeroesHash Table with ChainingOpen Addressing (Linear Probing)Double HashingCuckoo Hashing
Depth-First Search (DFS)Breadth-First Search (BFS)Dijkstra's AlgorithmFloyd-Warshall AlgorithmKruskal's AlgorithmPrim's AlgorithmTopological SortA* Pathfinding AlgorithmKahn's Algorithm (Topological Sort)Ford-Fulkerson Max FlowEulerian Path/CircuitBipartite Graph CheckBorůvka's Algorithm (MST)Bidirectional DijkstraPageRank AlgorithmBellman-Ford AlgorithmTarjan's Strongly Connected ComponentsArticulation Points (Cut Vertices)Find Bridges (Cut Edges)Articulation Points (Cut Vertices)Finding Bridges (Cut Edges)
0/1 Knapsack ProblemLongest Common Subsequence (LCS)Edit Distance (Levenshtein Distance)Longest Increasing Subsequence (LIS)Coin Change ProblemFibonacci Sequence (DP)Matrix Chain MultiplicationRod Cutting ProblemPalindrome Partitioning (Min Cuts)Subset Sum ProblemWord Break ProblemLongest Palindromic SubsequenceMaximal Square in MatrixInterleaving StringEgg Drop ProblemUnique Paths in GridCoin Change II (Count Ways)Decode WaysWildcard Pattern MatchingRegular Expression MatchingDistinct SubsequencesMaximum Product SubarrayHouse RobberClimbing StairsPartition Equal Subset SumKadane's Algorithm (Maximum Subarray)
A* Search AlgorithmConvex Hull (Graham Scan)Line Segment IntersectionCaesar CipherVigenère CipherRSA EncryptionHuffman CompressionRun-Length Encoding (RLE)Lempel-Ziv-Welch (LZW)Canny Edge DetectionGaussian Blur FilterSobel Edge FilterHarris Corner DetectionHistogram EqualizationMedian FilterLaplacian FilterMorphological ErosionMorphological DilationImage Thresholding (Otsu's Method)Conway's Game of LifeLangton's AntRule 30 Cellular AutomatonFast Fourier Transform (FFT)Butterworth FilterSpectrogram (STFT)
Knuth-Morris-Pratt (KMP) AlgorithmRabin-Karp AlgorithmBoyer-Moore AlgorithmAho-Corasick AlgorithmManacher's AlgorithmSuffix ArraySuffix Tree (Ukkonen's Algorithm)Trie for String MatchingEdit Distance for StringsLCS for String MatchingHamming DistanceJaro-Winkler DistanceDamerau-Levenshtein DistanceBitap Algorithm (Shift-Or, Baeza-Yates-Gonnet)Rolling Hash (Rabin-Karp Hash)Manacher's AlgorithmZ AlgorithmLevenshtein Distance

A* Pathfinding Algorithm

Graph
O(E) with good heuristic time, O(V) space
Advanced

A* (A-star) is a best-first search algorithm that efficiently finds the shortest path between two nodes using both actual cost and a heuristic estimate. Developed by Peter Hart, Nils Nilsson, and Bertram Raphael in 1968, it combines the strengths of Dijkstra's Algorithm (guaranteed shortest path) with Greedy Best-First Search (speed using heuristics). Widely used in game AI, robotics, GPS navigation, and puzzle solving.

Prerequisites:
Graph theory
Priority queues
Heuristic functions
Dijkstra

Visualization

Interactive visualization for A* Pathfinding Algorithm

A* Pathfinding Visualization

Optimal pathfinding using heuristic-guided search with f(n) = g(n) + h(n)

Click cells to add/remove walls

Start
End
Visited
Path

Time Complexity: O(E log V) with binary heap

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

  • g(n): cost from start to current node
  • h(n): heuristic estimate to goal (Manhattan distance)
  • Always expands lowest f-score node
  • Optimal if heuristic is admissible

Interactive visualization with step-by-step execution

Implementation

Language:
1function aStar(graph: Map<string, Array<{node: string; cost: number}>>, 
2                  start: string, goal: string, 
3                  heuristic: (node: string) => number): string[] {
4  const openSet = new Set([start]);
5  const cameFrom = new Map<string, string>();
6  const gScore = new Map<string, number>();
7  const fScore = new Map<string, number>();
8  
9  gScore.set(start, 0);
10  fScore.set(start, heuristic(start));
11  
12  while (openSet.size > 0) {
13    let current = Array.from(openSet).reduce((a, b) => 
14      (fScore.get(a) ?? Infinity) < (fScore.get(b) ?? Infinity) ? a : b
15    );
16    
17    if (current === goal) {
18      const path = [current];
19      while (cameFrom.has(current)) {
20        current = cameFrom.get(current)!;
21        path.unshift(current);
22      }
23      return path;
24    }
25    
26    openSet.delete(current);
27    
28    for (const {node, cost} of graph.get(current) || []) {
29      const tentativeG = (gScore.get(current) ?? Infinity) + cost;
30      
31      if (tentativeG < (gScore.get(node) ?? Infinity)) {
32        cameFrom.set(node, current);
33        gScore.set(node, tentativeG);
34        fScore.set(node, tentativeG + heuristic(node));
35        openSet.add(node);
36      }
37    }
38  }
39  return [];
40}

Deep Dive

Theoretical Foundation

A* evaluates nodes using f(n) = g(n) + h(n), where g(n) is the actual cost from start to node n, and h(n) is the heuristic estimated cost from n to goal. The algorithm maintains an open set (priority queue) of nodes to explore, always selecting the node with lowest f(n). If the heuristic is admissible (never overestimates) and consistent (satisfies triangle inequality), A* guarantees finding the optimal path. Common heuristics include Manhattan distance (grid with 4 directions), Euclidean distance (any direction), and Diagonal distance (8 directions). A* is complete and optimal when h(n) is admissible. With a perfect heuristic, A* expands minimal nodes; with h(n)=0, it becomes Dijkstra.

Complexity

Time

Best

O(E)

Average

O(E)

Worst

O(b^d)

Space

Required

O(V)

Applications

Industry Use

1

Video game AI pathfinding (NPCs, enemies, RTS units)

2

GPS navigation and route planning with traffic

3

Robot motion planning and obstacle avoidance

4

Puzzle solving (15-puzzle, Rubik's cube, Sokoban)

5

Network packet routing with QoS

6

Path planning in autonomous vehicles

7

Maze solving and procedural generation

8

AI planning systems and decision making

9

Logistics and delivery route optimization

Use Cases

Game AI
GPS navigation
Robotics
Puzzle solving

Related Algorithms

Depth-First Search (DFS)

Graph traversal exploring as deep as possible before backtracking. DFS is a fundamental algorithm that uses a stack (either implicitly through recursion or explicitly) to explore graph vertices. It's essential for cycle detection, topological sorting, and pathfinding problems.

Graph

Breadth-First Search (BFS)

Level-by-level graph traversal guaranteeing shortest paths in unweighted graphs. BFS uses a queue to explore vertices level by level, making it optimal for finding shortest paths and solving problems that require exploring nearest neighbors first.

Graph

Dijkstra's Algorithm

Finds shortest path from source to all vertices in weighted graph with non-negative edges. Uses greedy approach with priority queue.

Graph

Floyd-Warshall Algorithm

Floyd-Warshall is an all-pairs shortest path algorithm that finds shortest distances between every pair of vertices in a weighted graph. Unlike Dijkstra (single-source), it computes shortest paths from all vertices to all other vertices simultaneously. The algorithm can handle negative edge weights but not negative cycles. Developed independently by Robert Floyd, Bernard Roy, and Stephen Warshall in the early 1960s.

Graph
DSA Explorer

Master Data Structures and Algorithms through interactive visualizations and detailed explanations. Our platform helps you understand complex concepts with clear examples and real-world applications.

Quick Links

  • About DSA Explorer
  • All Algorithms
  • Data Structures
  • Contact Support

Legal

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • Code of Conduct

Stay Updated

Subscribe to our newsletter for the latest algorithm explanations, coding challenges, and platform updates.

We respect your privacy. Unsubscribe at any time.

© 2026 Momin Studio. All rights reserved.

SitemapAccessibility
v1.0.0