Invitation to Computer Science 8th Edition

Published by Cengage Learning
ISBN 10: 1337561916
ISBN 13: 978-1-33756-191-4

Chapter 3 - Exercises - Page 140: 5a


\begin{equation} N_{m}=\frac{n-1}{2}+1=\frac{n-1+2}{2}=\frac{n+1}{2} \end{equation}

Work Step by Step

We suppose we have an odd number of items, like $15 .$ Our task is to find the position for the middle item. Here's how we can find the position for a 15 -element list: $15=14+1=2 \cdot 7+1=7+1+7$ Here we can see that we have one single element in the middle because it is an odd number and odd numbers can be written in the form $2 \cdot m+1 .$ It is obvious that the middle element is the $8^{t h}$ element which has 7 elements before and 7 after it. We can do the same to a couple of other odd numbers: $\quad \quad \bullet 23=2 \cdot 11+1,$ with $12^{t h}$ as the middle element $\quad \quad \bullet 75=2 \cdot 37+1,$ with $38^{t h}$ as the middle element The number of comparisons required to find the middle item for each of the above lists is equal to the middle's position: $8,12,38 .$ We can write an expression to find this middle item $N_{m}$ in a $n$ -element list, where $n$ is odd: $N_{m}=\frac{n-1}{2}+1=\frac{n-1+2}{2}=\frac{n+1}{2}$
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.