pydatastructs icon indicating copy to clipboard operation
pydatastructs copied to clipboard

Add Segment Trees

Open czgdp1807 opened this issue 5 years ago • 10 comments

Description of the problem

Add segment trees to pydatastructs.trees.space_partitioning_trees.

Example of the problem

References/Other comments

Use, https://en.wikipedia.org/wiki/Segment_tree

czgdp1807 avatar Jun 20 '19 07:06 czgdp1807

I am working on it.

czgdp1807 avatar Jun 20 '19 07:06 czgdp1807

Can we also add update operation? As I think this is the most necessary feature for which segment tree is used as it can update the interval list in O(logN) time. That is segment tree are generally used to solve online problems (real time update and queries). Moreover, without this update operation, quering on just given set of segments there exits O(1) technique(using prefix sums which build in O(MAXN) and each query in O(1))

Smit-create avatar Mar 11 '21 05:03 Smit-create

It is, in principle, a static structure; that is, it's a structure that cannot be modified once it's built. A similar data structure is the interval tree.

From wikipedia. So, for dynamic segment trees we should subclass SegmentTree in DynamicSegmentTree and add an update method to it. Another question is how will the algorithm for updating segment tree will work, especially the ones defined here.

czgdp1807 avatar Mar 11 '21 05:03 czgdp1807

Can I work on this issue?

aman503 avatar Mar 23 '21 05:03 aman503

I can work on the issue.. I have so many templates..you can check in my GitHub..C++ -> Python I will do the implementation and conversion..

Rajveer100 avatar Feb 22 '22 12:02 Rajveer100

Sure. Please read the above comments before starting.

czgdp1807 avatar Feb 23 '22 07:02 czgdp1807

Hello @czgdp1807,

I have completed the implementation of Segment Tree with rangeQuery, rangeUpdate, pointUpdate, and all operations in O(log(n)) time...Here is my code...

Many more things like min, max, gcd, etc can be added just by changing the default values to respective ones..which I will make it in the template itself for ease of use...

This was to just update you..that most part is finished..Just need your suggestions and recommendations..Thank You.

(Also, forgot to mention, I am taking part in GSSOC 2022...as well..) 👍

Here is my code :

It is committed under the branch "origin_user"..and have also done the PR...Waiting for your approval...

Rajveer100 avatar Feb 26 '22 08:02 Rajveer100

Could you please checkout the above message so that I can make the changes if required...Thank you...

Rajveer100 avatar Mar 02 '22 05:03 Rajveer100

@Rajveer100 Please feel free to open a PR. I will review there. Thanks.

czgdp1807 avatar Mar 02 '22 07:03 czgdp1807

Yes I have already done the PR(483)..Thank you so much for your reply..

Rajveer100 avatar Mar 02 '22 09:03 Rajveer100