[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:
pre-commit-ci[bot]
2024-03-13 07:52:41 +01:00
committed by GitHub
parent 5f95d6f805
commit bc8df6de31
297 changed files with 488 additions and 285 deletions

View File

@@ -10,7 +10,6 @@ Reference: shorturl.at/exHM7
# Author: Swayam Singh (https://github.com/practice404)
from queue import PriorityQueue
from typing import Any

View File

@@ -1,6 +1,7 @@
"""
https://en.wikipedia.org/wiki/Bidirectional_search
"""
from __future__ import annotations
import time

View File

@@ -1,6 +1,7 @@
"""
https://en.wikipedia.org/wiki/Bidirectional_search
"""
from __future__ import annotations
import time

View File

@@ -1,29 +1,30 @@
"""Borůvka's algorithm.
Determines the minimum spanning tree (MST) of a graph using the Borůvka's algorithm.
Borůvka's algorithm is a greedy algorithm for finding a minimum spanning tree in a
connected graph, or a minimum spanning forest if a graph that is not connected.
Determines the minimum spanning tree (MST) of a graph using the Borůvka's algorithm.
Borůvka's algorithm is a greedy algorithm for finding a minimum spanning tree in a
connected graph, or a minimum spanning forest if a graph that is not connected.
The time complexity of this algorithm is O(ELogV), where E represents the number
of edges, while V represents the number of nodes.
O(number_of_edges Log number_of_nodes)
The time complexity of this algorithm is O(ELogV), where E represents the number
of edges, while V represents the number of nodes.
O(number_of_edges Log number_of_nodes)
The space complexity of this algorithm is O(V + E), since we have to keep a couple
of lists whose sizes are equal to the number of nodes, as well as keep all the
edges of a graph inside of the data structure itself.
The space complexity of this algorithm is O(V + E), since we have to keep a couple
of lists whose sizes are equal to the number of nodes, as well as keep all the
edges of a graph inside of the data structure itself.
Borůvka's algorithm gives us pretty much the same result as other MST Algorithms -
they all find the minimum spanning tree, and the time complexity is approximately
the same.
Borůvka's algorithm gives us pretty much the same result as other MST Algorithms -
they all find the minimum spanning tree, and the time complexity is approximately
the same.
One advantage that Borůvka's algorithm has compared to the alternatives is that it
doesn't need to presort the edges or maintain a priority queue in order to find the
minimum spanning tree.
Even though that doesn't help its complexity, since it still passes the edges logE
times, it is a bit simpler to code.
One advantage that Borůvka's algorithm has compared to the alternatives is that it
doesn't need to presort the edges or maintain a priority queue in order to find the
minimum spanning tree.
Even though that doesn't help its complexity, since it still passes the edges logE
times, it is a bit simpler to code.
Details: https://en.wikipedia.org/wiki/Bor%C5%AFvka%27s_algorithm
Details: https://en.wikipedia.org/wiki/Bor%C5%AFvka%27s_algorithm
"""
from __future__ import annotations
from typing import Any

View File

@@ -1,6 +1,7 @@
#!/usr/bin/python
""" Author: OMKAR PATHAK """
"""Author: OMKAR PATHAK"""
from __future__ import annotations
from queue import Queue

View File

@@ -12,6 +12,7 @@ while Q is non-empty:
mark w as explored
add w to Q (at the end)
"""
from __future__ import annotations
from collections import deque

View File

@@ -1,6 +1,7 @@
"""Breath First Search (BFS) can be used when finding the shortest path
from a given source node to a target node in an unweighted graph.
"""
from __future__ import annotations
graph = {

View File

@@ -1,9 +1,10 @@
"""Breadth-first search shortest path implementations.
doctest:
python -m doctest -v bfs_shortest_path.py
Manual test:
python bfs_shortest_path.py
doctest:
python -m doctest -v bfs_shortest_path.py
Manual test:
python bfs_shortest_path.py
"""
demo_graph = {
"A": ["B", "C", "E"],
"B": ["A", "D", "E"],

View File

@@ -3,6 +3,7 @@ Finding the shortest path in 0-1-graph in O(E + V) which is faster than dijkstra
0-1-graph is the weighted graph with the weights equal to 0 or 1.
Link: https://codeforces.com/blog/entry/22276
"""
from __future__ import annotations
from collections import deque

View File

@@ -9,6 +9,7 @@ Return a deep copy (clone) of the graph.
Each node in the graph contains a value (int) and a list (List[Node]) of its
neighbors.
"""
from dataclasses import dataclass

View File

@@ -1,4 +1,5 @@
"""Non recursive implementation of a DFS algorithm."""
from __future__ import annotations

View File

@@ -1,6 +1,6 @@
#!/usr/bin/python
""" Author: OMKAR PATHAK """
"""Author: OMKAR PATHAK"""
class Graph:

View File

@@ -30,6 +30,7 @@ only the distance between previous vertex and current vertex but the entire
distance between each vertex that makes up the path from start vertex to target
vertex.
"""
import heapq

View File

@@ -12,6 +12,7 @@ Constraints
Note: The tree input will be such that it can always be decomposed into
components containing an even number of nodes.
"""
# pylint: disable=invalid-name
from collections import defaultdict

View File

@@ -8,6 +8,7 @@ frequent subgraphs and maximum common subgraphs.
URL: https://www.researchgate.net/publication/235255851
"""
# fmt: off
edge_array = [
['ab-e1', 'ac-e3', 'ad-e5', 'bc-e4', 'bd-e2', 'be-e6', 'bh-e12', 'cd-e2', 'ce-e4',

View File

@@ -15,6 +15,7 @@ Potential Future Ideas:
- Make edge weights and vertex values customizable to store whatever the client wants
- Support multigraph functionality if the client wants it
"""
from __future__ import annotations
import random

View File

@@ -15,6 +15,7 @@ Potential Future Ideas:
- Make edge weights and vertex values customizable to store whatever the client wants
- Support multigraph functionality if the client wants it
"""
from __future__ import annotations
import random

View File

@@ -1,7 +1,7 @@
# floyd_warshall.py
"""
The problem is to find the shortest distance between all pairs of vertices in a
weighted directed graph that can have negative edge weights.
The problem is to find the shortest distance between all pairs of vertices in a
weighted directed graph that can have negative edge weights.
"""

View File

@@ -6,6 +6,7 @@ edges in the tree is minimized. The algorithm operates by building this tree one
at a time, from an arbitrary starting vertex, at each step adding the cheapest possible
connection from the tree to another vertex.
"""
from __future__ import annotations
from sys import maxsize

View File

@@ -1,6 +1,7 @@
"""
Author: https://github.com/bhushan-borole
"""
"""
The input graph for the algorithm is:

View File

@@ -1,8 +1,8 @@
"""Prim's Algorithm.
Determines the minimum spanning tree(MST) of a graph using the Prim's Algorithm.
Determines the minimum spanning tree(MST) of a graph using the Prim's Algorithm.
Details: https://en.wikipedia.org/wiki/Prim%27s_algorithm
Details: https://en.wikipedia.org/wiki/Prim%27s_algorithm
"""
import heapq as hq