Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Answer problem 2 please Problem 2: You are given an array A of length n. Each va

ID: 3756527 • Letter: A

Question

Answer problem 2 please

Problem 2: You are given an array A of length n. Each value is 1. However, you do not know what the value of n i of the array by calling Ali]. If i n, this will return 1, and if i n, this will return a message saying that the location does not exist (you can think of this as an error message, but it will not crash your program). Describe an O(log n) algorithm to determine the value of n. (Hint: think binary search, but in reverse. is. You are allowed to acc ess an element

Explanation / Answer

Hey,

Below si the answer to your question

The main thing to get this program would be based on reverse of binary search which means we will iterate like i=i*2 startng from i=1.

The above algorithm will work in O(logn)

Kindly revert for any queries

Thanks.