Grokking Algorithms



Download 6,4 Mb.
Pdf ko'rish
bet65/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   61   62   63   64   65   66   67   68   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

Step 1 again:
he LP is the next cheapest node at $5.
Step 2 again:
Update the values of all of its neighbors.
Hey, you updated the price of both the drums and the guitar! hat 
means it’s cheaper to get to the drums and guitar by following the edge 
from the LP. So you set the LP as the new parent for both instruments.


126
Chapter 7
 
 
I
 
 
Dijkstra’s algorithm
he bass guitar is the next cheapest item. Update its neighbors.
Ok, you inally have a price for the piano, by trading the guitar for the 
piano. So you set the guitar as the parent. Finally, the last node, the 
drum set.
Rama can get the piano even cheaper by trading the drum set for the 
piano instead. 
So the cheapest set of trades will cost Rama $35
.
Now, as I promised, you need to igure out the path. So far, you know 
that the shortest path costs $35, but how do you igure out the path? To 
start with, look at the parent for
piano
.
he piano has drums as its parent. hat means Rama trades the drums 
for the piano. So you follow this edge.


127
Trading for a piano
Let’s see how you’d follow the edges. 
Piano
has 
drums
as its parent.
And 
drums
has the LP as its parent.
So Rama will trade the LP for the drums. And of course, he’ll trade the 
book for the LP. By following the parents backward, you now have the 
complete path.
Here’s the series of trades Rama needs to make.


128
Chapter 7
 
 
I
 
 
Dijkstra’s algorithm
So far, I’ve been using the term 
shortest path 
pretty literally: calculating 
the shortest path between two locations or between two people. I
hope this example showed you that the shortest path doesn’t have to
be about physical distance. It can be about minimizing something. In 
this case, Rama wanted to minimize the amount of money he spent. 
hanks, Dijkstra!

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   61   62   63   64   65   66   67   68   ...   120




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish