Prim's Algorithm in C: Minimum Spanning Tree Implementation
Prim's algorithm builds a minimum spanning tree by adding the cheapest edge each step. See a tested C implementation and its O(V^2) complexity.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Prim's algorithm builds a minimum spanning tree by adding the cheapest edge each step. See a tested C implementation and its O(V^2) complexity.
Dijkstra's algorithm finds shortest paths from one vertex in a graph with non-negative weights. This guide gives a correct C implementation with path reconstruction.
Depth-first search uses a stack, breadth-first search uses a queue. See both traversals in C with complete code, complexity and use cases.
Learn how BFS works and build it in C with an adjacency list, a circular queue and shortest-path tracking, with checked allocations and O(V+E) time.
Bucket sort spreads values into range-based buckets, sorts each and joins them. See a complete C implementation with its complexity and trade-offs.
Radix sort orders integers digit by digit using a stable counting sort. See a complete, safe C implementation, its complexity and when it beats qsort.
Bubble sort is simple but O(n^2); quicksort averages O(n log n). See C code for both, a complexity table and when to use qsort.
Implement depth-first search in C with a recursive version and an explicit-stack version, on an adjacency list, with complexity and typical use cases.
Radix sort sorts digit by digit, bucket sort scatters values by range. See tested C implementations, complexity and when to use each.
Selection sort swaps the minimum into place; insertion sort inserts each element into a sorted prefix. See generic C code and a stability demo on records.
Selection sort does at most n-1 swaps but always n^2/2 comparisons; insertion sort is stable and O(n) on sorted data. Compare them with working C code.
Insertion sort in C shifts larger elements right and inserts each key into a sorted prefix. See the code, a trace, complexity and when to use it.
Learn how selection sort works in C with a complete, tested implementation, its O(n²) complexity and how it compares with other simple sorts.
Merge sort is stable with guaranteed O(n log n); quick sort is in place and usually faster. Compare them with tested C code and qsort advice.
Learn how quick sort works in C with a tested Lomuto partition implementation, O(log n) stack depth, complexity analysis and qsort usage.
Merge sort is a stable O(n log n) divide-and-conquer sort. See how it works and a complete C17 implementation with one reusable buffer.
A hash table is a general key-value structure, while a symbol table tracks identifiers and scopes in a compiler. See the difference with complete C code.
A symbol table maps identifiers to their type and scope inside a compiler. This guide implements a scoped hash-table version in C.
C has no built-in map, so you build one. See a complete hash table with chaining and resizing, and when to pick a tree or a library.
C has no built-in set type. This guide implements a growable hash set of integers with chaining and compares it with sorted arrays, bit sets and trees.