1

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?

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
vishalgoel
  • 69
  • 4

2 Answers2

0

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).

songlj
  • 927
  • 1
  • 6
  • 10
  • why is build time O(nlogn)? According to me, there are 2n-1 nodes in total. take as an e.g. n=16. so node 1 is 1-16, node 2 is 1-8, node 3 is 9-16..as we keep on dividing, we see that there are 2n-1 nodes. and for each node , there is only one comparison done.. so the time is O(2n-1) or O(n). plz explain me how the time is O(nlogn) – vishalgoel Jan 18 '13 at 09:38
0

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)
Толя
  • 2,839
  • 15
  • 23