关键词 > ICS

ICS Fall 2020 Final Exam

发布时间:2024-05-13

Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ICS Fall 2020

Final Exam

You have 2 hours to complete the whole exam. The exam materials include the following items:

●  answers.txt

Q1_help_indiana_student.py

Q2_floyd_warshall_student.py

The exam is open-book. Please have your answers to non-programming questions in answers.txt. When finished, please submit your answers into the NYU Classes Assignment / Final exam. Moreover, you are given 10 minutes to submit your answers.

(Note: If your submission is received after 10:40 pm (Shanghai time), you will get a 10-point-offpunishment.)

READ EACH QUESTION CAREFULLY BEFORE YOU PROCEED WITH SOLVING IT.

Part 1: Short Lecture Questions (40 points)

Note: save your answers in answers.txt

1.  According to the principles of locality (i.e., spatial/temporal locality), in the following code, which variables (and/or elements) are most likely to be put into the Cache when the code is running. (5 points)

a = [1, 3, 5, 7]

b = [2, 4, 6, 8]

c = 5

n = 0

while n < 4:

n += 1

print(a[n])

A.  n, a[n], c

B.  n, a[-1], a[n+1]

C.  b[n+1], n

D.  n, a[n+1]

2. What is the complexity of running min_sort(lst)when   lst is a list of n numbers  (in big-O notation)? (5 points)

N = len(lst)

def min_sort(lst) :

if len(lst) <= 1:

return lst

new = []

for n in range(N) :

m = lst[0]

for i in range(1,len(lst)) :

if lst[i] < m:

m = lst[i]

new .append(m)

lst .remove(m)

return new

3. Which one of the following statements about Object Oriented Programming (OOP) is true? (5 points)

A.     A “method is a component of a class that references data.

B.     The getter” method stores a value in a data attribute or changes its value.

C.     The _ _str_ _ method is automatically called when an object is created.

D.     One key advantage of OOP is that it can wrap data attributes and its relevant methods in a bundle.

4. What will be the output of the following code snippet? (5 points)

A. counter is 101 , number of times is 0

B. counter is 100, number of times is 0

C. counter is 100, number of times is 100

D. counter is 101, number of times is 101

5. Which of the following models are supervised learning algorithms? (Choose all that apply) (5 points)

A.  Linear regression

B.   K nearest neighbor classifier

C.   K means clustering analysis

D.   Deep convolutional neural network for image classification

6. Amdahl’s law can be used to estimate the speedup when your code runs on a single machine

that has a multi-core CPU. In such a case,  codes can be executed by different cores

simultaneously. Assume 80% of your code can be perfectly parallelized and executed on different cores (i.e., f = 0.2)

(a) How much speedup do you expect with a machine whose CPU has 16 cores (5 points)

(b) How much speedup do you expect if the CPU has infinite cores?(5 points)

Part 2: Programming

●   Q1 has multiple sub-questions with increasing difficulties.

●   You do NOT have to finish all sub-questions in Q1 before moving to Q2; choose your best strategy.

Q1. Helping Indiana Jones (again!)(50 points)

Few months after he came back from the lost temple, Indiana Jones would like to prepare for the next adventure. So, he decided to do some shopping on boxing day. You need to complete

the following tasks to help him in the shopping. Please put your code in

help_indiana_student .py.

1.   Implement the Item class, which represents an item of a product. The class contains the following methods (5 points each)

init ()

The code is given. It initializes an instance of Item, assigning the input name, price, and weight to self ._name, self ._price, and

self ._weight respectively. Note: you are not allowed to modify this method.

setName(), and getName()

You need to implement these two methods. setName() changes the name of the item to the new name, while getName() returns the name of the item.

setPrice(),

and

getPrice()

You need to implement these methods. setPrice() changes the price of the item to the new price, while getPrice() returns the price of the item.

setWeight(), and

getWeight()

You need to implement these methods. setWeight() changes the weight of the item to the new weight, while getWeight() returns the

weight of the item.

str ()

You need to implement this method. It overrides the inherited

__str__ () method, printing the name, price, and weight of the item in the format as the following:

add ()

You need to implement this method. It overrides the inherited

__add__ (), which adds the item to another item and returns a new item whose name is Total , the price is the sum of the prices of the two items, and the weight is the sum of the weights of the two items

2.   Implement the Cart class, which represents a shopping cart. The class contains the following methods. (5 points each)

init ()

The code is given. It initializes an instance of Cart. The Cart class has three attributes:

self .items which is a list type variable for storing items you

self .myCart which is a dict type variable for indexing these items. Each key in self .myCart is the name of an item, and

self .totalItems which counts the total number of items in the cart. If an item is added, it should be increased by 1, while when an item is removed, it should be decreased by 1.

Note: you are not allowed to modify this method.

getItems()

The code is given. It returns the self .items .

Note: you are not allowed to modify this method.

addItems()

You need to implement this method. It should add the new item into self .items and update the count in self .myCart .