CS 241 Exam

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What is the output of: for I in range(4): print(i)

0 1 2 3 4

Which of the following is NOT a benefit of encapsulation? Fewer lines of code to write Easier to change code later Easier for others to use our code Easier for us to use others' code

Fewer lines of code to write

If function A calls B, then B calls C, and C raises an exception, where can it be caught? Function A only Func C only Func B or C ( but not A) Func A, B, or C

Func A, B, or C

Relationship between a Car and a Steering Wheel? Is-a Has-a Either Is-a or Has-a Neither Is-a nor Has-a

Has-A

Which is the same as composition? Is-a Has-a Either Is-a or Has-a Neither Is-a nor Has-a

Has-A

What is the syntax for a lambda expression to return an item that has length greater than 3?

lambda x:x if len(x) > 3

What is the output of: try: print("1") raise ValueError("Yikes") print("2") except: print("3") print("4")

1, 3, 4

What is the output of: class A: def__init__(self): self.x = 10 class B(A): def__init__(self) super( ).__init__( ) self.y = 20 b = B( ) print(b.x)

10

What is the output of: x = 5 if x > 5: print("1") elif x < 5: print("2") else: print("3") print("4")

3, 4

What does a queue look like after the filling operations? enqueue 1 enqueue 2 enqueue 3 dequeue enqueue 4 dequeue dequeue enqueue 5 enqueue 6

4, 5, 6

What is the syntax for creating an abstract method in Python?

@abstractmethod def m( ):

What is a benefit of a setter function, as opposed to setting the data directly? We can include error checking on the value We can restrict the range of numbers that can be entered We can more easily change the internal representation of the class later All of these are benefits

All of these are benefits

What is the output of: class A: def m(self): print("Class A") classB(A): def__init__(self): def m(self) print("Class B") b = B( ) b.m( )

Class B

What type of data structure stores key-value pairs? Dynamic Array Linked List Stack Queue Binary Search Tree Set Dictionary (i.e., Hash Map)

Dictionary (i.e. Hash Map)

What is the best description for merge sort? Find the smallest value and merge it at the beginning of the list. Keep a sorted section of the list. Iteratively go through the remaining items and merge them into the correct spot in the sorted section. Divide the list into halves. Call merge sort on each half. Merge the two halves together. Pick a number in the list. Put all values less than it on the left. Put all values greater than it on the right. Call merge sort on each half.

Didvid the list into halves. Call merge sort on each law. Merge the two halves together.

Assume you are writing a program to handle novels, and picture books. You decide to create a base book class from which each will bee derived. What is an example of something that should not be in the base class? Author Illustrator ISBN (unique identifier for book) Title

Illustrator

What is a potential limitation or weakness of a dynamic array? Inserting at the front can be difficult. Inserting at the end can be difficult. Jumping directly to data in the middle can be difficult. Jumping directly to data at the end can be difficult.

Inserting at the front can be difficult

What type of relationship does a Visa card have to a Credit card? Is-a Has-a Either Is-a or Has-a Neither Is-a nor Has-a

Is-A

What type of relationship is the same as Inheritance? Is-a Has-a Either Is-a or Has-a Neither Is-a nor Has-a

Is-A

Why would we want to employ the principal of "information hiding"? It makes it easier to change our code later Keeps private data secure Hides which methods we have created from other users Makes it more difficult for others to hack our code

It makes it easier to change our code later

What is the effect on a derived class if the base class contains an abstract method?

It requires a derived class to override the method if the class is to be instantiated.

What is a potential limitation or weakness of a doubly-linked list? Inserting at the front can be difficult. Inserting at the end can be difficult. Jumping directly to data in the middle can be difficult. Jumping directly to data at the end can be difficult.

Jumping directly to data in the middle can be difficult.

What type of relationship does a textbook and flip phone have? Is-a Has-a Either Is-a or Has-a Neither Is-a nor Has-a

Neither Is-A not Has-A

What is the worst case time Complexity of a merge sort? O(1) O(log(n)) O(n) O(n log(n)) O(n^2) O(2^n)

O(n log(n))

Assuming an unsorted dynamic array, what is the time complexity of finding a given item? O(1) O(log(n)) O(n) O(n^2)

O(n)

What is the worst-case time complexity of an insertion sort? O(1) O(log(n)) O(n) O(n log(n)) O(n^2) O(2^n)

O(n^2)

After catching an exception, what keyword is used to jump back to where it was raised? return raise try you cannot jump back

You cannot jump back

Which of the following will create a list of even numbers? {x for x in range(100) where x % 2 == 0} {x for x in range(100) if x % 2 == 0} [x for x in range(100) where x % 2 == 0] [x for x in range(100) if x % 2 == 0]

[x for x in range(100) if x % 2 == 0]

What is "a custom definition typically consisting of data and its related functions"? Encapsulation Object Member variable Member function Class Exception

a Class

What is "Data is maintained in a sorted order"? Dynamic Array Linked List Stack Queue Binary Search Tree Set Dictionary (i.e., Hash Map)

a Dynamic array

What is "The data of a class" called? Encapsulation Object Member variable Member function Class Exception

a Member Variable

What is "The first item inserted will be the FIRST one removed." Dynamic Array Linked List Stack Queue Binary Search Tree Set Dictionary (i.e., Hash Map)

a Queue

What is "The first item inserted will be the LAST one removed." Dynamic Array Linked List Stack Queue Binary Search Tree Set Dictionary (i.e., Hash Map)

a Stack

What is "a function that belongs to a class"? Encapsulation Object Member variable Member function Class Exception

a member function

What is the best syntax to define a class, "B", that inherits from class "A" in python?

classB(A):

Assume a Pandas data frame named data, with a column named, "id". Which of the following filters the data frame to include all rows that do not have an id of "na"? data[id != "na"] data.id != "na" data[data.id != "na"] data.select(id != "na")

data[data.id != "na"]

Which of the following best computes a Fibonacci number (which is the sum of the two preceding values)? def fib(n): return fib(n-1) + fib(n-2) def fib(n): if n == 0: return 1 return fib(n-1) + fib(n-2) def fib(n): if n == 1: return 1 return fib(n-1) + fib(n-2) def fib(n): if n <= 1: return 1 return fib(n-1) + fib(n-2)

def fib(n): if n <= 1: return 1 return fib(n-1) + fib(n-2)

Which of the following demonstrates the best syntax for an if statement in Python? if (x > y){ print(x) } if (x > y) print(x) if x > y print(x) if x > y: print(x) if x > y:{ print(x) }

if x > y : print(x)

Consider a class containing the following init function: class MyClass: def __init__(self, x): self.x = x How is an object of type MyClass created? MyClass mc = MyClass( ) MyClas mc(10) mc = MyClass( ) mc = MyClass(10)

mc = MyClass(10)

What should a setter typically return?

nothing


संबंधित स्टडी सेट्स

Strategic Management Quizzes 1-8

View Set

Joseph Schumpeter - Creative Destruction

View Set

Katzung Pharmacology - Chapter 48 Qs

View Set

La Provence/ Marcel Pagnol and Jean de Florette

View Set