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

Java Quiz Please use this table list for ALL questions. Q1: If a binary search w

ID: 3717024 • Letter: J

Question

Java Quiz

Please use this table list for ALL questions.

Q1: If a binary search was used on the list in the accompanying figure, which element would the search element be compared to first?

A. 4

B. 35

C. 44

D. 98

Q2: If the list in the accompanying figure was to be searched using a sequential search on an unordered list, how many key comparisons would be made to find the number 44?

A. 1

B. 3

C. 5

D. 6

Q3: If the list in the accompanying figure were to be searched using a sequential search on an ordered list, how many key comparisons would be made to find the number 44?

A. 1

B. 3

C. 5

D. 6

Q4: If the list in the accompanying figure was to be searched for the number 44 using a binary search, how many key comparisons would have to be made?

A. 1

B. 3

C. 5

D. 7

0 1 2 3 4 5 6 7 List: 4 18 29 35 44 59 65 98

Explanation / Answer

Q1:
Answer: B. 35

Q2.
Answer: C. 5

Q3.
Answer: C. 5

Q4.
Answer: B. 3

Explanation:

Q1:
Answer: B. 35

Explanation:
In binary search the middle element is compared first i.e. mid=(lower bound + upper)/2

lower bound of list (L)= 0,
upper bound of list (U)= 7

mid=(0+7)/2=3
list[mid]=list[3]=35

Q2.
Answer: C. 5
Explanation:
In linear search element is compared with each element of list starting from first.
So in our case element(44) to to searched in list will be compared with elements 4,18,29,35 stored in 0,1,2,3 & finally found at location 4.
So total camparision =5

Q3.
Answer: C. 5
Explanation:
Ordered or unordered list does not make any difference in case of linear search.
So total camparision =5

Q4.
Answer: B. 3
l=0, u=7
mid=(L+U)/2

step1:
mid=(0+7)/2=3
list[3]=35 which is not equal to 44

so, find next middle element in sublist
44>35 so element will be found below 35 in list i.e.
L=mid+1=3+1=4
U=7 (unchanged)

step2:
mid=(4+7)/2=5
list[3]=59 which is not equal to 44
so, find next middle element in sublist
44<59 so element will be found above 59 i.e.
L=4
U=mid-1=5-1=4 (unchanged)

step3:
mid=(4+4)/2=4
list[mid]=list[4]=44

Element is found
So No. of comparison=3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote