Computer Science, asked by starcinj1313, 11 months ago

Given an array arr = {12, 34, 47, 62, 85, 92, 95, 99,105} and key = 34; what are the mid values (corresponding array elements) generated in the first and second iterations?

Answers

Answered by mariospartan
0

85 and 34 acts as the mid value in the first and second iteration respectively.

Explanation:

I am not writing the program since it is not necessary. Hence I am giving steps to find the mid value. This is the partial logic to find element in an array.

Total elements in the array: 9

So the array index starts from 0 and ends till 8.

Iteration 1:

middle value = (0+8) / 3 =4 (where 0 (low) and 8(high) are the index)

So, mid position =  4

arr[4] = 85, Hence 85 will be the mid value. This is compared with the key given.

 85 > 34 (key).

Hence, No change in low  value. But high is recalculated as  mid-1 = 4-1 = 3

Iteration 2:

Once again (0+3)/2 = 1.5 = 1(Truncating the float value)

 arr[1] = 34

Hence 34 would be the mid value.

To Know more:

https://brainly.in/question/12845273

Write an algorithm and program that creates a Binary Search Tree with a set of given inputs. Then, it should prompt for a key value and print a message about the presence of key value in the Binary Search Tree.

https://brainly.in/question/7083046

Write a program in c++ to read an array of sorted integers search for value using binary search method if the element is found print its location else print element not found

Similar questions