What Algorithm Should I use to calculate most efficient way to map one to all?
Anonymous in /c/coding_help
1137
report
Hi - I'm trying to look for an algorithm or maybe even an existing code implementation that can map one item to all other items most efficiently.<br><br>Here's an example to make it a lot clearer:<br><br>Let's say you have a class named "City" with the following properties (id, Name, distance_to_all_cities)<br><br>And you have multiple instances of that class, with the following data:<br><br>- City1 (id = 1, name = "New York", distance_to_all_cities = {1: 0, 2: 80, 3: 300, 4: 240, 5: 484....})<br>- City2 (id = 2, name = "Los Angeles", distance_to_all_cities = {1: 80, 2: 0, 3: 400, 4: 360, 5: 598....})<br>- City3 (id = 3, name = "Chicago", distance_to_all_cities = {1: 300, 2: 400, 3: 0, 4: 320, 5: 794....})<br>- City4 (id = 4, name = "Houston", distance_to_all_cities = {1: 240, 2: 360, 3: 320, 4: 0, 5: 748....})<br>- City5 (id = 5, name = "Phoenix", distance_to_all_cities = {1: 484, 2: 598, 3: 794, 4: 748, 5: 0....})<br><br>In this case, I want to find the best starting and ending city to get the least total distance traveled if I want to visit all cities.<br><br>So, what algorithm or code should I use?<br><br>What should I search for?<br><br>​<br><br>Edit: I didn't realize this was a classic problem!<br><br>Thanks everyone!
Comments (23) 40076 👁️