(3 points) Suppose I have an unsorted array of integers with a size of .

  1. Write the pseudocode for a looping (non-recursive) algorithm that finds the maximum element in the array.
  2. Write the pseudocode for a recursive algorithm that finds the maximum element in the array.
  3. What is the runtime Big- value for your recursive algorithm? Write a proof for your answer.
  4. What is the space Big- value for your recursive algorithm? Write a proof for your answer.

(2 points) Consider the Harmonic numbers, given by the series and recursion relation shown below. Let’s come up with a recursive algorithm for calculating the nth Harmonic number.

  1. What is the value of ?
  2. Write the pseudocode for a recursive algorithm to calculate the nth Harmonic number.
  3. Is your algorithm an example of linear, binary, or multiple recursion? Why?
  4. Sketch out a recursive trace of your function when the argument is used. Use the example of the recursive trace from your textbook as a template.

(3 points) Suppose I have a two-dimensional array of integers.

  1. Write the pseudocode for a looping (non-recursive) algorithm that computes the sum of all the elements in the two-dimensional array.
  2. Write the pseudocode for a recursive algorithm that computes the sum of all the elements in the two-dimensional array.
  3. What is the runtime Big- value for your recursive algorithm?
  4. What is the space Big- value for your recursive algorithm?

(2 points) You are given an array consisting of random integers. Write the pseudocode for a function that takes the array as an argument and returns a new array with length that satisfys the following conditions:

  1. Every element of the output array is a positive integer
  2. The elements of the output array are listed in increasing order
  3. The sum of the elements in the output array is as small as possible