Suppose you are in Canada\'s Thousand Islands National Park, and in one particul
ID: 3739039 • Letter: S
Question
Suppose you are in Canada's Thousand Islands National Park, and in one particular lake there are n small islands that park officials want to connect with floating bridges so that people can experience going between islands without a canoe. The cost of constructing a bridge is proportional to its length. Assume the distance between every pair of islands is given to you as a two dimensional matrix (an example of such a table for n-8 islands is shown below ? | 240 C210265 D340 175260 ? 280 | 215 | 115 | 160 F200180350330360 G345185435 295400 175 H120155 195230 170205305 240210 340 280 200345120 265175215180185 155 260 115 350 435195 160 330 295 230 360 400 170 175 205 305 Design an algorithm for determining which bridges they should build to connect the islands at minimal cost. Write down the pseudocode and analyze the runnning time of your algorithm. For full credit, your algorithm should be as efficient as possible.Explanation / Answer
Solution:
We will be using Kruskal's algorithm to build the bridges to connect them:
Algorithm/Pseudocode:
Correctness:
The above algorithm will give the correct result because from every island we are choosing the one which has the minimum distance to connect, this is the greedy approach but this will give users the correct result.
Running time:
Suppose there are V island s and E number of distances.
then the running time of the above algorithm will be
T(n)= O(V+E)
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.