Homework Assignment 1
Assignment
-
(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.
- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on
the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on
the ADT implementations.
-
(50 points) Describe in detail an algorithm for reversing a singly linked
list
L using only a constant amount of additional space.
- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on
the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on
the ADT implementations.
-
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.
- Provide and explain pseudocode
- Statement and proof of time complexity. Be clear of the assumptions on
the ADT implementations.
- Statement and proof of memory complexity. Be clear of the assumptions on
the ADT implementations.