Greedy Algorithm: Dynamic Programming Kruskal's Minimum Spanning Trees Dijkstra's

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

GREEDY ALGORITHM

A greedy algorithm can be proven to yield the


global optimum for a given problem class,
it typically becomes the method of choice
because it is faster than other optimisation
methods like dynamic programming.
Examples of such greedy algorithms are
Kruskal's algorithm and Prim's algorithm for
finding minimum spanning trees, Dijkstra's
algorithm for finding single-source shortest
paths, and the algorithm for finding optimum
Huffman trees.

HUFFMAN ENCODING
The Huffman encoding algorithm is a
greedy algorithm
You always pick the two smallest numbers
to combine

The Huffman algorithm finds


an optimal solution

MINIMUM SPANNING TREE


A minimum spanning tree is a least-cost subset of
the edges of a graph that connects all the nodes
Start by picking any node and adding it to the tree
Repeatedly: Pick any least-cost edge from a node in the tree to
a node not in the tree, and add the edge and new node to the
tree
Stop when all nodes have been added to the tree

You might also like