Grokking Algorithms



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

Breadth-irst search
We looked at a search algorithm in chapter 1: binary search. Breadth-
irst search is a diferent kind of search algorithm: one that runs on 
graphs. It can help answer two types of questions:
• Question type 1: Is there a path from node A to node B?
• Question type 2: What is the shortest path from node A to node B?
Graph of people who owe
other people poker money


100
Chapter 6
 
 
I
 
 
Breadth-irst search
You already saw breadt
h-irst search once, when you calculated the 
shortest route from Twin Peaks to the Golden Gate Bridge. hat was 
a question of type 2: “What is the shortest path?” Now let’s look at the 
algorithm in more detail. You’ll ask a question of type 1: “Is there a 
path?”
Suppose you’re the proud owner of a mango farm. You’re looking for a 
mango seller who can sell your mangoes. Are you connected to a mango 
seller on Facebook? Well, you can search through your friends.
his search is pretty straightforward.
First, make a list of friends to search.


101
Breadth-irst search
Now, go to each person in the list and check whether that person sells 
mangoes.
Suppose none of your friends are mango sellers. Now you have to 
search through your friends’ friends.
Each time you search for someone from the list, add all of their friends 
to the list.


102
Chapter 6
 
 
I
 
 
Breadth-irst search
his way, you not only search your friends, but you search their friends, 
too. Remember, the goal is to ind one mango seller in your network. 
So if Alice isn’t a mango seller, you add her friends to the list, too. hat 
means you’ll eventually search her friends—and then their friends, and 
so on. With this algorithm, you’ll search your entire network until you 
come across a mango seller. his algorithm is breadth-irst search.

Download 6,4 Mb.

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