0

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}};
Garnica1999
  • 215
  • 2
  • 12
  • 1
    Here you go: `O(program) = (O(Node::addNodeToList) + O(sortArray) + O(Roads::add) + O(Node::getNode) + O(Node::getPese) + O(clear)) * O(loop_count)` – jrook Oct 25 '18 at 06:45
  • @jrook The result of this operation is the maximum of each certain instruction? That is, `Omax (Node::addNodeToList, sortArray, Roads::add, Node::getNode, Node::getPece, clear, loop_count)`, Am I right? – Garnica1999 Oct 25 '18 at 07:39
  • Ummm...I guess my point is you can't calculate time complexity of a prgoram without a detailed description of the steps that program is taking during the course of its execution. Try to give a clear pseudocode representation of the algorithm in which the data structures and algorithms are clearly identified. – jrook Oct 25 '18 at 14:49

0 Answers0