Professional Documents
Culture Documents
CSC-SSC
CSC-SSC
Computer
Science
Curriculum
SundarSTEMSchool
Preparedby:AmirKafshdarGoharshady
April-June2021
]\
Foreword
Thiscurriculumconsistsoftwoparts.Thefirst(Normal,N)partisdesignedto
be taught to every student of the Sundar STEMSchool.Thesecond(Elite,E)
part targets only the students who are particularly talented in computing
(top 5-10%)orwouldliketoentertheInformaticsOlympiads,aswellasthose
who aspire for an academic career in computing. Both curricula cover the
same basic core concepts.However,thenormalcurriculumfocusesmoreon
applications and examples, whereas the elite curriculum gets progressively
deeperandmoretheoreticalatamuchfasterpace.Bothcurriculaaremeant
tobetaughtontopofanormalhigh-schooleducation.
The Main Challenge. A common issue in the current educational systemin
Pakistan, both at high-school level and in the university, is that it does not
prepare its graduates for algorithmic problem-solving or logical
(mathematical) thinking. The unfortunate result is that even the best
Pakistani university graduatesareutterlyunfitforpursuinggraduatestudies
in theoretical computer science. As an anecdote,overthecourseofthepast
year, the author has interviewed more than 20 students who graduated at
the top of their class f rom some of the most well-known universities in
Pakistan. Unfortunately, none of them could even reason at the level of a
talented high-school graduate. This sad situation leads to a vicious cycle,
affecting every level, and ultimately culminating in a lack of theoretical
computer scientists among the faculty at Pakistani universities. Pakistani
talentisinsteadbeingchanneledintolessdemandingaspectsofcomputing,
such assoftwaredevelopment,orinthecaseofuniversities,purelyempirical
research.
1
]\
Goals. The ultimate goal of this curriculum is to break thisviciouscycleand
provide our students with an early introductionandfirmbasisintheoretical
computer science. We aim to reverse the situation and make sure that our
students have a visible advantage over their peers in other countries. The
specificlearningoutcomesareasfollows:
1. Logical reasoning ability and mastery ofbasicsettheory,propositional
and first-order logic, as well as reasoning strategies such as proof by
inductionandcontradiction
2. Basicfamiliaritywithdiscretemathematics,especiallywhenitcomesto
enumerativecombinatoricsandgraphtheory
3. Familiaritywithclassicalalgorithms
4. End-to-endalgorithmicproblem-solvingability,including:
a. Mathematicalmodelingofareal-worldproblem
b. Reasoningaboutitscomplexity(e.g.NP-hardness)--onlyinE
c. Designinganalgorithmtosolveit
d. Formallyprovingthealgorithm’scorrectness,and
e. Analyzingtheasymptoticruntimeofthealgorithm
5. AlgorithmicprogrammingexperienceandfluencyinC/C++
Assumption. We assume that the students have already passed a basic
codingcourse(e.g.inPython)beforetheybeginwiththiscurriculum.Sundar
STEMschoolprovidessuchcoursesoverthesummer.
Structure.Theelitecurriculumisdividedinto80lessons.Thegoalistocover
30 lessons in each of the firsttwoyearsandtheremaining20lessonsinthe
third year. The normal curriculum is divided into 60 lessons, covering 20
lessonsperyear.
The third-year elite lessons are much more advancedandresemblethefirst
fewsessionsofundergraduatecourses.Theideaistomakesurethestudents
2
]\
obtainaverystrongfoundationinthefirsttwoyears,andthengetatasteof
thevariousmoderndirectionsinTCSintheirfinalyear.Whilethelatterpartis
broad,itisnotdeep.Itonlycoversthemostbasicideas.
The teachers will have significant flexibility with respect to the amount of
time that should be spent oneachlesson(basedonthestudents’progress).
However, each lesson has clearly-defined objectives and learning outcomes
and the teachers shall try their best to make sure every student achieves
theseoutcomes.
There are two fundamental guiding principles in the way this curriculum
shouldbetaught:
1. Emphasis on Proofs: The students should obtain the mindset of not
believing anything unless they have a formal proof for it. Every
statement is assumed to be untrustworthy and every algorithm is
assumed to be incorrect unless and until one can provide a detailed
mathematical proof of correctness. Unless otherwise noted, in every
lesson, convincing proofs of correctnessshouldbederivedinanactive
discussion with the students. The teacher’s role is to guide these
discussions.Theproofsshouldneverbespoon-fedtothestudents.The
students are the ones who should come up with the proof, even if it
takesmuchlonger.
2. Emphasis on Implementation: While most of the lessons are mainly
theoretical in nature, it is extremely important that the students
implement every single one of the algorithms that are covered inthis
curriculum.
For the elite curriculum, we only use C and C++ for implementation
lessons and homeworks.Theselanguagesgivetheprogrammeravery
high degree off reedom.Thisispreciselywhatweareaimingfor,since
we wouldliketocoveralotofdifferentdatastructures.Forthenormal
3
]\
curriculum, any programming language is fine and it is especially
recommendedthatthestudentsusePython.
Operating System. All students are required to use Ubuntu for every
programmingtask.Weusegccandg++forcompilation.
4
]\
ListofLessons
(1stYear,Elite)
Key:
A AlgorithmsandComplexity
C CodingandProgrammingLanguages
D Discretemathematics(excludinggraphtheory)
G Graphtheory
L LogicandSetTheory
1. DIntroductiontobinarynumbers
2. LB
asicsettheory
3. CData-typesinC/C++andtheimportanceofthetypesystem
4. CReadinginputandwritingoutputinC/C++
5. CArrays,conditionalsandloopsinC/C++
6. CR
epresentingnumbersandcharactersinacomputer
7. LRelationsandfunctions
8. CFunctionsandscopes
9. ASorting(bubblesort,selectionsort,insertionsort)
10. LIntroductiontopropositionallogic
11. AD
ivideandconquer
12. A
Mergesort
13. DBasiccounting(principlesofadditionandmultiplication)
14. G
Introductiontographsanddigraphs
15. LP
roofbycontradiction(andcontrapositive)
16. DPermutationsandnPk
5
]\
17. G
T
reesandforests
18. AGB
readth-firstsearchanddepth-firstsearch
19. LIntroductiontomathematicalinduction
20. G
Connectedcomponentsandstrongly-connectedcomponents
21. C
Bigintegers
22. G
EulerianandHamiltoniancircuits/trails
23. DChoicesandnCk
24. G
D
egreesandbijections
25. LQuantifiersandfirst-orderlogic
26. AA
symptoticruntimeanalysis
27. AIntroductiontogreedyalgorithms
28.AH
eaps
29. G
T
ournaments
30. A
S
orting(countingsort,bucketsort,radixsort)
6
]\
ListofLessons
(2ndYear,Elite)
1. G
B
ipartitegraphs
2. CP
layingwithstrings
3. DB
asicprobability
4. AM
aster’sTheorem
5. DP
ermutationsandchoiceswithrepetitions
6. AQ
uicksortandquickselect
7. DPartitions
8. DLP
rincipleofinvariance
9. AT
opologicalsortingandstronglyconnectedcomponents
10. CStructsandclasses
11. AD ijkstra’salgorithm
12. CPointersandmemorymanagement(+linkedlists)
13. AIntroductiontodynamicprogramming(+knapsack)
14. AF
loyd-WarshallandBellman-Fordalgorithms
15. AS
tringmatching(Rabin-Karp)
16. AS
tringmatching(KMP)
17. AB
inarysearchtrees
18. DThepigeonholeprinciple
19. AV
ectorsandtheiramortizedruntimeanalysis
20.CVectorsandsets
21. CO
perators
22. CF
urtherdatastructuresintheC++standardlibrary
23. AIntroductiontonumbertheoreticalgorithms
7
]\
24. G
M
atchings
25. A
GM
aximumbipartitematching
26. C
Iteratorsand“auto”
27. C
M
acros
28. A
Data-structuresfordisjointsets
29. A
T
ries
30. A
H
ashing
8
]\
ListofLessons
(3rdYear,Elite)
1. DTheinclusion-exclusionprinciple
2. GIntroductiontonetworkflow
3. AFord-Fulkersonalgorithm
4. LCountablevsuncountable
5. AM
emoization
6. ALowestcommonancestor(LCA)
7. CT
emplates
8. ARandomizedbinarysearchtreesandtreaps
9. DC
ombinatorialgames(winningandlosingpositionsandNim)
10. DC
ombinatorialgames(Sprague-Grundy)
11. ABalancedbinarysearchtrees(AVL)
12. AS
egmenttrees
13. AF
enwicktrees
14. AIncomputabilityandthehaltingproblem
15. AP
andNP
16. AReductionsandNP-hardness
17. AIntroductiontorandomizedalgorithms(2-3examples)
18. AIntroductiontoparameterizedalgorithms(2-3examples)
19. AIntroductiontokernelization(2-3examples)
20.AIntroductiontoapproximationalgorithms(2-3examples)
9
]\
ListofLessons
(1stYear,Normal)
1. DIntroductiontobinarynumbers
2. LB
asicsettheory(intersection,union,equality,subsetsandsupersets)
3. LRelations(pairsandtuples,equivalencerelations)
4. LFunctions(one-to-one,onto)
5. CR
ecursion
6. ABubblesort
7. AInsertionsort
8. AB
inarysearch
9. AWarmer-colder
10. AT
wo-dimensionalsearch
11. LP
ropositionallogic(truthvaluesandoperators)
12. LP
ropositionallogic(proofbytruthtables)
13. DB
asiccounting(principlesofadditionandmultiplication)
14. GIntroductiontographsanddigraphs
15. LP
roofbycontradiction
16. L
Gentleintroductiontoquantifiers
17. L
Counterexamples
18. A
C
ompletesearch(bruteforce)
19. AR
eturningchange
20. ATheknapsackproblem
10
]\
ListofLessons
(2ndYear,Normal)
1. AN
umberofpathsinagrid
2. G
T
rees
3. A
D
epth-firstsearch
4. A
B
readth-firstsearch
5. A
C
ountingsort
6. A
R
adixsort
7. A
P
rimalitychecking
8. A
P
alindromes
9. D
P
ermutationsandfactorial
10. D
n Pk
11. AMergesort
12. G
Connectedcomponentsandstrongly-connectedcomponents
13. D
C hoicesandnCk
14. C
Playingwithstrings
15. D
IntroductiontomathematicalinductionI(introduction)
16. D
IntroductiontomathematicalinductionII(weakinduction)
17. D
IntroductiontomathematicalinductionIII(stronginduction)
18. D
IntroductiontomathematicalinductionIV(problemsolving)
19. A
Q uicksort
20. AQ ueuesandstacks
11
]\
ListofLessons
(3rdYear,Normal)
1. DBasicProbability
2. ACS ingly-linkedlists(Pointersviaarrays)
3. GT ournaments
4. AD oubly-linkedlistsandthetexteditorproblem
5. CImplementingbinarytrees
6. AT reetraversals
7. DGentleintroductiontothepigeonholeprinciple
8. AAsymptoticruntimeanalysis
9. AC hesspuzzle:Howtocheck
10. AK nightonachessboard
11. GB ipartitegraphs
12. DC ombinatorialgames(winningandlosingpositions)
13. DN imwithtwoheaps
14. AIntroductiontogreedyalgorithms
15. AM edianviaquickselect
16. ATopologicalsort
17. ADijkstra’salgorithm
18. ADGreatestcommondivisor
19. GEulerianandHamiltoniancycles/paths
20.ATries
12
]\
DetailsofLessonsand
LearningOutcomes
Notes:
● Thehomeworksforeachlessonwillalsoincludeproblemsf rom
Codeforces.comortrain.usaco.org.Thesearenotincludedinthe
homeworkplanbelowandwillbechosenonacase-by-casebasis.
Whennootherhomeworkplanisgiven,oneshouldonlyfocuson
codeforcesproblemsandhavethestudentssolve5-10ofthemuntil
theymasterthetopicathand.
● Weshouldhaveameetingeveryweektodiscussandupdatethe
upcominglessonsbasedonthestudents’progress.
● Itisfineifweendupcoveringsomecoursesfaster/moreslowly.The
curriculumisflexible.
● Thereisahugeemphasisoncodingearlyandcodingalot.
● ThestudentsmustuseUbuntuandastandardcompiler(gcc/g++).
13
]\
IntroductiontoBinaryNumbers(1N,1E)
CoveredTopics
● Representingnumbersinvariousbases
● Integersinbase2(binary)
● Addition,subtractionandmultiplicationinbinary
● Fractionalbinarynumbers(decimalpoint->binarypoint)
PresentationNotes
Thef ractionalpartisonlypresentedintheelitecurriculum.
LearningOutcomes
● Abilitytoconvertnumbersbetweenbases(especiallydecimaltobinary
andback)
● Abilitytoperformbasicmathematicaloperationsonbinarynumbers
HomeworkPlan
● Bothcodingandpen-and-paperhomeworksarerequired.Inthe
pen-and-paperhomeworks,thestudentsareaskedtoperform
mathematicaloperationsinbinaryandtoconvertnumbersbetween
bases.Inthecodinghomework,thestudentshavetowriteaprogram
thatconvertsbothnegativeandnon-negativeintegersbetween
decimalandbinary.
14
]\
Basicsettheory(1N,1E)
CoveredTopics
● Anintuitivedefinitionofthenotionof“set”
● Elements
● SubsetsandSupersets
● Equalityofsets
● Powersets
● Setoperations(intersection,union)
● Venndiagrams
PresentationNotes
● MentionthatweassumetheexistenceofauniversalsetUandonlytalk
aboutitssubsets
● DonotgetintoZermelo-Fraenkel.Wewanttoprovideaveryinformal
andintuitiveintroductiontosets.
LearningOutcomes
● Abasicknowledgeofsettheoryandfluencywithset-theorynotation
● AbilitytoreasonusingVenndiagrams
● Abilitytoformallyprovetheequalityoftwosets(byshowingthateach
setisasubsetoftheother)
HomeworkPlan
● Pen-and-paper:Askthestudentstoproveseveralidentitieswithset
operations
15
]\
● Coding: Writingacodethatgetsasetofintegersandprintsitspower
set
16
]\
Relations(1N)
CoveredTopics
● Theproductoftwoormoresets(pairsandtuples)
● Equalitybetweenpairsandtuples
● Thenotionofarelationbetweentwosets
● Thevariousnotationsusedtospecifyarelation
● Reflexive,SymmetricandTransitiveproperties
● Equivalencerelationsandpartitions
PresentationNotes
● Itisusefultorelyonthestudents’understandingofthenotionoftuple
inprogramminginordertopresentpairsandtuplesinaset-theoretic
sense.
● Donotgetintothedifferencebetween((x,y),z)and(x,(y,z))orother
suchformaldistinctions.
LearningOutcomes
● Abilitytoreasonaboutproductsofsetsandrelations
● Fluencyinidentifyingpropertiessuchasreflexivity,symmetryand
transitivity
● Aconceptualunderstandingoftherelationshipbetweenequivalence
relationsandpartitions
17
]\
HomeworkPlan
● Pen-and-paper:Computetheproductofgivensets/Decideifgiven
relationsarereflexive,symmetric,ortransitive/Convertbetween
partitionsandequivalencerelations
● Coding:Writeacodethatgetstwosetsofintegersasinputandoutputs
theirproduct.Thecodeshouldhandlethecasewheretheinputsets
haverepetitiveitems.
18
]\
Functions(1N)
CoveredTopics
● Formaldefinitionofafunctionasaspecialtypeofrelation
● Compositionoffunctions
● One-to-onefunctions
● Ontofunctions
● Bijections
PresentationNotes
● Makesuretostressthefactthatiff:A->Bisone-to-onethenBis,ina
sense,atleastaslargeasA .Similarly,iffisonto,thenAisatleastas
largeasB.Finally,iffisabijection,thenbothAandBhavethesame
size.
● Provideexamplesofsetswithvarioustypesoffunctionsbetweenthem.
Makesuretousebothfiniteandinfinitesets.
● Showbijectionsbetweensetsofintegers,positiveintegersandeven
numbers.
● Formanystudents,thisistheirfirstencounterwithinfinitesets.Make
suretheygetenoughsupporttoformasolidintuitiveunderstandingof
thesesets.
LearningOutcomes
● Abilitytoformallyreasonaboutwhichrelationsarefunctions.
● Asolidintuitionabouthowonecancomparethe“size”ofvarioussets
byfindingfunctionsbetweenthem.
● Abilitytoobtainbijectionsbycomposingotherbijections.
19
]\
HomeworkPlan
● Pen-and-paper:Askthestudentstofindbijectionsbetweenvarious
sets,includinginfiniteones.Agoodexampleistohavethemfinda
bijectionbetweenthesetofoddnumbersandthesetofprime
numbers.
20
]\
Data-typesinC/C++andtheimportanceofthetype
system(1E)
CoveredTopics
● FundamentaldatatypesinC/C++
● Conversionbetweentypes
● Overflowandunderflow
● TheimportanceofstatictypinginC/C++
● uandllsuffixesforintegers
PresentationNotes
● EmphasizethedifferencesintypinginC/C++andPython.
● Emphasizethatthetypeofeveryvariableshouldbeknownassoonasit
isdefined.
● Showexamplesofautomaticandmanualtypecasting(includingbyan
operatorandbyassignment)
● Showexamplesofoverflowandunderflow
● Talkaboutthedifferencebetweenunsignedandsignedintegersand
theirranges
● Donotgetintothedetailsoffloatingpointnumbers.
LearningOutcomes
● UnderstandingtheC/C++typesystem
● Understandinghowmemoryisallocatedbasedontype
● Abilitytoreasonabouttypeerrorsandtypecasting
● Understandingtheimportanceofbeingvigilantaboutoverflowerrors
21
]\
HomeworkPlan
● Givethestudents4-5examplesofprogramswithtypingoroverflow
bugsandaskthemtoidentifytheproblems.
22
]\
ReadinginputandwritingoutputinC/C++(1E)
CoveredTopics
● stdin,stdoutandstderr
● Differencebetweenstdoutandstderr
● cin,coutandcerr
● Specifyingstdoutandstderrinthelinuxcommandline
● Handlingfiles(ifstream,ofstream)
● printfandscanf
● Specialcharacters:\n,\t
PresentationNotes
● TalkabouttheheaderfilenamesinCvsC++(e.g.stdio.hvscstdio)
● Emphasizethatprintf/scanfandcin/coutdonotmix
LearningOutcomes
● AbilitytoreadinputandwriteoutputofanytypeusingboththeC
functionsandtheC++streams
HomeworkPlan
● Coding:Askthestudentstowritevariousprogramsthatreaddifferent
typesofinputf romdifferentsourcesandwritetheiroutputtoother
destinations.Makesurethestudentsaretestedforreadinginputusing
cin/scanf/ifstreamandwritingoutputusingcout/printf/ofstream/cerr.
23
]\
Recursion(1N)
Note:IntheEcurriculum,thiscourseiscoveredunder“divideandconquer”.
CoveredTopics
● Recursivefunctions(functionsthatcalleachother)
○ InPythonfortheNcurriculum
○ InC/C++fortheEcurriculum
● Morecomplicatedrecursions(e.g.thoseconsistingoftwoormore
functions)
● Ensuringtheterminationofarecursivefunction
● Examplesofusingrecursiontocomputerecurrences,suchasFibonacci
● Basicintroductiontorecursiondepth
PresentationNotes
● Atthispoint,wedonotreallycareaboutformalruntimeanalysis.So,do
nottalkaboutasymptotics.However,itisagoodideatoaskthe
studentstoimplementtheFibonaccisequenceusingrecursionandsee
howslowtheirprogramsget.
LearningOutcomes
● Abilitytoimplementbothsimpleandmulti-functionrecursive
algorithmsinPython(N)andC/C++(E)
● Abilitytoprovetheterminationofarecursivefunction
24
]\
HomeworkPlan
● Coding:Writeacodethatgetsaninputnandcomputesthen-th
elementoftheFibonaccisequence.
● Pen-and-paper:Askthestudentstoidentifywhytheircodeissoslow.
[Duetorepeatedspuriouscalculations]
25
]\
Arrays,conditionalsandloopsinC/C++(1E)
CoveredTopics
● if,while,for,do...while,switch
● breakandcontinue
● arrays
● ?:
PresentationNotes
Thisisaprettystraightforwardlesson,especiallygiventhatthestudentsare
alreadyfamiliarwithPython.
● Emphasizethatthesizeofthearrayshouldbeknownatthetimeof
definition(duetothetypesystemandmemoryallocation)
● Showmanyexamplesofbreak/continue
● Makesurethestudentsunderstandthenewconstructsthatwere
absentinPython
26
]\
Representingnumbersandcharactersinacomputer
(1E)
CoveredTopics
● Thesizeofvarioustypes(int,longlong,etc)anditsinherentlimitations
● Assigningbinarysequencestounsignedintegers
● Signedintegers(one’scomplement--withtwozeros--andtwo’s
complement)
● Additionintwo’scomplement
● Whathappenswhenanintoverflows?
● -1u/2
● ASCIIandrepresentationofcharacters
● Savingspacebyusingcharforstoringsmallnumbers
● Unsignedchar
● Whydoesn’tPythonhavethesamelimitationswhenitcomesto
integers?
PresentationNotes
Thestudentsshouldseetwo’scomplementandASCIIinactionbytype
castingbetweenint/unsignedandchar/int.
LearningOutcomes
● Anunderstandingofhowdataisstoredinbinaryformatonmemory
● Anintuitionabouttheproblemwithsignednumbersandthemethods
toavoidit
27
]\
RelationsandFunctions(1E)
ThislessoncoverseverythinginRelations(1N)andFunctions(1N).
28
]\
BubbleSort(1N)
CoveredTopics
● Thebubblesortalgorithm
● Proofofthealgorithm’scorrectness
● Implementationofthealgorithm
● Countingthenumberofcomparisonsneededintheworstcase
PresentationNotes
● Showthestudentsananimationofbubblesortinaction.
● Makesurethecorrectnessproofispresentedindetailandthatall
studentshaveagoodintuitiveunderstandingofwhythealgorithm
works.
● Explicitlyconsiderthecasewherethearrayhasrepeatedelementsand
makesurethestudentsunderstandwhythealgorithmstillworks.
● Whencountingthenumberofcomparisons,donotignoreconstant
factorsorusetheOnotation.Thestudentshavenotseenthatyet.
LearningOutcomes
● Familiaritywiththemostbasicsortingalgorithm(bubblesort)
● Firstexperienceincodingarealalgorithmthatusesloopsandarrays
HomeworkPlan
● Coding:Implementbubblesortforanarrayofintegers
29
]\
InsertionSort(1N)
CoveredTopics
● Theinsertionsortalgorithm
● Proofofitscorrectness
● Implementationofthealgorithm
● Countingthenumberofcomparisonsintheworstcase
PresentationNotes
● SeePresentationnotesfor“bubblesort”.
● Computetheexactnumberofcomparisonsintheworst-caseand
comparethiswithbubblesort
LearningOutcomes
● Learninganotherquadraticsortingalgorithm
● Moreexperienceincodingbasicalgorithmswithloopsandarrays
HomeworkPlan
● Coding:Implementinsertionsortonanarrayofintegers
● Comparet hereal-worldruntimeofyourinsertionsortandbubblesort
implementations.Dotheycorrespondtoyourexpectations?
30
]\
Sorting(bubblesort,selectionsort,insertionsort,1E)
CoveredTopics
● Thethreebasicsortingalgorithms(bubble,selection,andinsertion)
● Proofsoftheircorrectness
● Theirimplementation
● Countingthenumberofcomparisonsperformedintheworstcasein
eachalgorithm
PresentationNotes
See“Bubblesort(1N)”and“InsertionSort(1N)”above
LearningOutcomes
● Sameas“Bubblesort(1N)” and“InsertionSort(1N)”
HomeworkPlan
● Coding:thestudentsmustimplementallthreealgorithms.
● Askthestudentstoruntheircodesonhugerandomly-generated
instances.Isonealgorithmalwaysfaster?Why(not)?
31
]\
FunctionsandScopes(1E)
CoveredTopics
● HowtowritefunctionsinC/C++
● Globalvslocalvariables
● Scopesofvariablesandtheirrelationshiptolifetimes
● Variableswiththesamename
PresentationNotes
● Emphasizethedifferenceinmemorymanagementforglobalvslocal
variables
● Emphasizetheroleofscopeinautomatedmemorymanagement
● Explaintheruleswhenseveralvariableshavethesamenamebuturge
thestudentstousedifferentnamesintheircodes
LearningOutcomes
● AbilitytowriteprogramsconsistingofseveralfunctionsinC/C++
● Understandingthedifferencebetweenlocalandglobalvariables
● Understandingthescopeandlifetimeofavariable
● UnderstandinghowmemoryismanagedautomaticallyinC/C++
32
]\
BinarySearch(1N)
CoveredTopics
● Thelinearsearchalgorithm
● Thebinarysearchalgorithm
● Itsproofofcorrectness
● Adetailedanalysisofthemaximumnumberofcomparisonsneeded
(logarithmicvslinear)
● Implementationsofbinarysearch
○ byrecursion
○ byawhileloop
PresentationNotes
Thereareseveralimportanttakeawaysinthislesson.Especially,thisisthefirst
timeourstudentsareseeingalgorithmswithvastlydifferentruntimesforthe
sameproblem.Makesurethispointiswellunderstoodbyeveryone.Have
themruntheircodesofbothsearchalgorithmsoverlargearrays,compare
theruntimes,andmakeagraph.
LearningOutcomes
● Familiaritywiththebinarysearchalgorithmanditsruntime
● Abilitytoimplementbinarysearchusingbothrecursionandloops
HomeworkPlan
● Coding:thestudentsmustimplementbinarysearchbybothrecursion
andawhileloop.
33
]\
● Pen-and-paper:Theyshouldformallyreasonaboutthecorrectnessof
theircodeandprovideproofsofcorrectnessf ortheimplementation.
34
]\
Warmer-colder(1N)
CoveredTopicsandPresentationNotes
● Inthislesson,weconsiderthefollowinggame:Alicechoosesaninteger
between0andn.Bobshouldguesshernumber.Aftereachguess,Alice
answerswithoneofthefollowingresponses:
○ “bingo”:Thiswasthecorrectguess.
○ “first”:ThiswasBob’sfirstguessbutitwasincorrect.
○ “warm”:Theguesswasincorrect,butitwasclosertoAlice’s
numberthanthepreviousguess.
○ “cold”:Theguesswasincorrect,butitwasfartherf romAlice’s
numberthanthepreviousguess(orhadthesamedistance).
● Thestudentsshouldfirstwriteaprogramthatgetsthenumbernas
inputandplaysasAlice.Theprogramshouldchooseaninteger
between0andnandthenacceptguessesandplay.Itshouldterminate
onlyafter“bingo”.
● ThestudentsshouldfindastrategyforBobinordertofigureoutAlice’s
numberassoonaspossible.Thisstrategyneednotbeoptimal.Tryto
steerthediscussiontowardsbinarysearchandstopassoonasa
strategywithO(lgn)guessesissuggested.Donottrytoimprovethe
constants!
● Havethestudentscodetheirstrategy.
LearningOutcomes
● Abilitytowriteinteractiveprograms
● Abilitytodesignnon-standardalgorithms(inthiscasebasedonbinary
search)
35
]\
Two-dimensionalSearch(1N)
CoveredTopicsandPresentationNotes
● Weconsiderthefollowinggame:Wearegivenannxngridwhose
pointshavecoordinatesf rom(0,0)atthebottomleftto(n,n)atthetop
right.Alicechoosesapoint(a,b)withintegralcoordinates0<=a,b<=n.
Bobshouldfindthispoint.Ateachturn,Bobcandooneofthe
following:
○ Chooseahorizontalliney=cfor0<=c<=n,andaskAliceifthe
pointisabove,beloworonthisline.cshouldbeaninteger.
○ Chooseaverticallinex=cfor0<=c<=n,andaskAliceifthepoint
istotheleft,totheright,oronthisline.cshouldbeaninteger.
● Similartothepreviouslesson,thestudentsshouldfirstwritean
interactiveprogramthatsimulatesAlice.
● ThestudentsshouldthenfindastrategyforBobtofindAlice’spoint
withinO(lgn)steps.Notethatourstudentsdonotknowanything
abouttheOnotationatthispoint.Trytosteerthediscussiontowards
binarysearchingandstopassoonasthereisalogarithmicalgorithm.
● Askthestudentstoimplementthisalgorithm.
LearningOutcomes
Thisisamoreadvancedversionofthepreviouslesson.Thelearning
outcomesareverysimilar.Specifically,weareinterestedinmakingsurethat
thestudentscanusebinarysearchinunfamiliarsituations.
36
]\
Propositionallogic(truthvaluesandoperators,1N)
CoveredTopics
● Propositions
● Assigningtruthvalues(T,F)topropositions
● logicalnegation(not)
● logicalconjunction(and)
● logicaldisjunction(or)
● logicalexclusivedisjunction(xor)
● logicalimplication(->)
● logicaltwo-sidedimplication(ifandonlyif,<->)
PresentationNotes
● StudentsoftenstrugglewiththedifferencebetweenORandXOR.This
shouldbeclarifiedbyprovidingseveralexamplesf romtherealworld.
● ManystudentsstrugglewithP->QwhenPisfalse.Agoodwayof
providingthemwiththerightintuitionistotalkofP->Qasapromise
thatifPholds,thenQwillhold,too.Thepromiseisofcoursefulfilledby
defaultifPisfalse.
● EmphasizethatwewillalwaysusethelogicalmeaningofORwhen
talkingaboutmathematicsoralgorithms
LearningOutcomes
● Basicunderstandingoflogicaloperators
● Abilitytotalkformallyandexactlywhenformulatingmathematical
sentences
37
]\
Propositionallogic(proofbytruthtables,1N)
CoveredTopics
● Truthtablesandhowtoformthem
● Provingthataformulaisatautologyusingtruthtables
● Provingimplicationusingtruthtables
● Proving“ ifandonlyif”statementsusingtruthtables
● Provethefollowinglogicalidentities
○ p->q==qOR~p
○ ~(pORq)==~pAND~q
○ ~(pANDq)==~pOR~q
○ p<->q==(p->q)AND(q->p)
PresentationNotes
Theconceptbeingcoveredhere(truthtables)isquitesimple,butthe
studentswillneedalotofpractice.Providemanyexamplesandmakesure
everystudentcontributestofillingthetruthtables.
LearningOutcomes
● Provingtautologiesandimplicationsbyrelyingontruthtables
● Anintuitiveunderstandingofbasicidentitiesinpropositionallogic
HomeworkPlan
● Pen-and-paper:Thestudentsshouldproveatleastonetautology,one
implication,andonetwo-sidedimplicationusingtruthtables.
38
]\
Introductiontopropositionallogic(1E)
CoveredTopics
Thislessoncoverseverythingin“Propositionallogic(truthvaluesand
operators,1N)”and“Propositionallogic(proofbytruthtables,1N)”.
Additionally,itcoversthefollowingideas:
● Formalproof/argument:asequenceofformulassuchthateachformula
iseitheranassumptionoraconsequenceoftheonescomingbeforeit
● Modusponens
PresentationNotes
Wecoverthisratherinformally.Forexample,intheproofs,wedonotrequire
theuseofmodusponensastheonlyrule.Wealsoallowthestudentstorely
ontruthtablesinordertoaddaxioms.
39
]\
Divideandconquer(1E)
Thislessonsalsocoverseverythingin“BinarySearch(1N)”and“Recursion(1N)”
CoveredTopics
● Thebasicideabehinddivide-and-conquer
● Binarysearchanditstwoimplementations
● Implementingdivide-and-conqueralgorithmsusingrecursion
● Postofficeroutingproblem
PresentationNotes
Themainideathatshouldbeconveyedinthiscourseisthemindsetthat
breakingdownaproblemintosimplersubproblemsisoftenagoodidea.The
entiretyofthelessonsonbinarysearchandrecursion(1N)shouldbecovered
hereaswell.Warmer-colder(1N)andtwo-dimensionalsearch(1N)canalsobe
usedasadditionalexamples.Towardstheendofthislesson(andinthe
homeworks),askthestudentstothinkaboutapplyingthe
divide-and-conquerapproachtothesortingproblem.Thistiesnicelyintothe
nextlesson(mergesort).Makesurethestudentscodeeveryexample.
Note:thestudentsshoulddefinitelyimplementtheFibonaccibyrecursion
exampleanddoitsrelatedexercise.Wewilllaterbuilduponthisinthe
dynamicprogramminglesson.
LearningOutcomes
● Familiaritywiththegeneralnotionofdivide-and-conquer
● Abilitytocodedivide-and-conqueralgorithmsusingrecursion
40
]\
HomeworkPlan
● Coding:Givethestudentsahomeworkthatessentiallyguidesthemto
mergesort.
41
]\
MergeSort(1E)
CoveredTopics
● Themergesortalgorithm
● Itsproofofcorrectness
● Implementingmergesortusingrecursion
● Implementingmergesortusingloops(painful,butnecessary)
● Analysisofthenumberofcomparisonsinmergesort
● Countingthenumberofinversionsinanarray
PresentationNotes
● Makesurethestudentscodemergesortusingbothrecursionand
loops.
● Whenpresentingtheruntimeanalysis(numberofcomparisons),rely
onabinarytree.Letthestudentsfigureoutthenumberofverticesina
binarytreeofdepthk.
LearningOutcomes
● FamiliaritywiththemostclassicalO(nlgn)sortingalgorithm,namely
mergesort
● Abilitytocodeinvolveddivide-and-conqueralgorithms
● Abilitytoanalyzetheruntimeofanalgorithmbasedonabinarytree
● Abilitytosolveunseenalgorithmicproblems(inversionsusingmerge
sort)
42
]\
HomeworkPlan
● Coding:Implementanalgorithmthatcountsthenumberofinversions
inagivenarrayofintegersbyrelyingonmergesort
43
]\
BasicCounting(principlesofadditionand
multiplication,1N,1E)
CoveredTopics
● Ruleofsum
● Importanceofdisjointnessintheruleofsum
● |A∪
B|=|A|+|B|-|A∩B|
● Ruleofproduct
PresentationNotes
Followthepresentationsinthelinksbelow:
● https://brilliant.org/wiki/rule-of-sum-and-rule-of-product-problem-solvi
ng/
● https://www.youtube.com/watch?v=zG9Y8hnXZOc
LearningOutcomes
● Familiaritywiththebasiccountingrules
● Abilitytosolveunseenproblemsbycombiningthetworules
44
]\
Introductiontographsanddigraphs(1N,1E)
CoveredTopics
● Whatisagraph?G=(V,E)
● Directedandundirectededges
● Walks,trailsandpaths
● Cycles
● Degreesandneighborhood
PresentationNotes
Itisusefultoexplaingraphsasasetofcitieswithroadsbetweenthem,where
directededgesareone-wayroads.However,makesuretoemphasizethelack
ofgeometricinformation.Otherwise,justfollowthepresentationinChapter1
of“IntroductiontoGraphTheory”byWest.Themodelsinthebookare
especiallygreatexamples.
LearningOutcomes
● Thislessonisourstudents’firstcontactwithgraphtheory.Themost
importantpointisthattheyunderstandwhatcanandcannotbe
modeledbyagraph.
45
]\
ProofbyContradiction(1N,1E)
CoveredTopics
● Thebasicideabehindproofbycontradiction
○ WewanttoproveP->Q
○ WeassumePistrue
○ WeassumeQisfalse(~Qistrue)
○ Weobtainacontradictionf rom(Pand~Q)
● Sqrt(2)isnotrational
● Thereareinfinitelymanyprimenumbers
● Therearenointegersolutionsto3x+9y=2
● Forallpositiveintegersn,ifn^3+9isodd,thenniseven
For1Eonly:
● Proofbycontrapositive
PresentationNotes
● Explainthattheideabehindproofbycontradictionisbasicallythis
identity:
○ (P->Q) ==(Pand~Q)->false
● Askthestudentstoprovethisidentityusingthetoolswehavealready
seen
● Similarly,for1Estudents,showthatproofbycontrapositiveisbasedon
thisidentity:
○ P->Q==~Q->~P
● Askthemtoprovethisidentity
● Followthispresentationforproofbycontrapositive:
https://www.youtube.com/watch?v=0YqZIHFmVzg
46
]\
LearningOutcomes
● Familiarityandsignificantexperienceinproofbycontradiction(both1N
and1E)andproofbycontrapositive(only1E)
47
]\
Gentleintroductiontoquantifiers(1N)
CoveredTopics
● Predicates
● Existentialquantification(∃)
● Universalquantification(∀)
● Negatingstatementswithquantifiers
PresentationNotes
● Avoidnestedquantifiersanddefinitelyavoidquantifieralternation
● Usetheexamplesinh
ttps://www.csm.ornl.gov/~sheldon/ds/sec1.6.html
● Followapresentationsimilarto
https://www.youtube.com/watch?v=GJpezCUMOxA
LearningOutcomes
● Understandingbasicquantifiers(withoutalternation)
● Reasoningaboutquantifiedstatements
48
]\
Counterexamples(1N)
CoveredTopics
● Basicideabehindcounterexamples
○ Supposethatwewanttorefute∀xf(x)
○ Thisisequivalenttoproving∃
x~f(x)
○ Itisthereforeenoughtofindasinglexsuchthat~f(x)
○ Thisxiscalledacounterexample
PresentationNotes
● Presenttheexamplesin
https://www.youtube.com/watch?v=mxcGpNji4ik
● Presentatleast4-5examplesf romgraphtheory
● Emphasizethedifferencesinproofbycounterexampleandproofby
contradictionandmakesurethestudentsunderstandthattheseare
notthesamemethod
LearningOutcomes
● Thestudentsshouldbeabletodisproveuniversally-quantified
statementsbyprovidingcounterexamples
● Theyshouldbeabletosolveunseenproblemsbasedonthistechnique
HomeworkPlan
● Ashomework,askthestudentstodisproveatleast5different
statementsusingacounterexample.Makesurethereareatleast2
graphstatementsand1algorithmicstatementinthemix.
49
]\
Completesearch(bruteforce,1N)
CoveredTopics
● Completesearch(tryingallthepossibilitiesbybruteforce)
PresentationNotes
● Askthestudentstowriteasimpleforloopinordertoestimate(roughly)
howmanyoperationspersecondtheycanmanagetoexecuteontheir
machine.
● Explainthattheycanrelyonthecomputationalpoweroftheirmachine
andtryallthepossibilitiesinaproblem,aslongasthenumberof
possibilitiesissmallenoughandeachofthemcanbecheckedfast
enough.
● Itisextremelyimportantthatoneavoidcheckingtoomanyspurious
cases.
● Followtheexampleson
https://train.usaco.org/usacotext2?a=IhhvfuQpHFq&S=comp
Dropthemoreinvolvedexamples.
LearningOutcomes
● Abilitytoperform(smart)brute-forcesearch
HomeworkPlan
ThefirsttwoproblemsofSection1.3oftrain.usaco.org
50
]\
ReturningChange(1N)
CoveredTopics
● Inthislesson,weconsiderthefollowingproblem:Youareacashierata
supermarketandshouldgivebackchangetoacustomer.Thechange
isnrupees.Youcanpayitbackusing1,2,5,10,50and100rupeecoins.
Yourgoalistominimizethenumberofcoinsthatyougiveout.
● Greedyalgorithmfortheproblem
● Proofthatthegreedyalgorithmworks
● Addingan8-rupeecoinandshowing(bycounterexample)thatthe
greedyalgorithmdoesnotworkanymore
PresentationNotes
● Makesurethestudentscodethealgorithm
○ Ifastudentusesalinear-timeimplementation,trytosteerthem
towardsaconstant-timevariant
● Letthestudentsfigureoutthecounterexample.Donotsimplypresent
ittothem.
LearningOutcomes
● Firstinteractionwithgreedyalgorithmsandprovingtheircorrectness
● Gainingmoreexperiencewithcounterexamples
51
]\
Theknapsackproblem(1N)
CoveredTopics
● 0-1Knapsackanditspseudo-polynomialalgorithm
● Multi-itemKnapsackanditspseudo-polynomialalgorithm
● Solvingthegeneralcaseofthe“ returningchange”problem
● Proofofcorrectnessofthealgorithms
PresentationNotes
● Iftimeallows,providethefollowingvariantandaskthestudentsto
solveit:
○ Considerthe0-1Knapsackproblem,exceptthatwehave10
“special”items.Thespecialitemshavedependencyandconflict
relationsamongthemselves(whicharegivenintheinput).We
wanttofillourknapsackandmaximizethevaluewhile
respectingtheseconstraints.
LearningOutcomes
● Firstexperiencewithdynamicprogramming(thoughitisnotnamedas
such)
● Abilitytosolvenewproblemsbasedonrecently-learnedalgorithmic
techniques
● Abilitytocombinealgorithmicideas(inthiscaseknapsackandbrute
force)
52
]\
PermutationsandnPk(1E)
CoveredTopics
● Numberofpermutationsofnitems(andthedefinitionoffactorial)
● nPk
● ViewingnPkasnumberofone-to-onefunctions
● Circularpermutations
PresentationNotes
FollowChapter1of“PrinciplesandTechniquesinCombinatorics”
LearningOutcomes
● Familiaritywithfactorials
● Abilitytoapplythemultiplicationprinciplerepeatedly
● Abilitytosolveunseenproblemsrelatedtopermutations
● Understandingtheideaofcountingeverythingctimes,andthen
dividingbyc
HomeworkPlan
● Coding:Writeaprogramthatgetsnandkasinputandprintsall
k-permutationsof{1,...,n}inlexicographicordering.
○ Variant:printscirculark-permutations
● Pen-and-paper:Exercisesf rom“PrinciplesandTechniquesin
Combinatorics”
53
]\
TreesandForests(1E)
CoveredTopics
● Definitionoftrees
○ Thethreefundamentalcharacteristicsofatree
○ Anytwoofthethreeentailtheremainingproperty
○ Thereisauniquepathbetweenanypairofvertices
● Rootedtreesandthenotionsofchild,parent,sibling,etc.
● Definitionandnumberofedgesinaforest
● Howtoimplementatreeusingarraysandvectors
PresentationNotes
● Itisunavoidabletotalkabitaboutconnectedcomponentswhen
presentingforests.Thisisfine.However,donotoverdoit.Connected
componentswillbecoveredinmoredetailinafuturelesson.
● PresentSection2.1and“TreesinComputerScience”f romIntroduction
toGraphTheorybyD.B.West
LearningOutcomes
● Familiaritywithtreesandforests
● AbilitytorepresenttreesinC/C++
HomeworkPlan
● Pen-and-paper:Exercisesf romSection2.1ofWest
54
]\
Breadth-firstsearchanddepth-firstsearch(1E)
CoveredTopics
● TheDFSalgorithm
● Itsimplementation
● DFStreeanditsproperties(includingadiscussionofback-edges)
● TheBFSalgorithm
● Itsimplementation
● BFStreeanditsproperties
● ProofthatBFSfindsshortestpaths
● Informalcomplexityanalysisofbothalgorithms
● ImplementationofDFSusingaloopandusingrecursion
● ImplementationofBFSusingaqueue
PresentationNotes
● Motivatethealgorithmsusingreachability
● Talkabouttheshortest-pathsproblembeforepresentingBFS
● Checkeverystudent’simplementationsindetail
LearningOutcomes
● FamiliaritywithDFSandBFS
● AbilitytoreasonaboutthepropertiesofDFS/BFStrees
● AbilitytocodetheclassicalBFSandDFSalgorithmsandusethemin
problem-solving
55
]\
IntroductiontoMathematicalInduction(1E)
This is the longest lesson of 1E and will probably take two orthreeweeksof
time. It is of utmost importance that the students understand the idea of
mathematical induction, but it is even more important that they solve
roughly50-60problemsusinginduction.
CoveredTopics
● Weakinduction
○ Thethreecomponentsofaninductiveproof
● Stronginduction
● Proofbyinfinitedescent
PresentationNotes
● FollowthepresentationinChapter1of“Introductiontoalgorithms:a
creativeapproach”byUdiManber
● Thisisaveryexercise-intensivelesson.Weshouldshowasmany
examplesofinductionastimeallows.
● Makesuretodemonstratethefactthatallthreecomponentsofan
inductiveproofareabsolutelynecessary.Dothisbyprovidingfaulty
proofsofnonsensicalstatements,inwhichoneofthecomponentsis
dropped.
● Thestudentsshouldseeexamplesinenumerativecombinatorics,
graphtheory,andprovingcorrectnessofalgorithms.
● Useexamplesf rom“Problem-SolvingStrategies”byEngeland“ 102
CombinatorialProblems”byAndreescuandFeng
● Provethecorrectnessofpreviously-taughtsortingand
divide-and-conqueralgorithmsusinginduction
56
]\
● Emphasizethattheproofsofterminationwegaveforrecursive
functionswereindeedproofsbyinductionandformalizethemfurther
LearningOutcomes
● Abilitytousethevariousformsofinductioninawidevarietyof
situations,includingproofsofcorrectnessforalgorithms
57
]\
Connectedcomponentsandstrongly-connected
components(1E)
CoveredTopics
● DefinitionofCC
● Maximumandminimumnumberofedgesinagraphwithnvertices
andcconnectedcomponents
● FindingCCsbyBFSandDFS
● DefinitionofSCC
● UniquenessofmaximalSCCsinadigraph
● FindingSCCsbyDFS
● TherelationshipbetweenSCCsandback-edgesinaDFStree
PresentationNotes
● Makesurethestudentscodeeverysinglealgorithm
LearningOutcomes
● Familiaritywithconnectivityingraphs
● Abilitytocomputetheconnectedcomponentsandstrongly-connected
componentsofagraphinC/C++
HomeworkPlan
● Coding:implementtheSCCbyDFSalgorithm
58
]\
BigIntegers(1E)
CoveredTopics
● BasicintroductiontovectorsinC++(push_back,pop_back)
● Usinganarrayofdigitstorepresentaninteger
● Addition,subtractionandmultiplication
● MultiplicationbyKaratsuba’salgorithm
PresentationNotes
● Wedonotwanttogetintohowvectorsactuallywork.Atthispoint,just
presentthemasresizablearrays.Therewillbeafuturelessonthatgoes
intomoredetail.
● Thisisanimplementation-heavylesson.Mostofthetimewillbespent
onhelpingstudentscodeanddebuggingtheircodes.
● PresentKaratsuba’salgorithmonlyafterthestudentshavesuccessfully
implementedthenaivemultiplicationmethod.
LearningOutcomes
● AbilitytoworkwithintegersofanylengthinC/C++
● Abilitytoconvertstringstobigintegers
● Furtherfamiliaritywithdivide-and-conquermethods
59
]\
EulerianandHamiltoniancircuits/trails(E1)
CoveredTopics
● Euleriancircuitsandtrails
● TheconditionsforaconnectedgraphtobeEulerian
● AlgorithmsforfindingEuleriancircuitsandtrails
● Hamiltonianpathsandcycles
● BitoperationsinC/C++
● Exponential-timealgorithmsforfindingHamiltonianpathsandcycles
PresentationNotes
● TheimplementationofthealgorithmforHamiltonianpaths/cycleswill
dependonbitwiseoperations.Theseshouldalsobetaughtaspartof
thislesson.
● Thislessonisourstudents’firstexperiencewithanNP-hardproblem.
Atthispoint,wearenotgoingtomentionthetheoryof
NP-hardness/completeness.However,weshouldmakesurethe
studentsunderstandthatfindingaHamiltoniancycleisinherently
harderthanfindinganEuleriancircuit.
LearningOutcomes
● UnderstandingtheideasbehindEuleriancircuitsandtheimportance
ofdegreesindecidingwhetheragraphisEulerian
● AnintuitiveunderstandingthatfindingHamiltoniancyclesismuch
harderthanEuleriancircuits
● Furtherexperienceinimplementinggraphalgorithms
● FamiliaritywithbitoperationsinC/C++
60
]\
HomeworkPlan
● Coding:Thereare4codingtaskscorrespondingtofinding
Eulerian/Hamiltoniantrails/circuits
61
]\
ChoicesandnCk(E1)
CoveredTopics
● Numberofsubsetsofsetvsnumberofpermutations
● nCk(choosinganunorderedteamofkf romagroupofnpeople)
● Choosingmorethanoneteam
● Solvingsystemsoflinearequationsovernonnegativeintegers(balls
andwalls)
● Pascal’sidentity
● Provingcombinatorialidentitiesbydoublecounting
● TheBinomialtheorem
PresentationNotes
● ProvePascal’sidentitybothcombinatoriallyandalgebraically
● Follow“PrinciplesandTechniquesinCombinatorics”
LearningOutcomes
● FamiliaritywithnCk
● Abilitytodistinguishbetweenorderedandunorderedsituationsin
counting
● AbilitytocombinenPkandnCkincountingproblems
● FamiliaritywithDouble-countingandabilitytoconstructcombinatorial
proofs
HomeworkPlan
● Pen-and-paper:“ 102problemsinCombinatorics”
62
]\
DegreesandBijections(E1)
ThislessoncloselyfollowsSection1.3of“IntroductiontoGraphTheory”byD.B.
West.Ahugeemphasisisputonsolvingexercisesandwewilltrytocoverall
ofthem.
63
]\
Quantifiersandfirst-orderlogic(E1)
Thisistheeliteversionof“Gentleintroductiontoquantifiers(N1)”and
“Counterexamples(N1)”.Itcoverseverythinginthoselessons,aswellasthe
followingideas:
CoveredTopics
● Nestedquantifiers(includingthosewithquantifieralternations)
● Thedifferencebetween∀∃and∃∀
● Binding(freeandboundvariables)
● Logicalidentities(withquantifiers)
● Negatingformulaswithseveralquantifiers
PresentationNotes
● Useexamplessuchastheonesin
https://www.whitman.edu/mathematics/higher_math_online/section01.
02.html
● Thereisahugeemphasisontheabilitytotranslatef romhuman
languagetoformalquantifiedstatementsandviceversa
LearningOutcomes
● Fluencyinquantifierlogic
● Abilitytohandlenestedquantifiersandquantifieralternations
HomeworkPlan
● Pen-and-paper:Anextensivesetofhomeworksaskingthestudentsto:
64
]\
○ translatesentencesf romhumanlanguagetoquantified
statements
○ negatingformulaswithvariousquantifiers
○ identifyingf reeandboundvariables
65
]\
AsymptoticRuntimeAnalysis(E1)
CoveredTopics
● Growthoffunctions(intuition)
● Irrelevanceofconstantfactors
● TheOnotationanditsformaldefinition
● o,Ω,ω
,Θandθ
● Runtimeanalysisofthequadraticsortingalgorithms
● Runtimeanalysisofmergesortusingabinarytree
● Runtimeanalysisofmergesortbywritingitsrecurrenceandapplying
induction
● Mastertheorem
PresentationNotes
● Followthepresentationin“IntroductiontoAlgorithms”byCormenetal
(CLRS)
● Provideruntimeanalysesofvariouspreviously-taughtalgorithmsas
examples
● Remindthestudentsthatmergesortwassomuchfasterthanthe
othersortingalgorithmswehaveseen
● Therearemanyyoutubevideosonthissubject,somewithreallynice
graphicsandanimations.Usethemwhenteachingthislesson
● PresentthedynamicprogrammingapproachtocomputingFibonacci
numbersandcomparetheruntimesoftherecursiveanddpmethods
LearningOutcomes
● UnderstandingthebigOnotationanditsvariants
66
]\
● Abilitytoformallyanalyzetheruntimeofanalgorithm
○ directly(byrelyingoncountingmethods)
○ byinduction
○ byrecurrencesolving
○ bybinarytrees
○ byMastertheorem
HomeworkPlan
● Pen-and-paper:Homeworksf romCLRS
67
]\
IntroductiontoGreedyAlgorithms(E1)
Thislessoncovers“Returningchange(N1)”asaspecialexample.
CoveredTopics
● Introductiontotheideaofgreedyalgorithms
● Importanceofprovingcorrectnesswhenapplyinggreedytechniques
● Examplesofcaseswhengreedyalgorithmsfail(e.g.variantsof
returningchange)
● Examplesofgreedyalgorithms
○ Returningchange
○ https://train.usaco.org/usacotext2?a=rgDjQ2qEhjb&S=greedy
○ Prim’salgorithmforfindingminimumspanningtrees
PresentationNotes
● Followh
ttps://train.usaco.org/usacotext2?a=rgDjQ2qEhjb&S=greedyand
Chapters16.1and16.2ofCLRS
● DonotpresentKruskal
LearningOutcomes
● Abilitytodesigngreedyalgorithmsandprove/disprovetheir
correctnessandoptimality
● Significantexperienceincodinggreedysolutions
● FamiliaritywithminimumspanningtreesandPrim’salgorithm
HomeworkPlan
● Coding:USACOproblems
68
]\
● Coding:ImplementingPrim’salgorithm
● Pen-and-paper:CLRSexercises
69
]\
Heaps(E1)
CoveredTopics
● Max-heapsandMin-heaps
● Storingaheapinanarray
● Insertingnewitemsinaheap(+correctness/runtimeanalysis)
● Removingitemsf romaheap(+correctness/runtimeanalysis)
● Turninganarrayintoaheap(+correctness/runtimeanalysis)
● Heapsort(+correctness/runtimeanalysis)
● Priorityqueues
PresentationNotes
● Sections4.3.2and6.4.5of“Introductiontoalgorithms:acreative
approach”
● Chapter6ofCLRS
● Itisveryimportantthatthestudentsimplementbothamax-heapand
amin-heap
LearningOutcomes
● Understandingandimplementingheaps(thefirstmajordatastructure
introducedtoourstudents)
70
]\
Tournaments(E1)
CoveredTopics
● Definitionofatournament
● EverytournamenthasaHamiltonianpath(+algorithm)
● Allremainingtopicsf romSection1.4of“Introductiontographtheory”
byWest
PresentationNotes
FollowtheWestbook.
LearningOutcomes
● Familiaritywithtournaments
● Moreexperiencewithmathematicalinduction(inshowingthe
existenceofaHamiltonianpath)
● Turninginductiveargumentsinto(recursive)code
71
]\
Sorting(countingsort,bucketsort,radixsort,E1)
CoveredTopics
● Proofthatcomparison-basedsortingneedsatleastΩ(nlgn)time
● Countingsort
● Bucketsort
● Radixsort
● Runtimeanalysis(linear)
PresentationNotes
● Itisveryimportantthatthestudentsunderstandtheinherent
limitationsinlinear-timesorting.Emphasizethatthesesorting
methodsarenotsolvingthesameproblemasinourprevioussorting
algorithms.
LearningOutcomes
● Understandingthatmergesortandheapsortareoptimal
● Familiaritywithlinear-timesortingandabilitytodistinguishthecases
whereitisapplicable
HomeworkPlan
● Coding:Implementallthreelinear-timesortingalgorithms
72