Final Part 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

Operator overloading allows programs to compute results that could not be computed without operator overloading.

False

Since the Python list methods are written in compiled C code, using the Python list to write a program will always be faster than a linked list implemented in Python.

False

The indexing operation on lists returns a sublist of the original.

False

Theta notation is an effective measure of algorithm efficiency when the expected input size for the algorithm is small

False

When designing a program, one way of locating potential objects is by looking for verbs in the system description

False

Card(6, "c") < Card (3, "s")

True

Arrays do not allow efficient random access.

False

Class variables can be shared by all instances of a class

True

Encapsulation refers to combining the data and methods into one syntactic unit

True

In a linked structure, nodes contain references to other nodes.

True

Python dictionary keys must be immutable objects.

True

The worst case for the amount of time to insert at the beginning of an array-based list is the same as the amount of time to insert at the end of an array-based list.

True

Unit tests should be executed whenever you make a change to a class.

True

When should you use class variables? A. when each instance of the class needs its own copy of the data B. when each instance of the class can share the same copy of the data C. when the data is constant D. b and c

Answer: D

If a ϴ(log2n) algorithm requires 20 seconds to execute on an input of one million elements, approximately how long should it take on an input of two million elements? A. 21 seconds B. 25 seconds C. 30 seconds D. 40 seconds

Answer: A

If you are designing a class to represent a polynomial, which of the following should be instance variables? A. the coefficients B. a value to evaluate with the polynomial C. the result of evaluating the polynomial with a specific value D. all of the above

Answer: A

What is the worst-case running time of a method that inserts an item at the beginning of a link-based list? a. ϴ(1) B. ϴ(log2n) C. ϴ(n) D. ϴ(n^2)

Answer: A

If you are examining a Python class that someone else wrote, how do you determine if a variable is a local variable or an instance variable? A. the same variable name is used in more than one method B. the variable is accessed by placing self. before the variable name C. the variable is used in the __init__ method D. instance variables are always preceded by an underscore

Answer: B

Which of the following is not true of Python dictionaries? A. They are implemented as hash tables B. Values must immutable C. Lookup is very efficient D. All of the above are true

Answer: B

Which of the following is not true of Python lists? A. They are implemented underneath as contiguous arrays. B. All of the items in a list must be of the same type C. They can grow and shrink dynamically D. They allow for efficient random access

Answer: B

Which parts of the program description will be most helpful in identifying possible objects for a system design? A. adjectives B. nouns C. verbs D. all of the above

Answer: B

How much more memory does a simply linked implementation of a list require compared to an array-based list? A. They require the same amount B. Only extra memory for each instance variable such as head C. Extra memory for each instance variable plus 4 bytes on 32-bit systems for each item in the list to hold the reference to the next node D. Twice as much memory

Answer: C

If a ϴ(n^3) algorithm requires 4 seconds to execute on an input of one million elements, approximately how long should it take on an input of two million elements? A. 8 seconds B. 16 seconds C. 32 seconds D. 64 seconds

Answer: C

What is the time efficiency of the operation max(myList)? a. ϴ(log n) b. ϴ(n log n) c. ϴ(n) d. ϴ(n^2)

Answer: C

What is the worst-case running time of a method that inserts an item at the beginning of an array-based list? A. ϴ(1) B. ϴ(log2n) C. ϴ(n) D. ϴ(n^2)

Answer: C

A function with two loops has an asymptotic running time of? A. ϴ(log2n) B. ϴ(n) C. ϴ(n^2) D. Not enough information to determine

Answer: D

If a ϴ(2^n) algorithm requires 10 seconds to execute on an input of 10 elements, approximately how long should it take on an input of 20 elements? A. 20 seconds B. 100 seconds C. 1,000 seconds D. 10,000 seconds

Answer: D

If you write a __len__ method for a container class, how is that method called for an instance b of the class? A. b.len() B. len(b) C. b.__len__() D. either len(b) or b.__len__()

Answer: D

What is the purpose of unit testing? A. to help you to think about your design B. to help you find errors in your code C. to allow you to easily test your code each time you change it D. all of the above

Answer: D

What is the time efficiency of the selection sort algorithm? a. ϴ(log n) b. ϴ(n log n) c. ϴ(n) d. ϴ(n^2)

Answer: D

What operation is not support for Python dictionaries? a. Item insertion b. Item deletion c. Item lookup d. Item ordering (sorting)

Answer: D

A well-designed function/method often has undocumented side effects

False

A Python list is a homogeneous container

False

A class invariant is a set of properties that must be true before and after each method of class is executed.

True

A function with more lines of code can be faster than a function with fewer lines.

True

A list implemented using linked structures requires more memory than a list implemented as an array.

True

All ϴ(n^2) algorithms are O(n^2)

True

Assuming the pre- and postconditions and code are correct, the post condition is guaranteed to be true after the code is executed if the precondition is met before the code is executed.

True


Conjuntos de estudio relacionados

Research Methods in Psych exam 3

View Set

Perry/Hockenberry chapter 9. Maternal and Fetal Nutrition

View Set

Accounting Chapter 13 - Payroll Liabilities and Tax Records

View Set

Manufacturing planning and control systems (MPC)

View Set

Module 7: Developing the Product

View Set

Class Chart 10/05 - The Foreign Exchange Market + International Monetary System

View Set

Astronomy Midterm #2 Units 3 and 4

View Set

CHAPTER 30, 31, 32 REVIEW, Ch 30: Chest Injuries mergeee, Chapter 31 Abdominal and Genitourinary Injuries mergee

View Set