## Purpose

The purpose of this assignment is to practice your analysis of algorithm complexity. It is recommended that this assignment be printed, and that the work be done right on it. This assignment is to be submitted in paper form to the assignment boxes, just to the left of the elevators, on the second floor of the Goldberg CS Building. For each of the algorithms below:

- Derive the cost function for the algorithm. Be sure to show your work like we do in lectures.
- State the complexity of the algorithm in Big-Oh.
- Prove that the derived cost function is in the stated order (big-Oh).

## Problem 0: Reverse

1 | input: vals[n] |

## Problem 1: Multiplication

1 | input: A[n][n] and B[n][n] // 2D arrays of size n x n |

## Problem 2: Edge Detection

1 | input: A[n][n], F[3][3] // 2D arrays |

## Problem 3: Sorting

1 | input: vals[n] |

## Problem 4: Longest Common Subsequence

Based on code from https://en.wikipedia.org/wiki/Longest_common_subsequence_problem

1 | input: X[n], Y[n] |

## Problem 5: Sorting, again

1 | input: vals[n] |

## Problem 6: Factorization

1 | input: n-bit integer X // see not below the algorithm |

Note: Recall that the range of values of an n-bit integer is 0 … 2^n.

## Problem 7: Pivot

1 | input: vals[n] |

## Bonus Problem: Sorting, Once more with feeling!

1 | input: vals[n] |

## Hints and Suggestions

- Print this assignment and show your work right on it.
- Feel free to use O(1) instead of specific constants when analyzing the algorithms.
- Be sure to show your work!

## Grading

Each problem will be graded out of 10 points:

4 marks for deriving the correct cost function. The cost function should be of the correct order, and it should be clear how it was derived from the algorithm. One mark for the correct answer, three marks for showing your work.

2 marks for identifying the correct order of the function (big Oh). One mark for the correct order, and one mark for correct notation. I.e., no multiplicative constants, or multiple terms.

4 marks for justifying your answer. Follow the steps discussed in lecture. Approximately, 1 mark per step.

## What to Hand In

Submit you assignment in hardcopy (paper form) to the submission box, which is located to the left of the elevators, on the second floor of the CS Goldberg Building.