Final CS100J, Spring 2006 NAME NET ID page 1
Grades for the final will be posted on the CMS as soon as it is
graded, hopefully tonight but perhaps tomorrow. Grades for
the course will take a few days more. You can look at your
final when you return in the fall. HAVE A NICE SUMMER!
Please submit all requests for regrades for things other than
the final BY 9PM TONIGHT. Use the CMS where possible;
email Gries otherwise.
You have 2.5 hours to complete the questions in this exam,
which are numbered 0..8. Please glance through the whole
exam before starting. The exam is worth 100 points.
Question 0 (1 point).
Print your name and
net id
at the top of
each page. Please make them legible.
Question 1 (12 points). Loops.
Array segment b[0..k] is al
ready sorted (in ascending order), but it may contain dupli
cates. We want an algorithm that will remove the duplicates,
as indicated by the following pre and postconditions.
For example, for the array b = {1, 2, 2, 2, 4, 4, 4}, execution of the algorithm sets h to 2 (because there
are 3 distinct values) and changes array b to this: b = {1, 2, 4, 2, 4, 4, 4}. The first three values in b are the
elements of the original array b, without duplicates.
Write one loop (with initialization) that performs this task. You need not declare any variables; assume
they are all declared. You
must
use the invariant shown below. You may write your answer on the back
of the next page. Read the invariant carefully before proceeding.
Post:b sorted, contains original b[0..k] this part of b
with duplicates removed is unchanged
Question 0. _________ (out of 01)
Question 1. _________ (out of 12)
Question 2. _________ (out of 12)
Question 3. _________ (out of 12)
Question 4. _________ (out of 08)
Question 5. _________ (out of 12)
Question 6. _________ (out of 16)
Question 7. _________ (out of 17)
Question 8. _________ (out of 10)
Total ___________ (out of 100)
Pre: b sorted
0 k
0 h k
inv: b sorted, contains original b[0..p] this part of b this part of b
with duplicates removed is unchanged is unchanged
0 h p k
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Final CS100J, Spring 2006 NAME NET ID page 2
Question 2 (12 points). Arrays and methods.
Some math formulas, like that for the determinant of a 2
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '07
 FAN/VANLOAN
 Englishlanguage films, MySpace, Friendster, Net ID

Click to edit the document details