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

segment trees questions added #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Manish2397
Copy link

Segment trees tutorial with question added.

@papachristoumarios
Copy link
Member

Hello @Manish2397,

This seems to be code for segment trees. Your PR is labeled as questions for segment trees.
Also consider formatting your code well and adding testcases to it.

@mstou
Copy link
Member

mstou commented Sep 27, 2019

Hello @Manish2397 , thanks for contributing. Can you please move the Segment tree folder to Data Structures/ Advanced DS/ Segment Trees instead of the root folder so as to follow the structure described in README?

We would also like you to provide a more thorough documentation of the code, as also indicated by @papachristoumarios.

Lastly, instead of implementing 2 segment trees (one for min/max querries and one for range sum querries) you could implement 1 generic segment tree that works with a function f (int f(int x, int y)). In the first case f would be int f(int x, int y){ return min(x,y); } and in the range sum segment tree it would be: int f(int x, int y){ return x+y; }

//right subTree
buildSegmentTree(tree,values,2*index+1,mid+1,end);

tree[index] = tree[2*index]+tree[2*index+1];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, in the generic segment tree described in my comment, line 22 would be:
tree[index] = f( tree[2*index], tree[2*index+1] );

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

Successfully merging this pull request may close these issues.

None yet

3 participants