Presentation on theme: "Working With Algorithm and Flowcharts"— Presentation transcript:
1Working With Algorithm and Flowcharts Understanding their practicality
2What 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.
3Design of an AlgorithmThe 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 properlyTop-down design approach is often used.
4How 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 portionsWe use flow charts to show how the algorithm will work.
5Let’s take a look at an algorithm Image you had to program a robot to make coffee.
6A Simple Algorithm : Making Coffee 1 Boil water2 Put coffee
7A Simple Algorithm : Making Coffee OriginalFirst Refinement1 Boil water2 Put coffee1.1 fill kettle1.2 switch kettle on1.3 wait until boiling1.4 switch off kettle2.1 open coffee jar2.2 Fill spoon with coffee2.3 tip spoonful into cup2.4 close coffee jar
8A Simple Algorithm : Making Coffee OriginalFirst RefinementSecond Refinement1 Boil water2 Put coffee1.1 fill kettle1.2 switch kettle on1.3 wait until boiling1.4 switch off kettle2.1 open coffee jar2.2 Fill spoon with coffee2.3 tip spoonful into cup2.4 close coffee jar1.1.1 put kettle undertap1.1.2 turn on tap1.1.3 wait till kettle is full1.1.4 turn off tap2.1.1 take coffee jar from shelf2.1.2 remove lid2.4.1 put lid on coffee jar2.4.2 replace coffee jar on shelf
9Selection (Decision Statement) An algorithm which is solely a sequence of steps is extremely inflexibleA ‘What if …? Then’ Statement allows for this flexibility.What if the coffee jar is empty?Then get a new jar.
10Iteration (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 coffeeContinue filling coffee jar until jar is found.
11What Is a Flowchart? A diagrammatic representation of a program Building a flowchart is like putting a puzzle together; there are standard piecesThe standard action shapes include terminal, process, in/output, decision and junction.
12What Are the Basic Symbols? A program should always begin with a start symbol and finish symbolFor Pascal it equals the begin and the endStartEnd
13What Are the Basic Symbols? Is mark> 50?yesWhenever a decision must be taken a diamond symbol is used.Can you see the correlation to the if…then…else… statements.noDecision/ Comparison Operation
14What Are the Basic Symbols? Used to connect different parts of the program together.Connector
15What Are the Basic Symbols? A rectangle represents a process.When a variable must be assigned to a value, a process must be usedWhen clearing the screen, changing colour a rectangle must be usedmark := 0Process to be performed
16What 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 userShow result to userInput /OutputOperation
17Let’s Put the Pieces Together! ExampleYou are going to school, how will you get there?