CS 2420 Assignment 5: Min-Cost Spanning Tree using Priority Queues - Prof. Daniel W. Watso, Assignments of Computer Science

Details of assignment 5 for cs 2420, a university course about algorithms and data structures. Students are required to write a function that designs a railroad network at minimum cost using a min-cost spanning tree algorithm based on priority queues. They must write their own priority queue code and fill in the adjacency array with the designed railroad system. The document also includes examples of input and output.

Typology: Assignments

Pre 2010

Uploaded on 07/31/2009

koofers-user-xsj
koofers-user-xsj 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 2420 – Fall 2006
Assignment 5 – 20 points
Due Oct 11, 2006
Railroad Tycoon – Part II
Story Line:
It’s still a wild frontier out there, in the Australian Outback (see the previous assignment). And you still
need to get a set of railroad lines in place. And because money is still an important thing in your life,
you want to make your railroad lines for as little money as possible.
Designing railroads with Prim’s Algorithm using a linear search to find the min-cost edge to add to the
tree is a somewhat time-expensive operation, though. That’s why you are going to employ your new
secret weapon: Priority Queues.
Objective:
Given a set of towns, their locations, and their elevations, write a function that designs a railroad
network designed to service each town at minimum cost, using a min-cost spanning tree algorithm based
on priority queues. For this assignment, you must write your own priority queue code. Thou shalt
borrow not from the book, nor from the standard template library, nor from any other source, save your
brain(s).
Details, details:
You are to read from standard input a list of towns, followed by three integers describing an x and y
coordinate (in kilometers), and an elevation (also in kilometers):
<town name> <x coordinate> <y coordinate> <elevation>
The last town in the list is always called “Zaboonaboon.”
You may assume a maximum number of 50 towns, if you wish.
The cost to create a railroad between two points can be determined by the following equation:
cost(k$) = distance + (10 * distance * sine(elevation_angle) )
For example, two towns 1km from each other on the same elevation could be joined by a railroad for a
cost of 1 Australian kilodollar, but two towns 1km from each other with a height different of 100 meters
would cost roughly 1.995 Australian kilodollars.
CS 2420 – Assignment 5 Page 1
pf3
pf4

Partial preview of the text

Download CS 2420 Assignment 5: Min-Cost Spanning Tree using Priority Queues - Prof. Daniel W. Watso and more Assignments Computer Science in PDF only on Docsity!

CS 2420 – Fall 2006

Assignment 5 – 20 points

Due Oct 11, 2006

Railroad Tycoon – Part II

Story Line:

It’s still a wild frontier out there, in the Australian Outback (see the previous assignment). And you still

need to get a set of railroad lines in place. And because money is still an important thing in your life,

you want to make your railroad lines for as little money as possible.

Designing railroads with Prim’s Algorithm using a linear search to find the min-cost edge to add to the

tree is a somewhat time-expensive operation, though. That’s why you are going to employ your new

secret weapon: Priority Queues.

Objective:

Given a set of towns, their locations, and their elevations, write a function that designs a railroad

network designed to service each town at minimum cost, using a min-cost spanning tree algorithm based

on priority queues. For this assignment, you must write your own priority queue code. Thou shalt

borrow not from the book, nor from the standard template library, nor from any other source, save your

brain(s).

Details, details:

You are to read from standard input a list of towns, followed by three integers describing an x and y

coordinate (in kilometers), and an elevation (also in kilometers):

The last town in the list is always called “Zaboonaboon.”

You may assume a maximum number of 50 towns, if you wish.

The cost to create a railroad between two points can be determined by the following equation:

cost(k$) = distance + (10 * distance * sine(elevation_angle) )

For example, two towns 1km from each other on the same elevation could be joined by a railroad for a

cost of 1 Australian kilodollar, but two towns 1km from each other with a height different of 100 meters

would cost roughly 1.995 Australian kilodollars.

Your function should be given an array of coordinates and elevations, plus an (empty) adjacency array

(plus whatever else you need). It should fill in the adjacency array with the designed railroad system

and return the cost needed to build it. Your program should print to standard output the resulting

adjacency array.

Following the list of towns is a set of town pairs, coming from standard input. Your program should

read in each pair and print out to standard output the distance along your railroad system from one to the

other, along with the names of the cities visited along the way. The last destination in the list of town

pairs is always “Zaboonaboon,” which appears nowhere else in the list.

Questions:

1. Draw the binary expression tree for the expression

(( a  b )( c  e ))|| a  b &&( x  y || y  z )

2. What is the maximum number of nodes in a binary tree that has n nodes?

3. Execute the following sequence of operations on an initially empty binary search

showing the tree after each operation:

Insert(10); Insert(100); Insert(30); Insert(80); Insert(50); Delete(10); Insert(60);

Insert(70); Insert(40); Delete(80); Insert(90); Insert(20); Delete(30); Delete(70);

4. The nodes of a binary tree are labeled a–h. The preorder listing is abcdefgh , and the

inorder listing is cdbaghef. Draw the binary tree. Also, list the nodes of your binary tree

in postorder and level order.

What to turn in:

Include a short narrative of your program in with your report, including the questions, and describe one

set of results garnered from it. Turn in your source code along with your report in a zipped archive.

And for the set of pairs: Sheilaville Billabong Wangalawa Fangbooboo Walkaboutcanyon Fangbooboo Sheilaville Yangboola Mercy Cawbillabilla Fangbooboo Walkaboutcanyon Chikamakagalwallawalla Plax Killdunnen Walkaboutcanyon Sheilaville Coocoobyrnie Boongalla Fangbooboo Walkaboutcanyon Zaboonaboon My program found: Sheilaville -> Gatorcreek -> Wangalawa -> Flitcairn -> Fangbooboo -> Billabong Wangalawa -> Flitcairn -> Fangbooboo Walkaboutcanyon -> Mercy -> Zaboonaboon -> X -> Billabong -> Fangbooboo Sheilaville -> Gatorcreek -> Wangalawa -> Flitcairn -> Chikamakagalwallawalla -> Cawbillabilla -> Yangboola Mercy -> Zaboonaboon -> X -> Billabong -> Fangbooboo -> Flitcairn -> Chikamakagalwallawalla -> Cawbillabilla Fangbooboo -> Billabong -> X -> Zaboonaboon -> Mercy -> Walkaboutcanyon Chikamakagalwallawalla -> Flitcairn -> Fangbooboo -> Billabong -> X -> Plax Killdunnen -> Yangboola -> Cawbillabilla -> Chikamakagalwallawalla -> Flitcairn -> Fangbooboo -> Billabong -> X -> Zaboonaboon -> Mercy -> Walkaboutcanyon Sheilaville -> Gatorcreek -> Wangalawa -> Flitcairn -> Fangbooboo -> Billabong -> X -> Zaboonaboon -> Mercy -> Coocoobyrnie Boongalla -> Zaboonaboon -> X -> Billabong -> Fangbooboo Walkaboutcanyon -> Mercy -> Zaboonaboon