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

Problem on article Segment Tree #1276

Open
Blume-Piyush opened this issue May 14, 2024 · 1 comment
Open

Problem on article Segment Tree #1276

Blume-Piyush opened this issue May 14, 2024 · 1 comment

Comments

@Blume-Piyush
Copy link

Blume-Piyush commented May 14, 2024

Article: Segment Tree

Problem:
The article states that Maximum number of nodes a segment tree would have is 4N, but if you look at the equation, maximum number of nodes a segment tree would have is 2N - 1.

@Bhaskar1312
Copy link

Say your array has a size of N = 2^k+1 for which you want to find the sum of elements [l, r] where 0<=l,r<=N-1
Now in the segment tree, the number fo leaf nodes has to be 2^(k+1) (rounded up by two factor) and
since the leaf nodes are 2^(k+1), the total number of nodes would be 2^(k+2) ~ 4N

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

No branches or pull requests

2 participants