1 / 10

Coin Weighing Decision Tree Problem Solving

Explore decision trees in solving the coin-weighing problem to find a counterfeit coin using a balance scale. Learn the minimum number of weighings needed and apply a strategic search approach.

tstrickland
Download Presentation

Coin Weighing Decision Tree Problem Solving

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Today’s topics • Decision Trees • Reading: Sections 9.1

  2. A Tree: A Forest: Tree and Forest Examples Leaves in green, internal nodes in brown.

  3. Coin-Weighing Problem • Imagine you have 8 coins, oneof which is a lighter counterfeit, and a free-beam balance. • No scale of weight markings is required for this problem! • How many weighings are needed to guarantee that the counterfeit coin will be found? ?

  4. As a Decision-Tree Problem • In each situation, we pick two disjoint and equal-size subsets of coins to put on the scale. A given sequence ofweighings thus yieldsa decision tree withbranching factor 3. The balance then“decides” whether to tip left, tip right, or stay balanced.

  5. Tree Height Theorem • The decision tree must have at least 8 leaf nodes, since there are 8 possible outcomes. • In terms of which coin is the counterfeit one. • Theorem: There are at most mh leaves in an m-ary tree of height h. • Corollary: An m-ary tree with  leaves has height h≥logm . If m is full and balanced then h=logm. • What is this decision tree’s height? • How many weighings will be necessary?

  6. General Solution Strategy • The problem is an example of searching for 1 unique particular item, from among a list of n otherwise identical items. • Somewhat analogous to the adage of “searching for a needle in haystack.” • Armed with our balance, we can attack the problem using a divide-and-conquer strategy, like what’s done in binary search. • We want to narrow down the set of possible locations where the desired item (coin) could be found down from n to just 1, in a logarithmic fashion. • Each weighing has 3 possible outcomes. • Thus, we should use it to partition the search space into 3 pieces that are as close to equal-sized as possible. • This strategy will lead to the minimum possible worst-case number of weighings required.

  7. General Balance Strategy • On each step, put n/3 of the n coins to be searched on each side of the scale. • If the scale tips to the left, then: • The lightweight fake is in the right set of n/3≈ n/3 coins. • If the scale tips to the right, then: • The lightweight fake is in the left set of n/3≈ n/3 coins. • If the scale stays balanced, then: • The fake is in the remaining set of n− 2n/3 ≈ n/3 coins that were not weighed! • Except if n mod 3 = 1 then we can do a little better by weighing n/3 of the coins on each side. You can prove that this strategy always leads to a balanced 3-ary tree.

  8. Coin Balancing Decision Tree • Here’s what the tree looks like in our case: 123 vs 456 left: 123 balanced:78 right: 456 4 vs. 5 1 vs. 2 7 vs. 8 L:1 L:4 L:7 R:2 B:3 R:5 B:6 R:8

  9. Problem 1 • How many weighings of a balance scale are needed to find a counterfeit coin among 12 coins if the counterfeit coin is lighter than the others? • Describe your algorithm to find this coin

  10. Problem 2 • 1 of 4 coins may be counterfeit • Counterfeit coin should be lighter or heavier than others • How many weighings are needed to • Determine whether there is a counterfeit coin • If so, is it lighter or heavier than others • What is your algorithm?

More Related