Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working With Algorithm and Flowcharts

Similar presentations


Presentation on theme: "Working With Algorithm and Flowcharts"— Presentation transcript:

1 Working With Algorithm and Flowcharts
Understanding their practicality

2 What is an Algorithm? It is a finite set of rules giving a sequence of operations for solving a specific type of problem. In most common computer applications an algorithmic solution to a problem must be constructed.

3 Design of an Algorithm The design of an algorithm tends to be difficult when the task is non-trivial. Computers tend to lack the intuition or ‘common sense’ to realise the full procedure. The designer must describe the procedure very precisely for it to function properly Top-down design approach is often used.

4 How does the top-down method work?
First try to break the process into a number of steps, which are smaller and simpler than that for the entire process. The sub-algorithms can themselves be broken down into smaller portions We use flow charts to show how the algorithm will work.

5 Let’s take a look at an algorithm Image you had to program a robot to make coffee.

6 A Simple Algorithm : Making Coffee
1 Boil water 2 Put coffee

7 A Simple Algorithm : Making Coffee
Original First Refinement 1 Boil water 2 Put coffee 1.1 fill kettle 1.2 switch kettle on 1.3 wait until boiling 1.4 switch off kettle 2.1 open coffee jar 2.2 Fill spoon with coffee 2.3 tip spoonful into cup 2.4 close coffee jar

8 A Simple Algorithm : Making Coffee
Original First Refinement Second Refinement 1 Boil water 2 Put coffee 1.1 fill kettle 1.2 switch kettle on 1.3 wait until boiling 1.4 switch off kettle 2.1 open coffee jar 2.2 Fill spoon with coffee 2.3 tip spoonful into cup 2.4 close coffee jar 1.1.1 put kettle under tap 1.1.2 turn on tap 1.1.3 wait till kettle is full 1.1.4 turn off tap 2.1.1 take coffee jar from shelf 2.1.2 remove lid 2.4.1 put lid on coffee jar 2.4.2 replace coffee jar on shelf

9 Selection (Decision Statement)
An algorithm which is solely a sequence of steps is extremely inflexible A ‘What if …? Then’ Statement allows for this flexibility. What if the coffee jar is empty? Then get a new jar.

10 Iteration (Repetition or Loop)
Sometimes it is necessary for the computer not just to make a decision, but a continuous action. This processes is called iteration. Example : With the robot making the coffee Continue filling coffee jar until jar is found.

11 What Is a Flowchart? A diagrammatic representation of a program
Building a flowchart is like putting a puzzle together; there are standard pieces The standard action shapes include terminal, process, in/output, decision and junction.

12 What Are the Basic Symbols?
A program should always begin with a start symbol and finish symbol For Pascal it equals the begin and the end Start End

13 What Are the Basic Symbols?
Is mark > 50? yes Whenever a decision must be taken a diamond symbol is used. Can you see the correlation to the if…then…else… statements. no Decision/ Comparison Operation

14 What Are the Basic Symbols?
Used to connect different parts of the program together. Connector

15 What Are the Basic Symbols?
A rectangle represents a process. When a variable must be assigned to a value, a process must be used When clearing the screen, changing colour a rectangle must be used mark := 0 Process to be performed

16 What Are the Basic Symbols?
Input and Output are represented using a parallelogram. In Pascal we are dealing with writeln, write, or readln. Read mark from user Show result to user Input /Output Operation

17 Let’s Put the Pieces Together!
Example You are going to school, how will you get there?

18 Leave the House

19 Leave the House Check the Weather

20 Leave the House Check the Weather Weather Clear?

21 Leave the House Check the Weather Weather Clear? Yes Walk

22 Leave the House Check the Weather Weather Clear? Yes Walk Arrive at School

23 Leave the House Check the Weather No, Rain. Weather Clear? Yes Walk Arrive at School

24 Leave the House Check the Weather No, Rain. Weather Clear? Put on raincoat Yes Walk Arrive at School

25 Leave the House Check the Weather No, Rain. Weather Clear? Put on raincoat Yes Walk Ride Bus Arrive at School

26 Leave the House Check the Weather No, Rain. Weather Clear? Put on raincoat Yes Walk Ride Bus Arrive at School


Download ppt "Working With Algorithm and Flowcharts"

Similar presentations


Ads by Google