Algorithm 1.2.1 Finding the Maximum of Three Numbers - PowerPoint PPT Presentation

About This Presentation
Title:

Algorithm 1.2.1 Finding the Maximum of Three Numbers

Description:

CHAPTER 1 Introduction ... Input Parameter: a Output Parameters: a shuffle(a) { for i = 1 to a.last - 1 swap(a[i], a[rand(i,a.last)]) } * * Title: CHAPTER 1 – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 6
Provided by: MSch158
Category:

less

Transcript and Presenter's Notes

Title: Algorithm 1.2.1 Finding the Maximum of Three Numbers


1
CHAPTER 1
  • Introduction

2
Algorithm 1.2.1 Finding the Maximum of Three
Numbers
This algorithm finds the largest of the numbers
a, b, and c.
Input Parameters a, b, c Output Parameter
x max(a,b,c,x) x a if (b gt x) // if b is
larger than x, update x x b if (c gt x) //
if c is larger than x, update x x c
3
Algorithm 1.2.2 Finding the Maximum Value in an
Array Using a While Loop
This algorithm finds the largest number in the
array s1, s2, ... , sn.
Input Parameter s Output Parameters
None array_max_ver1(s) large s1 i 2
while (i s.last) if (si gt large) //
larger value found large si i i
1 return large
4
Algorithm 1.2.4 Finding the Maximum Value in an
Array Using a For Loop
This algorithm finds the largest number in the
array s1, s2, ... , sn.
Input Parameter s Output Parameters
None array_max_ver2(s) large s1 for i
2 to s.last if (si gt large) // larger
value found large si return large
5
Algorithm 1.3.1 Array Shuffle
This algorithm shuffles the values in the array
a1, a2, ... , an.
Input Parameter a Output Parameters
a shuffle(a) for i 1 to a.last -
1 swap(ai, arand(i,a.last))
Write a Comment
User Comments (0)
About PowerShow.com