Repository navigation
Description
Student: Raj Manoj Patil
Task: R23-T040 · 10 of 10
Repository: https://github.com/S-AI-Projects/TheAlgorithms-Python
Assigned working branch: student/e26b07f0759
Goal
Contribute a new file in data_structures/binary_tree/ that follows every repository rule. Add a persistent segment tree for range minimum (the existing one is for sums) as a new file, reusing the same versioning idea.
Steps
- Read CONTRIBUTING.md: snake_case file names, type hints, doctests for valid and erroneous input, no new directories.
- Create the new file in data_structures/binary_tree/ as described in the goal, with doctests that also compare against the existing implementation.
- Run
python3 scripts/validate_filenames.py, Ruff and the doctests. - Explain in work/R23-T040/VARIANT.md how your version differs (time/space), with a small timing table.
- Make the code change in the repository: New data_structures/binary_tree/persistent_segment_tree_min.py (persistent range-minimum version) with type hints and doctests – first check segment_tree_other.py and data_structures/arrays/sparse_table.py so it is not a duplicate. Re-run the automated check and the repo's own tests afterwards.
- Prepare the PR: on branch R23-T040, commit the code change plus your work/R23-T040/ evidence, put your findings in the PR description and open the PR against the org fork. For a later upstream PR, create a second branch containing only the code change (no work/ folder).
Done when
☐ New data_structures/binary_tree/persistent_segment_tree_min.py; the PR explains why it is not a duplicate of segment_tree_other.py or sparse_table.py.
☐ Doctests query several versions after updates and check results against min() of the corresponding array.
☐ Full type hints; validate_filenames.py and Ruff pass; VARIANT.md compares it with the sum version.
Additional task guidance
Additional curated task guidance
Item:
data_structures/binary_tree/persistent_segment_tree.py (138 lines; 29 doctests)
Task type:
New sibling algorithm
Code change (goes into the PR):
New data_structures/binary_tree/persistent_segment_tree_min.py (persistent range-minimum version) with type hints and doctests – first check segment_tree_other.py and data_structures/arrays/sparse_table.py so it is not a duplicate.
Automated check:
python3 scripts/validate_filenames.py && uvx ruff check data_structures/binary_tree && uv run pytest data_structures/binary_tree && test -s work/R23-T040/VARIANT.md
Prerequisites:
Linux/WSL2/Codespaces with uv (https://docs.astral.sh/uv/getting-started/installation/); run uv sync --group=test once – it installs the Python version CI uses (.python-version = 3.15t) and the test dependencies, about 1–2 GB
Upstream PR rules:
Follow CONTRIBUTING.md: type hints on every parameter/return, doctests for valid and erroneous input, snake_case file names, no duplicate of an existing implementation, no hand edits to DIRECTORY.md. CI (pytest with doctests, ruff) must pass – bots close PRs without tests or type hints. Keep work/ (benchmarks, notes, property tests) out of the upstream branch; put results in the PR description.
Source (pinned):
https://github.com/TheAlgorithms/Python/blob/574d100b7181956e9c8384552fd078165e4cc326/data_structures/binary_tree/persistent_segment_tree.py
Change:
No change recorded
PR destination:
Preserved pilot guidance
Submission checklist
- Complete this task and its checks.
- Add the required evidence and link your pull request here.
- Select this S-AI-Projects fork as the PR base repository.
- Request instructor review.
Keep this PR focused on this task. Do not submit assignment PRs to the upstream repository.
Activity