Functional Problem Solving (CSC 151 2016S) : Assignments
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Taking Notes] [Rubric]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Labs] [Outlines] [Readings] - [Examples] [Handouts]
Reference: [Setup] [Remote] [VM] [Errors] - [Functions A-Z] [Functions By Topic] - [Racket] [Scheme Report (R5RS)] [R6RS] [TSPL4]
Related Courses: [Curtsinger (2016S)] [Davis (2013F)] [Rebelsky (2015F)] [Weinman (2014F)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] - [Issue Tracker (Course)]
Due: 10:30 p.m., 2 February 2016
Summary: For this assignment, you will identify the parts of an algorithm, find some problems with that algorithm, and write an improved version.
Purposes: The purpose of this assignment is for you to practice identifying the parts of algorithms, and to get some experience thinking carefully about the edge cases where an algorithm could go wrong.
Collaboration: You must work with your assigned partner(s) on this assignment. You may discuss this assignment with anyone, provided you credit such discussions when you submit the assignment.
Submitting:
Email your answer to <CSC151-02-grader@grinnell.edu>. The title of your
email should have the form CSC 151 Assignment 2: Exploring Algorithms
and should contain your answers to all parts of the assignment.
Scheme code should be in the body of the message.
Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.
In any sufficiently large group of people, the likehood that at least two people have the same birthday is surprisingly high (over 50% for a group of 23 people, source: Wikipedia). While this is an interesting theoretical result, it would be nice to test it in class. The following algorithm is supposed to tell us whether we have any common birthdays in this class, but it has some problems. Use this algorithm for all four parts of the assignment.
Many algorithms can be broken down into smaller steps. For example, this algorithm has two "stages," steps 1-5 and steps 6-9. Explain, in your own words, what each of these stages is supposed to accomplish.
a. What is the purpose of steps 1-5 in the algorithm above?
b. What is the purpose of steps 6-9 in the algorithm above?
The algorithm above uses all six of the parts of an algorithm covered in the Algorithms Reading. Find an example of each piece of an algorithm and list the step(s) that demonstrate that algorithmic building block. Briefly explain your choice.
a. Identify an example of sequencing in the algorithm above. Identify the step(s) that demonstrate this algorithmic building block, and explain your choice.
b. Identify an example of repetition in the algorithm above. Identify the step(s) that demonstrate this algorithmic building block, and explain your choice.
c. Identify an example of a conditional in the algorithm above. Identify the step(s) that demonstrate this algorithmic building block, and explain your choice.
d. Identify an example of a variable in the algorithm above. Identify the step(s) that demonstrate this algorithmic building block, and explain your choice.
e. Identify an example of a parameter in the algorithm above. Identify the step(s) that demonstrate this algorithmic building block, and explain your choice.
f. Identify an example of a subroutine in the algorithm above. Identify the step(s) that demonstrate this algorithmic building block, and explain your choice.
The birthday algorithm provided with this assignment has some problems. Find two problems with the algorithm and explain them below. At least one of the problems you identify should relate to the correctness of the algorithm rather than issues with clarity, efficiency, or precision. When you describe a problem with the algorithm that will cause it to produce an incorrect result, provide an example situation where you would get the wrong answer.
Write a new birthday algorithm that will produce the right answer. Make sure to address the issues you identified in problem 3. Explain why you think your new algorithm will work, and the high level idea behind your approach.
You may recall from your mathematics classes that there is a nice formula for the two roots of the quadratic equation ax2 + bx + c = 0. (If you don't recall, ask a friendly math major.)
Suppose we've defined three variables, a, b,
and c.
> (define a ...) > (define b ...) > (define c ...)
Write instructions for computing the two roots of the corresponding quadratic equation.
> (define root1 ...) > (define root2 ...)
In turning in your assignment, make sure to show a few different examples of your instructions in action. For example,
> (define a 1) > (define b 2) > (define c -3) > (define root1 ...) > (define root2 ...) > root1 -3 > root2 1
We will evaluate your work on the accuracy and level of detail you put into your answers. For problem 1, we expect that you will provided a correct high-level description of each stage, not just a reiteration of the steps in the provided algorithm. For problem 2, you will receive credit for correctly identified parts of the algorithm and the quality of your explanation. For problem 3, we will give credit for real issues that you identify and the example situations that show where the algorithm will go wrong. Finally, for problem 4 we will evaluate your algorithm's correctness, clarity, and the quality of your high-level description.