Given int number[8] = {15, 27, 16, 49, 62, 75, 83, 96}, and the target values of
ID: 3854791 • Letter: G
Question
Given int number[8] = {15, 27, 16, 49, 62, 75, 83, 96}, and the target values of 83, assuming that binary search is used, list the values of all the array elements which will be compared with 83, in the order in which they will be compared, before binary search concludes that 83 occurs in the array? How many elements compared with 83: ____ Value of second element compared with 83: ____ Value of second element compared with 83: ____ Value of third element compared with 83: ____ Values of other elements compared with 83, if any: ____ Assuming the declaration for a structure named FUN as given below, write C code to declare an array named my_fun of size 20, each of whose elements is of type FUN. typdef struct {char* x: char y: int z[200];} FUN: The required declaration: _____ A sorting algorithm is used to sort an int array with initial contents as shown below: After two passes of the sorting algorithm are executed, the array contents are in increasing order, as shown below: Name of the sorting algorithm used is: ____Explanation / Answer
Ans 48. In binary search, we compare the target value with the middle element, if the target value is greater than middle element the binary search is continued in the right part of middle element else in the left part and it continues till we do not get our target value.
Middle element is calculated as follows:
mid=low+(high-low)/2
So 1st element compared with 83 will be
mid=0+(7-0)/2=3 //i.e 49 will be compared
Now since 83>49 so consider the right part.
2nd element that will be compared with 83 is
mid=4+(7-4)/2=5 //i.e 75 will be compared
Now again 83>75, hence consider the right part
3rd element that will be compared is
mid=6+(7-6)/2=6 //i.e 83 will be compared with 83
And we get our element at index 6
So total 3 comparisons are made with 83.
Ans 49. FUN my_fun[20]; //to declare an array of struct FUN
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.