Code (or name): 1 (of 9) EDAA75 Exam 4 June 2022 Instructions Things you CAN use during the exam. Any written or printed material is fine. Textbook, other books, the printed slides, handwritten notes, whatever you like. In any case, it would be good to have a source for the relevant definitions, and also for notation, just in case you don’t remember the precise definition of everything we discussed in the course. Things you CANNOT use during the exam. Anything electrical or electronic, any communication device: computers, calculators, mobile phones, toasters, ... WRITE CLEARLY. If I cannot read/decipher/make sense of something you write, I will make the least favourable assumption about what you intended to write. A sheet with common symbols and notations is attached at the end. Good luck! 1 16 2 20 3 20 4 12 5 16 6 16 total 100 Total points: 100 points required for 3: 50 points required for 4: 67 points required for 5: 85 EDAA75 Exam 4 June 2022 Code (or name): 2 (of 9) 1 [16 p] 1. For k ∈ N+ , define the set Dk of positive natural numbers strictly larger than k that are divisible by k. Dk = {n ∈ N+ : (n > k) ∧ (k | n)} 2. Define the set P of prime numbers. (You can use the sets Dk .) + P = {N \ ({1} ∪ S k∈N+ ,k≥2 Dk )} or {n ∈ N : ((q ∈ N ) ∧ (q | n)) ! ((q = 1) ∨ (q = n))} or . . . + + 3. Recursively define a function f : N+ −! P that given a positive natural number n ∈ N+ returns the nth prime number. For example, f (1) = 2, f (2) = 3 and f (5) = 11. For our purposes here, you can use the min function over any subset of N. For example, if D2 is the set of all positive natural numbers strictly larger than 2 that are divisible by 2, then min D2 = 4 . You can use a helper function if you like. f : n 7! ( 2 if n = 1 min(P \ {n ∈ N+ : n ≤ f (n − 1)}) if n > 1 Alternatively, we could have defined a helper function f 0 : N+ × P(N) −! N that given n ∈ N+ and S ⊆ N returns the nth smallest element in S: ( min S if n = 1 f 0 : n, S 7! 0 f (n − 1, S \ {min S}) if n > 1 We would then have f (n) = f 0 (n, P). EDAA75 Exam 4 June 2022 Code (or name): 2 3 (of 9) [20 p] Let (V, E) be a directed graph. For any vertex v ∈ V , we write E 0 (v) = {v} and for n > 0, E n (v) = E(E n−1 (v)). Recall that a path is a finite sequence v0 v1 . . . vk of vertices vi ∈ V such that for all i ∈ {1, 2, . . . , k} it is the case that (vi−1 , vi ) ∈ E. We say the path v0 v1 . . . vk has length k (that is, the number of edges in the path, or one less than the number of vertices it contains). We only consider paths with at least one vertex. A path of length 0 is just a vertex itself. Also, a cycle is a path length at least 1 that begins and ends with the same vertex. 1. Write a formula that is true if and only if the graph (V, E) contains at least one cycle. ∃v ∈ V ∃n ∈ N+ (v ∈ E n (v)) or ∃v ∈ V (v ∈ E + (v)) etc. 2. Assume that (V, E) has at least one cycle. Using the definition above, give a formula for the length of the shortest cycle in (V, E). min{n ∈ N+ : ∃v ∈ V (v ∈ E n (v))} 3. Define a relation R ⊆ V × V such that for two vertices v, w ∈ V , it is the case that (v, w) ∈ R if and only if there is a path from v to w and there is a path from w to v. R = {(v, w) ∈ V 2 : ∃m, n ∈ N (v ∈ E n(w) ∧ w ∈ E m(v))} or, e.g., {(v, w) ∈ V 2 : v ∈ E[w]) ∧ w ∈ E[v]} 4. Is R transitive? Is it symmetric? Is it reflexive? R is transitive (always). R is symmetric (always). R is reflexive (always). EDAA75 Exam 4 June 2022 Code (or name): 4 (of 9) 3 [20 p] All intervals below are supposed to be intervals in the real numbers, R. Suppose f : A −! B is the function defined by f : x 7! x2 1. If A = {0, 1, 2, 3}, what is B so that f is a bijection? B = {0, 1, 4, 9} 2. If A = [−2, 3], what is B so that f is surjective? B = [0, 9] 3. If A = [2, 4], what is f [A]? If A = [2, 4], then f [A] is not well-defined since we have that f : A −! B. The question should have been: “If A = B = R+ , what is f [[2, 4]]?” In which case the answer would have been: f [[2, 4]] = [2, ∞[ 4. If B = [0, 10], give an A so that f is injective. For your choice of A, is f −1 a function? There are two types √ of possible answers here. Option 1: A = [0, 10].√In this case f −1 is a function. It could also be A = [− 10, 0] or other combinations of these intervals. Option 2: A = [0, 3]. In this case f −1 is NOT a function. Again, there are several possible choices of A here. 5. If A = [0, 3] and B = [0, 9], what is f −1 1 0, 3 ? The definition in the slides says we can only take closure of functions that have the same domain and codomain. So it would be okay to state this. Again, the question should have been “If A = B = R+ , what is f −1 0, 31 ?” In which case the answer would have been: f −1 0, 31 = ]0, 1[ EDAA75 Exam 4 June 2022 Code (or name): 5 (of 9) 4 [12 p] Let p, q, r be Boolean propositional variables. For each of the items below, answer whether the two statements are equivalent. If yes, explain how you got to this conclusion (either explain in words your reasoning or show the steps you took to get the answer). If no, give an example of values of p, q, r for which they differ. 1. (p ! q) ! r and ¬p ∨ ¬q ∨ r Not equivalent. For p = q = true and r = false, the first formula evaluate to true, but the second one to false. 2. ¬((p ∨ q) ↔ (r ∧ q)) and (p ∧ ¬q) ∨ (q ∧ ¬r) Equivalent. You can justify this by writing out the truth table, or the steps you took to obtain a DNF, or in words. q 0 0 0 0 1 1 1 1 p 0 0 1 1 0 0 1 1 r 0 1 0 1 0 1 0 1 (p ∨ q) 0 0 1 1 1 1 1 1 (r ∧ q) 0 0 0 0 0 1 0 1 ¬((p ∨ q) ↔ (r ∧ q)) 0 0 1 1 1 0 1 0 (p ∧ ¬q) 0 0 1 1 0 0 0 0 (q ∧ ¬r) 0 0 0 0 1 0 1 0 (p ∧ ¬q) ∨ (q ∧ ¬r) 0 0 1 1 1 0 1 0 3. (p ↔ q) ! (q ∧ r) and (¬p ∧ q) ∨ (p ∧ r) ∨ (q ∧ r) Not equivalent. For p = q = true and r = false, the first formula evaluate to false, but the second one to true. EDAA75 Exam 4 June 2022 Code (or name): 5 6 (of 9) [16 p] For the following problems, start by explaining how you can model them as a graph theory problem. Part A. [8 pt] The organizers of a social networking event invited 30 participants. The event included a dinner where the participants were to be seated in 6 tables each with 5 places each with unlimited seating. The organizers wanted each person to sit on a table with people that he or she didn’t already know. So they made a list of connections (who knows who) and figured out that each participant knows at most 5 other participants. 1. Argue why it is possible to place all 30 participants in the 6 tables so that no one sits with someone they already know. This problem can be modelled as a graph theory problem. The participants are the nodes, and there are edges between participants if they know each other. The tables are the colours. We should argue that given that the maximum degree of the graph is 5, then the graph can be coloured with 6 colours. There are several ways to argue this. Perhaps the simplest is to define a procedure that colours the graph. Let us consider one vertex at a time in an arbitrary order. For every vertex we assign it one colour that none of its already-coloured neighbours have. Since every vertex has degree at most 5 and there are 6 colours, there will always be an available colour to colour the given vertex. 2. Suppose there was one famous participant that knew 20 other participants, but all other participants knew at most 5 other participants. Can you still argue why it is possible to place all 30 participants in the 6 tables so that no one sits with someone they already know? We can do the same procedure as described above, except that we start by colouring the famous participant. EDAA75 Exam 4 June 2022 Code (or name): 7 (of 9) Part B. [8 pt] Max is visiting Sweden for the second time. He says he has carefully studied the train network information and figured out that most cities are connected to exactly 4 different cities by direct train (by this we mean that you can get between these cities, in both directions, by train without having to transfer). There were only four exceptions: Visby with no train connections, Stockholm with 6 train connections, Haparanda with only 1 train connection, and Malmö with an unknown number of train connections. Argue why there must be a way to get from Malmö to Haparanda by train (with possible transfers). Hint: You can show that there is a way to get from Malmö to Haparanda by using each certain train connection in exactly one direction. We can model this problem as a graph problem as follows. The cities are the nodes of the graph, and we include an edge between two nodes if the cities are connected by a direct train. We know that the graph has one vertex of degree 0, one of degree 6, one of degree 1, one of unknown degree, and all others of degree 4. Since any graph has an even number of odd degree vertices (by the handshaking lemma) we conclude that Malmö must have odd degree. We can also conclude that Malmö and Haparanda must be in the same connected component, since both cities are the only cities with odd degree, for each connected component it is also true that there an even number of odd degree vertices. This implies that there must be a path from Malmö to Haparanda. We could also argue that in the connected component that contains Malmö and Haparanda, there is an Eulerian path between the odd-degree vertices, so there must be a path from Malmö to Haparanda (as the hint suggests). But this argument is unnecessary since we already know that they are in the same connected component. EDAA75 Exam 4 June 2022 Code (or name): 8 (of 9) 6 [16 p] A kindergarten teacher decided to play some games with her n students. She put n red balls, n yellow balls and n blue balls in a bag. 1. She first asked whoever wanted to play a game to stand up and choose a ball. (a) Explain why there could have been n X n 3 k k=0 k different outcomes (including the case when no child stands up). An outcome consists of the children that stand up and what ball each child has. Any number between 0 and n children can choose to stand. There are nk ways for k children to stand and for each child that stands up, there are 3 options of balls the child could pick. So there are nk 3k outcomes if k children stand up. Summing over k = 0 up to n we get the expression above. (b) Write this as a function of n only (without k). k n−k Pn n n By using the binomial theorem (x + y) = x y with x = 3 and y = 1 we k=0 k Pn k n n conclude that k=0 3 k = 4 . Another option is to argue that we can count the same set of outcomes by considering that each child has 4 options: either not stand up, or to stand up and choose one of three balls. 2. A total of 15 kids stood up. They then returned the balls to the bag and formed three teams of 5. Each team had to choose a captain for the team. How many different outcomes could there have been? 10 15 · 5 5 · 53 3! There are 15 ways to choose the first team, 10 ways the second team, and the third team 5 5 is whoever is left. We are over counting by a factor of 3! since it doesn’t matter the order in which teams are chosen. Once teams are fixed, there are 5 ways of choosing each captain. 3. The teacher then told each team to choose 5 balls from the bag and then form as many different sequences as they could with the 5 balls (placing them in a row). In order to maximize the number of sequences that can be created with 5 balls, is it better to choose 2 red balls, 2 blue balls, and 1 yellow ball, or 3 red balls, 1 blue ball, and 1 yellow ball? Justify your answer. It is better to choose 2 red balls, 2 blue balls, and 1 yellow ball since with these we can create 5 · 42 = 30 different sequences, and if we choose 3 red balls, 1 blue ball, and 1 yellow ball then we can only create 5 · 4 = 20 different sequences. There are many ways of calculating the number of different sequences, depending on the colour you start with. EDAA75 Exam 4 June 2022 Code (or name): 9 (of 9) Some common symbols the natural numbers, starting at 0 • N • N+ • R • R+ • Z the integers • Q the rational numbers • a⊥b a and b are coprime, i.e., they do not have a common divisor other than 1 • a|b a divides b, i.e., ∃k ∈ N such that ka = b • P power set of A • R of a relation R: its complement • R−1 • R ◦ S, f ◦ g of relations and functions: their composition • R[X], f [X] closure of a set X under a relation R. a set of relations R or a function f • [a, b], ]a, b[, ]a, b], [a, b[ • A∼B • • • • • • the natural numbers, starting at 1 the real numbers the non-negative real numbers, i.e., including 0 of a relation R: its inverse closed, open, and half-open intervals from a to b two sets A and B are equinumerous A∗ for a finite set A, the set of all finite sequences of elements of A, including the empty sequence, ε X S sum of all elements of S Y S product of all elements of S [ S union of all elements of S \ S intersection of all elements of S [ E(a), a∈S \ E(a) generalized union / intersection of the sets computed for every a in S a∈S EDAA75 Exam 4 June 2022