Question: Python code help- Main idea of binary search: Eliminating part of the problem space and narrow it down to smaller space to find the answer

Python code help- Main idea of binary search: Eliminating part of the problem space and narrow it down to smaller space to find the answer faster. (must not forget binary search works on the sorted lists)

Based on this, solve the below question:

Python code help- Main idea of binary search: Eliminating part of the

Question 1) Write a code that finds the elements of a sorted list that its index is equal to the item in that index. For example if the list is Ist- [-2,0,2,3,6,7,9] then code has to return 2 and 3 since Ist[21-2 and Hint1: do you think the above question has any relation to the binary search? Think about it. It is a sorted list, so it has the first condition. Do you want to search all the items on the list? What if the list has 1 million elements? Do you want to test 1 million items to see if Ist[il-i? (imagine the last item is the answer and you have to go through the entire list to get to the last item) Can you use this fact that if Istlil>j then no entry after i can satisfy the given criterion? This is because each element in the list is at least 1 greater than the previous element. For the same reason if Istlil

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 Databases Questions!