1 / 5

Maximum-Finding Algorithms in Array Manipulation

This resource provides algorithms for finding the maximum value in an array and shuffling the array values.

rochellem
Download Presentation

Maximum-Finding Algorithms in Array Manipulation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 > x) // if b is larger than x, update x x = b if (c > 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 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 }

  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 s[1], s[2], ... , s[n]. Input Parameter: s Output Parameters: None array_max_ver2(s) { large = s[1] for i = 2 to s.last if (s[i] > large) // larger value found large = s[i] return large }

  5. Algorithm 1.3.1 Array Shuffle This algorithm shuffles the values in the array a[1], a[2], ... , a[n]. Input Parameter: a Output Parameters: a shuffle(a) { for i = 1 to a.last - 1 swap(a[i], a[rand(i,a.last)]) }

More Related