Skip to content

Add "build" function to segment_tree.md #1213

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

Merged
merged 1 commit into from
Jan 28, 2024

Conversation

akoutian
Copy link
Contributor

Ensure that each node stores the maximum of its children. Otherwise the results of any query will be wrong, unless this node has been visited by an "update" query previously.

@mhayter
Copy link
Contributor

mhayter commented Dec 21, 2023

I'm confused on what you're suggesting. The code is for range update point query. Each query goes down the entire tree. The query is a sum query. Have you tested this? Does it not work? I'm on my phone but it looks right to me.

@akoutian
Copy link
Contributor Author

What I'm suggesting is a "build" function that works for range update/maximum query, since there isn't one in the code. You're right, for point query this wouldn't work. What I wrote should go in the section below, "Adding on segments, querying for maximum"

Previously, there was no function explaining how to build the tree for
the case of range update/maximum query.
@akoutian akoutian changed the title Fix "build" function in segment_tree.md Add "build" function to segment_tree.md Dec 21, 2023
@akoutian
Copy link
Contributor Author

Changed commit message and title to better reflect the proposed change.

@adamant-pwn
Copy link
Member

Hi, thanks for the pull request! Have you tested this implementation against any existing problem?

@akoutian
Copy link
Contributor Author

akoutian commented Jan 4, 2024

Hello and happy new year!
I have implemented the algorithm along with unit tests here:
https://github.com/akoutian/algs/tree/master/src/algs/segtree

The unit tests check for correctness against various inputs.

Copy link
Member

@jakobkogler jakobkogler left a comment

Choose a reason for hiding this comment

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

Looks good.

@jakobkogler jakobkogler merged commit 1af10d5 into cp-algorithms:master Jan 28, 2024
@akoutian akoutian deleted the patch-1 branch January 29, 2024 14:59
@akoutian
Copy link
Contributor Author

Cheers!

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.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy