Professional Documents
Culture Documents
Final Exam EPIS2
Final Exam EPIS2
Final Exam EPIS2
2022
Name: Matriculation number:
21-737-762
Oleksandr Krupchenko
About Exam
1. You can use a tablet and pen (iPad, Surface, etc) to fill in your solution directly into the pdf file and upload the
completed pdf file to EPIS.
2. You can print the pdf file, use the available whitespace to fill in your solution, scan your solution, and upload the pdf
file to EPIS.
3. You can use blank white paper for your solutions, scan the sheets, and upload the pdf file to EPIS. Put your name and
matriculation number on every sheet. State all task numbers clearly.
Exercise 1 2 3 4 5 Total
Points
Achieved
1
Maximum
29 14 14 14 21 92
Points
4. You can use a text editor to answer the questions and submit the document as pdf.
Notes:
• If you do not have scanner it is possible to take pictures of your solution with your phone. We recommend Microsoft
Office Lens or Camscanner. Create a pdf file that includes all pictures and submit a single pdf file.
• We suggest that you submit your solutions several minutes earlier than the deadline.
Signature:
Exercise 2 14 Points
You are only allowed to use the following abstract data types and functions:
Queue:
Q = initQueue(): initializes a Queue enQueue(Q,x): inserts value
x to queue Q (in the end) deQueue(Q): removes value from
queue Q (in the beginning) queueSize(Q): returns the number of
elements in queue Q
Stack:
2
Name: Matriculation number:
return head
}
3
Task 2.2 [4 points]:
Analyze and explain the asymptotic complexity of function reverseEven for the
following cases:
4
Name: Matriculation number:
Exercise 3 14 Points
Consider a binary search tree T1 with n elements and root r1, and a binary search tree
T2 with m elements and root r2.
1 struct TreeNode {
2 int val;
3 struct TreeNode* left;
4 struct TreeNode* right;
5 };
Give the relevant parts of a C program that prints the elements of T1 and T2 sorted
in ascending order. As auxiliary data structure you are allowed to use an array that
is large enough to hold the combined elements of both trees. Your solution may not
use a sorting algorithm.
5
6
Name: Matriculation number:
7
Exercise 4 14 Points
G1 = (V,E)
8
Name: Matriculation number:
#include <bits/stdc++.h>
// Add edge
adj[s].push_back(d);
adj[d].push_back(s);
9
<< d << ":";
printf("\n");
int main() {
int V = 5;
// Create a graph
vector<int> adj[V];
// Add edges
addEdge(adj, 0, 1);
addEdge(adj, 0, 2);
addEdge(adj, 0, 3);
addEdge(adj, 1, 2);
printGraph(adj, V);
10
Name: Matriculation number:
11
Exercise 5 21 Points
Consider an array A with n positive integers. Let S be the sum over all integers of A.
In the Minus process, we repeat the following steps until only zero or one element is
left:
• we select any two elements, a and b, and remove these two elements from A
The M value is equal to the last element. If no element is left, the M value is 0. The task
is to compute the smallest possible M value that a Minus process can compute.
Determine the smallest possible M value after the Minus process on A1.
1 3 1 2
Array A1
12
Name: Matriculation number:
• If A1[1] = 3, the 2nd element, can be part of the subsequence, we use the value
of dp1[1][0] and dp1[1][3] to compute dp1[2][3].
• If A1[1] = 3, the 2nd element, cannot be part of the subsequence, we use the
value of dp1[1][3] to compute dp1[2][3].
Task 5.2 [3 points]: Fill in the following dp1 array for A1.
i=0 0 0 0 0
i=1
0
i=2
i=3 0
i=4
0
Figure 1: dp1 0
Write a C function calculate(A, n) that returns the smallest possible M value that is the
result of the Minus process.
13
14