Paolo Ferragina Dipartimento di Informatica, Università di Pisa

Slides:



Advertisements
Similar presentations
Interval Heaps Complete binary tree. Each node (except possibly last one) has 2 elements. Last node has 1 or 2 elements. Let a and b be the elements in.
Advertisements

An Improved Succinct Dynamic k-Ary Tree Representation (work in progress) Diego Arroyuelo Department of Computer Science, Universidad de Chile.
Paolo Ferragina, Università di Pisa Compressed Rank & Select on general strings Paolo Ferragina Dipartimento di Informatica, Università di Pisa.
Algorithms and Data Structures Lecture 4. Agenda: Trees – fundamental notions, variations Binary search tree.
Succinct Representations of Trees S. Srinivasa Rao Seoul National University.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Binary Search Trees1 Part-F1 Binary Search Trees   
Trees and Red-Black Trees Gordon College Prof. Brinton.
Kymberly Fergusson CSE1303 Part A Data Structures and Algorithms Summer Semester 2003 Lecture A12 – Binary Trees.
Mike 66 Sept Succinct Data Structures: Techniques and Lower Bounds Ian Munro University of Waterloo Joint work with/ work of Arash Farzan, Alex Golynski,
Binary Tree. Binary Trees – An Informal Definition A binary tree is a tree in which no node can have more than two children Each node has 0, 1, or 2 children.
B+ Trees COMP
Succinct Representations of Trees
Introduction n – length of text, m – length of search pattern string Generally suffix tree construction takes O(n) time, O(n) space and searching takes.
Data Structures : Project 5 Data Structures Project 5 – Expression Trees and Code Generation.
Summer School '131 Succinct Data Structures Ian Munro.
Binary Trees 2 Overview Trees. Terminology. Traversal of Binary Trees. Expression Trees. Binary Search Trees.
1 Red-Black Trees By Mary Hudachek-Buswell Red Black Tree Properties Rotate Red Black Trees Insertion Red Black Trees.
Tree Data Structures.
Succinct Data Structures Ian Munro University of Waterloo Joint work with David Benoit, Andrej Brodnik, D, Clark, F. Fich, M. He, J. Horton, A. López-Ortiz,
CS 361 – Chapter 3 Sorted dictionary ADT Implementation –Sorted array –Binary search tree.
Random access to arrays of variable-length items
Trees CS 105. L9: Trees Slide 2 Definition The Tree Data Structure stores objects (nodes) hierarchically nodes have parent-child relationships operations.
2-3 Trees Extended tree.  Tree in which all empty subtrees are replaced by new nodes that are called external nodes.  Original nodes are called internal.
Binary Tree 10/22/081. Tree A nonlinear data structure Contain a distinguished node R, called the root of tree and a set of subtrees. Two nodes n1 and.
Binary Search Trees ©Robert E. Tarjan Dictionary: contains a set S of items, each with associated information. Operations: Access(x): Determine.
Index construction: Compression of postings Paolo Ferragina Dipartimento di Informatica Università di Pisa Reading 5.3 and a paper.
1. Iterative Preorder Traversal Rpreorder(T) 1. [process the root node] if T!= NULL then Write Data(T) else Write “empty Tree” 2. [process the left subtree]
Trees and Graphs CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
1 Trees What is a Tree? Tree terminology Why trees? What is a general tree? Implementing trees Binary trees Binary tree implementation Application of Binary.
Question 4 Tutorial 8. Part A Insert 20, 10, 15, 5,7, 30, 25, 18, 37, 12 and 40 in sequence into an empty binary tree
Index construction: Compression of postings
Analysis of Algorithms
Red-Black Trees v z Red-Black Trees Red-Black Trees
Succinct Data Structures
Recursive Objects (Part 4)
Binary search tree. Removing a node
CISC220 Fall 2009 James Atlas Lecture 13: Binary Trees.
Problems with Linked List (as we’ve seen so far…)
AVL Tree.
Paolo Ferragina Dipartimento di Informatica, Università di Pisa
Section 8.1 Trees.
Insert in amortized cost O(1), Merge in O(lgn) DeleteMax in O(lgn)
Lecture 25 Splay Tree Chapter 10 of textbook
Binomial Heaps Chapter 19.
Data Structures Lecture 27 Sohail Aslam.
Red-Black Trees v z /20/2018 7:59 AM Red-Black Trees
Red-Black Trees v z Red-Black Trees Red-Black Trees
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Lecture 29 Heaps Chapter 12 of textbook Concept of heaps Binary heaps
CS 583 Analysis of Algorithms
Trees & Forests D. J. Foreman.
Index construction: Compression of postings
Forests D. J. Foreman.
Trees (Part 1, Theoretical)
CS 583 Analysis of Algorithms
Red-Black Trees v z /17/2019 4:20 PM Red-Black Trees
Lecture 36 Section 12.2 Mon, Apr 23, 2007
CS 583 Analysis of Algorithms
Trees Addenda.
21장. Fibonacci Heaps 숭실대학교 인공지능 연구실 석사 2학기 김완섭.
Solution for Section Worksheet 4, #7b & #7c
Index construction: Compression of postings
Tree.
Index construction: Compression of postings
Paolo Ferragina Dipartimento di Informatica, Università di Pisa
Chapter 20: Binary Trees.
Succinct Data Structures
Tree and its terminologies
Red-Black Trees v z /6/ :10 PM Red-Black Trees
Presentation transcript:

Paolo Ferragina Dipartimento di Informatica, Università di Pisa Representing Trees Paolo Ferragina Dipartimento di Informatica, Università di Pisa Paolo Ferragina, Università di Pisa

Standard representation Binary tree: each node has two pointers to its left and right children An n-node tree takes 2n pointers or 2n lg n bits. Supports finding left child or right child of a node (in constant time). For each extra operation (eg. parent, subtree size) we have to pay additional n lg n bits each. x x x x x x x x x

Can we improve the space bound? There are less than 22n distinct binary trees on n nodes. 2n bits are enough to distinguish between any two different binary trees. Can we represent an n node binary tree using 2n bits?

Binary tree representation A binary tree on n nodes can be represented using 2n+o(n) bits to support: parent left child right child in constant time.

Heap-like notation for a binary tree 1 Add external nodes 1 1 Label internal nodes with a 1 and external nodes with a 0 1 1 1 1 1 Write the labels in level order 1 1 1 1 0 1 1 0 1 0 0 1 0 0 0 0 0 One can reconstruct the tree from this sequence An n node binary tree can be represented in 2n+1 bits. What about the operations?

Heap-like notation for a binary tree 1 x  x: # 1’s up to x (Rank1(x)) x  x: position of x-th 1 (Select1(x)) 1 2 3 2 3 4 5 6 7 Let x be an internal node: left child(x) = On green(2x) right child(x) = On green(2x+1) If bit is 0 then pointer is NULL 4 5 6 12 8 9 10 11 13 7 8 Let x be an internal node or a leaf: - parent(x) = On red (⌊x/2⌋) 14 15 16 17 1 2 3 4 5 6 7 8 1 1 1 1 0 1 1 0 1 0 0 1 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Arbitrary fan-out A rooted ordered tree (on n nodes, arbitrary fan-out): Navigational operations: - parent(x) = a - first child(x) = b - next sibling(x) = c Other useful operations: - degree(x) = 2 - subtree size(x) = 4 a x c b

Level-order degree sequence (LOUDS) 3 Write the degree sequence in level order 3 2 0 3 0 1 0 2 0 0 0 0 2 3 But, this still requires n lg n bits 1 2 Solution: write them in unary 3 2 0 3 0 1 0 2 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 0 Takes 2n-1 bits (every node is represented twice, as 0 and as 1, except the root represented only as 0) A tree is uniquely determined by its degree sequence

Supporting operations Add a dummy root so that each node has a corresponding 1 1 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 1 Node k corresponds to the k-th 1 in the sequence Children of k correspond to the 1s following the k-th 0 3 4 2 First_child(k): y=Select_0(k)+1 if B[y] = 0 then leaf else return y-k [i.e. #1 up to y] Next sibling(k) = k+1 if B[Select_1(k)+1] ≠ 0 Parent(k) = # 0’s up to the k-th 1 7 9 5 6 8 degree(k) = Select_0(k+1) – First_child(k) In 2n+o(n) bits and constant time per ops. No support for subtree size. 10 11 12