Presentation on theme: "Space-Efficient Static Trees and Graphs Guy Jacobson IEEE Symposium on Foundations of Computer Science, 1989 Speaker: 吳展碩."— Presentation transcript:
1 Space-Efficient Static Trees and Graphs Guy Jacobson IEEE Symposium on Foundations of Computer Science, 1989Speaker: 吳展碩
2 A pointer needs lg n bits to address n different locations. 1234567812345678nilA pointer needs lg n bits to address n different locations.Using pointers to represent the linking relation of a graph will therefore occupy (n lg n) bits.
3 Outline To store a binary tree in asymptotically optimal space Represent a tree in O(n) bitsEfficient tree-traversal in space-efficient treesTo store planar graphs in asymptotically optimal space
4 Binary Trees in 2n+1 bits Mark all the nodes of the tree with 1. Add external nodes to the tree, and mark them all with 0.Read off the makes of nodes of the tree in level-order.
5 Binary Trees in 2n+1 bits Mark all the nodes of the tree with 1. Add external nodes to the tree, and mark them all with 0.Read off the makes of nodes of the tree in level-order.
6 How to compute the linking relations in a space-efficient tree?
7 Rank and SelectDefine two operations rank(m) and select(m) as follows:rank(m): Counts the number of 1s from position 1 up to position m in a binary stringselect(m): Finds the m-th 1s in a binary stringExample:rank(10) = 7select(7) = 101234567891011121314151617
9 How to compute rank(m) and select(m) efficiently? (e.g. constant time)
10 Compute Rank(m) and Select(m) The rank directory:Conceptually break the bit-string into blocks of length lg2n. Keep a table containing the number of 1s up to the last position in each block. This takes n / lg n bits.Break each block into sub-blocks of length ½lg n. Keep a table containing the number of 1s within the block up to the last position in each sub-block. This takes n lglg2n / lg n bits.Keep a pre-computed table giving the number of 1s up to every possible position in every possible distinct sub-block.
11 n bits123n/lg2n101100110011001.....11000010101000lg2n375556lg nn / lg n bits½lg nlglg2n2n lglg2n / lg n bits
12 2½lg n ½lg n lg½lg n bits 123n/lg2n101100110011001.....11000010101000lg2n375556lg nn / lg n bits½lg nPrecomputed Table2½lg n ½lg n lg½lg n bitslglg2n2n lglg2n / lg n bits
13 Planar Graphs in O(n) Space Represent a special case of planar graphs called one-page graphs in O(n) bitsk-page graphs can be represented in O(kn) bitsAny planar graph can be embedded in a four-page graph.Yannakakis, M. "Four pages are necessary and sufficient for planar graphs." Proceedings of the 18th ACM Symposium on Theory of Computing, pages , 1986.
14 One-page graph One-page Graph: All edges are lying to one side and can not cross.
15 One-page graph in O(n) Space All edges are lying to one side and can not cross.| ((( | )( | ( | )) | )( | ))
16 How to compute the linking relations in the parenthesis string?
17 Finding the close parenthesis which match the open one First, break the string of parentheses into blocks of length lgn.
18 Definitions Far parenthesis: An open parenthesis p is called a far parenthesis if and only if p's matching parenthesis lies outside its own block.Pioneer:A far parenthesis is a pioneer if and only if its matching parenthesis lies in a different block that of the previous far parenthesis.The number of pioneers is at most 2lgn.Dotted lines denote the matches of far parenthesesRed ones denote the matches of pioneers
19 Use a Directory Structure of Size O(n) bits for Matching Parentheses
24 Conclusion References A space-efficient data structure achieve almost optimal space while supporting the required operations almost as efficient as using pointers to represent it.ReferencesDinesh P. Mehta and Sartaj Sahni. Handbook of Data Structures and Applications. Chapman & Hall/CRC, 2005.