Search code examples
dynamic-programming

Dynamic Programming: find the minimal route with ten nodes from a set of 100 nodes


You are given 100 stations and distance between each adjacent stations. Now you have to select 10 stations(means 10 hops) among those 100 stations in such a way that maximum of distance between any 2 hops will be minimised. By default 1 and 100 stations are selected , so you need to choose only 8 more stations.


Solution

  • Since you haven't told us:

    • I'll assume time isn't an issue
    • I'll assume memory isn't an issue.
    • I'll assume the answer isn't programming language specific
    • I'll assume you are aiming to get from one station (1) to a destination station (100)
    //Iterate through all possible paths to destination
    
    //If you take more than 8 steps, stop and go back
    
    //Note the total length of each path
    
    //Select the shortest path