1 / 8

Mathematical Analysis of Non Recursive Algorithms (Section 2.3)

Mathematical Analysis of Non Recursive Algorithms (Section 2.3). O(1). O(f(n)). O(g(n)). O(t(n)). O(1). Non Recursive Algorithms. Complexity of Algorithm X =. Algorithm X (n) i  5 j  … while ( i < …) …

siusan
Download Presentation

Mathematical Analysis of Non Recursive Algorithms (Section 2.3)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Mathematical Analysis of Non Recursive Algorithms (Section 2.3)

  2. O(1) O(f(n)) O(g(n)) O(t(n)) O(1) Non Recursive Algorithms Complexity of Algorithm X = Algorithm X (n) i  5 j  … while ( i < …) … k  Algorithm Y(…) … for (…) while (…) … return …

  3. MaxElement MaxElement(A[1..n]) maxval  A[1] for i  2 to n do if A[i] > maxval maxval  A[i] return maxval

  4. UniqueElement UniqueElement(A[1..n]) for i  1 to n-1 do for j  i+1 to n do{ if A[i] = A[j] return false} return true

  5. MatrixMultiplication UniqueElement(A[1..n,1..n], B[1..n,1..n]) for i  1 to n do for j  1 to n do C[i,j] 0 for k  1 to n do C[i,j]  C[i,j] + A[i,k] *B[k,j] return C

  6. termination f(n) Recursive Algorithms Algorithm X (n, …) if (n = 0) return value while ( i < …) … return Algorithm X(n1) // where n1 < n Complexity of Algorithm X = T(n) //n is the size of the input T(n) = f(n) + T(n1) T(0) = 1

  7. Solving a Recursive Equation • Make a few evaluations of T(n) for a few values n1, n2, n3 according to the recursive call • Deduce a pattern for T(n) • Compute the number of times, k, the recursive call is made until the termination condition (e.g.,. T(0)) • Use 1 and 3 for obtaining a final equation T(n) • Solve the equation T(n)

  8. SumElement(A[1..n], i) If (i = n) then return A[n] Else return A[i] + sumElement(A,i+1) SumElement

More Related