2017
Problem 7
(1) Given an integer , we calculate a polynomial, . A single addition or multiplication of two values takes a unit time regardless of the number of the digits in the representation of the values.
(A) Let . Find the time complexity (with regard to ) of an algorithm that calculates individually and then calculates .
(B) Let $$g_i = \begin{cases}
a_n & \text{(when } i = n\text{)} \
g_{i+1} x + a_i & \text{(when } i < n\text{)}
\end{cases}$$. Notice that holds. Find the time complexity (with regard to ) of an algorithm that calculates , hence by calculating in this order.
(2) Given two -bit integers and , let be the highest bits of and , and the lowest bits of and , respectively. We calculate the product of and when is fairly large. Assume that computation time for addition or shift is negligible compared to that for multiplication.
(A) The multiplication of -bit integers can be constructed from the multiplication of -bit integers as follows: , where . We can recursively apply this reduction until every multiplication only involves integers small enough to fit in the machine word of the computer. Let be the number of machine-word multiplications required in the multiplication of two -bit integers. Express in terms of .
(B) Solve the recursive equation you answered in (A), and express in Landau’s notation.
(C) We reduce the number of multiplications in the calculation in (A) by calculating as . Express in Landau’s notation, and prove it.
(1) 给定一个整数 ,我们计算一个多项式,。两个值的单次加法或乘法的计算时间是一个单位时间,与值的表示形式中的位数无关。
(A) 令 。找到一个算法的时间复杂度(关于 ),该算法分别计算 ,然后计算 。
(B) 令 $$g_i = \begin{cases}
a_n & \text{(当 } i = n\text{ 时)} \
g_{i+1} x + a_i & \text{(当 } i < n\text{ 时)}
\end{cases}$$
。注意 成立。找到一个算法的时间复杂度(关于 ),该算法计算 ,从而通过依次计算 得到 。
(2) 给定两个 位的整数 和 ,令 为 和 的最高 位, 为 和 的最低 位。我们在 较大时计算 和 的乘积。假设加法或移位的计算时间相对于乘法可以忽略不计。
(A) 位整数的乘法可以通过 位整数的乘法构造,如下所示:,其中 。我们可以递归地应用这种缩减,直到每次乘法仅涉及足够小的整数以适应计算机的机器字。设 为两个 位整数相乘所需的机器字乘法次数。用 表示 。
(B) 解答你在 (A) 中回答的递归方程,并用 Landau 符号 表示 。
(C) 我们通过计算 为 来减少 (A) 中的乘法次数。用 Landau 符号 表示 ,并证明它。
Problem 8
Answer the following questions about linear algebra.
(1) Denote by the zero vector. Let denote a two-dimensional vector that is not . is the orthogonal projection of a point on . Prove the following propositions.
(1.1) for any two-dimensional point .
(1.2) for any non-zero two-dimensional vector orthogonal to .
(2) Assume that a real symmetric matrix satisfies . Prove that the eigenvalues of are either 0 or 1.
(3) Denote by the column vectors corresponding to the bases of a two-dimensional subspace of the three dimensional space. Describe the projection matrix to the subspace using .
回答以下有关线性代数的问题。
(1) 用 表示零向量。设 表示一个二维向量,它不是 。 是点 在 上的正交投影。证明以下命题。
(1.1) 对于任意二维点 ,。
(1.2) 对于任意非零二维向量 ,它与 正交,。
(2) 假设一个实对称矩阵 满足 。证明 的特征值要么是 0,要么是 1。
(3) 用 表示对应于三维空间的二维子空间基的列向量。用 描述该子空间的投影矩阵。
Problem 9
Suppose that is an array with distinct integers. The quicksort algorithm for sorting in the ascending order has the following three steps.
A) Select and remove an element from . Call a pivot.
B) Divide into arrays and such that for and for .
C) Sort and in the ascending order using quicksort, and return the concatenation of , , and .
Answer the following questions.
-
How would you implement Step B in quicksort?
-
In Step A, if we always set the first element in to pivot , show an input array that the algorithm sorts in worst-case time, and prove this property.
-
In Step A, if we select a position in at random and set the element at the position to pivot , prove that the expected time complexity is for an arbitrary input array.
-
Design an algorithm that calculates the -th smallest element in in expected time, and prove this property.
假设 是一个包含 个不同整数的数组。用于升序排列 的快速排序算法有以下三个步骤。
A) 从 中选择并移除一个元素 。称 为枢轴。
B) 将 分成数组 和 ,使得 对于所有 ,并且 对于所有 。
C) 使用快速排序按升序排列 和 ,并返回 , 和 的连接。
回答以下问题。
-
你将如何在快速排序中实现步骤 B?
-
在步骤 A 中,如果我们总是将 的第一个元素设置为枢轴 ,展示一个输入数组,使算法在 最坏情况下进行排序,并证明这一性质。
-
在步骤 A 中,如果我们在 中随机选择一个位置并将该位置的元素设置为枢轴 ,证明对于任意输入数组,预期时间复杂度为 。
-
设计一个算法,在 预期时间内计算 中的第 小元素,并证明这一性质。
Problem 10
We define the shortest distance from a vertex to a vertex on a graph as the number of edges in a path from to that contains the smallest number of edges, except that the shortest distance is when no such path exists and that it is when and are identical.
(1) Let us consider the directed graph shown below.
(A) Show the adjacency matrix.
(B) Show a matrix , whose element is the shortest distance from a vertex to a vertex .
graph TD;
1 --> 2;
2 --> 3;
3 --> 1;
3 --> 6;
4 --> 1;
5 --> 1;
5 --> 4;
6 --> 4;
7 --> 5;
7 --> 6;
(2) Suppose we are given a simple directed graph , where the vertex set and is the edge set. is represented by a matrix , where
(A) Let . Let be the set of edges in that start from and end at a vertex in . Let be the shortest distance from a vertex to a vertex on a directed graph , and let . Express in terms of .
(B) can be computed from as follows. Fill in the two blanks.
(C) Given , show an algorithm to compute the all-pair shortest distances, and find its time complexity with regard to .
我们将从顶点 到顶点 的最短距离定义为图中从 到 的包含最少边数的路径中的边数,除了当不存在这样的路径时最短距离为 ,以及当 和 相同时为 。
(1) 让我们考虑下图所示的有向图。
(A) 显示邻接矩阵。
(B) 显示一个矩阵 ,其元素 是从顶点 到顶点 的最短距离。
graph TD;
1 --> 2;
2 --> 3;
3 --> 1;
3 --> 6;
4 --> 1;
5 --> 1;
5 --> 4;
6 --> 4;
7 --> 5;
7 --> 6;
(2) 假设我们有一个简单的有向图 ,其中顶点集 和边集 。 由矩阵 表示,其中
(A) 设 。设 为从顶点 中的顶点出发并结束于顶点的边集。设 为有向图 上从顶点 到顶点 的最短距离,并设 。用 表示 。
(B) 可以从 计算如下。填写两个空格。
(C) 给定 ,展示一个算法来计算所有对的最短距离,并找到其关于 的时间复杂度。
Problem 11
Let be a sequence of mutually independent random variables such that each takes the value of 1 with probability , and 0 with probability (). We define a sequence () as follows:
Here, is a positive real number. Answer the following questions.
-
Find the expected value of .
-
Find the variance of .
-
Express as a function of and the elements of ().
-
Find ().
-
Find as a function of and .
设 为一组相互独立的随机变量,使得每个 以概率 取值为 1, 以概率 取值为 0()。我们定义一个序列 ()如下:
其中, 是一个正实数。回答以下问题。
-
求 的期望值 。
-
求 的方差 。
-
表示 作为 和 元素的函数()。
-
求 ()。
-
求 ,作为 和 的函数。
Problem 12
Consider an algorithm that calculates a longest palindrome that is a substring of a given string .
Here, we define a string to be a palindrome if for any .
Any string of one character is a palindrome and a string of two characters is a palindrome if and only if .
Answer the following questions.
-
When is a palindrome, show the condition that is necessary and sufficient for to be a palindrome.
-
Variable is 1 if is a palindrome, otherwise 0. Show the formula for each of the blanks, , and , in the following iterative equation. is 1 if , otherwise 0.
-
Show all the initial values of and the procedure of the iterations for calculating by dynamic programming using the above iterative equation.
-
Explain how to get a longest palindrome that is a substring of using .
考虑一种算法来计算给定字符串 的最长回文子串。
这里,我们定义一个字符串 为回文串,如果对于任意 ,。
任何一个字符的字符串都是回文串,任何两个字符的字符串 是回文串当且仅当 。
回答以下问题。
-
当 是回文串时,证明 成为回文串的充要条件。
-
变量 若 是回文串则为 1,否则为 0。展示以下迭代方程中每个空白的公式,, 和 。 当 时为 1,否则为 0。
-
通过使用上述迭代方程,展示所有 的初始值和通过动态规划计算 的迭代过程。
-
解释如何使用 获取 的最长回文子串。