Prüfer code algorithm Algorithm (Prüfer code)

Slides:



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

Introduction to Algorithms
CS 336 March 19, 2012 Tandy Warnow.
Great Theoretical Ideas in Computer Science for Some.
THE WELL ORDERING PROPERTY Definition: Let B be a set of integers. An integer m is called a least element of B if m is an element of B, and for every x.
Trees Chapter 11.
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
Bayesian Networks, Winter Yoav Haimovitch & Ariel Raviv 1.
CompSci 102 Discrete Math for Computer Science April 19, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
R. Bar-Yehuda © 1 קומבינטוריקה למדעי - המחשב – הרצאה #17 Chapter 2: TREES מבוסס על הספר : S. Even, "Graph Algorithms",
Linear-time encodable and decodable error-correcting codes Daniel A. Spielman Presented by Tian Sang Jed Liu 2003 March 3rd.
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.
What is the next line of the proof? a). Let G be a graph with k vertices. b). Assume the theorem holds for all graphs with k+1 vertices. c). Let G be a.
Graphs and Trees This handout: Trees Minimum Spanning Tree Problem.
Algorithm Design Techniques: Induction Chapter 5 (Except Section 5.6)
Is the following graph Hamiltonian- connected from vertex v? a). Yes b). No c). I have absolutely no idea v.
Job Scheduling Lecture 19: March 19. Job Scheduling: Unrelated Multiple Machines There are n jobs, each job has: a processing time p(i,j) (the time to.
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
Lecture 6: Point Location Computational Geometry Prof. Dr. Th. Ottmann 1 Point Location 1.Trapezoidal decomposition. 2.A search structure. 3.Randomized,
03/01/2005Tucker, Sec Applied Combinatorics, 4th Ed. Alan Tucker Section 3.1 Properties of Trees Prepared by Joshua Schoenly and Kathleen McNamara.
What is the next line of the proof? a). Assume the theorem holds for all graphs with k edges. b). Let G be a graph with k edges. c). Assume the theorem.
Induction and recursion
Mathematical Maxims and Minims, 1988
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.
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.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
 Rooted tree and binary tree  Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices.
5.2 Trees  A tree is a connected graph without any cycles.
Introduction to Graph Theory
Cayley’s Formula - Srinivas Nambirajan. The Setting Arthur Cayley (August 16, 1821 – January 26, 1895) Pure Mathematician Group Theory (Cayley’s Theorem)
Unit – V Graph theory. Representation of Graphs Graph G (V, E,  ) V Set of vertices ESet of edges  Function that assigns vertices {v, w} to each edge.
Great Theoretical Ideas in Computer Science for Some.
Indian Institute of Technology Kharagpur PALLAB DASGUPTA Graph Theory: Trees Pallab Dasgupta, Professor, Dept. of Computer Sc. and Engineering, IIT
Algorithms for hard problems Parameterized complexity Bounded tree width approaches Juris Viksna, 2015.
COMPSCI 102 Introduction to Discrete Mathematics.
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.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
MCA 520: Graph Theory Instructor Neelima Gupta
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar.
Trees.
Theory of Computational Complexity Probability and Computing Chapter Hikaru Inada Iwama and Ito lab M1.
Encoding and Decoding August 22, 2016 Miles Jones MTThF 8:30-9:50am
Chapter 5 : Trees.
Discrete Mathematicsq
Great Theoretical Ideas In Computer Science
Computing Connected Components on Parallel Computers
12. Graphs and Trees 2 Summary
Proving the Correctness of Huffman’s Algorithm
CMSC 341 Introduction to Trees.
Gray Code Can you find an ordering of all the n-bit strings in such a way that two consecutive n-bit strings differed by only one bit? This is called the.
Great Theoretical Ideas in Computer Science
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Discrete Mathematics for Computer Science
CSE 421: Introduction to Algorithms
The Art Gallery Problem
Trees.
Theorem 5.13: For vT‘, l’(v)= min{l(v), l(vk)+w(vk, v)}
Great Theoretical Ideas In Computer Science
About the number of regular vines on n nodes
Application: Algorithms
Application: Algorithms
Discrete Mathematics for Computer Science
The Selection Problem.
Proving the Correctness of Huffman’s Algorithm
Mathematical Induction II
Presentation transcript:

Prüfer code algorithm 2.2.1 Algorithm (Prüfer code) Input: A tree T with vertex set S Output: f(T) = (a1,a2,…,an-2), a sequence from S Iteration: Iterate i = 1, …, n-2. At the ith step, delete the least remaining leaf, and let ai be the neighbor of this leaf.

Prüfer code example Output: f(T) = 744171 Delete 2, a1=7 2 7 1 4 3 7 1 6 8 5 6 8 5 Tree T Delete 3, a2=4 Delete 4, a4=1 Delete 5, a3=4 7 1 7 1 4 7 1 4 6 8 6 8 6 8 5 Delete 6, a5=7 7 1 Delete 7, a6=1 1 Output: f(T) = 744171 8 8

Prüfer code property Fact. If T has vertices {1,…,n} and Prüfer code a1a2…an-2, then the leaves of T are {1,…,n} ─ {a1,a2,…,an-2}. Proof. (1) No leaf u of T appears in the code, as this would require removing all n-1 vertices except u. (2) All non-leaves of T have degree ≥ 2. Every vertex of v of T is eventually either removed or reduced to degree 1. In either case, at exactly d(v)-1 iterations of the algorithm, v is the neighbor of a leaf being deleted.

Prüfer decoding example Used Active Code 2,3,5,6,8 744171 2 3,5,6,8 44171 2,3 5,6,8 4171 2,3,5 4,6,8 171 2,3,4,5 6,8 71 2,3,4,5,6 7,8 1 2,3,4,5,6,7 1,8 2 7 1 4 3 6 8 5 2 7 1 4 3 6 8 5 2 7 1 4 3 6 8 5 2 7 1 4 3 6 8 5 2 7 1 4 3 6 8 5 2 7 1 4 3 6 8 5 2 7 1 4 3 6 8 5

Cayley’s Formula [1889] 2.2.3. Theorem. For a set S of size n, there are nn-2 trees with vertex set S. Proof. Formula true for n=1. Use induction for n ≥ 2 to show that any code a=(a1,a2,…,an-2) is the Prüfer code of exactly one tree T on vertices S. Base case. Prüfer code when n=2 is the empty sequence. There is one tree when n=2, with this code. Inductive step. Fix n ≥ 2 and assume true for smaller n. By the previous fact, the leaves of T are S ─ {a1,a2,…,an-2}. Call x the minimum element of S ─ {a1,a2,…,an-2}. Every tree T with code a with V(T)=S has leaf x, which is adjacent to a1. T-x is a tree with vertex set S’=S-{x} and code a’=(a2,…,an-2). By the induction hypothesis, T-x is uniquely determined by a’ on vertices S’. T must attach leaf x to a1 of T’ and this uniquely determines T from code a and vertex set S.