Analysis of an Algorithm |
Document last modified: |
Assignment
| Find_Largest (A) //@ pre A != null; //@ post (\forall int i; 1 <= i && i <= A.length; A[\result] >= A[i]); // post: result = index in A of the largest element in A
|
Cost |
Times Executed |
|
| 1 | location ← 1 | c1 | |
| 2 | for i ←2 to length[A] do | c2 | |
| 3 | if A[location] < A[i] then | c3 | |
| 4 | location ← i | c4 | |
| 5 | return location | c5 | |