Applied Combinatorics, 4th Ed. Alan Tucker

Slides:



Advertisements
Similar presentations
Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
Advertisements

3.3 Spanning Trees Tucker, Applied Combinatorics, Section 3.3, by Patti Bodkin and Tamsen Hunter.
1 Section 9.4 Spanning Trees. 2 Let G be a simple graph. A spanning subtree of G is a subgraph of G containing every vertex of G –must be connected; contains.
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.
MATH 310, FALL 2003 (Combinatorial Problem Solving) Lecture 13, Monday, September 29.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 21: Graphs.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Applied Combinatorics, 4th Ed. Alan Tucker
Lists A list is a finite, ordered sequence of data items. Two Implementations –Arrays –Linked Lists.
Transforming Infix to Postfix
3/29/05Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 4.2 Minimal Spanning Trees Prepared by Amanda Dargie and Michele Fretta.
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.
2/10/03Tucker, Sec Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The trees.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
1 Section 1.4 Graphs and Trees A graph is set of objects called vertices or nodes where some pairs of objects may be connected by edges. (A directed graph.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
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.
CSCI 115 Chapter 7 Trees. CSCI 115 §7.1 Trees §7.1 – Trees TREE –Let T be a relation on a set A. T is a tree if there exists a vertex v 0 in A s.t. there.
TREES. What is a tree ? An Abstract Data Type which emulates a tree structure with a set of linked nodes The nodes within a tree are organized in a hierarchical.
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.
Chapter 7. Trees Weiqi Luo ( 骆伟祺 ) School of Software Sun Yat-Sen University : Office : A309
Trees : Part 1 Section 4.1 (1) Theory and Terminology (2) Preorder, Postorder and Levelorder Traversals.
Trees By P.Naga Srinivasu M.tech,(MBA). Basic Tree Concepts A tree consists of finite set of elements, called nodes, and a finite set of directed lines.
Discrete Mathematics Chapter 5 Trees.
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.
CMSC 202, Version 5/02 1 Trees. CMSC 202, Version 5/02 2 Tree Basics 1.A tree is a set of nodes. 2.A tree may be empty (i.e., contain no nodes). 3.If.
Chapter 20: Graphs. Objectives In this chapter, you will: – Learn about graphs – Become familiar with the basic terminology of graph theory – Discover.
1 Trees : Part 1 Reading: Section 4.1 Theory and Terminology Preorder, Postorder and Levelorder Traversals.
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.
Discrete Structures Li Tak Sing( 李德成 ) Lectures
Code: BCA302 Data Structures with C Prof. (Dr.) Monalisa Banerjee By.
Review Graph Directed Graph Undirected Graph Sub-Graph Spanning Sub-Graph Degree of a Vertex Weighted Graph Elementary and Simple Path Link List Representation.
Non Linear Data Structure
Applied Discrete Mathematics Week 15: Trees
Discrete Mathematicsq
Trees Chapter 11.
Source Code for Data Structures and Algorithm Analysis in C (Second Edition) – by Weiss
12. Graphs and Trees 2 Summary
Tree.
Introduction to Trees Section 11.1.
Section 8.1 Trees.
Depth-First Search.
Discrete Maths 10. Trees 242/ , Semester 2, Objective
Applied Combinatorics, 4th Ed. Alan Tucker
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Binary Tree Traversal Methods
Trees 1: Theory, Models, Generic Heap Algorithms, Priority Queues
Trees.
Binary Tree Traversal Methods
Graphs.
Binary Tree Traversal Methods
Applied Combinatorics, 4th Ed. Alan Tucker
Applied Combinatorics, 4th ed. Alan Tucker
COMPS263F Unit 2 Discrete Structures Li Tak Sing( 李德成 ) Room A
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
And the Final Subject is…
Backtracking and Branch-and-Bound
COMP108 Algorithmic Foundations Graph Theory
Applied Combinatorics, 4th Ed. Alan Tucker
ARTIFICIAL INTELLIGENCE
CSC 325: Algorithms Graph Algorithms David Luebke /24/2019.
Trees Chapter 11.
8.2 Tree Traversals Chapter 8 - Trees.
Presentation transcript:

Applied Combinatorics, 4th Ed. Alan Tucker Section 3.2 Search Trees and Spanning Trees Prepared by Jessica Scheld 9/22/2018 Tucker, Sec. 3.2

Trees Enumeration: Finding all of the possible paths in a rooted tree that begin at the root, or the solutions that path represents; finding the unique path from the root to each internal vertex and leaf Example: A The paths are: (A-B) (A-B-D) B C (A-B-E) (A-C) (A-C-F) D E F 9/22/2018 Tucker, Sec. 3.2

Depth-First Search Tree (A-B-D-E-C-F) B C D E F 9/22/2018 Tucker, Sec. 3.2

Breadth-First Search Tree A-B-C-D-E-F B C D E F 9/22/2018 Tucker, Sec. 3.2

Spanning Tree Spanning tree: a subgraph of a graph G that is a tree containing all vertices of G can be constructed in 2 ways Depth-first (backtrack) search Breadth-first search If a graph is not connected, no spanning tree exists. 9/22/2018 Tucker, Sec. 3.2

Depth-First Search for a Spanning Tree Pick a vertex as the root and begin building a path from the root composed of edges of the graph. Continue this path until it cannot go any further without repeating a vertex already in the tree. Vertex where path must stop is a leaf of the spanning tree. Now, backtrack to the parent of the leaf and try to build a path from the parent in another direction. Exhaust all paths from parent y, then backtrack to parent of y and repeat the process until forced to return to the root. 9/22/2018 Tucker, Sec. 3.2

Finding a Spanning Tree For a graph G: Search Tree - Depth-First Search A B A F C B C E D D E Note: There are other ways to find a spanning tree by doing a depth-first search. F 9/22/2018 Tucker, Sec. 3.2

Finding a Spanning Tree For a graph G: Search Tree – Depth-First Search A B A F C D E E D B C F 9/22/2018 Tucker, Sec. 3.2

Breadth-First Search for a Spanning Tree Pick some vertex x as the root and put all edges leaving x (along with the vertices at the ends of these edges) in the tree. Successively add to the tree the edges leaving the vertices adjacent from x, unless such an edge goes to a vertex already in the tree. Continue in a level-by-level fashion. 9/22/2018 Tucker, Sec. 3.2

Finding a Spanning Tree Given a graph G: Find spanning tree using the breadth-first method: A B A F C B F D E D C E 9/22/2018 Tucker, Sec. 3.2

Spanning Trees from Adjacency Matrices This adjacency matrix shows that A is connected to B and C, B is connected to A, C and D, C is connected to A and B, and D is connected to B. The corresponding graph would look like this: a b c d 1 A B C D 9/22/2018 Tucker, Sec. 3.2

Adjacency Matrices A B C D E F G H 1 1 This graph G is represented in the adjacency matrix to the left. We want to determine a spanning tree given this information. A B C D F E G H 9/22/2018 Tucker, Sec. 3.2

Finding Spanning Trees Depth-first search spanning tree A B C D E F G H 1 f b 1 1 e 1 1 c g h d 1 A F B 1 1 E D C G H 9/22/2018 Tucker, Sec. 3.2

Finding Spanning Trees B C D E F G H 1 Breadth-first search spanning tree 1 1 1 1 a 1 1 f b d c g e h A F B 1 E D C G H 9/22/2018 Tucker, Sec. 3.2

The problem: You have 3 pitchers: sizes 10 quarts, 7 quarts, and 4 quarts. Begin with 10 quarts of water in the largest pitcher, other two pitchers are empty. You can pour until the receiving pitcher is full or the pouring pitcher is empty. Problem: Is there a way to have exactly 2 quarts in the 7- or 4-quart pitcher? If so, what is the minimum sequence of pourings to get 2 quarts? 9/22/2018 Tucker, Sec. 3.2

Example: Pitcher-Pouring Puzzle 4 2 1 (0,4) (10,0,0) 3 (6,0,4) (3,7,0) (7,0) 0 1 2 3 4 5 6 7 Draw a grid. The boundaries are that b=7, c=4, and b+c=10. Pouring between 10 and 7 quart pitchers will be represented by horizontal lines, between 10 and 4 quart pitchers will be by vertical lines, and between 4 and 7 quart pitchers is a diagonal line. Start at (0,0) – the root of the tree You have two choices – pour all the water into the 7 quart pitcher or the 4 quart pitcher. 9/22/2018 Tucker, Sec. 3.2

Pitcher Problem Continued 0 1 2 3 4 5 6 7 4 3 2 1 (4,0) (3,4) (6,4) (7,3) (10,0,0) (6,0,4) (3,7,0) (6,4,0) (0,6,4) (0,7,3) (3,3,4) Note: We are using the breadth-first search method since it produces a spanning tree with the shortest paths from the root to every other vertex in the graph. 9/22/2018 Tucker, Sec. 3.2

Pitcher Problem Continued (2,4) (4,4) 4 (10,0,0) (0,3) 3 2 (6,0,4) (3,7,0) 1 (7,1) (6,4,0) 0 1 2 3 4 5 6 7 (0,6,4) (0,7,3) (3,3,4) (3,0) (6,0) (2,4,4) (4,6,0) (7,0,3) (7,3,0) The shortest path is from (0,0)-(0,4)-(6,4)-(6,0)-(2,4) (2,7,1) (4,2,4) 9/22/2018 Tucker, Sec. 3.2

Problem: Jealous Wives We have 3 wives and their respective husbands who are on the left side of a river. They must all make it to the right side of the river via a little boat which seats at most 2 people. Problem: Find a sequence of boat trips which allows all 6 to get across without any husband being alone (without his wife) and with another husband’s wife. Let the wives be denoted: A,B,C. Let the husbands be denoted: a,b,c. 9/22/2018 Tucker, Sec. 3.2

Example 4: Jealous Wives Puzzle This is one example of the path taken to get the 6 people across. This graph represents the process from one side to the other. ABCabc BCbc ABCbc ABC ABCa Aa ABab ab abc a ab END Aa A bc a BC Bb AB c bc b ab Vertices represent who is on the left side of the river and still needs to cross. Edges represent who is crossing. The arrows dictate the direction of movement (right arrow represents crossing the river, left arrow represents returning to the original side). 9/22/2018 Tucker, Sec. 3.2

Definitions Preorder traversal: depth-first search that examines an internal vertex when the vertex is first encountered in the search; when vertex precedes its children and all its other descendants. Postorder traversal: examines an internal vertex when last encountered (before the search backtracks away from the vertex and its subtree); when a vertex follows its children and all its other descendants. If a tree is binary, an inorder traversal checks an internal vertex in between the traversal of its left and right subtrees. 9/22/2018 Tucker, Sec. 3.2

Examples A D E F C B A D E F C B A Pre: A,B,D,E,C,F Post: D,E,B,F,C,A Identify vertex last time you see it. Identify vertex first time you see it. B C In order: D,B,E,A,G,C,F Must be binary – identify vertex in between children. D E G F 9/22/2018 Tucker, Sec. 3.2

Arithmetic Tree × ÷ ÷ - + c g ÷ a f b q + e d 9/22/2018 Tucker, Sec. 3.2

Class Exercise: Pg. 113 #23 4 people have to cross a bridge that only holds 2 people at a time It is night, there is one flashlight. Any party to cross must have the flashlight. Person A takes 1 minute to cross Person B takes 2 minutes Person C takes 5 minutes Person D takes 10 minutes. You must go at the pace of the slowest walker. Find a way to get all 4 to the other side in 17 minutes. 9/22/2018 Tucker, Sec. 3.2

Bridge Crossing: Solution First, let A and B cross the bridge 2 minutes A returns with the flashlight 1 minute C and D cross the bridge 10 minutes B returns with the flashlight A and B cross the bridge TOTAL TIME: 17 minutes! ABCD CD ACD AB A CD A AB Complete AB B 9/22/2018 Tucker, Sec. 3.2