 In this video, we provide the solution to question number 15 for practice exam number one for math 1030, in which case we're given a weighted complete graph K5 right here. We're asked to solve the traveling salesman problem using the repeated nearest neighbor algorithm. We gotta try every vertex as a starting point. So if we start at A, what is gonna happen here? So we go from at A, the nearest neighbor is going to be D, which is 185. We can write that down in just a second. At D, the nearest neighbor, let's say we got 320, 360, 302, so we'd come over to E, like so. At E, the nearest neighbor would be C, which costs 165. At C, you'd have to go to B for 305 and then you go back to A. So you're gonna construct that path right there. Let's write that thing down. So we're gonna go from A to D to E to C to B to A, which then has a cost of 185 plus 302 plus, just looking at the graph here and copying these down, 165 plus 305 plus 300, which then cost 1,457, so that's one option. The next options we do, we start at B, okay? So starting at B, let's say we have 305, 360, 345, 100, so 305 is the best option there. Then at C, the cheapest option is 165, so we take that one. At E, the cheapest option is 205, we go there. At A, we can't go back to C yet, so we can't use that one, but obviously 185 is cheaper anyways. So we go to D and then we're gonna go back to B of that situation. So our circuit's gonna look like B to C to E to A to D back to B. So let's write that down. So we go from D to C to E to A to D to B, to B, not eight, I don't know if that was. So we're gonna get 305 plus 165 plus 205 plus 185 plus 360, just adding up the weights of the edges we used in that circuit. And that's gonna add up to be 1,220, all right? So next we have to look at what happens if we start here at C, right? From C, let's even put this over here, starting at C now. At C, the nearest neighbor is E at 165. At E, the nearest neighbor is 205 to A. At A, the nearest neighbor is D at 185, for which then you have to go to B and then go back to C at that point. So our circuit turned out to be C to E to A to D to B to back to C, so let's write that down. So we get C to E to A to D to B to C like so, for which I want you to note that the thing we just did here, this is the exact same path, C to E to A to D to B to C. That's the exact same path we just did a moment ago, so I'm just gonna put an official ditto right there. That one also costs 1220, all right? So then if we try the next one, we're gonna start at D this time. So starting here, we take the nearest neighbor, which is going to be going to A, which is 185. Then at A we're gonna go to C, which costs 200. At C we're gonna go to E, which costs 165. Then we're gonna go to B, which costs 340, and then from B we go back to D, which costs 360. That does seem to give us a new path. I don't think we've done that one yet. So D, what do we say? We go from D to A, from A to C, from C to E, from E to B, and then back to D. Now what's gonna cost 185 plus 200 plus, we're gonna get 165, just looking at the graph there, 165 plus 340 plus 360. That adds up to be 1250, all right? So notice like these ones are losing so far. The ones that started B and C so far are the best ones. Give myself a little bit more space here so we can squeeze in this final attempt. We have to also start it at E. So if we start at E, the cheapest option is go to C for 165. Then at C we go to A for 200. At A we go to D for 185. At D we have to go to B for 360, and then at B we have to go back to E for 340. That's just the star in the middle again. That's the one we just did, right? So I do need to list that out there. We went from E to C to A to D to B to E. But again, that was just the star in the middle. That's gonna cost the exact same amount. So that's just gonna give you 1250 again, which didn't work. So it turns out that the correct answer, the best answer is gonna be start at B or C and the suboptimal tour we got was 1220. So that circuit illustrated right there. Let's draw it on the board one more time here. So we go from B to C to E to A to D to B. That is the optimal. I should say that's the best Hamilton circuit that the nearest neighbor algorithm will produce.