finalspring2006 - Final CS100J, Spring 2006 NAME NET ID...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 post-conditions. 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...
View Full Document

This note was uploaded on 06/01/2008 for the course CS 100 taught by Professor Fan/vanloan during the Fall '07 term at Cornell University (Engineering School).

Page1 / 9

finalspring2006 - Final CS100J, Spring 2006 NAME NET ID...

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

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