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