Difference between revisions of "2.7"

From The Algorithm Design Manual Solution Wiki
Jump to navigation Jump to search
(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 15: Line 15:
  
  
Back to [[Chater 2]]
+
Back to [[Chapter 2]]

Latest revision as of 18:52, 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 Chapter 2