Follow

Translate

Tuesday, March 8, 2016

Algorithm Largest Element in Array

Algorithm 2.1: (Largest Element in Array) A nonempty array DATA with N numerical values is given.This algorithm finds the location LOC and the value MAX of the largest element of DATA.The variable K is used as a counter.

Step 1.  [Initialize] Set K: = 1, LOC: = 1 and MAX : = DATA[1].

Step 2.  [Increment Counter]. Set K : = K+1.

Step 3. [test counter.] If K > N, then:
Write: LOC,  MAX, and Exit.

Step 4. [Compare and Update.] If MAX < DATA[K], then:
Set LOC: = K and MAX : = DATA[K].

Step 5. [Repeat Loop.] Go to the Step 2.

If You want to learn about the technology, computer science & engineering, web programming, freelancing, earning please click here :CSE SOLVE

0 comments:

Post a Comment