What is the Big - O of the following equation?
T(n) = 36n + 42n + n * log n
What is n * log n
100
Best case complexity of binary search.
What is O(1)
100
97 % 3
What is 1
100
myList = [7, 12, 14, 39, 64]
i = 0
while i < len(myList)-1:
print myList[i]
i = i + 1
Number of times i = i + 1 is executed.
What is 4
200
myString = "the cat in the hat came back"
print myString[4:7], myString[-4:len(myString):1]
What is "cat", "back"
200
def complexA(numbers):
n = len(numbers) # n is the problem size
result = 0
for i in range(n):
j = 1
while j < n:
result += numbers[i]*numbers[j]
j = j + 1
return result
What is O(n squared)
200
This algorithm sorts by repeatedly finding the minimum value in the unsorted portion of the list and moving it to its correct location.
What is the Selection Sort
200
2 ** 4
What is 16
200
x = 5
y = 6
print (x < 10) or (y > 6)
What is True
300
myList = [17, 29, 43, 62]
for i in myList:
if i < 20 or i > 40:
print i
What is [17, 43, 62]
300
def complexB(numbers):
N = len(numbers) # problem size
done = False
result = 0
i = 1
while i < N and not done:
if numbers[i] < 1000:
result += numbers[i]
else:
done = True
i += 1
return result
What is O(n)
300
This algorithm can sort integer values in O(n) time.
What is the Radix sort (or the "Beach Sort")
300
x = 17
y = x
x = 13
print y
What is 17
300
alist = [12, 24, 36, 43, 62, 29, 33, 66, 104, 206]
for i in range(2, len(alist), 3):
   print alist[i]
What is 36, 29, 104
400
aLine = "Roses are red, Violets are blue"
newLine = aLine.split()
x = len(newLine) + 10
print x
What is 16
400
def myFun(aList):
#aList is a list of strings
n = len(aList) #the problem size
for i in aList:
for j in aList[i]:
print j
for i in range(0:len(aList)):
print aList[i][0]
What is O(n)
400
The worst case complexity of the bubble sort.
What is O(n squared).
400
print 1,000,101
What is 1 0 101
400
See Flow 400 in Powerpoint
What is 28 (24 + 4)
500
myStr = "happy reading week, hope you have fun!"
myStr[-1] = "?"
myStr[0] = "H"
What is a big syntax error!
500
def comp(aList):
n = len(aList):
for i in aList:
for j in range(100):
print i, j
if i < 25:
for k in range(n):
print mylist[k], j
else:
for k in range(n):
print k
What is O(n squared)
500
myList = [76, 42, 29, 43, 22, 16]
The first pass of the insertion sort compares 76 with 76.
After 3 passes of the insertion sort, the list looks like this.