the algorithmic model. what is computer science what is programming algorithms –definition...

16
The Algorithmic Model

Upload: warren-craig

Post on 01-Jan-2016

217 views

Category:

Documents


1 download

TRANSCRIPT

The Algorithmic Model

The Algorithmic Model• What is Computer Science• What is Programming• Algorithms

– Definition– Properties of Good Algorithms– Describing Algorithms– Examples– Components of Algorithms

What is Programming

• Programming requires two skills:– Algorithmic thinking

– Knowledge of programming language syntax

• Learning language syntax is the easy part

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

Algorithm Defined• A set of logical steps to accomplish

a task• A “recipe of action”• A way of describing behavior

Algorithms contain:• Data• Instructions

Algorithms in Computing

Input Data

Algorithm

Output Data

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”

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)

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

What’s Wrong With This Algorithm?

(From back of shampoo bottle)

Directions: Wet Hair Apply a small amount of shampoo Lather Rinse Repeat

Properties of Good Algorithms

Good algorithms are• Precise• Unambiguous• Complete• Correct• Simple• Contain levels of abstraction

Describing Algorithms• Natural language (English)

• Pictures

• Pseudo-code or a specific programming language

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.

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

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

FIN