mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort * Fixed doctest error due whitespace * reduce loop times for optimization * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -56,14 +56,14 @@ def connect(graph, a, b, edge):
|
||||
def prim(graph: list, root: Vertex) -> list:
|
||||
"""Prim's Algorithm.
|
||||
|
||||
Runtime:
|
||||
O(mn) with `m` edges and `n` vertices
|
||||
Runtime:
|
||||
O(mn) with `m` edges and `n` vertices
|
||||
|
||||
Return:
|
||||
List with the edges of a Minimum Spanning Tree
|
||||
Return:
|
||||
List with the edges of a Minimum Spanning Tree
|
||||
|
||||
Usage:
|
||||
prim(graph, graph[0])
|
||||
Usage:
|
||||
prim(graph, graph[0])
|
||||
"""
|
||||
a = []
|
||||
for u in graph:
|
||||
@ -86,14 +86,14 @@ def prim(graph: list, root: Vertex) -> list:
|
||||
def prim_heap(graph: list, root: Vertex) -> Iterator[tuple]:
|
||||
"""Prim's Algorithm with min heap.
|
||||
|
||||
Runtime:
|
||||
O((m + n)log n) with `m` edges and `n` vertices
|
||||
Runtime:
|
||||
O((m + n)log n) with `m` edges and `n` vertices
|
||||
|
||||
Yield:
|
||||
Edges of a Minimum Spanning Tree
|
||||
Yield:
|
||||
Edges of a Minimum Spanning Tree
|
||||
|
||||
Usage:
|
||||
prim(graph, graph[0])
|
||||
Usage:
|
||||
prim(graph, graph[0])
|
||||
"""
|
||||
for u in graph:
|
||||
u.key = math.inf
|
||||
|
Reference in New Issue
Block a user