Comparing Data Structure

Computer Science Level pending

Both the Sparse Table and Segment Tree are data structures that can answer the Range Minimum Query. It's not right to say that which is definitely better than the other because it depends on the circumstances.

Let the number of elements be n n and the number of queries be q q . Given that that q > > n q >> n , which data structure should we apply?

Segment Tree Both performs equally well Sparse Table

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Christopher Boo
Jun 9, 2016

The time complexity for a Sparse Table and Segment Tree is O ( n lg n + q ) O(n\lg n + q) and O ( n + q lg n ) O(n+q\lg n) respectively. Both runtime increases linearly as q q increases, but for Segment Tree there is a lg n \lg n factor. Since q q is significantly larger than n n , the construction time could be neglected, hence Sparse Table will work better.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...