algorithms cs280 – 10/20/05. announcement part 1 of project 2 due. read chapters 10, 7 for this...
DESCRIPTION
What is an algorithm?TRANSCRIPT
![Page 1: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/1.jpg)
AlgorithmsCS280 – 10/20/05
![Page 2: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/2.jpg)
Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom
We will be doing a little more with algorithms We will also be doing some history. Be prepared
to talk about your topic from project 1.
![Page 3: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/3.jpg)
What is an algorithm?
![Page 4: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/4.jpg)
Problem SolvingYour roommate, who is taking CS280, is in a
panic. He knows his grades from each of his classes, but doesn’t know how to calculate his semester GPA. He wants to be able to warn his parents before the official grades come out.
How can he figure out his GPA?How can you build a process that any student
can use to calculate their GPA at any time?
![Page 5: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/5.jpg)
Algorithm Development Objectives At the end of this unit the student will:
define the term algorithm state the 5 properties of a good algorithm from a given problem and stated audience, create
an appropriate algorithm using the properties stated above.
use the concept of abstraction and top-down design in creating an algorithm.
begin to think about the kinds of problems that have a computing solution.
![Page 6: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/6.jpg)
Problem Solving - Polya1. Understand the problem (and the audience)
1. Are you making a pie?2. Needing directions?3. Putting together a piece of equipment?4. Trying to solve a mathematical puzzle?
2. Devise a plan1. Is this similar to something else?2. Who is the audience for the solution?3. What are the required steps?
![Page 7: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/7.jpg)
3. Carry out the plan (implement)1. Does it work?2. Is each step correct? Necessary?
4. Is the solution accurate? (Correct)1. Will it always lead to a solution
![Page 8: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/8.jpg)
Algorithm Definition A logical sequence of steps for solving a
problem, … From http://Dictionary.msn.com
Dale and Lewis: a plan of solution for a problem Algorithm – An unambiguous (and precise) set of steps
for solving a problem (or sub-problem) in a finite amount of time using a finite amount of data.
![Page 9: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/9.jpg)
Algorithm Definition, cont Shackelford, Russell L. in Introduction to
Computing and Algorithms – “An algorithm is a specification of a behavioral
process. It consists of a finite set of instructions that govern behavior step-by-step.”
![Page 10: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/10.jpg)
Notice Notice the term finite. Algorithms should
lead to an eventual solution. Step by step process. Each step should do
one logical action.
![Page 11: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/11.jpg)
Algorithms Algorithms are addressed to some audience.
Consider: A set of instructions for building a child’s bicycle. A diagnostic checklist for a failure of some system on the
space shuttle. The algorithm for what to do when a nuclear reactor
begins to overheat. An algorithm that will run on a computer system to
calculate student GPA’s.
![Page 12: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/12.jpg)
Audience Each audience will have its own “rules” that
govern how we will address them, the language that they speak.
Each audience will have certain assumptions about what they know and don’t know.
An audience might include people or a computer.
![Page 13: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/13.jpg)
Good vs. Bad Algorithms All algorithms will have input, perform a
process, and produce output. A good algorithm should be:
Precise Simple - relative Correct (Right) Completeand should have appropriate levels of Abstraction. –
grouping steps into a single module Mnemonic - SCRAP
![Page 14: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/14.jpg)
Precision Precision means that there is only one way to
interpret the instruction. Unambiguous Words like “maybe”, “sometimes” and
“occasionally” have no business in a well developed algorithm.
Instead of “maybe”, we can specify the exact circumstances in which an action will be carried out.
![Page 15: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/15.jpg)
Simplicity Simple can be defined as having no
unnecessary steps and no unnecessary complexity.
Each step of a well developed algorithm should carry out one logical step of the process.
![Page 16: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/16.jpg)
It has Levels of Abstraction. From the Oxford English Dictionary,
abstraction is defined as: “The act or process of separating in thought, of
considering a thing independently of its associations; or a substance independently of its attributes; or an attribute or quality independently of the substance to which it belongs.”
![Page 17: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/17.jpg)
Or in other words The abstraction property lets us view an
algorithm as a series of high level aggregate steps, with the detail hidden in a lower level.
![Page 18: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/18.jpg)
Abstraction, cont. Instead of approaching a problem and worrying
about each and every thing you must do to solve the problem, you can begin to look at the major steps. (Top down design)
After the major steps, you can begin to fill in how you would accomplish the major step.
That fill in may lead to the need for additional levels to fill in those details, etc.
Top down design.
![Page 19: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/19.jpg)
Diagrammatically
Drive the car to
school
Get directions
Start the car
Follow the directions
Get parking pass
Drive to the destination
Turn left out of your driveway
At the next light, turn right.
At the intersection with I-66, take the on-ramp for
I-66 West
…Level 1
Level 2
Level 3Find a place to park
Stop the car
![Page 20: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/20.jpg)
Other algorithm attributes A good algorithm should be correct. A good algorithm should be complete. Shackelford again, “To be correct, an
algorithm must produce results that are correct and complete given any and all sets of appropriate data.”
And to be correct, an algorithm must proceed through to a conclusion.
![Page 21: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/21.jpg)
Figure 6.3: The Interactions Between Problem-Solving Phases
From Dale and Lewis website.
![Page 22: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/22.jpg)
Steps from Schaum’s Analyze the problem and develop the specification. Design the solution
Test the solution as part of the design steps. Implement the program (code the program) Test the program Validate the program (further extensive testing) to
insure it works under all circumstances.
![Page 23: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/23.jpg)
For the following exercise, you may use a calculator.
![Page 24: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/24.jpg)
In class exercise In your group, create an algorithm to calculate a
semester GPA. Recall:
GPA is based on the letter grade achieved in the class and the number of credit hours for the class.
Generally QP’s – A = 4.0, B = 3.0, C=2.0, D=1.0, F=0.0 and a + adds .3 to the grade and a – subtracts .3 from the QP.
The semester GPA is then the average QP for each credit hour attempted.
![Page 25: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/25.jpg)
For example: For example, a student is taking 4 classes:
CS139 – 4 credits – C CS110 – 1 credit – A GWRIT103 – 3 credits – B+ GHIST101 – 3 credits – C-
What is the student’s semester average? How did you figure it out? How can you describe that process for others in the
class?
![Page 26: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/26.jpg)
Now trade papers with another group
![Page 27: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/27.jpg)
Look at the GPA calculation algorithm What properties does the testing algorithm display?
Is is simple, precise, etc. Test the solution using a couple of different test
cases. Does the algorithm work for those different cases?
What happens if the grades are all F’s? All A’s (limits)?
What about different numbers of classes? One or 6?
![Page 28: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/28.jpg)
Other considerations What is the input to the algorithm?
How will you obtain that input? What is the nature of the input? (numbers,
physical objects, verbal communication) What is to be output?
Who gets the output? What is the nature of the output?
How do you get from input to output?
![Page 29: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/29.jpg)
Some other algorithms Create an algorithm for making a sandwich
(pick your favorite). Create an algorithm for calculating your grade
for this class. Create an algorithm for sorting a deck of cards
to find the value of the missing card. Create an algorithm for making a paper
airplane.
![Page 30: Algorithms CS280 – 10/20/05. Announcement Part 1 of project 2 due. Read chapters 10, 7 for this unit Tuesday we will also be in the classroom We](https://reader035.vdocuments.site/reader035/viewer/2022062412/5a4d1af97f8b9ab059983330/html5/thumbnails/30.jpg)
Testing and Debugging Testing is the process of exercising an
algorithm (or program) to determine if there are flaws and where those flaws are.
Debugging is the process of removing those flaws.
You test and debug as part of your everyday existence.