Computers and Technology

Let A[1..n] be a sorted array of n numbers. Here is a code for finding the index of a number x in A. The code uses two indexes, left and right, such that w is between A[left) and A[right]. That is, A[left] < x < A[right]. We start when left = 1 and right = n.

Find(A, x, left, right) {

if (right == left) Return right
Else {mid = [ (right + left)]}
# Note: This is not actually the median value
if x == A[mid) return mid.
If x < A[mid call Find(A, x, left, mid – 1)
Else call Find(A, x, mid, right)

Assume that this code is invoked by calling Find(A, X, 1, n), but x is not one of the keys stored in the array. Write a recursive function that describes the running time in the worst case, and in the best case (the answers are slightly different). Express your answer as logan, where a is a constant you need to specify (Hint: It is not 2).

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:00, lgary9462
Perform the following tasks: a. create a class named testclass that holds a single private integer field and a public constructor. the only statement in the constructor is one that displays the message “constructing”. write a main()function that instantiates one object of the testclass. save the file as testclass. cpp in the chapter 08 folder. run the program and observe the results. b. write another main()function that instantiates an array of 10 testclass objects. save the file as test class array. c . run this program and observe the results.
Answers: 1
image
Computers and Technology, 23.06.2019 14:00, ava5015
What is html ? give a small description about html
Answers: 2
image
Computers and Technology, 24.06.2019 00:20, talyku843
Describe a data structures that supports the stack push and pop operations and a third operation findmin, which returns the smallest element in the data structure, all in o(1) worst-case time.
Answers: 2
image
Computers and Technology, 24.06.2019 07:00, AnaiyaKirksey8
You are most likely to automatically encode information about
Answers: 1
Do you know the correct answer?
Let A[1..n] be a sorted array of n numbers. Here is a code for finding the index of a number x in A....

Questions in other subjects:

Konu
Mathematics, 04.03.2021 04:40
Konu
Mathematics, 04.03.2021 04:40
Konu
Mathematics, 04.03.2021 04:40
Konu
Mathematics, 04.03.2021 04:40
Konu
Mathematics, 04.03.2021 04:40