Domanda

What is the most efficient data structure among these there:

  • Edge list
  • Adjacency list
  • Adjacency matrix

for executing Prim-Jarnik's algorithm and why?

È stato utile?

Soluzione

By edge list I suppose you mean the list of all edges in a graph G ? Then that is the slowest of the three since you would need to traverse the entire list each time you are at a vertice u just to know which (u, v) pairs are in G. Adjacency matrix is somewhat faster than that, but still slow since you will need to traverse an entire row of the matrix to find the adjacent vertices and the respective edge weights. But if you have a dense graph, the adjacency matrix is just like an adjacency list. Adjacency list is the faster one supposing a not so dense graph such that traversing the list isn't more costly than directly accessing each column in the matrix row.

Said that, the key issue in Prim's algorithm is not actually this. To achieve its described computational complexity, you need to use a priority queue (and this is the part you should be concerned).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top