CSE 131 / 501N (Fall 2013)
Recitation Questions

Some of the questions may involve more time than you have in lab. The idea is to stretch some on these problems, so that you will find the quiz and exam questions easier to tackle. The quiz and associated exam problems will resemble the questions you see here, so work to master these and you should have no problem on the quiz or exam.

Where there are multiple exercises within a problem, choose one or two and leave the rest for homeowork on your own.

  1. An array of 100 elements is allocated. What is the index of its first element? What is the index of its last element?
  2. DNA bases are usually denoted as A, T, C, or G. Declare and initialize a String array that contains those bases.
  3. Write code that populates an array of N elements with a random base for each element.
  4. Take an array of int values and create a copy of that array, with all of the elements reversed in terms of their position.
  5. Why does the following code not reverse the elements of an array in-place?
       int N = array.length;
       for (int i=0; i < N; ++i) {
          array[N-i-1] = array[i]
  6. Try to write a Sieve of Eratostothenes prime number finder for primes up to 1000, without looking at an existing solution.
  7. Write a program that tests the randomness of a random number generator along the following lines:
  8. Given an array of values between 1 and N, determine if that array has any duplciate values. Do not change the array itself.
  9. Sedgewick 1.4.21 on page 116
  10. Sedgewick 1.4.8 on page 114 (if you know the name of what is computed, say so, but it's not necessary: you can just describe the sequence)