Question
Computer algorithm question: (a), pretend a,b,c are in an array (in slots E[0], E[1], E[2]), and have your algorithm return the INDEX (namely 0, 1,
Computer algorithm question:
(a), pretend a,b,c are in an array (in slots E[0], E[1], E[2]), and have your algorithm return the INDEX (namely 0, 1, or 2) of the median.
Your algorithm should take care not to destroy the array.
(c) How many comparisons are necessary in the worst case to find the median of three numbers? Justify your answer. Optimality argument is required.
(e): The parameters of the problem have simplified things so that there are no ties, and your answers to the first four parts can assume that this is the case. Assume for a moment that ties are allowed. If your (unwritten, and you do NOT have to write a new one) algorithm were to discover that the first two entries you compared were equal to each other, what can you say about the median of the entries in this 3-element array?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started