mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 17:34:49 +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
@ -6,6 +6,7 @@ elements whose sum is equal to req_sum.
|
||||
|
||||
https://practice.geeksforgeeks.org/problems/count-pairs-with-given-sum5022/0
|
||||
"""
|
||||
|
||||
from itertools import combinations
|
||||
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
"""
|
||||
Sparse table is a data structure that allows answering range queries on
|
||||
a static number list, i.e. the elements do not change throughout all the queries.
|
||||
Sparse table is a data structure that allows answering range queries on
|
||||
a static number list, i.e. the elements do not change throughout all the queries.
|
||||
|
||||
The implementation below will solve the problem of Range Minimum Query:
|
||||
Finding the minimum value of a subset [L..R] of a static number list.
|
||||
The implementation below will solve the problem of Range Minimum Query:
|
||||
Finding the minimum value of a subset [L..R] of a static number list.
|
||||
|
||||
Overall time complexity: O(nlogn)
|
||||
Overall space complexity: O(nlogn)
|
||||
Overall time complexity: O(nlogn)
|
||||
Overall space complexity: O(nlogn)
|
||||
|
||||
Wikipedia link: https://en.wikipedia.org/wiki/Range_minimum_query
|
||||
Wikipedia link: https://en.wikipedia.org/wiki/Range_minimum_query
|
||||
"""
|
||||
|
||||
from math import log2
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ Please do not modify this file! It is published at https://norvig.com/sudoku.ht
|
||||
only minimal changes to work with modern versions of Python. If you have improvements,
|
||||
please make them in a separate file.
|
||||
"""
|
||||
|
||||
import random
|
||||
import time
|
||||
|
||||
|
@ -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]
|
||||
|
@ -1,6 +1,6 @@
|
||||
"""
|
||||
Disjoint set.
|
||||
Reference: https://en.wikipedia.org/wiki/Disjoint-set_data_structure
|
||||
Disjoint set.
|
||||
Reference: https://en.wikipedia.org/wiki/Disjoint-set_data_structure
|
||||
"""
|
||||
|
||||
|
||||
|
@ -58,6 +58,7 @@ The probability decreases with the number of bits in the bitarray.
|
||||
>>> bloom.bitstring
|
||||
'01100101'
|
||||
"""
|
||||
|
||||
from hashlib import md5, sha256
|
||||
|
||||
HASH_FUNCTIONS = (sha256, md5)
|
||||
|
@ -11,6 +11,7 @@ Where hash1() and hash2() are hash functions and TABLE_SIZE is size of hash tabl
|
||||
|
||||
Reference: https://en.wikipedia.org/wiki/Double_hashing
|
||||
"""
|
||||
|
||||
from .hash_table import HashTable
|
||||
from .number_theory.prime_numbers import is_prime, next_prime
|
||||
|
||||
|
@ -7,6 +7,7 @@ Another hash map implementation, with a good explanation.
|
||||
Modern Dictionaries by Raymond Hettinger
|
||||
https://www.youtube.com/watch?v=p33CVV29OG8
|
||||
"""
|
||||
|
||||
from collections.abc import Iterator, MutableMapping
|
||||
from dataclasses import dataclass
|
||||
from typing import Generic, TypeVar
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
module to operations with prime numbers
|
||||
module to operations with prime numbers
|
||||
"""
|
||||
|
||||
import math
|
||||
|
@ -5,6 +5,7 @@ Nodes contain data and also may link to other nodes:
|
||||
head node gives us access of the complete list
|
||||
- Last node: points to null
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Algorithm that merges two sorted linked lists into one sorted linked list.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable, Iterator
|
||||
|
@ -2,6 +2,7 @@
|
||||
Based on "Skip Lists: A Probabilistic Alternative to Balanced Trees" by William Pugh
|
||||
https://epaperpress.com/sortsearch/download/skiplist.pdf
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from random import random
|
||||
|
@ -1,6 +1,7 @@
|
||||
"""
|
||||
Implementation of double ended queue.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterable
|
||||
|
@ -1,4 +1,5 @@
|
||||
""" A Queue using a linked list like structure """
|
||||
"""A Queue using a linked list like structure"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""Queue represented by a pseudo stack (represented by a list with pop and append)"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@ RULE 5: When the entire infix expression has been scanned, the value left on
|
||||
|
||||
NOTE: It only works with whole numbers.
|
||||
"""
|
||||
|
||||
__author__ = "Alexander Joslin"
|
||||
|
||||
import operator as op
|
||||
|
@ -1,4 +1,5 @@
|
||||
""" A Stack using a linked list like structure """
|
||||
"""A Stack using a linked list like structure"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Iterator
|
||||
|
Reference in New Issue
Block a user