L600T
AM
KHOA
HOC VA CONG
NGHE VIET
NAM
iw^ACH
DAI HOC VA SAU DAI HOC
•
• • • •
LE
CONG
THANH
NHA
XUAT
BAN
KHOA
HOC
TU" NHIEN
VA CONG
NGHE
L
LE
CONG THANH
Bien
muc tren xuat ban pham cua
Thu
vien Quoc gia Viet Nam
Le
Cong Thanh
Ly
thuyet do phiic tap
ciia
tinh
loan :
Sach
chuyen khao / Le
Cong Thanh. - H. : Khoa hoc Tu nhien va Cong nghe, 2013. - 372tr.
:
hinh ve ; 24cm
Thiimuc:
tr. 259-362
ISBN
9786049131158
1.
Toantin 2. Li thuyet
tinh
toan 3.
Sach
chuyen khao
004.01 - de
14
KTF0003p-CIP
VIEN
HAN
LAM KHOA
HOC VA
CONG NGHE
VIET
NAM
BO SACH
DAI
HOC
VA SAU DAI HOC
HOI
DONG
BIEN TAP
Chu
t[ch
HQI
dong:
GS. TSKH. NGUYEN DINH CONG
Cac
uy vien:
1.
GS.
TSKH.
Ngo
Viet
Trung,
2.
GS. TS. Nguyen Dai Hung,
3. GS. TSKH.Tn\nVanSung,
4.
GS. TS. Le Tran
Binh.
'i'f
I
(if
\
I
Lo'i
gioi
thieu
Vien
Khoa
hoc va Cong nghe Viet Nam la ca quan nghien
cuu
khoa hoc tu nhien va cong nghe da ngdnh Ian
nhdt
cd nuac,
CO
thi
mgnh
trong nghien cuu ca bdn, nghien cuu va phdt
triin
cong
nghe, dieu tra tdi nguyen thien nhien va moi truang Viet
Nam. Vien tap trung mot doi
ngU
cdn bo nghien cuu c6 trinh do
cao,
ca sa vat chdt ky
thudt
hi^n dgi ddp ung cdc yeu cdu vi
nghien cuu va thuc nghiem cua nhieu ngdnh khoa hoc tu nhien va
cong
nghe.
Trong
gdn 40 nam xdy dimg vd phdt trien, nhieu cong trinh
va
kit qua nghien cuu cd gid tri cua Vien da ra dai phuc vu ddc
luc
cho su nghiep xdy dung vd bdo v^ To quoc. De tong hap vd
giai
thieu c6 he thong a trinh do cao cdc cong trinh vd ket qud
nghien cuu tai ban doc trong nuac vd quoc te, Vien
Khoa
hoc vd
Cong
nghe Viet Nam quyet dinh xudt bdn bo sdch chuyen khdo.
Bo
sdch tap trung vdo bdn
iTnh
vuc sau:
-
ling
dung
vd
phdt trien cong nghe cao;
-
Tdi nguyen thien nhien vd mdi truang
Viet
Nam;
-
Bien
vd cong nghe bien;
-
Gido
trinh dgi
hQC
vd sau dgi hoc.
Tdc
gid cm cdc chuyen khdo la nhung nhd khoa hoc ddu
ngdnh cua
Vien
hogc cdc cong tdc vien da timg hop tdc nghien cuu.
Vien
Khoa
hoc vd Cong nghe Viet Nam xin trdn trong giai
thi^u tai cdc quy doc gid bo sdch ndy vd hy vong bo sdch chuyen
khdo se Id tdi lieu
tham
khdo bo ich, c6 gid tri phuc vu cho cong
tdc nghien cuu khoa hoc, ung dung cong nghe, ddo tgo dgi hoc vd
sau
dgi hgc.
HOI
D6NG
BIEN
TAP
Ldi
tifa
Ly
thuyet do philc tap
tinh
toan diroc hinh thanh do nhu can cua
boat dong thirc
ti6n
va duoc phat
tridn
manh me trong khoang bon
miroi
nam qua. Ly thuyet nay nghien
ciiu
tinh
hieu qua cua cac mo
hinh
tinh
toan va cua thuat toan noi rieng, nhSm phan chia cac bai
toan theo do phiic tap cua thuat toan
giai
chung thanh nhiing Idp
phutc tap khac nhau, va qua do tao nen mot hinh anh khai quat ve
tinh
phiic tap cua cac bai toan noi chung.
Ly
thuyet do philc tap
tinh
toan, dac biet nhiing kgt qua khao
sat ve moi quan he
giiia
cac 16p phiic tap va ve ban chat cua mot
so Idp quan trong, cho ta nhiing
hidu
biet t6ng quat ve van de phiic
tap va hudng dan ta
each
xii
ly
diing
dan trong
triidng
hop cu thg.
Noi
rieng, nhiing
higu
biet nhu vay giup ta ly
giai
vi sao c6 su
khac biet
giiia
"giai
ducc ve mat ly thuyet" va
"giai
diioc mot
each
thuc te" doi vdi nhieu bai toan kho ma ta gap phai.
Mat
khac, ly thuyet do phiic tap
tinh
toan cung cap cho ta cac
y
niem cung nhu nhfrng khia canh don gian va trang nha cua cac
qua
trinh
tinh
toan va cua thuat toan noi rieng.
Nhiing
hiiu
biet
sau sic vg qua
trinh
tinh
toan cua thuat toan
giiip
ta phan
tich
va danh gia mot
each
chuin xac do phiic tap
ciia
thuat toan. Han
niia,
nhiing
hi6u
biet ay c6 thg goi md cho ta hudng cai
tign
hoac
tim
kiem thuat toan tot hon.
Nhu
vay, ly thuyet do phiic tap
tinh
toan khong chi cho ta mot
each
nhin thong nhat ve van de phiic tap cua cac bai toan ma con
giiip
ta tim ra hudng
giai
quyet hop ly khi xem xet nhiing bai to^n
cu
thg. Dg thay dudc ly thuyet nky hap dan the nao, xin hay tim
higu
no mot
each
ki luOng.
iv
Ldi
tua
Duong nhien, tim hieu ki bat ci3 chu de m6i nao cung
viec
lam kho, nhung no trd nen d§ dang va thu vi hon ngu nhu chu de
ay
duoc
trinh
bay mot
each
thoa dang. Muc tieu hang dau cua tac
gia khi
viet
cuon
sach
nay la muon bay to cho doc gia cac khi'a canh
thuc sir hijtng thu cua ly thuyet do phutc tap
tinh
toan, nhung khong
bi
sa lay vao nhiing dieu qua nang ne va buon te. Muc tieu
thii
hai
la
nham dap ling phan nao nhu cau cua doc gia muon tim hi6u noi
dung cd ban cua ly thuyet nay, trong boi canh tai lieu tieng
Viet
vg
linh
vuc nay con rat khan hiem.
Mong
muon la vay, nhimg nhOlng
muc tieu nay kho c6 the dat
dUdc
tron ven. B5i vi, ly thuyet do
phiic tap
tinh
toan qua that la philc tap va dang diroc phat trign
manh me, cho nen mot vai hu6ng nghien
cilu
md\i nhuing ket qua
ly thu va nhieu ufng dung hieu qua cua no ciing kho c6 the
duoc
trinh
bay trong mot khuon kh5 han che.
V6i muc tieu kg trgn, tac gia c6
gSng
lua chon nhflng chu de
thiet
thuc va
trinh
bay rnot
each
ranh mach nhat c6 thg, nhSm
dam bao doc gia vdi mot so lirong kien thufc toi thigu van c6 thg
tim
higu va nhanh chong di vao nhung vka de
thdi
su nhat cua ly
thuyet do phiic tap
tinh
toan. . , . ;
Noi dung cuon
sach
nay
duoc
chia thanh 6 chuong, trong do
Chuong 0 la chuong md dau nhSm
g\6\u khai quat ve ly thuyet
do phiic tap
tinh
toan va
trinh
bay mot
each
tigp can thich hop cac
bai toan thuoc nhieu iTnh vUc
khae
nhau, tao tien de cho
viec
giai
cac bai toan ay tren ciing mot mo
hinh
tinh
toan tSng quat, mo hinh
may Turing, cung nhu
viec
phan chung thanh nhUng Idp phiic tap.
Chuong 1 nghien
ciiu
may Turing va cac bien thg chinh cua no,
chii
yeu la khao sat kha nSng doan nhan ngon ngu cua may, nhSim
ly giai tai sao may Turing
duoc
chon lam mo
hinh
tmh toan tSng
quat. Do may Turing
duoc
de xuat v6i muc dich chinh xac hoa
khai
niem thuat toan, tao co sd dg c6 thg chiing minh "cac bai toan
khong giai
duoc",
cho ngn phan cuoi chuong nay gidi thieu mot vai
VI
du don gian nhu nhung minh chiing ve cac bai toan khong giai
duoc
de doc gia tham khao them. Hon nfla, noi dung ciia phan nay
tuy
nam
ngoai
pham vi cua ly thuygt do phiic tap
tinh
toan, nhung
no chUa dung mot phuong phap ma ta can den 6 Chuong 4
Ldi
tua
V
cac Chuong 2 va 3 tign hanh khao sat do philc tap
thdi
gian va
do
phUc
tap khong gian cua thuat toan, thuc hien phan Idp cac bai
toan
theo
do phutc tap cua cac thuat toan giai chung. Mot s6 Idp
phiic tap bao gdm cac bai toan thuoc nhieu
linh
vuc khac nhau vdi
nhflng dac
tinh
thu vi
duoc
kham pha. NOi dung cua hai chuong
nay bao ham nhflng kgt qua cd ban ve do phflc tap
tinh
toan.
Trong ChUdng 4 thigt lap
trat
tu
thdi
gian va
trat
tu khong gian
doi vdi cac Idp phflc tap nham chflng to
tinh
nan giai cua nhigu bai
toan.
Phan
con lai ciia chfldng nay gidi thieu
each
tiep can mot van
d^
trung
tarn
va kha nan giai hien nay, van dg P = NP.
Chuong cuoi ciing, CliUdng 5, danh dg gidi thieu cac hudng
nghign cflu ma e6 kha nang mang lai nhflng giai phap
tich
cue doi
vdi cac van de nay sinh, dac biet trong hoat
dong
thuc tign.
Nhu tren da ngu, do khuon kho han che, mot so chu de ly thu
nhung khong
dUOc
dua vao cuon
sach
nay, nhu He bhng chiing xac
suat va Tinh toan
luong
tit hay Mat md hoc - mot
linh
vue flng
dung hieu qua cua ly thuyet do phflc tap
tinh
toan. Doe gia cd thg
tim
higu nhflng
chii
de nay trong nhigu tai lieu hien ed,
ehang
han
nhflng tai lieu cd trong phan Tai lieu tham khao d cuoi
sach
nhu
[2, 10, 12, 31]. Nhflng tai lieu ay va hai tai lieu [11, 13] cung
duoc
tac gia tham khao nhieu khi
viet
cuon
sach
nay. Tuy
duoc
xuat ban
kha
sdm, nhung cuon
sach
[13] cung da chfla dung nhieu van dg cd
ban cua ly thuygt
tinh
toan va ciia ly thuygt do phflc tap
tinh
toan
noi
rigng; cuon
sach
[11] chuygn ve
tinh
NP-day
du, ngn cd phan
Phu luc - mot Danh
sach
bao gom hon ba tram bai toan
NP-day
dii
duoc
biet dgn cho tdi
thdi
digm do. Danh
sach
nay hien nay vln
duoc
nhieu ngudi sfl dung.
B6n chuong dau cua cuon
sach
nay cd thg dung lam chuygn de
giang
day cao hoc
hoac
sinh vign nhflng nam cuoi, chuygn nganh
toan hoc va tin hoc ly thuygt. Noi dung nay da
duoc
tac gia
giang
day cho hoc vien cao hoc trong nhieu nam qua, tai Vien
Toan
hoc,
Vien han lam
Khoa
hoc va
Cong
nghe
Viet
Nam, va tai Dai hoc
Bach khoa Ha Noi. Do
sach
dudc
viet
vdi kha day du cac khai niem
can thiet va dudc dien dat tudng doi mach lac, nen nd cung cd the
bo ich cho nhflng ai muon bat dau tim higu ly thuygt nay.
vi
Ldi tixa
' Tac gia chan thanh cam dn GS. Le Tuan Hoa da doc ki ban thao,
siia I5i vk cho nhflng y kien dong gop quy bau dg chinh siia noi dung
tot hon; GS. Ngo DSc Tan cung da doc, sijta I6i ban thao va iing ho
tac gia vigt cuon sach nay.
Mac dil tac gia da rat c6 gang khi viet, nhung cuon sach nay
khong thi tranh khoi thieu sot. Tac gia mong muon nhan duoc
nhung nhan xet va gop y cua dong nghiep va cua doc gia gan xa
ve cuon sach nay. Moi nhan xet v^ gop y xin dtroc giii vg dia chi:
leecthanhSgmail. com/.
Ha Noi, thang 8 nam 2013
Tac gia
Muc luc
L6i tiia iii
0 Md d§u 1
0.1 Cac thuat ngu: va khai niem 2
0.1.1 Tap hop 2
0.1.2 Ham 4
0.1.3 Bicn do tiem can cua ham 6
0.1.4 Logic Boole 8
0.1.5 Dothi 13
0.1.6 Ngon ngu: hinh thiic 18
0.2 Vc ly thuyet do phurc tap tinh toan 20
0.2.1 Vi tri trong Ly thuyet tinh toan 20
0.2.2 Sir ra ddi va phat trien 22
0.3 Cach tiep can cac bai toan 25
0.3.1 Bai toan tim kiem va bai toan quyet dinh . 27
0.3.2 Ngon ngfl bigu dign bai toan quygt dinh . . 29
0.3.3 Doan nhan ngon ngii 32
Bai tap 32
1 May Turing va Thuat toan 35
1.1 May Turing 36
1.1.1 Mo ta 36
1.1.2 Dinh nghia hinh thi'ic 42
1.1.3 Cac chute nang chinh cua may Turing 49
1.2 Mot vai bien thg ciia may Turing 58
1.2.1 May Turing nhieu bang 59
1.2.2 May Turing khong tat dinh 69
MUC
LUC
1.3 Luan d6 Church-Turing va Thuat toan 77
L3.1 Thuat toan
theo
ngliia true
giac
77
L3.2 Luan de Church-Turing va
Dinh
nghia thuat toan 79
lA
Mot vai bai toan khong giai
duac
84
L4.1 Bai toan
chap
nhan 85
L4.2 Bai toan
diing
99
L4.3 Bai toan taong i3ng
Post
102
Bai tap 113
2 Do
phufc
tap thdi
gian
117
2.1 Do phufc tap
thdi
gian cua cac loai may Turing . . . 118
2.1.1 Quy chuin ve
thdi
gian
hoat
dOng cua may . 118
2.1.2
Phan
tich thuat toan 122
2.1.3 Quan he
tlidi
gian giiia cac loai may 132
2.2 May Turing tat dinh
thdi
gian da thufc 138
2.2.1 Thdi gian da thufc va Idp P 138
2.2.2 Thi du ve cac bai toan thuOc Idp P 142
2.3 May Turing khong tat dinh
thdi
gian da thufc . . . 153
2.3.1 Ldp NP va ngon ngfr kic^m chiing nhanh . . 154
2.3.2 Thi du vg cac bai toan thuoc ldp NP 161
2.3.3
VandeP
= NP 166
2.4 Tinh NP-day du 168
2.4.1 Quy dan
thdi
gian da thi'rc 169
2.4.2 Ngon ngir NP-day du va ldp NPC 176
2.4.3 Dinh ly Cook-Levin ve
tinh
NP-day du 178
2.4.4 Mot vai bai toan NP-day du 182
2.5 Cau true cua cac ldp NP va
eo-NP
191
2.5.1 Ldp trung gian NPI giiia P va NPC 192
2.5.2 Quan he gifra ldp NP va ldp
co-NP
195
Dm tap 201
3 Do
phiJc
tap
khong
gian
207
3.1 Do phiic tap khong gian cua cac may Turing 208
3.1.1 Do phvjfc tap khong gian eiia may Turing tat
dinh
mot bang 208
MUC
LUC , ix
3.1.2 Do phufc tap khong gian cua may Turing tat
dinh
nhigu bang 215
3.1.3 Do phufc tap khong gian cua may Turing
khong tat dinh 222
3.2 Nhiing moi quan he co ban ve do phufc tap 224
3.2.1 Quan he giiia
thdi
gian va khong gian 225
3.2.2 Quan he giiia tat dinh va khong tat dinh . . 227
3.3 Do phiic tap khong gian da thiic 229
3.3.1 Cac ldp phufc tap PS va NPS 230
3.3.2 Tinh
PS-day
du 232
3.4 Do phiic tap khong gian loga 242
3.4.1 Cac ldp phiic tap LS va NLS 243
3.4.2 Tinh NLS-day du 245
3.4.3 Quan he giiia NLS va
eo-NLS
251
Bai tap 255
4 Tinh nan giai 259
4.1 Trat tu cua cac ldp phufc tap 260
4.1.1 Trat tir khong gian 260
4.1.2 Trat tii
thdi
gian 267
4.2 Phuong phap quan he hoa va van de P = NP . . . . 271
4.2.1 May Turing vdi tii van 271
4.2.2 Han chl ciia phuong phap dudng
cheo
275
4.3 Maeh
Boole
doi vdi van de P = NP 278
4.3.1 Mach
Boole
doan nhan ngon
ngii
279
4.3.2
Cach
chiing minh
khac
cho Dinh ly
Cook-Levin289
. Bai tap 292
5 Cac giai
phap
295
5.1 Tinh toan
kinh
luan 296
5.1.1 Thdi gian va khong gian
kinh
luan 298
5.1.2 Vg trat tii
thdi
gian da thiic 304
5.2 Tinh toan
song song
305
5.2.1 Cac mach
Boole
dong bo 305
5.2.2 Ldp phiic tap NC 308
5.2.3 Tinh
P-day
du 311
X
MUC LUC
5.3 Thuat toan xac suit 312
5.3.1 May Turing xac
suat
va Idp BPP 312
5.3.2 Tinh nguyen to 316
5.3.3 Cac chuong
trinh
phan nhanh 324
5.4 Thuat toan xap xi , 331
5.4.1 Bai toan tap bao quat nho nhat 333
5.4.2 Bai toan do thi con day du Idn nhat 336
5.5 Phan tich xac
suat
cac thuat toan 338
5.5.1 Hieu suit hau
chac
chan cua thuat toan . . 343
5.5.2 Do phirc tap
thdi
gian
trung
binh da thiic . 353
Bai tap 357
Tai
lieu
tham
khao
. ; ,^ 359
Ky
hieu va Tuf khoa 363
ChLfdng
0
McT dau
Trirdc
khi muon tim higu ki mot chu de nao do, c6 le tot nhat \k
hay xem xet mot
each
khai quat nhflng net ca ban cua chu de ay.
B6i vay, muc
tieu
tM
nhat
cua Chuong Md dau la
gidi
thieu sd
luoc ve ly thuygt do phutc tap
tinh
toan, bao gom: su ra ddi cua ly
thuyet
nay, vi tri cung nhu moi tucing quan gifla no v6i cac chu de
khac
trong ciing mot
llnh
vuc - ly thuyet
tinh
toan, va cuoi cung
la
gidi
thieu noi dung chinh cua ly thuyet do phirc tap
tinh
toan,
do la viec phan chia cac bai toan thanh cac Idp theo "dO phiic tap"
cua thuat toan giai chiing.
Dg
CO
the phan Idp d6i vdi cac bai toan thuoc nhigu
linh
vuc
khac
nhau, ly thuyet do phutc tap
tinh
toan xem xet cac bai toan
theo mot thg thong nhat, nhd do
dign
dat chung bang ngon ngiJ
hinh
thufc va tien hanh giai chung
trgn
cung mot mo
hinh
tinh
toan.
Do do, myc
tieu
tM hai cua chuong nay la
trinh
bay
each
tiep can
cua ly thuyet do-phiic tap
tinh
toan doi vdi cac bai toan noi chung.
Trudc khi cu the hda cac muc
tigu
vtta ngu, giong nhu cac tai
lieu
chuyen khao khac, ta hay bat dau bang viec
gidi
thieu mot so
thuat
ngu: va khai niem toan co ban; dac biet la cac khai niem ve
ngon
ngU
hinh
thitc,
dd thi va
logic
Boole.
Chung khong chi can thiet
cho viec cu thg hoa muc
tigu
de ra ma con duoc sii dung thudng
xuyen
trong tai lieu nay.
2 Md dau
0.1
Cac
thuat
ngvt
va
khai niem
0.1.1
Tap hgfp
TSiP
hop
Ih
mot
khai
niem
co
ban cua toan
hoc vk
khong thi
dinh
nghia
duoc
mot
each
chinh xac.
Theo
true quan,
tap hdp (hay
c6n
diroc
goi tat la tap) bao gom cac doi
tuong
c6 thg
thuoc
mot hay
nhi^u
chung loai
khae
nhau, chang han
nhir
cac eon so, cdc ky tu
va
kg ca cac do
vat,
v.v
M5i
doi
tuong
do
duoc
goi la
phcin
tH
hay
la
thanh vien cua tap hop.
Cac tap
hop thudng
duge
ky
hieu
bdi
cac
chu: cai
La
tinh
A,B,C, ,
hoac
hdi cac
chii
cai
Hy Lap c6
nhir
r,
E,
f), Dg
bilu
thi
"x la
phan
tijf
cua tap hop
E" ta
dung
ky hieu
x G E (doc la
"x thuoc
E").
Trong trudng
hop
nguoc
lai,
khi
"y
khong
la
phan tii cua
E", ta
viet
y ^ E ("y
khong thuoc
E").
Tap
hop
dugc
thg
hien bang nhieu
each
khae
nhau.
Caeh
don
gian nhat
la
liet
kg tat ca cac
phan tii
cua tap hop ay roi dg vko
gifla hai'dau
ngoac
nhgn.
Thi
du,
E
=
{3,5,15,a,i,c,«}
la
tap hop bao gom cac so
3,5,15,
cac
chii
cai
a, b,
c va ky ttr [t-
Ta
CO
3 e E va 5 6 E, con 35 ^ E,
v.v
Viee
mo ta
tap hop b^ng
each
liet
kg
tat
ca cac
phan
tiJf
cua
no
doi khi khong don gian
doi
vdi nhiing tap hop
bao gom
nhieu phan
tijf,
dac
biet
la tap v6 han - tap
vdi
vo so cac
phan
tii.
Tuy
nhign,
dg mO
ta
tap
vo
han,
ta c6
thi diing dau
ba
eham
" " vdi
nghia
thong thudng
la "cac
phan
tii
con
duoc
tiep
tuc
liet
kg
mai mai".
Chang
han, b^ng
each
nay ta
dign
ta tap cdc s6 tii
nhien
N va
tap
cdc so
nguyen
Z
nhu sau:
<
N
=
{i,2,3, }
Z
=
{ ,-2,-1,0,1,2,
}.
Rlt
tiee
cdeh
mo ta
"true
giae"
tren
chi
dting
doi vdi
loai
tap
hop
dugc
ggi la
tQp
dim
dU0c trong
ly
thuyet
tap
hgp.
0.1
Cdc
thuat
ngU va
khai niem
3
Mot
each
thong dung hon,
tap
hgp
dugc
dign
ta
bang
each
bilu
thi
dac
tinh
cua cac
phan
tijt
tao nen tap hgp iy, ta eo thg
viet
{
X
I X
CO
dac
tinh
nao do }.
Thi du,
tap cac so
chinh phuong
dugc
dign
ta
bdi
{ n
\ = vdi mot m nao do
thuoc
N }. Dg mo ta eac
tap philc tap hgn, ngudi
ta
con dung
cac
phep
toan
va cac
each
xay
dung khae.
Do day
khong phai
la mot
giao
trinh
ve ly
thuygt
tap
hgp, ngn chung toi
se
khong
di
sau
vao cac
khia canh
do.
Nhan
thg ta ky
hieu
tap cdc sd
hitu
ti va tap cdc s6
thiic
tuong ling
la Q va R. Cac ky
hieu
Z+, Q+ va R+
dugc
dung
dg
chi
cdc tap nhflng s6 khong
am
thuoc
Z, Q va R
tuong ling.
Tap
khong
ehiia phan tii
nao
dugc
ggi la tap
rSng
va
dugc
ky
hieu
la 0.
Hai tap
hgp A R
dugc
coi la
bang
nhau,
va
dugc
ky
hieu
la
A
=
R,neu chung
gom cac
phan
tiJt
nhu nhau. Trong trudng
hgp
ngugc
lai, chiing
dugc
coi la
khdc nhau
va
dugc
ky
hieu \h
A ^ R.
Doi
vdi
hai
tap hgp A vk R,
ta. noi rang
A la tap con
cua
R,
va
ky
hieu
Ik A C B
hoac
R D
A,neu m5i phan tii cua
A
eung deu
la
phan tii
cua R. Ta eon noi
f&ng
A la tap con
thtXc sytcna.
R,
ky higu
la
/I
C ngu
/I
la tap eon cua R va
khae
R. Tap hdp
tdt
ca cdc tap con cua R
dugc
ky
hieu lkV{R).
Cho hai tap
Avk R. Hdp
cua AvkR,
dugc
ky
hieu \kAuR,\k
tap
bao gom tat ca eac
phan tii thuoc
A
hoac
thuoc
R.
Giao cua
A
va S,
dugc
ky
hieu IkAOR,
la tap bao gom cac
phan tii eung
thuOe
A va
thuoc
R.
Hieu cua
Avk R,
dugc
ky
hieu
la
>1
\a
tap
bao gom cac
phan tii thuoc
A va
khong thuoc
R.
AUR
AnR
Hinh
0.1
Hgp,
giao
va
hieu cua hai
tap hgp
4
Mci
dau
Phdn
bu
(complement)
cua tap hop A,
duoc
xac dinh trong mot
pham vi cu thg nao do, la tap hop bao gom nhiing phan tut trong
pham vi ay ma khong thuoc A, va
duoc
ky hieu la A" (khi khong
gay nham Ian, phan hu cua A con
diTOc
ky hieu la lA).
Tich
De-cdc
{Cartesian
product)'cna.
hai tap A va B, diroc ky
hieu la /I X /?, la tap hop bao gom tat ca cac cSp c6 thuf tir ma
thanh phan trirdc la phan tii thuoc A con thanh phan sau la phan
tii
thuoc R. Cu thg,
AxB
=
{{a,h)\a
€ .4,5 e R).
Tuong tir, tich
Descartes
diroc dinh nghia cho nhigu tap hop. Trong
trirdng
hop khi tat ca k tap deu bang nhau, ta viet
k
AXAX XA
= A'^.
0.1.2 Ham -'-^
•
- - '
'-^^-'^
Ham
la mot d6i tirong quan trong cua toan hoc, phan anh moi quan
he vao-ra tir tap hop nay den tap hop kia. Ham f til tap hop X
den tap hop Y, ta viet f:X —> y, la mot quy tac ma
theo
do m6i
phan
tijf
dau vao thuoc X tao ra
nhiSu
nhdt
mot phan
tiJt
tuong
ling
thuoc Y.
Theo
ham f: X —^ K, khi phan tii x € X c6 phan tut tuong
ling
y
eY,ta
noi rang " ham / xac dinh tai x va nhan gia tri y",
vh ta viet f{x) = y. Nguoc lai, khi phan tut x' nao do khong c6 gia
tri
tuong
ling
nao, ta noi rang " ham / khong xac dinh tai x'" hay
don
gian
"/(x')
khong xac
dinh".
Ky hieu f{x) con thg hien rang
X la
bien
cua ham /. Khi X = Xi x
• • •
x X^, ham /
duoc
goi la
ham
k-ngdi
hay ham k
bien.
Tap cac phan tut thuoc X ma tai do ham f:X —> Y x&c
dinh,
tutc tap D = {x
\ e X mh f{x) xac dinh},
duoc
goi la
miin
'
xac
dinh
(domain)
cua /. Tap tat ca cac gia tri cua ham /, tiic
i
0.1 Cac
thuat
ngii
vd
khdi
niem
5
tap R = {y\ e Y,3x e X : f(x) = y},
duoc
goi la
miin
gia,
tri
(range)
cua ham do. Ham /
duoc
goi la ham
hoan
toan
xac
dinh,
neu no xac dinh tai moi x 6 X, nghia la D = X. Khi R = Y,
ta noi rang / la ham len.
Vay la khi noi dgn "ham" ta can higu rang do la ham bo
phan
noi
chung va dan tri. Ham toan phan chi la mot tru5ng hop rieng, va
khi
can thiet ta se nhan manh chi tiet nay. Hon nfla, tuy "don tri"
la dac
tinh
cua ham nhung ngiroc lai, c6 the nhieu gia tri
khac
nhau
cua bien dau vao
duoc
tirong
ilng
v6i ciing mot gia tri dau ra.
Thi
du,
theo
ham gia tri tuyet doi cua s6 nguygn, /abs: Z —* Z,
m5i
so nguyen n dmc tirong ijtng vdi n, neu n la duong, va vdi -n,
neu n la am.
Theo
ham cong hai so nguygn, /add : Z x Z —> Z,
mOi
cap cac so
duoc
tirong utng vdi tong cua nhiing so ay. Day
la cac ham toan phan.
Theo
ham /abs, hai so vdi dau. doi
nguoc
nhau
duoc
tudng
ling
vdi ciing mot so,
/abs(")
=
/abs(-^0
= "
doi
vdi moi n > 0. Dua
theo
ham /add) rat nhieu gia tri dau vao
khac
nhau
duoc
tuong
ling
vdi ciing mOt gia tri dau ra,
chang
han
/add(«, -•''0 = 0 doi vdi moi n > 0.
Nhu
vay, ham /: X —> Y la mot mo hinh toan hoc dign dat
quan he vao-ra tiT tap X dgn tap Y, ma
theo
do mOi phan tut cua
X
CO
thg
duoc
tuong utng vdi khong qua mot phan tii cua Y. Tuy
nhien, doi khi ta can xem xet mot moi quan he rong hon gifla tap
X va tap y, ma moi phan tii cua tap X c6 kha nang
duoc
tUOng
iSng vdi nhieu phan tut cua tap Y. Trong trudng hop nay, dg dam
bao
tinh
ddn tri cua ham, moi quan he nay
duoc
dign ta bdi ham
/': X —> V(Y), trong d6 V{Y) la tap tat ca cac tap con cua Y.
Cac moi quan he vdi nhiing dac
thii
rigng
duoc
thg hien bdi
cac ham thich hop. Chang han, vj tit
(predicate)
hay
tinh
chat
(property),
lign
quan den cac doi
tUOng
thuoc tap hop X nao do, la
mot ham tii tap X den tap cac gia tri
chan
ly {DUNG, SAl}. Dg ti?n
dung,
tap {DUNG, SAl} thudng dudc thay thg bdi tap {1,0} neu
khdng
gay nham Ian.
6
M6
dau
Cung
nhu doi vdi bat cuf mo
hinh
nao, mieu ta ham mot each
ro
rang la rat can thiet. Ta c6 thg mo ta ham b^ng nhieu each khac
nhau. Chang han, khi ham /: X —> Y c6 mien xac
dinh
D huu
han va khong qua Idn, ta lap mot danh
sach
theo titng gia tri thuoc
D
ma moi dong la mot cong thute dang f{x) = y vdi day du gia
tri
cu the cua
bi6n
x va gia tri tudng utng y cua ham/,
hoac
lict
ke
trong
mot bang gom hai cot ma cot
thil
nhat Ian
luot
la eac gia tri
thuoc D duoc gan cho bien x va cot
thiit
hai la nhiJng gia tri tUdng
ling
f{x). Tuy nhien, trong moi trudng hop, dii khong that cu th6
nhung
lai ddn gian neu nhu ta mieu ta duoc ham bdi cong
thiic
tong
quat nho do. Thi du, ham cong hai so dtrqc mo ta hdi cong
thiirc
fadd{"i',n)
= in + n.
0.1.3 Bien do tiem can cua ham
Gia
sit f vhg la cac ham
tii
N den R+.
Nhieu
khi can cua ham f{n)
duoc quan tarn xem xet chi vdi
nhiing
ii du Idn,
tiic
la vdi moi n
hit
dau tit mot so
HQ
nao do. Ta noi do la can tiem can hay la bien
dg
tiem can
cua.
hhin
f
{n).
• • • •
•
Can tren
tiem
can. Ta noi rang "/('O O-ldn cua
(ji^iif
va
ta
viet
/(n) =
0[f/(ri)],
neu ton tai cac so tu nhien c va no sac cho,
doi
vdi moi s6 tu nhien n > no,
/(")
<
cyiji).
Khi
/(n) =
0[(j{;n)]
ta noi rang
g{;n)
la can tren cua /(n), hay
chinh
xac hdn,
r/(/i)
la can tren
tiem
can
ciia
f{ii).
Mot
each true giae, /(n) =
0[y{n)\6 nghia la ham /(n) nho
hon
hoac
b^ng ham r/(n) ngu ta bo qua nhiJng khac nhau khong co
ban giOa ehung, nhu cac thanh phan phu va he so eua thanh phan
ehinh;
hay noi each khac, ham / tang cham hdn
hoac
bang ham g.
Thi
du, gia sii /i(n) la ham 5n^ + Sn^ + 18n + 7. Khi do, bang
each chon thanh phan chinh 5n^ va bo he so 5 cua no, ta thu dUdc
/i(n)
=
0[n^].
Dieu
nay hoan toan thoa man
dinh
nghIa
hinh
thiic.
0.1 Cac thuat
ngU
va khdi niem
7
That
vay, cho c = 6 va no = 7, ta co 5/)^ + 3n^ + 18/t + 7 < 6n^ doi
vdi
moi n > 7. Hdn
nila,
J\{n) =
t>[n^]
bdi vi n**
luon
16n hdn n^
va
do do cung la can tren
tiem
can cua
/i(n).
The nhung, /i(n)
khong
the la
0[n'^]
bdi
vi,
vdi bat cii gia tri nao ta gan cho c va no,
yeu
cau trong
dinh
nghIa vln khong duoc thoa man.
•
Can
diidi
tiem
can. Ta noi rang
"(/(n)
la can
dtCdi
tiem
can
eua /(n)" va ta
viet
/(n) =
n[y(n)],
khi j{n) la can tren
tiem
can
eua g{n),
tire
la khi g{n) =
0\f{n)
.
Doi
vdi ham /i(n) neu tren, ta co /i(n) = n[n^] va dudng nhien
=
txtc va rt^ la
nhiing
can
dudi
tiem
can eua
/i(n).
Tuy
nhien, n'' khong la can
dudi
tiem
can cua
/i(n).
•
Can sat
tiem
can. Ta
viet
/(n) =
e[(y(n)],
neu /(n) =
0[g{n)
va
/(n) =
^[g{n)].
Mot each tUdng
diTdng,
neu ton tai ba so
diidng
ci,
C2 va no S g{n) < f{ii) <
C2g{n),
doi vdi moi n > /lo-
Khi
/(n) =
Q[g{n)i
ta noi rang "g{n) la can sat
tiem
can hay
la
can chat
tiem
can eua
/(/i)"-
Trong trudng hop nay, cac ham
/(n)
va g{n) co cap tang nhu nhau. , ,
R6 rang, cung doi vdi ham /i(/0 neu tren, la can sat
tiem
can,
tiic
/i(n) ^ Q[ii^ •
•
Khai
niem o-be. Ta
viet
/(n) -
o[g{n)]
va n6i rang "/(") 1^
o-be
ciia
g{iiy\u
Noi
each khac, f{n) =
o[g{n)\d nghIa rang, ddi vdi mOi s6 thue
c
> 0, ton tai mot n, sao cho f{n) < cg{n) d6i vdi moi n > n,.
Cac
khai
niem
O-ldn
va
0-1)6
tao thanh mot cap tUdng
d&ng.
Khai
niem
O-ldn
the hien ham no khong Idn han mot each item can
so vdi ham kia, eon
khai
niem o-be the hien ham no nho han mot
each
tiem can so vdi ham kia. Sxt khac nhau
gifla
hai
khai
mem
O-ldn
va o-be
gifmg
nhu sU khac nhau
giiia
< va <.
8
M6
dau
0.1.4 Logic Boole
Logic
Boole
la mot he
toan,
do
George Boole
de
xuat
vao
gifla
the
ki
XIX,
dudc
xay
dirng xoay quanh
hai gia
tri
doi
ngiroc nhau,
do
la cac gia
tri chan
ly
DUNG
va
SAI
(TRUE
va
FALSE).
Hinh
thanh
trong
khung canh
cua
toan
hoc
Ung dung, ngay
nay
logic Boole diioc
coi
la
CO
sd cua
dien toan
va
thict
kc may
tinh.
Trudc
khi
trinh
bay
nhung kien
thiic
quan trong
va can
thiet,
ta
hay lam
quen
vdi cac
khai nicm
co ban cua ly
thuyet
nay.
•
Gia tri Boole. Cac gia tri
chan
ly
DUNG
va
SAI
diroc
goi la
cdc
gid tri
Boole
{boolean
values)
va,
nhir
da neu
tren, thudng
duoc
bigu
thi b5i 1 va 0. Ta sut
dung
cac gia tri
Boole trong
cac
boi
canh
hay
trong
cac
tinh
huong vdi
hai kha
nSng
c6 the xay ra.
Chang
han nhu
khi
ta can xcm xet cac sir
kien:
trdi
c6 thg
"tanh"
hoac
"mua",
mot
menli
de c6 thd
"dung"
hoac
"sai",
hay la mot cau
hoi CO
thg
duoc
tra \d\a
"dung"
hoac
"sai",
v.v
•
Bien
Boole va cac phep toan Boole.
Bien
chi
nhan
cac gia
tri
Boole duoc
goi la
bien
Boole {Boolean variable).
Nhu
thudng
le,
cac
bien Boole cung dudc
ky
hieu
bcii
cac
chO
cai La
tinh
x,
y, z,
hay
xi,x-2,
Tren
cac
bien Boole, thirc chat
la
tren
cac gia tri
Boole,
ta c6
thg
thao
tac cac
phep
toan
vdi
tinh
sang
tao
dac biet, duoc
goi la
cdc
phep
toan
Boole
{boolean
operations).
Phep
toan Boole
don
gian
nhat
la
phep
phu
dinh
{negation)
hay la
phep
NOT, duoc
ky
hieu
bdi Phu
dinh
cua mOt gia
tri Boole
nay la gia tri
Boole
kia
doi nguoc
vdi no. Nhu
vay,
ta c6 0 = 1 va
-il
= 0.
Phep
hoi
{conjunction)
hay la
phep
AND, duoc
ky
hieu
bdi
A.
Hoi cua hai
bien
Boole
nhan
gia
tri
1 neu ca hai
bien cung
lay gia tri 1.
Phep
tuyen
{disjunction)
hay la
phep
OR,
duoc
ky
hieu
bdi
V. TuySn
cua
hai
biSn Boole
nhan
gia
tri
1 neu it
nhat
mot
trong
hai
bien
ay
lay
gia
tri
1. , , . . , „
0.1
Cdc
thudt
ngU
vd
khdi
mem
9
Day
la ba
phep
toan
cd sd cua
logic Boole
va
duoc
the
hien
day
dii
nhu sau:
-,0
= 1 .: 0A0 = 0 0V0 = O
^1
= 0 ' 0A1 = 0 0V1 = 1
1
A 0 0 1 V 0 = 1
1
A 1 - 1 1 V 1 = 1
Ngoai
ra, mot vai
phep
toan Boole khac cung thudng duoc
sii
dung,
do la
phep
tuyin
loai
{exclusive
or) hay
phep
XOR,
phep
suy
diin
{implication),
va
phep
suy
diin
thuan nghich
hay
b&ng nhau
logic
{equality),
chung
lan
ludt dUdc
ky
hieu
la 0,
—>
va
Gia sii x va y la hai
bien Boole. Khi
do, x © y = 0 neu va
chi
neu x va y
nhan nhung
gia
tri
nhu
nhau. Tiep theo,
x
—>
y = 0
neu
va chi neu .; - 1 va y = 0.
Cuoi cung,
x y = 0
neu
va chi
neu X
va y
nhan
cac gia
tri khac nhau.
Cu thg ta c6:
0®0=0
0^0=1 0^0=1
0©1=1
0^1-1 0^1=0
1©0=
1 • 1-^0 = 0 1^0 = 0
1®1
= 0 1-^1 = 1 1^1 = 1
•
Cong thufc Boole.
Ta c6 thg
siJt dung
cac
bien Boole
va cac
phep toan Boole
de tao nen cac
cong thirc, duoc goi
la cdc
cony
thvcc
Boole, nham
bi6u
thi nhung mcnh
de ma ta
thudng gap. Chang
han,
gia
sit
X
la mot
bien Boole
bigu
thi
meiih
de
"Ngay
mai
trdi
tanh",
nghia
la x
nhan
gia
tri
1
(trdi
tanh)
va gia
tri
0
(trdi
mua).
Gia
sut
y la mot
bien Boole
bigu
thi
"Ngay
mai
chung
toi
chac
chan
sc di
Choi",
tire
la y
nhan
gia
tri
1
(chung
toi di
choi)
va gia
tri
0
(chung
toi
khong
di
choi). Khi
do
mcnh
de
"Neu ngay
mai
trdi
tanh,
thi
chdng
toi
chac
chan
se di
clidi" dudc
bigu
thi bdi
cong tlnic
don
gian
nhu x ^ y.
Tiep theo,
nhd cac
phep
toan Boole,
ta c6 thg kgt
noi
cac
cong
thilc
Boole
ddn
gian
vdi
nhau
dg thu
dUdc
cac
cong
thilc
Boole phirc
hop, dap
urng
uliuiig
ygu cau
bigu
thi
cac
mgnh
de
Phurc
tap
hdn
10
Md dhu
Dinh
nghia 0.1.1
Cong
thvtc
Boole
{Boolean
formula)
du(fc
dinh
nghia
mot
each
de quy
nhic
sau:
1. MSi
bien
Boole
Id mot
cong
thiic
Boole;
2. Neu A vd B Id cac
cong
thxic
Boole,
thi
cung
Id cac
cong
thiic
Boole;
3.
Khong
c6 mot
cong
thiic
Boole
ndo
khdc
ngodi
cac
cong
thiic
— thu
duac
theo
cac quy tdc I vd2.
Can
liru
y rang, khi ket n6i cac cong thiic v6i nhau bdi cac phep
toan
Boole,
d6
khoi
gay nhim Ian ta c6 thg sijf dung them nhiing
cap cac dau
ngoac
tron
"( , )".
• Sit ti^dng difdng cua cac
cong
thufc
Boole.
Gia sii P la mot
cong thiic
Boole
chuta n bien xi, x^, , x^. Khi do vdi moi
each
gan
tri
Boole
1
hoac
0 cho cac bien x, {i =
1,2,
,n), cong thiic P
cung se nhan mot trong hai gia tri do. Nhu vay, cong thiic
Boole
P
xac
dinh
mot ham
P(X1,X2, ,X„) :
{0.1}"
—^
{0,1}.
Dinh
nghia 0.1.2
Cong
thiic
Boole
P
dupe
goi la
hang dung
neu no
dung,
tiic
nhan
gid tri 1, vdi moi
cdch
gdn tri
Boole
cho cdc
bien
cua no; P
duac
goi Id
hang
sai {hay con
duac
goi la mdu
thudn)
neu no sai, tiic
nhan
gid tri 0, vdi moi
cdch
gdn tri
Boole
cho cdc
bien
cua no; P
duac
goi la
thoa
diidc
{satisfiable)
neu c6
it
nhdt
mot
cdch
gdn tri ndo do cho cdc
bien
di no
dung.
H^ng
dung va mau thuan rat can thiet trong cac suy luan toan
hoc. Mot
bu6c
quan trong trong lap luan toan hoc la viec thay
the mOt menh de nay bang mot menh d6
khac
vai cung cac gia tri
0.1 Cdc
thudt
ngU vd
khdi
niem
11
chan ly. Cac menh de vdi cung cac gia tri chan ly duoc coi la
tuang
duang
nhau.
Khai niem nay dudc
dinh
nghia chinh xac nhu sau.
Dinh
nghia 0.1.3 Cdc
cong
thiic
Boole
P vd Q
dupe
gpi Id
Mdng
dvCdng
{equivalent),
vd
dupe
ky
hieu
Id P = Q, neu
cong
thiic
Boole
P ^ Q la
hdng
dung.
Nhieu
cong thiic
Boole
tuang dudng da dudc thiet lap va mot so
cong thiic tvd thanh cac luat logic. Nhd cac cong thiic tuang duang
ta
CO
the bien dSi nhflng cong thiic
Boole
phiic tap thanh nhfing
cong thiic tuang duang dan gian han theo mot nghia nao do.
Dudi
day la mot vai luat logic tien ich:
1. Luat De Morgan
^(PVQ)
=
( PA-Q).
2. Luat phu
dinh
kep
-1-P = P
3. Luat suy diSn
p^g
= -PVQ.
4. Luat suy
dign
thuan nghich
p^Q
= (p-g)A(g p).
5. Luat phan phoi ',
PA(gv7?)
= (PAQ)
V(PAP),
py{QAR) =
(PVQ)
A(PV7?).
Nhd
cac bigu thiic tuang duang nay, moi cong thiic
Boole
dgu
CO
thI
bilu
dien dugc
dudi
dang dan gian han ma trong do chi can
Md dau
sil
dung cac
phep
toan
Boole
co s6 A va V. Sau day la hai dang
biSu dien tuong duong quan trong cua
cong
thiic
Boole,
do la dang
hoi
chudn
tac CNF {conjunctive normal form) vh dang
tuyin
chudn
tac DNF {disjunctive normal
form).
Gia sijt P(xi, , x„) la mot
cong
thiic
Boole
chiia cac bien
xi, ,
x„. Dg don gian hoa
viec
dien ta cac dang chudn tSc cua
cong
thurc nay, doi vcti moi bien
Boole
x- va u e {0,1}, ta se
sijf
dung cac ky hieu sau day:
neu cr = 0,
neu (7 = 1
neu cr = 0, • I ' "
neu (7 = 1.
Khi
do,
bang
each
ap dung cac bi6u thiic tUdng duong neu tren, ta
de dang thu dixoc cac dang hOi va tuygn
chuSn
tic ciia mot
cong
thiic
Boole.
'1 '
Dinh ly 0.1.4 Moi cong thvcc Boole P(xi, ,x„) deu c6 cac
dang biiu diin sau day:
(i) Dfing tuyin chudn tdc
P(xi, ,
Xn)
(ii)
Dang hoi chudn tac
P(xi, ,x„)
= V (4' A Ax^");
P(<ji, ,<j„)=i
= /\f V Vx^").
P(<^l,-,<T„) =
()
0.1 Cac thuat ngU vd khdi niem
13
0.1.5 Do thi
Do thi la mOt mo hinh toan hoc dien ta mot
each
tudng minh nhfmg
moi
quan he hai ngoi (mot chieu cung nhu hai chieu) giiia cac doi
tirong
can
duoc
xem xet. Chinh vi vay, do thi dudc sii dung rong
rai
trong rit nhieu
linh
vuc
khac
nhau; cliSng han nhu: khoa hoc,
ky thuat,
kinh
te, xa hoi, v.v
Mot
each
hinh thiic, do thi
{graph)
(hay chinh xac hon, dS thi
vd
hiidng
{undirected
graph))
la mot cSp c6
thii
txi G = {V, P),
trong
do V la mot tap gom
hiiu
han cac phan tii, con P la mot
tap nhflng cSp khong
thii
tu cac phan tii
khac
nhau thuoc V,
tilc
P C {{u, v}
I
u,
V
eV vk u / v]. Phan
tijt
cua V
dugc
goi la
dinh
{vertex),
con phan tii {u, v} cua P dudc goi la
canh
{edge) va
duac
ky hieu bcii uv. Nhu vay uu va vu la cac ky hieu cua cung mot canh.
Ngoai
each
dinh nghia nhu tren, do thi con
duoc
di6n ta mOt
each
true
giac
tren mat phang nhu sau: Cac dinh do thi
ducc
bi6u
thi
bdi cac vong
tron
nho
hoac
cac cham dam vdi "ten" cua
dinh,
con moi canh dUdc thg hien hdi mot doan thing hocic
cong
noi hai
vong
tron
tUdng
ling.
Hinh
0.2 bigu dien do thi hinh ngoi sao
Gi =
{{vi,V2,
U3, Vi, Us},
{viV3,
ViVi,
V2V4, V2V5,
VsVr,}),
va do thi
G2= {{a,b,c,d,e,f,g,h},{ub,ac,ad,bc,cd,ef,fg}).
® © ® ®
G2
Hinh 0.2 Cac bigu dien true
giac
ciia do thi Gi va G2
14
M6
dau
V6i iru di6m nhtr vay,
bieu
dien
true
giac cua do
thi thirdng
duoc
diing
d6
di6n
ta
nhiing
so do ve
"mute
do"
quan
he
giiJa tdng
cSp
doi
tuong,
bang
eaeh gan cho m6i
eanh,
tile
moi
doan
thSng
hoac
cong
noi
tren,
eae da
lieu lien
quan
den m6i
quan
he do.
Thi
du, ta
diing
do
thi
dg
bigu dign
he
thong
giao
thong
dirdng
bo
giiia
eac
thanh
pho
bang
each gan cho m6i
dinh
ten cua mot
thanh
pho va noi hai
dinh
vdi
nhau
bdi mot
doan
thing
hoae eong,
bigu
thi
tuyen
quoc lO qua hai
thanh
pho
tirong uTng. Tren
m8i
doan
ay duoe ghi
ehii
tgn quoc lo va ca
khoang
each khi ckn
thiet.
Chang
lian, Hinh
0.3 sau day
dien
ta eac
tuyen
quoc lo
chinh
noi
lien
mot so
thanh
pho
Idn
5
vdng
Dong-Nam
thii
do Ha Noi (HN),
bao gom
Hai
Duong
(HD), Hai
Phong
(HP), Nam
Dinh (ND), Thai
Binh
(TB),
Phil
Ly (PL),
Ninh Binh
(NB) va
Thanh
Hoa (TH).
Hinh
0.3 He
thong
quoc lo
viing
Dong-Nam
Hk Noi
0.1 Cdc
thuat
ngU va
khdi
niem
15
Tiep
theo,
dg chi su phu
thuoc
vao do thi G, tap
dinh
va tap
canh
cua no duoc thg
hien
ro hon bdi V{G) va R{G)
tuong
ilng.
Lien
quan
den
canh
e = uu cua do tin G,
tiic
canh
vdi cdc
dinh
dau
mut
(endvertices)
u va u, ta noi
rang: Thvc nhdt,
canh
e noi
(join)
dinh
u
vd'i dinh
v;
Thii
hai,
dinh
(/ hoac/va
dinh
v
lien
thuoc
(incident)
canh
c. Hai
dinh
duoc goi la ke
nhau {adjacent),
hay la
Idng
gieng
(neighbour)
cua
nhau,
neu
cluing
duoc noi v6i
nhau
bdi
mot
canh,
tiie lien
thuoc
ciing
mot
canh.
Hai
canh
ciing
c6
chung
mot dinh
dau mut
cung
duoc goi la ke
nhau.
Do thi G duoc goi
la
day du
(complete)
ngu hai
dinh
bat ky cua no deu ke
nhau.
Cho
u la mOt
dinh
cua do thi G. Bac
(degree)
cua
dinh
u
trong
G, ta ky
hieu
la
degG(v)
hay don
gian
la
deg(v)
khi
khong
gay
nham
lln,
dudc
dinh
nghia
bcii
so tat ca cac
lang
gieng
cua v
trong
G.
Dinh
vdi bac 0 duoc goi la
dinh
cd lap
{isolated vertex).
Bay gi5,
ta noi
rang
do
thi
H = (W, F) la dd thi con
(subgraph)
cua
do
thi
G = (V, E), ta
viet
H C G, neu W CV va F C R.
Trong
tru5ng
hop, khi F
chura
tat ca cac
canh
ciia
G ma ca hai dau mut
deu
thuOc
W, do
thi
H duoc goi la dd thi con cam
sinh (induced
subgraph)
bdi G
tren
W, va ta
viet
// =
G[U^
.
Dmdng
di
(path) trong
do thi G la mot day cac
dinh
doi mot
khac
nhau
(uo,
ui, ,
ujt), trong
do
dinh
ke vdi
dinh
Ui doi
vdi
m6i / =
1, A;.
Mot
dirdng
di nhu vay con duoc ky
hieu
la
P= UQUX
Uk.TR
noi
rang trong
do
tin
G, hai
dinh
w,, va Uk
duac
ndi
vdi
nhau
bdi
dirdng
di P, hay
dirdng
di P not
hai dinh
an va u^.
Thi
du,
trong
do
thi
G2
tren Hinh
0.1,
abed
la
dudng
di noi a va d,
nhung acbd
khong
la
dirdng
di. Do dai
(length) ciia
dudng
di P,
duoc ky
hieu
bdi /(P), la so cac
canh
ciia
no,
tiic
l(P) = k.
Trong
do thi Gi
trgn Hinh
0.2, cac
dinh
va
U2
duoc noi vdi
nhau
bdi
dudng
di
uxu^Ui
do dai 2, va con bdi
dudng
di
uiu^v^Ui
do dai 3.
Do thi
duoc goi la
lien
thong
(connected)
neu hai
dinh
bat ky
cua
no deu duoc noi vdi
nhau
bdi
dudng
di nao do.
Tren Hinh
0.2,
do
thi
G,
lien
thong,
con do
tin
G2
khong
lign
thong.
16
M6
dau
Chu
trlnh
{cxjde)
trong
do thi G la
dudng
di
(uo, ui,
•
•.,
Uk)
do
dai > 2 ma hai
dinh
dau mut
UQ
va
ciing
kg
nhau trong
G.
Noi
each
kliac,
chu
trlnh
la mot
"dudng
di
khep kin", nghia
la
dirdng
di
vdi
do
dai
> 2 ma hai
dinh dau mut
eua no
ciing ditdc
noi
true ticp vdi nhau bdi mOt
canh,
tutc 'aoUk-
Chu
trlnh
Hamilton
{Hamiltonian
cycle)
trong
mot d5 thi cho
trudc
la chu
trinh
chila
tat
ea cac
dinh
cua do
thi
ay.
Trcn
Hinh
0.2, do
thi
Gi la chu
trlnh
Hamilton,
con
trong
do thi G2 c6 tat ca 3 chu
trlnh:
1 chu
trlnh
dang "hlnh vuong"
ahcd,
2 chu
trlnh
dang "tam
giac"
ahc va acd.
Cay
{tree)
la
mot
do
thi lien thong
va
khong
c6
chu
trlnh.
Trong
cay thudng duoc
chi
dinh
mot
dinh
dac
bict
(theo
mot
yeu
cau nao
do)
lam gdc
{root).
Dinh
bac 1
khac
vdi
goc cay
duoc goi
la
Id
{leaf).
Riing
{forest)
la mOt do thi gom mot
hoac
nhieu
cay,
tiic
la mot
do
thi
khong
CO
chu
trlnh.
Hinh
0.4
Rirng gom
3 cay -rdn
Trong
cac do thi da
duoc
xcm xet, ncu moi
canh
{u, u}
duoc
tliay
the
bang mot
cSp c6
thiJ
tu
(u,
u)
hohc/vk
{u,
u),
thi
ta c6
khai
niem "do thi
c6
hudiig".
Cap
thuf
tu {u, u)
duoc goi
la
cung
{arc)
til
dinh
a den
dinh
u, hay
cung
vdi di6m
dau u va
didm
cu6i
v.
Theo
each
bi£^u
dien true
giac,
moi cung (u,
v)
thudng duoc bi6u
thi bdi
r-'
• -
0.1
Cac
thuat
ngU va
khdi niem
17
mot doan thing
hoac
cong
ciing vdi mui
ten
hudng
theo
chieu
tii
u
den V. Thi
du,
Hlnh
0.5 sau day cho ta
bifni
dicn true
giac
mot
do thi
CO
hudng.
Hinh
0.5 Do
thi
CO
hudng
Mot
each
hlnh thilc,
do thi cd
hvCdng
{directed
graph)
la mot
cap
CO
till?
tu G - (V; A),
trong
do V la tap
dinh
va .4 la tap
cung,
tile
tap con cua tap
{(u,
(;)/u,eV]u
v).
Trong
do thi
CO
hudng,
mot
dinh
v c6 the la
didm
dau cua mOt so
cung
nay
va cung
cd the la
diem cuoi
cua mot vai
cung
khac.
V\, doi
vdi
dinh
V trong
do
thi
co
hudng,
ta can
phaii bict
"bac ra" va "bac vao"
cua
no. Bac ra
{outdejjree)
ciia
u,
dudc
ky
hieu
bdi
oatd('(j{u),
la
so
tat ca cac
cung vdi diem
dau u; con bac vao
{indegree)
cua u,
duoc
ky
hieu
bdi
iiHk.(j[v).
la so tat ca cac
cung vdi diem cuoi
u.
Cac khai niem
khac
cua do
thi vd hudng
(chang
han
nhu: dudng
di,
chu
trlnh,
lien thong,
cay, )
cung duoc chuygn
the cho do thi
CO
hudng.
Thi
di.i. diidng
di c6
htCdng
[directed
path)
trong
do
thi
G la mot day cac
dinh doi
mot
nhau
khac
nhau (uo,
ui, ,
ujt),
trong
do
dinh
Ui_,
dudc noi vdi dinh
(/,
bdi cung
Ui)
thuoc
G,
d6i
vdi
inpi
/ -
\.2 ,k.
Nhu vay,
day la mot
dudng
di c6
hudng
tii
dinh
un den
dinh
11 k-
THI/
VlfNTINHBlNH THUAN
18
Mcl
dau
Hinh
0.6 Cac cay con c6 hudng cua do thi G3
Do thi thudng dmc sut dung d6 mieu ta moi quan he gifra cac doi
tudng.
Cac
dinh
c6 the la nhiing thanh pho va cac canh la nhflng
doan quoc 15 noi lien chiing,
hoac
cac
dinh
la nhiing tram dicn va
cac canh la nhiing day dan lien kct chiing. D6 dign ta mot each ro
rang,
ta dan nhan cho cac
dinh
va/hoac
cac canh ciia do thi, va ta
thu
dUdc do thi duCdc dan nhan [labeled graph)^ nhu
Hinh
0.3.
0.1.6
Ngon
ngi? hinh thut • E
• Bang
chiJ.
Xau cac ky tir, hdcic cac dac
tinh
noi chung, la
khoi
(block)
dong vai tro nhu mot ddn vi
kicn
thict
cd ban trong
khoa
hoc
tinh
toan. Bang
chii
diang dG xac
dinh
cac xau diidc
lira
chon
phii
hdp nhu cau sii dung. Vcfi muc
dicli
khao sat
khai
quat,
ta
dinh
nghia hang
chit
(alphabet) mot each
hinh
thiic,
do la mot
tap
hiiu
han khac rSng bat ky ma m6i phaii tut ciia no la mot ky ti/
{symbol). Bang
chii
thudng dudc ky hieu bdi
chii
cai Hy Lap c6,
nhu
E, r va H; con cac ky tii cua bang
chii
thudng duoc
lict
ke theo
mot thu: tit xac
dinh.
Thi du, cac tap sau day la cac bang
chii:
r
= {a, b, c, d, f, g,
h,
i,
j,
k, 1,
m,
n,
o, p, q, r, s, t,
u,
v, w, x, y, z},
n
=
{0.1,«,x,y,z}.
0.1 Cac thuat ngvc va khdi niem
19
• Tii. Tie (word), hay con duoc goi la xau (string), tren mot
bang
chii
cho trudc la mot day
hiiu
han cac ky tu cua bang
chii
ay,
diTdc viet lien nhau va khong can ngan each hdi cac dau phay nhu
thudng
le. Thi du, bacca la mOt tit tren bang
chii
Ti = {a,b, c},
va 10100011 la mot tii tren bang
chii
^ =
{0,1}.
Cho w = (710-2 (Jn-ian la mot tii tren bang
chii
E. Dp dai
(length) cua tit w, dUdc ky hieu bdi la so Ian xuat hien cua
cac ky tu trong w,
tiic
|u;|
= n. Tii vdi do dai 0 dudc goi la ta
rSng
(empty
word) va dUdc ky hieu bdi e. Tit rdng duoc xem la
mot tir tren bat cii bang
chii
nao, dong vai tro nhu so 0 trong cac
he dem so. Ngtidc (reverse) cua tit w, duoc ky hieu bdi u;^, la
tir
nhan dUdc b^ing each viet cac ky tu ciia w theo
thii
tu nguoc,
tufc
=
(yn(^n-\ • •<72cri. Tir V la tie con (subword) cua w, ngu
cdc ky tu cua v xuat hien lien tiep trong w. Til con
aia2-
• -
(^i, vdi
I
< i <n, dudc goi la
khuc
dau (prefix) cua w.
Cho hai tir u = ui Um va v = vi
Vn.
Phep ghep (concate-
nation) u vdi V, ta ky hieu la uu, dUdc thuc hien b^ng each viet
them
tii v vao cuoi tii tt,
tiic
uv = ui
Um'Ui
Vn- Trong trudng
A:
hop, khi tit u dude
ghep
k Ian vdi chinh no, ta viet mT'Tli = u'^.
•
Ngon
ngU. Gia suf E la mot bang
chit.
Ta ky hieu E+ la tap
tat cd cac tii khdc rang tren bang
chii
E, va dat:
E* = E+ U {e},
tiic
tap tat cd cac tic tren E,
= {w
I
w e E*,
\w\ n}, tile tap tdt cd cac tii do dai n tren S.
Ngon
nga (language), hay ngon ngU
hinh
thUc (formal lan-
guage), tren bang chU E la tap cac tii tren E. Nhu vay, mot tap
con bat ky cua E* la mot ngon ngU tren E. Thi du,
dudi
day la cac
ngQn ngit tren bang
chii
{0,1} :
y4 =
{0'l'|«
=
0,1,2, },
= {O'lO'l I =
1,2, }.
20
M6
dau
De tien dung, cac ttf trong E* duoc liet ke theo thit tiX tH
diin
quen thuoc, tren co sci
thii
tu cua cac ky tu trong E va dong
thdi
theo do dM ciia t\i. Thi du, doi v6i bang chu: E = {a, b, c}, ta c6
E*
=
{e,
a, b, c, aa, ab, ac, ba, bb, be, ca, cb, cc, aaa, aab, }.
0.2 Ve ly
thuyet
do phiJc tap tinh
toan
0.2.1 Vi tri
trong
Ly
thuyet
tinh
toan
Ta hay bat dau bang viec
gidi
thieu mot
each
so luoc ba
linh
vuc
trong
tarn c6
tinh
truygn
thong cua Ly
thuyet
tinh
toan
(Theory
of Computation), do la: Ly thuySt
otomat
(Automata theory), Ly
thuyet
ve kha
ndng
tinh
toan
(Computability theory) va Ly
thuyet
do
phtic
tap
tinh
toan
(Complexity theory). Ba
linh
vUc nay phoi
hop Cling nhau kham pha nhflng tiem nang va nhiJng han che chinh
cua
tinh
toan noi chung, ca
tinh
toan ly thuyet Ian
tinh
toan thuc te.
Van
de nay dira ta quay trd lai v6i nhiJng nam 30 cua the ki XX,
khi
cac nha logic toan bat dau xem xet mot
each
than trong ve
gidi
han cua
tinh
toan. Cac ket qua ly thuyet thu duoc trong khoa hoc
tinh
toan, nhu viec de xuat mot s6 mo
hinh
ciia cac qua
trinh
tinh
toan va cua thuat toan noi rieng, va dac biet la viec chi ra mot so
bai toan khong giai duqe, da cho ta biet duqc phan nao noi dung
cua van de, til pham vi ly luan den quan niem thue tien. Den nay,
du
khoa hoe va eong nghe ngay mot phat
trign
manh me, viec lam
sang
to noi dung cua van de noi tren van eon rat gian nan.
Ba
linh
vuc nghien eiiu cua ly thuyet
tinh
toan tuy co noi dung
nghien
ciiu
rieng re, nhung chung co quan he mat thiet vdi nhau.
Ly
thuyet
otomat
dg cap den viec xay dung cac mo
hinh
toan
hoc ve tmh toan. Muc tieu cua ly
thuyet
vi kha
nang
tinh
toan
la phan chia cac bai toan thanh Idp cac bai toan giai duoc va Idp
cac bai toan khong giai duqc. Trong khi do, ly
thuyet
do phvCc
tap
tinh
toan
phan chia cac bai toan giai duoc thanh cac Idp
khae
nhau theo imic do kho khan khi giai clmng.
0.2 Ve ly
thuyet
do
phitc
tap
tinh
toan
21
Trong
m6i
linh
vUc nghien
ciiu,
van d^ kham pha noi tren duqc
thi
hien theo nhUng khia canh phu hop vdi chute
nSng
cua
tvfng
linh
virc. D6
hinh
dung duqc su anh hudng qua lai giiia ba
linh
vUc
trong
su phat
trign
chung cua ly thuygt
tinh
toan, chung ta hay
quan sat vai tro cua moi
linh
vUc duqc thg hien nhu the nao trong
qua
trinh
giai quyet mot bai toan.
Bai toan can giai quyet co the la mot bai toan tong quat
hoac
la mot bai toan cu thg duoe xem nhu mot trudng hop rigng cua bai
toan tCng quat. Di nhign, dieu mong muon la giai bai toan trong
trirdng
hop t6ng quat. Ve ly thuygt, qua
trinh
giai bai toan bao gom
viec lap mo
hinh
toan hoc cho bai toan khi can thiet va, dua tren
mo
hinh
do, xay dung phuong phap giai hay cu the hon la thuat
toan giai. Tuy nhien, dg bai toan giai duqc mot
each
thuc te, viec
lap mo
hinh
toan hoc cho bai toan ciing nhu viec xay dung thuat
toan giai no dgu phai thieh hop vdi nhiing trang thiet bi
tinh
toan
hien
co.
Nhiing
trang thiet bi nay co duqc la nhd cac thanh tUu ciia
eong nghg mang lai, ma co sd ly luan cua no dua tren nhiing kgt
qua nghien
ciiu
cua ly
thuyet
otomat.
Doi
khi trong qua
trinh
giai bai toan, mac dii da rat co g^ng
nhung
ta vtn khong thg tim duqc mOt thuat toan giai no. Kho khan
nay co thg do ban
chat
phiic tap cua bai toan chuf khong phai vi ta
kem coi. Khing
dinh
dieu nay, tiic la viec ehdng to khong co thuat
toan giai bai toan, la phan su ciia ly
thuyet
ve kha
ndng
tinh
toan.
De lam duoe dieu do, can thiet phai co mot
dinh
nghia chinh xae
ve thuat toan thay the cho khai niem thuat toan theo nghia true
giac
ma ta van thudng
diing
khi xay dung thuat toan giai mot bai
toan nao do. Bdi vi, khai niem true
giac
ve thuat toan khong thi la
CO
sd de ta
CO
thg chilng
minh
rang khong ton tai mot thuat toan
nao giai bai toan da cho. Dg dap
ling
nhu eau nay, mot vai khai
nigm
hinh
thiic ve thuat toan da duqc de xuat, va nhd do mot so
bai toan quan trong khong the giai duqc bang thuat toan da duqc
kham
pha. Chang han nhu bai toan xac
dinh
mot menh de toan
22 M6 dau
hoc dung hay sai, bai toan tuong
ilng
Pots,
bai toan
thuf
mudi cua
Hilbert
va v.v Kham pha nay khong chi la hien tuong phi thu5ng
ma no con thg hien ban chat chinh xac cua toan hoc.
Mat
khac,
ngay
ca trong trudng hap ta da xay dung
dudc
thuat
toan giai bai toan, nhung tren thuc tc doi khi d6 nhan dtrdc mot
Idi
giai thoa dang lai rat gian nan, du ta
dUdc
cung cap day du cac
trang
thiet bi tien tien nhat.
Nhil
vay, giiJa "giai
dUdc
ve mat ly
thuyet"
va "giai diTdc mot
each
thuc te" c6 mot sir
khac
biet dang
ke, trong do "giai
dUdc
mot
each
thuc te" la giai
dudc
tren may
tinh
dien
tijf
trong pham vi kha nang ve
thdi
gian cung nhu ve bp nh6
ma may c6 the c6
dadc.
Ly giai su
khac
biet nay la
viec
lam cua
ly
thuyet
do phic tap tinh toan.
0.2.2 Sy ra d5i va phat
trien
Quay trd lai vdi nhung nam 40 va 50 cua the ki XX, tiep
theo
nhung
ket qua sau sac vg cac bai toan khong giai
dUdc
la sir
tri§n
khai
nhiing
tu tudng ve cac mo hinh ly thuyet cua may
tinh
va cuoi cung
dan den sir ra d6i cua may
tinh
thuc tc. Day la mot
bade
tien quan
trong
cua khoa hoc
cong
nghe.
Sau khi may
tinh
dien tut ra ddi, tucing rang vdi nhflng phudng
tien
tinh
toan hien dai nhir vay,
viec
thirc hien thuat toan d6 giai
tiep bai toan la mot
viec
lam ddn gian.
Song,
thuc te lai khong
liic
nao cung nhu mong muon. Chang
lian,
khi thuc hien thuat toan
tren
may
tinh,
nhicu bai toan giai
dudc
mot
each
d6 dang va cung
khong it bai toan rat kho giai, tham chi khong thg giai
dudc,
mac
dii
v6 mat ly thuyet chung hoan toan giai
dUdc
bang nhieu thuat
toan
khac
nhau. Thi du, doi vdi bai toan sdp xep cac doi tUdng
theo
mot
thfl
tU da dinh, ta cd thg giai bai toan vdi hang
trieu
doi
tUdng
mot
each
nhanh chdng chi tren mot may
tinh
nho. Trong khi
do, doi vdi bai toan lap
lich
bieu cho mot trudng dai hoc thi van
de lai trd nen kha phflc tap.
Viec
bo tri phong hoc cho cac Idp chi
can dam bao mOt yen cau thong thudng, sao cho khong cd hai Idp
0.2 Vi ly
thuyet
do phiic tap tinh toan
23
dUdc
bo tri vao ciing mot phong hoc tai cung mot
thdi
diim.
D6 cd
dUdc
mot
thdi
gian bigu cho mOt trudng dai hoc, gom khoang 100
Idp
vdi mSt so thay co va mot luqng phong hoc nao do, cd khi ddi
hoi
mOt
thdi
gian thuc hien
tinh
toan dgn hang the ky
ngay
tren
ca sieu may
tinh.
Vay la bai toan lap lich bigu khong the giai
dudc
mot
each
thuc te.
Nhu
vay, trong
boat
dong
thuc
tign
ta thudng gap nhflng bai
toan dg va ca nhflng bai toan khd. Ngoai ra, mot bai toan cung cd
thg
giai
dudc
bang nhieu thuat toan xau tot
khac
nhau, va
ngay
vdi
mot thuat toan thi cd the trong trudng hdp nay nd cho ta ket
qua nhanh con trong trudng hdp
khac
nd lai cho ket qua cham. Hdn
nfla,
gifla giai
dUdc
ve mat ly thuyet va giai
dUdc
mOt
each
thuc te
doi vdi nhieu bai toan cung cd nhflng
khac
biet dang kg.
Nhflng
dieu ndi
trgn
la hien tUdng kha pho bien.
Viec
kham pha
nguygn nhan dan den hien tUdng nhu vay se cd y nghia quan trong
ve mat ly thuyet va cd gia
tri
to Idn ve mat flng dung. Nguygn nhan
ay phai
chang
la do ban chat phflc tap cua bai toan, hay la do thuat
toan ma ta xay dung
chua
that hieu qua, va cung cd thg la do cac
trang
thigt
bi
tinh
toan
chua
that hien dai,
Lien
quan den van dg nay, vao cuoi thap nign 60 cua thg ki XX
mot
linh
vuc nghign cflu
dUdc
hinh thanh, do la ly
thuyet
do phiic
tap tinh toan. Dua
trgn
nhflng kham pha ve su phu
thuoc
gifla
"kich
cd" cua bai toan vdi
thdi
gian thuc hien thuat toan cung nhu
vdi
dung ludng bo nhd ma may can sfl dung trong qua
trinh
tinh
toan, ly thuyet nay tien hanh xem xet "do phflc tap
thdi
gian" vh
"do phflc tap khong gian" cua thuat toan nhu nhflng ham phu
thuoc
vao "kich
Cd"
cua bai toan. Nhd dd ta cd
dUdc
mot
each
nhin thong
nhat
ve do phflc tap cua cac thuat toan.
Ra ddi va phat
trign
manh me khoang bon mUdi nam qua, ly
thuygt
do phflc tap
tinh
toan tuy vln
chua
cd
duqc
mot ly giai thoa
dang cho nhung hien tUdng phd bign ngu
tren,
nhung nd da cd mot
budc
tign
dang kg vdi nhieu ket qua phong phu cd y nghia nhat
24
Md
dau
dinh
ve ly thuyet cung nhir
ling
dung. Nhd
tign
hanh khao sat cAc
hhi
toan trong mOt khuon kh5 chung, ly thuyet do phiJc tap
tinh
toan cho ta nhUng
hilu
biet khai quat ve
tinh
phiic tap cua mot Idp
rong
rai cac bai toan, dSng
thdi
cung goi md cho ta nhiing phuong
hudng
giai
quyet doi vdi cac bai toan cu thg ma ta gap phai.
Sau day ta hay khao sat mot vai khia canh cua
linh
vuc nghien
cilu
hap dan nay.
Mot
trong nhiing hudng sQi dong cua ly thuyet do phiic tap
tinh
toan la nghien
ciiu
kham pha mot ludc do tao nha nham phan
loai
cac bai toan theo "do phiic tap
tinh
toan" cua thuat toan
giai
chung, mot luoc do tudng tu nhu bang tuan hoan cac nguyen to
hoa hoc duoc phan Idp theo
tinh
chat hoa hoc cua
chiing.
Qua lUdc
do ly tudng ay, ta c6 thg biet dudc bai toan nao de, bai toan nao
kho
ma khong can phai
giai
chung. Day la mot hudng nghien
ciiu
vdi
mot tam nhin bao quat.
Trong
trudng hop cu thg, khi duong dau vdi mot bai toan xem ra
la
kho
giai,
ta c6 the
xiJt
ly theo mot vai
each
khac nhau. Cdch xit ly
tM
nhdt,
ta can tim
higu
xem khia canh nao cua bai toan la can
nguyen cua su kho
giai,
roi tim
each
khac phuc dg bai toan duoc
giai
quyet dg dang hdn. Cdch xic ly
thU
hai, thay vi kho tim dUdc
Idi
giai
hoan hao cho bai toan, ta c6 thg
chap
nhan mot 15i
giai
it
hoan hao hon
mign
sao tim dUdc dg
dang
hdn; chang han, doi vdi
nhieu
bai toan toi Uu ma khong thg
giai
dUdc mot
each
thuc te, viec
tim
mot 16i
giai
gan dung dg
dang
hdn dang kg so vdi viec tim mOt
Idi
giai
chinh xac. Cdch
xvc
ly
thi2
ha, ta c6 thg de xuat cac thuat
toan
giai
nhanh doi vdi "hau het" cac trudng hdp cua bai toan va
chi
gap kho khan trong mot so it "trudng hdp xau";
hoac
xay dung
cac thuat toan vdi "do phiic tap trung binh"
viia
phai. Cach
xiJt
ly
nhu
vay thudng c6 y nghia
ling
dung, tuy thuoc vao doi hoi thuc te.
Cuoi
cung, ta c6 thg nghi den cac
kiiu
tinh
toan
linh
hoat hon theo
nghia nao do, chang han nhu
tinh
toan toan song song hay thuat
toan xac
suat,
va hy vong r^ng bai toan dUdc
giai
quyet tot hdn.
0.3 Cdch
tiep
can cac bai
toan
25
0.3
Cach
tiep
can cac bai toan
Cac bai toan ma ta thudng gap thuoc rat nhieu
linh
vUc khac nhau
va
CO
nhang dang phan biet, nhung da phan la dang bai
toan
quyet
djnh
hoac
bai
toan
tim
kiem,
trong do noi rieng la dang bai
toan
toi uu. Day la nhiing bai toan thuan tuy toan hoc va cung c6 thg
la nhiing bai toan thong dung nay sinh tii hoat dong thuc tien.
Cac bai toan do c6 thg
dupe
phat
bigu
chinh xac bang ngon
ngii
toan hoc, nhung doi khi cung dUdc phat
bigu
theo mot ngon
ngii
tu
nhien
dan da. Trong trudng hop khi bai toan chua duoc phat
bilu
bang ngon
ngii
toan hoc, thi viec dau
tign
phai lam la dich bai toan
do
sang
mot
ngii
canh toan hoc thich hdp; chang han nhu trudng
hdp sau day.
Bai
toan xep ba 16. Cho mot Id hang hod gSm cdc goi hang,
moi goi diu c6 khoi luang cung vdi gid tri cu the, vd cho mot chiec
ba Id. Hay chon tit Id nay mot so goi hang nao do vd xep day vao
ba
16,
nhung khong duac qud, sao cho thu duac mot gid tri Idn
nhdt
c6 thi.
Day
la mot bai toan t6i Uu to hop quen thudc, dUdc ky hieu
la
MAX-KNAPSACK
va dudc phat
bilu
b^ng ngon
ngii
toan hpc
dudi
dang tdng quat nhu sau:
MAX-KNAPSACK
DQ
ki$n: Cho "hai day so nguyen dudng
Si,S2, ,Sn,-5
va
Y^u
cdu: Tim mot tap con / C
{1,2,n}
sao cho
^
Si < 5 va E
'^i
—' "^ax-
26 Md dau |
Lap
dudc mo hinh thich hop nhir vay cho hhi toan la mot budc
quan trong, nhung mdi chi la phln
khdi
dau cua qua
trinh
giai
bai
toan. Trong viec hoan tat qua
trinh
giai,
khau cd ban nhat la dtra
tren
mo hinh toan hoc cua bai toan ta can de xuat mot phuong
phap
giai,
hay ly tu5ng hdn la xay dung mot thu tuc chat che xii
ly
mot
each
hieu qua cac thong tin
lien
quan den m6i du kien bai
toan, dl tii do thu dudc nghiem tUdng utng vdi ttrng dii kien. Cuoi
cung, can tien hanh phan
tich
va danh gia hieu qua
ciia
each
giai
bai toan cung nhu kha nang hien thuc hoa tren nhiing trang
thigt
bi
tinh
toan hien c6.
Xay
dung cac phudng
phap
hieu qua
giai
cac bai toan rieng re
nay sinh ttt thuc
tign
rat c6 y nghia doi vdi
ilng
dung. Dg c6 dUdc
nhiing
kgt luan hay nhiing ket qua nghien
ciiu
mang
tinh
khai quat,
cdc bai toan can dUdc xem xet trong mot khuon kh6 chung. Cac
nghign
ciiu
nhu vay giup ta c6 mot
each
nhin thong nhat doi v6i
van
d§"
phiic
tap cua cac bai toan, dong
thdi
cho ta nhiing hieu biet
khai
quat va nhiing hudng dan can thiet trong cac
tinh
huong cu
thg,
va vi the no khong chi c6 y nghia ly luan ma eon rat
thiit
thuc
cho
ling
dung. Viec nghien
ciiu
nay diidc
gi5i
han trong pham vi
cac bai toan quyet dinh, do ehiing eo mOt s\l thg hien kha tu nhign
dudi dang ngon
ngii
hinh
thiic
rat thich hop cho viec phan
tich
va
xii
ly thong tin hdi mot mo hinh
tinh
toan chung. Tuy nhien, viec
gidi
han nhtr vay thuc chat khong gay ngn mot han che nao dang
k^,
bdi thay vi can xem xet mot bai toan tim kiem hay bai toan
toi
uu noi
rigng,
ta c6 thl nghign
ciiu
bai toan quyet dinh khong
kh6
hon tuong
ling
vdi no, va tii nhiing ket qua nghien
ciiu
lign
quan den van de phiic tap cua bai toan quyet dinh, ta c6 thg di den
nhiing
ket luan thich hop doi vdi bai toan da cho.
De cac bai toan thuoe nhieu
linh
vuc
khae
nhau c6 the
duoe
xem
xet trong mot khuon kh6 chung va
dupe
giai
quyet trgn
ciing
mSt mo hinh
tinh
toan, sau day ta hay
tiing
bude
cu the hoa cac
digm
CO
ban trong
each
tiep can bai toan.
0.3 Cdch
tiep
can cac bdi
toan
27
0.3.1 Bai toan tim kilm va bai toan quyet dinh
D6
xac lap sir tuong
ling
giiia
bai toan tim kiem va bai toan quyet
dinh,
trude
tign
ta can phan biet cac
loai
bai toan ma ta xem xet.
Nhan thay rang, mot bai toan c6 thg
dupe
phat
bigu
thanh
hai
phan tach biet: phan Da kien vk phan Yeu cau. Doi vdi phan
Da kien, ta can xac dinh ro tap dii kien cua bai toan bao gom
nhiing
dii kien cu thg nao. Con phan Yeu cau thudng c6 hai
loai.
Loai
thii
nhat la mot Cau hoi ma doi vdi m6i dii kien bai toan
chi
can trd Idi don gian la "dung"
hoac
"sai". Bai toan vdi cau hoi
nhu
vay
dupe
gpi la bai
toan
guy it dinh {decision problem).
Loai
thii
hai la ygu cau Tim
kiem
nghiem doi vdi dii kien bat ky cho
triidc.
Bai toan vdi ygu cau nhu vay c6 tgn gpi la bdi
toan
tim
kiim
{search problem). Trong Idp cac bai toan tim
kiem,
cac bdi
todn
toi Uu (optimization problems) eo mot vi tri quan trpng. Bdi
toan
cite
dai hoa (maximization problem) va bdi
todn
cue
tiiu
hoa
(minimization
problem) la eac bai toan toi Uu vdi ygu cau tim kiem
nghiem
chap
nhan
dupe
vdi gia tri Idn
nhat
va nho
nhat
tuong
ling.
Bai toan quygt dinh tUOng
ling
vdi bai toan tim kiem c6 the
dupe
xac dinh dOn gian bang
each
thay Yeu
cau:
"Tim
nghiem doi
vdi
dii kien bat ky cho trude" bang Cau hoi: "Phai chang ton tai
nghiem
doi vdi moi dii kien da cho?" Trong trudng hpp nay tap dfl
kien
khong thay ddi. Thi du, bai toan "Hay tim chu
trinh
Hamilton
trong
moi do thi cho trude"
dupe
tuong
ling
vdi bai toan quyet dinh
sau day:
HAMILTONIAN
CYCLE
Da kien: Cho mot do thi G.
Cau
hoi: Phai chang trong G c6 chu
trinh
Hamilton?
Tuy
nhien, cac bai toan toi liu
dupe
tuong
ling
vdi cac bai toan
quyet dinh thich hpp hon. Bai toan quyet dinh tUOng
ling
vdi bai
28
M6 dau
to4n
circ
dai hoa (bai toan
cttc
tilu
hoa)
duoc
xac dinh nhir sau:
Tap da kien cua no
duac
xay dung
bang
each
them
vao mdi dH
kien
cm bai
toan
toi m mot
ranh
gidi
B tuy y,
thuoc
ciing mien xac
dinh
gia tri cua nghiem. Tiep
theo,
eau hoi
duoc
phat bigu rang,
doi
vdi m5i du kien nhu vay,
phdi
chdng
c6 mot
nghiem
chap
nhan
duac
vdi gia tri
khong
nho han B
{khong
Idn han B, tudng ijfng)?
Thi
du, bai toan cue dai hoa MAX-KNAPSACK
duoc
tuong
ling
vdi
bai toan quyet dinh sau day:
KNAPSACK
•
••
• •
• • • • '•'
DO
kien:
Cho hai day s6 nguyen duang
iwii
n ;> ^' •^li ^2, S„, S
va
Cau hoi:
Phai
chang
c6 mot tap con I C
{l,2, ,'n}
sao cho
E^^<S va .
E^t>S?
iei iei
Nhu
vay, moi bai toan tim kigm hay moi bai toi Uu noi rieng
deu
CO
the
duoc
tUOng
ilng
vdi mot bai toan quyet dinh ma thudng
la khong kho hon.
Rieng
doi vdi bai toan toi Uu,. do
viee
tinh
toan
gia tri cua nghiem bai toan toi uu la tUOng doi d6 dang, cho nen
bai toan quyet dinh tuong
ling
khong thg kho hon bai toan toi uu
ban dau. ' if*
Cuoi eung, ta tim
each
dac trung moi bai toan quyet dinh bdi
mot ngon ngu hinh thiic nao do,
bang
each
ma hoa (tufc mieu ta)
tiing
du: kien bai toan bdi mot tit tren
bang
chii thich hop va xac
dinh
ngon ngu: tuong
ling
vdi bai toan ay.
Viec
ma hoa nay eo thi
duoc
thuc hien
theo
mot quy
trinh
ehung vdi mot vai rang
buoc
can thiet. Sau day la mot quy
trinh
ma hoa thong dung mang
tinh
nguygn t^c. . , ,
0.3
Cdch
tiep
can cdc bai
toan
29
0.3.2
Ngon
ngu* bieu diln bai
toan
quyet
dinh
• Tinh sue tich.
Theo
le tu nhien, mot bai todn quyet dinh cung
thudng
duoc
di6n ta
bang
nhieu ngon ngu hinh thire
khae
nhau
theo
nhung phep ma hoa
khae
nhau doi vdi cac dU kien bai toan.
Song,
di dam bao yeu eau toi thigu ve
tinh
sue tich doi vdi ngon
ngii,
viec
ma hoa can
thoa
man cac ticu chuin sau day:
(ci)
Tiit
ma (xau bigu dien) cua moi dfl kien bai toan phai ngan
gon va khong dUdc "don them" nhUng thong tin khong
can thiet.
(C2)
Cac so tham gia trong dfl kien bai toan can
duoc
bigu dign
dudi
dang nhi phan
hoac
theo
mot co s6 nao do Idn hon 1
(bdi VI
dang bigu dign
theo
co s6 1 dai hon c3 ham mfl so vdi
bat ky dang bigu dien n^o
theo
cO so A; vdi > 2).
• Sd do ma hoa
chu§n.
Doi vdi
tflng
bai toan cu the ta dg dang
xay dung
duoc
mot phep ma hoa thich hop. Tuy nhign,
viec
dua ra
mot dinh nghia hinh thflc ve phep ma hoa la khong hg don gian.
Song,
ve mat nguyen tac, cac phep ma hoa thich hop co thg
duoc
xay dung dua trgn mOt scf dd md hoa
chudn,
ma
theo
do cac dfl
kien cua bai toan
dugc
bigu dien bdi cac "xau lien ket", tile "xau co
cau true", tren bang chfl chfla ^ = {0,1, - ,[,],(,),,} vdi ky tu cu6i
Cling
la dau phay " ,". Xau
lien
kit
dugc
dinh nghia mot
each
de
quy nhu sau:
(ci) Bigu dien nhi phan cua mot so nguygn k (mot xau bao gom
cac ky tU 0 va 1, co ky tu "-" d phia trudc ngu k la so am)
la, mot xau lien ket bieu thi so nguygn k.
(^2) Neu X la mot xau
lign
kgt bigu thi so nguygn k, thi [x] Ih mot
xau
lign
ket bieu thi "tgn" cua doi tugng mang so hieu k.
(ea) Neu </i, ^2,
•
•, ym la cac xau
lign
kgt bigu thi cac doi tugng
Yi,Y2, ,
y„„ thi
(yi,
^2,
•
•, 'Jm) la mot xau lien kgt bigu
thi
day {Y,,Y2, ,YJ.
30
Ma dau
Dxta
theo
so do ma hoa nay, ta c6 the bieu dien cac du; kien bai
toan bdi cac xau lien ket tren mot
bang
chii: nao do chiia cac ky
tu
thuoc
bang
chii ke tren. Di nhien, day la mot sd do nen no
chi mang tinh nguyen tac. D6 dap utng yeu cau ve tmh sue tich cua
ngon ngfl, trong ttog trudng hop cu thg ta c6 thg b6 sung nhung
quy tac thich hdp can thiet, nhung vln phai dam bao tinh
chuan
xac cila
viec
bigu
diin.
Dudi
day la nhflng bieu dign cua mot vai doi tUdng quen
thuoc
nhir:
tap hap, ham, so
hiiu
ti va do thi. Ta se dung ky hieu k d6 chi
bieu
diin
nhi
phdn
cua so nguyen dirong k.
De biiu dign mot tap hap Mu han X, dau tien ta sap xep cac
phan tit cua no
theo
trat tu nhu mot day X = {Xi, X2, , X„},
trong trudng hop chung
chua
c6 mot trat tu nhu vay. Khi do tap
X
duoc
bilu dign bc)i mot xau lien ket (xi,
X2, ,
trong do Xj
la xau lien kgt bigu dign phan tii X, tUdng
iJng
ciia day, \ i < n.
Mot ham f : X Y dUdc bieu dien b6i mot xau lign ket
((:ci,yi)(x2,y2)
• • •
(x„, :(/„)), trong do Xi la xau lien ket bigu dien
phan tijf Xj G X va yt la xau lign ket bigu dien phan tur /(X^) e Y,
l<i< n.
Mot so hHu ti q = rn/n, trong do rn va n la cac so tu nhign
nguygn to ciing nhau, dUdc bigu dign bdi xau lien ket (m, /i), trong
do rii va h la bigu dign nhi phan cua cac so rn va n tiTdng
ling.
Mot do thi CO
hxldng
G = {V, A) dildc bieu dien bdi mot xau
lign
ket (x,y), ta ky hieu la (G) ^ (x,y), trong do x la xau lien
ket bigu dien tap dinh V va y la xau lign ket bieu dien tap cung
A
cua do thi (m5i phan
tilt
ciia A la mot cap cac dinh
thuoc
V).
Cu thg, vdi V =
{vuV2, ,
Vn} va A =
{ui,
a2, •,
"m},
trong do
cung Uj = 1 < j < "i,
theo
sd do ma hoa chuin ngu trgn
ta CO thg bigu dign do thi G nhu sau:
(G) = (([i],[2],
,[/i]),(([/:'i],[/t,]),(N,[M),
•
XlkmUKM-
Tuy
nhign,
dg dap Ung yeu cau ve tinh sue
tich
cua
ngon
ngii, do
thi G CO thg
dudc
bigu
dign
bdi mot xau don
gian
hon
(G) =
i\2, ,ntl(/^i,/i0(^-2,/i2) (fc^,/i^)
tren
bang
chU gom sau ky tu {0,1, (, ,},
trong
do xau
trudc
ky tu t)
bigu
dign
tap dinh va xau sau JJ
bigu
dign
cac
cung
cua
do thi. Thi du, do thi hinh
ngoi
sao nam
canh
Gj vdi tap dinh
{vi,V2,
V3, V4, Us} (Hinh 0.2)
dudc
bigu
dign
bdi xau lien ket
(Gi) =
i,2,3,4,5«(i,3)(i,4)(2,4)(2,5)(3,5).
•
Ngon
ngiJ
dac
trtfng
cua bai
toan
quygt
dinh. Gia
sijf
11
la mot bai
toan
quyet
dinh vdi tap dU kien Dn va cau hoi Qn
trgn
m5i dvi kien bai
toan.
Khi do Qn xac dinh mot tinh
chat
doi vdi
moi dii kien cua bai
toan,
tiJc
mot ham tii tap Dn den tap cac gia
tri
chan
ly {DUNG, SAl} nhu sau: Doi vdi m5i dii kien d e Dn, ta
CO
Quid)
= DUNG khi cau hoi Qn
trgn
dii kien d
dudc
tra Idi la
"dung";
trong trudng hdp
ngUdc
lai.
Quid)
= SAL
Gia
sijr e la mot
phep
ma hoa
thich
hdp n^G do doi vdi bai
toan
n, ma
theo
d6 moi dU kien bai
toan
dUdc
bigu
dien
bdi mot
xau lien kgt
tren
bang
chfl E. Nhu vay, e anh xa cac dU kien bai
toan
thanh
cac xau
thuoc
£*. Dg ddn
gian,
khi
khong
can luu y
den
phep
ma hoa t, t;a ky hieu (d) = e{d) doi vdi mdi d e Dn-
Ta dinh
nghia
cac
ngon
ngU sau:
L{Du)
=
{{d)\deDu},
L(n) =
{{d)\deDn
^ Qn{d) = DUNG}.
Ro
rang
ngon
ngU L{U)
dien
dat noi
dung
cua bai
toan
IT, nen
duoc
goi la
ngon
ngU dac
trxing
cua IT, hay
ngon
ngvC
tuCdng
"^ng vdi bai
toan
U, va dUdc ky hieu
ngan
gon bdi chfl
nghigng
77.
Ta CO
32
Md dau
0.3.3
Doan
nhan
ngon
ngu*
Cho n la mot bai toan quyet dinh, L{Du) 1^ ngon ngfl tren bang
chO: E bieu dign tap dii kien cua n, va /7 la ngon ngu: tircng urng vdi
bM toan IT. Gia sijt ton tai mot mo hinh
tinh
toan hinh thiic, m^
khi
xiJt ly tren m6i xau thuoc L{Dn), hay thuoc E* noi chung, no
CO
thg phan biet dirac xau nao thuoc 17 va xau nao khong; nghia
Ih,
mo hinh
tinh
toan ay c6 kha nSng "nhan biet" hay "doan nhan"
ngon ngii 17. Khi do ta dg dang thu diioc Idi giai cua bai toan quyet
dinh
n.
Nhu vay, thay cho
viec
xay dirng thuat toan giai bai toan quyet
dinh
cho trildc ta c6 the tim kiem mot mo hinh
tinh
toan hinh thiic
liho do dg doan nhan ngon ngiJ tuong ling vdi bai toan ay. Mot
trong nhiing mo hinh nhu vay da
duoc
Alan Turing de xuat, va vi
the no
duoc
mang ten ong, do la may Turing.
May Turing la mot mo hinh
tinh
toan don gian nhung kha tSng
quat, CO kha nSng di6n ta mot
each
ro rang va ti mi hau het moi
qua
trinh
tmh toan. Vi vay, may Turing
duoc
sii dung nhu mot
cong
cu
kha thuan tien trong
viec
khao sat cac qua
trinh
tinh
toan noi
chung, va dac biet trong vi^c phan tich do phiic tap cua thuat toan.
Bai tap
0.1 Hay dien ta mot
each
phi hinh thilc bang tieng Viet tiing tap
hop sau day:
a.
{1,3,5,7, }.
b.
{ ,-4,-2,0,2,4, }.
c.
{n
I
n = 2m doi vdi m6i m thuoc N}.
d. {n| n = 2rn doi v6i mot m nho 66 thuoc N, ; .
va n = 3k doi vdi mot k nho do thuQc N}.
Bai
tap
33
0.2 Hay di6n ta mot
each
hinh thilc ttag tap hop sau day:
a. Tap bao gom cac so 2, 4 va 6.
b. Tap bao gom tat ca cac so nguyen duong Idn hon 10.
c. Tap bao gom tat ca cac so tu nhien nho hon 10.
d. T^p bao gom tir aba.
e. Tap bao gom
tijf
rong.
f. Tap khong bao gom gi ca.
0.3 Cho A = {x,y} vk B =
{x,y,z}.
Hay tra Idi cac cau hoi
sau day:
••••••
. - . •'j , . . , •
a. A la tap con ciia B? '
•
'
b. B la tap con cua A? '
c. /I n/? cu thi la tap
nao?
• -
d. AU B cu the la tap
nao?
e. A X B cn thg la tap
nao?
f. ViA) cu thg la tap
nao?
0.4 Neu ^ CO a phan tuf va B c6 b phan tut, thi A x B c6 bao
nhigu
phan tut?
0.5 Neu C CO c phan tut, thi ho tat ca cac tap con cua C, tiic
V{C),
CO,
bao nhieu phan tut?
0.6 Hay cho bigt, trong so nhiing dieu sau day, digu nao dung vk
dieu nao
sai?
n
a. 3n = 0
b. n^ = 0[n].
c.
n^ = 0[nlog^n.
d. n log
71
= 0[n^
e. 3" =
2°t"l.
f. 22" = Of22"l.