MIT6_851S10_assn04_sol

# MIT6_851S10_assn04_sol - many of the characters match....

This preview shows pages 1–2. Sign up to view the full content.

. + ). 6.851 Advanced Data Structures (Spring’10) Prof. Erik Demaine Dr. Andr´ e Schulz TA: Aleksandar Zlateski Problem 4 Sample Solutions Analyzing Partition Trees. Let r be the upper bound of 2( c 2) 1 Out of r partitions at most c r of them will cross a line. Therefore we get: T ( n ) O ( r ) + c rT (2 n/r ) 1 2 Solving the equation using the Master Theorem, we get T ( n ) Θ( n Speed Up With LCP Array. Finding the LCP for SA [ i ] and SA [ i + 1] breaks down into three cases. First case when SA [ i ] and SA [ i +1] are both from T 0 T 1 . Then we can calculate their LCP by looking up their locations in the SA for T ˜ , and getting the RMQ in the LCP array for T ˜ . When SA [ i ] and SA [ i + 1] are both from T 0 T 2 we compare the ±rst character of both strings. If they are diﬀerent, we know that the LCP is 0, otherwise, the LCP is 1 plus the LCP of the two strings without their ±rst characters. Finally if SA [ i ] and SA [ i + 1] are both from T 1 T 2 we comparse the ±rst two characters of both strings. If they diﬀer in some way, we can set the LCP to either 0 or 1, depending on how

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: many of the characters match. Otherwise, we proceed as in the previous case. The rst two cases take O(1) plus the time for the recursion. For the third case, when comparing equal characters L s is increased by one. The total number of comparisons if equal chars cant be larger than | P | . The number of other comparisons in the last case is O (1) per level of recursion. Hence the running time of O ( | P | + log | T | ) 1 MIT OpenCourseWare http://ocw.mit.edu 6.851 Advanced Data Structures Spring 2010 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms ....
View Full Document

## This note was uploaded on 03/31/2011 for the course EECS 6.851 taught by Professor Erikdemaine during the Spring '10 term at MIT.

### Page1 / 2

MIT6_851S10_assn04_sol - many of the characters match....

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online