Advanced Algorithms, Quiz 2
You are given a sequence of integers of length . You have to split these integers into pairs; each pair will represent the coordinates of a point on a plane. Each number from the sequence should become the or coordinate of exactly one point. Note that some points can be equal.
After the points are formed, you have to choose a path that starts from one of these points, ends at one of these points, and visits all points at least once.
The length of path is the sum of distances between all adjacent points on the path. In this problem, the distance between two points and is defined as .
Your task is to form points and choose a path in such a way that the length of path is minimized.
For example, if the given sequence is 15, 1, 10, 5, then you can form points and and start the path from the first point and end it at the second point. Then the length of the path will be . It can be shown that this is the best possible.
Based on the above data, answer the given subquestions.
You are given a sequence of integers $a$ of length $2n$. You have to split these $2n$ integers into $n$ pairs; each pair will represent the coordinates of a point on a plane. Each number from the sequence $a$ should become the $x$ or $y$ coordinate of exactly one point. Note that some points can be equal. After the points are formed, you have to choose a path $s$ that starts from one of these points, ends at one of these points, and visits all $n$ points at least once. The length of path $s$ is the sum of distances between all adjacent points on the path. In this problem, the distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is defined as $|x_1 - x_2| + |y_1 - y_2|$. Your task is to form $n$ points and choose a path $s$ in such a way that the length of path $s$ is minimized. For example, if the given sequence is `15, 1, 10, 5`, then you can form points $(10, 1)$ and $(15, 5)$ and start the path $s$ from the first point and end it at the second point. Then the length of the path will be $|10 - 15| + |1 - 5| = 5 + 4 = 9$. It can be shown that this is the best possible. Based on the above data, answer the given subquestions. Figure from the original question paper You are given a sequence of integers $a$ of length $2n$. You have to split these $2n$ integers into $n$ pairs; each pair will represent the coordinates of a point on a plane. Each number from the sequence $a$ should become the $x$ or $y$ coordinate of exactly one point. Note that some points can be equal. After the points are formed, you have to choose a path $s$ that starts from one of these points, ends at one of these points, and visits all $n$ points at least once. The length of path $s$ is the sum of distances between all adjacent points on the path. In this problem, the distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is defined as $|x_1 - x_2| + |y_1 - y_2|$. Your task is to form $n$ points and choose a path $s$ in such a way that the length of path $s$ is minimized. For example, if the given sequence is `15, 1, 10, 5`, then you can form points $(10, 1)$ and $(15, 5)$ and start the path $s$ from the first point and end it at the second point. Then the length of the path will be $|10 - 15| + |1 - 5| = 5 + 4 = 9$. It can be shown that this is the best possible. Based on the above data, answer the given subquestions. Figure from the original question paper You are given a sequence of integers $a$ of length $2n$. You have to split these $2n$ integers into $n$ pairs; each pair will represent the coordinates of a point on a plane. Each number from the sequence $a$ should become the $x$ or $y$ coordinate of exactly one point. Note that some points can be equal. After the points are formed, you have to choose a path $s$ that starts from one of these points, ends at one of these points, and visits all $n$ points at least once. The length of path $s$ is the sum of distances between all adjacent points on the path. In this problem, the distance between two points $(x_1, y_1)$ and $(x_2, y_2)$ is defined as $|x_1 - x_2| + |y_1 - y_2|$. Your task is to form $n$ points and choose a path $s$ in such a way that the length of path $s$ is minimized. For example, if the given sequence is `15, 1, 10, 5`, then you can form points $(10, 1)$ and $(15, 5)$ and start the path $s$ from the first point and end it at the second point. Then the length of the path will be $|10 - 15| + |1 - 5| = 5 + 4 = 9$. It can be shown that this is the best possible. Based on the above data, answer the given subquestions. Figure from the original question paper