slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Speaker: 吳展碩 PowerPoint Presentation
Download Presentation
Speaker: 吳展碩

Loading in 2 Seconds...

play fullscreen
1 / 13

Speaker: 吳展碩 - PowerPoint PPT Presentation


  • 124 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Speaker: 吳展碩' - diana-schultz


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

The LCA Problem RevisitedMichael A. Bender Martin Farach-ColtonLatin American Theoretical Informatics Symposium, pages 88—94, 2000.

Speaker: 吳展碩

introduction
Introduction
  • Lowest Common Ancestor
  • After a O(n) time preprocessing, any LCA query can then be answered in O(1) time.
outline
Outline
  • Range Minimum Query (RMQ) Problem
  • Reduce LCA to 1RMQ
  • An Algorithm for 1RMQ
rmq problem
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.

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

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

an o n log n preprocessing for rmq
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))
constant time rmq
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

an o n preprocessing for 1rmq
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

how to compute rmq i j
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

an o n preprocessing for 1rmq1
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).
slide12

i

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