1. Repeated Digits

Write a method repeated(int n) that finds the highest base b in the range 2 ≤ b ≤ 16 in which the integer n has any two identical consecutive digits. The method should print b, and should also print n in that base. Use the letters 'a'..'f' to print digits that are greater than 9.

2. Two Digits

Write a program that reads two decimal integers, one per line, and writes the last two digits of their product in base 7. The integers may be arbitrary large (i.e. they might not even fit in memory).

3. Double-Ended Queue

Write a class implementing a double-ended queue. Implement this interface:


// double-ended queue
interface Deque<T> {
  void prepend(T val);
  T removeFirst();
  void append(T val);
  T removeLast();
  bool isEmpty { get; }
}

All of these operations should run in constant time. Use a doubly-linked list.

4. Vector

Write a C# class Vector that represents a vector in n-dimensional space. Your class should include the following:

5. Polynomial

Write a C# class Polynomial representing a polynomial of a single variable. Your class should include the following:

6. Set of Characters

Write a class CharSet that implements Set<char>, where Set is defined as

interface Set<T> {
  void add(T val);
  void remove(T val);
  bool contains(T val);
}

add, remove and contains should all run in O(1). Also provide

7. Linear Probing

Implement a class LinearHashMap that implements this interface:

interface Map<K, V> {
    // When getting, if the key is not present, return the default value
    // for type V (e.g. null or 0).
    // When setting, if the key is already present, replace the given value.
    V this[K key] { get; set; }
    
    bool containsKey(K key);

    bool removeKey(K key);  // returns true if key was removed
}

Use a hash table with linear probing as discussed in the lecture. Allocate 10 hash buckets initially. Dynamically resize the table as necessary to keep the table's load factor under 0.3. When a key is removed, rehash all keys that follow it.

8. Hash Chain Lengths

Write a program that reads an integer N and simulates inserting (100 N) values into a hash table with N buckets using separate chaining, assuming uniform hashing. The program should print the lengths of the longest and shortest chains.

9. Topological Sort

Write a method that takes a jagged array representing an undirected graph with no cycles, and outputs a list of vertices in an ordering such that all edges point from a vertex earlier in the order to a vertex later in the order.