-
-
Notifications
You must be signed in to change notification settings - Fork 48.8k
Add advanced algorithms implementation #13505
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
Add advanced algorithms implementation #13505
Conversation
- Add Fast Fourier Transform (FFT) using Cooley-Tukey algorithm - Supports forward and inverse FFT - Includes magnitude/phase extraction and frequency bin generation - Complete with visualization examples - Add Bloom Filter implementation - Space-efficient probabilistic data structure - Configurable false positive rate - Includes Counting Bloom Filter for deletion support - Comprehensive examples and testing - Add Fenwick Tree (Binary Indexed Tree) - Efficient range sum queries and updates - 1D and 2D implementations - O(log n) time complexity for operations - Complete with range query examples - Add Segment Tree implementation - Range queries and updates - Lazy propagation for efficient range updates - Min/Max segment tree variants - Comprehensive examples and testing - Add Advanced Trie (Prefix Tree) - Full-featured trie with autocomplete - Pattern matching with wildcards - Longest common prefix functionality - Compressed trie for memory efficiency - Complete with all operations and examples All implementations include: - Comprehensive documentation - Type hints and examples - Error handling - Performance analysis - Test cases and usage examples
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.
size: Number of words in the trie | ||
""" | ||
|
||
def __init__(self): |
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:
data_structures/advanced_trie.py
Outdated
node.prefix_count -= 1 | ||
return len(node.children) == 0 and not node.is_end_of_word | ||
|
||
def _find_node(self, word: str) -> Optional[TrieNode]: |
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/advanced_trie.py
, please provide doctest for the function _find_node
self.tree[right_child] | ||
) | ||
|
||
def query(self, left: int, right: 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/segment_tree.py
, please provide doctest for the function query
data_structures/segment_tree.py
Outdated
class MinSegmentTree(SegmentTree): | ||
"""Segment Tree for range minimum queries.""" | ||
|
||
def __init__(self, data: List[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.
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:
for more information, see https://pre-commit.ci
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.
""" | ||
return self.get_all_words_with_prefix("") | ||
|
||
def clear(self) -> None: |
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/advanced_trie.py
, please provide doctest for the function clear
self.tree[left_child], self.tree[right_child] | ||
) | ||
|
||
def _push_lazy(self, node: int, start: int, end: int) -> None: |
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/segment_tree.py
, please provide doctest for the function _push_lazy
|
||
self.tree[node] = self.operation(self.tree[left_child], self.tree[right_child]) | ||
|
||
def query(self, left: int, right: 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/segment_tree.py
, please provide doctest for the function query
|
||
return self._query(0, 0, self.size - 1, left, right) | ||
|
||
def _query(self, node: int, start: int, end: int, left: int, right: 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/segment_tree.py
, please provide doctest for the function _query
for more information, see https://pre-commit.ci
- Fix advanced_trie.py: - Replace deprecated typing.List/Dict/Set with built-in list/dict/set - Replace Optional[T] with T | None syntax - Remove unused imports (Set, re) - Fix line length issues - Convert else-if chains to elif - Remove f-string prefixes where no placeholders - Fix unused variable by prefixing with underscore - Fix bloom_filter.py: - Replace deprecated typing.List with built-in list - Replace Union[T, U] with T | U syntax - Remove unnecessary int() casting around math.ceil() - Remove f-string prefixes where no placeholders - Fix fenwick_tree.py: - Replace deprecated typing.List with built-in list - Fix exception f-string issues by assigning to variables first - Remove f-string prefixes where no placeholders - Fix segment_tree.py: - Replace deprecated typing.List with built-in list - Import Callable from collections.abc instead of typing - Fix Optional type annotations - Fix exception f-string issues by assigning to variables first - Remove f-string prefixes where no placeholders - Fix fft_cooley_tukey.py: - Replace deprecated typing.List/Tuple with built-in list/tuple - Fix long line by breaking into multiple lines - Remove unused typing.Optional import All files now pass ruff linting checks and follow modern Python type annotation standards.
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.
for more information, see https://pre-commit.ci
- Add doctests to advanced_trie.py: - _pattern_search_helper: Demonstrates pattern matching with wildcards - clear: Shows trie clearing functionality - Add doctests to segment_tree.py: - _build: Shows recursive tree building process - _push_lazy: Demonstrates lazy propagation mechanism - range_update: Shows range update functionality - query (LazySegmentTree): Shows range query functionality - _query: Shows internal query mechanism All doctests include: - Clear parameter descriptions - Working examples that demonstrate functionality - Proper return value documentation - Edge case coverage where applicable This addresses all remaining algorithms-keeper bot review comments for missing doctests on internal and public methods.
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.
size: Number of words in the trie | ||
""" | ||
|
||
def __init__(self): |
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:
self.root = TrieNode() | ||
self.size = 0 | ||
|
||
def __len__(self) -> 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/advanced_trie.py
, please provide doctest for the function __len__
""" | ||
self.data = data.copy() | ||
self.size = len(data) | ||
self.operation = operation or (lambda x, y: x + y) |
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 descriptive name for the parameter: x
Please provide descriptive name for the parameter: y
- Lazy propagation for efficient range updates | ||
""" | ||
|
||
def __init__( |
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:
for more information, see https://pre-commit.ci
Add Fast Fourier Transform (FFT) using Cooley-Tukey algorithm
Add Bloom Filter implementation
Add Fenwick Tree (Binary Indexed Tree)
Add Segment Tree implementation
Add Advanced Trie (Prefix Tree)
All implementations include:
Describe your change:
Checklist: