1 / 13

Speaker: 吳展碩

The LCA Problem Revisited Michael A. Bender Martin Farach-Colton Latin American Theoretical Informatics Symposium , pages 88—94, 2000. Speaker: 吳展碩. Introduction. L owest C ommon A ncestor After a O ( n ) time preprocessing , any LCA query can then be answered in O (1) time. Outline.

Download Presentation

Speaker: 吳展碩

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The LCA Problem RevisitedMichael A. Bender Martin Farach-ColtonLatin American Theoretical Informatics Symposium, pages 88—94, 2000. Speaker: 吳展碩

  2. Introduction • Lowest Common Ancestor • After a O(n) time preprocessing, any LCA query can then be answered in O(1) time.

  3. Outline • Range Minimum Query (RMQ) Problem • Reduce LCA to 1RMQ • An Algorithm for 1RMQ

  4. RMQ Problem Structure to Preprocess: An array A of numbers. Query: RMQ(i, j) returns the index of the smallest element in the subarray A[i...j]. RMQ(4, 8) = 5.

  5. 1RMQ Problem • A restricted case of RMQ such that all adjacent elements in the array A differ by +1 or -1. • Example:

  6. 1 2 2 3 3 3 3 3 4 4 Reduce LCA to 1RMQ • Compute the level array while visiting the tree in an Euler Tour. Level 1 Level 2 Level 3 Level 4

  7. An O(nlogn) Preprocessing for RMQ • An O(n2) brute-force preprocessing: • precompute every query RMQ(i, j) • An O(nlogn) preprocessing: • only precompute the queries whose length is a power of 2 (there are nlogn such queries at most) • the preprocessing table can be computed in O(nlogn) by using dynamic programming. • RMQ(i, j) = min(RMQ(i, (j-i+1)/2), RMQ((j-i+1)/2+1, j))

  8. Constant Time RMQ • RMQ(i, j) is the minima of the two blocks (one start at i and one end at j) covering the range [i, ...,j]. i j

  9. An O(n) Preprocessing for 1RMQ • Partition A into blocks of size ½logn • Define an array A’[1, ..., n/½logn], where A’[k] is the minimum element in the kth block of A. The RMQ preprocessing of A’ spends O(n/½logn x log(n/½logn)) = O(n) time and space. n ½logn

  10. How to compute RMQ(i, j)? • The answer is minimum of min(R1): The minimum from i forward to the end of its block. min(R2): The minimum of all the blocks in between i’s block and j’s block. min(R3): The minimum from the beginning of j’s block to j. • The preprocessing of A’ can be used to compute min(R2). • How to compute min(R1) and min(R3)? 1 2 3 ½logn

  11. An O(n) Preprocessing for 1RMQ • Normalize each block of length ½logn to a binary string of length ½logn-1 Ex: 5676545 => 110001 • If two blocks normalize to the same binary string, the RMQ answers of these two blocks will be the same. • There are only O(n) kinds of normalized blocks. There are only 2(½logn)-1 = O(n) kinds of binary strings of length (½logn)-1. (Example) • The total preprocessing time for all normalized block is O(nlognloglogn) = O(n).

  12. i • There are logn such queries started at position i at most.

More Related