24
Flow chart and Algorithm

Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Embed Size (px)

Citation preview

Page 1: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Flow chart and Algorithm

Page 2: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Announcement

Exam One– Wednesday October 1st– 100 points– Mixture of short answer, problem solving, matching,

and maybe a multiple choice question Monday class will be held as a review session.

Page 3: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Exam Next Wednesday

History of Computers Hardware – inside and outside Software – Microsoft Word, Excel Spread sheet and data Operating Systems and Computer Security Pirates of Silicon Valley Writing Lab Reports Binary Mathematics Flowcharts and Algorithms

Page 4: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Today’s Topics

Algorithms Flowcharts Pseudo code

Page 5: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Problem Solving

For the rest of the semester, we will practice problem-solving. If you learn nothing else from this class, I would like you to learn to take a good approach to problem solving

Page 6: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Algorithms

To solve a problem, you got to figure out how to solve it by yourself.

To make a computer solve a problem, you need to you have to tell the computer, step by step, exactly what you want it to do.

The computer then "executes" the program, following each step mechanically, to accomplish the end goal.

Algorithm: Sequence of step-by-step instructions that will produce a solution to a problem

Page 7: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Four algorithms

The taxi algorithm: – Go to the taxi stand. – Get in a taxi. – Give the driver my

address. The call-me algorithm:

– When your plane arrives, call my cell phone.

– Meet me outside baggage claim.

The rent-a-car algorithm: – Take the shuttle to the rental

car place. – Rent a car. – Follow the directions to get to

my house. The bus algorithm:

– Outside baggage claim, catch bus number 70.

– Transfer to bus 14 on Main Street.

– Get off on Grand River Ave. – Walk two blocks north to my

house.

Page 8: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Problem to Solve

What steps would you propose to solve the following problem?– You are dirty and want to clean up– Solution: Take a shower

What are the steps?

Page 9: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Example of Algorithm

Take clothes off Turn on water Step into shower Wash face Wash body Shampoo hair Turn water off Dry off Get dressed

Problem:You are dirty

Solution:Take a shower

How:Take a ShowerAlgorithm

Take a Shower Algorithm

Page 10: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Sequence of Steps

Fairly regular order of events– must take clothes off first– cannot dry off before washing

Cannot skip steps to complete job Result oriented Termination of algorithm after result

Page 11: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Algorithm Example

Define the algorithm for mailing a letter, from obtaining the envelope to placing it in the mailbox

Page 12: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Mailing a Letter

Obtain Envelope If letter is too big, fold letter Place letter in envelope Address Envelope Seal envelope Obtain stamp Affix stamp Place in mailbox

Page 13: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Flowcharts

Flowcharts are graphical and verbal illustrations of algorithms

Flowcharts are useful in describing any step-by-step procedure

Flowcharts make it easier to create programming code

Page 14: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Flowchart Elements

read x

print y

x = y * x

begin

if x > 0

start, end

input

output

computation

comparisonor decision

Specific shapes have specific roles in a flowchart ...

T

F

DoAssignment

#5

Pre-defined process, usually complex

Page 15: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Flowcharts

obtainenvelope

Is letterbigger thanenvelope?

yes

fold letter

insert intoenvelope

no

address envelope

affix stamp

place inmailbox

obtain stamp

end

start

sealenvelope

raise flag

Page 16: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Flowchart Checklist

All major elements of the algorithm are indicated.

The elements are clearly labeled. Sequence of elements is clear and there are

no gaps or dead ends. Sequence of elements is logical from user's

point of view. Flowchart symbols are used correctly.

Page 17: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Decimal number to binary number:

Page 18: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Decimal number to binary number

Start Get a number

Divide the Number

By 2

Is the quotient Equal to 1?

PrintThe Remainto the left of

previous remains

No

Print 1To the left of

Previous remains

End Yes

Page 19: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Pseudo code

Flow chart in a text form. More like a computer program, but with human

language. Can be easily translated into computer

languages.

Page 20: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Elements of pseudo code

IF condition is true THEN

Process step (1)

ELSE

Process step (2)

GOTO– Unconditional jump

If conditionIs true

Process Step (1)

ProcessStep (2)

Page 21: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Example: Binary2Decimal

1. Get a number2. IF the number is equal to 1 or 0

Print the number; END

3. Divide the number by 24. IF quotient is 1 THEN

Print 1 to the left of the previous remains

5. ELSEPrint the remain to the left of previous remains. GOTO 3

6. END

Page 22: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Binary-ASCII conversion

Each letter is represented by an 8-bit binary number, called ASCII (American Standard Code for Information Interchange. )

Binary to Base Ten Base Ten to ASCII Details?

Page 23: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Steps in Binary-ASCII

Input number Break number up into eight bits Compute base two values for each bit Sum base two values to get base ten value Using base ten number, look in ASCII chart Output ASCII character Is there another number? Repeat procedure

Page 24: Flow chart and Algorithm. Announcement Exam One – Wednesday October 1st – 100 points – Mixture of short answer, problem solving, matching, and maybe a

Pre-lab Assignment

Using the steps of the Binary-ASCII conversion, create a flowchart, using the proper shapes, arrows, etc.

In Friday’s Lab we will use Powerpoint to create flow chart.