mountain classpptx

15

Click here to load reader

Upload: gbarna

Post on 11-Jul-2015

185 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Mountain classpptx

The MountainJohn Latimer

And

Kyle Whittall

Page 2: Mountain classpptx

Does it have a peak?

Are all values in the array increasing before the peak?

Are all values in the array decreasing after the peak?

Is the array a mountain?

Page 3: Mountain classpptx

If so….You have a mountain!

Page 4: Mountain classpptx

A high point in an array.

Example:

1, 2, 3, 4, 5, 4, 3, 2, 1

A peak is…

5

Page 5: Mountain classpptx

It is a mountain range!

If it does not have a single mountain…

1 2 31

3 2 2 3 3 21

23

21

Page 6: Mountain classpptx

Has multiple peaks…

The numbers are not only increasing and decreasing before and after one peak.

Example:

A mountain range…

0

2

4

6

8

C

Page 7: Mountain classpptx

Determine a peak index…

The peak index is the element whose value is greater than the value immediately before it and also greater than the value immediately following it.

The first step…

Page 8: Mountain classpptx

0

1

2

3

4

5

6

Series 1

Column2

Column1

The peak index here is 5

Page 9: Mountain classpptx

Determine if all values leading up to a peak are increasing

The second step is to…

Page 10: Mountain classpptx

Check that all values following the peak are decreasing

The third step is to…

Page 11: Mountain classpptx

There is a peak if all values before the highest number are increasing and all values following the highest number are decreasing

Page 12: Mountain classpptx

The code required for a mountain class…

Page 13: Mountain classpptx

public static int getPeakIndex(int[] arr)

{

// part a

}

To determine if all values after the peak are decreasing…

Page 14: Mountain classpptx

Next use a for loop to vary through the array

Use an if stmt to contrast i and i-1

You must then add to the if stmt to make it compare i and i+1

Page 15: Mountain classpptx

If the program finds a peak return that value

If the program does not find a peak have it return -1

Last is the return