Complete BLoC with Clean Architecture (group chat) Discount !! E-commerce App With Backend Source Code Video and Voice Chatting App Firebase Chatting App Source Code Complete Gym App BLoC State Management Source Code Complete Study App Buy Ticket Booking App Source Code Buy Travel App With Backend Source Code Complete Chat App Udemy Course Special Offer Discount !! Online Learning Course App (BLoC) Online Learning Course App (Riverpod) Online Learning Course App (Getx) Discount !! Shopping App (Provider) Cool Flutter Game Flutter Nodejs Chat App Flutter Nodejs Api And Firebase Chat App Riverpod Task Management App
A * or A-star algorithm is another basic for finding shortest path in a graph. This algorithm is used in maps or games a lot.
There are three different parameters are used to find the shortest path using A* or A-star algorithm. These are called g, h, f. Let's see their definition
g: This is used for finding the cost from initial node to the current node. As we traverse through the nodes, this value always gets increased since this is the summation of all the previous costs.
h: This is used to describe the cost from the corrent node to the final or goal node. This values always gets decreased as we move from the current node to goal node.
f: This is the total cost for going to the final node. This is the summation of the previous two parameters. So f = g + h
Since g and h are always changable during the traversal, f is always changable. So we have to recalculate f all the time.
Let's see in detail how it works.
From the above video you see that we reach from node A to node E.
From A to C the f value is 3, but from A to B the f value is 4. So A to C path is choosen as shortest path. When we start from node A to C, the current cost 1 that is g value, and from C to E the value is 2, so total f value at node C is 1+2=3.
But from node A to B the value is 2+2=4. So this node path is not choosen.