京都大学 情報学研究科 知能情報学専攻 2025年8月実施 情報学基礎 F2-1
Author
祭音Myyura
Description
Q.1
In the undirected graph shown below, the numbers attached to the edges represent their lengths. The edge length x between nodes a and b is a positive real number. Among all paths between two nodes s and t, those with the minimum total edge length are called the shortest paths between s and t. The total edge length in a shortest path is referred to as the distance between s and t. A path is represented as a sequence of nodes in which no node appears more than once.
(1) Derive the distance between b and j, and identify all shortest paths, each represented as a sequence of nodes.
(2) Derive the condition on x under which b is included in all shortest paths between a and j.
Q.2
Given a set U={1,2,…,n} and a set S={S1,S2,…,Sm} where each Si is a subset of U, the set cover problem is to identify a set C={Sc1,Sc2,…,Sck}⊆S with the minimum k such that Sc1∪Sc2∪⋯∪Sck=U holds. Note that n and m are positive integers and it is assumed that S1∪S2∪⋯∪Sm=U holds. The following pseudo-code describes a greedy algorithm that computes an approximate solution to this problem.
1234567C←{};P←S;V←U;while V={} do beginh←max({#(Sj∩V)∣Sj∈P});i←min({j∣#(Sj∩V)=h, Sj∈P});P←P∖{Si}; V←V∖Si; C←C∪{Si};endoutput C;
Note that #(X), max(X), and min(X) denote the number of elements, the maximum element, and the minimum element of a set X, respectively. Note also that X∖Y denotes the set difference, which is the set obtained by deleting the elements belonging to both X and Y from X. For example, {1,3,4,5}∖{2,3,5}={1,4} holds.
This algorithm may output different solutions even for the same S, depending on the ordering of their elements. For example, suppose that U={1,2,3,4,5} and S={{1,3,5},{2,4},{2,3,5}}. This algorithm outputs C={{1,3,5},{2,4}} if S1={1,3,5},S2={2,4}, and S3={2,3,5}, whereas it outputs C={{2,3,5},{2,4},{1,3,5}} if S1={2,3,5},S2={2,4}, and S3={1,3,5}.
When considering all possible orderings of the elements of S (i.e., all permutations of the elements of S) for given U and S, among all solutions C outputted by this algorithm, let Amin(U,S) denote the cardinality of C with the smallest cardinality, and let Amax(U,S) denote the cardinality of C with the largest cardinality. Note that for the case of (U,S) given above, Amin(U,S)=2 and Amax(U,S)=3 hold. Answer the following questions where reasons must be given for all answers.
(1) Let U={1,2,…,10} and S={{i,i+1}∣i=1,2,…,9}. Derive Amin(U,S) and Amax(U,S).
(2) Let U={1,2,…,100} and S={{i,j}∣all integers i,j satisfying 1≤i<j≤100}. Derive Amin(U,S) and Amax(U,S).
(3) Let U={1,2,…,63} and S={{i,2i},{i,2i+1}∣i=1,2,…,31}. Derive Amin(U,S).
题目描述
-
下图为一张无向图,边旁数字表示边长,其中顶点 a,b 之间的边长 x 为正实数。两个顶点 s,t 之间总边长最小的路径称为最短路径,其总边长称为 s,t 之间的距离。路径用不含重复顶点的顶点序列表示。
(1)求 b 与 j 之间的距离,并以顶点序列列出所有最短路径。
(2)求使 a 与 j 之间的每一条最短路径都经过 b 的 x 的条件。
-
给定全集 U={1,2,…,n} 和集合族 S={S1,S2,…,Sm},其中每个 Si⊆U。集合覆盖问题要求找出
C={Sc1,Sc2,…,Sck}⊆S,
使 Sc1∪Sc2∪⋯∪Sck=U 且 k 最小。这里 n,m 为正整数,并假设 S1∪⋯∪Sm=U。以下贪心算法计算该问题的一个近似解:
1234567C←{}; P←S; V←U;while V={} do beginh←max({#(Sj∩V)∣Sj∈P});i←min({j∣#(Sj∩V)=h, Sj∈P});P←P∖{Si}; V←V∖Si; C←C∪{Si};endoutput C.
其中 #(X)、max(X)、min(X) 分别表示集合 X 的元素个数、最大元素和最小元素;X∖Y 表示从 X 中删除同时属于 Y 的元素所得的集合差,例如
{1,3,4,5}∖{2,3,5}={1,4}.
即使集合族 S 本身相同,其元素的编号顺序也可能使算法输出不同结果。例如,若
U={1,2,3,4,5},S={{1,3,5},{2,4},{2,3,5}},
当 S1={1,3,5}、S2={2,4}、S3={2,3,5} 时,算法输出
C={{1,3,5},{2,4}};
而当 S1={2,3,5}、S2={2,4}、S3={1,3,5} 时,算法输出
C={{2,3,5},{2,4},{1,3,5}}.
对固定的 U,S,考察 S 中元素的所有排列。将算法所有可能输出中 C 的最小基数记为 Amin(U,S),最大基数记为 Amax(U,S)。上述例子中 Amin(U,S)=2、Amax(U,S)=3。回答下列问题,并说明每个答案的理由。
(1)令
U={1,2,…,10},S={{i,i+1}∣i=1,2,…,9},
求 Amin(U,S) 与 Amax(U,S)。
(2)令
U={1,2,…,100},S={{i,j}∣1≤i<j≤100, i,j 为整数},
求 Amin(U,S) 与 Amax(U,S)。
(3)令
U={1,2,…,63},S={{i,2i},{i,2i+1}∣i=1,2,…,31},
求 Amin(U,S)。
Kai
Q.1
(1)
Applying Dijkstra's algorithm from b, the relevant distances are
d(b,d)=3,d(b,f)=4,d(b,e)=5,
d(b,i)=6,d(b,h)=7,d(b,j)=8.
The distance 8 is attained by the following three paths:
(b,d,e,j),(b,f,e,j),(b,f,i,h,j).
Their lengths are
and
4+2+1+1=8,
respectively.
Any path from b through a has length at least x+12>8, since
x>0. Therefore,
d(b,j)=8
and all shortest paths are
(b,d,e,j),(b,f,e,j),(b,f,i,h,j).
(2)
A shortest a-j path through the edge {a,b} has length
x+d(b,j)=x+8.
If b is avoided, the path must start with {a,c}. In the graph
with b removed,
d(c,j)=7,
as shown by
(c,f,e,j),(c,f,i,h,j),(c,g,i,h,j).
Hence the shortest a-j path avoiding b has length
Thus b is contained in every shortest path exactly when
Since x is positive,
0<x<4.
When x=4, shortest paths both through and avoiding b exist; when
x>4, the shortest paths avoid b.
Q.2
In each case, regard U as the vertex set of a graph and each
two-element set in S as an edge.
While an edge with two uncovered endpoints exists, the greedy algorithm
chooses such an edge. These chosen edges form a maximal matching M.
Let
After these r choices, 2r vertices are covered. Since M is
maximal, no two uncovered vertices are adjacent, so each later choice
covers exactly one new vertex. Therefore, the total number of selected
sets is
r+(n−2r)=n−r.
Moreover, any maximal matching can be obtained by placing all its edges
first in the ordering.
(1)
The graph is the path
1−2−⋯−10.
Its maximum matching size is 5, for example,
{{1,2},{3,4},{5,6},{7,8},{9,10}}.
Hence
Amin(U,S)=10−5=5.
For Amax, we need a maximal matching of minimum size. The matching
{{2,3},{5,6},{8,9}}
is maximal and has size 3.
No maximal matching can have size at most 2: otherwise at least six
vertices would be unmatched, but a path on ten vertices has an
independent set of size at most five. Thus two unmatched vertices would
be adjacent, contradicting maximality.
Therefore,
Amin(U,S)=5,Amax(U,S)=7.
(2)
The graph is the complete graph K100.
As long as at least two vertices are uncovered, an edge joining two
uncovered vertices exists, so the greedy algorithm covers two new
vertices at every step. Equivalently, every maximal matching in
K100 is a perfect matching of size 50.
Therefore, independently of the ordering,
Amin(U,S)=Amax(U,S)=50.
(3)
The graph is the complete binary tree with vertices 1,…,63,
where vertex i is joined to 2i and 2i+1.
Let Th be the complete binary tree with levels 0,…,h. Define
- Fh: the maximum matching size when the root is not matched to its
parent;
- Gh: the maximum matching size when the root is already matched to
its parent.
Then
F0=G0=0,
and, for h≥1,
Gh=2Fh−1,
Fh=max{2Fh−1,1+Gh−1+Fh−1}.
The values are
hFhGh0001102223544101052120
Thus the maximum matching size of the given tree is
Consequently,
Amin(U,S)=63−21=42.