Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithm & Flowchart.

Similar presentations


Presentation on theme: "Algorithm & Flowchart."— Presentation transcript:

1 Algorithm & Flowchart

2 An informal definition of an algorithm is:
Algorithm: a step-by-step method for solving a problem or doing a task. Figure 8.1 Informal definition of an algorithm used in a computer

3 Algorithm A step-by-step problem-solving procedure
An algorithm is a sequence of unambiguous instructions for solving a problem. The number of steps of an algorithm will be countable and finite. It is a sequence of instructions (or set of instructions) to make a program more readable; a process used to answer a question.

4 Develop an algorithm/method of solution
Understand the problem. Define the problem Analyze the problem Develop an algorithm/method of solution Write a computer program corresponding to the algorithm Test and debug the program Document the program (how it works and how to use it)

5 There are two commonly used tools to help to document program logic (the algorithm). These are :
Flowcharts Pseudo code.

6 Flowchart A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds and their order by connecting these with arrows. This diagrammatic representation can give a step-by-step solution to a given problem.

7 Process operations are represented in these boxes, and arrows connecting them represent flow of control. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.

8 Symbols Start and end symbols, represented as lozenges, ovals or rounded rectangles, usually containing the word "Start" or "End", or another phrase signaling the start or end of a process, such as "submit enquiry" or "receive product". Arrows, showing what's called "flow of control" in computer science. An arrow coming from one symbol and ending at another symbol signifies flow passes to the symbol the arrow points to. Processing steps, represented as rectangles. Examples: "Add 1 to X"; "replace identified part"; "save changes" or similar. Input/Output, represented as a parallelogram. Examples: Get X from the user; display X. Conditional (or decision), represented as a diamond (rhombus). These typically contain a Yes/No question or True/False test .

9 Start or end of the program
Computational steps or processing function of a program Input or output operation Decision making and branching Connector or joining of two parts of program

10 1- Simple sequential Flowchart
• Example 1: - Read X, Y, Z Compute Sum (S) as X + Y +Z Compute Average (A) as S / 3 Compute Product (P) as X xYxZ - Write (Display) the Sum,Average and Product

11 • Example 2: Find the sum of two numbers
• Example 2: Find the sum of two numbers. – Variables: • A: First Number • B: Second Number • C: Sum (A+B) – Algorithm: • Step 1 – Start • Step 2 – Input A • Step 3 – Input B • Step 4 – Calculate C = A + B • Step 5 – Output C • Step 6 – Stop

12

13 • Example 3: Find the difference and the division of two numbers and display the result

14

15 • Example 4: Find the circle area and circumcenter of a circle where R (radius) is given (exercise) – Variables: • R: Radius • A: Area •C: Circumcenter – Algorithm: • Step 1 – Start • Step 2 – Input R • Step 3 – Calculate Pi • Step 4 – Calculate A = Pi(R)2 • Step 5 – Calculate C = 2Pi(R) • Step 6 – Print R, A, C • Step 7– Stop

16 • Example 1: 2- Branched Flowcharts
Draw a flowchart that shows the traffic light processing (exercise) – Algorithm: • Step 1 – Start • Step 2 – make a Decision (what is the color) • Step 3 – if the color is Red then STOP • Step 4 – if the color is Yellow then WAIT • Step 5 – if the color is Green then PASS • Step 6– Stop

17 3- Loop Flowcharts • Example 1:

18 • Example 2 Average for 10 numbers


Download ppt "Algorithm & Flowchart."

Similar presentations


Ads by Google