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 programs in pretty much any programming language.

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 solves the problem is O(n) but another (better) 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 of integers and an integer k, determine if k is in the list.
  5. Given a sorted list of integers and an integer k, determine if k is in the list.
  6. Given a list of integers, find the maximum (or minimum) difference between any two entries from the list.
  7. Given a list of n integers and a positive integer k < n, find the k'th largest (or k'th smallest) element of the list.
  8. Given a list of integers, find the integer that occurs the most often in the list.
  9. 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.
  10. Given a list of integers and an integer S, determine if any pair of entries from the list sum to S.
  11. Given a list of n integers, an integer S, and a positive integer k < n, determine if any k entries from the list sum to S.
  12. Given a list of numbers, create a new list with the same length such that the i'th element in the new list is the sum of the first i elements from the original list (the "prefix sum" algorithm).
  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 33200 lecture page.
Return to the CS 33200 home page.


compliments and criticisms