# A04 - Assignment 4 Algorithms Counting Complexity and Interfaces CSci 1001 Spring 2010 10 March 2009 Due date Due in hardcopy at the beginning of

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

Assignment 4: Algorithms, Counting, Complexity, and Interfaces CSci 1001, Spring 2010 10 March 2009 Due date: Due in hardcopy at the beginning of class on Wednesday March 31, 2010. See the “assignment rules” ﬁle on the class “Assignments” web page for assignment rules. Do each of the following problems. You will probably need a calculator for many of them. Use scientiﬁc notation for large numbers, e.g., 6 . 02 × 10 23 . Show your work! Answers that do not show intermediate steps will not receive full credit. The point of the homework is for you to understand a process, and to apply the process to ﬁnd the right answer. If you do not show your work, we cannot tell if you understood the process. Also, we use the work to diagnose mistakes and award partial credit if you get wrong answers. 1 Writing Good Algorithms Problem 1.1 (5 points) Is the following algorithm correct? (Does it do what is in- tended? Does it do what is intended correctly ?) If not, what is wrong and how can it be ﬁxed? This algorithm is designed as a variation on Gauss’ algorithm (see p. 81 of your texxt- book). It adds up the multiples of ﬁve from 5 to 100. GaussVariation ± Input: None. ± Output: sum of the multiples of ﬁve from 5 to 100 1 Set the value of sum to 0 2 Set the value of x to 1 3 while x 100 4 Add x to sum 5 Add 5 to x 6 Print sum 7 Stop 1

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

View Full Document
Here is another algorithm that attempts to add all multiples of ﬁve from 5 to 100. GaussVariation2 ± Input: None. ± Output: sum of the multiples of ﬁve from 5 to 100 1 sum = (100/10)*105 2 Print sum 3 Stop Problem 1.2 (5 points) Which of the two algorithms is more elegant? In which is the intended outcome clear? Problem 1.3 (10 points)
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/28/2010 for the course CSCI 1001 taught by Professor Staff during the Spring '08 term at Minnesota.

### Page1 / 6

A04 - Assignment 4 Algorithms Counting Complexity and Interfaces CSci 1001 Spring 2010 10 March 2009 Due date Due in hardcopy at the beginning of

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

View Full Document
Ask a homework question - tutors are online