This preview shows pages 1–6. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: B.B. Karki, LSU 0.1 CSC 3102 Nonrecursive Algorithms B.B. Karki, LSU 0.2 CSC 3102 Definition and Examples Nonrecursive algorithm: Executed only once to solve the problem. Examples Largest element in a list of numbers Element uniqueness problem Matrix operations: addition, multiplication, and transpose Digits in binary representation Recursive algorithm invokes (makes reference to) itself B.B. Karki, LSU 0.2 CSC 3102 Definition and Examples Nonrecursive algorithm: Executed only once to solve the problem. Examples Largest element in a list of numbers Element uniqueness problem Matrix operations: addition, multiplication, and transpose Digits in binary representation Recursive algorithm invokes (makes reference to) itself repeatedly until a certain condition matches. B.B. Karki, LSU 0.3 CSC 3102 Analyzing Efficiency of Nonrecursive Algorithms Steps in mathematical analysis of nonrecursive algorithms: Decide on parameter n indicating input size Identify algorithm’s basic operation Determine worst, average, and best case for input of size n if the basic operation count depends not only on n Set up summation for C ( n ) reflecting algorithm’s loop structure Express the number of times the algorithm’s basic operation is executed Simplify summation using standard formulas and rules of sum manipulation (see Appendix A) Find a closedform formula for the count and/or establish it’s order of growth. B.B. Karki, LSU 0.4 CSC 3102 Example 1: Maximum Element Algorithm MaxElement ( A[0.. n  1] ) //Determines the value of the largest element in a given array //Input: An array A[0.. n  1] of real numbers //Output: The value of the largest element in A maxval ← A[0] for i ← 1 to n  1 do if A[i] > maxval maxval ← A[i] return maxval B.B. Karki, LSU 0.5 CSC 3102 Example 1: Maximum Element (Cont.) Input size = n , the number of elements in the array Algorithm’s basic operation is “comparison” It is executed on each repetition of the loop Formula for the basic operation count: Sum is simply 1 repeated by n 1 times....
View
Full
Document
This note was uploaded on 10/06/2009 for the course CSC 3102 taught by Professor Kraft,d during the Fall '08 term at LSU.
 Fall '08
 Kraft,D
 Algorithms

Click to edit the document details