Trees. CSC 1300 Discrete Structures Villanova University

Similar documents
Major Themes. Trees. Types of Graphs. Which of the following are trees? G 3 G 1 G 2 G 4. Dr Papalaskari 1

Foundations of Discrete Mathematics

CS 441 Discrete Mathematics for CS Lecture 26. Graphs. CS 441 Discrete mathematics for CS. Final exam

Minimum Spanning Trees My T. UF

March 20/2003 Jayakanth Srinivasan,

CSE 21 Mathematics for Algorithm and System Analysis

Trees Algorhyme by Radia Perlman

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

Minimum Spanning Trees

Chapter 10: Trees. A tree is a connected simple undirected graph with no simple circuits.

Graph Traversals. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari 1

Trees Rooted Trees Spanning trees and Shortest Paths. 12. Graphs and Trees 2. Aaron Tan November 2017

Graph Planarity. CSC 1300 Discrete Structures Villanova University

Graph and Digraph Glossary

Hamilton paths & circuits. Gray codes. Hamilton Circuits. Planar Graphs. Hamilton circuits. 10 Nov 2015

Graphs Definitions. Gunnar Gotshalks. GraphDefinitions 1

License. Discrete Mathematics. Tree. Topics. Definition tree: connected graph with no cycle. examples. c T. Uyar, A. Yayımlı, E.

An undirected graph is a tree if and only of there is a unique simple path between any 2 of its vertices.

Introduction to Computers and Programming. Concept Question

COP 4531 Complexity & Analysis of Data Structures & Algorithms

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Problem Set 2 Solutions

Graph Theory CS/Math231 Discrete Mathematics Spring2015

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND

Lecture 13. Reading: Weiss, Ch. 9, Ch 8 CSE 100, UCSD: LEC 13. Page 1 of 29

Elements of Graph Theory

Undirected Graphs. Hwansoo Han

12/5/17. trees. CS 220: Discrete Structures and their Applications. Trees Chapter 11 in zybooks. rooted trees. rooted trees

Major Themes. Graph Traversals. Euler s SoluWon to The Bridges of Königsberg. The Bridges of Königsberg Puzzle. Dr Papalaskari 1

18 Spanning Tree Algorithms

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

DS UNIT 4. Matoshri College of Engineering and Research Center Nasik Department of Computer Engineering Discrete Structutre UNIT - IV

Spanning Trees. Lecture 20 CS2110 Spring 2015

Algorithm Design and Analysis

Topics. Trees Vojislav Kecman. Which graphs are trees? Terminology. Terminology Trees as Models Some Tree Theorems Applications of Trees CMSC 302

CS204 Discrete Mathematics. 11 Trees. 11 Trees

Math.3336: Discrete Mathematics. Chapter 10 Graph Theory

Warm Up. Use Kruskal s algorithm to find the minimum spanning tree and it s weight.

Weighted Graphs and Greedy Algorithms

Trees. Arash Rafiey. 20 October, 2015

Greedy Algorithms. Previous Examples: Huffman coding, Minimum Spanning Tree Algorithms

LECTURE 26 PRIM S ALGORITHM

22 Elementary Graph Algorithms. There are two standard ways to represent a

Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )

CSC 373: Algorithm Design and Analysis Lecture 4

Section Summary. Introduction to Trees Rooted Trees Trees as Models Properties of Trees

v V Question: How many edges are there in a graph with 10 vertices each of degree 6?

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

CS 6783 (Applied Algorithms) Lecture 5

Minimum spanning trees

K 4 C 5. Figure 4.5: Some well known family of graphs

Minimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem

CHAPTER 10 GRAPHS AND TREES. Alessandro Artale UniBZ - artale/

Self-Balancing Search Trees. Chapter 11

Key Graph Theory Theorems

Chapter Summary. Introduction to Trees Applications of Trees Tree Traversal Spanning Trees Minimum Spanning Trees

Course Review for Finals. Cpt S 223 Fall 2008

Algorithms. Graphs. Algorithms

CPCS Discrete Structures 1

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

22 Elementary Graph Algorithms. There are two standard ways to represent a

Lecture Notes for Chapter 23: Minimum Spanning Trees

Induction Review. Graphs. EECS 310: Discrete Math Lecture 5 Graph Theory, Matching. Common Graphs. a set of edges or collection of two-elt subsets

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

CSE 100: B+ TREE, 2-3 TREE, NP- COMPLETNESS

CS302 - Data Structures using C++

A graph is a set of objects (called vertices or nodes) and edges between pairs of nodes.

MAT 7003 : Mathematical Foundations. (for Software Engineering) J Paul Gibson, A207.

Discrete mathematics II. - Graphs

Data Structure. IBPS SO (IT- Officer) Exam 2017

Announcements Problem Set 5 is out (today)!

Proposition 1. The edges of an even graph can be split (partitioned) into cycles, no two of which have an edge in common.

Algorithms: Graphs. Amotz Bar-Noy. Spring 2012 CUNY. Amotz Bar-Noy (CUNY) Graphs Spring / 95

Lecture Notes. char myarray [ ] = {0, 0, 0, 0, 0 } ; The memory diagram associated with the array can be drawn like this


Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

CSC 505, Fall 2000: Week 7. In which our discussion of Minimum Spanning Tree Algorithms and their data Structures is brought to a happy Conclusion.

Chapter 11: Graphs and Trees. March 23, 2008

Section 8.2 Graph Terminology. Undirected Graphs. Definition: Two vertices u, v in V are adjacent or neighbors if there is an edge e between u and v.

Discrete mathematics

Solutions to Midterm 2 - Monday, July 11th, 2009

CHAPTER 11 Trees. 294 Chapter 11 Trees. f) This is a tree since it is connected and has no simple circuits.

Graphs. Introduction To Graphs: Exercises. Definitions:

4 Basics of Trees. Petr Hliněný, FI MU Brno 1 FI: MA010: Trees and Forests

Discrete Mathematics. Chapter 7. trees Sanguk Noh

Chapter 2 Graphs. 2.1 Definition of Graphs

CSE 100: GRAPH ALGORITHMS

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Minimum Spanning Tree (5A) Young Won Lim 5/11/18

Data Structures and Algorithms

Chapter 3 Trees. Theorem A graph T is a tree if, and only if, every two distinct vertices of T are joined by a unique path.

managing an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Major Themes. 14: Graph Traversals. The Bridges of Königsberg Puzzle. Dr Papalaskari 1. Graph traversals: Euler circuit/trail.

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Graph Theory

r=1 The Binomial Theorem. 4 MA095/98G Revision

Union/Find Aka: Disjoint-set forest. Problem definition. Naïve attempts CS 445

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

BMI/STAT 768: Lecture 06 Trees in Graphs

Transcription:

Trees CSC 1300 Discrete Structures Villanova University

Major Themes Trees Spanning trees Binary trees Binary search trees ApplicaAons But first: Review Graphs Villanova CSC 1300 - Dr Papalaskari 2

Review Graphs Graphs a c G VerAces f Edges d b Path g Cycle e Isomorphism Subgraph G - the complement of a graph G Σ deg(v) = 2 E - handshaking lemma v V Villanova CSC 1300 - Dr Papalaskari 3

Review Types of Graphs Directed graph Weighted graph (directed or undirected) Simple graph Special graphs Cycle C x Wheel W x Complete graph K x A Complete BiparAte K x,y Connected graph Tree: a connected graph with no cycles Forest: a graph with no cycles Villanova CSC 1300 - Dr Papalaskari 4

Which of the following are trees? G 1 G 3 G 2 G 4 Villanova CSC 1300 - Dr Papalaskari 5

Subgraphs of K 3 which of these are trees? 3.8 Problem #6 Draw the 7 nonisomorphic subgraphs of K 3 and the 17 disanct subgraphs of K 3. Non-isomorphic subgraphs of K 3 DisAnct subgraphs of K 3 Villanova CSC 1300 - Dr Papalaskari 6

Tree: a connected graph with no cycles A tree with n veraces has n-1 edges A connected graph with n veraces and n-1 edges is a tree. Every tree with at least 2 veraces has 2 or more leaves A leaf is a vertex of degree 1. Villanova CSC 1300 - Dr Papalaskari 7

A Spanning Trees Spanning Tree: A subgraph that is a tree and contains all the veraces of a given graph. Every connected graph has at least 1 spanning tree. Every weighted connected graph has a minimum spanning tree Villanova CSC 1300 - Dr Papalaskari 8

Kruskal s Minimum Spanning Tree Algorithm Order the edges of G, by increasing weight break Aes by using ordering on vertex labels G starts out as the graph with all the veraces of G and none of the edges Keep adding edges to G, at each iteraaon adding the lowest weighted edge that does not introduce a cycle Stop when the graph becomes connected. G is now the minimum spanning tree. Villanova CSC 1300 - Dr Papalaskari 9

Prim s Minimum Spanning Tree Algorithm G starts out as the graph with the least weighted edge in G and the 2 veraces incident with this edge break any Aes by using ordering on vertex labels Select the lowest weighted edge that connects a vertex in G to any of the remaining veraces of G; add edge and vertex to G and repeat unal all the veraces of G are added to G G is now the minimum spanning tree. Villanova CSC 1300 - Dr Papalaskari 10

Kruskal s Algorithm Villanova CSC 1300 - Dr Papalaskari 11

Prim s Algorithm Villanova CSC 1300 - Dr Papalaskari 12

Rooted Tree A rooted tree has a disanguished vertex called the root Rooted trees are usually drawn with the root at the top and all other veraces connected by edges growing downward Each edge in a rooted tree connects a parent vertex with a child vertex below it. Villanova CSC 1300 - Dr Papalaskari 13

Binary Tree A rooted tree Each vertex has at most 2 children The children of a vertex are disanguished as le4 and right child. the k th rank of a binary tree is the collecaon of veraces at distance k from the root In a complete binary tree every vertex has exactly two children, except for the leaves in the bocom rank. the height of a tree is the highest rank of its leaves Villanova CSC 1300 - Dr Papalaskari 14

Turn these into rooted trees G 1 G 4 which of them are binary trees? Villanova CSC 1300 - Dr Papalaskari 15

More about binary trees: How many leaves in a complete binary tree? If a tree has height 5 and 50 veraces, is it possible for it to be: a binary tree? a complete binary tree? Repeat with a tree of height 5 with 100 veraces Example 10.5.3 ancestral trees Villanova CSC 1300 - Dr Papalaskari 16

Binary Search Trees A binary search tree has a datum associated with each node such that in the ordering of the data set, the datum occurs earlier than any of the data downward and to the right and occurs later than any of the data downward and to the lee. Villanova CSC 1300 - Dr Papalaskari 18

Check Yourself 10.5 #4 Place baa at the root and draw the binary search tree for aaa, ab, baa, baba Villanova CSC 1300 - Dr Papalaskari 19

Example: Subsets of the set {a,b,c} as a binary decision tree Villanova CSC 1300 - Dr Papalaskari 20

Fake coin puzzle You have some gold coins and a balance scale. One of the coins is a fake and weighs less (gold is HEAVY). How can you determine which coin is fake with the least number of weighings? Villanova CSC 1300 - Dr Papalaskari 21