0% found this document useful (0 votes)
11 views29 pages

Lec7 Greedy Approach

Uploaded by

Warda Iftikhar
Copyright
© © All Rights Reserved
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)
11 views29 pages

Lec7 Greedy Approach

Uploaded by

Warda Iftikhar
Copyright
© © All Rights Reserved
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/ 29

Greedy Algorithms

Or
Greedy Approach

LECTURE 07
BY ENGR. SEEMA BUGHIO
Greedy Algorithms

Greedy algorithms are a class of algorithms that make locally optimal choices at each step
with the hope of finding a global optimum solution. In these algorithms, decisions are made
based on the information available at the current moment without considering the
consequences of these decisions in the future. The key idea is to select the best possible
choice at each step, leading to a solution that may not always be the most optimal but is often
good enough for many problems.
Example
Problem: Suppose we have to travel from A to B.
Condition: within 12hr S1: by walk
S2: by bike
S3: by car
S4: by train
S5: by flight

S3 & S4 are feasible solutions.


Feasible solution are solutions which satisfying the condition. There are more than
one feasible solutions of given problem.
Example
Problem: Suppose we have to travel from A to B.
Condition: within 12hr S1: by walk
S2: by bike
S3: by car
S4: by train
S5: by flight

If I say I want to cover this journey in minimum cost. So we say it is a minimization


problem.
So out of feasible solution one solution taking minimum cost [by train].
This is optimal solution.
A solution which satisfy objective of problem & which is already feasible and giving
me minimum cost, that is best result according to problem, is called optimal solution.
Greedy Method

Optimization problems are problems which demands or which requires either maximum
result or minimum result.
Greedy method is about solving optimization problems.
There are more approaches to solve Optimization problems :
 Greedy method
 Dynamic programming
 Branch and bound
Greedy Method
Greedy Approach In Real-life ….!

Route planning: GPS navigation systems use Greedy algorithms to find the shortest route between two
points, choosing the next step based on the shortest distance.
Resource allocation: In project management, resources are allocated to tasks based on their priority and
availability, using a Greedy approach to maximize efficiency.
Scheduling: When scheduling tasks or appointments, you might use a Greedy approach to prioritize the
most important or urgent tasks first.
Packing: When packing items into boxes or containers, you might use a Greedy approach to pack the
largest or heaviest items first.
Algorithms Follow Greedy Approach….!

1. Shortest Path:- Dijkstra's algorithm (DA)


2. Data Compression:- Huffman coding algorithm (HCA)
3. Packing:- Knapsack algorithm (KA)
4. Job-Scheduling algorithms
Shortest Path:- Dijkstra's algorithm
Dijkstra's algorithm

 Dijkstra's algorithm is often considered to be the most straightforward algorithm for


solving the shortest path problem.
 Dijkstra's algorithm is used for solving single-source shortest path problems for directed
or undirected paths. Single-source means that one vertex is chosen to be the start, and the
algorithm will find the shortest path from that vertex to all other vertices.
Dijkstra's algorithm
Dijkstra's algorithm
Dijkstra's algorithm
Dijkstra's algorithm

UPDATED:-
Dijkstra's algorithm
Dijkstra's algorithm
Dijkstra's algorithm

UPDATED:-
Dijkstra's algorithm
Dijkstra's algorithm
Dijkstra's algorithm

UPDATED:-
Dijkstra's algorithm
Dijkstra's algorithm

UPDATED:-
Dijkstra's algorithm
Dijkstra's algorithm

UPDATED:-
Dijkstra's algorithm
Dijkstra's algorithm
Dijkstra's algorithm
Time Complexity

Build heap (Q)= o(n)


Extract-min from Q = 0(LOGN)

0(V-1)
0(V)
0(1)

v.Log v

E.logv
THANK YOU

You might also like