Practice Problems (not for submission)

  1. Understanding Mathematical Induction

  2. Write a function that given an integer n in base 10 , prints out the equivalent integer in base b (for an arbitrary natural number b.

  3. Bertrand's postulate

    Write a function to find out the number of primes between a given number n and 2n.

  4. Extended Euclid

    Given two positive integers m and n determine two integers i and j such that i.m + j.n = gcd (m,n) where gcd (m,n) is the greatest common divisor of m and n.

  5. Bisection method

    You are given an interval [a, a+b], where the value of a function f is initially positive (starting from a) and then it becomes negative for some a < c <= b, and remains negative, i.e. f(b) is negative. Write ocaml function that computes the first negative occurence in [a, a+b] using a halving method. Given an interval [ a, a+b], it computes the sign of f at the midpoint a + b/2 and if it is positive then it recursively searches the interval beginning at a +b/2 (since the sign change must occur in the interval to the right), else it searches the lower interval.

  6. We want to multiply two non-negative integers m , n using the following algorithm. If n is an even number then we halve n and double m and compute their product otherwise we decrement n by 1 and add m to the product of m and n-1. Write an OCAML function Mult(m, n) to implement the above algorithm. () Write an OCAML function Mult(m, n) to implement the above algorithm

  7. List programming