Skip to content

Commit c2b37f9

Browse files
committed
for now
1 parent 00d7bfe commit c2b37f9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/algorithms/graph.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,33 @@ def collect_scc(node, component):
256256
sccs.append(component)
257257

258258
return sccs
259+
260+
261+
if __name__ == "__main__":
262+
# Example usage
263+
graph_data = {
264+
1: {2: {}, 3: {}},
265+
2: {4: {}},
266+
3: {4: {}},
267+
4: {},
268+
}
269+
start_node = 1
270+
print(
271+
"Graph Traversal from node",
272+
start_node,
273+
":",
274+
graph_traversal(graph_data, start_node),
275+
)
276+
277+
path_finder = PathFinder({"A": ["B", "C"], "B": ["D"], "C": ["D"], "D": []})
278+
print("Shortest path from A to D:", path_finder.find_shortest_path("A", "D"))
279+
nodes = [{"id": "1"}, {"id": "2"}, {"id": "3"}, {"id": "4"}]
280+
edges = [{"source": "1", "target": "2"}, {"source": "2", "target": "3"}]
281+
print("Leaf nodes:", find_leaf_nodes(nodes, edges))
282+
print("Cycle vertices:", find_cycle_vertices(edges))
283+
print(
284+
"Node with highest degree:",
285+
find_node_with_highest_degree(
286+
["1", "2", "3", "4"], {"1": ["2"], "2": ["3"], "3": ["1"], "4": []}
287+
),
288+
)

0 commit comments

Comments
 (0)