Question: # NOTE: This implementation of insertion sort is provided for you. # NOTE: DO NOT EDIT THIS FUNCTION IN THIS FILE. def insertion _ sort
# NOTE: This implementation of insertion sort is provided for you.
# NOTE: DO NOT EDIT THIS FUNCTION IN THIS FILE.
def insertionsortarr:
# Set index to for the outer loop.
index
# The outer loop steps the index variable through
# each subscript in the list, starting at This
# is because element is considered already sorted.
while index lenarr:
# The first element outside the sorted subset is
# arrindex Assign the value of this element
# to unsortedvalue.
unsortedvalue arrindex
# Start the scan variable at the subscript of the
# first element outside the sorted subset.
scan index
# Move the first element outside the sorted subset
# into its proper position within the sorted subset.
while scan and arrscan unsortedvalue:
arrscan arrscan
scan scan
# Insert the unsorted value in its proper position
# within the sorted subset.
arrscan unsortedvalue
# Increment index.
index index
# NOTE: This implementation of binary search is provided for you!
# NOTE: DO NOT EDIT THIS FUNCTION IN THIS FILE.
def binarysearcharr value:
# Set the initial values.
first
last lenarr
position
found False
# Search for the value
while not found and first last:
# Calculate the mid point.
middle intfirst last
# If the value is found at the mid point...
if arrmiddle value:
found True
position middle
# else if value is in the lower half...
elif arrmiddle value:
last middle
# else if value is in the upper half...
else:
first middle
# Return the position of the item, or
# if it was not found.
return position
# TODO: We want to run binary search on this list to find a certain element.
# But something is wrong with this list that prevents us from doing that.
# Do you know what it is You should fix that first.
testlist
# TODO: Once you have "fixed" the list so that you can run binary search on it
# you should find the index of this target number.
# HINT: Look at the functions defined in this file.
targetnumber
binarysearchtargetnumber
printFound at this index in fixed list:
# TODO: Print the index of targetnumber in the fixed list. You
# just need to print the number below. That's it
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
