PRACTICE QUESTIONS:
void foo(int x) {
int* const p = &x; //line A
x = 28; //line B
cout << *p << ''; //line C
*p = 42; //line D
}
int main() {
int y = 17;
foo(y);
cout << y << endl;
}
Question 3 (25 points)
In this question, you should implement the following function:
def remove_duplicates(lnk_lst)
Question 1
Given the following binary search tree bst:
9
/ \
/ \
7 13
/ / \
/ / \
3 11 15
/ \
/ \
1 5
Submission instructions:
-
For this assignment, you should turn in four files:
a. A file containing the definition of the LinkedBinaryTree class, including all the additional methods implemented in this assignment (questions 2 and 4).
b. 3 ‘.py’ files: each one includes the functions you wrote for questions 1, 3 and 5.Name your files: ‘YourNetID_hw7_q1.py’, ‘YourNetID_hw7_q3.py’, and ‘YourNetID_hw7_q5.py’.Note: your netID follows an abc123 pattern, not N12345678.
-
In this assignment, we provided ‘LinkedBinaryTree.py’ file (with the implementation of a binary tree).
-
You should submit your homework via Gradescope. For Gradescope’s autograding feature to work:autograding feature to work:
a. Name all functions and methods exactly as they are in the assignment specifications.
b. Make sure there are no print statements in your code. If you have tester code, please put it in a “main” function and do not call it.
Question 1
Consider the following definition of the left circular-shift operation: lf seq is the sequence , the left circular-shift of seq is ,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: , is: .
Question 1
Define a LinkedQueue class that implements the Queue ADT.
Implementation Requirement: All queue operations should run in worst-case.
Question 1
Implement an interpreter-like postfix calculator. Your program should repeatedly:
- Print a prompt to the user. The prompt should be: ‘
-->
’ - Read an expression from the user
- Evaluate that expression
- Print the result
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
Question 1
Question 2
Question 3
Question 4
Give a recursive implement to the following function:
def list_min(lst, low, high)
The function is given lst
, a list of integers, and two indices: low
and high
(), which indicate the range of indices that need to be considered.
-
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.
Submission instructions:
a) Youshouldturnin6files:
-
3 ‘.py’ files: one, with all the code related, to each of the questions 2-4.Name your files: ‘YourNetID_hw3_q2.py’, ‘YourNetID_hw3_q3.py’, and
‘YourNetID_hw3_q4.py’.
-
A ‘.pdf’ file with all your written answers. Name your file: ‘YourNetID_hw3.pdf’ Note: your netID follows an abc123 pattern, not N12345678.
-
YoushouldsubmityourhomeworkviaGradescope.
Question 1:
Use the definitions of and of in order to show the following:
Vitamins (30 minutes)
For big-O proof, show that there exists constants c, and such that for every , then .
Question 1
Draw the memory image for evaluating the following code:
为以下代码绘制内存图像:
>>> lst1 = [1, 2, 3]
>>> lst2 = [lst1 for i in range(3)]
>>> lst2[0][0] = 10
>>> print(lst2)
Homework #1
Due by Thursday 9/21, 11:59pm
Submission instructions:
- For this assignment, you should turn in 6 files:
-
A ‘.pdf’ file for the first question.
Name your file: ‘YourNetID_hw1_q1.pdf’
-
5 ‘.py’ files, one for each question 2-6. Name your files:
‘YourNetID_hw1_q2.py’ and ‘YourNetID_hw1_q3.py’, etc.
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.
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:
- 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)