Homework Assignment 1


Assignment

  1. (50 points) Let A be an array of size n ≥ 2 containing integers from 1 to n-1 inclusive, one of which is repeated. Describe an algorithm for finding the integer in A that is repeated.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
  2. (50 points) Describe in detail an algorithm for reversing a singly linked list L using only a constant amount of additional space.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.
  3. Bonus. (10 points) Write a method, shuffle(A), that rearranges the elements of array A so that every possible ordering is equally likely. You may rely on a function rand(n), which returns a random number between 0 and n-1 inclusive.
    1. Provide and explain pseudocode
    2. Statement and proof of time complexity. Be clear of the assumptions on the ADT implementations.
    3. Statement and proof of memory complexity. Be clear of the assumptions on the ADT implementations.


General Instructions, Turning in assignments, and Grading

General Instructions

Turn in Instructions

Each assignment will be turned in in class (hard copy). Assignments are due BEFORE, let me repeat, before class starts. This does not mean one minute after class starts. Details:

Grading