Invitation to Computer Science 8th Edition

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

Chapter 2 - Exercises - Page 87: 14

Answer

$\bullet$ Get value for $n,$ size of the list $\bullet$ Get values for $A_{1}, A_{2}, \ldots, A_{n}$ of the list $\bullet$ Set value of $M e d i a n$ to $A_{1}$ $\bullet$ Set the value of Location to 1 and of $i$ to 1 $\bullet$ Set value of Found to $N O$ $\bullet$ If $n$ is even then $\bullet \quad$ Set value of Smaller to $n / 2-1$ $\bullet$ else $\bullet \quad$ Set Smaller to $n / 2$ $\bullet$ While $(i \leq n)$ and $(f o u n d=N O)$ do $\bullet$ Set value of $j$ to 1 and of Count to 0 $\bullet$ While $(j \leq n)$ do $\bullet \quad$ If $A_{i} \leq A_{j}$ $\bullet \quad \quad$ Add 1 to the value of Count $\bullet \quad$ Add 1 to $j$ $\bullet$ End of loop $\bullet$ If Count $=$Smaller $\bullet \quad$ Set value of Found to $Y E S$ $\bullet \quad$ Set value of Found to $A_{i}$ $\bullet \quad$ Set Location to $i$ $\bullet$ Add 1 to $i$ $\bullet$ End of loop $\bullet$ Print the values of Median and Location $\bullet$ Stop

Work Step by Step

--
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.