Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 718762a

Browse files
up
1 parent c2132e0 commit 718762a

File tree

168 files changed

+383
-256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+383
-256
lines changed

Benchmark Reports.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Benchmark Reports
22

3-
This document contains benchmark results for the entire `pofk_algorithms` Rust library, including execution time and memory usage for representative algorithms in each module.
3+
This document contains benchmark results for the entire `pofk_algorithm` Rust library, including execution time and memory usage for representative algorithms in each module.
44

55
## How to Run Benchmarks
66

CHANGELOG.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Total Algorithms: 106
2+
3+
# v0.1.0 (2025-08-11)
4+
5+
## Major Additions
6+
7+
**Total algorithms added: 23**
8+
9+
### List Algorithms (16)
10+
11+
### Set Algorithms (7)
12+
13+
## Other Changes
14+
- Added robust, dedicated test files for each new algorithm in tree, linked list, and DP modules.
15+
- Added comprehensive documentation and doctests for all new algorithms.
16+
- Created full example files: `examples/tree_algorithms_examples.rs`, `examples/linked_list_algorithms_examples.rs`, `examples/dp_algorithms_examples.rs` demonstrating usage of all new algorithms.
17+
18+
# v0.2.0 (2025-08-11)
19+
20+
## [Unreleased]
21+
22+
### Major Additions
23+
24+
**Total graph algorithms added: 10+**
25+
26+
### Graph Algorithms (10+)
27+
- Kruskal's Minimum Spanning Tree (MST) algorithm (`graph_algorithms::kruskal`)
28+
- Prim's Minimum Spanning Tree (MST) algorithm (`graph_algorithms::prim`)
29+
- Kosaraju's Strongly Connected Components (SCC) algorithm (`graph_algorithms::kosaraju_scc`)
30+
- Articulation Points (Cut Vertices) algorithm (`graph_algorithms::articulation_points`)
31+
32+
## Other Changes
33+
- Added robust, dedicated test files for each new graph algorithm.
34+
- Comprehensive documentation and doctests for all new graph algorithms.
35+
36+
## Major Additions
37+
38+
**Total string algorithms added: 10**
39+
40+
### String Algorithms (10)
41+
- Reverse String
42+
- Palindrome Check
43+
- Anagram Check (for strings)
44+
- Longest Palindromic Substring
45+
- String Compression
46+
- Substring Search (Brute Force)
47+
- Rabin-Karp
48+
- Longest Common Prefix
49+
- Edit Distance
50+
- Count Vowels/Consonants
51+
52+
## Tree Algorithms (11)
53+
- Binary Tree Traversals: Inorder, Preorder, Postorder (`tree_algorithms::binary_tree_traversal`)
54+
- Diameter of Binary Tree (`tree_algorithms::diameter_of_tree`)
55+
- Balanced Binary Tree Check (`tree_algorithms::balanced_tree`)
56+
- Level Order (BFS) Traversal (`tree_algorithms::level_order_traversal`)
57+
- Lowest Common Ancestor (LCA) (`tree_algorithms::lowest_common_ancestor`)
58+
- Invert Binary Tree (`tree_algorithms::invert_tree`)
59+
- Zigzag Level Order Traversal (`tree_algorithms::zigzag_traversal`)
60+
- Validate Binary Search Tree (`tree_algorithms::validate_bst`)
61+
- Depth of Binary Tree (`tree_algorithms::tree_depth`)
62+
- Serialize and Deserialize Binary Tree (`tree_algorithms::serialize_deserialize`)
63+
- Robust, dedicated test files and a full example file for all tree algorithms
64+
65+
## Linked List Algorithms (9)
66+
- Singly Linked List Node and Traversal (`linked_list_algorithms::singly_linked_list`)
67+
- Insert and Delete at Position (`linked_list_algorithms::insert_delete`)
68+
- Doubly Linked List Node and Reverse (`linked_list_algorithms::doubly_linked_list`)
69+
- Reverse Singly Linked List (`linked_list_algorithms::reverse_list`)
70+
- Detect Cycle (Floyd's) (`linked_list_algorithms::detect_cycle`)
71+
- Merge Two Sorted Lists (`linked_list_algorithms::merge_sorted`)
72+
- Remove Nth Node From End (`linked_list_algorithms::remove_nth_from_end`)
73+
- Palindrome Linked List Check (`linked_list_algorithms::palindrome`)
74+
- Intersection of Two Lists (`linked_list_algorithms::intersection`)
75+
- Robust, dedicated test files and a full example file for all linked list algorithms
76+
77+
## Dynamic Programming Algorithms (13)
78+
- Fibonacci (Memoization) (`dp_algorithms::fibonacci`)
79+
- 0/1 Knapsack (`dp_algorithms::knapsack_01`)
80+
- Longest Increasing Subsequence (`dp_algorithms::longest_increasing_subsequence`)
81+
- Longest Common Subsequence (`dp_algorithms::longest_common_subsequence`)
82+
- Edit Distance (`dp_algorithms::edit_distance`)
83+
- Matrix Path Sum (`dp_algorithms::matrix_path_sum`)
84+
- Coin Change (`dp_algorithms::coin_change`)
85+
- Subset Sum (`dp_algorithms::subset_sum`)
86+
- Partition Equal Subset Sum (`dp_algorithms::partition_equal_subset_sum`)
87+
- House Robber (`dp_algorithms::house_robber`)
88+
- Jump Game (`dp_algorithms::jump_game`)
89+
- Palindromic Substrings (`dp_algorithms::palindromic_substrings`)
90+
- Rod Cutting (`dp_algorithms::rod_cutting`)
91+
- Robust, dedicated test files and a full example file for all DP algorithms
92+
93+
## Backtracking Algorithms (9)
94+
95+
## Matrix/Grid Algorithms (8)
96+
- Flood Fill (`matrix_algorithms::flood_fill`)
97+
- Island Count (DFS/BFS) (`matrix_algorithms::island_count`)
98+
- Shortest Path in Grid (`matrix_algorithms::shortest_path_grid`)
99+
- Word Search (`matrix_algorithms::word_search`)
100+
- Path Sum in Matrix (`matrix_algorithms::path_sum`)
101+
- Matrix Rotation (`matrix_algorithms::matrix_rotation`)
102+
- Spiral Traversal (`matrix_algorithms::spiral_traversal`)
103+
- Surrounded Regions (`matrix_algorithms::surrounded_regions`)
104+
- Robust, dedicated test files and a full example file for all matrix/grid algorithms

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[package]
2+
name = "pofk_algorithm"
3+
version = "0.0.1"
4+
edition = "2024"
5+
authors = ["POFKLabs <[email protected]>"]
6+
description = "A collection of efficient algorithms implemented in Rust for real-world projects."
7+
license = "MIT"
8+
readme = "README.md"
9+
repository = "https://github.com/POFKLabs/pofk_algorithm_rust"
10+
keywords = ["algorithms", "data-structures", "rust", "library"]
11+
categories = ["algorithms", "data-structures"]
12+
documentation = "https://docs.rs/pofk_algorithm_rust"
13+
homepage = "https://pofklabs.vercel.app"
14+
15+
[dependencies]
16+
num-traits = "0.2.19"
17+
18+
[dev-dependencies]
19+
criterion = "*"
20+
21+
[[bench]]
22+
name = "benchmark"
23+
harness = false

benches/benchmark.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//! Library-wide benchmarks for pofk_algorithms
1+
//! Library-wide benchmarks for pofk_algorithm
22
//! Run with: `cargo bench`
33
44
use criterion::{criterion_group, criterion_main, Criterion};
55
use std::hint::black_box;
6-
use pofk_algorithms::*;
6+
use pofk_algorithm::*;
77

88
fn bench_merge_sort(c: &mut Criterion) {
99
let data = (0..10_000).rev().collect::<Vec<_>>();
@@ -55,7 +55,7 @@ fn bench_dijkstra(c: &mut Criterion) {
5555
}
5656

5757
fn bench_lca(c: &mut Criterion) {
58-
use pofk_algorithms::tree_algorithms::binary_tree_traversal::TreeNode;
58+
use pofk_algorithm::tree_algorithms::binary_tree_traversal::TreeNode;
5959
let root = Some(Box::new(TreeNode::new(1)));
6060
c.bench_function("tree::lowest_common_ancestor", |b| {
6161
b.iter(|| {
@@ -65,7 +65,7 @@ fn bench_lca(c: &mut Criterion) {
6565
}
6666

6767
fn bench_reverse_list(c: &mut Criterion) {
68-
use pofk_algorithms::linked_list_algorithms::singly_linked_list::ListNode;
68+
use pofk_algorithm::linked_list_algorithms::singly_linked_list::ListNode;
6969
let mut head = Some(Box::new(ListNode::new(1)));
7070
head.as_mut().unwrap().next = Some(Box::new(ListNode::new(2)));
7171
c.bench_function("linked_list::reverse_list", |b| {

examples/backtracking_algorithms_examples.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Examples for all backtracking_algorithms
2-
use pofk_algorithms::backtracking_algorithms::n_queens::n_queens;
3-
use pofk_algorithms::backtracking_algorithms::sudoku_solver::solve_sudoku;
4-
use pofk_algorithms::backtracking_algorithms::subset_generation::subset_generation;
5-
use pofk_algorithms::backtracking_algorithms::permutations::permutations;
6-
use pofk_algorithms::backtracking_algorithms::word_search::word_search;
7-
use pofk_algorithms::backtracking_algorithms::combinations::combinations;
8-
use pofk_algorithms::backtracking_algorithms::combination_sum::combination_sum;
9-
use pofk_algorithms::backtracking_algorithms::letter_combinations_phone_number::letter_combinations;
10-
use pofk_algorithms::backtracking_algorithms::rat_in_a_maze::rat_in_a_maze;
2+
use pofk_algorithm::backtracking_algorithms::n_queens::n_queens;
3+
use pofk_algorithm::backtracking_algorithms::sudoku_solver::solve_sudoku;
4+
use pofk_algorithm::backtracking_algorithms::subset_generation::subset_generation;
5+
use pofk_algorithm::backtracking_algorithms::permutations::permutations;
6+
use pofk_algorithm::backtracking_algorithms::word_search::word_search;
7+
use pofk_algorithm::backtracking_algorithms::combinations::combinations;
8+
use pofk_algorithm::backtracking_algorithms::combination_sum::combination_sum;
9+
use pofk_algorithm::backtracking_algorithms::letter_combinations_phone_number::letter_combinations;
10+
use pofk_algorithm::backtracking_algorithms::rat_in_a_maze::rat_in_a_maze;
1111

1212
fn main() {
1313
// N-Queens

examples/dp_algorithms_examples.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//! Examples for all dp_algorithms
2-
use pofk_algorithms::dp_algorithms::fibonacci::fibonacci;
3-
use pofk_algorithms::dp_algorithms::knapsack_01::knapsack_01;
4-
use pofk_algorithms::dp_algorithms::longest_increasing_subsequence::longest_increasing_subsequence;
5-
use pofk_algorithms::dp_algorithms::longest_common_subsequence::longest_common_subsequence;
6-
use pofk_algorithms::dp_algorithms::edit_distance::edit_distance;
7-
use pofk_algorithms::dp_algorithms::matrix_path_sum::matrix_path_sum;
8-
use pofk_algorithms::dp_algorithms::coin_change::coin_change;
9-
use pofk_algorithms::dp_algorithms::subset_sum::subset_sum;
10-
use pofk_algorithms::dp_algorithms::partition_equal_subset_sum::partition_equal_subset_sum;
11-
use pofk_algorithms::dp_algorithms::house_robber::house_robber;
12-
use pofk_algorithms::dp_algorithms::jump_game::jump_game;
13-
use pofk_algorithms::dp_algorithms::palindromic_substrings::palindromic_substrings;
14-
use pofk_algorithms::dp_algorithms::rod_cutting::rod_cutting;
2+
use pofk_algorithm::dp_algorithms::fibonacci::fibonacci;
3+
use pofk_algorithm::dp_algorithms::knapsack_01::knapsack_01;
4+
use pofk_algorithm::dp_algorithms::longest_increasing_subsequence::longest_increasing_subsequence;
5+
use pofk_algorithm::dp_algorithms::longest_common_subsequence::longest_common_subsequence;
6+
use pofk_algorithm::dp_algorithms::edit_distance::edit_distance;
7+
use pofk_algorithm::dp_algorithms::matrix_path_sum::matrix_path_sum;
8+
use pofk_algorithm::dp_algorithms::coin_change::coin_change;
9+
use pofk_algorithm::dp_algorithms::subset_sum::subset_sum;
10+
use pofk_algorithm::dp_algorithms::partition_equal_subset_sum::partition_equal_subset_sum;
11+
use pofk_algorithm::dp_algorithms::house_robber::house_robber;
12+
use pofk_algorithm::dp_algorithms::jump_game::jump_game;
13+
use pofk_algorithm::dp_algorithms::palindromic_substrings::palindromic_substrings;
14+
use pofk_algorithm::dp_algorithms::rod_cutting::rod_cutting;
1515

1616
fn main() {
1717
// Fibonacci

examples/graph_algorithms_xampp_example.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// This file demonstrates all new algorithms in a single Rust main function.
33
// You can run this as a Rust binary, or adapt the code for FFI/WebAssembly integration.
44

5-
use pofk_algorithms::graph_algorithms::kruskal::kruskal;
6-
use pofk_algorithms::graph_algorithms::prim::prim;
7-
use pofk_algorithms::graph_algorithms::kosaraju_scc::kosaraju_scc;
8-
use pofk_algorithms::graph_algorithms::articulation_points::articulation_points;
5+
use pofk_algorithm::graph_algorithms::kruskal::kruskal;
6+
use pofk_algorithm::graph_algorithms::prim::prim;
7+
use pofk_algorithm::graph_algorithms::kosaraju_scc::kosaraju_scc;
8+
use pofk_algorithm::graph_algorithms::articulation_points::articulation_points;
99

1010
fn main() {
1111
use std::collections::HashMap;
@@ -51,11 +51,11 @@ fn main() {
5151
graph.insert(2, vec![4]);
5252
graph.insert(3, vec![]);
5353
graph.insert(4, vec![]);
54-
let dfs_order = pofk_algorithms::graph_algorithms::dfs::dfs(&graph, 1);
54+
let dfs_order = pofk_algorithm::graph_algorithms::dfs::dfs(&graph, 1);
5555
println!("DFS order: {:?}", dfs_order);
5656

5757
// BFS
58-
let bfs_order = pofk_algorithms::graph_algorithms::bfs::bfs(&graph, 1);
58+
let bfs_order = pofk_algorithm::graph_algorithms::bfs::bfs(&graph, 1);
5959
println!("BFS order: {:?}", bfs_order);
6060

6161
// Dijkstra
@@ -64,7 +64,7 @@ fn main() {
6464
wgraph.insert(2, vec![(3, 2), (4, 5)]);
6565
wgraph.insert(3, vec![(4, 1)]);
6666
wgraph.insert(4, vec![]);
67-
let dist = pofk_algorithms::graph_algorithms::dijkstra::dijkstra(&wgraph, 1);
67+
let dist = pofk_algorithm::graph_algorithms::dijkstra::dijkstra(&wgraph, 1);
6868
println!("Dijkstra distances: {:?}", dist);
6969

7070
// Bellman-Ford
@@ -73,7 +73,7 @@ fn main() {
7373
bf_graph.insert(2, vec![(3, -2), (4, 5)]);
7474
bf_graph.insert(3, vec![(4, 1)]);
7575
bf_graph.insert(4, vec![]);
76-
let bf_dist = pofk_algorithms::graph_algorithms::bellman_ford::bellman_ford(&bf_graph, 1);
76+
let bf_dist = pofk_algorithm::graph_algorithms::bellman_ford::bellman_ford(&bf_graph, 1);
7777
println!("Bellman-Ford distances: {:?}", bf_dist);
7878

7979
// Floyd-Warshall
@@ -84,7 +84,7 @@ fn main() {
8484
(1, 3, 4),
8585
(3, 4, 1),
8686
];
87-
let fw_dist = pofk_algorithms::graph_algorithms::floyd_warshall::floyd_warshall(&nodes_fw, &edges_fw);
87+
let fw_dist = pofk_algorithm::graph_algorithms::floyd_warshall::floyd_warshall(&nodes_fw, &edges_fw);
8888
println!("Floyd-Warshall distances: {:?}", fw_dist);
8989

9090
// Topological Sort
@@ -95,11 +95,11 @@ fn main() {
9595
dag.insert(3, vec![1]);
9696
dag.insert(0, vec![]);
9797
dag.insert(1, vec![]);
98-
let topo = pofk_algorithms::graph_algorithms::topological_sort::topological_sort(&dag);
98+
let topo = pofk_algorithm::graph_algorithms::topological_sort::topological_sort(&dag);
9999
println!("Topological sort: {:?}", topo);
100100

101101
// Union-Find
102-
let mut uf = pofk_algorithms::graph_algorithms::union_find::UnionFind::new();
102+
let mut uf = pofk_algorithm::graph_algorithms::union_find::UnionFind::new();
103103
uf.add(1); uf.add(2); uf.add(3);
104104
uf.union(1, 2);
105105
println!("Union-Find connected(1,2): {}", uf.connected(1, 2));
@@ -111,7 +111,7 @@ fn main() {
111111
cc_graph.insert(2, vec![1]);
112112
cc_graph.insert(3, vec![4]);
113113
cc_graph.insert(4, vec![3]);
114-
let mut comps = pofk_algorithms::graph_algorithms::connected_components::connected_components(&cc_graph);
114+
let mut comps = pofk_algorithm::graph_algorithms::connected_components::connected_components(&cc_graph);
115115
for comp in &mut comps { comp.sort(); }
116116
comps.sort();
117117
println!("Connected components: {:?}", comps);
@@ -121,17 +121,17 @@ fn main() {
121121
cycle_graph.insert(1, vec![2]);
122122
cycle_graph.insert(2, vec![3]);
123123
cycle_graph.insert(3, vec![1]);
124-
println!("Has cycle: {}", pofk_algorithms::graph_algorithms::cycle_detection::has_cycle(&cycle_graph));
124+
println!("Has cycle: {}", pofk_algorithm::graph_algorithms::cycle_detection::has_cycle(&cycle_graph));
125125
cycle_graph.insert(3, vec![]);
126-
println!("Has cycle (after removal): {}", pofk_algorithms::graph_algorithms::cycle_detection::has_cycle(&cycle_graph));
126+
println!("Has cycle (after removal): {}", pofk_algorithm::graph_algorithms::cycle_detection::has_cycle(&cycle_graph));
127127

128128
// Bipartite Graph
129129
let mut bipartite_graph = HashMap::new();
130130
bipartite_graph.insert(1, vec![2, 3]);
131131
bipartite_graph.insert(2, vec![1, 4]);
132132
bipartite_graph.insert(3, vec![1, 4]);
133133
bipartite_graph.insert(4, vec![2, 3]);
134-
println!("Is bipartite: {}", pofk_algorithms::graph_algorithms::bipartite_graph::is_bipartite(&bipartite_graph));
134+
println!("Is bipartite: {}", pofk_algorithm::graph_algorithms::bipartite_graph::is_bipartite(&bipartite_graph));
135135
bipartite_graph.insert(4, vec![2, 3, 1]);
136-
println!("Is bipartite (after making non-bipartite): {}", pofk_algorithms::graph_algorithms::bipartite_graph::is_bipartite(&bipartite_graph));
136+
println!("Is bipartite (after making non-bipartite): {}", pofk_algorithm::graph_algorithms::bipartite_graph::is_bipartite(&bipartite_graph));
137137
}

examples/linked_list_algorithms_examples.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Examples for all linked_list_algorithms
2-
use pofk_algorithms::linked_list_algorithms::singly_linked_list::{ListNode, traverse};
3-
use pofk_algorithms::linked_list_algorithms::insert_delete::{insert_at, delete_at};
4-
use pofk_algorithms::linked_list_algorithms::doubly_linked_list::{DListNode, reverse_doubly};
5-
use pofk_algorithms::linked_list_algorithms::reverse_list::reverse_list;
6-
use pofk_algorithms::linked_list_algorithms::detect_cycle::has_cycle;
7-
use pofk_algorithms::linked_list_algorithms::merge_sorted::merge_sorted;
8-
use pofk_algorithms::linked_list_algorithms::remove_nth_from_end::remove_nth_from_end;
9-
use pofk_algorithms::linked_list_algorithms::palindrome::is_palindrome;
10-
use pofk_algorithms::linked_list_algorithms::intersection::intersection;
2+
use pofk_algorithm::linked_list_algorithms::singly_linked_list::{ListNode, traverse};
3+
use pofk_algorithm::linked_list_algorithms::insert_delete::{insert_at, delete_at};
4+
use pofk_algorithm::linked_list_algorithms::doubly_linked_list::{DListNode, reverse_doubly};
5+
use pofk_algorithm::linked_list_algorithms::reverse_list::reverse_list;
6+
use pofk_algorithm::linked_list_algorithms::detect_cycle::has_cycle;
7+
use pofk_algorithm::linked_list_algorithms::merge_sorted::merge_sorted;
8+
use pofk_algorithm::linked_list_algorithms::remove_nth_from_end::remove_nth_from_end;
9+
use pofk_algorithm::linked_list_algorithms::palindrome::is_palindrome;
10+
use pofk_algorithm::linked_list_algorithms::intersection::intersection;
1111

1212
fn main() {
1313
// Singly linked list: 1 -> 2

examples/list_algorithms_examples.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
use pofk_algorithms::list_algorithms::*;
2+
use pofk_algorithm::list_algorithms::*;
33

44
fn main() {
55
// Linear Search

0 commit comments

Comments
 (0)