Sections 0101, 0102, 0103 and Honors, Fall 1995
Tuesday November 14, 1995
Assigned Reading: 11.1 - 11.3
Handouts (available on-line): none
Topics Covered:
- Attendance was taken.
- A program that uses arrays to count the
number of times that a value appears as the outcome of rolling
two six-sided dice.
Sample runs.
- Tested our random number generator
(from October 26 Lecture)
by simulating rolling two six-sided dice 50 times.
Used arrays in this program
to help us plot the histograms.
- We examined
a new version of the sampling
program that allows us to specify the number of trials.
Note that as the number of trials increases, the distribution
of the results of rolling two six-sided dice approaches the
expected distribution. Sample runs.
- We discussed what happens when you pass an array as a parameter
to a function. The main difference between passing an array to
a function and passing a normal variable is that changes made
to the array by the called function changes the array in the
calling function. We looked at a sample
program that exploits this behavior.
Sample run.
- We modified our program that counts the occurrence of letters
in the user's input to report some additional statistics
(minimum, maximum and average). The new
program uses functions that have arrays as parameters.
Sample runs.
- With arrays, we can also sort a list of integers entered
by the user. This program uses
Selection Sort to put the numbers in increasing order.
Sample runs.
- With a sorted list, we can find the location of a number
more efficiently than looking at every entry. This
program uses binary search
to find the location of a number in a sorted list (not shown
in class). In a list
of 63 numbers, we need to examine at most 6 entries to find
the location of any number. If our array had 250 million
entries (approximate population of the United States), we would
only need to examine 38 entries to find the position of any number.
Sample run.
Last Modified:
Thu Nov 16 17:52:01 EST 1995
Richard Chang, chang@gl.umbc.edu