Get in touch with us
Send us an e-mail
Question
Consider the following Binary Search Algorithm
upper = length - 1;
lower = 1;
while (upper >= lower)
{ mid_pt = (upper + lower) / 2;
if (data[mid_pt] < target) ; comparison A
{ lower = mid_pt + 1; }
else if (data[mid_pt] == target) ; comparison B
{ return mid_pt; }
else { upper = mid_pt – 1;}
}
//target not found
Give the values for lower, upper and mid-pt for each iteration of the while loop and state how many times will the two comparisons A and B be executed using this algorithm to find the value 77 in the following array? You may not need to complete all the rows.
|
[0] |
[1] |
[2] |
[3] |
[4] |
[5] |
[6] |
[7] |
[8] |
[9] |
[10] |
[11] |
[12] |
|
14 |
27 |
29 |
38 |
42 |
55 |
57 |
61 |
64 |
69 |
77 |
79 |
84 |
|
|
|
|
||||||||||
|
Lower |
Upper |
Mid-pt |
|
- |
- |
- |
|
- |
- |
- |
|
- |
- |
- |
|
- |
- |
- |
|
- |
- |
- |
Comparison A executed ------ times & Comparison B executed ------- times.
Download Full Solution
I was apprehensive to begin with. I had bitter experiences with online service providers for assignments and homework essays during my masters. But the online dissertation help expert assigned to me by TheReliableTutor has been extremely responsible and professional in his approach to my subject of choice and the research work has been totally as I had wanted. We are on a good path I feel.
The corporate strategy case study which I was handed over by my professor was a bit difficult and I was not certain that I would be able to meet the standards. So I looked online for help and eventually landed here in HwA. I was thrilled to see that the experts here are all well aware of my syllabus and they did a fantastic job in providing an excellent solution.
Thank you guys for your great assistance. Loved the way you dealt with the assignment. Very satisfied with the work and will use your service again.
Was partying late night and forgot about my biotechnology assignment which was about to submit in 5 hours. Then approached several service providers but they refused to take up the assignment. Finally TheReliableTutor.com saved me. Submitted the assignment on time..!!!
Biochemistry was difficult to me right from the day I started to attend classes. I had problems in understanding the concepts. Then I found TheReliableTutor.com and my perspective towards the subject has completely changed. Learning became more interesting than before. Thanks to thereliabletutor.com
Comments
this is a very good website
I have 50 questions for the same test your page is showing only 28
hi can you please help or guide me to answer my assignments. thanks
hi can anyone help or guide me to my assignments. thanks
This solution is perfect ...thanks
Hello Allison,I love the 2nd image that you did! I also, had never heard of SumoPaint, is something that I will have to exolpre a bit! I understand completely the 52 (or so) youtube videos that you probably watched. Sometimes they have what you want, sometimes they don't! However, it is always satisfying when you are able to produce something that you have taught yourself. Great job!Debra 0 likes
Perfect bank of solution.
great !
thanks for the quick response. the solution looks good. :)
thnx for the answer. it was perfect. just the way i wanted it.
works fine.