Mathematical Analysis of Non Recursive Algorithms - PowerPoint PPT Presentation

About This Presentation
Title:

Mathematical Analysis of Non Recursive Algorithms

Description:

Mathematical Analysis of Non Recursive Algorithms (Section 2.3) Non ... Complexity of Algorithm X = MaxElement. MaxElement(A[1..n]) maxval A[1] ... pattern ... – PowerPoint PPT presentation

Number of Views:3514
Avg rating:3.0/5.0
Slides: 9
Provided by: cseLe
Category:

less

Transcript and Presenter's Notes

Title: Mathematical Analysis of Non Recursive Algorithms


1
Mathematical Analysis of Non Recursive
Algorithms (Section 2.3)
2
Non Recursive Algorithms
Complexity of Algorithm X
Algorithm X (n) i ? 5 j ?
while ( i lt ) k ?
Algorithm Y() for ()
while ()
return
3
MaxElement
MaxElement(A1..n) maxval ? A1 for i ? 2
to n do if Ai gt maxval
maxval ? Ai return maxval
4
UniqueElement
UniqueElement(A1..n) for i ? 1 to n-1 do
for j ? i1 to n do if Ai
Aj return false return true
5
MatrixMultiplication
UniqueElement(A1..n,1..n, B1..n,1..n) for i
? 1 to n do for j ? 1 to n do
Ci,j ?0 for k ? 1 to n do
Ci,j ? Ci,j Ai,k
Bk,j
return C
6
Recursive Algorithms
Algorithm X (n, ) if (n 0) return value
while ( i lt )
return Algorithm X(n1) // where n1 lt 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
  1. Make a few evaluations of T(n) for a few values
    n1, n2, n3 according to the recursive call
  2. Deduce a pattern for T(n)
  3. Compute the number of times, k, the recursive
    call is made until the termination condition
    (e.g.,. T(0))
  4. Use 1 and 3 for obtaining a final equation T(n)
  5. Solve the equation T(n)

8
SumElement
  • SumElement(A1..n, i)
  • If (i n) then return An
  • Else
  • return Ai sumElement(A,i1)
Write a Comment
User Comments (0)
About PowerShow.com