Professional Documents
Culture Documents
Currency enchange
fractional knapsack
U Greedy Properties
4 Activity Selection
4
job scheduling
Greedy Algorithm
Accept the
offer
I
GOLDA 45 CPA I co
5 10
100 2 I 3
Indian currency 1 2,5 10 20,50 100 200 500 2000
I IT It Is É
Cash 5548 min number Coins notes to
s
of get required
Cash hmultiples coins are allowed
of fame
I 1 1
10
I Curenty 1 amount É
212,18 thou to
Sylve
l m discussed
18 10
32
1
n so I
greedy won't
work
1 10 34
a Fractional knapsack
K
you can consume kg of vegetables you can
eat any integral amount of item Man Proteinyou canget
vegetables
Eating complete item
protein gained bit f Raton
thebasis
Protein
Tomato
20kg 200P COP
kg 20 Loop of man
onion sokg72500
Apples 180 P 1201kg 15 1808
15kg Tomato 120kg72000
Onion 50kg 250 P JP kg us P
Class Pair C
int w
int P
double PPV
I Psuedo Code
int i m t i o i I
for Pair seem items i
if Coen k
w c
ans ans t rem Pj
K k se sem w
g
else Sem Ppu K
ans any A
K 20
break
I
g return ans
binarysearch
Greedy Properties greedy
40
for
min montalbobums
Based on what Parameter we want to applygreedy
I counter enamph
U most likely idea is incorrect
your
man Count
of task you can do
Note Start a task we need to complete
At Point time single task
any of
office is
missatiissi cricket
a
ya
a creaking a shopping
ending early
yoga running Meaning Shopping Slater
Hns
S
Correctness TaekA
n tasks
ji
Task B l
I
Tff
n tasks
D
D pentosks
class Pair
IPSweds code
init
int activityselection int started int end Ca
T.cc OCrelogne
S C OCN
II Pick all the non overlapping tasks
Usetum ans
Job Scheduling
I Given a tasks to complete
Deadline assigned
for each task day on or before we
can do task
FENI Parameter
a 3 100 Iodine
b I 19 a 3 100
C 2 27 b t 19
C 21 27
d I 25 d 1 2 25
e 3 30 e 31 1 30
Enz I 5
Job deadlineday Payment soot the basis
on
of deadline
a 3 5
I t 2 3 3 3
deadline I
C 3 6 Payment I 3 5 6 9
d 2 3
e s g
deadline I f g
deadline 3 t
Enz Tasks I 22 3 4 5 6 77 8 9 10
dead 2 I t I 4 5 4 5 5 2
Money 200 250 200 350300 100 250 600 400 150
of deadline
Steps Sort on the basis
Tasks 2 3 4 1 10 5 7 6 8 9
dead I 1 I 2 2 4 4 5 5 5
money 250 200 350 200 150 300 250 100 600 400
min near
It 5 I 300 400
250350
600
24
250
addthem
am 1900
I PSued code
minheap e int mh
Lint i ical it t
for
O
deadline fi mh sizes
if
i
T c Olalogal mh insert money
S C Ocn 3
else I
if I moneyCig smh Peek C
mh semovell
mh insert money i
g
3
U sum all the elements mh
of
a 3 100
b I 19
C 21 27
d 1 2 25
e BI 30
di
b c e d a
1 I 1 2 3
19 27 30 25 100