#I
ntr
oduct
iont
oDat
aSt
ruct
ures&Al
gor
it
hms
CodeWi
thshar
an
Thiscour sei sprimaril
yforplacementpr eparati
onandwi ll beusingCandC++f orthe
algor
ithmsanddat ast r
uctures.Thenotesf orthecour sewi l
lbepr ovidedinPDFf or
matf or
conveni ence.Dat astruct
uresar eessenti
alfordev el
opi ngef fi
cientalgorit
hmst hatar
rangedata
i
nmai nmemor yforoptimal usage.It
'si
mpor tanttonot et hatalgor i
thmsanddat astructur
es
aretwodi f
ferentthings.Cisabar e-
bonespr ogrammingl anguaget hatrequir
esyoutodo
every
t hingy ourself
,butJav acanal sobeusedt oi mplemental gorithms.Thiscourseisidealf
or
thosel ookingtoswi tchjobsorpr epareforinter
v i
ews,andt hereisa15- hourvi
deoonC
programmi ngav ail
ableont hechannel wit
hnot es.
shoul dbeabl et ousei tiny ourwor kori ny ourpr ojectsori ny ourcour sesori ny ourprojects
thaty ouar edoi ngint hef utureori ny ourwor kthaty ouar edoi ngrightnowsoi fyouwantt o
usesomet hingt heny oushoul dbeabl et ousei ti
ny ourwor kori nyourpr ojectsori ny our
cour sesori ny ourfut urewor kori ny ourpr ojectst hatyouar edoi ngr i
ghtnow.Sodat a
structuresandal gor i
thmsar ethingst hathel pusi nourwor kori nourpr ojectsori nourcour ses
orinourf utur epr oj
ect sori nourwor kori nourpr ojectsthatwear edoi ngr ightnowsoi fy ou
wantt ousesomet hingt heny oushoul dbeabl etousei tinyourwor kori ny ourprojectsori n
yourcour sesori ny ourf uturewor kori ny ourpr ojectsthaty ouar edoi ngr i
ghtnowwat erinapot
andy ouputt het eabagi nthecupandy oumaket hecof feeNowwhati st hedi f
ferencebet ween
datast r
uctur esandal gorit
hms?Al gorithmsar especi fi
cst epst hatneedt obet akeni nor derto
solveapr oblem. Ihav ebeeni nthei ndust r
yf oralongt i
menowandIhav eseenal otofpeopl e
l
ear ningC, C++andwhent heystar ttolearni ttheygetv erylost&conf used&t heydon' tknow
whatt heyar edoi ng&t heydon'tknowhowt ouset helanguagepr oper l
y&ev entuall
yt heyst op
l
ear ningit&t heyendupbecomi ngabegi nneragai n&t hatisnotgoodf ortheindust ry&i tisnot
goodf orthel ear nersei thersoIwoul dsayl earnC, C++&don' tgetlostint helanguagel earning
process
Dat astructurei sthearr
angementofdat ainmai nmemor y,andtheconceptofdat abase,dat a
war ehouse, andbi gdatawill
becov eredinthecourse.Thef uelofbigal gor i
thmsi sdata,and
keepi ngitproper l
yintheharddiskisessentialf
oreffici
entretri
eval,updat i
ng, anddeleti
on.
Althoughdat awar ehousi
ngisbey ondthescopeoft hiscour se,i
t'
sst i
l
l impor t
anttounder stand
i
t.Dat ast r
uctur esandalgori
thmsar ebestlear
nedf rom CandC++, whi chpr ov i
deagood
pictureofmemor yusage.Theconcept sofstackandheapar eessentialinunder st
andinghowC
progr amswor k,andspaceandt imecompl exit
ywi l
lbecov eredinfutur evideos.Ov er
all
,this
cour sewillcov ermanydat astr
uctureconcepts,suchasl i
nkedl i
sts,arrays,binarysearcht r
ees,
andmor e.
, #Ti
meCompl
exi
tyandBi
gONot
ati
on
Sotheinputsi
zedidn'ti
ncreaseandther unt
imeofthealgor
it
hmsdi dn'ti
ncr
easeeit
her.No, i
t
doesn'
tdependont hesizeoftheinput.Whenweaskquest i
onslikeast hei
nputwil
li
ncrease,
Thentherunti
mewi ll
changeasperwhat ?Andaft
erthatNowy ouwillgotoaunty
'shouseYou
wil
lbetreat
ed.Considerther
earediffer
entrout
estocomeandgo.
Iwantt otellyouguy sonest ory.Ithappenedl ikethis,Iwasbor edinmyhouse.Iwassobor ed
thatIneededsomeent ert
ainment .Thisguyhasamazi nggamesl i
kePubgandGTA5.Sohehas
acol lecti
onofgames.Hel ikespl ay i
nggamesal ot.Andy oucangetev erytypeofgamef rom
him.Butt hereisonepr oblem , Ialsousej io.Heal sousesj i
oandwegetj ust1Gbf oroneday .
Andwi thmor einternet,wecan' tsellfi
lesandal l
.Sof orme, whati sthef astestwayt otake
thegamef rom thi
sf r
iend.Sowhatwi llIdo?Iwi l
ltakemybi keAst hesi zeoft hisi
nputwi l
lget
i
ncr eased, therunti
meoft heal gor i
thmswi l
li
ncrease.Thi smeanst hatast heinputsizeis
i
ncr easingl i
kethatThet imer equiredt osendt hefile,Thatisalsoincreasing.Therei sahard
diskt hent hereisyourmot or cycle.Youwi llgoont hatbike.Andy ouwi lltakeitandi nharddisk
whet hery oubr i
ng250kborTb.Ast heinputsizeofal go2increasedliket hatwhathappened?
Fort hat,ther ewasnochangei nt her unti
me.Runt i
mer emainedt hesame.Sowesayast he
sizeoft hei nputkeepsoni ncr easing, Similarl
y,whatist heeffectoftheal gori
thm onr unt
ime.
Wear etot ryi
ngt oremov et het i
mecompl exi
tyoft hem.
i
st healgori
thm thatrunsi nconst antti
me.K1nt othepower0+k2+k3+k4Thi st i
mei srequir
ed
i
nal go2.Thesent encei s:Runt i
meofi t,
therear
esomet hi
ngsthatwewi llrecite.Becausewe
won'tconstantl
yuseourbr ai nsagai nandagai n,
asweseeBi gOof1i tisconst ant.Now, come
hereandl i
stentoanot herst ory.Ifwedoananal ysisoft hefir
stal
gori
thm, I
fIdoTal go1Then
whatwi l
lhappenher e?Andal ongwi thconsiderthatgamei sofL3kb.Ifthegamei sofNkb
thenhowmucht i
mewi l
l y
ouneed?Thesent enceis: Runtimeofit,
therearesomet hingsthat
wewi l
lrecit
e.Therearepol ynomi alalgori
thmsandt hereareexponenti
alalgorithmsandt here
arelogari
thmicalgorit
hmsandt herear eexponentialfuncti
onsandtherear elogar i
thmic
functi
ons.Therear ealsoal gor i
thmst hatarenotl i
nearint i
me.
#Asy
mpt
oti
cNot
ati
ons:
BigO,
BigOmegaandBi
gThet
aExpl
ained
We'
llt
alkali
tt
lebitaboutasymptot
icnot
ati
on.wetal
kedaboutor
der
.Wetal
kedaboutor
der
ing.
Wehavepri
maril
y3t ypesofasy
mpt i
cnotat
ionbi
gO,bigThet
a( )andbi
gOmega()bi gOis
ntr
oduct
iont
oDat
aSt
ruct
ures&Al
gor
it
hms
CodeWi
thshar
an
Thiscour sei sprimaril
yforplacementpr eparati
onandwi ll beusingCandC++f orthe
algor
ithmsanddat ast r
uctures.Thenotesf orthecour sewi l
lbepr ovidedinPDFf or
matf or
conveni ence.Dat astruct
uresar eessenti
alfordev el
opi ngef fi
cientalgorit
hmst hatar
rangedata
i
nmai nmemor yforoptimal usage.It
'si
mpor tanttonot et hatalgor i
thmsanddat astructur
es
aretwodi f
ferentthings.Cisabar e-
bonespr ogrammingl anguaget hatrequir
esyoutodo
every
t hingy ourself
,butJav acanal sobeusedt oi mplemental gorithms.Thiscourseisidealf
or
thosel ookingtoswi tchjobsorpr epareforinter
v i
ews,andt hereisa15- hourvi
deoonC
programmi ngav ail
ableont hechannel wit
hnot es.
shoul dbeabl et ousei tiny ourwor kori ny ourpr ojectsori ny ourcour sesori ny ourprojects
thaty ouar edoi ngint hef utureori ny ourwor kthaty ouar edoi ngrightnowsoi fyouwantt o
usesomet hingt heny oushoul dbeabl et ousei ti
ny ourwor kori nyourpr ojectsori ny our
cour sesori ny ourfut urewor kori ny ourpr ojectst hatyouar edoi ngr i
ghtnow.Sodat a
structuresandal gor i
thmsar ethingst hathel pusi nourwor kori nourpr ojectsori nourcour ses
orinourf utur epr oj
ect sori nourwor kori nourpr ojectsthatwear edoi ngr ightnowsoi fy ou
wantt ousesomet hingt heny oushoul dbeabl etousei tinyourwor kori ny ourprojectsori n
yourcour sesori ny ourf uturewor kori ny ourpr ojectsthaty ouar edoi ngr i
ghtnowwat erinapot
andy ouputt het eabagi nthecupandy oumaket hecof feeNowwhati st hedi f
ferencebet ween
datast r
uctur esandal gorit
hms?Al gorithmsar especi fi
cst epst hatneedt obet akeni nor derto
solveapr oblem. Ihav ebeeni nthei ndust r
yf oralongt i
menowandIhav eseenal otofpeopl e
l
ear ningC, C++andwhent heystar ttolearni ttheygetv erylost&conf used&t heydon' tknow
whatt heyar edoi ng&t heydon'tknowhowt ouset helanguagepr oper l
y&ev entuall
yt heyst op
l
ear ningit&t heyendupbecomi ngabegi nneragai n&t hatisnotgoodf ortheindust ry&i tisnot
goodf orthel ear nersei thersoIwoul dsayl earnC, C++&don' tgetlostint helanguagel earning
process
Dat astructurei sthearr
angementofdat ainmai nmemor y,andtheconceptofdat abase,dat a
war ehouse, andbi gdatawill
becov eredinthecourse.Thef uelofbigal gor i
thmsi sdata,and
keepi ngitproper l
yintheharddiskisessentialf
oreffici
entretri
eval,updat i
ng, anddeleti
on.
Althoughdat awar ehousi
ngisbey ondthescopeoft hiscour se,i
t'
sst i
l
l impor t
anttounder stand
i
t.Dat ast r
uctur esandalgori
thmsar ebestlear
nedf rom CandC++, whi chpr ov i
deagood
pictureofmemor yusage.Theconcept sofstackandheapar eessentialinunder st
andinghowC
progr amswor k,andspaceandt imecompl exit
ywi l
lbecov eredinfutur evideos.Ov er
all
,this
cour sewillcov ermanydat astr
uctureconcepts,suchasl i
nkedl i
sts,arrays,binarysearcht r
ees,
andmor e.
, #Ti
meCompl
exi
tyandBi
gONot
ati
on
Sotheinputsi
zedidn'ti
ncreaseandther unt
imeofthealgor
it
hmsdi dn'ti
ncr
easeeit
her.No, i
t
doesn'
tdependont hesizeoftheinput.Whenweaskquest i
onslikeast hei
nputwil
li
ncrease,
Thentherunti
mewi ll
changeasperwhat ?Andaft
erthatNowy ouwillgotoaunty
'shouseYou
wil
lbetreat
ed.Considerther
earediffer
entrout
estocomeandgo.
Iwantt otellyouguy sonest ory.Ithappenedl ikethis,Iwasbor edinmyhouse.Iwassobor ed
thatIneededsomeent ert
ainment .Thisguyhasamazi nggamesl i
kePubgandGTA5.Sohehas
acol lecti
onofgames.Hel ikespl ay i
nggamesal ot.Andy oucangetev erytypeofgamef rom
him.Butt hereisonepr oblem , Ialsousej io.Heal sousesj i
oandwegetj ust1Gbf oroneday .
Andwi thmor einternet,wecan' tsellfi
lesandal l
.Sof orme, whati sthef astestwayt otake
thegamef rom thi
sf r
iend.Sowhatwi llIdo?Iwi l
ltakemybi keAst hesi zeoft hisi
nputwi l
lget
i
ncr eased, therunti
meoft heal gor i
thmswi l
li
ncrease.Thi smeanst hatast heinputsizeis
i
ncr easingl i
kethatThet imer equiredt osendt hefile,Thatisalsoincreasing.Therei sahard
diskt hent hereisyourmot or cycle.Youwi llgoont hatbike.Andy ouwi lltakeitandi nharddisk
whet hery oubr i
ng250kborTb.Ast heinputsizeofal go2increasedliket hatwhathappened?
Fort hat,ther ewasnochangei nt her unti
me.Runt i
mer emainedt hesame.Sowesayast he
sizeoft hei nputkeepsoni ncr easing, Similarl
y,whatist heeffectoftheal gori
thm onr unt
ime.
Wear etot ryi
ngt oremov et het i
mecompl exi
tyoft hem.
i
st healgori
thm thatrunsi nconst antti
me.K1nt othepower0+k2+k3+k4Thi st i
mei srequir
ed
i
nal go2.Thesent encei s:Runt i
meofi t,
therear
esomet hi
ngsthatwewi llrecite.Becausewe
won'tconstantl
yuseourbr ai nsagai nandagai n,
asweseeBi gOof1i tisconst ant.Now, come
hereandl i
stentoanot herst ory.Ifwedoananal ysisoft hefir
stal
gori
thm, I
fIdoTal go1Then
whatwi l
lhappenher e?Andal ongwi thconsiderthatgamei sofL3kb.Ifthegamei sofNkb
thenhowmucht i
mewi l
l y
ouneed?Thesent enceis: Runtimeofit,
therearesomet hingsthat
wewi l
lrecit
e.Therearepol ynomi alalgori
thmsandt hereareexponenti
alalgorithmsandt here
arelogari
thmicalgorit
hmsandt herear eexponentialfuncti
onsandtherear elogar i
thmic
functi
ons.Therear ealsoal gor i
thmst hatarenotl i
nearint i
me.
#Asy
mpt
oti
cNot
ati
ons:
BigO,
BigOmegaandBi
gThet
aExpl
ained
We'
llt
alkali
tt
lebitaboutasymptot
icnot
ati
on.wetal
kedaboutor
der
.Wetal
kedaboutor
der
ing.
Wehavepri
maril
y3t ypesofasy
mpt i
cnotat
ionbi
gO,bigThet
a( )andbi
gOmega()bi gOis