 The graph concept can be extended in several ways. In an edge-weighted graph, each edge is assigned a weight or a cost, or you might think about this as a distance. Taking the edge incurs the cost, and so a question we can ask, what path between nodes has the least cost? So let's introduce the idea of an algorithm. An algorithm is a systematic procedure that solves a problem. Taking an algorithm requires ingenuity and imagination. Following an algorithm, on the other hand, requires blind obedience to orders. Humans are good at ingenuity and imagination. Humans are also good at blind obedience to orders, but we don't want to encourage this. The important idea to keep in mind is that once we produce an algorithm to solve a problem, a machine can solve the problem faster, more accurately, and more cheaply than any human. What this means is that any task that can be reduced to an algorithm can and will be done by a machine, and so it is not worth learning algorithms at the expense of understanding. Now that doesn't mean you shouldn't learn algorithms, this will be on the test, but it does mean that you should also understand why they work, because understanding why something works is the key to making it better. The advantage of a human side is that humans do things without knowing how they do it. For example, find the shortest path. If we give a human the task of finding the shortest path, they can probably do it quickly without difficulty, but they would have a hard time describing how they do it. In order to create an algorithm, we have to consider how we make our choices. Now before we go on one important idea about our creation of algorithms, in 1950 computer scientist Alan Turing described what he called the imitation game, but would later be called the Turing test. Reduced to its essentials, we don't care if a computer solves problems the same way we do, it only matters that it gets the same answers we would. So we don't have to describe how we would solve the problem, rather we can focus on whether the problem has been solved. Now because computers can do things very, very, very, very quickly, it's tempting to use what's called a brute force algorithm, try every possible answer, and see which one works. Unfortunately most problems have too many possible answers for a brute force algorithm to be useful. It would take a computer longer than the lifetime of the universe to try every possible answer to certain questions. So one way humans make decisions is they look around and say what's the best possible decision I could make right at this instant. And this leads to what's called a greedy algorithm. In a greedy algorithm we make the best possible decision at the instant we have to make the decision. And what's important here is that we're not considering the long term consequences of our decision. Now in this case if we want to minimize the distance, this means we should take the shortest path from wherever we are. Now one risk that we have whenever we describe an algorithm, because an algorithm describes a sequence of steps to be followed without deviation, we do run the risk that that sequence of steps will trap us into a loop. And so to avoid cycling we'll also require that the vertex be one we haven't visited. So let's apply a greedy algorithm to find the shortest path from A to H. So we'll start at A, and if we want to take the shortest path from a node that doesn't go to a node we've been to, from A we could go to either B, distance 15, or C, distance 6. And since we want to take the shortest path we'll go to C. Now we're at C. Well if we're at C we can go to B, distance 7, E, distance 8, G, distance 15, or F, distance 12. And since we're being greedy we go to B which has the shortest distance. Now from B we can go to D, distance 12, or E, distance 6. So we go to E which has the shortest distance. The only path from E that takes us to a new node is the path to H which is where we want to go anyway. And so our last leg is going to go from E to H and our total distance A to C is 6, C to B is 7, B to E is 6, and E to H is 10 for a total distance of 29.