Last set of python problem. Thank you very much! Examine the following code and
ID: 666648 • Letter: L
Question
Last set of python problem. Thank you very much!
Examine the following code and answer the following question without running it.
The preceding Python statements will print False because
A) x is not equal to y
B)sorted(x) is not equal to sorted(y)
C)x.sort() is not equal to y.sort()
D)x.sort() is not equal to sorted(y)
PROBLEM 2-2
(2 points possible)
Suppose you have a class called At. There exists a special method defined in the class with two underbars called __lt__ that tests whether one instance of the class, a, is less than another instance of the class, b. Which is true?
A) a < b is syntactically correct
B) a.__lt__(b) is syntactically correct
C) Both of the above
D) None of the above
PROBLEM 2-3
(2 points possible)
The function 8000nlog(n)+1000log(n)+40n300+2n is
A) O(2^n) B) O(nlog(n)) C) O(n^300) D)O(log(n))
PROBLEM 2-4
(2 points possible)
Consider the function f below. What is its big oh complexity?
A)O(1) B)O(log(n)) C)O(n) D)O(n^2)
PROBLEM 2-5
(2 points possible)
Consider the code:
Which of the following does NOT cause an exception to be thrown?
A)print L[3] B)print d['b']
D) print int('abc') E) None of the above
Explanation / Answer
1.
D)x.sort() is not equal to sorted(y)
x.sort() soesnt return anythind, whereas sorted(y) returns a list containing the elements of y sorted.
2.
B) a.__lt__(b) is syntactically correct
3.
C) O(n^300), because complexity in a complex function is the highest complexity from its individual terms
4.
C)O(n), because the function g(m)'s loop doesn't run at all. Because m = 0
5.
A has exception, b, d have errors, c has infinite loop
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.