The Wayback Machine - https://web.archive.org/web/20250116100259/https://www.geeksforgeeks.org/weight-heavy-ball/
Open In App

Puzzle | Weight of Heavy Ball

Last Updated : 18 Jan, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Puzzle: There are 2187 balls, out of which 1 is heavy. Find the minimum number of attempts the balls have to be weighed for finding out the heavy ball.

 
 
 

Solution: The minimum amount of measurements needed to be done will be equal to 7 times.
2187 = 3^7

  1. Step 1: Divide the 2187 balls into 3 equal groups of 729 each, let’s say C1, C2 and C3. Put C1 on one side of the weighing machine and C2 on the other. This can give rise to 3 conditions:
    • Condition 1: C1 equals C2, which means C3 has the heaviest ball
    • Condition 2: C1 < C2, which means C2 has the heaviest ball.
    • Condition 3: C1 > C2, which means C1 has the heaviest ball.

    Let’s suppose Condition 1 follows up, and C3 has the heaviest ball.

  2. Step 2: Now divide C3 again into 3 equal groups of 243 each, naming them again C1, C2 and C3. Put C1 on one side of the weighing machine and C2 on the other. This can give rise to 3 conditions:
    • Condition 1: C1 equals C2, which means C3 has the heaviest ball
    • Condition 2: C1 < C2, which means C2 has the heaviest ball.
    • Condition 3: C1 > C2, which means C1 has the heaviest ball.

    Let’s suppose Condition 2 follows up, and C2 has the heaviest ball.

  3. Step 3: Now divide C2 again into 3 equal groups of 81 each, naming them again C1, C2 and C3. Put C1 on one side of the weighing machine and C2 on the other. This can give rise to 3 conditions:
    • Condition 1: C1 equals C2, which means C3 has the heaviest ball
    • Condition 2: C1 < C2, which means C2 has the heaviest ball.
    • Condition 3: C1 > C2, which means C1 has the heaviest ball.

    Let’s suppose Condition 3 follows up, and C1 has the heaviest ball.

  4. Step 4: Now divide C1 again into 3 equal groups of 27 each, naming them again C1, C2 and C3. Put C1 on one side of the weighing machine and C2 on the other. This can give rise to 3 conditions:
    • Condition 1: C1 equals C2, which means C3 has the heaviest ball
    • Condition 2: C1 < C2, which means C2 has the heaviest ball.
    • Condition 3: C1 > C2, which means C1 has the heaviest ball.

    Let’s suppose Condition 3 follows up, and C1 has the heaviest ball.

  5. Step 5: Now divide C1 again into 3 equal groups of 9 each, naming them again C1, C2 and C3. Put C1 on one side of the weighing machine and C2 on the other. This can give rise to 3 conditions:
    • Condition 1: C1 equals C2, which means C3 has the heaviest ball
    • Condition 2: C1 < C2, which means C2 has the heaviest ball.
    • Condition 3: C1 > C2, which means C1 has the heaviest ball.

    Let’s suppose Condition 1 follows up, and C3 has the heaviest ball.

  6. Step 6: Now divide C3 again into 3 equal groups of 3 each, naming them again C1, C2 and C3. Put C1 on one side of the weighing machine and C2 on the other. This can give rise to 3 conditions:
    • Condition 1: C1 equals C2, which means C3 has the heaviest ball
    • Condition 2: C1 < C2, which means C2 has the heaviest ball.
    • Condition 3: C1 > C2, which means C1 has the heaviest ball.

    Let’s suppose Condition 1 follows up, and C3 has the heaviest ball.

  7. Step 7: Now finally divide C3 which has 3 balls into group of 1, naming them again B1, B2 and B3. Put B1 on one side of the weighing machine and B2 on the other. This can give rise to 3 conditions:
    • Condition 1: B1 equals B2, which means B3 has the heaviest ball
    • Condition 2: B1 < B2, which means B2 has the heaviest ball.
    • Condition 3: B1 > B2, which means B1 has the heaviest ball.

    Let’s suppose Condition 1 follows up, then B3 is the heaviest ball we were looking for.

    1. So, in all, it takes 7 steps to reach to the heaviest ball.

      Unlock your potential with our DSA Self-Paced course, designed to help you master Data Structures and Algorithms at your own pace. In 90 days, you’ll learn the core concepts of DSA, tackle real-world problems, and boost your problem-solving skills, all at a speed that fits your schedule. With comprehensive lessons and practical exercises, this course will set you up for success in technical interviews and beyond.

      And here's the challenge – join the Three 90 Challenge! Complete 90% of the course in 90 days, and you’ll earn a 90% refund. It's a great way to stay motivated, track your progress, and reward yourself for your dedication. Start the challenge today, and push your limits to achieve mastery in DSA!


      Next Article

Similar Reads

three90RightbarBannerImg