Do you know, all these algorithms are somehow related to our daily life! Don't beleive? Let's have a quick demonstartion.
For some moments Stop thinking about any algorithms and look at this diagram.
Do you know, all these algorithms are somehow related to our daily life! Don't beleive? Let's have a quick demonstartion.
For some moments Stop thinking about any algorithms and look at this diagram.
Suppose you’re travelling from your office to your home and you want to reach as soon as possible, then which path will you choose? Think for a while.
Ok, now let's look at the diagram below.
If I’m not wrong, you might have thought about this path, which seems the shortest among all, right? If it is right then you’ve just tried to be greedy.
In this way, we as a human, decide which case/path is best for us. Now let's think from an computer's perspective. I think you all have played Counter Strike! Have you ever wondered how an enemy agent finds the location of the player in the Game World?
This is where Algorithms comes into play. In games, best-first search may be used as a path-finding algorithm for game characters.
Greedy best-first search tries to expand the node that is closest to the goal, on the grounds that it is likely to lead to a solution quickly. Thus, it evaluates nodes by using just the heuristic function; that is, f(n)=h(n).
Let us see how this works for the route-finding problems. Here we use the straight-line distance heuristic, which we will call hSLD. If the goal node is I, we need to know the straight-line distances to the node I, which is shown below:
The first node to be expanded from A will be B because it is closer to I than either B or C. The next node to be expanded will be F because it is closest. F, in turn, generates I, which is the goal. For this particular problem, greedy best-first search using hSLD finds a solution without ever expanding a node that is not on the solution path; hence, its search cost is minimal. This shows why the algorithm is called "Greedy" - at each step it tries to get as close to the goal as it can.
Instructions!
5
7
6
S
3
6
6
9
4
2
4
2
3
2
3
4
4
7
6
5
5
3
5
7
2
1
2
F
2
3
2
3
9
9
5
6
5