Presentation on theme: "Succinct Data Structures for Permutations, Functions and Suffix Arrays"— Presentation transcript:
1Succinct Data Structures for Permutations, Functions and Suffix Arrays Ian MunroUniversity of WaterlooJoint work with F. Fich, M. He, J. Horton, A. López-Ortiz, S. Srinivasa Rao, Rajeev Raman, Venkatesh RamanHow do we encode a permutation orgeneralization … function orspecialization … suffix arrayin a small amount of spaceand still perform queries in constant time ???
2Permutations: a Shortcut Notation Let P be a simple array giving π; P[i] = π[i]Also have B[i] be a pointer t positions back in (the cycle of) the permutation;B[i]= π-t[i] .. But only define B for every tth position in cycle. (t is a constant; ignore cycle length “round-off”)So array representationP = [ x x 3 x 2 x 10 1]245131831210
3Representing Shortcuts In a cycle there is a B every t positions …But these positions can be in arbitrary orderWhich i’s have a B, and how do we store it?Keep a vector of all positions0 indicates no B 1 indicates a BRank gives the position of B[“i”] in B arraySo: π(i) and π -1(i) in O(1) time & (1+ε)n lg n bitsTheorem: Under a pointer machine model with space (1+ ε) n references, we need time 1/ε to answer π and π -1 queries; i.e. this is as good as it gets.
4Getting n lg n Bits: an Aside This is the best we can do for O(1) operationsBut using Benes networks:1-Benes network is a 2 input/2 output switchr+1-Benes network … join tops to tops1234567835781642R-Benes NetworkR-Benes Network
6What can we do with it?Divide into blocks of lg lg n gates … encode their actions in a word. Taking advantage of regularity of address mechanismand alsoModify approach to avoid power of 2 issueCan trace a path in time O(lg n/(lg lg n)This is the best time we are able get for π and π-1 in minimum space.Observe: This method “violates” the pointer machine lower bound by using “micropointers”.
7Back to the main track: Powers of π Consider the cycles of π( )( )( )Keep a bit vector to indicate the start of each cycle( )Ignoring parentheses, view as new permutation, ψ.Note: ψ-1(i) is position containing i …So we have ψ and ψ-1 as beforeUse ψ-1(i) to find i, then bit vector (rank, select) to find πk or π-k
8Functions Now consider arbitrary functions [n]→[n] “A function is just a hairy permutation”All tree edges lead to a cycle
9Challenges hereEssentially write down the components in a convenient order and use the n lg n bits to describe the mapping (as per permutations)To get fk(i):Find the level ancestor (k levels up) in a treeOrGo up to root and apply f the remaining number of steps around a cycle
10Level Ancestors There are several level ancestor techniques using O(1) time and O(n) WORDS.Adapt Bender & Farach-Colton to work in O(n) bitsBut going the other way …
11f-k is a set Moving Down the tree requires care f-3( ) = ( ) The trick:Report all nodes on a given level of a tree in time proportional to the number of nodes, andDon’t waste time on trees with no answers
12Final Function Result Given an arbitrary function f: [n]→[n] With an n lg n + O(n) bit representation we can compute fk(i) in O(1) time and f-k(i) in time O(1 + size of answer).
13Back to Text … And Suffix Arrays Text T[1..n] over (a,b)*# (a<#<b)There are 2n-1 such texts, which of the n! suffix arrays are valid?SA=isa b b a a b a #SA-1=M= isn’t ..why?
14Ascending to Max M is a permutation so M-1 is its inverse i.e. M-1[i] says where i is in MAscending-to-Max: 1 i n-2M-1[i] < M-1[n] and M-1[i+1] < M-1[n] M-1[i] < M-1[i+1]M-1[i] > M-1[n] and M-1[i+1] > M-1[n] M-1[i] > M-1[i+1]OKNO
15Non-Nesting Non-Nesting: 1 i,j n-1 and M-1[i]<M-1[j] M-1[i] < M-1[i+1] and M-1[j] < M-1[j+1] M-1[i+1] < M-1[j+1]M-1[i] > M-1[i+1] and M-1[j] > M-1[j+1] M-1[i+1] < M-1[j+1]OKNO
16Characterization Theorem for Suffix Arrays on Binary Texts Theorem: Ascending to Max & Non-nesting Suffix ArrayCorollary: Clean method of breaking SA into segmentsCorollary: Linear time algorithm to check whether SA is valid
17Cardinality Queries T= a b a a a b b a a a b a a b b # Remember lengths longest run of a’s and of b’sSA (broken by runs, but not stored explicitly)8 3 | | |16 | |6 14Ba, bit vector .. If SA-1[i-1] in an “a” section store 1 in Ba,[SA-1[i]], else 0BaCreate rank structure on Ba, and similarly Bb, (Note these are reversed except at #)Algorithm Count(T,P)s ← 1; e ←n; i ← m;while i>0 and se doif P[i[=a thens← rank1(Ba,s-1)+1; e←rank1(Ba,e)elses← na rank1(Bb,s-1); e←na + 1 +rank1(Bb,e)i ← i-1Return max(e-s+1,0)Time: O(length of query)
18Listing Queries Complex methods Key idea: for queries of length at least d, index every dth position .. For T and forT(reversed)So we have matches for T[i..n] and T[1,i-1]View these as points in 2 space (Ferragina & Manzini and Grossi & Vitter)Do a range query (Alstrup et al)Variety of results follow
19General ConclusionInteresting, and useful, combinatorial objects can be:Stored succinctly … O(lower bound) +o()So thatNatural queries are performed in O(1) time (or at least very close)This can make the difference between using them and not …