1 / 18

Algorithm & Flowchart

Algorithm & Flowchart. 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. Algorithm. A step-by-step problem-solving procedure

waltery
Download Presentation

Algorithm & Flowchart

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. 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. 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

  10. • 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

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

  12. • 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

  13. 2- Branched Flowcharts • Example 1: 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

  14. 3- Loop Flowcharts • Example 1:

  15. • Example 2 Average for 10 numbers

More Related