17.1 CompSci 102 Today’s topics Instant InsanityInstant Insanity TreesTrees –Properties –Applications Reading: Sections 9.1-9.2Reading: Sections 9.1-9.2.

Slides:



Advertisements
Similar presentations
Chapter 11 Trees Graphs III (Trees, MSTs) Reading: Epp Chp 11.5, 11.6.
Advertisements

Trees Chapter 11.
Chapter 9 Graphs.
2012: J Paul GibsonT&MSP: Mathematical FoundationsMAT7003/L2-GraphsAndTrees.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson,
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Today’s topics Decision Trees Reading: Sections 9.1 CompSci 102.
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
Introduction to Trees Chapter 6 Objectives
1 Chapter 10 Trees. Tree Definition 1. A tree is a connected undirected graph with no simple circuits. Theorem 1. An undirected graph is a tree if and.
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.
17.1 CompSci 102 Today’s topics Instant InsanityInstant Insanity Random WalksRandom Walks.
Discrete Structure Li Tak Sing( 李德成 ) Lectures
1 Section 9.1 Introduction to Trees. 2 Tree terminology Tree: a connected, undirected graph that contains no simple circuits –must be a simple graph:
Discrete Mathematics – CIS166
Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.
The Instant Insanity Game
Section 3.1 Properties of Trees Sarah Graham. Tree Talk: Vocabulary oTree: a tree is a special type of graph that contains designated vertex called a.
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
© 2006 Pearson Addison-Wesley. All rights reserved11 A-1 Chapter 11 Trees.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Trees.
03/01/2005Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 3.1 Properties of Trees Prepared by Joshua Schoenly and Kathleen McNamara.
Marc Smith and Jim Ten Eyck
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
Binary Trees Chapter 6.
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Let G be a pseudograph with vertex set V, edge set E, and incidence mapping f. Let n be a positive integer. A path of length n between vertex v and vertex.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
COSC2007 Data Structures II
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
LOGO.  Trees:  In these slides: Introduction to trees Applications of trees Tree traversal 2.
Section 10.1 Introduction to Trees These class notes are based on material from our textbook, Discrete Mathematics and Its Applications, 6 th ed., by Kenneth.
May 1, 2002Applied Discrete Mathematics Week 13: Graphs and Trees 1News CSEMS Scholarships for CS and Math students (US citizens only) $3,125 per year.
Foundations of Discrete Mathematics
Tree A connected graph that contains no simple circuits is called a tree. Because a tree cannot have a simple circuit, a tree cannot contain multiple.
Binary Trees. Binary Tree Finite (possibly empty) collection of elements A nonempty binary tree has a root element The remaining elements (if any) are.
Copyright © Cengage Learning. All rights reserved. CHAPTER 10 GRAPHS AND TREES.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Module #19: Graph Theory: part II Rosen 5 th ed., chs. 8-9.
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Trees – Chapter 9 Slides courtesy of Dr. Michael P. Frank University of Florida Dept. of Computer & Information Science & Engineering.
5.5.3 Rooted tree and binary tree  Definition 25: A directed graph is a directed tree if the graph is a tree in the underlying undirected graph.  Definition.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
5.5.2 M inimum spanning trees  Definition 24: A minimum spanning tree in a connected weighted graph is a spanning tree that has the smallest possible.
Discrete Mathematics Chapter 5 Trees.
CS 103 Discrete Structures Lecture 23 Trees (1). Second Midterm Exam 1 st Lecture in December (same time as the lecture) 75 minute duration Will cover.
1 Slides by Sylvia Sorkin, Community College of Baltimore County - Essex Campus Trees.
Chapter 10: Trees A tree is a connected simple undirected graph with no simple circuits. Properties: There is a unique simple path between any 2 of its.
CHAPTER 11 TREES INTRODUCTION TO TREES ► A tree is a connected undirected graph with no simple circuit. ► An undirected graph is a tree if and only.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
Discrete Structures – CNS 2300 Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 9 Trees.
Discrete Mathematics Chapter 10 Trees.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 11. Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum Spanning.
Section10.1: Introduction to Trees
Applied Discrete Mathematics Week 15: Trees
Discrete Mathematicsq
Trees Chapter 11.
12. Graphs and Trees 2 Summary
Introduction to Trees Section 11.1.
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Trees.
Trees.
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
And the Final Subject is…
Trees Chapter 11.
Presentation transcript:

17.1 CompSci 102 Today’s topics Instant InsanityInstant Insanity TreesTrees –Properties –Applications Reading: Sections Reading: Sections

17.2 CompSci 102 Instant Insanity Given four cubes, how can we stack the cubes, so that whether the cubes are viewed from the front, back, left or right, one sees all four colorsGiven four cubes, how can we stack the cubes, so that whether the cubes are viewed from the front, back, left or right, one sees all four colors

17.3 CompSci 102 Cubes 1 & 2

17.4 CompSci 102 Cubes 3 & 4

17.5 CompSci 102 Creating graph formulation Create multigraphCreate multigraph –Four vertices represent four colors of faces –Connect vertices with edges when they are opposite from each other –Label cubes SolvingSolving –Find subgraphs with certain properties –What properties?

17.6 CompSci 102 Summary Graph-theoretic Formulation of Instant Insanity: Find two edge-disjoint labeled factors in the graph of the Instant Insanity puzzle, one for left-right sides and one for front-back sides Use the clockwise traversal procedure to determine the left-right and front-back arrangements of each cube.

17.7 CompSci 102 Try it out: Find all Instant Insanity solution to the game with the multigraph:

17.8 CompSci 102 Answer: and

17.9 CompSci 102 §9.1: Introduction to Trees A tree is a connected undirected graph that contains no circuits.A tree is a connected undirected graph that contains no circuits. –Theorem: There is a unique simple path between any two of its nodes. A (not-necessarily-connected) undirected graph without simple circuits is called a forest.A (not-necessarily-connected) undirected graph without simple circuits is called a forest. –You can think of it as a set of trees having disjoint sets of nodes. A leaf node in a tree or forest is any pendant or isolated vertex. An internal node is any non-leaf vertex (thus it has degree ≥ ___ ).A leaf node in a tree or forest is any pendant or isolated vertex. An internal node is any non-leaf vertex (thus it has degree ≥ ___ ).

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

17.11 CompSci 102 Rooted Trees A rooted tree is a tree in which one node has been designated the root.A rooted tree is a tree in which one node has been designated the root. –Every edge is (implicitly or explicitly) directed away from the root. You should know the following terms about rooted trees:You should know the following terms about rooted trees: –Parent, child, siblings, ancestors, descendents, leaf, internal node, subtree.

17.12 CompSci 102 Rooted Tree Examples Note that a given unrooted tree with n nodes yields n different rooted trees.Note that a given unrooted tree with n nodes yields n different rooted trees. root Same tree except for choice of root

17.13 CompSci 102 Rooted-Tree Terminology Exercise Find the parent, children, siblings, ancestors, & descendants of node f.Find the parent, children, siblings, ancestors, & descendants of node f. a b c d e f g h i jk l m n o p q r root

17.14 CompSci 102 n-ary trees A rooted tree is called n-ary if every vertex has no more than n children.A rooted tree is called n-ary if every vertex has no more than n children. –It is called full if every internal (non-leaf) vertex has exactly n children. A 2-ary tree is called a binary tree.A 2-ary tree is called a binary tree. –These are handy for describing sequences of yes-no decisions. Example: Comparisons in binary search algorithm.Example: Comparisons in binary search algorithm.

17.15 CompSci 102 Which Tree is Binary? Theorem: A given rooted tree is a binary tree iff every node other than the root has degree ≤ ___, and the root has degree ≤ ___.Theorem: A given rooted tree is a binary tree iff every node other than the root has degree ≤ ___, and the root has degree ≤ ___.

17.16 CompSci 102 Ordered Rooted Tree This is just a rooted tree in which the children of each internal node are ordered.This is just a rooted tree in which the children of each internal node are ordered. In ordered binary trees, we can define:In ordered binary trees, we can define: –left child, right child –left subtree, right subtree For n-ary trees with n>2, can use terms like “leftmost”, “rightmost,” etc.For n-ary trees with n>2, can use terms like “leftmost”, “rightmost,” etc.

17.17 CompSci 102 Trees as Models Can use trees to model the following:Can use trees to model the following: –Saturated hydrocarbons –Organizational structures –Computer file systems In each case, would you use a rooted or a non-rooted tree?In each case, would you use a rooted or a non-rooted tree?

17.18 CompSci 102 Some Tree Theorems Any tree with n nodes has e = n−1 edges.Any tree with n nodes has e = n−1 edges. –Proof: Consider removing leaves. A full m-ary tree with i internal nodes has n=mi+1 nodes, and =(m−1)i+1 leaves.A full m-ary tree with i internal nodes has n=mi+1 nodes, and =(m−1)i+1 leaves. –Proof: There are mi children of internal nodes, plus the root. And, = n−i = (m−1)i+1. □ Thus, when m is known and the tree is full, we can compute all four of the values e, i, n, and, given any one of them.Thus, when m is known and the tree is full, we can compute all four of the values e, i, n, and, given any one of them.

17.19 CompSci 102 Some More Tree Theorems Definition: The level of a node is the length of the simple path from the root to the node.Definition: The level of a node is the length of the simple path from the root to the node. –The height of a tree is maximum node level. –A rooted m-ary tree with height h is called balanced if all leaves are at levels h or h−1. Theorem: There are at most m h leaves in an m-ary tree of height h.Theorem: There are at most m h leaves in an m-ary tree of height h. –Corollary: An m-ary tree with leaves has height h≥  log m . If m is full and balanced then h=  log m .

17.20 CompSci 102 Binary Search Trees A representation for sorted sets of items.A representation for sorted sets of items. –Supports the following operations in Θ(log n) average-case time: Searching for an existing item.Searching for an existing item. Inserting a new item, if not already present.Inserting a new item, if not already present. –Supports printing out all items in Θ(n) time. Note that inserting into a plain sequence a i would instead take Θ(n) worst-case time.Note that inserting into a plain sequence a i would instead take Θ(n) worst-case time.

17.21 CompSci 102 Binary Search Tree Format Items are stored at individual tree nodes.Items are stored at individual tree nodes. We arrange for the tree to always obey this invariant:We arrange for the tree to always obey this invariant: –For every item x, Every node in x’s left subtree is less than x.Every node in x’s left subtree is less than x. Every node in x’s right subtree is greater than x.Every node in x’s right subtree is greater than x Example:

17.22 CompSci 102 Coin-Weighing Problem Imagine you have 8 coins, one of which is a lighter counterfeit, and a free-beam balance.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?How many weighings are needed to guarantee that the counterfeit coin will be found? ?

17.23 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.In each situation, we pick two disjoint and equal- size subsets of coins to put on the scale. The balance then “decides” whether to tip left, tip right, or stay balanced. A given sequence of weighings thus yields a decision tree with branching factor 3.

17.24 CompSci 102 Applying the Tree Height Theorem The decision tree must have at least 8 leaf nodes, since there are 8 possible outcomes.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. Recall the tree-height theorem, h≥  log m .Recall the tree-height theorem, h≥  log m . –Thus the decision tree must have height h ≥  log 3 8  =  1.893…  = 2. Let’s see if we solve the problem with only 2 weighings…Let’s see if we solve the problem with only 2 weighings…

17.25 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.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.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.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.This strategy will lead to the minimum possible worst-case number of weighings required.

17.26 CompSci 102 General Balance Strategy On each step, put  n/3  of the n coins to be searched on each side of the scale.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.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.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!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.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.

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