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 have really benefited after taking help from HwA with my visual basic assignment solutions. The team here is excellent and during my course of VB programming, I got tremendous assistance. Starting from the basic concepts of classes and then window controls to web programming, I got help with each and every aspect of visual basic programming from HwA.
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.com
From my undergraduate course till my master degree, I have been a regular client of HwA. The experts around here not only help you with the solutions of particular assignment but also at the same time helps you clear the concepts. It is like a marvellous bond and connection I share with this website.
My balance sheet never tallied before I approached HwA for help. I always used to mess things up. My ideas regarding the items to be entered where shady and I needed serious help. The balance sheet experts of HwA were of a great help and now I have gained much confidence in the subject.
Most of my classmates where very relaxed when it was time to deliver our Research Proposal. They don’t perceive it to be important to invest time in selecting the topic. The Research Proposal writer at HwA helped me to understand the importance of choosing simpler and doable topics rather than creating challenges later during the time of conducting the research. Needless to say that I was the only one in the class to get A+ in the Research Proposal and A in the actual Research Paper.
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.