403: algorithms and data structurespetko/classes/fall16-csi403-slides/01-intro.pdf403: algorithms...
TRANSCRIPT
403:AlgorithmsandDataStructures
Prof.PetkoBogdanov
Introduction
Fall2016UAlbany
ComputerScience
Whatisthiscourseabout?
• Designandanalysisofalgorithms.• Whatisanalgorithm?• Algorithm:awell-defined(computational)proceduretosolveaproblem
Input:DirtyHands
Output:CleanHands
Beforewedelveintoalgorithms…
• Instructor:PetkoBogdanov,• Forthisweekonly:Prof.Mariya Zheleva– [email protected]
• OfficeHours:Tue,Thu:1pmto3pm,orbyappointment
• Office:UAB416->Administrativebuildingnotonthepodium(1215WesternAve)
• Email:[email protected]
UAB
TAs
• Ashish Jadhav– [email protected]– Officehours:Tue,Thu 10:30am-11:30am.
• Zumrut Akcam– [email protected]– Officehours:Tue3-4pmandWed11am-12pm
• TAofficehoursroomsTBD(lookforanannouncementfromBlackboard)
Prerequisites
• Prerequisites:– CSI210(DiscreteStructures)and– CSI213(DataStructures)
• Istheresomeonewhohasnottakenthoseclasses?– DoHW1and…– Ifyougetmorethan80pointsyoucanstayintheclass
– Else,please,take210and213first
Book• RequiredText:– ThomasH.Cormen,CharlesE.Leiserson,RonaldL.Rivest,Cliord Stein,“IntroductiontoAlgorithms:Ed.3”,MITPress
• Wewillmostlyfollowthebook• Someassignmentfromthebook
Grading
Midterm- 20%
Final- 30%
Programs- 20%
Homework- 30%
Policies:exams
• Twoexams– openbook–Midterm– inclasson10/17/2016– Final– earlyDecember2016(dateTBD)
• Make-upexams– Onlyformajoremergencies(validandverifiable)– Contacttheinstructorassoonasyouknowyouwillbemissinganexamtore-schedule
Policies:programming
• Twoprogrammingassignments– Implementationandcomparisonofalgorithms– InJavaonthedepartmentLinuxcluster• Besuretochecktheycompileontheclusterbeforesubmitting!0pointsforprogramsthatdon’tcompile.
– Testinput/outputprovided• Willnotbethesameforgrading
Policies:homework
• Sixhomeworkassignments– Aboutaweektocompleteeach– Equally-graded– Best-5-of-6policy• Nomake-uphomeworks
• AssignmentsubmissionthroughBlackboard– Programmingasasinglearchivefile– HomeworkasascannedPDFofyoursolution• Onlyifyouarenotabletoscanbeforeclass:youcanbringahardcopy
Policies:cheating
• Cheatingonexams– YouwillreceiveanE-gradeandwillbereported
• Cheatingonassignments– Allassignmentsaretobecompletedindividually– Firstattempt:allstudentsinvolvedwillget0pointsfortheassignment
– FollowingattemptswillresultinE-grade;studentswillbereportedfordisciplinaryaction
Policies:I grades(incomplete)
• OnlygivenforcircumstancesbeyondyourcontrolIF:– Yourworkisingoodstandingasofthemidtermpoint(10/17/2016)• Homeworkscore>=50%• Programmingcompletedatleastat50%• MidtermgradeequivalentofC
– Youareabletoprovidewrittendocumentationtoproveyouareunabletocompletethecourse
Policies:attendance
• Notmandatorybutwilldetermineyourclassperformance– Itisyourresponsibilitytofindoutthematerialandnotescoveredinclassesyoumissed
• Thisisahybridslide/boardcourse– Alwayscomepreparedtotakenotes
Reading ahead
• Readmaterialaheadinthebook– makemoreoutofthelectures– letideas“sink”longer– donotworryifsomedetailsunclear
• Forthisweek:ReadChapters1and2
Homework1
• Due09/07/2016beforeclass
• 4problemstobrushupyourDiscreteMath
• Needtopasswithatleast80%tostayinclass
• Startearly,soyoucanconsultwiththeTAsandProf.Bogdanov.
Backtoourdefinition
• Algorithm:awelldefined(computational)proceduretosolveaproblem
• Tospecifytheproblemweneed:– Input:Whatisgiven?–Output:Whatisneeded?
Exampleproblemspecifications
• Findingthemaximum– Input: Asequenceofnumbers<x1,x2…xn>– Output: Thelargestnumberamongx1,x2…xn
• Sortinginnon-decreasingorder– Input: Asequenceofnumbers<x1,x2…xn>– Output: Apermutation(reordering)of<x’1,x’2…x’n>suchthatx’1≤x’2≤…≤x’n
Instanceandcorrectness
• Asequencesuchas<-7,4,9,2,17,8>isaninstance oftheproblem(i.e.valuesforallrequiredinputs,satisfyingstatedconstraints)
• Asortingalgorithmtransformsthesequence<-7,4,9,2,17,8>into<-7,2,4,8,9,17>
• Analgorithmiscorrect ifforeveryinstanceithalts withthecorrectoutput.
Whatkindofproblemsaresolvedbyalgorithms?
TheInternet
• Internetroutingalgorithms– DecidehowtohandlepacketsthroughInternetpaths
– YouwillstudyDijkstra’salgorithmforfindingtheshortestpath
• Internetapplications.E.g.GoogleSearchusesPageRank– Aroughestimateofpageimportance
u
yx
wv
z2
21
3
1
1
2
53
5
Otherexamplesinclude
• Electroniccommerce– Privacyofuserinformation– Persistencyacrossmultipleserverinstances
• Manufacturing/commercial/politicalenterprises– Politicalcandidates– howtospendcampaignmoneytomaximizethechanceofwinning
– Airlinecompanies– assigncrewstoflightstominimizeexpenses
– Internetserviceprovider– wheretobuildinfrastructuretominimizedelaysandmaximizeInternetbandwidth
Twocommoncharacteristics
• Manycandidatesolutions– Findingonethatis”thebest”canpresentquiteachallenge
• Practicalapplications– Presentsopportunitiestonarrowthescopeàeasiertofind“thebest”solution
Morebasics
• PseudocodeandAlgorithmAnalysisbyexample
• Insertionsort
Exampleofinsertionsortonaninstance
• Whichisthealgorithm?• Whichistheinput?• Whichistheoutput?• Whatistheinstance?
Thealgorithm
Theinput
Theoutput
<5,2,4,6,1,3>
Insertionsort(pseudocode)
Thisstepcanbereachedwheni=0orifA[i]≤key.Inbothcaseskeyisplaceds.t. A[1…i]issorted
Whatisalgorithmanalysis?
• Estimating(predicting)theresourcesneededbyanalgorithm– Time: howlongwouldittake– Memory: howmuchmemoryitwouldrequirefortheuseddatastructures
• Ourgoalistofindthebestalgorithmamongalternativesintermsofminimumresourcerequirements.
• Howtoquantifyimportantalgorithmcharacteristicsandomittediousdetails?
Analysis• Resourcesareexpressedasafunctionofthesizeoftheinput
• Thesizeoftheinputdependsontheproblem:– Sorting: numberofelementsbeingsortedn– Integermultiplication:sizeoftheintegers(i.e.numberofbitstobemultiplied)
• Execution(running)timeofanalgorithm:thenumberofprimitiveoperationsexecuted– e.g.assignment,comparisons,arithmeticops.…– typicallyassumedthatoperationstakeconsttime– allowsmachineindependencefortheanalysis
Worstcase
• Whenusingrunningtimewewillmeanworst-casetime– thelargestrunningtimeforanyinputofafixedsize n– Noteitisalsopossibletodefineaverage(orexpected)timeassumingwehavepickedaninstanceatrandomfromallpossibleinstances,butwewillmostlikelynotdiscussthishere
• Inasensewewillbepessimistsaboutouralgorithms,alwaysexpectingtheworstpossibleinput.
Advantagesofbeingpessimist
• Worst-casetimeanalysis– Providesanupperboundonanyinput,i.e.thealgorithmwillnevertakemorethanthis.
– Forsomealgorithms,worst-caseoccursoften– Helpsusprovisionwithredundancy(oftenagoodideainbuildingsoftwaresystems)
Sanitycheck
• Supposecomputerswereinfinitely-fastandcomputermemorywasfree.– Wouldyouhaveanyreasontostudyalgorithms?– Yes!Youstillneedtodemonstratethatyoursolutionterminates(halts) andgainsthecorrect answer.
• But...memoryisnotfreeandCPUstaketimetocompleteaprimitiveoperation.– Efficient useofresourcestogaincorrectanswers.
Announcements
• Nexttime:InsertionSort– ReadthroughChapters1and2fromthebook
• Homework1posted,DueonSep.7• Gooverthesyllabusonyourownandaskquestionsasnecessary