Introduction to Algorithms, Third Edition



Download 4,84 Mb.
Pdf ko'rish
bet394/618
Sana07.04.2022
Hajmi4,84 Mb.
#534272
1   ...   390   391   392   393   394   395   396   397   ...   618
Bog'liq
Introduction-to-algorithms-3rd-edition

Lemma 22.3
Suppose that during the execution of BFS on a graph
G
D
.V; E/
, the queue
Q
contains the vertices
h
1

2
; : : : ; 
r
i
, where
1
is the head of
Q
and
r
is the tail.
Then,
r
:
d
1
:
d
C
1
and
i
:
d
i
C
1
:
d
for
i
D
1; 2; : : : ; r
1
.
Proof
The proof is by induction on the number of queue operations. Initially,
when the queue contains only
s
, the lemma certainly holds.
For the inductive step, we must prove that the lemma holds after both dequeuing
and enqueuing a vertex. If the head
1
of the queue is dequeued,
2
becomes the
new head. (If the queue becomes empty, then the lemma holds vacuously.) By the
inductive hypothesis,
1
:
d
2
:
d
. But then we have
r
:
d
1
:
d
C
1
2
:
d
C
1
,
and the remaining inequalities are unaffected. Thus, the lemma follows with
2
as
the head.
In order to understand what happens upon enqueuing a vertex, we need to ex-
amine the code more closely. When we enqueue a vertex
in line 17 of BFS, it
becomes
r
C
1
. At that time, we have already removed vertex
u
, whose adjacency
list is currently being scanned, from the queue
Q
, and by the inductive hypothesis,
the new head
1
has
1
:
d
u:
d
. Thus,
r
C
1
:
d
D
:
d
D
u:
d
C
1
1
:
d
C
1
. From
the inductive hypothesis, we also have
r
:
d
u:
d
C
1
, and so
r
:
d
u:
d
C
1
D
:
d
D
r
C
1
:
d
, and the remaining inequalities are unaffected. Thus, the lemma
follows when
is enqueued.
The following corollary shows that the
d
values at the time that vertices are
enqueued are monotonically increasing over time.
Corollary 22.4
Suppose that vertices
i
and
j
are enqueued during the execution of BFS, and
that
i
is enqueued before
j
. Then
i
:
d
j
:
d
at the time that
j
is enqueued.
Proof
Immediate from Lemma 22.3 and the property that each vertex receives a
finite
d
value at most once during the course of BFS.
We can now prove that breadth-first search correctly finds shortest-path dis-
tances.

Download 4,84 Mb.

Do'stlaringiz bilan baham:
1   ...   390   391   392   393   394   395   396   397   ...   618




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