2025/2026 CIT 332 FINAL EXAM
QUESTIONS AND DETAILED CORRECT
ANSWERS | A+ GRADE VERIFIED
ANSWERS
The list [20, 30, 40, 10] is sorted by insertion sort with 3
calls to the insert method. How many of those calls need
to modify the location of at least one element in the list
and why? Correct Answer One call - only the last call to
insert modifies the location of an element since it starts
with [<20, 30, 40> ,10]
The list [40, 10, 20, 30] is sorted by insertion sort with
three calls to the insert method. How many of those calls
need to modify the location of at least one element in the
list and why? Correct Answer All calls to insert modify an
element's location - since all elements to be inserted are
smaller than 40.
To sort a list in descending order, what changes are
needed in the insert function? Correct Answer Change the
condition for the while to: i >= 0 and elements[i] < target.
Given a sorted list with 1,000,000,000 elements, how
many comparisons are needed to find an element in the
worst case? Correct Answer 30
What's the output of the following code?
def find(all, target):
,left = 0
right = len(all) - 1
while left <= right:
mid = (left + right) // 2
print(mid, all[mid])
if all[mid] == target:
return mid
elif all[mid] > target:
right = mid - 1
else:
left = mid + 1
return -1
def main():
all = [1, 2, 5, 8, 11, 15, 19]
print(find(all, 6))
main() Correct Answer 3 8
12
25
-1
What's the output of the following code?
def find(all, target):
left = 0
right = len(all) - 1
while left <= right:
mid = (left + right) // 2
print(mid, all[mid])
if all[mid] == target:
return mid
elif all[mid] > target:
right = mid - 1
,else:
left = mid + 1
return -1
def main():
all = [1, 2, 5, 8, 11, 15, 19]
print(find(all, 5))
main() Correct Answer 3 8
12
25
2
Given the following statement in a code
from random import *
which of the following is a correct statement to shuffle list
list1? Correct Answer shuffle(list1)
What is the output of the following code?
aList = [1, 2, 3, 4]
aList.reverse()
print(aList) Correct Answer [4, 3, 2, 1]
What is the output when the following code segment is
executed?
firstList = [10, 31, 85, 96]
secondList = firstList
secondList[1] = 400
print(secondList)
print(firstList == secondList) Correct Answer [10, 400, 85,
96] True
, Suppose list1 is [13, 18, 59, 21, 75, 44], what are the
elements of list1 after executing list1.pop()? Correct
Answer [13, 18, 59, 21, 75]
Suppose that list1 is [99,16, 85, 43], What is the result of
list1[:-1]? Correct Answer [99,16, 85]
Given a list1 with the following value:
list1 = [ [9, 7, 4], [0, 99, 8], [74, 33, 89]]
which of the following expression has the value of 99.
Correct Answer list1[1][1]
What's the output of the following code?
aList = [1, 3, 4, 2, 4, 2, 4]
m = aList[0]
index = 0
for i in range(len(aList)):
if aList[i] > m:
m = aList[i]
index = i
print(index) Correct Answer 2
What's the output of the following code?
list1 = ['XYZ', 'Zara', 'abc']
print(max(list1)) Correct Answer abc
What's the output of the following code?
sList = [1, 2, 3, 4, 5]
print(sList[-2])
print(sList[-4:-1]) Correct Answer 4
[2, 3, 4]
QUESTIONS AND DETAILED CORRECT
ANSWERS | A+ GRADE VERIFIED
ANSWERS
The list [20, 30, 40, 10] is sorted by insertion sort with 3
calls to the insert method. How many of those calls need
to modify the location of at least one element in the list
and why? Correct Answer One call - only the last call to
insert modifies the location of an element since it starts
with [<20, 30, 40> ,10]
The list [40, 10, 20, 30] is sorted by insertion sort with
three calls to the insert method. How many of those calls
need to modify the location of at least one element in the
list and why? Correct Answer All calls to insert modify an
element's location - since all elements to be inserted are
smaller than 40.
To sort a list in descending order, what changes are
needed in the insert function? Correct Answer Change the
condition for the while to: i >= 0 and elements[i] < target.
Given a sorted list with 1,000,000,000 elements, how
many comparisons are needed to find an element in the
worst case? Correct Answer 30
What's the output of the following code?
def find(all, target):
,left = 0
right = len(all) - 1
while left <= right:
mid = (left + right) // 2
print(mid, all[mid])
if all[mid] == target:
return mid
elif all[mid] > target:
right = mid - 1
else:
left = mid + 1
return -1
def main():
all = [1, 2, 5, 8, 11, 15, 19]
print(find(all, 6))
main() Correct Answer 3 8
12
25
-1
What's the output of the following code?
def find(all, target):
left = 0
right = len(all) - 1
while left <= right:
mid = (left + right) // 2
print(mid, all[mid])
if all[mid] == target:
return mid
elif all[mid] > target:
right = mid - 1
,else:
left = mid + 1
return -1
def main():
all = [1, 2, 5, 8, 11, 15, 19]
print(find(all, 5))
main() Correct Answer 3 8
12
25
2
Given the following statement in a code
from random import *
which of the following is a correct statement to shuffle list
list1? Correct Answer shuffle(list1)
What is the output of the following code?
aList = [1, 2, 3, 4]
aList.reverse()
print(aList) Correct Answer [4, 3, 2, 1]
What is the output when the following code segment is
executed?
firstList = [10, 31, 85, 96]
secondList = firstList
secondList[1] = 400
print(secondList)
print(firstList == secondList) Correct Answer [10, 400, 85,
96] True
, Suppose list1 is [13, 18, 59, 21, 75, 44], what are the
elements of list1 after executing list1.pop()? Correct
Answer [13, 18, 59, 21, 75]
Suppose that list1 is [99,16, 85, 43], What is the result of
list1[:-1]? Correct Answer [99,16, 85]
Given a list1 with the following value:
list1 = [ [9, 7, 4], [0, 99, 8], [74, 33, 89]]
which of the following expression has the value of 99.
Correct Answer list1[1][1]
What's the output of the following code?
aList = [1, 3, 4, 2, 4, 2, 4]
m = aList[0]
index = 0
for i in range(len(aList)):
if aList[i] > m:
m = aList[i]
index = i
print(index) Correct Answer 2
What's the output of the following code?
list1 = ['XYZ', 'Zara', 'abc']
print(max(list1)) Correct Answer abc
What's the output of the following code?
sList = [1, 2, 3, 4, 5]
print(sList[-2])
print(sList[-4:-1]) Correct Answer 4
[2, 3, 4]