You are on page 1of 4

Charles University, Faculty of Mathematics and Physics

Master of Computer Science, Take-Home Assignment


2023 Entry

Scoring. Each problem is worth a maximum of 10 points, for a maximum total score of 50.

Problem 1. In Fig. 1 there is a weighted graph, circles represent vertices, links represent
edges, and numbers represent edge weights.

3
S C F
2 4
3 2 2
4 2 3
A D G T
3 1
1 1 1 1
2

B E H I
3 3 2

Figure 1: The graph.

1. Find a shortest path from vertex S to vertex T , i.e., a path of minimum weight between
S and T .
2. Find a minimum subgraph (set of edges) that connects all vertices in the graph and
has the smallest total weight (sum of edge weights).

Justify your answers.

Problem 2.
1. Let E be a binary relation symbol representing adjacency in graphs. (That is, E(x, y)
means in a graph that “the vertices x and y are adjacent”.) Write a formula ϕ(x, y) in
the first-order logic over the language L = hEi with equality expressing that

“x and y have exactly two common neighbors.”

Note that except logical symbols you may use only E and =. (The phrases “x and y
are adjacent” and “x and y are neighbors” have the same meaning.)

1
2. Find a model and a non-model of a theory
T = {(∀x)¬E(x, x), (∀x)(∀y)(E(x, y) → E(y, x)), (∀x)(∃y)ϕ(x, y)}
over the language L. By a non-model of T we mean a structure of the same language
that is not a model of T .
3. Is the formula (∃x)(∀y)ϕ(x, y) provable or refutable from T (in a sound and complete
proof system using the axioms of T )? Give an explanation for your answer.

Problem 3. Consider finite strings over the alphabet Σ = {a, b, c, d}. The power operation
represents string repetition, for example a3 b4 c denotes the string aaabbbbc. Define a context-
free grammar G generating the language L(G) = {w|(∃i, j, k)w = ai b(i+j+k) cj dk }, the set of
words where the number of b’s is the same as the number of all other letters together and
the letters are ordered alphabetically. For example, the words ab, aaabbbbd, abbbcd belong to
the language, words abba, aabbbbbc, abc do not belong to the language. Justify your answers.

Problem 4. Consider the following C++ program, and one of the C# or Java programs:
C++:

1 # include < iostream >


2
3 template < typename T > void m ( T t ) { std :: cout << " m ( T = " <<
4 typeid ( T ) . name () << " ) " << std :: endl ; }
5 void m ( int i ) { std :: cout << " m ( int ) \ n " ; }
6 template < typename T > void f ( T t ) { m ( t ) ; }
7
8 int main () {
9 f ( " Hello " ) ;
10 f (123) ;
11 f (4000000000) ;
12 }

C#:

1 using System ;
2
3 class Program {
4 static void m <T >( T t ) { Console . WriteLine ( $ "m <T >( T ={ typeof ( T ) }) " ) ; }
5 static void m ( int i ) { Console . WriteLine ( " m ( int ) " ) ; }
6 static void f <T >( T t ) { m ( t ) ; }
7
8 static void Main ( string [] args ) {
9 f ( " Hello " ) ;
10 f (123) ;
11 f (4000000000) ;
12 }
13 }

2
Java:

1 public class Main {


2 static <T > void m ( T t ) { System . out . println ( " m ( T ) " ) ; }
3 static void m ( int i ) { System . out . println ( " m ( int ) " ) ; }
4 static <T > void f ( T t ) { m ( t ) ; }
5
6 public static void main ( String [] args ) {
7 f ( " Hello " ) ;
8 f (123) ;
9 f (4000000000 L ) ;
10 }
11 }

For the chosen pair of the C++ and C# programs, or the C++ and Java programs, answer
the following:
1. What output will be printed by the C++ program, and what output by the second
language in the pair?
2. Explain why the C++ program behavior is different (in terms of methods called) from
that of the C# or Java one. Why do different methods get called?
3. In C++, C#, or Java, write a generic function that takes 3 arguments of any suitable
type T and returns their maximum value.

Problem 5. Consider a transaction schedule S = R1 (A), W2 (B), R3 (C), R3 (B), W1 (C),


W3 (B), COMMIT3 , ABORT2 , COMMIT1 .
The notation uses Ri (X) and Wi (X), respectively, for reading from and writing to the vari-
able X in the i-th transaction. COMMITi and ABORTi denote successful and unsuccessful
end of i-th transaction, respectively.
If operations from individual transactions are written separately while maintaining their
ordering, the schedule can be presented as follows:

Time T1 T2 T3
(running top to bottom)
1 R1 (A)
2 W2 (B)
3 R3 (C)
4 R3 (B)
5 W1 (C)
6 W3 (B)
7 COMMIT3
8 ABORT2
9 COMMIT1

3
1. Find all conflicting pairs of operations in the schedule S.

2. Is the schedule S conflict-serializable? Justify your answer.

3. Is the schedule S recoverable? Justify your answer.

If the schedule S lacks a particular property, correct it so that it satisfies the property without
changing the order of the read and write operations.
If the schedule cannot be fixed, describe why not.

You might also like