Question: Problem 1 : Find Crossover Indices. We have two cross over points. Your algorithm may output either i = 0 or i = 3 .

Problem 1: Find Crossover Indices. We have two cross over points. Your algorithm may output either i=0 or i=3.
(A) Design an algorithm to find an index iin{0,1,dots,n-1} such that xiyi but x,yxxyyxy(n)0xi+1.
Describe your algorithm using python code for a function findCrossoverIndexHelper(x,y, left, right)
xis a list ofx values sorted in increasing order.
yis a list ofy values sorted in increasing order.
x and y are lists of same size (n).
left and right are indices that represent the current search region in the list such that 0 left right n
Your solution must use recursion.
Hint: Modify the binary search algorithm we presented in class. In []: #First write a "helper" function with two extra parameters
# left, right that ddedscribes the search region as shown below
def findCrossoverIndexHelper(x, y, left, right):
# Note: Output index i such that
# left i right
# ,x[i]y[i]
# First, Write down our invariants as assertions here
assert(len (x)==len(y)
assert(left >=0)
assert(left = right-1)
assert(right len(x))
# Here is the key property we would like to maintain.
assert(x[left]> y[left])
assert right
You are given data that consists of points (x0,y0),dots,(xn,yn), wherein yn>xnin-1yixiyi+1>xi+1i=3i=0i=3iin{0,1,dots,n-1}xiyix,yxxyyxy(n)0nxi+1.
Describe your algorithm using python code for a function findCrossoverIndexHelper(x,y, left, right)
xis a list ofx values sorted in increasing order.
yis a list ofy values sorted in increasing order.
x and y are lists of same size (n).
left and right are indices that represent the current search reaion in the list such that 0 left right ny0 and yn>xn.
Find a "cross-over" index i between 0 and n-1 such that yixi and yi+1>xi+1.
Note that such an index must always exist (convince yourself of this fact before we proceed).
Example
Your algorithm must find the index i=3as the crossover point.
On the other hand, consider the data
We have two cross over points. Your algorithm may output either i=0ori=3.
(A) Design an algorithm to find an index iin{0,1,dots,n-1} such that xiyi but xi+1.
Describe your algorithm using python code for a function findCrossoverIndexHelper(x,y, left, right)
xis a list ofx values sorted in increasing order.
yis a list ofy values sorted in increasing order.
x and y are lists of same size (n).
left and right are indices that represent the current search reaion in the list such that 0 left right ny0as well.
Furthermore, itis given that y0 and yn>xn.
Find a "cross-over" index i between 0 and n-1 such that yixi and yi+1>xi+1.
Note that such an index must always exist (convince yourself of this fact before we proceed).
Example
Your algorithm must find the index i=3as the crossover point.
On the other hand, consider the data
We have two cross over points. Your algorithm may output either i=0ori=3.
(A) Design an algorithm to find an index iin{0,1,dots,n-1} such that xiyi but xi+1.
Describe your algorithm using python code for a function findCrossoverIndexHelper(x,y, left, right)
xis a list ofx values sorted in increasing order.
yis a list ofy values sorted in increasing order.
x and y are lists of same size (n).
left and right are indices that represent the current search reaion in the list such that 0 left right nx0, and y0as well.
Furthermore, itis given that y0 and yn>xn.
Find a "cross-over" index i between 0 and n-1 such that yixi and yi+1>xi+1.
Note that such an index must always exist (convince yourself of this fact before we proceed).
Example
Your algorithm must find the index i=3as the crossover point.
On the other hand, consider the data
We have two cross over points. Your algorithm may output either i=0ori=3.
(A) Design an algorithm to find an index iin{0,1,dots,n-1} such that xiyi but xi+1.
Describe your algorithm using python code for a function findCrossoverIndexHelper(x,y, left, right)
xis a list ofx values sorted in increasing order.
yis a list ofy values sorted in increasing order.
x and y are lists of same size (n).
left and right are indices that represent the current search reaion in the list such that 0 left right n
Problem 1 : Find Crossover Indices. We have two

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!