|
| 1 | +# Find (Maximum) |
| 2 | + |
| 3 | +Find the maximum number from a list of given numbers. |
| 4 | + |
| 5 | +## Applications |
| 6 | + |
| 7 | +By finding the maximum number in a list, we can perform many operations based on this. |
| 8 | + |
| 9 | +Uses: |
| 10 | + |
| 11 | +- Sort our records based on the largest value. |
| 12 | +- Makes our process of finding a particular item easy. |
| 13 | +- If we are able to find out and sort our records based on |
| 14 | + largest value then we can sort or find our records according |
| 15 | + to particular index or element with ease. |
| 16 | + |
| 17 | +## Steps |
| 18 | + |
| 19 | +The maximum number from an array can be found by various ways. |
| 20 | +Here, we will see three different ways of finding the largest |
| 21 | +number. |
| 22 | + |
| 23 | +1. By comparing all the elements of an array. |
| 24 | +2. By using predefined methods. |
| 25 | +3. By sorting. |
| 26 | + |
| 27 | +## Example 1 |
| 28 | + |
| 29 | +By comparing all the elements of an array: |
| 30 | + |
| 31 | +Given the list `[6, 4, 50, 8, 70, 2, 20]`, let's find the maximum number. |
| 32 | + |
| 33 | +### Step 1 |
| 34 | + |
| 35 | +Provide `[6, 4, 50, 8, 70, 2, 20]` as input for a method or function. |
| 36 | + |
| 37 | +### Step 2 |
| 38 | + |
| 39 | +By using the comparsion process, we are going to find the largest number. |
| 40 | +Set the the index element of an array as maximum number. |
| 41 | +max = array[0] |
| 42 | +`max = 6` |
| 43 | + |
| 44 | +### Step 3 |
| 45 | + |
| 46 | +Looping the entire array of elements and compare each element with max. |
| 47 | +If a given number is bigger than the max, then we make this particular number as max. |
| 48 | +Consider one of the iterations, which happens between 6 and 50. |
| 49 | +`max = 50` |
| 50 | + |
| 51 | +End of the entire loop. |
| 52 | +`max = 70` |
| 53 | + |
| 54 | +### Step 4 |
| 55 | + |
| 56 | +Return the value 70. |
| 57 | + |
| 58 | +## Example 2 |
| 59 | + |
| 60 | +By predefined max method: |
| 61 | + |
| 62 | +Given the list `[6, 4, 50, 8, 70, 2, 20]`, let's find the maximum number. |
| 63 | + |
| 64 | +### Step 1 |
| 65 | + |
| 66 | +Provide `[6, 4, 50, 8, 70, 2, 20]` as input for a method/ function. |
| 67 | + |
| 68 | +### Step 2 |
| 69 | + |
| 70 | +The predefined max method, find the maximum element. |
| 71 | +`70` |
| 72 | + |
| 73 | +### Step 3 |
| 74 | + |
| 75 | +Return the value 70. |
| 76 | + |
| 77 | +## Example 3 |
| 78 | + |
| 79 | +By sorting: |
| 80 | + |
| 81 | +Given the list `[6, 4, 50, 8, 70, 2, 20]`, let's find the maximum number. |
| 82 | + |
| 83 | +### Step 1 |
| 84 | + |
| 85 | +Provide `[6, 4, 50, 8, 70, 2, 20]` as input for a method/ function. |
| 86 | + |
| 87 | +### Step 2 |
| 88 | + |
| 89 | +The predefined sort method, sorts the entire array in ascending (small to big) order. |
| 90 | +`[2, 4, 6, 8, 20, 50, 70]` |
| 91 | + |
| 92 | +### Step 3 |
| 93 | + |
| 94 | +Get the last value out of the list by using predefined last method. |
| 95 | +`70` |
| 96 | + |
| 97 | +### Step 4 |
| 98 | + |
| 99 | +Return the value 70. |
| 100 | + |
| 101 | +## Implementation |
| 102 | + |
| 103 | +- [Ruby](https://github.com/TheAlgorithms/Ruby/blob/master/maths/find_max.rb) |
| 104 | + |
| 105 | +# Source |
| 106 | + |
| 107 | +- [GeeksForGeeks](https://www.geeksforgeeks.org/c-program-find-largest-element-array/) |
| 108 | + |
| 109 | +# YouTube |
| 110 | + |
| 111 | +- [YouTube URL video](https://youtu.be/En68ipRaFOU) |
0 commit comments