Fundamentals of Computer Science I (CS151.01 2006F)
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2006F (Davis)]
[CSCS151 2005S (Stone)]
[CSC151 2003F (Rebelsky)]
[CSC153 2004S (Rebelsky)]
This homework assignment is also available in PDF.
Assigned: Tuesday, 14 November 2006
Due: Friday, 17 November 2006
No extensions!
Summary: In this assignment, you will explore another sorting algorithm, selection sort.
Purpose: To help you think more about sorting.
Expected Time: One to two hours.
Collaboration: You may work in a group of any size between one and four, inclusive. You may consult others outside your group, provided you cite those others. You need only submit one assignment per group.
Submitting: Email me your work, using a subject of CSC151 Homework 15.
Warning: So that this exercise is a learning assignment for everyone, I may spend class time publicly critiquing your work.
As you may recall from our inclass discussion of sorting techniques, one popular strategy for sorting vectors involves repeatedly finding the smallest remaining value and then swapping it into the next place in the vector. We call this procedure selection sort because the primary operation is selecting the smallest value.
The process is fairly straightforward. For example, in a vector of 10 elements, selection sort
As that example suggests, a key helper for selection sort is finding the index of the smallest value in a subvector. We might document that procedure as follows:
;;; Procedure: ;;; indexofsmallest ;;; Parameters: ;;; vec, a vector ;;; pos, an integer ;;; mayprecede?, a binary predicate ;;; Purpose: ;;; Find the index of the smallest value in positions [pos..len) of vec. ;;; Produces: ;;; ios, an integer ;;; Preconditions: ;;; mayprecede? is transitive and reflexive. ;;; 0 <= pos < (vectorlength vec). ;;; vec contains no duplicate values. ;;; Postconditions: ;;; For all i, pos <= i < (vectorlength vec), i not equal to ios, ;;; (mayprecede? (vectorref vec ios) (vectorref vec i)).
a. Implement indexofsmallest
.
b. Implement (swap! vec i j)
, a procedure that swaps
the values at positions i
and j
of
vec
.
c. Using indexofsmallest
and swap!
,
implement selectionsort!
. Note that you will probably
want to iterate over the position in the vector.
Sunday, 12 November 2006 [Samuel A. Rebelsky]
Monday, 13 November 2006 [Samuel A. Rebelsky]
indexofsmallest
.
[Skip to Body]
Primary:
[Front Door]
[Syllabus]
[Glance]
[Search]

[Academic Honesty]
[Instructions]
Current:
[Outline]
[EBoard]
[Reading]
[Lab]
[Homework]
Groupings:
[EBoards]
[Examples]
[Exams]
[Handouts]
[Homework]
[Labs]
[Outlines]
[Projects]
[Readings]
Reference:
[Scheme Report (R5RS)]
[Scheme Reference]
[DrScheme Manual]
Related Courses:
[CSC151.02 2006F (Davis)]
[CSCS151 2005S (Stone)]
[CSC151 2003F (Rebelsky)]
[CSC153 2004S (Rebelsky)]
Disclaimer:
I usually create these pages on the fly
, which means that I rarely
proofread them and they may contain bad grammar and incorrect details.
It also means that I tend to update them regularly (see the history for
more details). Feel free to contact me with any suggestions for changes.
This document was generated by
Siteweaver on Thu Nov 30 21:42:54 2006.
The source to the document was last modified on Mon Nov 13 11:23:11 2006.
This document may be found at http://www.cs.grinnell.edu/~rebelsky/Courses/CS151/2006F/Homework/hw.15.html
.
You may wish to validate this document's HTML ; ;
Samuel A. Rebelsky, rebelsky@grinnell.eduhttp://creativecommons.org/licenses/bync/2.5/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.