跳至主要內容
NYU CS-UY 1134 复习

Question 3 (25 points)

In this question, you should implement the following function:

def remove_duplicates(lnk_lst)

AI悦创原创...大约 3 分钟python 1v1NYU – Tandon School of Engineering
NYU CS-UY 1134 Midterm Exam

Question 1

Consider the following definition of the left circular-shift operation:
lf seq is the sequence <a1,a2,...an1,an><a_1, a_2,...a_{n-1}, a_n> , the left circular-shift of seq is <a2,a3,,an,a1><a_2, a_3,…,a_n, a_1> ,that is the sequence we get when moving the first entry to the last position, while shifting all other entries to the previous position. For example, the left circular-shift of: <2,4,6,8,10><2, 4, 6, 8, 10>, is: <4,6,8,10,2><4, 6, 8, 10, 2>.


AI悦创原创...大约 13 分钟python 1v1NYU – Tandon School of Engineering
NYU CS-UY 1134 Practice

Question 1

题目

给定以下 Python 代码:

import copy

list1 = [1, [2, 3], 4]
list2 = list1.copy()
list3 = copy.deepcopy(list1)

list2[0] = 0
list2[1][0] = 0

list3[1][1] = 0

AI悦创原创...大约 18 分钟python 1v1NYU – Tandon School of Engineering
NYU CS-UY 1134 Lab 6
  1. For each of the following code snippets:

    a. Given the following inputs, trace the execution of each code snippet.Write down all outputs in order and what the functions return.

    b. Analyze the running time of each. For each snippet:

    ​ i. Draw the recursion tree that represents the execution process of the function, and the cost of each call

    ​ ii. Conclude the total (asymptotic) run-time of the function.


AI悦创原创...大约 3 分钟python 1v1NYU – Tandon School of Engineering
NYU CS-UY 1134 Lab3

Vitamins (30 minutes)

For big-O proof, show that there exists constants c, and n0n_0 such that f(n)cg(n)f(n) ≤ c*g(n) for every nn0n ≥ n_0, then f(n)=O(g(n))f(n) = O(g(n)).


AI悦创原创...大约 8 分钟python 1v1NYU – Tandon School of Engineering
NYU CS-UY 1134 Lab1

Vitamins (10 minutes)

Write the output for the following lines of code given the Student class. (10 minutes).

为以下代码写输出,给定的是Student类。(10分钟)。

Coding

In this section, it is strongly recommended that you solve the problem on paper before writing code. This will be good practice for when you write code by hand on the exams.


AI悦创原创...大约 4 分钟python 1v1NYU – Tandon School of Engineering
NYU – Tandon School of Engineering CS-UY 1114 Final Review

The Story

Professor and Pokémon trainer Katz wants to be the very best that no one ever was. To that end, he has travelled across the land and caught and trained a bunch of Eevees , which have now evolved. His team looks like this at the moment:


AI悦创原创...大约 4 分钟python 1v1NYU – Tandon School of Engineering
NYU – Tandon School of Engineering True Exam – 16 December 2021
  1. Evaluate this code. What will be printed
class Animal:
    def __init__(self, name, species, age):
        self.name = name
        self.species = species
        self.age = age

    def is_adult(self):
        return self.age > 3

    def is_young(self):
        return self.age < 1

    def __str__(self):
        return "{} ({}, {} years old)".format(self.name, self.species, self.age)

    def __repr__(self):
        return "Animal('{}', '{}', {})".format(self.name, self.species, self.age)

def main():
    cat = Animal("Fluffy", "cat", 2)
    dog = Animal("Rover", "dog", 4)
    bird = Animal("Tweety", "bird", 1)
    fish = Animal("Nemo", "fish", 0.5)

    a = cat.is_adult()
    b = dog.is_young()
    c = repr(bird)
    d = str(fish)
    e = fish.is_adult()
    f = bird.name

    print('It is', b, bird.name, "is young")
    print(b)
    print(c)
    print(bird)
    print(d)
    print(e)
    print(f)

AI悦创原创...大约 3 分钟python 1v1NYU – Tandon School of Engineering
NYU – Tandon School of Engineering Final Exam – 16 December 2021

Final Exam – 16 December 2021

  1. (15 Points) Provide the value of the variable “var” (use python form to show the appropriate data type, e.g. “str” , [list], etc). Note: following code snippets will not produce errors.

Value of var after code runs


AI悦创原创...大约 13 分钟python 1v1NYU – Tandon School of Engineering