Блог пользователя uttom

Автор uttom, история, 10 лет назад, По-английски

For preprocessing in segment tree and sparse table Both takes O(nlogn) times. And in every query both takes O(log(n)) times. But How sparse Table faster than Segment tree? Thanks in Advance.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Segment tree's preprocessing takes O(N) and sparse table's query takes O(1).

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Lets show them with <preprocess , query , update an element>.

sparse table <O(nlgn) , O(1) , O(nlgn)>

segment tree <O(n) , O(lgn) , O(lgn) >

Here you can find something more!

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    How, is querying sparse tabke O(1) ? . Let's say I want to query a interval of length n. Then, the number of operations I would have to do will be equal to number of set bits in n right ? In worst case, the number of set bits in n could be log(n)

    • »
      »
      »
      10 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +5 Проголосовать: не нравится

      Let's t[d][i] minimum in range [i; i+2d). Query in range l, r find minimum. Take maximal d that 2d  ≤  r - l + 1. Answer will be minimum t[d][l] and t[d][r - 2d + 1].