// Find a maximum element in the array.
findMax(A)
findMaxHelper(A, 0, A.length)
findMaxHelper(A, left, right)
if (left == right - 1)
return A[left]
else
max1 = findMaxHelper(A, left, (right + left) / 2)
max2 = findMaxHelper(A, (right + left) / 2, right)
if (max1 > max2)
return max1
else
return max2
I am having a hard time understanding what is happening in this pseudo-code.
Can someone help explain what is happening at each line. I need to understand this code before I can answer the questions.
I know that the function findMax calls the helper function findMaxHelper, then findMaxHelper uses recursion. Other than that, I really don't understand it.
See Question&Answers more detail:os