Embed presentation


![Example 2.3.1 Finding the Maximum Value in an Array Using a While Loop This algorithm finds the largest number in the array s [1], s [2], ... , s [ n ]. Input Parameter: s Output Parameters: None array_max_ver1 ( s ) { large = s [1] i = 2 while ( i ≤ s . last ) { if ( s [ i ] > large ) // larger value found large = s [ i ] i = i + 1 } return large }](https://image.slidesharecdn.com/chap02alg-100316020509-phpapp01/85/Chap02alg-3-320.jpg)

This document provides examples of algorithms to compute the factorial of a number, find the maximum value in an array, and recursively call a function. The factorial algorithm uses a while loop to multiply all integers from 1 to the given number n. The maximum value algorithm also uses a while loop to iterate through an array and track the largest number found. The recursive function example divides the input n by 2 and calls itself until n equals 1.


![Example 2.3.1 Finding the Maximum Value in an Array Using a While Loop This algorithm finds the largest number in the array s [1], s [2], ... , s [ n ]. Input Parameter: s Output Parameters: None array_max_ver1 ( s ) { large = s [1] i = 2 while ( i ≤ s . last ) { if ( s [ i ] > large ) // larger value found large = s [ i ] i = i + 1 } return large }](https://image.slidesharecdn.com/chap02alg-100316020509-phpapp01/85/Chap02alg-3-320.jpg)
