su23-midterm1

pdf

School

University of Wisconsin, Madison *

*We aren’t endorsed by this school

Course

320

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

14

Uploaded by BaronLapwingPerson1669

Report
Midterm 1 This is a preview of the published version of the quiz Started: Sep 20 at 8:44pm Quiz Instructions 1 pts Question 1 What translates Python code into machine code given an instruction set? process interpreter CPU operating system 1 pts Question 2 (Fill in the blank) In order to avoid a ghost commit, your head should always points to a when making a commit. commit branch tag
1 pts Question 3 The following graph indicate the current status of your repository, which of the following git commands will result in a fast-forwarding merge? Hint: Please note where the head is currently pointing to. git checkout main; git merge feature git checkout feature; git merge main git merge main git checkout feature; git merge bugfix git merge feature
1 pts Question 4 def magic(a, b): while True: yield a * b a = b b = a + b gen = magic(3, 2) print(next(gen)) print(next(gen)) print(next(gen)) What does the above code snippet print? 6 8 32 6 25 100 3 2 6 6 15 24 1 pts Question 5 Suppose N is an integer. What is the complexity of the following code snippet? sum = 0 for i in range(N): for j in range(i): sum += j O(N) O(N log N) O(N**2) O(log N)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
1 pts Question 6 Recall that if for some fixed constant , for large values. We want to show for the graph below. If , what is the LOWEST value that needs to be greater than or equal to? 5 200 100 2 3 6 1 pts Question 7
Which of the following will correctly run git status in the "CS320-SU23" directory using check_output ? check_output("git status") check_output(cwd = "CS320-SU23", ["git", "status"]) check_output("git status", cwd = "CS320-SU23") check_output(["git", "status"], cwd = "CS320-SU23") 1 pts Question 8 L is a list of N elements and L2 = [1,2,3]. Which of the following operations on L has the O(N) complexity? 1. L.pop(-10) 2. len(L) 3. max(L) 4. L.insert(10, "a") 5. L1.extend(L2) 6. L1[L2[1]] 3 and 4 1, 4, and 5 3, 4, and 5 2 and 3 2, 3, and 4 1, 3, and 4 1 pts Question 9
speaker_settings = {"volume": 1} class CustomMultiplierContext: def __init__(self, multiplier): self.multiplier = multiplier def __enter__(self): self.old_volume = speaker_settings["volume"] speaker_settings["volume"] *= self.multiplier def __exit__(self, exc_type, exc_value, traceback): speaker_settings["volume"] = self.old_volume print(speaker_settings["volume"]) with CustomMultiplierContext( 4 ): print(speaker_settings["volume"]) with CustomMultiplierContext( 2 ): print(speaker_settings["volume"]) with CustomMultiplierContext( 3 ): print(speaker_settings["volume"]) print(speaker_settings["volume"]) print(speaker_settings["volume"]) print(speaker_settings["volume"]) What does the above code snippet print? 1 1 1 1 1 1 1 1 4 8 24 24 24 24 1 4 8 24 8 4 1 1 4 2 3 2 4 1 1 pts Question 10 class Course: def __init__(self, name, number, instructor, semester="SU", year=2023): self.name = name self.number = number self.instructor = instructor self.semester = semester self.year = year c = Course(...) What is the minimum number of positional arguments is passed into Course.__init__ to create and initiate the Course object on the last line?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
4 3 5 6 1 pts Question 11 class Pyramid: def volume(self): return self.base_area() * self.height / 3 def base_area(self): return 0 class RectangularPyramid(Pyramid): def __init__(self, base_w, base_h, height): self.base_w = base_w self.base_h = base_h self.height = height def base_area(self): return self.base_w * self.base_h class SquarePyramid(RectangularPyramid): def __init__(self, base_l, height): super().__init__(base_l,base_l,height) Given the above code snippet, which methods are called in order when we run the following two lines? my_pyramid = SquarePyramid(2, 3) my_pyramid.volume() SquarePyramid.__init__, RectangularPyramid.__init__, Pyramid.volume SquarePyramid.__init__, Pyramid.volume, RectangularPyramid.base_area SquarePyramid.__init__, RectangularPyramid.__init__, Pyramid.volume, RectangularPyramid.base_area SquarePyramid.__init__, RectangularPyramid.__init__, Pyramid.volume, Pyramid.base_area
1 pts Question 12 I want to display information of an object with customizable colors and fonts in jupyter notebook. Which of the following special methods should I implement to accomplish my goal? __repr__ _repr_svg __str__ _repr_html 1 pts Question 13 def foo(num): if num <= 1: return 1 return foo(num - 1) + 2 * foo(num - 2) print(foo(5)) What does the above code snippet print? 21 11 41 8 1 pts Question 14 result = [] def magic(a,b):
if len(a) == 0 and len(b) == 0: return elif len(a) < len(b): result.append(b[-1]) magic(a, b[:-1]) else: result.append(a[-1]) magic(a[:-1], b) magic([1,2,3,4], [5,6]) What is result after running the above recursive function? [4,3,6,2,5,1] [1,2,3,5,4,6] [4,3,2,6,1,5] [1,2,5,3,6,4] 1 pts Question 15 Given the following graph, which of the following statement is true?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
A B C D E The graph is cyclic and weakly connected. The graph is acyclic and strongly connected. The graph is acyclic and weakly connected. The graph is cyclic and strongly connected. 1 pts Question 16 Let T be an empty Binary Search Tree. Then we insert the numbers in the following order using the insertion algorithm we introduced in lectures without balancing the tree in between: 4, 7, 2, 1, 3, 6, 5 Which of the following nodes share the same immediate parent? A. 2 and 3 B. 5 and 6
C. 1 and 3 D. 2 and 5 E. 3 and 6 F. 2 and 7 A and B B, C and F C and F D and E 1 pts Question 17 What is the time complexity of searching for an element in a balanced BST? O(N log N) O(log N) O(N**2) O(N) 1 pts Question 18 Given the following graph (both BFS and DFS questions have the same graph), what will the visiting order if we run BFS starting from node C to node B? Assume that for every node its children are alphabetically ordered.
A B F C E D C, A, E, F, B, D C, A, E, F, B C, A, B C, E, A, F, B 1 pts Question 19 Given the following graph (both BFS and DFS questions have the same graph), what will the visiting order if we run DFS starting from node C to node E? Assume that for every node its children are alphabetically ordered.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
A B F C E D C, A, B, E, F, D C, A, E C, A, B, E C, A, B, F, E 1 pts Question 20 from collections import deque import heapq heap = [-57, 94, 84, -100, 85, 43] heapq.heapify(heap) queue = deque() while heap:
Quiz saved at 8:44pm item = heapq.heappop(heap) queue.appendleft(item) What is queue after running the above code snippet? deque([94, 85, 84, 43, -57, -100]) deque([-100, -57, 43, 84, 85, 94]) deque([-100, -57, 43, 94, 85, 84]) deque([-100, -57, 84, 43, 85, 94]) Submit Quiz