Let's go through each question and identify the correct responses.
Question 1: Which of the following is false?
- A heap must be manually managed. - True, in languages like C/C++, memory management in the heap needs to be done manually.
- A stack uses a last in, first out (LIFO) approach. - True, that's the definition of a stack.
- A heap is generally faster than a stack. - False, a stack is generally faster than a heap because stack allocations and deallocations are simpler and more efficient.
- A stack automatically deallocates space when variables are no longer needed. - True, this happens when the function call scope ends.
Answer to Question 1: A heap is generally faster than a stack. (This statement is false.)
Question 2: True or False? In Python, a file is always automatically closed for you after you are done reading it or writing to it.
- Answer: False. In Python, if you do not explicitly close the file or use a
with
statement, the file will not be automatically closed.
Question 3: What type of file is best for storing discrete items that are stored in rows?
- Answer: CSV. CSV (Comma-Separated Values) files are specifically designed to store tabular data in rows.
Question 4: Which of the following is the correct way to instantiate an object belonging to the user-defined class Dog that has attributes of name and breed?
- pet = new Dog("Fido", "puppy", "Dalmatian") - Incorrect syntax (Python does not use
new
). - dog = new Dog(self, "Oscar", "Lab") - Incorrect syntax (also includes
self
incorrectly in this context). - dog = Dog(self, "Buddy", "Boxer") - Incorrect; similar to above regarding
self
. - pet = Dog("Spot", "Dalmatian") - Correct, assuming the class
Dog
has a constructor that takes the name and breed as parameters.
Answer to Question 4: pet = Dog("Spot", "Dalmatian").
Summary of Answers
- False: A heap is generally faster than a stack.
- False
- CSV
- pet = Dog("Spot", "Dalmatian")