403: algorithms and data structurespetko/classes/fall16-csi403-slides/01-intro.pdf403: algorithms...

32
403: Algorithms and Data Structures Prof. Petko Bogdanov Introduction Fall 2016 UAlbany Computer Science

Upload: others

Post on 12-Feb-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Announcements

• Nexttime:InsertionSort– ReadthroughChapters1and2fromthebook

• Homework1posted,DueonSep.7• Gooverthesyllabusonyourownandaskquestionsasnecessary