๐ง algorithms core

A comprehensive, fast, and extensible algorithms library for Dart. Includes classic and modern techniques for lists, sets, maps, strings, and graphs โ built with clean APIs and strong generics.
- Actively maintained with ambitious roadmap (1,000+ algorithms planned)
- Type-safe generics across the library
- Readable code with clear documentation and tests
Environment: Dart SDK โฅ 3.7.2 (see pubspec.yaml).
๐ฆ Install ## algorithms core
Use in your Dart or Flutter project.
Dart
dart pub add algorithms_core
Flutter
flutter pub add algorithms_core
๐ Quick start ## algorithm
import 'package:algorithms_core/algorithms_core.dart';
import 'package:algorithms_core/graph_algorithms/weighted_edge.dart';
void main() {
// List: binary search and sorting
final idx = binarySearch<int>([1, 3, 5, 7, 9], 7);
final sorted = mergeSort<int>([5, 2, 4, 6, 1, 3]);
// String: algorithms
final isPal = isPalindrome('A man a plan a canal Panama');
final lcp = longestCommonPrefix(['flower', 'flow', 'flight']);
// Graph: Dijkstra over weighted edges
final graph = <String, List<WeightedEdge<String>>>{
'A': [WeightedEdge('A', 'B', 1), WeightedEdge('A', 'C', 4)],
'B': [WeightedEdge('B', 'C', 2)],
'C': [],
};
final dist = dijkstra(graph, 'A');
// Tree: binary tree operations
final root = BinaryTreeNode<int>(10);
root.left = BinaryTreeNode<int>(5);
root.right = BinaryTreeNode<int>(15);
final inorder = inorderTraversal(root);
final isValid = validateBST(root);
// Linked List: basic operations
final list = LinkedListNode.fromList<int>([1, 2, 3, 4, 5]);
final reversed = reverseLinkedList(list);
final hasCycle = detectCycle(list);
print([idx, sorted, isPal, lcp, dist, inorder, isValid, reversed, hasCycle]);
}
For a full tour, see example/algorithms_core_example.dart, example/tree_algorithms_example.dart, and example/linked_list_algorithms_example.dart.
๐งฉ Algorithms included
List algorithms
- binary_search, linear_search
- merge_sort, quick_sort, bubble_sort, insertion_sort, selection_sort
- counting_sort (non-negative ints)
- reverse_list, find_max_min, find_duplicates, remove_duplicates
- kadanes_algorithm
- max_sum_subarray_of_size_k, min_sum, average_subarray, prefix_sum, two_sum_sorted
- rotate_array_right
Set algorithms
- has_duplicates, has_two_sum, has_unique_window
- disjoint_set (Union-Find), find_intersection, set_difference, is_frequency_unique
Map algorithms
- frequency_count, most_frequent_element, top_k_frequent
- group_by_key, first_non_repeated_element
- anagram_checker (generic list-based)
- two_sum (indices), lru_cache, length_of_longest_substring
String algorithms
- reverse_string, palindrome_checker, anagram_checker
- brute_force_search, kmp_search, rabin_karp_search
- longest_common_prefix, longest_palindromic_substring
- edit_distance, string_compression, count_vowels_consonants
Graph algorithms (new)
- bfs, dfs, topological_sort
- connected_components, cycle_detection (directed/undirected), bipartite_graph
- shortest_path (unweighted BFS), weighted_edge (utility)
- dijkstra, bellman_ford, floyd_warshall
- mst_kruskal, mst_prim
- kosaraju_scc, articulation_points, union_find (typedef)
Tree algorithms (new)
- binary_tree_node (generic tree node)
- tree_traversals (inorder, preorder, postorder)
- level_order_traversal (BFS)
- tree_depth (height calculation)
- invert_tree (mirror tree)
- lowest_common_ancestor (LCA)
- validate_bst (BST validation)
- tree_diameter (longest path)
- balanced_tree_check (height-balanced check)
- tree_serialization (serialize/deserialize)
- zigzag_traversal (alternating level order)
Linked List algorithms (new)
- linked_list_node (generic singly linked list node)
- doubly_linked_list_node (generic doubly linked list node)
- insert_delete_at_position (insert/delete at specific positions)
- reverse_linked_list (iterative, recursive, group reverse, reverse between)
- detect_cycle (Floyd's cycle detection algorithm)
- merge_sorted_lists (merge two sorted linked lists)
- remove_nth_from_end (remove nth node from end)
- palindrome_linked_list (check if linked list is palindrome)
- intersection_of_lists (find intersection point of two lists)
Each function includes Dartdoc with usage and time/space complexity.
๐ Usage notes
- Import everything via
package:algorithms_core/algorithms_core.dart. - Sorting/searching functions use
T extends Comparablewhere appropriate. - Weighted graph utilities use
WeightedEdge<T>. - Algorithms are pure and side-effect free unless documented otherwise.
๐งช Running tests
dart test
All tests pass in the repository (see test/).
Key Algorithms
| Algorithm | Description |
|---|---|
| binary_search | Fast and efficient binary search on a sorted list. |
| merge_sort | Stable sorting algorithm with excellent performance. |
| quick_sort | Fast sorting algorithm with good average-case performance. |
| kadanes_algorithm | Finds the maximum sum of a contiguous subarray. |
| dijkstra | Finds the shortest path in a weighted directed graph. |
| bellman_ford | Shortest path algorithm that handles negative weights and detects negative cycles. |
| floyd_warshall | Finds shortest paths between all pairs of nodes in a graph. |
| bfs (Breadth-First Search) | Graph traversal method for connectivity and shortest unweighted paths. |
| dfs (Depth-First Search) | Graph traversal method for cycle detection, classification, and orderings. |
| topological_sort | Orders nodes in a directed acyclic graph (DAG). |
| disjoint_set (Union-Find) | Data structure for managing disjoint sets and connectivity. |
| kmp_search (Knuth-Morris-Pratt) | Efficient substring search using prefix tables. |
| rabin_karp_search | Substring search algorithm based on hashing. |
| longest_common_prefix | Finds the longest common prefix among a list of strings. |
| lowest_common_ancestor (LCA) | Finds the lowest common ancestor node in a tree. |
| validate_bst | Validates whether a binary tree is a binary search tree. |
| reverse_linked_list | Reverses a singly or doubly linked list. |
| detect_cycle (Floydโs Cycle Detection) | Detects cycles in a linked list. |
| mst_kruskal | Constructs a minimum spanning tree using Kruskal's algorithm. |
| mst_prim | Constructs a minimum spanning tree using Prim's algorithm. |
๐ค Contributing
Contributions are welcome!
- Add new algorithms or optimize existing ones
- Improve docs and examples
- Increase test coverage
Open a PR with a brief description and test cases.
๐บ๏ธ Roadmap (short-term)
- Expand graph algorithms (SPFA, Johnson, Edmonds-Karp, Dinic)
- Add tree/heap/DP/geometry modules
- Benchmarks and performance docs
๐ License
MIT. See LICENSE.
The most important sections of the library algorithms_core
backtracking algorithms
Tree.md Important to know the library structure algorithms core
Benchmark Report.md To view the library's benchmark results algorithms core
graph algorithms
dp algorithms
list advanced sorts
linked list algorithm
Libraries
- algorithms_core
- Support for doing something awesome.
- backtracking_algorithms/combination_sum
- backtracking_algorithms/combinations
- backtracking_algorithms/letter_combinations_phone_number
- backtracking_algorithms/n_queens
- backtracking_algorithms/permutations
- backtracking_algorithms/rat_in_a_maze
- backtracking_algorithms/subset_generation
- backtracking_algorithms/sudoku_solver
- backtracking_algorithms/word_search
- dp_algorithms/alternating_subsequences
- dp_algorithms/coin_change
- dp_algorithms/edit_distance
- dp_algorithms/fibonacci_memoization
- dp_algorithms/house_robber
- dp_algorithms/jump_game
- dp_algorithms/knapsack_01
- dp_algorithms/longest_common_subsequence
- dp_algorithms/longest_increasing_subsequence
- dp_algorithms/matrix_path_sum
- dp_algorithms/partition_equal_subset_sum
- dp_algorithms/rod_cutting
- dp_algorithms/subset_sum
- graph_algorithms/articulation_points
- ๐งฉ Articulation Points (Cut Vertices)
- graph_algorithms/bellman_ford
- ๐งฎ Bellman-Ford Algorithm (Single-Source Shortest Paths)
- graph_algorithms/bfs
- ๐ฏ Breadth-First Search (BFS)
- graph_algorithms/bipartite_graph
- ๐จ Bipartite Graph Check (Two-Coloring via BFS)
- graph_algorithms/bridge_finding
- graph_algorithms/chinese_postman
- graph_algorithms/connected_components
- ๐ Connected Components (Undirected)
- graph_algorithms/cycle_detection
- โป๏ธ Cycle Detection
- graph_algorithms/dfs
- ๐งญ Depth-First Search (DFS)
- graph_algorithms/dijkstra
- ๐ฆ Dijkstra's Algorithm (Single-Source Shortest Paths)
- graph_algorithms/dinics_algorithm
- graph_algorithms/edmonds_karp
- graph_algorithms/eulerian_path
- graph_algorithms/floyd_warshall
- ๐ Floyd-Warshall (All-Pairs Shortest Paths)
- graph_algorithms/graph_coloring
- graph_algorithms/hamiltonian_path
- graph_algorithms/hierholzer
- graph_algorithms/johnsons_algorithm
- graph_algorithms/kosaraju_scc
- ๐ Kosaraju's Algorithm (Strongly Connected Components)
- graph_algorithms/mst_kruskal
- ๐ฒ Kruskal's Algorithm (Minimum Spanning Tree/Forest)
- graph_algorithms/mst_prim
- ๐ฟ Prim's Algorithm (Minimum Spanning Tree/Forest)
- graph_algorithms/shortest_path
- ๐ค๏ธ Shortest Path (Unweighted) via BFS
- graph_algorithms/spfa
- graph_algorithms/stoer_wagner_min_cut
- graph_algorithms/tarjans_scc
- graph_algorithms/topological_sort
- โ๏ธ Topological Sort (Kahn's Algorithm)
- graph_algorithms/transitive_closure
- graph_algorithms/tree_diameter
- graph_algorithms/union_find
- ๐ Union-Find (Disjoint Set Union, DSU)
- graph_algorithms/weighted_edge
- ๐งฑ Weighted Edge
- graph_algorithms/yens_algorithm
- linked_list_algorithms/add_two_numbers_linked_list
- โ Add Two Numbers (Linked List Representation)
- linked_list_algorithms/convert_binary_linked_list_to_int
- ๐ข Convert Binary Number in Linked List to Integer
- linked_list_algorithms/detect_and_remove_loop
- ๐ Detect and Remove Loop in Linked List
- linked_list_algorithms/detect_cycle
- ๐ Cycle Detection Algorithms (Floyd's Algorithm)
- linked_list_algorithms/doubly_linked_list_node
- ๐๐ Generic Doubly Linked List Node
- linked_list_algorithms/insert_delete_at_position
- ๐ Insert and Delete at Position Algorithms
- linked_list_algorithms/intersection_detection_hashset
- ๐ Intersection Detection using HashSet
- linked_list_algorithms/intersection_of_lists
- ๐ Intersection of Two Linked Lists Algorithm
- linked_list_algorithms/linked_list_node
- ๐ Generic Linked List Node
- linked_list_algorithms/merge_sort_linked_list
- ๐ Sort Linked List (Merge Sort)
- linked_list_algorithms/merge_sorted_lists
- ๐ Merge Sorted Linked Lists Algorithms
- linked_list_algorithms/palindrome_linked_list
- ๐ญ Palindrome Linked List Algorithm
- linked_list_algorithms/partition_list
- ๐ Partition Linked List
- linked_list_algorithms/remove_duplicates_sorted_list
- ๐ Remove Duplicates from Sorted Linked List
- linked_list_algorithms/remove_nth_from_end
- ๐๏ธ Remove Nth Node From End Algorithm
- linked_list_algorithms/reverse_linked_list
- ๐ Reverse Linked List Algorithms
- linked_list_algorithms/reverse_nodes_in_k_group
- ๐ Reverse Nodes in K-Group
- linked_list_algorithms/rotate_linked_list
- ๐ Rotate Linked List
- linked_list_algorithms/swap_nodes_in_pairs
- ๐ Swap Nodes in Pairs
- list_advanced_sorts/bitonic_sort
- list_advanced_sorts/bucket_sort
- list_advanced_sorts/comb_sort
- list_advanced_sorts/cycle_sort
- list_advanced_sorts/gnome_sort
- list_advanced_sorts/heap_sort
- list_advanced_sorts/lis_binary_search
- list_advanced_sorts/max_product_subarray
- list_advanced_sorts/odd_even_sort
- list_advanced_sorts/pancake_sort
- list_advanced_sorts/pigeonhole_sort
- list_advanced_sorts/quickselect
- list_advanced_sorts/radix_sort
- list_advanced_sorts/shell_sort
- list_advanced_sorts/stooge_sort
- list_algorithms/average_subarray
- list_algorithms/binary_search
- ๐ Generic Binary Search Algorithm
- list_algorithms/bubble_sort
- list_algorithms/counting_sort
- list_algorithms/find_duplicates
- list_algorithms/find_max_min
- list_algorithms/insertion_sort
- list_algorithms/kadanes_algorithm
- list_algorithms/linear_search
- list_algorithms/max_sum_subarray_of_size_k
- list_algorithms/merge_sort
- merge_sort.dart
- list_algorithms/min_sum
- list_algorithms/prefix_sum
- list_algorithms/quick_sort
- list_algorithms/remove_duplicates
- list_algorithms/reverse_list
- list_algorithms/rotate_array_right
- list_algorithms/selection_sort
- list_algorithms/two_sum_sorted
- map_algorithms/all_pairs_with_sum
- map_algorithms/anagram_checker
- map_algorithms/count_pairs_with_diff
- map_algorithms/find_subarrays_with_sum
- map_algorithms/first_non_repeated_element
- map_algorithms/frequency_count
- map_algorithms/group_anagrams
- map_algorithms/group_by_key
- map_algorithms/index_mapping
- map_algorithms/invert_map
- map_algorithms/length_of_longest_substring
- map_algorithms/lru_cache
- map_algorithms/merge_maps_conflict
- map_algorithms/min_window_substring
- map_algorithms/most_frequent_element
- map_algorithms/mru_cache
- map_algorithms/top_k_frequent
- map_algorithms/two_sum
- map_algorithms/word_frequency_ranking
- matrix_algorithms/flood_fill
- matrix_algorithms/island_count_bfs
- matrix_algorithms/island_count_dfs
- matrix_algorithms/matrix_rotation
- matrix_algorithms/path_sum
- matrix_algorithms/shortest_path_in_grid
- matrix_algorithms/spiral_traversal
- matrix_algorithms/surrounded_regions
- matrix_algorithms/word_search
- set_algorithms/disjoint_check
- set_algorithms/disjoint_set
- set_algorithms/find_intersection
- set_algorithms/has_duplicates
- set_algorithms/has_two_sum
- set_algorithms/has_unique_window
- set_algorithms/is_frequency_unique
- set_algorithms/list_to_set_preserve_order
- set_algorithms/multiset_operations
- set_algorithms/power_set
- set_algorithms/set_difference
- set_algorithms/subset_check
- set_algorithms/superset_check
- set_algorithms/symmetric_difference
- string_algorithms/anagram_checker
- string_algorithms/atoi
- string_algorithms/boyer_moore_search
- string_algorithms/brute_force_search
- string_algorithms/count_vowels_consonants
- string_algorithms/edit_distance
- string_algorithms/integer_roman
- string_algorithms/kmp_search
- string_algorithms/longest_common_prefix
- string_algorithms/longest_palindromic_substring
- string_algorithms/longest_repeating_substring
- string_algorithms/manacher_longest_palindrome
- string_algorithms/min_window_subsequence
- string_algorithms/palindrome_checker
- string_algorithms/rabin_karp_search
- string_algorithms/remove_consecutive_duplicates
- string_algorithms/reverse_string
- string_algorithms/rolling_hash
- string_algorithms/string_compression
- string_algorithms/string_permutations
- string_algorithms/z_algorithm
- tree_algorithms/balanced_tree_check
- ๐ณ Balanced Tree Checker
- tree_algorithms/binary_tree_node
- ๐ณ Generic Binary Tree Node
- tree_algorithms/bottom_top_view_binary_tree
- ๐ณ Bottom View and Top View of Binary Tree
- tree_algorithms/boundary_traversal
- ๐ณ Boundary Traversal of Binary Tree
- tree_algorithms/construct_tree_inorder_postorder
- ๐ณ Construct Binary Tree from Inorder and Postorder Traversal
- tree_algorithms/construct_tree_inorder_preorder
- ๐ณ Construct Binary Tree from Inorder and Preorder Traversal
- tree_algorithms/convert_sorted_array_to_bst
- ๐ณ Convert Sorted Array to Balanced BST
- tree_algorithms/count_full_nodes
- ๐ณ Count Full Nodes in a Binary Tree
- tree_algorithms/count_half_nodes
- ๐ณ Count Half Nodes in a Binary Tree
- tree_algorithms/count_leaf_nodes
- ๐ณ Count Leaf Nodes in a Binary Tree
- tree_algorithms/flatten_binary_tree_to_linked_list
- ๐ณ Flatten Binary Tree to Linked List (in-place, preorder)
- tree_algorithms/invert_tree
- ๐ณ Tree Inverter (Mirror Tree)
- tree_algorithms/level_order_traversal
- ๐ณ Level Order Traversal (BFS)
- tree_algorithms/lowest_common_ancestor
- ๐ณ Lowest Common Ancestor (LCA)
- tree_algorithms/lowest_common_ancestor_no_bst
- ๐ณ Lowest Common Ancestor in Binary Tree (not BST)
- tree_algorithms/morris_traversal
- ๐ณ Morris Traversal (Inorder Traversal without Stack or Recursion)
- tree_algorithms/path_sum_in_tree
- ๐ณ Path Sum in Binary Tree
- tree_algorithms/print_all_root_to_leaf_paths
- ๐ณ Print All Root-to-Leaf Paths in a Binary Tree
- tree_algorithms/threaded_binary_tree_traversal
- ๐ณ Threaded Binary Tree Traversal
- tree_algorithms/tree_depth
- ๐ณ Tree Depth/Height Calculator
- tree_algorithms/tree_diameter
- ๐ณ Tree Diameter Calculator
- tree_algorithms/tree_serialization
- ๐ณ Tree Serialization and Deserialization
- tree_algorithms/tree_traversals
- ๐ณ Binary Tree Traversal Algorithms
- tree_algorithms/validate_bst
- ๐ณ Binary Search Tree Validator
- tree_algorithms/vertical_order_traversal
- ๐ณ Vertical Order Traversal of Binary Tree
- tree_algorithms/zigzag_traversal
- ๐ณ Zigzag Level Order Traversal