Chat with us, powered by LiveChat Need to be done in java Add a code in the given code// Subodh Shrestha // CSCI308 Fall 2021 21F // Date: 11/22/2021 Time:3:3 - Essayabode

Need to be done in java Add a code in the given code// Subodh Shrestha // CSCI308 Fall 2021 21F // Date: 11/22/2021 Time:3:3

Need to be done in java

Add a code in the given code// Subodh Shrestha
// CSCI308 Fall 2021 21F
// Date: 11/22/2021 Time:3:30PM
package djkstrashortestpath_shrestha;

class DsAlgorithm
{
   //1.Find the shortest path for all of the given vertices:
   //  We have not visited yet.
   // Note:  If the vertex is marked as true, we have visited it.
   //2. Update the distance value of all neighboring vertices
   //   of the selected vertex
   //3. Update distance[loc] if and only if it is not in the
   //   PathArray, there is an shorter path from source to the vertex at loc.
   
   public static int[] Dijkstra(int graph[][],
           int s, int distanceArr[], int VNum)
       {
       //PathArray[j] will be true if the given vertex j
       //is included in the shortest path tree from origin to j
       Boolean PathArray[] = new Boolean[VNum];
   
       // Initializing distance = INFINITE PathArray[] = false
       for(int j = 0; j < VNum; j++)
       {
           distanceArr[j] = Integer.MAX_VALUE;
           PathArray[j] = false;
       }
   
       distanceArr[s] = 0; // node to self distance is 0

       for(int i = 0; i < VNum – 1; i++)
       {
           int minIndex = minimumDistance(distanceArr, PathArray, VNum);

           PathArray[minIndex] = true;

           for(int j =0; j < VNum; j++)
               {
               if(!PathArray[j] && graph[minIndex][j] != -1
                && distanceArr[minIndex] != Integer.MAX_VALUE
                && distanceArr[minIndex]
                + graph[minIndex][j] < distanceArr[j])
                   {   
                       distanceArr[j] = distanceArr[minIndex] + graph[minIndex][j];
                   }
               }
           }
       return distanceArr;
       }
           
   //Compute the min distance value between a vertex and other verticies.
   public static int minimumDistance(int distance[],
                   Boolean PathArray[], int VNum)
   {
       //Let the min be an integer max value and the index begin with -1
       int minimum = Integer.MAX_VALUE;
       int MinimumIndex = -1;

       for(int i =0; i< VNum; i++)
       {
       // compare values and keep the minimum
           if (PathArray[i] == false && distance[i] <= minimum)
           {
               minimum = distance[i];
               MinimumIndex = i;
           }
       }
       return MinimumIndex;
   }
}

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?