0% found this document useful (0 votes)
58 views

Greedy Algorithms

Greedy algorithms are algorithms that make locally optimal choices at each step to arrive at a global optimum. They are composed of steps that are feasible, locally optimal, and irrevocable. For a greedy algorithm to be correct, locally optimal choices must lead to a globally optimal solution. Two common algorithms for finding minimum spanning trees are Prim's and Kruskal's algorithms, which run in O(E log V) time when using a min-heap priority queue.

Uploaded by

hiranhl
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Greedy Algorithms

Greedy algorithms are algorithms that make locally optimal choices at each step to arrive at a global optimum. They are composed of steps that are feasible, locally optimal, and irrevocable. For a greedy algorithm to be correct, locally optimal choices must lead to a globally optimal solution. Two common algorithms for finding minimum spanning trees are Prim's and Kruskal's algorithms, which run in O(E log V) time when using a min-heap priority queue.

Uploaded by

hiranhl
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

GREEDY ALGORITHMS

HIRAN H L FUS 100608 DEPT.OF FUTURES STUDIES

A greedy algorithm is a sequence of steps, where each step leads to a partial solution to the problem.
Each step must be: - feasible: i.e., it does not violate the problems rules. - locally optimal: i.e., it leads to the best choice at the current stage. - irrevocable: i.e., once a decision is made, it is never changed (no backtracking). In order for a greedy algorithm to be correct, the problem must satisfy the following property: local optimal choices lead to a globally optimal solution.

Minimum spanning tree


Spanning tree: A spanning tree of a connected graph G(V,E) is a connected acyclic2 subgraph3 of G. A minimum spanning tree of a weighted connected graph is a spanning tree with a minimum weight, where the weight of a graph is the sum of the weights of its edges. How can we find a minimum spanning tree of a connected weighted graph?

When the priority queue is implemented using min-heap, Enqueue, De-queue, and Update operations of the priority queue take O(log |V |) time. Prims algorithm has |V | Enqueue operations, |V | Dequeue operations, and at most |E| Update operations. Therefore, the running time for Prims algorithm is (2|V | + |E|)O(log |V |) O(|E| log |V |).

Kruskals algorithm

When the priority queue is implemented using min-heap, Enqueue, Dequeue, and Update operations of the priority queue take O(log |V |) time. Prims algorithm has |V | Enqueueoperations, |V | Dequeue operations, and at most |E| Update operations. Therefore, the running time for Prims algorithm is (2|V | + |E|)O(log |V |) O(|E| log |V |).

THANK YOU

You might also like