Other代写:CSCI2110 Algorithm Complexity代做Matlab编程

代写算法作业,计算代码的时间复杂度。PurposeThe purpose of this assignment is to practice your analysis of algorithm complexity. It is recommended that this assignment be printed, and that the work be done right on it. This assignment is to be submitted in paper form to the assignment boxes, just to the left of the elevators, on the second floor of the Goldberg CS Building. For each of the algorithms below:Derive the cost function for the algorithm. Be sure to show your work like we do in lectures.State the complexity of the algorithm in Big-Oh.Prove that the derived cost function is in the stated order (big-Oh).Problem 0: Reverse123456789input: vals[n]output: vals reversedfor i = 0 ... n/2 t = vals[i] vals[i] = vals[n-i-1] vals[n-i-1] = treturn valsProblem 1: Multiplication1234567891011input: A[n][n] and B[n][n] // 2D arrays of size n x noutput: C[n][n]C = array[n][n] // Assume O(1) cost to create 2D arrayfor i = 0 ... n for j = 0 ... n C[i][j] = 0 for k = 0 ... n C[i][j] = C[i][j] + A[i][k] x B[k][j]return CProblem 2: Edge Detection123456789101112input: A[n][n], F[3][3] // 2D arraysoutput: E[n][n]E = array[n][n] // Assume O(1) basic operation to create 2D arrayfor x = 1 ... n - 1 for y = 1 ... n - 1 E[x][y] = 0 for k = -1 ... 2 for l = -1 ... 2 E[x][y] = E[x][y] + A[x+k][y+l] x F[k+1][l+1]return EProblem 3: Sorting12345678910input: vals[n]output: sorted vals[n]for i = n - 1 ... 0 for j = 0 ... i if vals[j] ] vals[j+1] v = vals[j] vals[j] = vals[j+1] vals[j+1] = vreturn valsProblem 4: Longest Common SubsequenceBased on code from https://en.wikipedia.org/wiki/Longest_common_subsequence_problem1234567891011121314151617input: X[n], Y[n]output: length of longest common sequence between X and YC = Array[n][n]for i = 0 ... n C[i,0] = 0 C[0,i] = 0for i = 1 ... n for j = 1 ... n if X[i] == Y[j] C[i,j] = C[i-1,j-1] + 1 else if C[i,j-1] < C[i-1,j] C[i,j] = C[i-1,j] else C[i,j] = C[i,j-1]return C[n,n]& Problem 5: Sorting, again1234567891011input: vals[n]ouOther代写:CSCI2110 Algorithm Complexity代做留学生Matlab编程tput: sorted vals[n]for i = 1 ... n for j = i ... 1 if vals[i] >= vals[i-1] break v = vals[i] vals[i] = vals[i-1] vals[i-1] = vreturn valsProblem 6: Factorization123456789101112input: n-bit integer X // see not below the algorithmoutput: list of prime factors and their multiplicityacc = Xfor i = 2 ... sqrt( X ) count = 0 while acc % i == 0 acc = acc / i count = count + 1 if count > 0 print i (count)Note: Recall that the range of values of an n-bit integer is 0 … 2^n.Problem 7: Pivot123456789101112131415161718input: vals[n]output: vals divided by a pivot at val[0]low = 1high = n - 1while low <= high if vals[0] <= vals[high] t = vals[high] vals[high] = vals[low] vals[low] = t low = low + 1 else high = high - 1t = vals[high]vals[high] = vals[0]vals[0] = tBonus Problem: Sorting, Once more with feeling!12345678910111213141516171819202122232425262728293031323334input: vals[n]output: sorted vals[n]sort( vals[n] )function sort( V[n] ): if n > 2 m=n/2 sort( V[0:m] ) sort( V[m,n] ) A = array[n] // assume 1 operation to create array i=0 j=m k=0 while i < m and j < n if V[i] [<= V[j] A[k] = V[i] i=i+1 else A[k] = V[j] j=j+1 k=k+1 if j < n i=j for l = k ... n A[l] = V[i] i=i+1 for l = 0 ... n V[l] = A[l]return VHints and SuggestionsPrint this assignment and show your work right on it.Feel free to use O(1) instead of specific constants when analyzing the algorithms.Be sure to show your work!GradingEach problem will be graded out of 10 points:4 marks for deriving the correct cost function. The cost function should be of the correct order, and it should be clear how it was derived from the algorithm. One mark for the correct answer, three marks for showing your work.2 marks for identifying the correct order of the function (big Oh). One mark for the correct order, and one mark for correct notation. I.e., no multiplicative constants, or multiple terms.4 marks for justifying your answer. Follow the steps discussed in lecture. Approximately, 1 mark per step.What to Hand InSubmit you assignment in hardcopy (paper form) to the submission box, which is located to the left of the elevators, on the second floor of the CS Goldberg Building.转自:http://ass.3daixie.com/2019011522881440.html

你可能感兴趣的:(Other代写:CSCI2110 Algorithm Complexity代做Matlab编程)