What is the most efficient data structure among these there:
- Edge list
- Adjacency list
- Adjacency matrix
for executing Prim-Jarnik’s algorithm and why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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).