|
|
|
|
Project 1b is due Monday |
|
Notice that the reading sequence jumps to
Chapter 17 for Monday |
|
|
|
|
Algorithms are a familiar idea. Our goal is to
learn to specify them right so someone or something else does the work |
|
|
|
|
|
|
Algorithm, a precise, systematic method to
produce a specified result |
|
We have seen algorithms already... |
|
Placeholder technique is an algorithm with an
easy specification: |
|
longStringWithShortStringInIt ¬ placeholder |
|
ShortString ¬ e |
|
placeholder ¬ longStringWithShortStringInIt |
|
|
|
|
|
|
For an algorithm to be well specified it must
have … |
|
Inputs specified |
|
Outputs specified |
|
Definiteness |
|
Effectiveness |
|
Finiteness |
|
|
|
|
|
|
A program is an algorithm specialized to a
particular situation |
|
Algorithm: |
|
longStringWithShortStringInIt ¬ placeholder |
|
ShortString ¬ e |
|
placeholder ¬ longStringWithShortStringInIt |
|
Program: ¿¿ ¬ # |
|
¿ ¬ e |
|
# ¬ ¿¿ |
|
|
|
|
|
|
1. Use Artist_of to refer to the name of group |
|
2. Decide which end or the rack is to be the
start of alphabetic sequence, and call the first slot alpha |
|
3. Call the slot next to alpha, beta |
|
4. If Artist_of the CD in the alpha slot is
later in the alphabet than the Artist_of the CD in the beta slot,
interchange the CDs, otherwise continue on |
|
5. If a slot follows the beta slot, begin
calling it the beta slot and go to step 4, otherwise continue on |
|
6. If two slots follow the alpha slot, begin
calling the next one the alpha slot and the one following it the beta slot,
and go to step 4; otherwise stop |
|
|
|
|
|
|
|
We have studied abstraction as a method of
removing an idea or process form a situation … abstract |
|
Beta sweep -- while alpha points to a fixed
slot, beta sweeps through slots following alpha, interchanging as necessary |
|
The beta sweep is a concept removed based on our
understanding of the operation of the algorithm |
|
|
|
|
|
|
|
By abstracting we can analyze parts of an
algorithm … |
|
The beta sweep has 4 properties: |
|
Exhaustive -- it considers all CDs after alpha |
|
Non-redundant -- no slot pair is checked twice |
|
Progressive -- the alphabetically earliest CD
considered so far is always in the alpha slot |
|
Effective -- at completion, the alphabetically
earliest CD from alpha to end is in alpha slot |
|
|
|
|
|
|
The alpha sweep... |
|
Process of sweeping through all of the CDs (but
the last) performing the beta sweep |
|
Exhausitve -- considers all but last CD |
|
Non-redundant -- a slot is alpha only once |
|
Progressive -- when beta sweep completes the
alphabetically next CD in alpha |
|
Complete -- when last beta sweep is done the
last slot’s CD is later than next to last slot |
|
Effective -- the alpha sweep alphabetizes |
|
|
|
|
|
We figure out most algorithms on our own,
abstracting from specific cases |
|
Also we abstract parts of an algorithm or
program to understand them |
|
Thinking of how the program works and reasoning
about properties that it has allows us to know why it works … and then we
can let the computer do it |
|