storage time in segment tree

484 Views Asked by At

I want to know how many nodes are there in a segment tree made for solving range minimum query problem.

Also, how much time does the build operation take and why?

2

There are 2 best solutions below

0
On

Segment Tree Complexity:

  1. Initialization one by one elements: O(NLogN)
  2. Initialization from array: O(N)
  3. Query range: O(logN)
  4. Insert(Update) element: O(logN)
1
On

if u use segment tree, build is O(nlgn), each query is O(lgn)

if the array is static, u can also try another algorithm RMQ. build time is O(nlgn) and each query is only O(1).