2、>suchthata'1≤a'2≤…≤a'n.Example:解釋什么是實例?Input:824936Output:234689TimeIsImportant“Timeisimportantforeverybody,especiallyforthecomputerscientistwhostudiesalgorithms.”J.S.YuWhatkindsofproblemsaresolvedbyalgorithms?LevelsofHardness1.Thereisnomethodtosolvetheprobleminfinitelymanysteps.2
3、.Theoretically,thereisanalgorithm,buttherunningtimeincreasestoomuchwiththesizeofinput,eventotheuniverseage(NPCproblems).3.Amongthe"good"algorithms,thereisstillahierarchyofrunningtime.多項式算法:把漸近復(fù)雜性與規(guī)模N的冪同階的這類算法稱為多項式算法。指數(shù)型算法:把漸近復(fù)雜性與規(guī)模N的指數(shù)同階的這類算法稱為指數(shù)型算法。這兩種算法在效率上有質(zhì)的區(qū)別的內(nèi)在原因是算法漸近復(fù)雜性的階的區(qū)
4、別。可見,算法的漸近復(fù)雜性的階對于算法的效率有著決定性的意義。多項式算法是有效的算法。很多問題都有多項式算法。但也有一些問題還未找到多項式算法,只找到指數(shù)型算法。Homework1.1-3,1.1-41.2AlgorithmsasatechnologySupposecomputerswereinfinitelyfastandcomputermemorywasfree.Wouldyouhaveanyreasontostudyalgorithms?Comparetherunningtimeofinsertsortandmergesort.Whystudyalg
5、orithmsandperformance??Algorithmshelpustounderstandscalability.?Performanceoftendrawsthelinebetweenwhatisfeasibleandwhatisimpossible.?Algorithmicmathematicsprovidesalanguagefortalkingaboutprogrambehavior.?Performanceisthecurrencyofcomputing.?Thelessonsofprogramperformancegenerali
6、zetoothercomputingresources.?Speedisfun!2GettingStartedAnalysisofAlgorithmsInsertionSortMergeSortTheproblemofsortingInput:sequenceofnumbers.Output:permutationsuchthata'1≤a'2≤…≤a'n.Example:Input:824936Output:234689AnExample:InsertionSortInsertionSort(A,n)
7、{fori=2ton{key=A[i]j=i-1;while(j>0)and(A[j]>key){A[j+1]=A[j]j=j-1}A[j+1]=key}}AnExample:InsertionSortInsertionSort(A,n){fori=2ton{key=A[i]j=i-1;while(j>0)and(A[j]>key){A[j+1]=A[j]j=j-1}A[j+1]=key}}301040201234i=?j=?key=?A[j]=?A[j+1]=?AnExample:InsertionSortInsertionSort
8、(A,n){fori=2ton{key=A[i]j=i-1;w