Sample Problems

This page lists a number of elementary problems that are good examples of the kinds of problems that can be studied from the point of view of an algorithms course. Each one of these problems can be solved by one or more algorithms which can be implemented as Java or C++ programs.

Notice how the problems on this page are in a certain way analogous to classes in object oriented programming. Each problem below is really a description of a whole family of problems, just as a class is a description of a whole family of objects. Each problem below can be "instantiated" as a specific problem with specific numbers in a specific list (much as objects are specific instances of a class). We say that an algorithm solves a problem if the algorithm finds the correct solution for every instance of the problem.

Given one of these problems and given a specific algorithm that solves it, the key issue for us is how the "run time" of the algorithm, when it is applied to an instance of the problem, depends on the "size" of the problem instance. For example, if you double the length of an input list, does the algorithm's run time double (an O(n) algorithm), or does it quadruple (an O(n^2) algorithm), or maybe the run time goes up by just a very small amount (an O(ln(n)) algorithm). One important thing to realize is that a specific problem can have different algorithms with different run time behaviors, i.e., one algorithm that solve the problem is O(n) but another algorithm that also solves the problem is O(ln(n)).

  1. Given a list of integers, sort the list.
  2. Given a list of integers, find the maximum (or minimum) entry in the list.
  3. Given a list of integers, determine if there are any duplicate entries in the list.
  4. Given a list L of integers and an integer k, determine if k is in L.
  5. Given a sorted list L of integers and an integer k, determine if k is in L.
  6. Given a list of integers, find the minimum difference between any two entries from the list.
  7. Given a list of integers, find the maximum difference between any two entries from the list.
  8. Given a list L of n integers and a positive integer k < n, find the k'th largest (or k'th smallest) element of L.
  9. Given a list of integers, find the integer that occurs the most often in the list.
  10. Given two lists of integers L1 and L2, each of size n, and an integer S, determine if there exits a pair of integers, one from each of L1 and L2, that sum to S.
  11. Given a list L of integers and an integer S, determine if any pair of entries from L sum to S.
  12. Given a list L of n integers, an integer S, and a positive integer k < n, determine if any k entries from L sum to S.
  13. Given a list of integers, find the maximum sum over all possible contiguous sub lists.
  14. Given a positive integer n, create a list containing a random permutation of the integers from 1 to n.
  15. Given a list of points in the plane, find the two points from the list that are closest to each other.

Return to the CS 332 lecture page.
Return to the CS 332 home page.


compliments and criticisms