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
1. Being a computer science engineer is my dream and it wouldn’t have possible for me to minutely understand the basics of C++ programming without the help of TheReliableTutor.com and the engineering assignment tutors. I grasped C programming on my own, but for C++ and Java, I am definitely grateful to TheReliableTutor
My main concern was the relevant local Wellington research and reference work that was required for the final Statistics Assignment for my post graduate program at the Victoria University of Wellington. My professor was very particular about his requirement of relevant local data and samples from Wellington. With the stats assignment expert at TheReliableTutor I did not have to worry about that since the expert provided the most excellent and relevant local data and references helping me to top the class.
We were practically bombarded with assignments pertaining to magnetism and electro-magnetism, when I became desperate and started searching help online. Luckily I landed on this page and since then I always approach them for help. They are professional in their approach and get the job done, no matter what.
Thank you so much guys…!!! The final product was very precise, thorough and was far beyond what I expected for. It’s simply awesome and best part is that I got top grades in the assignment. I am very grateful to TheReliableTutor.com.
I never expected that I could make so many grammatical errors in my college application essay. Thankfully, I took advice from HwA before submitting the same for my college admission. I got through smooth and since then take their service.
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.