Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Imagine an island archipelago that consists of several disconnected islands. Within the islands, the pair of cities are connected through a unique highway. You can

Imagine an island archipelago that consists of several disconnected islands. Within the islands, the pair of cities are connected through a unique highway. You can assume that you can reach every city from a city within the island. There can be multiple unique roads between cities. You are given two text files -

city_population.txt: contains a list of all cities and their population. The file data format is in : . For example, City A : 1000 means City A has a population of 1000. You can assume each city has a unique name.

road_network.txt: contains the list of all highways in the island archipelago. The file data format is in : . For example, City A : City B.Means City A and City B are connected by a unique highway. You can consider the highways as bi-directional.

Complete the following tasks -

  • Implement a class City that will include the following fields - [4 pt]
    • Name of the city
    • The population of the city
    • List of cities that are connected to this particular city.
  • Read the text file and construct a graph of cities. Use the objects of a class City to model a city and the graph. Note that conceptually, this is similar to the adjacency list representation of the graph. [4 pt]
  • Given the list of City objects, write a function that would return the number of islands in the island archipelago. Note that this function would require you to find the number of connected components in the graph. [4 pt]
  • Given the list of City objects, write a function that would return the population of each island in the island archipelago. Note that this function would require you to find the population of each connected component in the graph. [4 pt]
  • Given two City objects, write a function that would return the minimum number of unique highways you can take to reach from one city to another. Note that this function requires you to find the distance i.e. number of unique highways between two cities. [4 pt]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions