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

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

Guys , in the below TRIE tutorial in problem 2 , he explains a way to find maximum XOR subarray in a given array.But i find that the method illustrated requires O(n^2) operations as N times he queries the Trie each of which takes linear time.How does the solution pass the time limit. Trie Tutorial

Trie Question

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

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

Querying trie works O(log2(val)) because it's length is log2(val), so overall n * log2(max_ai).

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

Fun fact: tries over binary bits of values is actually a segment tree!

Querying the trie is therefore actually just querying a segment tree, O(log_base2(max_value)).