C program to create a subsets using backtracking method.

The subset sum problem asks: given a set of integers and a target sum, find all subsets of the set whose elements add up to the target. It is a classic application of backtracking — a systematic method that builds candidates incrementally and abandons a partial candidate (“prunes”) as soon as it determines the candidate …

DFS Program in C – Depth First Search with Example

Depth First Search (DFS) is a graph traversal algorithm that explores as far as possible along each branch before backtracking. Starting from a source node, it follows one path all the way to a dead end, then backtracks and tries the next unvisited neighbor. DFS uses a stack — either an explicit one or the …

BFS Algorithm in C – Adjacency Matrix and List with Example

Breadth First Search (BFS) is a graph traversal algorithm that explores nodes level by level — starting from a source, it visits all immediate neighbors first, then their neighbors, and so on. Because of this level-by-level behavior, BFS always finds the shortest path in an unweighted graph. It is used in GPS navigation, social network …

Dijkstra’s Algorithm in C – Shortest Path with Step-by-Step Trace

Dijkstra’s algorithm finds the shortest path from one source vertex to all other vertices in a weighted graph with non-negative edge weights. It is a greedy algorithm: at each step it picks the unvisited vertex with the smallest known distance, marks it done, and relaxes its neighbours — updating any neighbour’s distance if a shorter …

0-1 Knapsack Problem in C – DP Solution with Table Trace

The 0-1 knapsack problem asks: given a set of items each with a weight and a value, and a knapsack with a maximum weight capacity, which items should you pack to maximize the total value? Each item can be taken once (0-1) — you cannot take a fraction. This is a classic dynamic programming problem …