Skip to content

Commit 358a324

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 1cecf29 commit 358a324

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

dsa_programs/bellman_ford.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
Edge = Tuple[T, T, float]
77

88

9-
def bellman_ford(vertices: Iterable[T], edges: Iterable[Edge], source: T) -> Dict[T, float]:
9+
def bellman_ford(
10+
vertices: Iterable[T], edges: Iterable[Edge], source: T
11+
) -> Dict[T, float]:
1012
edge_list: List[Edge] = list(edges)
1113
vertex_set: Set[T] = set(vertices)
1214
for u, v, _ in edge_list:

dsa_programs/dijkstra_shortest_path.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def dijkstra_shortest_path(graph: Graph, source: T) -> Dict[T, float]:
1515
current_dist, node = heappop(heap)
1616
if current_dist > distances.get(node, float("inf")):
1717
continue
18-
for neighbor, weight in graph.get(node, ()): # missing key means no outgoing edges
18+
for neighbor, weight in graph.get(
19+
node, ()
20+
): # missing key means no outgoing edges
1921
cost = current_dist + weight
2022
if cost < distances.get(neighbor, float("inf")):
2123
distances[neighbor] = cost

dsa_programs/knapsack_01.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ def knapsack_01(items: Sequence[Item], capacity: int) -> int:
1111
dp: List[int] = [0] * (capacity + 1)
1212
for weight, value in items:
1313
for current_capacity in range(capacity, weight - 1, -1):
14-
dp[current_capacity] = max(dp[current_capacity], dp[current_capacity - weight] + value)
14+
dp[current_capacity] = max(
15+
dp[current_capacity], dp[current_capacity - weight] + value
16+
)
1517
return dp[capacity]

dsa_programs/rabin_karp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
from typing import List
44

55

6-
def rabin_karp_search(text: str, pattern: str, base: int = 256, modulus: int = 1_000_000_007) -> List[int]:
6+
def rabin_karp_search(
7+
text: str, pattern: str, base: int = 256, modulus: int = 1_000_000_007
8+
) -> List[int]:
79
if not pattern:
810
return list(range(len(text) + 1))
911
if len(pattern) > len(text):

dsa_programs/reservoir_sampling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
T = TypeVar("T")
77

88

9-
def reservoir_sample(stream: Iterable[T], k: int, rng: Optional[random.Random] = None) -> List[T]:
9+
def reservoir_sample(
10+
stream: Iterable[T], k: int, rng: Optional[random.Random] = None
11+
) -> List[T]:
1012
if k <= 0:
1113
raise ValueError("Sample size must be positive")
1214
rand = rng or random.Random()

dsa_programs/tarjan_scc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ def strong_connect(node: T) -> None:
3636
break
3737
components.append(component)
3838

39-
for node in set(graph) | {neighbor for neighbors in graph.values() for neighbor in neighbors}:
39+
for node in set(graph) | {
40+
neighbor for neighbors in graph.values() for neighbor in neighbors
41+
}:
4042
if node not in indices:
4143
strong_connect(node)
4244
return components

0 commit comments

Comments
 (0)