# Question #20 from Chapter 3 Section 1Describe an algorithim for f.pdf

26 de Mar de 2023
1 de 1

### Question #20 from Chapter 3 Section 1Describe an algorithim for f.pdf

• 1. Question #20 from Chapter 3 Section 1: Describe an algorithim for finding both the largest and the smallest integers in a finite sequence of integers. Solution Let n be the total number of integers. Have k be the "count" of the sequence, where f(k) gives you the integer at that "space" in the sequence. (i.e. f(3) in a sequence 2,3,6 would be f(3)=6) Let h be your highest value, and l be your lowest value. Start with an algorithm for finding the largest number: 1. Set h and k equal to zero. (h=k=0) 2. If f(k)>h, then h=f(k). 3. Add 1 to k. (k+1) 4. Loop the above two steps until k=n. (Loop back to step 2 until k=n) This will both allow you to keep replacing h with the next highest number, and also end the loop. Similarly with an algorithm for finding your lowest number: 1. Set h and k equal to zero. (h=k=0) 2. If f(k)