find the maximum algorithm

14
Find the Maximum Algorithm currentIndex: 0 maxValue: -1 start with -1 as maximum 5 3 1 2 9 8 7 3 9 0 1 2 3 4 5 6 7 8

Upload: gail-carmichael

Post on 22-Jan-2018

270 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 0 maxValue: -1

start with -1 as maximum

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 2: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 0 maxValue: -1

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 3: Find the Maximum Algorithm

Find the Maximum Algorithm

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

currentIndex: 0 maxValue: -1

found a new maximum!

Page 4: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 0 maxValue: 5

found a new maximum!

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 5: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 1 maxValue: 5

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 6: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 2 maxValue: 5

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 7: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 3 maxValue: 5

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 8: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 4 maxValue: 5

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

found a new maximum!

Page 9: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 4 maxValue: 9

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

found a new maximum!

Page 10: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 5 maxValue: 9

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 11: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 6 maxValue: 9

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 12: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 7 maxValue: 9

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 13: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 8 maxValue: 9

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8

Page 14: Find the Maximum Algorithm

Find the Maximum Algorithm

currentIndex: 8 maxValue: 9

Finished: output is 9

5 3 1 2 9 8 7 3 9

0 1 2 3 4 5 6 7 8