Advanced Algorithms Summative

Qn 1

Solve a mathematical problem that returns the sum of the first n numbers.
There are a number of algorithms that can be used to solve the same problem.
At this point we need to use loops to add the first n numbers and return the sum.

Context

  1. n = 8
  2. Numbers considered are: 1, 2, 3, 4, 5, 6, 7, 8
  3. Sum will be 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8

The sum will be returned.

Tasks to be completed

  1. Write the pseudocode for the algorithm (sufficiently commented)
  2. Derive the function of the running time of the algorithm and express the function in big-oh notation.
  3. Write the program and test it on four different values: 10, 10,000, 1,000,000, 1,000,000,000. What were your observations on the response time on every respective input? How did the output behave and why?