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

Slides:



Advertisements
Similar presentations
CSC 421: Algorithm Design & Analysis
Advertisements

Fake coin detection. Fake coins Suppose we have a number of coins, at most one is fake (i.e. either one is fake or none is fake). You have a pair of scales.
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Types of Algorithms.
HandoutLecture 6Binary Search Weighing with a Balance A large container is known to hold 24 oz of nails. The hardware store has a balance, but no weights.
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
1 Copyright M.R.K. Krishna Rao 2003 Ch 9 - Trees Definition: A tree is a connected undirected graph with no simple circuits. Since a tree cannot have a.
Deterministic Selection and Sorting Prepared by John Reif, Ph.D. Analysis of Algorithms.
Discrete Structure Li Tak Sing( 李德成 ) Lectures
CS 206 Introduction to Computer Science II 04 / 27 / 2009 Instructor: Michael Eckmann.
B-Trees. Motivation for B-Trees Index structures for large datasets cannot be stored in main memory Storing it on disk requires different approach to.
CSC 2300 Data Structures & Algorithms March 27, 2007 Chapter 7. Sorting.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
Other time considerations Source: Simon Garrett Modifications by Evan Korth.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
Department of Computer Eng. & IT Amirkabir University of Technology (Tehran Polytechnic) Data Structures Lecturer: Abbas Sarraf Search.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
CS 206 Introduction to Computer Science II 12 / 01 / 2008 Instructor: Michael Eckmann.
B + -Trees (Part 1) Lecture 20 COMP171 Fall 2006.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
3/10/03Tucker, Sec.3-51 Tucker, Applied Combinatorics, Sec. 3.5, Jo E-M “Big O” Notation We say that a function is if for some constant c, when n is large.
B-Trees. CSM B-Trees 2 Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so.
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
Marc Smith and Jim Ten Eyck
1 B-Trees Section AVL (Adelson-Velskii and Landis) Trees AVL tree is binary search tree with balance condition –To ensure depth of the tree is.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
A few leftover Decrease-and-conquer Algorithms
LOGO.  Trees:  In these slides: Introduction to trees Applications of trees Tree traversal 2.
B-Trees. CSM B-Trees 2 Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
MA/CSSE 473 Day 14 Permutations wrap-up Subset generation (Horner’s method)
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
B-Trees. Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so much data that it.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
Trees – Chapter 9 Slides courtesy of Dr. Michael P. Frank University of Florida Dept. of Computer & Information Science & Engineering.
B-Trees. CSM B-Trees 2 Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so.
Binary Search Tree vs. Balanced Search Tree. Why care about advanced implementations? Same entries, different insertion sequence: 10,20,30,40,50,60,70,
1 Tree Indexing (1) Linear index is poor for insertion/deletion. Tree index can efficiently support all desired operations: –Insert/delete –Multiple search.
17.1 CompSci 102 Today’s topics Instant InsanityInstant Insanity TreesTrees –Properties –Applications Reading: Sections Reading: Sections
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
MA/CSSE 473 Day 20 Questions before exam More decrease and Conquer.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
CS 61B Data Structures and Programming Methodology Aug 7, 2008 David Sun.
Asymptotic Behavior Algorithm : Design & Analysis [2]
B-TREE. Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so much data that it won’t.
Copyright © Cengage Learning. All rights reserved. CHAPTER 4 ELEMENTARY NUMBER THEORY AND METHODS OF PROOF ELEMENTARY NUMBER THEORY AND METHODS OF PROOF.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
Logic Development Problems. Puzzle #1 You have a measurement scale where on both sides you can put some balls for weighing. You have a set of eight balls,
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
1 Section 5.1 Analyzing Algorithms Let P be a problem and A an algorithm to solve P. The running time of A can be analyzed by counting the number of certain.
Decision Trees DEFINITION: DECISION TREE A decision tree is a tree in which the internal nodes represent actions, the arcs represent outcomes of an action,
Lecture Trees Professor Sin-Min Lee.
Some more Decrease-and-conquer Algorithms
Applied Discrete Mathematics Week 15: Trees
B-Trees B-Trees.
20 Questions and 12 Coins How to select 'good questions'?
Direct Proof and Counterexample V: Floor and Ceiling
Wednesday, April 18, 2018 Announcements… For Today…
Trees.
Lecture 13: Tree Traversals Algorithms on Trees.
CSIT 402 Data Structures II With thanks to TK Prasad
And the Final Subject is…
CS203 Lecture 14.
Chapter 11 Trees © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

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

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

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

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

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

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

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

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

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

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