mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-06 18:49:26 +08:00
[pre-commit.ci] pre-commit autoupdate (#11322)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
![66853113+pre-commit-ci[bot]@users.noreply.github.com](/assets/img/avatar_default.png)
committed by
GitHub

parent
5f95d6f805
commit
bc8df6de31
@ -5,6 +5,7 @@ python3 -m doctest -v avl_tree.py
|
||||
For testing run:
|
||||
python avl_tree.py
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
|
@ -88,6 +88,7 @@ True
|
||||
>>> not t
|
||||
True
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable, Iterator
|
||||
|
@ -7,6 +7,7 @@ python -m unittest binary_search_tree_recursive.py
|
||||
To run an example:
|
||||
python binary_search_tree_recursive.py
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
@ -8,7 +8,6 @@ Python implementation:
|
||||
frames that could be in memory is `n`
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
@ -2,6 +2,7 @@
|
||||
The diameter/width of a tree is defined as the number of nodes on the longest path
|
||||
between two end nodes.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
@ -10,6 +10,7 @@ https://www.geeksforgeeks.org/flatten-a-binary-tree-into-linked-list
|
||||
Author: Arunkumar A
|
||||
Date: 04/09/2023
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ https://bit.ly/46uB0a2
|
||||
Author : Arunkumar
|
||||
Date : 14th October 2023
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
@ -13,6 +13,7 @@ If n is the number of nodes in the tree then:
|
||||
Runtime: O(n)
|
||||
Space: O(1)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
@ -3,6 +3,7 @@ Is a binary tree a sum tree where the value of every non-leaf node is equal to t
|
||||
of the values of its left and right subtrees?
|
||||
https://www.geeksforgeeks.org/check-if-a-given-binary-tree-is-sumtree
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
@ -5,6 +5,7 @@ The rule for merging is that if two nodes overlap, then put the value sum of
|
||||
both nodes to the new value of the merged node. Otherwise, the NOT null node
|
||||
will be used as the node of new tree.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ Given the root of a binary tree, mirror the tree, and return its root.
|
||||
|
||||
Leetcode problem reference: https://leetcode.com/problems/mirror-binary-tree/
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
@ -35,6 +35,7 @@ https://www.geeksforgeeks.org/segment-tree-efficient-implementation/
|
||||
>>> st.query(0, 2)
|
||||
[1, 2, 3]
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
|
@ -6,6 +6,7 @@ We will use the formula: t(n) = SUMMATION(i = 1 to n)t(i-1)t(n-i)
|
||||
|
||||
Further details at Wikipedia: https://en.wikipedia.org/wiki/Catalan_number
|
||||
"""
|
||||
|
||||
"""
|
||||
Our Contribution:
|
||||
Basically we Create the 2 function:
|
||||
|
@ -2,6 +2,7 @@
|
||||
psf/black : true
|
||||
ruff : passed
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
@ -3,6 +3,7 @@ Segment_tree creates a segment tree with a given array and function,
|
||||
allowing queries to be done later in log(N) time
|
||||
function takes 2 values and returns a same type value
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
from queue import Queue
|
||||
|
||||
|
@ -4,6 +4,7 @@ Given the root of a binary tree, check whether it is a mirror of itself
|
||||
|
||||
Leetcode reference: https://leetcode.com/problems/symmetric-tree/
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
@ -7,6 +7,7 @@ such as the with segment trees or fenwick trees. You can read more about them he
|
||||
2. https://www.youtube.com/watch?v=4aSv9PcecDw&t=811s
|
||||
3. https://www.youtube.com/watch?v=CybAgVF-MMc&t=1178s
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
test_array = [2, 1, 4, 5, 6, 0, 8, 9, 1, 2, 0, 6, 4, 2, 0, 6, 5, 3, 2, 7]
|
||||
|
Reference in New Issue
Block a user