I would like to know how to extract the complexity of this algorithm, based on dynamic programming and the traveling agent:
do{
this.addNodeToList(actual, cost);
this.sortArray();
Node node = this.arrayElements.get(0);
roads.add(node.getNode());
actual = node.getNode();
totalCost += node.getPese();
arrayElements.clear();
x++;
}while(actual != begin);
The actual
variable is the node where the program is stopped, and evaluates its neighbors, the begin
variable is the beginning of the route, begin
is inialized in 0, the algorithm starts from the end, that is, from graph.length-1
What the next algorithm does as such is to find the path of least cost, based on the principle of dynamic programming. The problem is that n is not the number of edges of the graph, because although a graph has n nodes, the complexity varies depending on the number of connections of the graph, according to my analysis
Is this true? Even, it can also be affected by the best case, the average case and the worst case of all, but I can not think of how to get them out.
The definition of the cost graph is as follows:
private static final int graph[][] = {
{0, 85, 52, 45, 0, 0, 0, 0, 0, 0, 0, 0},
{85, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 0},
{52, 0, 0, 0, 45, 28, 0, 0, 0, 0, 0, 0},
{45, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0},
{0, 18, 45, 0, 0, 0, 15, 19, 0, 0, 0, 0},
{0, 0, 28, 15, 0, 0, 30, 15, 0, 0, 0, 0},
{0, 0, 0, 0, 15, 30, 0, 0, 43, 23, 0, 0},
{0, 0, 0, 0, 19, 15, 0, 0, 0, 13, 35, 0},
{0, 0, 0, 0, 0, 0, 43, 0, 0, 0, 0, 40},
{0, 0, 0, 0, 0, 0, 23, 13, 0, 0, 0, 25},
{0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 45},
{0, 0, 0, 0, 0, 0, 0, 0, 40, 25, 45, 0}};