TITLE: Expected Value of Local Maxima and Local Minima
QUESTION [11 upvotes]: Recently I came across this question:
Given a random permutation of integers 1, 2, 3, …, n with a discrete, uniform distribution, find the expected number of local maxima. (A number is a local maxima if it is greater than the number before and after it.) For example, if n=4 and our permutation was 1, 4, 2, 3, then the # of local maxima would be 2 (both 4 and 3 are maxima).
I know the answer will be (n+1)/3 .I wanted to know what will be the answer when we have to consider the local maxima as well as the local minima i.e Finding out the expected number of local maxima and local minima.

REPLY [2 votes]: Here is a numerical method that can be used to solve the problem for small K.
1) Brute force solve the problem for small x (say x = 3 to 12)
2) Find a common denominator for each of your solutions (for K = 2, the common denominator is 90)
3) put each solution in terms of the common denominator
4) Use the method of common differences to find what the maximum order of the quadratic equations will be $(ax^n + bx^{n-1} + cx^{n-2} ... )$
http://www.purplemath.com/modules/nextnumb.htm
5) using your solutions set up a matrix representing the system of linear equations and then solve the matrix, which will give you your values for $a, b, c$, ...
6) then use those values for your your equation.
7) simplify as desired  
For $K = 2$, it simplifies to $E[X^2] = (40 X^2 - 144 X + 131)/90$
For $K = 3$, it simplifies to $E[X^3] = (280 X^3 -1344 X^2 + 2063 X - 1038)/945 $