The Ford-Fulkerson algorithm is a method that resolves the max-flow min-cut problem. That is, given a network with vertices and edges between those vertices that have certain weights, how much “flow” can the network process at a time? Flow can mean anything, but typically it means data through a computer network.
When the capacities are integers, the runtime of Ford–Fulkerson is bounded by O ( E *f ).
Ford-Fulkarson’s algorithm
Given a graph which represents a flow network where every edge has a capacity. Also given two vertices source ‘s’ and sink ‘t’ in the graph, find the maximum possible flow from s to t with following constraints:
Flow on an edge doesn’t exceed the given capacity of the edge.
Incoming flow is equal to outgoing flow for every vertex except s and t.
The maximum possible flow in the above graph is 23.
Program in C :
Output:
Please comment below in case of any problem found during running the code or any other doubts.
Prim’s algorithm to find the minimum cost spanning tree of for a weighted undirected graph, uses the greedy approach. Prim’s algorithm, in contrast with Kruskal’s algorithm, treats the nodes as a single tree and keeps on adding new nodes to the spanning tree from the given graph.
Prim’s algorithm
Initialize a tree with a single vertex, chosen arbitrarily from the graph.
Grow the tree by one edge: of the edges that connect the tree to vertices not yet in the tree, find the minimum-weight edge, and transfer it to the tree.
Repeat step 2 (until all vertices are in the tree).
The time complexity of Prim’s algorithm depends on the data structures used for the graph and for ordering the edges by weight, which can be done using a priority queue.
The average runtime= O((n+e)log n), where n=number of vertices, and e= number of edges.
Program in C :
Output:
Please comment below in case of any problem found during running the code or any other doubts.