Computing Foundations [10 points]
Question 1
What is the binary representation of the decimal number 12 (remember the prefix ”0b”)?
◦ 0b0011
◦ 0b0110
◦ 0b10011
◦ 0b1100
Question 2
The Windows-1252 encoding uses 8 bits to encode each of a set of 256 characters, from the character ”NUL”
to the character ”ÿ”. Which of the following might be a correct Windows-1252 encoding of the character ”$”?
□ 0x24
□ 0b00100100
□ 0x324
□ 0x1234
□ 0b1011
Question 3
A colleague claims: ”The core function of a transistor is to act as an electronic switch. This is accomplished by
using a superconductor that switches the ”drain” off when there is voltage at the ”gate”.”
Is your colleague’s statement correct?
◦ Yes!
◦ No!
Question 4
Why does a Half-Adder require its ”AND” gate?
◦ The AND gate is used to calculate the carry bit and the XOR gate is used to calculate the sum bit.
◦ The AND gate is used to calculate the sum bit and the XOR gate is used to calculate the carry bit.
◦ the AND gate is used to calculate both output bits.
Question 5
The following 2-bit adder circuit is used to add the 2-bit numbers A = 0b01 and B = 0b01. Please mark all
correct statements.
B1
A1
B0
A0
C0
C1
Full Adder
Half Adder
S1
S0
□ A0 contains a 1, A1 contains a 0.
□ A0 contains a 0, A1 contains a 1.
□ C0 contains a 1.
□ C1 contains a 1.
□ S0 contains a 0.
□ S1 contains a 0.
Question 6
The following code is given:
a = [1 , 2 , 3 , 4 , 5]
b = tuple ( range (1 ,5 ,2) )
3 a . append ( b [ -1])
4 for
i in a :
5
a [ i - 1] = a [ i - 1] - 1
1
2
Which value(s) do the following calls return? If you think an error occurs, please enter error.
a[ 0 ]
a[ 1 ]
a[ 2 ]
a[ 3 ]
a[ 4 ]
a[ 5 ]
a[ 6 ]
a[ ::-2 ]
b[ 0 ]
b[ : ]
Question 7
The following function definition is given:
def f ( a =0) :
if a > -1:
3
print ( ’ False ’)
4
elif a == -1:
5
print ( ’ False ’)
6
elif a >= -1:
7
return False
8
else :
9
f ( a +1)
10
return True
1
2
Which value(s) do the following function calls return? If you think an error occurs, please enter error.
f(1)
f(b=0)
f(a=-1):
f()
f(-2)
f(-100)
f(’0’)
f(-1.1)
f([-1,-2][1])
f(-1,1)
Question 8
The following program is given:
1
class Track :
2
def __init__ ( self , AAA , artist ) :
self . _name = name
self . BBB = artist
3
4
5
6
@property
def CCC ( self ) :
return self . _name
7
8
9
10
@property
def artist ( self ) :
return self . _artist
11
12
13
14
@artist . setter
def DDD ( self , artist ) :
""" Always make sure _artist is a list or a string .
If it is a string , convert it to a list with one element . """
if isinstance ( artist , str ) :
self . EEE = [ artist ]
elif isinstance ( artist , list ) :
self . _artist = artist
else :
raise TypeError ( " Artist must be a string or a list . " )
15
16
17
18
19
20
21
22
23
24
25
def play ( FFF ) :
""" Plays the track """
# please assume code here that plays
# the track on the speaker output
print ( f ’ Playing { self } ’)
26
27
28
29
30
31
def __str__ ( GGG ) :
return f ’{ self . name } by { self . artist } ’
32
33
34
35
class ClassicalTrack ( HHH ) :
36
def __init__ ( self , name , artist , composer ) :
super () . __init__ ( name , artist )
self . III = composer
37
38
39
40
@property
def composer ( self ) :
return self . _composer
41
42
43
44
def play ( self ) :
""" Plays the track """
JJJ () . play ()
print ( f ’ composed by { self . composer } ’)
45
46
47
48
49
50
class Album () :
51
def __init__ ( self , title , tracks ) :
self . _title = title
self . _tracks = tracks # this is a list of tracks
52
53
54
55
@property
def title ( self ) :
return self . _title
56
57
58
59
@property
def tracks ( self ) :
return self . _tracks
60
61
62
63
def play ( self ) :
""" Plays all tracks of the album """
print ( f ’ playing album { self . title } ’)
for track in self . tracks :
KKK . play ()
64
65
66
67
68
69
track1 = Track ( ’ track1 ’ , ’ artist1 ’)
track2 = Track ( ’ track2 ’ , [ ’ artist1 ’ , ’ artist2 ’ ])
72 track3
= ClassicalTrack ( ’ track3 ’ , ’ artist3 ’ , ’ composer1 ’)
70
71
The program defines a class Track. This is supposed to be a music track, which can be played ((play()) A Track
has name and artist. artist is supposed to be a list so that several artists can be stored. ClassicalTrack inherits from Track. It extends its superclass by a composer. An Album has a little and may comprise many tracks.
Please replace the positions marked AAA - KKK in the program so that the desired functionality is achieved.
Then please add the additionally requested codes. If you need to work with strings, use single quotes (’...’) only
- no double or triple quotes.
AAA:
BBB:
CCC:
DDD:
EEE:
FFF:
GGG:
HHH:
III:
JJJ:
KKK:
Declare a variable album1 and assign an instance of Album with the title: album1. The album shall comprise
track1 and track2 - in this sequence:
Play all tracks of album1 - write the shortest possible code version:
Let’s assume there is a playlist1. How can we play everything from this playlist? Please replace the position
marked NNN:
1
playlist1 = [ track3 , album1 ]
2
3
4
for item in playlist1 :
NNN
NNN:
Question 9
Please mark all correct statements.
□ In Python, Strings are immutable, unless they are used in Lists, since Lists are mutable in Python.
□ In Python, a while loop can contain another while loop.
□ In Python, methods can be used to reuse code blocks and structure the behavior of objects.
□ An if ... elif ... else code block may be executed more efficiently than a code block that delivers the same
results, but uses only if ... else constructs. AND whether or not the if ... elif ... else code block is more
efficient depends on the conditions to be tested.
□ In Python, two variables must not reference the same object because this may compromise consistency.
□ In Python, a while loop can contain a for loop.
□ In Python, the values of dictionaries need to be unique.
□ In Python, int, float, str, list, tuple, dict, and set data types have in common that their objects are
iterable.
□ In Python, if we can assign any value to a variable var1 (e.g., var1 = 1 ) then it is safe to assume that we
can also assign any value to a variable var2 that is a property of an object (e.g., obj2.var2 = 1 ).
□ In Python, if we apply the map function to an iterable with ten elements, the returned iterable will also
have ten elements.
Question 10
Given is this Python code:
In this code, a/an
via a port together with a/an
connection. The
socket of a
is created. This socket, which is defined
address, is used to exchange data via a/an
protocol is used on the application layer.
Question 11
Mark all correct statements about the Web and the HTTP protocol.
□ A response code of ”201” needs to be handled by the client, since this indicates a client-side problem.
□ An HTTP request that uses the GET method is considered ”safe” (i.e., side-effect free) and can therefore
not be cached.
□ An HTTP request typically requires a previous DNS request to map the target URL (e.g., http://example.com)
to the server’s MAC address (e.g., 00:1B:44:11:3A:B7).
□ In HTTP, clients and servers are mandated to ignore header fields that they do not know so that the
HTTP protocol may be extended over time.
□ The World Wide Web is the most prominent application on top of the Internet.
1
Databases [21 points]
For the following database tasks the relational database from the lecture (SQL Murder Mystery) with the
following tables (relations), columns (attributes), and keys is given.
Please create the following queries in SQL (no Python) and answer the respective questions.
Strictly adhere to the following formatting instructions. Deviating formatting will not be considered correct.
• Upper and lower case
– All table and column names must be written exactly as above.
– All SQL keywords must be written completely in capital letters, e.g. ”SELECT” (instead of ”select”
or ”Select”) or ”COUNT” (instead of ”count” or ”Count”).
• Do NOT use abbreviations of table names in SQL code.
• Do NOT rename columns in the output.
• Do NOT insert line breaks, but write the SQL code in one line.
• Do NOT terminate the SQL code with a semicolon or similar.
• When asked for specific columns, output ONLY those and no others.
• Keep the SQL code minimal to achieve the desired result, i.e., if, for example, sorting is not asked for and
is not otherwise necessary, then do not sort.
Attached is a correct example of outputting all names of all persons:
SELECT name FROM person
Question 12
Display an alphabetically sorted list (A,B, ...) of street names (address street name) in the database. Make
sure the list contains unique values only. To do this, complete the gaps AAA-CCC in the following SQL query.
AAA
FROM BBB
3 CCC
1
2
AAA:
BBB:
CCC:
Question 13
We are looking for BMW (car make) drivers with an annual income of less than 40000. How do genders rank
in this group? Your SQL query should return a sorted list of genders (gender ) starting with the most frequent
gender in this group. To do this, complete the gaps AAA-MMM in the following SQL query.
AAA
BBB drivers_license
3 CCC
person
4
ON DDD . EEE = drivers_license . FFF
5 JOIN
GGG
6
ON GGG . ssn = HHH
7 III
= ’ BMW ’
8 JJJ
< 40000
9 KKK
gender
10 LLL ( gender )
MMM
1
2
AAA:
BBB:
CCC:
DDD:
EEE:
FFF:
GGG:
HHH:
III:
JJJ:
KKK:
LLL:
MMM:
Question 14
You want to insert a new person with a new interview a new drivers license and a new ssn and annual income.
What would be legitimate sequences to insert values in the affected tables given the constraint, that the referential integrity must not be broken at any time.
□ income, drivers license, person, interview
□ interview, person, income, drivers license
□ person, interview, income, drivers license
□ drivers license, income, person, interview
□ person, interview, drivers license, income
□ some other sequence not listed here
2
Data Science [37 points]
Question 15
Given is the following DataFrame:
1
2
import numpy as np
import pandas as pd
3
df = pd . DataFrame ({ ’ Huawei_Hzf34X ’: [5 , 8 , 7 , 0] ,
’ Huawei_HfEW34X ’: [0 , 3 , 6 , np . nan ] ,
6
’ Huawei_H5Zf34X ’: [8 , 6 , 10 , np . nan ] ,
7
’ Huawei_HSFERWX ’: [5 , 7 , 6 , np . nan ] ,
8
’ Fronius_e5643 ’: [23 , 18 , 24 , np . nan ] ,
9
’ Fronius_edf43 ’: [4 , 3 , 6 , 5] ,
10
’ Fronius_esaf3 ’: [3 , 0 , 4 , 1] ,
11
’ SMA_63 ’: [4 , 3 , 5 , 2] ,
12
’ SMA_634 ’: [2 , 1 , 3 , 1] ,
13
’ SMA_635 ’: [9 , 4 , 12 , 4]} ,
4
5
14
index =[ ’ August ’ ,
’ September ’ ,
’ October ’ ,
’ November ’ ])
15
16
17
18
It contains monthly production data from photovoltaic (PV) systems that are installed on three buildings. On
each building PV inverters from a specific manufacturer have been used:
• Building A has Huawei inverters
• Building B has Fronius inverters
• Building C has SMA inverters
Someone has written Python code to rename the columns of df so that they contain building names and inverter
numbers instead of those difficult-to-remember IDs. The resulting df looks like this:
You found the source code for renaming the columns of df :
1
buildings = []
2
for col in df . columns :
if col [:3] == ’ Huaw ’:
5
if ’ Building A ’ in buildings :
6
buildings [ ’ Building A ’] += 1
7
else :
8
buildings [ ’ Building A ’] = 1
9
df . rename ( columns ={
10
col : ’ Building A , Inverter ’ + str ( buildings [ ’ Building A ’
,→ ])
11
} , inplace = True )
3
4
12
13
14
15
16
17
18
19
20
elif col [:3] == ’ Fro ’:
if ’ Building B ’ in buildings :
buildings [ ’ Building B ’] += 1
else :
buildings [ ’ Building B ’] = 1
df . rename ( columns ={
col : ’ Building B , Inverter ’ + str ( buildings [ ’ Building B ’
,→ ])
} , inplace = True )
21
22
23
24
25
26
27
28
29
elif col [:3] == ’ Sma ’:
if ’ Building C ’ in buildings :
buildings [ ’ Building C ’] = 1
else :
buildings [ ’ Building C ’] += 1
df . rename ( columns ={
col : ’ Building C , Inverter ’ + str ( buildings [ ’ Building C ’
,→ ])
} , inplace = True )
However, it turns out the source code may not be the latest version and is not suited to create the result shown
above. It still contains errors. Please enter the line of the source code, where the first respective error occurs,
i.e., enter only a single number for each error. If you think a specific error is NOT present, enter 0.
1. Variable has the wrong data type:
2. There is an inappropriate slicing of an iterable:
3. inplace is used wrongly:
4. There is a capitalization/case sensitivity issue:
5. A wrong value gets assigned but the data type is correct:
6. Double quotes instead of single quotes should have been used:
Finally, you fixed the source code but now you also want to have the total monthly production values entered
in an additional column called monthly total. Please write one line of code to achieve this goal:
Question 16
In addition to Accuracy, we have learned about the two metrics Recall and Precision to indicate the quality of
classification models.
Select all correct statements.
□ In a multi-class classifier, a Recall of 1.0 for one class can be achieved by always predicting this class.
□ In a multi-class classifier, a Precision of 1.0 for one class can be achieved by always predicting this class.
□ A binary classifier has to beat the Accuracy of 50% to be reasonable.
□ The F1 measure is the harmonic mean of Precision and Recall.
□ To compute the Accuracy and have a trustworthy result, the respective data should be balanced.
□ When evaluating a multi-class classifier, you must compute Precision, Recall, and F1-Score via micro average (micro), macro average (macro), or weighted average (weighted ) across the classes. This is necessary
because the metrics are per-class.
Question 17
Please interpret this Confusion Matrix and select all correct statments.
□ The Accuracy of the model is 0.6.
□ The Accuracy of the model is 6.
□ The Recall for class 1 is 0.625.
□ The Recall for class 1 is 0.5.
□ This result is typical of a multi-class classification task.
□ The Precision for class 1 is 0.833. . .
□ The Precision for class 1 is 0.25.
□ In this case, the F1 Score cannot be computed (division by zero).
Question 18
The following figure shows a binary classification case (red vs. blue) with two features (x1 and x2 ).
□ The distance δ1 is much higher than δ2 .
□ The distance δ2 is much higher than δ1 .
□ The two distances δ1 and δ2 cannot be compared.
□ Given how distinct these two classes appear, a distance-based classifier like a KNN classifier may be
well-suited for this task.
□ A distance-based classifier, like KNN, would achieve better results if this dataset were preprocessed in a
specific matter.
Question 19
Look at the following three figures:
They show three trained models. The orange line is the true function, the blue dots are all training examples,
and the blue line is the trained model. The first one shows a small model with a small number of trainable
parameters, the middle one has a medium number of trainable parameters, and the model on the right has a
large amount of trainable parameters.
Select all true statements.
□ The model on the right, with the largest number of parameters, captures the training set almost perfectly.
□ The model in the middle captures the training set almost perfectly.
□ The model on the left captures the training set almost perfectly.
□ The right model shows signs of overfitting.
□ The model on the right shows signs of underfitting.
□ The model on the left shows signs of overfitting.
□ The model on the left shows signs of underfitting.
□ Assuming a similar data distribution in the validation or test set, the model in the middle will show the
best performance out of these three models for these data sets.
□ Assuming a similar data distribution in the validation or test set, the model on the right will show the
best performance out of these three models for these data sets.
□ Assuming a similar data distribution in the validation or test set, the model on the left will show the best
performance out of these three models for these data sets.
Question 20
You have built a multi-class image classifier that is trained on distinguishing three classes: car, airplane, and
bicycle.
The training set consists of 1,000 images for each class and the validation set shows an macro-averaged F1 score
of 0.95. You are happy with the results and deploy the model publicly.
However, on the next day, you receive many complaints that your product always misclassified motorcycle images as bicycles.
Select all true statements
□ Although the customers are unsatisfied, you are happy that the model generalized from bicycle to twowheeled vehicles.
□ You are disappointed with your model because it should have predicted the correct class (motorcycle) or
at least notify the user that it could not classify the image correctly.
□ With all the user complaints that fortunately contain the misclassified images, you could train a new
model on the now four classes.
3
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )