An algorithm for finding the minimum number of weights needed to search for a defective ball from a set of n balls

Well, here is a puzzle that I come across many times - Given a set of 12 balls, one of which is faulty (it weighs either less or more). You can weigh 3 times to find the defective, and also report that it weighs less or more.

There is a solution to this problem, but I want to know if we can algorithmically determine if a set of "n" balls is given, what is the minimum number of times when you need to use the beam balance to determine which one is faulty and how (lighter or heavier) .

+5
source share
3 answers

( n (3 ^ k-3)/2, n, . )

, , ,

n (3 ^ k-3)/2 , k.

...


Jack Wert n.

n, ( ):

, n (3 ^ k-3)/2. , .

,

n = 3t (.. n 3), m > n , m (3 ^ k-3)/2. k. 1, 3, 3 ^ 2,..., 3 ^ (k-2), Z, 3 ^ (k-2) Z < 3 ^ (k-1) .

. A (, , ), Z.

n = 3t + 1, 3t ( ). 3t, , , .

n = 3t + 2, 3t + 3, . , , , , ( 3).

+4

!:)

: n , 3 A, B C n/3 .

A B. , C. .

, - , n (, ).

+1

All Articles