The Algorithmic Model
-
Upload
isadora-watson -
Category
Documents
-
view
32 -
download
0
description
Transcript of The Algorithmic Model
![Page 1: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/1.jpg)
The Algorithmic Model
![Page 2: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/2.jpg)
The Algorithmic Model• What is Computer Science• What is Programming• Algorithms
– Definition– Properties of Good Algorithms– Describing Algorithms– Examples– Components of Algorithms
![Page 3: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/3.jpg)
What is Programming
• Programming requires two skills:– Algorithmic thinking
– Knowledge of programming language syntax
• Learning language syntax is the easy part
![Page 4: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/4.jpg)
How We Learn Computer Science• We use pseudo-code to focus on learning
algorithmic thinking• From there, you can go anywhere!• Not using a computer to compile and run
your program forces you to mentally execute your program and debug it!
• Too many programmers try to program by brute force and twiddling
![Page 5: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/5.jpg)
Algorithm Defined• A set of logical steps to accomplish
a task• A “recipe of action”• A way of describing behavior
Algorithms contain:• Data• Instructions
![Page 6: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/6.jpg)
Algorithms in Computing
Input Data
Algorithm
Output Data
![Page 7: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/7.jpg)
Chocolate Chip Cookies DATA (ingredients) 2 1/4 cups flour 1 tsp salt 1 tsp baking soda 2 eggs 3/4 cup brown sugar 1 tsp vanilla ext. 3/4 cup gran’d sugar 1 cup soft butter 12oz. semi-sweet chocolate chips
INSTRUCTIONS (steps) Preheat oven to 375°. Combine flour, salt, baking soda, in bowl, set mixture aside. Combine sugars, butter, vanilla, beat until creamy. Add eggs and beat. Add dry mixture and mix well. Stir in chocolate chips Drop mixture by teaspoons onto ungreased cookie sheet Bake 8 to 10 minutes
Algorithm “Recipe”
![Page 8: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/8.jpg)
Abstraction1. a general idea or term2. an impractical idea; visionary and unrealistic3. general characteristics apart from concrete
realities, specific objects or actual instances 4. withdrawal 5. absent-mindedness; inattention6. a work of art stressing formal relationships
In Computer Science:•Abstraction refers to the LOGICAL GROUPING of concepts or objects•Define/implement the general idea, isolate the details
(Random House Dictionary of the English Language)
![Page 9: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/9.jpg)
Abstraction in AlgorithmsThe Abstraction: Get to Clayton State IT Dept. from Atlanta
One Implementation:begin get on I-75 heading south exit I-75 onto exit 234 turn left turn right on Clayton State Bvd. hit duck park in front of IT Dept. walk into front doorend
Other implementations of the same abstraction can be just as correct, better, or worse
![Page 10: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/10.jpg)
What’s Wrong With This Algorithm?
(From back of shampoo bottle)
Directions: Wet Hair Apply a small amount of shampoo Lather Rinse Repeat
![Page 11: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/11.jpg)
Properties of Good Algorithms
Good algorithms are• Precise• Unambiguous• Complete• Correct• Simple• Contain levels of abstraction
![Page 12: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/12.jpg)
Describing Algorithms• Natural language (English)
• Pictures
• Pseudo-code or a specific programming language
![Page 13: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/13.jpg)
1. Make a list of courses you want to register for, in order of priority
2. Start with empty schedule. Number of hours = 0.3. Choose highest priority class on list.4. If the chosen class is not full and its class time
does not conflict with classes already scheduled, then register for the class: 4.a. Add the class to the schedule4.b. Add the class hours to the number of hours
scheduled5. Cross that class off of your list.6. Repeat steps 3 through 5 until the number of
hours scheduled is >= 15, or until all classes have been crossed out.
7. Stop.
![Page 14: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/14.jpg)
End
Flowcharts Begin
Make list of classes you want to take
Num Hours = 0
Choose highest priority class on list
Add the class to your schedule. Add class hours to Num Hours.
Cross the class off your list.
yes
yes
yes
no
no
no
Is this class full?
Is there a time conflict?
Num Hours >= 15?
More classes on list?yes
no
![Page 15: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/15.jpg)
Components of AlgorithmsAny computing algorithm will have AT
MOST five kinds of components:
• Data structures to hold data• Instructions change data values• Conditional expressions to make
decisions• Control structures to act on decisions• Modules to make the algorithm
manageable by abstraction, i.e., grouping related components
![Page 16: The Algorithmic Model](https://reader036.fdocuments.net/reader036/viewer/2022062422/56813623550346895d9d982e/html5/thumbnails/16.jpg)
FIN