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.

- An array of 100 elements is allocated. What is the index of its first element? What is the index of its last element?
- DNA bases are usually denoted as A, T, C, or G. Declare and initialize
a
`String`array that contains those bases. - Write code that populates an array of
`N`elements with a random base for each element. - Take an array of int values and create a copy of that array, with all of the elements reversed in terms of their position.
- 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] }

- Try to write a Sieve of Eratostothenes prime number finder
for primes up to 1000, without looking at an existing solution.
- What role does the array index play?
- What is the type of the array?

- Write a program that tests the randomness of a random number generator
along the following lines:
- Arrange for your code to compute 100,000 random values, but let these be integers between 0 and 99.
- Count how many times each integer is randomly generated.
- Print out your results and see if you believe the random number generator is behaving properly.
- What happens if you run your program a second time?

- Given an array of values between 1 and N, determine if that array has any duplciate values. Do not change the array itself.
- Sedgewick 1.4.21 on page 116
- 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)