Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Segment Trees #6

Open
czgdp1807 opened this issue Jun 20, 2019 · 10 comments · Fixed by #10
Open

Add Segment Trees #6

czgdp1807 opened this issue Jun 20, 2019 · 10 comments · Fixed by #10
Assignees
Labels

Comments

@czgdp1807
Copy link
Member

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 czgdp1807 self-assigned this Jun 20, 2019
@czgdp1807
Copy link
Member Author

I am working on it.

@Smit-create
Copy link
Member

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

@czgdp1807
Copy link
Member Author

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 czgdp1807 reopened this Mar 11, 2021
@aman503
Copy link

aman503 commented Mar 23, 2021

Can I work on this issue?

@Rajveer100
Copy link
Contributor

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

@czgdp1807
Copy link
Member Author

Sure. Please read the above comments before starting.

@Rajveer100
Copy link
Contributor

Rajveer100 commented Feb 26, 2022

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
Copy link
Contributor

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

@czgdp1807
Copy link
Member Author

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

@Rajveer100
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants