Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You need to implement the merge - sort algorithm to sort a list of cities, but the sorting should only consider the population of the
You need to implement the mergesort algorithm to sort a list of cities, but the sorting should only consider the population of the cities. No other criteria should be used in the sorting process. However, if two cities have the same population, they should maintain their original order as in the input. This is commonly referred to as a stable sort An Onlogntime algorithm is sufficient to pass any feasible test cases.
Input You need to read the input from the console. The input consists of n lines of data. Each line i contains two positive integers: ai which is the index of the city, and pi representing the population of the city. You can assume that ai and pi
Output You need to output to console. The output from line to line n you need to output the cities in ascending order of population.
Example: Below are examples of input and output:
Example input: Example output:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started