You are on page 1of 47

th

th l mt cu trc lu tr rt quan trng. Chng c th c s dng


gii quyt nhng bi ton phc tp nh bi ton thit k v phn tuyn cho
ng bay, hoc bi ton v tm ng truyn tin ngn nht trong mt mng
my tnh.
Thut ng
th l mt tp hp cc node, gi l nh, v mt tp hp cc ng ni gia
cc nh , gi l cnh. Ni cch khc, th bao gm 2 tp, tp nh v tp
cnh. th c th c hng hoc v hng. th gi l c hng nu mi cnh
ca chng c chiu xc nh, trong khi th v hng, c 2 chiu ca mt
cnh u c th i c. Hnh 12-1 l mt v d v th c hng (a) v mt
th v hng (b).

HNH 12-1: TH C HNG V V HNG
Hai nh trong th c gi l k nhau nu tn ti mt cnh trc tip ni
gia chng. Trong hnh 12-1, A v B k nhau cn D v F th khng.
th l mt tp hp cc node gi l nh v tp hp cc ng gi l cnh,
ni gia hai nh.
ng i (path) l mt chui cc nh k nhau. Trong hnh 12-1, {A, B, C, E} v
{A, B, E, F} l nhng ng i. Ch rng c th c hng v v hng u c
ng i. ng i trong th v hng c th i c c 2 chiu.
Chu trnh (cycle) l mt ng i c t nht 3 nh v ng i ny bt u v
kt thc ti cng mt nh. Trong hnh 12-1(b) B, C, D, E, B l mt chu trnh.
Vnh khuyn (loop) l mt trng hp c bit ca chu trnh trong mt
cnh n bt u v kt thc ti cng mt nh.
th c th c hng hoc v hng. Trong th c hng, mi cnh c
mt chiu xc nh. Trong th v hng, mi cnh c th i c c 2 chiu.
Hai nh c gi l lin thng (connected) nu c mt ng i gia chng.
Mt th c gi l lin thng nu b qua hng th gia hai nh bt kz u
c ng i. Trong th c hng cn c thm hai khi nim l lin thng mnh
(strong connected) v lin thng yu (weakly connected). Mt th c hng
c gi l lin thng mnh nu gia hai nh bt kz trong th lun c mt
ng i (xt c hng). th c hng gi l lin thng yu nu c t nht hai
nh khng lin thng.
Bc (degree) ca mt nh c xc nh l s cnh ni vi nh . Trong hnh
12-2(a), bc ca nh B l 3 v ca E l 4. Bc ra (outdegree) ca mt nh trong
th c hng l s canh c hng ri khi nh ; bc vo (indegree) ca mt
nh trong th c hng l s cnh c hng i vo nh . Mt ln na,
trong hnh 12-2(a) bc vo v bc ra ca nh B ln lt l 1 v 2; trong hnh 12-
2(b) bc vo v bc ra ca nh E l ln lt l 3 v 1.

HNH 12-2: TH LIN THNG V TCH RI
Php ton
Trong phn ny chng ta s nh ngha su php ton chnh yu nht, cung cp
nhng module c bn thao tc trn th: thm nh, xa nh, thm cnh,
xa cnh, tm mt nh, v duyt th.
Thm nh
Add vertex thm mt nh mi vo th. Khi nh mi ny c thm vo n
tch ri vi phn cn li ca th, ngha l n khng ni vi bt c nh no
trong danh sch nh. Thc t qu trnh thm ny ch l bc u tin trong php
ton chn. Sau khi thm nh mi vo, n phi c ni vi cc nh cn li trong
th. Hnh 12-3 th hin trng thi ca th trc v sau khi thc hin thm
nh.
Xa nh
Delete vertex xa mt nh khi th. Khi nh ny b xa i, hin nhin tt c
cc cnh ni vi n cng b loi b khi th. Hnh 12-4 l mt v d v xa nh.
Chn cnh
Add edge thm cnh ni hai nh vi nhau. lm c iu ny, vic u tin
phi xc nh c hai nh cn ni. c bit trong th c hng ta phi bit
c nh ngun (source) v nh ch (destination). Hnh 12-5 th hin qu trnh
thm cnh {A, E} vo th.

HNH 12-3: CHN NH

HNH 12-4: XA NH

HNH 12-5: CHN CNH
Xa cnh
Delete edge xa cnh khi th. Trong hnh 12-6 l mt v d xa cnh {A, E}
ra khi th.
Tm nh
Find vertex duyt qua ht th tm mt nh cho trc. Nu tm thy, d
liu cha trong nh s c tr, ngc li th thng bo li. Trong hnh 12-7 l
qu trnh duyt th tm ra nh C.
Duyt th (traversal graph)
Thc t lun c nhng chng trnh i hi vic duyt qua tt c cc nh
trong mt th. Bi v mt nh trong th c th c nhiu nh cha nn vic
duyt th gp mt s rc ri m trong danh sch tuyn tnh hoc cy khng c.
c bit chng ta phi chc chn rng mi nh ch c duyt qua mt ln. Bi v
c nhiu ng i ti mt nh nn chng ta c th duyt qua nh bng
nhiu cch khc nhau. Gii php truyn thng cho vn ny l gn thm mt
c (flag) cho mi nh. Trc khi duyt, tt ht tt c cc c. Mi ln gh qua nh
no, ta bt c nh ln, m ch nh ny c duyt qua.

HNH 12-6: XA CNH

HNH 12-7: TM NH
Hai loi duyt th c bn l duyt u tin chiu su v duyt u tin chiu
rng.
Duyt u tin chiu su (depth-first-traversal)
Trong duyt u tin chiu su, ta gh qua tt c cc nh con chu trc khi di
chuyn sang cc nh k. Quy lut ny rt d nhn din trong cu trc cy. Hnh
12-8 cho thy qu trnh duyt cy tin th t, y cng l mt dng chun ca
duyt u tin chiu su.
Cng theo cch , thut ton duyt u tin chiu su duyt qua nh u tin
ca th. Sau ta chn mt nh k vi n v duyt ti. Lp li nh vy cho ti
khi no nh khng cn nh k no na. N cng ging nh th chng ta
duyt n node l ca mt cy. n y, thut ton phi quay ngc li v tip
tc duyt qua cc nh k b b qua. D thy thut ton ny cn dng ti mt
stack (hoc k thut quy) hin thc.
Trong duyt u tin chiu su, tt c cc con chu ca mt nh c duyt
trc khi di chuyn qua cc nh k vi n.

HNH 12-8: DUYT U TIN CHIU SU MT CY

HNH 12-9: DUYT U TIN CHIU SU CA MT TH
Chng ta th p dng thut ton ny trong th trong hnh 12-9. S nm bn
cnh mi nh cho bit th t c duyt.
1. Chng ta b nh u tin ca th vo trong stack.
2. Pop stack, x l{ nh ny, v push stack tt c cc nh k vi n
vo trong stack. Lp li qu trnh ny.
3. Cho n khi no stack rng th duyt xong.
Duyt u tin chiu rng (breadth-first-traversal)
Trong duyt u tin chiu rng, chng ta duyt qua tt c cc nh k trc khi
di chuyn n bc (level) tip theo. Nhn hnh 12-10, chng ta thy thut ton
duyt u tin chiu rng bt u t bc 0 ri sau qu tt c cc nh trong bc
1 trc khi qua bc 2.

HNH 12-10: DUYT U TIN CHIU RNG CA MT CY
Trong chng 7 chng ta thy k thut duyt u tin chiu rng s dng queue
thay v stack. Mi khi duyt qua mt nh, ta t tt c cc nh k vi n trong
mt queue. Ta th p dng thut ton ny trong th hnh 12-11.
1. Chng ta b nh u tin ca th vo trong queue.
2. Dequeue, x l{ nh ny, t tt c cc nh k vi n vo trong
queue. Lp li qu trnh ny.
3. Cho n khi no queue rng th duyt xong.
Trong duyt u tin chiu rng tt c cc nh k trc khi di chuyn qua cc
nh con chu.

HNH 12-11: DUYT U TIN CHIU RNG CA MT TH
Cu trc lu tr th
Ma trn k (adjacency matrix)
Ma trn k s dng mt vector (aray mt chiu) lu nh v mt ma trn
(array 2 chiu) lu cnh (hnh 12-12). Nu hai nh k nhau th giao ca hai
nh trong ma trn c gi tr bng 1, ngc li th bng 0.

HNH 12-12: MA TRN K
Trong phng php lu tr bng ma trn k, chng ta s dng mt vector
lu tr nh v mt ma trn lu tr cnh.
Mt hn ch l kch thc ca th phi c xc nh trc thi chng trnh
bt u, m mt ci quan trng na l ch c mt cnh ni gia hai nh c lu
tr, bi v mt s cu trc mng i hi nhiu cnh ni gia hai nh.
Danh sch k (adjacency list)
Danh sch k s dng array 2 chiu lu tr cnh. Hnh 12-13 l mt v d v
danh sch k.
Danh sch nh (vertex list) l mt danh sch lin kt n. Ty theo tng loi
chng trnh m n c th hin thc bng danh sch lin kt vng hoc kp. Con
tr tri ni cc nh li vi nhau. Con tr phi ch ti danh sch cc cnh t nh
.

HNH 12-13: DANH SCH K
Trong danh sch k, chng ta s dng danh sch lin kt lu tr nh v mt
danh sch 2 chiu lu tr cnh.
Gii thut trn th
Trong phn ny chng ta s i xy dng mt s gii thut chnh yu trong vic
to ta (create) v thao tc trn th c hng. Ngoi cc php ton c miu
t trong phn 12-2 cn c thm mt s khc, chng hn to mi th. Da vo
nhu cu ca th, mt s gii thut khc cng cn thit. V d phi c mt gii
thut tr v s lng nh hoc bc ra v bc vo ca mt nh xc nh trong
th.
Trc khi bt u i vo tm hiu gii thut, chng ta phi thit k mt cu trc
s dng lu tr th. Cu trc linh hot v uyn chuyn nht l danh sch
k c hin thc bng danh sch lin kt n. Ngoi nhng cu trc trong hnh
12-13, chng ta cn c thm cu trc u ca th (graphHead). graphHead lu
tr siu d liu (metadata) v danh sch. C th cu trc lu tr th c trnh
by trong hnh 12-14.

HNH 12-14: CU TRC D LIU CA TH
Ch rng d liu ca th, nu c, c lu tr trong tng nh. M gi ca
cu trc th c th hin trong thut gii 12-1
graphHead
count <integer>
first <pointer to graphVertex>
end graphHead

graphVertex
nextVertex <pointer to graphVertex>
data <dataType>
inDegree <integer>
outDegree <integer>
processed <0, 1, 2>
arc <pointer to first graphArc>
end graphVertex

graphArc
destination <pointer to graphVertex>
nextArc <pointer to graphArc>
end graphArc
THUT GII 12-1: CU TRC TH
Ngoi d liu v cc con tr, mi nh cn cha c bc ra v bc vo s
dng vo mt s thut gii sau ny. Khi xa mt nh, tt c cc cnh ch n nh
ny cn li c th khin cho chng trnh b li. V th thut gii xa nh phi
nhn bit c nh cn xa c cn cnh no ch n hay khng.
Cui cng l c processed c s dng trong qu trnh duyt th. N cho
bit mt nh ang ch c x l hoc x l xong ri.
To mi th
Create graph khi to siu d liu cho cu trc u (graphHead) ca th.
on m ca php ton ny c trong gii thut 12-2
algorithm createGraph (ref graph <metaData>)
Initializes the metadata elements of a garph structure.
Pre graph is a metadata structure
Post metadata elements have been initialized
1. count = 0
2. first = null
End createGraph
THUT GII 12-2: TO MI TH
Chn mt nh
Insert vertex thm mt nh c lp vo th. Cc cnh ni vi n phi c
thm mt cch ring bit trong nhng thut gii c trnh by phn sau. M
gi c trnh by trong thut gii 12-3.
algorithm insertVertex (ref graph <metadata>, val dataIn
<dataType>)
Allocates memeory for a new vertex and copies the data to
it.
Pre graph is a graph head structure
dataIn contains data to be inserted into vertex
Post new vertex allocated and data copied
Return +1 if successful
-1 if memory overflow
1. allocate (newPtr)
2. if (allocate successful)
1. newPtr->nextVertex = null
2. newPtr->data = dataIn
3. newPtr->inDegree = 0
4. newPtr->outDegree = 0
5. newPtr->processed = 0
6. newPtr->arc = null
7. graph.count = graph.count + 1
3. else
Out of memory
1. return -1
4. end if
Now find insertion point
5. locPtr = graph.first
6. if (locPtr null)
Empty graph. Insert at beginning.
1. graph.first = newPtr
7. else
1. predPtr = null
2. loop (locPtr not null AND dataIn.key > locPtr-
>data.key)
1. predPtr = locPtr
2. locPtr = locPtr->nextVertex
3. end loop
4. if (predPtr null)
Insert before first vertex
1. graph.first = newVertex
5. else
1. predPtr->nextVertex = newPtr
6. end if
7. newPtr->nextVertex = locPtr
8. end if
9. return 1
end insert Vertex
THUT GII 12-3: THM NH
y chng qua ch l gii thut chn c bn trong danh sch lin kt. Sau khi xin
cp b nh cho nh mi, chng ta di chuyn d liu vo v t tt c siu d liu
ca n v null.
Bi v th khng cha mt cu trc cho header, chng ta phi xt ring n
trng hp chn vo mt th rng (null graph) v trng hp chn vo ngay
trc nh u tin. Chn vo mt danh sch null c m t trong m lnh 6.1.
Chn trc nh u tin c m t trong m lnh 7.4.1.
iu cui cng cn phi ch trong phn ny l gi tr tr v. Nu chn thnh
cng, ta tr v 1. Ta s dng gi tr ny xuyn sut cc gii thut cn li ch
thc hin thnh cng. Nu b nh y (overflow) th tr v -1. Khi cc bn xem
cc thut gii cn li. Cc bn s nhn ra rng cc gi tr tr v thng bo li u l
nhng s m. Chng hn cc bn bit -1 ch b nh y, -2 khi khng tm thy
gi tr cho trc.
Xa nh
Vic u tin trong thut gii ny l phi tm c nh mun xa. Sau kim
tra th n c c lp vi th hay khng, ngha l chc chn rng khng c cnh
no ni vi n. Nu c th khng th thc hin c. M gi c trnh by trong
thut gii 12-4.
algorithm deleteVertex (ref graph <metadata>, val key
<keyType>)
Deletes an existing vertex only if its degree is 0.
Pre graph is a pointer to a graph head structure
Key is the key of the vertex to be deleted
Post vertex deleted (if degree zero)
Return +1 if successful
-1 if degree not zero
-2 if key not found
1. if (graph.first full)
1. return -2
2. end if
Locate vertex to be deleted
3. predPtr = null
4. locnPtr = graph.first
5. loop (locnPtr not null AND key > locnPtr->data.key)
1. predPtr = locnPtr
2. locnPtr = locnPtr->nextVertex
6. end loop
7. If (locnPtr null OR key not equal locnPtr->data.key)
1. return -2
8. end if
Found vertex to be deleted. Test degree.
9. if (locnPtr->inDegree > 0 OR locnPtr->outDegree > 0)
1. return -1
10. end if
Okay to delete vertex
11. if (predPtr null)
1. graph.first = locnPtr->nextVertex
12. else
1. predPtr->nextVertex = locnPtr->nextVertex
13. end if
14. graph.count = graph.count 1
15. recycle (locnPtr)
16. return 1
end deleteVertex
THUT GII 12-4: XA NH
y cng ging nh thut gii xa c bn trong danh sch lin kt. Ch c mt
ci phc tp l chng ta khng th xa mt nh nu bc ca n ln hn 0. Do
chng ta phi kim tra bc ra v bc vo ca nh ny nh trong m lnh 9.
Chn cnh
Mt khi ta c mt nh, ta cng c th ni nh ny vi cc nh khc bng cch
thm cnh. lm c iu nay, trc tin chng ta phi bit c hai thng
tin: nh ngun (fromPtr) v nh ch (toPtr). Mi nh c xc nh thng qua
kha (key) ca n thay v ia ch vt l. M gi ca gii thut ny c trnh by
trong gii thut 12-5.
algorithm insertArc (ref graph <metadat>, val fromKey
<keyType>, val toKey <keyType>)
Adds an arc between two vertices..
Pre graph is graph head structure
fromKey is the key of originating vertex
toKey is the key of the destination vertex
Post arc added to adjacency list
Return +1 if successful
-1 if memory overflow
-2 if fromKey not found
-3 if toKey not found
1. allocate (newPtr)
2. if (allocate fails)
1. return -1
3. end if
Locate source vertex
4. fromPtr = graph.first
5. loop (fromPtr not null AND fromKey > fromPtr-
>data.key)
1. fromPtr = fromPtr->nextVertex
6. end loop
7. if (fromPtr null OR fromKey not equal fromPtr-
>data.key)
1. return -2
8. end loop
Now locate to vertex
9. toPtr = graph.first
10. loop (toPtr not null AND toKey > toPtr->data.key)
1. toPtr = toPtr->nextVertex
11. end loop
12. if (toPtr null OR toKey not equal toPtr->data.key)
1. return -3
13. end if
From and to vertices located Insert new Arc.
14. fromPtr->outDegree = fromPtr->outDegree + 1
15. toPtr->inDegree = toptr->inDegree + 1
16. newPtr->destination = toPtr
17. if (fromPtr->arc null)
Inserting first arc
1. fromPtr->arc = newPtr
2. newPtr->nextArc = null
3. return 1
18. end if
Find insertion point in adjacency (arc) list
19. arcPredPtr = null
20. arcWalkPtr = fromPtr->arc
21. loop (arcWalkPtr not null AND toKey >= arcWalkPtr-
>destination->data.key)
1. arcPredPtr = arcWalkPtr
2. arcWalkPtr = arcWalkPtr->nextArc
22. end loop
23. if (arcPredPtr null)
Insertion before first arc
1. fromPtr->arc = newPtr
24. else
1. arcPredPtr->nextArc = newPtr
25. end if
26. newPtr->nextArc = arcWalkPtr
27. return 1
end insertArc
THUT GII 12-5: CHN CNH
Gii thut kh di. Chng ta bt u bng vic xin cp b nh cho cnh mi.
Nu khng b nh, ngay lp tc tr v -1.
Sau chng ta i xc nh nh ngun v nh ch cho cnh ny. N ging
nh bi ton tm kim trong danh sch lin kt. Nu mt trong hai thng tin ny
khng c tm thy, ta tri v gi tr -2 (nh ngun) hoc -3 (nh ch).Tip
theo cp nht gi tr bc ca nh v t con tr vo nh ch. V gi chng ta
sn sng thm cnh mi ny vo danh sch.
Xa cnh
Xa mt cnh khi danh sch k. mt cnh xc nh, ta cn c hai nh. nh
c xc nh thng qua kha (key) ca n. Bi vy thut gii bt u bng vic
tm nh ngun v nh ch trong danh sch k. Sau khi xa cnh i, bc ca hai
nh ny phi c cp nht v gii phng b nh. M gi c trnh by trong
gii thut 12-6.
algorithm deleteArc (ref graph <metadata>, val fromKey
<keyType>, val toKey <keyType>)
Deletes an arc between two vertices.
Pre graph is a pointer to a graph head structure
fromKey is the key of the originating vertex
toKey is the key of the destination vertex
Post arc deleted
Return +1 if successful
-2 if fromKey not found
-3 if toKey not found
1. if (graph.first null)
1. return -2
2. end if
Locate source vertex
3. fromVertex = graph.first
4. loop (fromVertex not null AND fromKey > fromVertex-
>data.key)
1. fromVertex = fromVertex->nextVertex
5. end loop
6. if (fromVertex null OR fromKey < fromVertex->data.key)
1. return -2
7. end if
Locate destination vertex in adjacency list
8. if (fromVertex->arc null)
1. return -3
9. end if
10. predPtr = null
11. arcPtr = fromVertex->arc
12. loop (arcPtr not null AND toKey > arcPtr-
>destiantion->data.key)
1. prePtr = arcPtr
2. arcPtr = arcPtr->nextArc
13. end loop
14. if (arcPtr null OR toKey < arcPtr->destination-
>data.key)
1. return -3
15. end if
16. toVertex = arcPtr->destination
fromVertex, toVertex, and arcPtr all located. Delete arc.
17. fromVertex->outDegree = fromVertex->outDegree 1
18. toVertex->inDegree = toVertex->inDegree 1
19. if (prePtr null)
Deleting first arc
1. fromVertex->arc = arcPtr->nextArc
20. else
1. prePtr->nextArc = arcPtr->nextArc
21. end if
22. recycle (arcPtr)
23. return 1
end deleteArc
THUT GII 12-6: XA CNH
C ba phn chnh trong thut gii: (1) xc nh nh ngun, (2) xc nh nh
ch, v (3) xa cnh. nh ngun c tm trong danh sch nh (vertex list). Sau
, da vo danh sch k ta tm tip nh ch. Cui cng ta n gin xa cnh v
hiu chnh bc ca cc nh c lin quan.
Truy xut nh
Retrieve vertex tr v gi tr c lu tr trong nh. Cho trc kha (key) ca
nh cn truy xut, sau khi thc hin xong thut ton, d liu s c tr v
thng qua bin c nh trc. M gi c trnh by trong gii thut 12-7.
algorithm retrieveVertex (ref graph <metadata>, val key
<keyType>, ref dataOut <dataType>)
Data contained in vertex identified by key passed to
caller.
Pre graph is a pointer to a graph head to caller.
key is the key of the vertex data
Post vertex data copied to dataOut
Retrun +1 if successful
-2 if key not found
1. if (graph.first null)
1. return -2
2. end if
3. locnPtr = graph.first
4. loop (locnPtr not null AND key > locnPtr->data.key)
1. locnPtr = locnPtr->nextVertex
5. end loop
6. if (key equal locnPtr->data.key AND locnPtr is not
null)
1. dataOut = locnPtr->data
2. return 1
7. else
1. return -2
8. end if
end retrieveVertex
THUT GII 12-7: TRUY XUT MT NH
Truy xut nh thc cht cng ging nh thut ton tm kim trong danh sch
lin kt. Nu thnh cng, d liu ca nh c t bin cho trc v gi tr
(+1) c tr v. Nu danh sch null hoc khng th tm c d liu hoc kha
(key), tr v (-2).
Cnh u tin (first arc)
Nhng cnh ni vi mt nh c sp xp trong danh sch k theo th t
tng dn. Do thut gii ny tr v nh ch vi kha b nht (the lowest key).
M gi c trnh by trong gii thut 12-8.
algorithm firstArc (ref graph <metadata>, val key
<keyType>, ref destKey <keyType>)
Key of first arc source vertex located and passed back to
caller.
Pre graph is a pointer to a graph head structure
key is the key of vertex data
destKey is the destination key of the first arc
Post destKey passed back
Return +1 if successful
-2 if key does not exist
-3 no destination key (no arcs)
1. if (graph.first null)
1. return -2
2. end if
3. locnPtr = graph.first
4. loop (locnPtr not null AND key > locnPtr->data.key)
1. locnPtr = locnPtr->nextVertex
5. end loop
6. if (loncPtr not null AND key euqal locnPtr->data.key)
1. if (locnPtr->arc not null)
1. toPtr = locnPtr->arc
2. destKey = toPtr->destination->data.key
3. return 1
2. else
1. return -3
3. end if
7. else
1. return -2
8. end if
end firstArc
THUT GII 12-8: CNH U TIN
tng ca gii thut ny rt ging vi gii thut truy xut nh. im khc
bit duy nht l sau khi xc nh c nh ngun, ta duyt qua danh sch cc
cnh ni vi nh . Bi v th c th cha cc nh c lp, chng ta phi chc
chn rng c t nht mt cnh ni vi nh ang xt. Nu thnh cng tr v (+1),
nu khng tm thy nh tr v (-2) hoc l (-3) nu tm thy nh nhng khng c
cnh no.
Tm kim u tin chiu su.
C hai cch hin thc gii thut ny: s dng k thut quy hoc s dng
stack. Chng ta quyt nh s dng stack trong phn ny. Khi duyt qua mt nh,
ta t a ch ca n trong stack. Sau pop stack, thc hin thao tc trn nh
v t tt c cc nh k vi n vo trong stack.
Vn y l mt nh c th c nhiu ng i ti. Do chng ta phi
chc chn rng mi nh ch c duyt qua duy nht mt ln. Khi thit k cu
trc d liu cho nh phn trc, chng ta c to mt c (processed flag). Khi
bt u, t tt c cc c v gi tr 0. Khi push mt nh vo trong stack, t gi tr
ca c v 1 ch rng nh ny ang nm trong stack v ch ti lt x l.
iu ny gip ngn nga vic ta a mt nh vo trong stack hn mt ln. Cui
cng, sau khi x l{ xong, t gi tr ca c tr v -2. M gi c trnh by gii
thut 12-9.
algorithm depthFirst (val graph <metadata>)
Process the keys of the graph in depth-first order.
Pre graph is a pointer to a graph head structure
Post vertices processed
1. if (empty graph)
1. return
Set processed flags to not processed
2. walkPtr = graph.first
3. loop (walkPtr)
1. walkPtr->processed = 0
2. walkPtr = walkPtr->nextVertex
4. end loop
Process each vertex in list
5. createStack (stack)
6. walkPtr = graph.first
7. loop (walkPtr not null)
1. if (walkPtr->processed < 2)
1. if (walkPtr->processed < 1)
Push and set flag to stack
1. pushStack (stack, walkPtr)
2. walkPtr->processed = 1
2. end if
Process vertex at stack top
3. loop (not emptyStack (stack))
1. popStack (stack, vertexPtr)
2. process (vertexPtr->dataPtr)
3. vertexPtr->processed = 2
Push all vertices from adjacency list
4. arcWalkPtr = vertexPtr->arc
5. loop (arcWalkPtr not null)
1. verToPtr = arcWalkPtr->destination
2. if (vertToPtr->processed is 0)
1. pushStacl (stack, vertToPtr)
2. vertToPtr->processed = 1
3. end if
4. arcWalkPtr = arcWalkPtr->nextArc
6. end loop
4. end loop
2. end if
3. walkPtr = walkPtr->nextVertex
8. end loop
9. destroyStack (stack)
10. return
end depthFirst
THUT GII 12-9: DUYT U TIN CHIU SU
Gii thut bt u bng vic t tt c cc nh v trng thi cha c x l.
Sau chng ta t con tr ch vo nh u tin v bt u duyt nh trong m
lnh 7. Nu bn chc chn rng th lin thng mnh th khng vic g phi s
dng vng lp ny. Tuy nhin trong trng hp khng c ng i t nh u
tin n cc nh khc trong th hoc th c nh c lp, chng ta phi chc
chn tt c cc nh phi c duyt qua bng cch lp tun t qua danh sch
nh. y l mc ch chnh ca m lnh 7.
Khi mt nh c chn x l, vic u tin l chng ta phi kim tra xem
nh ny tng c a vo stack hay cha? Nu cha, ta push vo stack nh
cu lnh 7.1.1.1. Sau chng ta em ra x l{ nh top ca stack v cho tt c
cc nh k vi nh vo trong stack. Ch rng v chng ta ang s dng stack
cha cc nh, cho nn chng ta khng ch duyt qua cc nh theo u tin
chiu su m cn x l{ cc nh k theo th t gim dn.
Khi stack rng, ta tng con tr vertex walker ln ri quay tr li cu lnh 7
chc chn tt c cc nh c x l.
Duyt u tin chiu rng
Thay v s dng stack nh gii thut duyt u tin chiu su, chng ta s dng
queue trong duyt u tin chiu rng. M gi c trnh by trong gii thut 12-
10.
algorithm breadFirst (val graph <metadata>)
Processes the keys of the graph in breadth-first order.
Pre graph is pointer to graph head structure
Post vertices processed
1. if (empty graph)
1. return
2. end if
First set all processed to not processed
Flag: 0not processed, 1enqueued, 2processed
3. createQueue (queue)
4. walkPtr = graph.first
5. loop (walkPtr not null)
1. walkPtr->processed = 0
2. walkPtr = walkPtr->nextVertex
6. end loop
Process each vertex in vertex list
7. walkPtr = graph.first
8. loop (walkPtr not null)
1. if (walkPtr->processed < 2)
1. if (walkPtr->processed < 1)
Enqueue and set process flag to queued
1. enqueue (queue, walkPtr)
2. walkPtr->processed = 1
2. end if
Now process descendents of vertex at queue front
3. loop (not emptyQueue (queue))
1. dequeue (queue, vertextPtr)
Process vertex and flag as processed
2. process (vertexPtr)
3. vertexPtr->processed = 2
Enqueue all vertices from adjacency list
4. arcPtr = vertexPtr->arc
5. loop (arcPtr not null)
1. toPtr = arcPtr->destination
2. if (toPtr->processed zero)
1. enqueue (queue, toPtr)
2. toPtr->processed = 1
3. end if
4. arcPtr = arcPtr->nextArc
6. end loop
4. end loop
2. end if
3. walkPtr = walkPtr->nextVertex
9. end loop
10. destroyQueue (queue)
11. return
end breadthFirst
THUT GII 12-10: DUYT U TIN CHIU RNG
Gii thut bt u bng vic t c processed v 0. Ch ba gi tr ca c c
th c: nu nh cha c x l c l 0, nu nh ang nm trong queue nhng
cha c x l c l 1. iu ny gip ngn chn vic ta b mt nh vo trong
queue qu mt ln. Sau khi mt nh c x l xong, gi tr ca c s l 2.
Khi chng ta lp qua danh sch nh (cu lnh 8.), chng ta kim tra nh
c x l (cu lnh 8.1) hay cha. Nu ri th ta nhy qua nh tip theo (cu
lnh 8.3) v quay ngc li kim tra ln na. Cng ging nh trong tm duyt u
tin chiu su, vng lp ny cho php chng ta duyt ti nhng nh c lp hoc
mt s nh trong th lin thng yu.
Nu mt nh cha c x l, chng ta kim tra xem n c c t trong
queue hay cha (cu lnh 8.1.1); nu cha th enqueue n. Chng ta x l qua tt
c cc nh con chu ca mt nh ti u (front) ca queue vi mt vng lp (cu
lnh 8.1.3): dequeue, x l{ nh, t tt c cc nh k cha x l vo queue. Lp
li cho ti khi no queue rng.
Sau khi x l xong tt c cc nh con chu ti u (front) ca queue, chng ta
nhy qua nh k trong danh sch nh v quay ngc li cu lnh 8 x l ton
b nh trong danh sch.
Mng - Networks
Mng l mt th c cnh c gn trng s. N cng thng c gi l
th c trng s. Ty theo ng dng m trng s y c th c hiu theo
nhiu ngha khc nhau. V d, mt ng bay c th s dng th biu din
khong cch gia cc thnh ph trn ng bay ca chng. Trong v d ny, mi
nh biu din mt thnh ph, v mi cnh i din cho khong cch gia hai
thnh ph. Trng s ca mi cnh c th i din cho dm bay hoc l chi ph bay
gia hai thnh ph. Trong hnh 12-15 l mt mng li ng bay, trng s
mi cnh c hiu l khong cch (tnh bng dm) gia cc thnh ph.

HNH 12-15: MNG LI THNH PH
Bi v trng s l mt trong nhng thuc tnh ca mt cnh nn n c lu
tr cng mt cu trc lu tr cnh. Trong ma trn lin k, gi tr ca trng s c
th c lu tr giao ca hai nh. i vi danh sch lin k, n c lu nh
mt gi tr trong danh sch lin kt. Hai nh dng ny c m t trong hnh 12-
16.
Cy bao trm nh nht
Chng ta c th tm c mt hoc nhiu cy bao trm t mt mng li. Mt
cy bao trm l cy cha tt c cc nh trong th. Mt iu th v gii thut
ny sau khi hon thnh, tng ca tt c cc trng s t gi tr nh nht. Nu
trng s trong mng li l duy nht th s cy bao trm nh nht l duy nht.
Nu nhiu trng s ging nhau th s c nhiu cy bao trm nh nht.

HNH 12-16: LU TR TRNG S TRONG CU TRC TH
Cy bao trm nh nht c rt nhiu ng dng trong thc t. Chng hn, cho
mt mng li my tnh, chng ta c th to mi cy ni tt c cc my vi nhau.
Cy bao trm nh nht gip ta tm c on cable ngn nht ni tt c chng v
m bo hai my tnh bt kz lun c ni vi nhau.
Cy bao trm l cy cha tt c cc nh ca trong th. Cy bao trm nh
nht l cy bao trm trong tt tng cc trng s ca tt c cc cnh t gi tr
nh nht c th.
tm ra cy bao trm nh nht trong mt mng lin thng mnh ngha l
gia hai nh bt kz lun c mt ng i cnh ca cy bao trm nh nht tha
cc yu cu sau:
1. Tt c cc nh nm trong cy
2. Tng trng s l nh nht c th, gia hai nh bt kz lun c mt
ng i.
V d v cy bao trm nh nht
Trc khi i vo thut gii chi tit, chng ta hy t tm cy bao trm nh nht
bng tay trong hnh 12-17.
Chng ta c th bt u vi bt c nh no, th bt u vi nh A. Sau
chn cnh ni t nh A vi cc nh k sao cho trng s l b nht. Trong hnh
12-17 l cnh AC. Tip tc nh vy t hai nh trong cy, A v C, ta chn cnh
c trng s nh nht. Cnh AB bng 6, BC bng 2, CD bng 3, CE bng 4. D thy
cnh nh nht l BC. Ch rng cnh no nm trong cy ri th khng c xt
na. Trong trng hp ny l AC.
xy dng gii thut, ta tun theo nguyn tc sau: t tt c cc nh nm
trong cy, chn cnh c trng s b nht ni vi mt nh cha nm trong cy v
thm n vo. Theo , ta thm cnh CD (3), DE (2), DF (3) ln lt. Tng bc
c trnh by trong hnh 12-18.
Cu trc d liu cy bao trm nh nht
Trc khi bt tay vo xy dng gii thut, ta phi quyt nh la chn cu trc
lu tr. s linh hot v uyn chuyn cao, ta s dng danh sch k.

HNH 12-17: CY BAO TRM

HNH 12-18: TM CY BAO TRM NH NHT
Ta phi thm mt s trng phc v cho vic xc nh cy bao trm nh
nht. Mi nh phi c mt c gi tr boolean cho bit nh ny nm trong
cy hay cha. Ngoi ra mi cnh cng cn mt trng tng t nh vy. y,
chng ta t tn trng ny cho c hai trng hp l inTree. Cui cng, bi v y
l mng, cho nn cn phi c trng s na. Kt qu ca cu trc ny c th
hin trong thut gii 12-11.
graphHead
count <integer>
first <pointer to graphVertex>
end graphHead

graphVertex
nextVertex <pointer to graphVertex>
data <dataType>
inDegree <integer>
outDegree <integer>
inTree <Boolean>
edge <pointer to first graphEdge>
end graphVertex

graphEdge
destination <pointer to graphVertex>
weight <integer>
inTree <Boolean>
nextEdge <pointer to graphEdge>
end graphEdge
THUT GII 12-11: CU TRC LU TR CY BAO TRM
M gi cy bao trm nh nht
Gii thut cy bao trm nh nht theo quy lut m chng ta vch ra t
trc, bt u bng vic thm nh u tin vo trong cy. Sau s dng vng
lp thm cnh c trng s nht vo trong cy cho n khi no tt c cc nh
trong cy. Sau khi chy xong, cy bao trm nh nht c xc nh thng qua c
inTree. M gi c trnh by trong gii thut 12-12.
algorithm spanningTree (val graph <metadata>)
Determine the minimum spanning tree of a graph
Pre graph contains a network
Post spanning tree determined
1. if (empty graph)
1. return
2. end if
3. vertexPtr = graph.first
4. loop (vertexptr not null)
Ste inTree flags false.
1. vertexPtr->inTree = false
2. edgePtr = vertexPtr->edge
3. loop (edgePtr not null)
1. edgePtr->inTree = false
2. edgePtr = edgePtr->nextEdge
4. end loop
5. vertexPtr = vertexPtr->nextVertex
5. end loop
Now derive spanning tree.
6. vertexPtr = graph.first
7. vertexPtr->inTree = true
8. treeComplete = false
9. loop (not treeComplete)
1. treeComplete = true
2. chkVertexPtr = vertexPtr
3. minEdge = +INF
4. minEdgePtr = null
5. loop (chkVertexPtr not null)
Walk through graph checking vertices in tree.
1. if (chkVertexPtr->inTree = true AND chkVertexPtr-
>outDegree > 0)
1. edgePTr = chkVertexPtr->edge
2. loop (edgePtr not null)
1. if (edgePtr->destination->inTree false)
1. treeComplete = false
2. if (edgePtr->weight < minEdge)
1. minEdge = edgePTr->weight
2. minEdgePtr = edgePtr
3. end if
2. end if
3. edgePtr = edgePtr->nextEdge
3. end loop
2. end if
3. chkVertexPtr = chkVertexPtr->nextVertex
6. end loop
7. if (minEdgePtr not null)
Found edge to insert into tree.
1. minEdgePtr->inTree = true
2. minEdgePtr->destination->inTree = true
8. end if
10. end loop
11. return
end spanningTree
THUT GII 12-12: CY BAO TRM NH NHT CA MT TH
Ta chia gii thut ra lm ba phn. Phn u chun b trng thi sn sng cho
th bng vic t tt c cc c inTree v false.
Phn hai l phn lp (cu lnh 9) qua cc nh thm cnh nh nht. Khi bt
u vng lp ta t c treeComplete v true. Nu tn ti mt nh no cha
nm trong th, ta lp tc t li gi tr v false (cu lnh 9.5.1.2.1.1). Trong ln
lp cui cng, khng c cnh mi no c thm vo cy, v do , gi tr
treeComplete vn gi l true, y l iu kin thot ra khi vng lp. Cn thit
phi nh li gi tr ca cnh c trng s nh nht qua tng vng lp, v th u
vng lp ta to mt bin lu gi tr ny v gn cho n gi tr ln nht c th,
cng v cng. Cng lc , ta gn gi tr ca con tr vo cnh nh nht gi tr null.
Trong vng lp ny, cc cnh ni t nh nm trong cy s c kim tra
qua mt vng bn trong tm ra c cnh no c gi tr nh nht. Mi cnh
cha nm trong cy li c tip tc kim tra xem gi tr ca n c nh hn gi tr
ang c hay khng. Nu nh hn, ta cp nht trng s v cnh mi ny. cui
vng lp (cu lnh 9.7), ta t c cho cnh v nh mi thm vo.
ng i ngn nht
Mt ng dng kh ph bin khc ca th l tm ra ng i ngn nht gia
hai nh trong mt mng li. V d, nu mt mng th hin cc tuyn bay, chng
ta c th tm c ng bay r nht gia nh v a im cn n d dng.
Edsger Dijkstra xy dng gii thut c in cho bi ton ny vo nm 1959.
Gii thut Dijkstra c s dng tm ng i ngn nht gia hai node bt
kz trong th.
V d v ng i ngn nht
Trc khi i vo xy dng gii thut, chng ta hy th xem qua v d. Chng ta
s dng li th dng cho cy bao trm nh nht. Trong v d ny, ta mun
tm ng i ngn nht t nh A n cc nh khc trong th. Kt qu ca bi
ton l mt cy c gc nh A. Kt qu ny c trnh by trong hnh 12-19.

HNH 12-19: TM NG I NGN NHT
Gii thut ny cng kh ging vi gii thut tm cy bao trm nh nht. Chng
ta bt u bng vic thm im xut pht vo cy. Sau , kim tra tt c cc
ng i t im xut pht n cc nh k v thm vo cnh c trng s nh
nht. By gi chng ta c hai nh nm trong cy nh hnh 12-19 (a2).
Sau , chng ta li tip tc kim tra tt c cc ng i t hai nh ny, A C,
ti tt c cc nh k vi chng trong th. Thay v xc nh ng i ngn nht
n nh k tip nh chng ta lm trong bi ton tm cy bao trm nh nht,
chng ta xc nh tng ng i n cc nh k. Tng ny c th hin trong
hnh 12-9 bng k hiu T:n k bn mi nh. Nhn vo hnh 12-9 (b1), cc bn s
thy c tt c l bn ng nh vy: AB vi tng l 6, CB c tng l 5, CD tng l
6, CE tng l 7. Chng ta chn ng ngn nht CB (T:5), v t n vo trong cy.
Kt qu trong hnh 12-19 (b2).
Trong ln duyt th ba qua th, chng ta kim tra ng i t nhng nh
nm trong cy (A, C v B) ti nhng nh cha nm trong cy (D v E). Khng
cn ng i no t A. T B ta c mt ng, BD, vi tng l 10. T C c hai
ng, CD c tng l 6 v CE c tng l 7. Ta chn ng i ngn nht l CD, tng
bng 6.
Tng qut ha cc bc ta lm:
1. Thm nh u tin vo trong cy.
2. T mi nh nm trong cy, kim tra cc ng i n tt c
cc nh k cha nm trong cy. Chn cnh c ng i ngn nht v thm
vo trong cy.
3. Lp li bc 2 cho ti khi no tt c cc nh u nm trong cy.
Cu trc lu tr cho ng i ngn nht
tm c ng i ngn nht, ta phi thm mt trng mi vo cu trc
th, tng chiu di ng i n mt nh. Ta gi n l path-Length (trong gii
thut 12-13).
graphHead
count <integer>
first <pointer to graphVertex>
end graphHead

graphVertex
nextVertex <pointer to graphVertex>
data <dataType>
inDegree <integer>
outDegree <integer>
inTree <Boolean>
pahtLenght <integer>
edge <pointer to first graphEdge>
end graphVertex

graphEdge
destination <pointer to graphVertex>
weight <integer>
inTree <Boolean>
nextEdge <pointer to graphEdge>
end graphEdge
THUT GII 12-13: CU TRC D LIU CHO NG I NGN NHT
M gi ng i ngn nht
By gi chng ta sn sng xy dng gii thut. M gi c trnh by
trong gii thut 12-14.
algorithm shortestPath (val graph <metadata>)
Determine shortest path from a network vertex to other
vertices.
Pre graph is pointer to network
Post minimum path tree determined
1. if (empty graph)
1. return
2. end if
3. vertexPtr = graph.first
4. loop (vertexPtr not null)
Initialize inTree flags and path length.
1. vertexPtr->inTree = false
2. vertexPtr->pathLength = +INF
3. edgePtr = vertexPtr->edge
4. loop (edgePtr not null)
1. edgePtr->inTree = false
2. edgePtr = edgePtr->nextEdge
5. end loop
Now derive minimum path tree.
6. vertexPtr = graph->first
7. vertexPtr->inTree = true
8. vertexPtr->pathLength = 0
9. treeComplete = false
10. loop (not treeComplete)
1. treeComplete = true
2. chkVertexPtr = vertexPtr->edge
3. minEdgePtr = null
4. pathPtr = null
5. newPathLen = +INF
6. loop (chkVertex not null)
Walk through graph checking vertices in tree.
1. if (chkVertexPtr->inTree true AND chkVertexPtr-
>outDegree > 0)
1. edgePtr = chkVertexPtr->edge
2. minPath = chkVertexPtr->pathLength
3. minEdge = +INF
4. loop (edgePtr not null)
Locate smallest path from this vertex.
1. if (edgePtr->destination->inTree false)
1. treeComplete = false
2. if (edgePtr->weight < minEdge)
1. minEdge = edgePtr->weight
2. minEdgePtr = edgePtr
3. end if
2. end if
3. edgePtr = edgePtr->nextEdge
5. end loop
Test for shortest path.
6. if (minPath + minEdge < newPathLen)
1. newPathLen = minPath + minEdge
2. pathPtr = minEdgePtr
7. end if
2. end if
3. chkVertexPtr = chkVertexPtr->nextVertex
7. end loop
8. if (pathPtr not null)
Found edge to insert into tree.
1. pathPtr->inTree = true
2. pathPtr->destination->inTree = true
3. pathPtr->destination->pathLength = newPathLen
9. end if
11. end loop
12. return
end shortestPath
THUT GII 12-14: NG I NGN NHT
Nh chng ta thy trong gii thut tm cy bao trm nh nht, gii thut bt
u bng vic t tt c cc c inTree v gi tr false v khi to gi tr di
ng i v dng v cng.
Chng ta bt u vi nh u tin trong th - y cng l im bt u. Nu
mun xc nh ng i ngn nht t mt nh khc, chng ta ti gn li gi tr
ny.
Qua mi vng lp (cu lnh 10) ta thm mt nh vi ng i ngn nht ti
bt kz nh no c ni, u tin ch c nh A. T mi nh trong cy (cu lnh
10.6) chng ta kim tra cc nh k vi n v xc nh trng s nh nht ti mt
nh cha nm trong cy (cu lnh 10.6.1.4). Khi chn c ng i ri, ta kim
tra xem th n c nh hn ng i ln trc ta tm c hay khng (cu lnh
10.6.1.6), nu nh hn, ta lu li gi tr mi ny v ch con tr n cnh .
Mt khi tm c ng i ngn nht, ta thm n vo (cu lnh 10.8) v tr
li kim tra th ln la (cu lnh 10).
Tng kt chng
th l mt tp hp cc node gi l nh, v tp hp cc ng ni
tng cp nh gi l cnh.
th c th c hng hoc v hng. th c hng, l th
trong mi cnh xc nh chiu. th v hng l th trong mi
cnh khng c chiu xc nh, c th i c c hai hng.
Trong th, hai nh c gi l k nhau nu c mt cnh ni trc
tip gia chng.
ng i l mt chui cc nh k nhau.
Chu trnh l mt ng i c t nht ba nh, bt u v kt thc
cng mt nh.
Vnh khuyn l mt trng hp c bit ca chu trnh, trong , mt
cnh n bt u v kt thc cng mt nh.
Mt th gi l lin thng nu gia hai nh bt kz lun c mt
ng i.
Bc ca mt nh l s cnh ni ti n. Bc ra ca mt nh l s
cnh ri khi nh , bc vo ca mt nh l s cnh i vo nh .
Su thao tc c nh ngha cho th: chn mt nh, xa mt
nh, chn mt cnh, xa mt cnh, tm mt nh v duyt th.
o Chn mt nh thc hin thm mt nh mi vo th m
khng ni n vi bt kz nh no.
o Xa mt nh thc hin loi b nh ra khi th.
o Thm cnh thc hin chn mt cnh mi gia nh ngun v
nh ch trong th.
o Xa cnh thc hin loi b cnh gia nh ngun v nh ch
trong th.
o Tm nh thc hin duyt qua th xc nh nh cho
trc.
o Duyt th thc hin gh qua tt c cc nh trong th v
x l tng ci mt.
C hai phng php duyt th: duyt u tin chiu su v duyt
u tin chiu rng.
o Trong duyt u tin chiu su, tt c cc nh con chu c
duyt qua trc khi di chuyn n nh k.
o Trong duyt u tin chiu rng, tt c cc nh k c duyt
qua trc khi di chuyn n cc nh con chu.
lu tr th trong my tnh, ta phi lu hai tp thng tin: tp
th nht i din cho cc nh v tp th hai i din cho cc cnh.
Phng php ph bin nht lu tr th l s dng ma trn
hoc danh sch lin k.
o Trong ma trn lin k, ta s dng mt vector lu tp nh
v mt ma trn lu tp cnhl
o Trong danh sch lin k, ta s dng mt danh sch lin kt
lu tp nh v mt danh sch lin kt hai chiu lu tp cnh.
Mng l mt th trong mi cnh c gn trng s.
Cy bao trm l cy cha tt c cc nh trong th.
Cy bao trm nh nht l cy bao trm trong tng cc trng s
t gi tr nh nht c th.
Mt gii thut ph bin trong th l tm ng i ngn nht gia
hai nh.
Bi tp:
Cho th nh hnh bn
Cu 1: C tt c bao nhiu ng
i t (path) t nh A n nh H:
a) 4
b) 5
c) 6
d) 7
Cu 2: Chn cu sai:
a) Lun c ng i gia hai nh bt k trong th
b) Mi nh trong th u c bc ln hn 2
c) C tt c 6 ng i t nh C n nh E trong
th
d) y l th lin thng
Cu 3: Cc nh k vi A l:
a) B, E
b) C, F, B
c) G, H, C
d) G, C, B
Cu 4: Bt u t nh A, th t cc nh c duyt u
tin theo chiu su l (cc nh c a vo stack hoc
queue theo th t bng ch ci):
a) A G F H D E C B
b) A G B F C E D H
c) A B F G H E D C
d) Tt c u sai
Cu 5: Bt u t nh A, th t cc nh c duyt u
tin theo chiu rng l (cc nh c a vo stack hoc
queue theo th t bng ch ci):
a) A B C D E F G H
b) A B C G H F E D
c) A B C G E D F H
d) Tt c u sai
Cu 6: Chn pht biu ng:
a) Trong phng php lu tr th bng ma trn k, ta
s dng ma trn lu nh v cnh ca n.
b) Trong duyt u tin chiu rng, tt c cc nh k
(adjacent vertices) c x l (process) trc khi
di chuyn qua x l cc nh con chu (descendents)
c) Khng th s dng phng php quy hin thc
hai loi duyt th
d) Khi nim lin thng mnh ch tn ti trong th
v hng
Cho th nh hnh bn
Cu 7: Bc ca nh A, B, C ln
lt l:
a) 1, 2, 3
b) 2, 3, 2
c) 4, 2, 2
d) 2, 4, 2
Cu 8: Bc ra, bc vo ca nh C ln lt l:
a) 3, 1
b) 3, 2
c) 1, 3
d) 2, 2
Cu 9: Chn pht biu sai:
a) th lin thng mnh
b) Bc ra ca nh D bng 0
c) nh E v F c cng s bc
d) Khng tn ti chu trnh no trong th ny
Cu 10: Mun B tr thnh nh tch ri, phi thc hin
thao tc xa cnh my ln:
a) 1
b) 2
c) 3
d) 4
p n: 1. c, 2. b, 3.d, 4, a, 5.c, 6.b, 7.d, 8.a, 9.a, 10.b