Maximum and minimum

Report a typo

We can easily modify some divide and conquer algorithms. For example, the following pseudocode finds the maximum value of an array:

function maximum(array, start, end):
    if start == end then:  
        return array[start]
    mid = int((start + end) / 2)
    left = maximum(array, start, mid)
    right = maximum(array, mid + 1, end)
    if left > right then:
        return left
    else:
        return right

Here int()int() function returns the largest integer less than the given number, i.e. for example, int(4.5)int(4.5) will return 4.

By modifying one line of the pseudocode, you can use it to find the minimum value of an array. Please mention the line number below:

Enter a number
___

Create a free account to access the full topic