algorithm - given 5 numbers, what is the minimum number of comparisons needed to find the median? -


In general, how do you set the minimum number of comparisons?

To quote Donald Knuth (via Wikipedia, I currently have my copy of T.O.P.P. Is not), the lower bound for the number of comparisons is six:

(scroll down to the section titled "Lower Bounce").

Your goal is to find at least values, effectively, where half the size of the K list, round-up, (therefore, K = 3; n = 5) and then take the maximum of them . By placing on that page in the formula, you get:

  (5 - 3) + 1 + 1 + 2 = 6  

In this case ,.

If you are in doubt that the task of finding mediocrity is as difficult to find the lowest values ​​of Kashmir, then after the 5.3.3 chapters you will see Knuth's TAoCP, section 3, excercise # 2 Can mention.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -