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.
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).
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.
Write a C# class Vector
that represents a vector in
n-dimensional space. Your class should include the following:
a constructor that takes a variable number of arguments of
type double
, yielding a vector with those components
an overloaded operator +
that adds two vectors
an overloaded operator *
that multiplies a
vector by a scalar, yielding a new vector
an overloaded operator * that computes the dot product of two vectors, yielding a scalar
a method that computes the length of a vector
a method that computes the angle between two vectors in radians
a ToString()
method that yields a string such as
"[3.25 5.02 -6.12]
", with two digits after
the decimal point in each component
a static method Parse()
that parses a string
such as "[3.25 5.02 -6.12]
", yielding a
vector
Write a C# class Polynomial
representing a polynomial
of a single variable. Your class should include the following:
a constructor that takes a variable number of arguments of
type double
, yielding a polynomial with those
coefficients. For example,
new Polynomial(1.0, 4.0, 5.0)
should yield the polynomial x2 + 4x + 5.
an overloaded operator +
that adds two
polynomials
an overloaded operator *
that multiplies two
polynomials
a method that evaluates a polynomial for a given value of x
a method that returns the first derivative of a polynomial
a method that returns the k-th derivative of a polynomial for a given k
a ToString()
method that yields a string such as
"x^2 + 4x + 5
"
a static method Parse()
that parses a string
such as "x^2 + 4x + 5
", yielding a polynomial
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
a constructor CharSet(string s)
that intializes
a CharSet
with all characters found in the given string
an Equals
method that can test whether two
CharSet
objects represent the same set.
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.
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.
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.