Input: sequence "s" indexed from 1 to n; number of elements in the sequence "n" Output: First occurrence of the largest element in the sequencefind_largest_element(s,n) {large = s_1 \\ initializes largeindex_large = 1 \\ initializes the index of largefor i = 2 to n \\ steps through the sequenceif (s_i > large) { \\ since this is >, it will not be called if valueequals largelarge = s_i index_large = i}return index_large}
Comments