|
1 | | -package com.thealgorithms.graph; |
| 1 | +package com.thealgorithms.graphs; |
2 | 2 |
|
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.Collections; |
|
7 | 7 | import java.util.List; |
8 | 8 | import java.util.Map; |
9 | 9 | import java.util.PriorityQueue; |
10 | | -import java.util.Set; |
11 | 10 | import java.util.Scanner; |
| 11 | +import java.util.Set; |
12 | 12 |
|
13 | 13 | /** |
14 | | - * Implementation of the A* Search Algorithm for shortest pathfinding. |
| 14 | + * Implementation of the A* Search Algorithm for shortest path finding. |
15 | 15 | * |
16 | 16 | * <p> |
17 | | - * A* combines Dijkstra’s algorithm with a heuristic to efficiently find the |
| 17 | + * A* combines Dijkstra's algorithm with a heuristic to efficiently find the |
18 | 18 | * shortest path in weighted graphs. |
19 | 19 | * </p> |
20 | 20 | * |
|
23 | 23 | * </p> |
24 | 24 | * |
25 | 25 | * <p> |
26 | | - * Time Complexity: O(E + V log V) with a binary heap priority queue.<br> |
| 26 | + * Time Complexity: O(E + V log V) with a binary heap priority queue. |
27 | 27 | * Space Complexity: O(V + E) |
28 | 28 | * </p> |
29 | 29 | */ |
30 | 30 | public class AStarSearch { |
31 | 31 |
|
32 | 32 | private static class Node implements Comparable<Node> { |
33 | | - int id; |
34 | | - double g; // cost from start |
35 | | - double h; // heuristic to goal |
36 | | - double f; // total cost = g + h |
37 | | - Node parent; |
| 33 | + private final int id; |
| 34 | + private final double g; // cost from start |
| 35 | + private final double h; // heuristic to goal |
| 36 | + private final double f; // total cost = g + h |
| 37 | + private final Node parent; |
38 | 38 |
|
39 | 39 | Node(int id, double g, double h, Node parent) { |
40 | 40 | this.id = id; |
@@ -65,8 +65,8 @@ public AStarSearch() { |
65 | 65 | * @param weight edge weight |
66 | 66 | */ |
67 | 67 | public void addEdge(int u, int v, int weight) { |
68 | | - graph.computeIfAbsent(u, k -> new ArrayList<>()).add(new int[]{v, weight}); |
69 | | - graph.computeIfAbsent(v, k -> new ArrayList<>()).add(new int[]{u, weight}); |
| 68 | + graph.computeIfAbsent(u, k -> new ArrayList<>()).add(new int[] {v, weight}); |
| 69 | + graph.computeIfAbsent(v, k -> new ArrayList<>()).add(new int[] {u, weight}); |
70 | 70 | } |
71 | 71 |
|
72 | 72 | /** |
|
0 commit comments