Grokking Algorithms



Download 6,4 Mb.
Pdf ko'rish
bet53/120
Sana21.12.2022
Hajmi6,4 Mb.
#893167
1   ...   49   50   51   52   53   54   55   56   ...   120
Bog'liq
Grokking Algorithms An Illustrated Guide for Programmers and Other

 
I
 
 
Breadth-irst search
Aha! Now the Golden Gate Bridge shows up. So it takes three steps to 
get from Twin Peaks to the bridge using this route.
here are other routes that will get you to the bridge too, but they’re 
longer (four steps). he algorithm found that the shortest route to the 
bridge is three steps long. his type of problem is called a 
shortest-path 
problem
. You’re always trying to ind the shortest something. It could 
be the shortest route to your friend’s house. It could be the smallest 
number of moves to checkmate in a game of chess. he algorithm to 
solve a shortest-path problem is called
breadth-irst search
.
To igure out how to get from Twin Peaks to the Golden Gate Bridge
there are two steps:
1. Model the problem as a graph.
2. Solve the problem using breadth-irst search.
Next I’ll cover what graphs are. hen I’ll go into breadth-irst search in 
more detail.
What is a graph?
A graph models a set of connections. For 
example, suppose you and your friends are 
playing poker, and you want to model who owes 
whom money. Here’s how you could say, “Alex 
owes Rama money.”


99
Breadth-irst search
he full graph could look something like this.
Alex owes Rama money, Tom owes Adit money, and so on. Each graph 
is made up of 
nodes
and 
edges
.
hat’s all there is to it! Graphs are made up of nodes and edges. A node 
can be directly connected to many other nodes. hose nodes are called 
its 
neighbors
. In this graph, Rama is Alex’s neighbor. Adit isn’t Alex’s 
neighbor, because they aren’t directly connected. But Adit is Rama’s and 
Tom’s neighbor.
Graphs are a way to model how diferent things are connected to one 
another. Now let’s see breadth-irst search in action.

Download 6,4 Mb.

Do'stlaringiz bilan baham:
1   ...   49   50   51   52   53   54   55   56   ...   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