Download presentation

Presentation is loading. Please wait.

Published byJaidyn Bryant Modified over 3 years ago

1
Today’s topics Decision Trees Reading: Sections 9.1 CompSci 102

2
**Tree and Forest Examples**

Leaves in green, internal nodes in brown. A Tree: A Forest: CompSci 102

3
**Coin-Weighing Problem**

Imagine you have 8 coins, one of 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? ? CompSci 102

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 of weighings thus yields a decision tree with branching factor 3. The balance then “decides” whether to tip left, tip right, or stay balanced. CompSci 102

5
**Theorem: There are at most mh leaves in an m-ary tree of height h.**

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? CompSci 102

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. CompSci 102

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 − 2n/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. CompSci 102

8
**Coin Balancing Decision Tree**

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

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 CompSci 102

10
**1 of 4 coins may be counterfeit**

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? CompSci 102

Similar presentations

OK

Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c)2001-2004, Michael P. Frank and Modified By Mingwu Chen Trees.

Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c)2001-2004, Michael P. Frank and Modified By Mingwu Chen Trees.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

A ppt on android Ppt on power systems Full ppt on electron beam machining set Ppt on new zealand culture and family tradition Save ppt on ipad mini Ppt on viruses and bacteria articles Ppt on life study of mathematicians Ppt on matter in our surroundings Ppt on job rotation policy Ppt on service oriented architecture for dummies