 Rooted tree and binary tree  Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices.

Slides:



Advertisements
Similar presentations
CS 336 March 19, 2012 Tandy Warnow.
Advertisements

Trees Chapter 11.
 Theorem 5.9: Let G be a simple graph with n vertices, where n>2. G has a Hamilton circuit if for any two vertices u and v of G that are not adjacent,
2012: J Paul GibsonT&MSP: Mathematical FoundationsMAT7003/L2-GraphsAndTrees.1 MAT 7003 : Mathematical Foundations (for Software Engineering) J Paul Gibson,
Greedy Algorithms Greed is good. (Some of the time)
22C:19 Discrete Structures Trees Spring 2014 Sukumar Ghosh.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
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.
Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.
1 Huffman Codes. 2 Introduction Huffman codes are a very effective technique for compressing data; savings of 20% to 90% are typical, depending on the.
CSE 421 Algorithms Richard Anderson Lecture 22 Network Flow.
Graphs and Trees This handout: Trees Minimum Spanning Tree Problem.
Data Structures – LECTURE 10 Huffman coding
Chapter 9: Huffman Codes
Lecture Recursive Definitions. Fractals fractals are examples of images where the same elements is being recursively.
4.8 Huffman Codes These lecture slides are supplied by Mathijs de Weerd.
Discrete Mathematics Lecture 9 Alexander Bukharovich New York 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.
5.4 Shortest-path problem  Let G=(V,E,w) be a weighted connected simple graph, w is a function from edges set E to position real numbers set. We denoted.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
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.
Foundations of Discrete Mathematics
Trees and Distance. 2.1 Basic properties Acyclic : a graph with no cycle Forest : acyclic graph Tree : connected acyclic graph Leaf : a vertex of degree.
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.
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.
5.2 Trees  A tree is a connected graph without any cycles.
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.
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.
1/24 Introduction to Graphs. 2/24 Graph Definition Graph : consists of vertices and edges. Each edge must start and end at a vertex. Graph G = (V, E)
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.
Huffman’s Algorithm 11/02/ Weighted 2-tree A weighted 2-tree T is an extended binary tree with n external nodes and each of the external nodes is.
Foundation of Computing Systems
 Quotient graph  Definition 13: Suppose G(V,E) is a graph and R is a equivalence relation on the set V. We construct the quotient graph G R in the follow.
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.
Huffman Codes. Overview  Huffman codes: compressing data (savings of 20% to 90%)  Huffman’s greedy algorithm uses a table of the frequencies of occurrence.
1 Assignment #3 is posted: Due Thursday Nov. 15 at the beginning of class. Make sure you are also working on your projects. Come see me if you are unsure.
 Hamilton paths.  Definition 20: A Hamilton paths is a path that contains each vertex exactly once. A Hamilton circuit is a circuit that contains.
Approximation Algorithms Greedy Strategies. I hear, I forget. I learn, I remember. I do, I understand! 2 Max and Min  min f is equivalent to max –f.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
5.6 Prefix codes and optimal tree Definition 31: Codes with this property which the bit string for a letter never occurs as the first part of the bit string.
Greedy Algorithms. p2. Activity-selection problem: Problem : Want to schedule as many compatible activities as possible., n activities. Activity i, start.
Section10.1: Introduction to Trees
Trees.
Graph Graphs and graph theory can be used to model:
Chapter 5 : Trees.
Greedy Technique.
12. Graphs and Trees 2 Summary
Introduction to Trees Section 11.1.
Advanced Algorithms Analysis and Design
Chapter 9: Huffman Codes
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 10 Trees Slides are adopted from “Discrete.
Math 221 Huffman Codes.
Richard Anderson Lecture 21 Network Flow
Problem Solving 4.
Activity Networks
Trees Addenda.
Theorem 5.13: For vT‘, l’(v)= min{l(v), l(vk)+w(vk, v)}
Trees 11.1 Introduction to Trees Dr. Halimah Alshehri.
Lecture 21 Network Flow, Part 1
Podcast Ch23d Title: Huffman Compression
Huffman Coding Greedy Algorithm
Algorithms CSCI 235, Spring 2019 Lecture 31 Huffman Codes
5.7 Transport Networks Transport Networks Transport Networks
Richard Anderson Lecture 22 Network Flow
Presentation transcript:

 Rooted tree and binary tree  Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices.

 Theorem 5.20: Let T be a full binary tree. We denote the sum of length of simple paths from root to all internal vertices by I, and the sum of length of simple paths from root to all leaves by E. Then E=I+2i, where i is the number of internal vertices.  Proof: Let us apply induction on the number i of internal vertices.  E=2 and I=0 when i=1

 Suppose that result holds for i=k-1  For i=k, we chose internal vertex v so that its children are leaves. We have a new tree which is obtained by omitting edges of incident v and its children.  By the inductive hypothesis, E'=I'+2(k-1)  We denote the length of path from root to v by l.  E'=E- l-2, I'=I-l.  E= E'+l+2=I'+2(k-1)+l+2=I-l+2(k-1)+l+2=I+2k 。  Let T be a full m-ary tree. Then E=(m-1)I+mi, where i is the number of internal vertices.

5.6 Prefix codes and optimal tree  a b c d e   The set {00,110,010,10,01} is called code   ead or cc?  The string of e is prefix of string of c  c: 111  The set {00,110,111,10,01} is called prefix code

 Definition 31: Codes with this property which the bit string for a letter never occurs as the first part of the bit string for another letter are called prefix codes.  Theorem 5.21: We can construct a prefix code from any binary tree, and we can construct a binary tree from the prefix codes.  Proof: (1) We can construct a prefix code from any binary tree where the left edge at each internal vertex is labeled by 0 and the right edge by a 1 and where the leaves are labeled by characters  (2)We can construct a binary tree from the prefix codes

 Huffman algorithm:  Let a 1,a 2, ,a n be n vertex with weight w 1,w 2, ,w n and w 1  w 2  w n 。  F:=forest of n rooted tree each consisting of the single vertex a i with weight w i for i=1,2,...n.  While F is not a tree  Begin  Replace the rooted trees T and T’ of least weights from F with w(T)≥ w(T’) with a tree having a new root that has T as its left subtree and T’ as its right subtree. Assign w(T)+w(T’) as the weight of the new tree.  end

 Example: Find a optimal tree with weight 2,4,7,8,10,12

w(T)=2*4+4*4+7*3+ 12*2+8*2+10*2=105

 Theorem 5.22: Let T be built according to Huffman algorithm and leaves of T with weight w 1,w 2, ,w n. Then T is an optimal tree.  Proof: Let us apply induction on the number n of vertices.  n=2, The results holds Suppose that result holds for n=k-1 For n=k , By the inductive hypothesis, Suppose that nodes in an optimal tree T have weights w 1 +w 2,w 3, ,w k. Then This is an optimal tree with weight w 1,w 2,w 3, ,w k if T’s leaf with weight w 1 +w 2 is replaced by subtree

 Lemma 5.1 Let T 1 be an optimal tree with weights w 1  w 2  w 3  w k. Then there is an optimal tree T 2 so that T 2 ’s two vertices with weights w 1 and w 2 are brother nodes.  Proof: Let T 1 be an optimal tree with weights w 1  w 2  w 3  w k  The two weights w a,w b are on lowest level and they are brothers. We denoted by v a and v b. Let v 0 be the father of v a, v b.  w a  w 1, w b  w 2.  Let l a be the length of the path from root to v a, and l b be the length of the path from root to v b.  l a =l b, l a  l 1, l a  l 2,  We obtain a new tree T 2 by exchanging from leaf v 1 to v a and from leaf v 2 to v b.  w(T 1 )-w(T 2 )=(w a -w 1 )(l a -l 1 )+ (w b -w 2 )(l a -l 2 )  0

 Lemma 5.2: Suppose that nodes of an optimal tree T have weights w 1 +w 2,w 3, ,w k. Then this is an optimal tree with weight w 1,w 2,w 3, ,w k if T*’s leaf with weight w 1 +w 2 is replaced by subtree Proof: By the Lemma 5.1,there is an optimal tree T 2 with weight w 1,w 2,w 3, ,w k so that T 2 ’s two vertices with weights w 1 and w 2 are brother nodes. Let l 1 be the length of the path from root to v 1 with weight w 1. Let T 2 * be a same tree as T 2 without leaf with weight w 1 and leaf with weight w 2, but with a having leaf of weight w 1 +w 2. w(T 2 *)=w(T 2 )-w 1 l 1 - w 2 l 1 +(w 1 +w 2 )(l 1 -1) Thus w(T 2 )=w(T 2 *)+w 1 +w 2 Let T* be a same tree as T without leaf with w 1 +w 2 but with subtree Suppose that T* is not an optimal tree.

 Theorem 5.22:Proof: Let us apply induction on the number n of vertices.  n=2, The results holds Suppose that result holds for n=k-1 For n=k , By the inductive hypothesis, the tree with weight w 1 +w 2,w 3, ,w k by according to Huffman algorithm is an optimal tree. By lemma 5.2, this is an optimal tree with weight w 1,w 2,w 3, ,w k if T’s leaf with weight w 1 +w 2 is replaced by subtree

5.7 Transport Networks  Transport Networks  Definition 33: A transport network or a network, is a connected digraph N(V,E,C) with the following properties:  (1)N has no loop.  (2)There is a unique node s, the source, that has in- degree 0. And there is a unique node t, the sink, that has out-degree 0.  (3)The graph is labeled. The label, c ij on edge (i,j) is a nonnegative number called the capacity of the edge. Let C={c ij |(i,j)  E}.

 Definition 34: A flow in a network N(V,E,C) is a function that assigns to each edge (i,j) of N a nonnegative number f ij that does not exceed c ij. A conservation flow is a flow with the properties:  for each vertex other than the source and sink. The sum  is called the value of the conservation flow. A conservation flow f is called maximum flow, if v f ≥v f’ for any conservation flow f ’ of N.

 Definition 35: Let N be a network with the source node and the sink node. If P is a subset of V containing source s but not sink t then E(P,V-P)is called a cut separating s from t.  In effect, a cut does “cut” a digraph into two pieces, one containing the source and one containing the sink. If the edges of a cut were removed, it has not any paths from source to sink.

The capacity of a cut E(P,V-P)is, we denote by C(P,V-P). i.e.

 A cut E(P,V-P) of N is called minimum cut, if C(P,V-P)≤C(P',V-P') for any cut E(P',V-P') of N.  Theorem 5.23: For every conservation flow f and any cut E(P,V-P), the result holds: V f  C(P,V-P).  V f  C(P,V-P) ,  V f max  C min (P,V-P)

 Lemma 5.3: Let f be a conservation flow, E(P,V-P) be a cut. If V f =C(P,V-P) , then V f max =V f , C min (P,V-P)=C(P,V-P).  Proof: By the theorem 5.23,  Frod,Falkerson  1956

 Next: Transport Networks, 8.4 P307  Graph Matching 8.5 P315  Exercise: P  1. Let T be a full m-ary tree. We denote the sum of length of simple paths from root to all internal vertices by I, and the sum of length of simple paths from root to all leaves by E. Then E=(m-1)I+2i, (m-1)i=t-1, where i is the number of internal vertices and t is the number of leaves  2.(1)Find a optimal binary tree with weight 1,3,8,9,12, 15,16  (2)Construct a algorithms for optimal 3-ary tree  (3)Find a optimal 3-ary tree with weight 1,2,3,4,5,6,7,8,9  (4)Find a optimal 3-ary tree with weight 1,2,3,4,5,6,7,8,