Grokking Algorithms



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

Chapter 7
 
 
I
 
 
Dijkstra’s algorithm
You’ll keep updating this table as the algorithm goes on. To calculate the 
inal path, you also need a 
parent
column on this table.
I’ll show you how this column works soon. Let’s start the algorithm.
Step 1:
Find the cheapest node. In this case, the poster is the cheapest 
trade, at $0. Is there a cheaper way to trade for the poster? his is a 
really important point, so think about it. Can you see a series of trades 
that will get Rama the poster for less than $0? Read on when you’re 
ready. Answer: No. 
Because the poster is the cheapest node Rama can get 
to, there’s no way to make it any cheaper.
Here’s a diferent way to look at 
it. Suppose you’re traveling from home to work.
If you take the path toward the school, that takes 2 minutes. If you take 
the path toward the park, that takes 6 minutes. Is there any way you can 
take the path toward the park, and end up at the school, in less than 
2 minutes? It’s impossible, because it takes longer than 2 minutes just 
to get to the park. On the other hand, can you ind a faster path to the 
park? Yup.


125
Trading for a piano
his is the key idea behind Dijkstra’s algorithm: 
Look at the cheapest 
node on your graph. here is no cheaper way to get to this node!
Back to the music example. he poster is the cheapest trade.
Step 2:
Figure out how long it takes to get to its neighbors (the cost).
You have prices for the bass guitar and the drum set in the table. heir 
value was set when you went through the poster, so the poster gets set 
as their parent. hat means, to get to the bass guitar, you follow the edge 
from the poster, and the same for the drums.

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   60   61   62   63   64   65   66   67   ...   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