Greedy Algorithms
Greedy Algorithms
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.
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