Question: Use Python to develop and test a program to solve the following problem. Suppose we have two n - element lists of numbers, Dlist and

Use Python to develop and test a program to solve the following problem. Suppose we have two n-element lists of numbers, Dlist and Ilist. The list Dlist is sorted in decreasing order, and the list Ilist is sorted in increasing order, i.e. Dlist[i]>= Dlist[i+1] and Ilist[i]<= Ilist[i+1] for each i in 0...n-2. You are to write two versions of a function to determine whether there is an i such that Dlist[i] is equal to Ilist[i]. If there is an index where the elements are equal, your function must return the index; otherwise it must return -1. Your main program will print "YES, equal at index = #" where # is the index where they are equal; or "NO" if there is no index where they are equal. Version a) Write a function seqsearch(DS,IS) that uses a sequential search to solve this problem where DS is a list in decreasing order and IS is a list in increasing order. It should return the index where the elements are the same or -1 if there is no such index. Version b) If you find an index i where the list values are not equal, you should be able to determine whether to search to the right or to the left.. Write a function binsearch(DB,IB) that uses a binary search to solve this problem where DB is a list in decreasing order and IB is a list in increasing order. It should return the index where the elements are the same or -1 if there is no such index.

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!