Multiple Choice Questions on Linked Structures and Iterators 1. What is the worst-case running time of a method that inserts an item at the beginning
Multiple Choice Questions on Linked Structures and Iterators
1. What is the worst-case running time of a method that inserts an item at the beginning of an arrray-based list?
a) (1)
b) (log2n)
c) (n)
d) (n2)
2. What is the worst-case running time of a method that inserts an item at the beginning of a linked-based list?
a) (1)
b) (log2n)
c) (n)
d) (n2)
3. What is the worst-case running time of a method that inserts an item at the end of an array-based list?
a) (1)
b) (log2n)
c) (n)
d) (n2)
4. What is the worst-case running time of a method that inserts an item at the end of a linked-based list if you only have an instance variable that refers to the first node in the list?
a) (1)
b) (log2n)
c) (n)
d) (n2)
5. How much more memory does a simple 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 system for each item in the list to hold the reference to the next node
d) twice as much memory
6. 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_ _()
8. If you want to write an iterator that uses the yield statement, what methods must to write?
a) the _ _iter_ _ and the next methods
b) only the _ _iter_ _ method
c) only the next method
d) you cannot write an iterator using the yield statement
9. If you do not use the yield statement to write an iterator, what methods must you write?
a) the _ _iter_ _ and the next methods
b) only the _ _iter_ _ method
c) only the next method
d) you cannot write an iterator using the yield statement
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started