finalfall2003 - NAME NET ID page 1 Final CS100J 15 Dec 2003...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
NAME _____________________________________ NET ID ______________________ page 1 Final CS100J 15 Dec 2003, 15:00–17:30 Barton Hall HAVE A GOOD BREAK! The results of this Final will be posted on CMS as soon as it is graded. Grades for the course will take several days to create and post to the CMS. Submit regrade requests for the course using CMS where possible (email [email protected] where it is not possible) by noon tomorrow. You have 2.5 hours to complete the questions in this final. The questions are numbered 0. .8. The exam is worth 100 points. Please glance through the whole exam before starting. In answering a question, read it through first. If it has several parts, concentrate on one at a time. Solve any problem in terms of several smaller/simpler problems. You may separate the pages and write on the back of each. We have staplers at the front of the room. Question 0 (1 point). Print your name and net id at the top of each page. Please make them legible. Question 1 (10 points). Algorithms. Write the partition algorithm, which, given a nonempty array segment b[m. .n], permutes its values and stores a value in variable k to truthify the fol- lowing, where x is the initial value in b[m]: Postcondition R: b[m. .k–1] <= x, b[k] = x, b[k+1. .n] >= x DON’T write a method. Just write the statements that perform the task. The algorithm requires ONE loop, whose postcondition is: You are expected to write the loop invariant first and then to develop the loop from the invariant. You can write the invariant as a picture, in English, or in a mixture of English and mathematics. It is up to you. If you have to swap two array elements, for example b[c] and b[d], just say “Swap b[c] and b[d]”. You don’t have to write the Java statements to perform the swap. But all other statements should be in Java. Question 0. _________ (out of 01) Question 1. _________ (out of 10) Question 2. _________ (out of 12) Question 3. _________ (out of 08) Question 4. _________ (out of 09) Question 5. _________ (out of 10) Question 6. _________ (out of 15) Question 7. _________ (out of 20) Question 8. _________ (out of 15) Total ___________ (out of 100) <= x x >= x m k n R: b x <= x >= x m k n R1: b
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
NAME _____________________________________ NET ID ______________________ page 2 Question 2 (12 points). One-dimensional arrays and loops. You know how to add two inte- gers together, as shown in the box to the right. The digits are added from right to left, and at each position there is a carry (could be 0 or 1) from the position to its right. For example, adding the 7 and 6 results in 3 with a carry of 1, which gets added into the next position to the left. Write Java code to perform such addition. Here are the ground rules:
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 9

finalfall2003 - NAME NET ID page 1 Final CS100J 15 Dec 2003...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online