-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
implement segment tree using node (new .py file in data_structures/binary_tree/segment_tree_node.py) #12707
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
@@ -0,0 +1,145 @@ | |||
class Node(): | |||
def __init__(self, start, end): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: start
Please provide type hint for the parameter: end
self.right = None | ||
|
||
class SegmentTree(): | ||
def __init__(self, nums, mode='max'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: __init__
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: nums
Please provide type hint for the parameter: mode
# Build the tree from the input list | ||
self.root = self.build(0, self.size - 1, nums) | ||
|
||
def build(self, start, end, nums): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: build
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function build
Please provide type hint for the parameter: start
Please provide type hint for the parameter: end
Please provide type hint for the parameter: nums
|
||
return root | ||
|
||
def max_in_range(self, start_index, end_index): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: max_in_range
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function max_in_range
Please provide type hint for the parameter: start_index
Please provide type hint for the parameter: end_index
|
||
return self.query(self.root, start_index, end_index, 0, self.size - 1) | ||
|
||
def sum_in_range(self, start_index, end_index): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: sum_in_range
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function sum_in_range
Please provide type hint for the parameter: start_index
Please provide type hint for the parameter: end_index
|
||
return self.query(self.root, start_index, end_index, 0, self.size - 1) | ||
|
||
def query(self, node, start_index, end_index, start, end): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: query
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function query
Please provide type hint for the parameter: node
Please provide type hint for the parameter: start_index
Please provide type hint for the parameter: end_index
Please provide type hint for the parameter: start
Please provide type hint for the parameter: end
else: | ||
return (self.query(node.left, start_index, end_index, start, mid) + self.query(node.right, start_index, end_index, mid + 1, end)) | ||
|
||
def update(self, index, new_value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: update
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function update
Please provide type hint for the parameter: index
Please provide type hint for the parameter: new_value
|
||
self.modify(self.root, index, new_value, 0, self.size - 1) | ||
|
||
def modify(self, node, index, new_value, start, end): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please provide return type hint for the function: modify
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function modify
Please provide type hint for the parameter: node
Please provide type hint for the parameter: index
Please provide type hint for the parameter: new_value
Please provide type hint for the parameter: start
Please provide type hint for the parameter: end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
# Build the tree from the input list | ||
self.root = self.build(0, self.size - 1, nums) | ||
|
||
def build(self, start: int, end: int, nums: list[int]) -> Node: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function build
|
||
return root | ||
|
||
def max_in_range(self, start_index: int, end_index: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function max_in_range
|
||
return self.query(self.root, start_index, end_index, 0, self.size - 1) | ||
|
||
def sum_in_range(self, start_index: int, end_index: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function sum_in_range
|
||
return self.query(self.root, start_index, end_index, 0, self.size - 1) | ||
|
||
def query(self, node: Node, start_index: int, end_index: int, start: int, end: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function query
node.left, start_index, end_index, start, mid | ||
) + self.query(node.right, start_index, end_index, mid + 1, end) | ||
|
||
def update(self, index: int, new_value: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function update
|
||
self.modify(self.root, index, new_value, 0, self.size - 1) | ||
|
||
def modify(self, node: Node, index: int, new_value: int, start: int, end: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function modify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
# Build the tree from the input list | ||
self.root = self.build(0, self.size - 1, nums) | ||
|
||
def build(self, start: int, end: int, nums: list[int]) -> Node: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function build
|
||
return root | ||
|
||
def max_in_range(self, start_index: int, end_index: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function max_in_range
|
||
return self.query(self.root, start_index, end_index, 0, self.size - 1) | ||
|
||
def sum_in_range(self, start_index: int, end_index: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function sum_in_range
|
||
return self.query(self.root, start_index, end_index, 0, self.size - 1) | ||
|
||
def query(self, node: Node, start_index: int, end_index: int, start: int, end: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function query
else: | ||
return self.query(node.left, start_index, end_index, start, mid) + self.query(node.right, start_index, end_index, mid + 1, end) | ||
|
||
def update(self, index: int, new_value: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function update
|
||
self.modify(self.root, index, new_value, 0, self.size - 1) | ||
|
||
def modify(self, node: Node, index: int, new_value: int, start: int, end: int) -> int: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no test file in this pull request nor any test function or class in the file data_structures/binary_tree/segment_tree_node.py
, please provide doctest for the function modify
for more information, see https://pre-commit.ci
Describe your change:
Checklist: