Find the minimum cost path from a designated start node to

Assignment Help Data Structure & Algorithms
Reference no: EM13350607

Find the Minimum Cost Path from a designated start node to a designated destination node in a graph.

ASSUMPTIONS:

• graph is already stored, including:
1) n, which is the number of graph nodes (where node are numbered 0 to N-1, not 1 to N)
2) edgeWeight - stored as EITHER:

  • an adjacency matrix with 3 possible types of values:
  • actual edge weights, 2) 0's in the diagonal, 3) "infinity" (i.e., MaxValue) for "no edge" node-pairs [conventionally, directed graphs use rowNumber as the source ("from") & columnNumber as the sink ("to")]
  • an array of adjacency lists

• GetWeight(a,b) method returns the numeric weight value for edge <a,b> from the stored graph - for

  • internal AdjacencyMatrix: use direct address to get edgeWeight[a,b] (or edgeWeight[a][b])
  • external AdjacencyMatrix: use direct address to read weight (after calculating offset, and seek-ing) [When calculating offset, allow for: a) headerRec; b) nodeNumbers being 0 to N=1, not 1 to N; c) weights being int or short or long or double... (as specified). So at start of program, calculate sizeOfHeaderRec, sizeOfARow, sizeOfAWeight once and for all to use in individual offset calculation each seek]
  • internal AdjacencyLists: search linkedList[a]for node b to get its weight [not vice versa, so as to accommodate directed graph]

• program has already gotten "from user": startNodeNumber & destinationNodeNumber (integers from 0 to N-1) [if user instead provides startNodeName & destinationNodeName, then these have been converted into corresponding 2 Numbers]

THE ALGORITHM

A) Initialize the 3 "working storage" arrays:

• included - booleans ["Is thisNode included yet in the group of nodes already used to revise distance . . . or not?"]

- set all to false, except start's included is set to true

• distance - integers (usually) ["What's the distance from start to thisNode SO FAR?"
- set each to its corresponding edgeWeight from the graph for start to thisNode which would be either: 1) weight for an actual edge OR 2) 0 for [start] OR 3) "infinity" for no-edge cases

• path - integers ["What's the nodeNumber of thisNode's predecessor on the path from start to thisNode?"

- set all to -1's, except use startNodeNumber instead when distance[i] has an actual edge weight

B) Do the Search: [Algorithm handles "normal case" - check if changes are needed for "special case", e.g., start == destination]
while destination is NOT yet included {

1. out of nodes NOT yet included, choose target node (its node number) as the node with the minimum distance value [target is a subscript not a distance]
2. target now becomes included [as having been evaluated in step 3 below, to see it's effect]
3. check all distance values [they're ceilings] to see which ones can be lowered [i.e., loop: i = 0 to N-1]

if included[i] is false [GUARD #1 against doing the BIG TEST unnecessarily]
if edgeWeight from target to i is a valid edgeWeight [GUARD#2 against doing ...]
[as opposed to a non-edge of 0 or "infinity"]
[Finally comes the "BIG TEST" - i.e., should distance[i] ceiling be lowered?]
if distance[target] + edgeWeight from target to i < distance[i]
then: 1) distance[i] = distance[target] + edgeWeight from target to i
2) path[i] = target
}

C) Report the answer:

• TOTAL DISTANCE of the minimum path from start to destination is found in distance[destination]

• FINAL PATH itself from start to destination is gotten from following the values in path array from [destination] to -1.

However, this gives the path in reverse order, from destination to start.

To instead correctly report the path from start to destination, either use:

o recursion - printing the results on the way back UP recursion
o OR push answers on a stack instead of printing them, then pop them off the stack to print them
o OR store them to an array (incrementing, starting at 0), then print the array in reverse (decrementing, stopping at 0).

Reference no: EM13350607

Questions Cloud

Metropolis toys metropolis toys is an independent : metropolis toys metropolis toys is an independent family-owned manufacturer of wooden toys. the toys are designed by
Question 1 explain five types of information systems and : question 1. explain five types of information systems and give an example of each.question 2. describe three common
A marketing plan for lawn care a landscaping design : a marketing plan for lawn care a landscaping design servicemy project all in lawn care will offer regular services will
Select the marketing industry then write about the dream : select the marketing industry then write about the dream job within the marketing industry.what skills will you develop
Find the minimum cost path from a designated start node to : find the minimum cost path from a designated start node to a designated destination node in a graph.assumptions bull
An asynchronous sequential logic circuit is given on page : an asynchronous sequential logic circuit is given on page by its primitive flow map i.e. initial state table where x1
1 polymer diffusion the figure below shows the result of a : 1 polymer diffusion the figure below shows the result of a particle tracking experiment where lateral positions of
Part a - performance objectivereport and monitor : part a - performance objectivereport and monitor expenditure and compare with financial plans so that recommendations
Metropolitan city church managementmetropolitan city church : metropolitan city church managementmetropolitan city church management mccm has hired you as a consultant to modernize

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Inventory tracking database

Construct a relational database of your choice. The DB should contain no more than six tables. Define three business requirements that this database will provide.

  Write an algorithm to count nodes in a linked list

storage pool and that there is a special null value. Write an algorithm to count the nodes in a linked list with first node pointed to by first."

  Calculations on rows and columns of an array

Make a menu bar with a document menu that includes a Perform Action command and an Exit command. The Perform Action command calculates either the sum or the average of rows or columns in array and displays result in a message box.

  Java program to make choice for a coffee cup size

Create an application that prompts the user to make a choice for a Coffee cup size, S for Small, T for Tall, G for Grande and V for Venti the rates of cup sizes will be stored in a parallel double array as $2, $2.50, $3.25, and $4.50 respectively.

  Questionm about distributed database

Explain what a distributed database is and how replication works with respect to managing the information in these databases.

  Sorting arrays of name in descending order

Then sort arrays so that records are in descending order by purchase amount for month. Output lists the names of the top five customers.

  Describe an algorithm to play the game of nim

Describe an algorithm to play the Game of Nim using all of the three tools discussed in class (pseudocode, flowchart, hierarchy chart).

  Solving information technology question

XYZ Corporation has a small office with eighty users in California. The office employs a file and print server that caters to user requests.

  Entity relationship diagrams

Discuss why are Entity Relationship Diagrams an important initial stage in developing databases? Who would be the initial parties interacting to develop the ERDs?

  Data structures assignment requiring c++ program

You should build enough new roads such that if City A was reachable from City B via some old roads, City A must be reachable from City B via some new roads.

  Create the entity relationship diagram

Create the entity relationship diagram for your project database based on the initial data requirements.

  Question about designing a database

As we start designing a database for implementation should we use the latest and greatest technology? Does the user need a flat-file or object-oriented database?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd