From fa1b46d88c212a5c72b46e7f13d5d60f8da06209 Mon Sep 17 00:00:00 2001 From: fadli0029 Date: Fri, 12 Jul 2024 20:24:15 -0700 Subject: [PATCH] [ADD] more drafts of graphs algos --- algorithms/graph/astar.cpp | 0 algorithms/graph/bellman_ford.cpp | 4 ++++ algorithms/graph/dfs.cpp | 6 +++--- algorithms/graph/dijkstra.cpp | 0 algorithms/graph/kruskal.cpp | 0 algorithms/graph/prim.cpp | 0 6 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 algorithms/graph/astar.cpp create mode 100644 algorithms/graph/bellman_ford.cpp create mode 100644 algorithms/graph/dijkstra.cpp create mode 100644 algorithms/graph/kruskal.cpp create mode 100644 algorithms/graph/prim.cpp diff --git a/algorithms/graph/astar.cpp b/algorithms/graph/astar.cpp new file mode 100644 index 0000000..e69de29 diff --git a/algorithms/graph/bellman_ford.cpp b/algorithms/graph/bellman_ford.cpp new file mode 100644 index 0000000..a6fe24a --- /dev/null +++ b/algorithms/graph/bellman_ford.cpp @@ -0,0 +1,4 @@ +// There's two variant: +// 1. We want shortest path, so do N-1 iterations. +// 2. A constraint says at most k edges are allowed to get the shortest distance between two nodes, so do k iterations. +// (see letcode graph explore card bellman ford chapter). diff --git a/algorithms/graph/dfs.cpp b/algorithms/graph/dfs.cpp index 72999f2..2de1c8a 100644 --- a/algorithms/graph/dfs.cpp +++ b/algorithms/graph/dfs.cpp @@ -1,5 +1,5 @@ -/* ============================================================================== - This is an implementation of the Depth First Search (DFS) algorithm using a +/* ==================================================================================== + This file contains implementations of the Depth First Search (DFS) algorithm using a stack explicitly and using recursion (recursion is using stack implicitly by nature of a function call). The implementation assumes the starting node to be `0` by default. It then prints the visited nodes in the order they @@ -11,7 +11,7 @@ @param adj_list: the adjacency list representation of the graph @author: Muhammad Fadli Alim Arsani -===============================================================================*/ +=====================================================================================*/ #define CATCH_CONFIG_MAIN #include diff --git a/algorithms/graph/dijkstra.cpp b/algorithms/graph/dijkstra.cpp new file mode 100644 index 0000000..e69de29 diff --git a/algorithms/graph/kruskal.cpp b/algorithms/graph/kruskal.cpp new file mode 100644 index 0000000..e69de29 diff --git a/algorithms/graph/prim.cpp b/algorithms/graph/prim.cpp new file mode 100644 index 0000000..e69de29