Difference between pages "Chapter 12" and "2.7"
(Difference between pages)
Jump to navigation
Jump to search
(Created page with "Problems Back to Chapter List") |
(Created page with "'''n = 1''' The single element array is already its max. Loop is not entered. Max is returned Let for '''n=k''', the algorithm is true For '''n = k+1''' ,two cases arise :...") |
||
Line 1: | Line 1: | ||
− | + | '''n = 1''' | |
+ | The single element array is already its max. Loop is not entered. Max is returned | ||
+ | Let for '''n=k''', the algorithm is true | ||
− | Back to [[ | + | For '''n = k+1''' ,two cases arise : |
+ | |||
+ | '''1)''' a[k+1] is max | ||
+ | |||
+ | '''2)''' a[k+1] is not max. | ||
+ | |||
+ | If '''1)''' holds then at the last iteration when i = k+1, m = a[k+1] is assigned. Hence max is returned | ||
+ | |||
+ | Else if '''2)''' holds then we are left with the task of finding the max among '''n = k''' elements, which we already assumed that the algorithm does correctly. | ||
+ | |||
+ | |||
+ | Back to [[Chater 2]] |
Revision as of 18:51, 9 September 2020
n = 1 The single element array is already its max. Loop is not entered. Max is returned
Let for n=k, the algorithm is true
For n = k+1 ,two cases arise :
1) a[k+1] is max
2) a[k+1] is not max.
If 1) holds then at the last iteration when i = k+1, m = a[k+1] is assigned. Hence max is returned
Else if 2) holds then we are left with the task of finding the max among n = k elements, which we already assumed that the algorithm does correctly.
Back to Chater 2