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.

Slides:



Advertisements
Similar presentations
Trees Chapter 11.
Advertisements

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.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
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.
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 Transparency No. 8-1 Chapter 8 Trees.
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.
Marc Smith and Jim Ten Eyck
Discrete Mathematics Lecture 9 Alexander Bukharovich New York University.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
CS 2210(22C:19) Discrete Math Graphs
Trees Chapter 15 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS Data Structures Chapter 15 Trees Mehmet H Gunes
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
LOGO.  Trees:  In these slides: Introduction to trees Applications of trees Tree traversal 2.
COSC 2007 Data Structures II Chapter 14 Graphs III.
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.
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
Discrete Structures Lecture 12: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Trees – Chapter 9 Slides courtesy of Dr. Michael P. Frank University of Florida Dept. of Computer & Information Science & Engineering.
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.
Discrete Structures Trees (Ch. 11)
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.
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Discrete Mathematics Chapter 5 Trees.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
1 Spanning Trees Longin Jan Latecki Temple University based on slides by David Matuszek, UPenn, Rose Hoberman, CMU, Bing Liu, U. of Illinois, Boting Yang,
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Trees Dr. Yasir Ali. A graph is called a tree if, and only if, it is circuit-free and connected. A graph is called a forest if, and only if, it is circuit-free.
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.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
Discrete Mathematics Chapter 10 Trees. Outline 10.1 Introduction to Trees 10.2 Applications of Trees 10.3 Tree Traversal 10.4 Spanning Trees 10.5 Minimal.
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
© 2006 Pearson Addison-Wesley. All rights reserved14 B-1 Chapter 14 (continued) Graphs.
Discrete Mathematics Trees.
Applied Discrete Mathematics Week 15: Trees
Trees Chapter 15.
Chapter 5 : Trees.
Discrete Mathematicsq
Trees Chapter 11.
12. Graphs and Trees 2 Summary
Introduction to Trees Section 11.1.
Spanning Trees Longin Jan Latecki Temple University based on slides by
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Trees.
Trees.
And the Final Subject is…
Spanning Trees Longin Jan Latecki Temple University based on slides by
Binary Trees.
Trees Chapter 11.
Presentation transcript:

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

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 2 Topics Terminology Trees as Models Some Tree Theorems Applications of Trees Binary Search Tree Decision Tree Tree Traversal Spanning Trees

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 3 Terminology Tree A tree is a connected undirected graph that contains no circuits. Subtree of node n A tree that consists of a child (if any) of n and the child’s descendants Parent of node n The node directly above node n in the tree Child of node n A node directly below node n in the tree

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 4 Terminology Root The only node in the tree with no parent Leaf A node with no children Siblings Nodes with a common parent Ancestor of node n A node on the path from the root to n Descendant of node n A node on a path from n to a leaf

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 5 n-ary trees A 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. These are handy for describing sequences of yes-no decisions. Example: Comparisons in binary search algorithm.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 6 Trees as Models Can use trees to model the following: Saturated hydrocarbons Organizational structures Computer file systems

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 7 Some Tree Theorems Any tree with n nodes has e = n−1 edges. 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.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 8 Some More Tree Theorems 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. Corollary: An m-ary tree with leaves has height h≥  log m . If m is full and balanced then h=  log m .

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 9 Binary Search Trees A binary search tree A binary tree that has the following properties for each node n n’s value is greater than all values in its left subtree T L n’s value is less than all values in its right subtree T R Both T L and T R are binary search trees

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 10 Binary Search Trees (BST) BST supports the following operations in Θ(log n) average-case time: Searching for an existing item. Inserting a new item, if not already present. BST supports printing out all items in Θ(n) time. Note that inserting into a plain sequence a i would instead take Θ(n) worst-case time.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 11 Recursive Binary Tree Insert procedure insert(T: binary tree, x: item) v := root[T] if v = null then begin root[T] := x; return “Done” end else if v = x return “Already present” else if x v} return insert(rightSubtree[T], x)

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 12 Decision Trees A decision tree represents a decision-making process. Each possible “decision point” or situation is represented by a node. Each possible choice that could be made at that decision point is represented by an edge to a child node. In the extended decision trees used in decision analysis, we also include nodes that represent random events and their outcomes.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 13 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? ?

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 14 As a Decision-Tree Problem 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.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 15 Applying the 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. 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…

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 16 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.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 17 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!

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 18 Coin Balancing Decision Tree 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:1R:2B:3L:4R:5B:6 L:7 R:8

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 19 Tree Traversal A traversal operation is to visit each node in the tree, for example, to perform a task in each node. Traversal algorithms Preorder traversal Inorder traversal Postorder traversal Infix/prefix/postfix notation

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 20 Traversals of a Binary Tree Traversals of a binary tree: a) preorder; b) inorder; c) postorder

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 21 Spanning Trees A tree is an undirected connected graph without cycles A spanning tree of a connected undirected graph G A subgraph of G that contains all of G’s vertices and enough of its edges to form a tree To obtain a spanning tree from a connected undirected graph with cycles Remove edges until there are no cycles

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 22 Spanning Trees Detecting a cycle in an undirected connected graph A connected undirected graph that has n vertices must have at least n – 1 edges A connected undirected graph that has n vertices and exactly n – 1 edges cannot contain a cycle A connected undirected graph that has n vertices and more than n – 1 edges must contain at least one cycle Connected graphs that each have four vertices and three edges

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 23 The DFS Spanning Tree Depth-First Search (DFS) proceeds along a path from a vertex v as deeply into the graph as possible before backing up To create a depth-first search (DFS) spanning tree Traverse the graph using a depth-first search and mark the edges that you follow After the traversal is complete, the graph’s vertices and marked edges form the spanning tree

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 24 Breadth-First Search (BFS) visits every vertex adjacent to a vertex v that it can before visiting any other vertex To create a breath-first search (BFS) spanning tree –Traverse the graph using a bread-first search and mark the edges that you follow –When the traversal is complete, the graph’s vertices and marked edges form the spanning tree The BFS Spanning Tree

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 25 Minimum Spanning Trees Cost of the spanning tree Sum of the costs of the edges of the spanning tree A minimal spanning tree of a connected undirected graph has a minimal edge- weight sum There may be several minimum spanning trees for a particular graph

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen 26 Prim’s Algorithm Finds a minimal spanning tree that begins at any vertex Find the least-cost edge (v, u) from a visited vertex v to some unvisited vertex u Mark u as visited Add the vertex u and the edge (v, u) to the minimum spanning tree Repeat the above steps until there are no more unvisited vertices