5 balls - which one has the middle weight? I'm looking for some help.
It's one riddle, and i'm not sure, if my solution is the best one
We have 5 balls. Every ball has different weight.
You have scales, which tells you, which ball is heavier.
Find the least weighing, that you need to find the ball, which has the middle weight.
I know solution for 6 weighing, but I'm not sure, if it's best solution.
Thank you and good evening
Leechy
 A: It's not possible to do this in under $6$ weighings.
Consider the situation after $4$ weighings. The undirected graph that contains a node for each ball and an edge for each pair of balls compared can be of one of three types:


*

*A tree. In this case, it's possible to colour the balls black and white such that only balls of different colours have been compared, and the results of the comparisons may be that all black balls were heavier than all white balls. There are at least $3$ balls of one of the colours, and any of these could be the median ball.

*A graph with a cycle that misses one of the balls. Then the missed ball and at least two of the other balls could be the median ball.

*A graph with two components (one with two balls and one with three). Then all five balls could be the median.


In all three cases, more than two balls could be the median, so a single fifth weighing cannot reliably decide among them.
(Note that in the tree case, the fact that you can use the results of previous weighings in deciding which balls to weigh doesn't allow you to preclude such a colouring.)
Here's Java code that confirms the result.
