京都大学 情報学研究科 知能情報学専攻 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).
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.