In A * algorithm we choose the node with minimum f ( f = g+h) where g is the distance from start to current node and h is the distance from end to current node.
I implemented A* search in a grid with some obstacles that can traverse up , down ,left , right and at the same time also implemented breadth first search .
I judged the performance of both by finding number of nodes visited by both algorithms and it were same ,no difference was seen.
Now even after applying heuristic in A* search and picking the node with the least f from open list , A* was not efficient as the number of visited nodes was same in both case .
But when i picked node from open list on the basis of minimum h i could see A* performance increased .
Now if h is only sufficient then why f is needed in A* search?
agrupathfinder.azurewebsites.net/ … visit this site here you can easily see the difference in performance of the two algorithms, also if you want the implementation or want to understand the concept behind then you can ask me
the efficiency of A* depends on the heuristics. Of course, it may be the case that gready best first search or even a simple dfs scan fewer positions, but those algorithms do not guarantee that it has found the shortest path. The link agru povided is a nice tool to compare algos
Instead of else it should be else if(tempG<neighbor.g) , there are also other improvements that can be made to reduce the time complexity but the main reason your algorithm is visiting all nodes is because of the else part. Do try this and let me know.
I made it a few months back, you should definitely try and build one as it showcases both , your development skills and algorithmic knowledge as it is very hard to make it efficient with all the visualization, and the features that you can add and change are limitless, you can check the github repository the link of which is present at the bottom of the site to see the code.
A* has a disadvantage as it guess , it estimates g value correctly but the estimation of h value is guessed using heuristic and sometimes that guess may be incorrect leading it to visit maximum cells.
I say my A* algorithm is correct , just because of incorrect guess of h it is visiting maximum cells.
If we want correct h value than it will be lot more time consuming.
So there is not any highly efficient shortest path algorithm , every algorithm has its disadvantage and if we try to make it efficient the cost increases which is another disadvantage.
I understood your code, did you made the change that I told you to made? also do you use discord/telegram/facebook whatsapp? whichever option you are comfortable with share the respective way to connect and we can discuss further. Also you should study dijkstra algorithm first as A* is just a slight modification of that and you can easily find the explanations and code for optimized dijkstra… one such link - Dijkstra on sparse graphs - Algorithms for Competitive Programming