-- May 1 In-Class Exercise
1. For this graph, we can check if the triangle inequality is true by seeing if for any set of three edges, the sum of any of the two should be greater than the third edge.
Since the weight of each edge is calculated by i+j, where i and j are vertices, then assuming that we have three vertices i, j, k, then i+j will always be less than [(i+k) + (j+k)], unless any of i,j or k are less than 1, which is not possible in our problem.
2. Then we can use Prim's algorithm to compute the minimal spanning tree by first constructing a priority queue of all vertices. We traverse this vertex to vertex, removing edges once we have visited them and before we move.
So our queue would look like,
{(1,0), (2,inf), (3,inf), (4,inf)}
{(2,3), (3,4), (4,5)}
{(3,4), (4,5)}
{(4,5)}
We go from 1 -> 2 -> 3 -> 4 -> 1, so in this case it is a Hamiltonian cycle.
1. For this graph, we can check if the triangle inequality is true by seeing if for any set of three edges, the sum of any of the two should be greater than the third edge.
Since the weight of each edge is calculated by i+j, where i and j are vertices, then assuming that we have three vertices i, j, k, then i+j will always be less than [(i+k) + (j+k)], unless any of i,j or k are less than 1, which is not possible in our problem.
2. Then we can use Prim's algorithm to compute the minimal spanning tree by first constructing a priority queue of all vertices. We traverse this vertex to vertex, removing edges once we have visited them and before we move.
So our queue would look like,
{(1,0), (2,inf), (3,inf), (4,inf)}
{(2,3), (3,4), (4,5)}
{(3,4), (4,5)}
{(4,5)}
We go from 1 -> 2 -> 3 -> 4 -> 1, so in this case it is a Hamiltonian cycle.