The document defines algorithms and flowcharts. An algorithm is a set of steps to solve a problem from input to output. Flowcharts can visually represent algorithms using standard symbols like rectangles for processes and diamonds for decisions. Common algorithm types are sequences of steps, branching based on conditions, and loops for repetition. Examples show algorithms to find sums, greater numbers, even numbers between ranges, and odd numbers less than or equal to a given input. Flowcharts effectively communicate logic, analyze problems, document programs, aid maintenance, and support coding.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
180 views
Algorithm AND Flowcharts
The document defines algorithms and flowcharts. An algorithm is a set of steps to solve a problem from input to output. Flowcharts can visually represent algorithms using standard symbols like rectangles for processes and diamonds for decisions. Common algorithm types are sequences of steps, branching based on conditions, and loops for repetition. Examples show algorithms to find sums, greater numbers, even numbers between ranges, and odd numbers less than or equal to a given input. Flowcharts effectively communicate logic, analyze problems, document programs, aid maintenance, and support coding.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17
ALGORITHM
AND FLOWCHARTS DEFINING ALGORITHM
Algorithm can be defined as: “A sequence of activities
to be processed for getting desired output from a given input.” Webopedia defines an algorithm as: “A formula or set of steps for solving a particular problem. To be an algorithm, a set of rules must be unambiguous and have a clear stopping point”. There may be more than one way to solve a problem, so there may be more than one algorithm for a problem. SYMBOLS FOR DIFFERENT OPERATIONS USED IN ALGORITHM ‘+’ for Addition ‘-’ for Subtraction ‘*’ for Multiplication ‘/’ for Division ‘ ’ for assignment. For example A X*3 means A will have a value of X*3. TYPE OF ALGORITHMS The algorithm and flowchart, classification to the three types of control structures. 1. Sequence The sequence is exemplified by sequence of statements place one after the other – the one above or before another gets executed first. In flowcharts, sequence of statements is usually contained in the rectangular process box. EXAMPLES OF ALGORITHM Problem1: Write an algorithm to read two numbers and find their sum. Inputs to the algorithm: First num1. Second num2. Expected output: Sum of the two numbers. Algorithm: Step1: Start Step2: Read\iput the first num1. Step3: Read\input the second num2. Step4: Sum num1+num2 // calculation of sum Step5: Print Sum Step6: End EXAMPLES OF ALGORITHM Problem 1: Find the area of a Circle of radius r. Inputs to the algorithm: Radius r of the Circle. Expected output: Area of the Circle Algorithm: Step1: Read\input the Radius r of the Circle Step2: Area PI*r*r // calculation of area Step3: Print Area Step4: End TYPES OF ALGORITHM 2. Branching (Selection) The branch refers to a binary decision based on some condition. If the condition is true, one of the two branches is explored; if the condition is false, the other alternative is taken. This is usually represented by the ‘if- then’ construct in pseudo-codes and programs. In flowcharts, this is represented by the diamond-shaped decision box. Problem1: write algorithm to find the greater number between two numbers Step1: Start Step2: Read/input A and B Step3: If A greater than B then C=A Step4: if B greater than A then C=B Step5: Print C Step6: End Problem2: write algorithm to find the result of equation: ( ) Step1: Start Step2: Read/input x Step3: If X Less than zero then F=-X Step4: if X greater than or equal zero then F=X Step5: Print F Step6: End TYPES OF ALGORITHM 3. Loop (Repetition) The loop allows a statement or a sequence of statements to be repeatedly executed based on some loop condition. It is represented by the ‘while’ and ‘for’ constructs in most programming languages, for unbounded loops and bounded loops respectively. Problem1: An algorithm to calculate even numbers between 0 and 99 1. Start 2. I ← 0 3. Write I in standard output 4. I ← I+2 5. If (I <=98) then go to line 3 6. End Problem2: Design an algorithm which gets a natural value, n,as its input and calculates odd numbers equal or less than n. Then write them in the standard output: 1. Start 2. Read n 3. I ← 1 4. Write I 5. I ← I + 2 6. If ( I <= n) then go to line 4 7. End • The flowchart is a diagram which visually presents the flow of data through processing systems. This means by seeing a flow chart one can know the operations performed and the sequence of these operations in a system. Algorithms are nothing but sequence of steps for solving problems. So a flow chart can be used for representing an algorithm. There are 6 basic symbols commonly used in flowcharting of assembly language Programs: Terminal, Process, input/output, Decision, Connector and Predefined Process. 1. All boxes of the flowchart are connected with Arrows. (Not lines) 2. Flowchart symbols have an entry point on the top of the symbol with no other entry points. The exit point for all flowchart symbols is on the bottom except for the Decision symbol. 3. The Decision symbol has two exit points; these can be on the sides or the bottom and one side. 4. Generally a flowchart will flow from top to bottom. However, an upward flow can be shown as long as it does not exceed 3 symbols. 5. Connectors are used to connect breaks in the flowchart. Examples are: • From one page to another page. • From the bottom of the page to the top of the same page. • An upward flow of more then 3 symbols 6. Subroutines and Interrupt programs have their own and independent flowcharts. 7. All flow charts start with a Terminal or Predefined Process (for interrupt programs or subroutines) symbol. 8. All flowcharts end with a terminal or a contentious loop. • 1) Communication: A Flowchart can be used as a better way of communication of the logic of a system and steps involve in the solution, to all concerned particularly to the client of system. 2) Effective analysis: A flowchart of a problem can be used for effective analysis of the problem. 3) Documentation of Program/System: Program flowcharts are a vital part of a good program documentation. Program document is used for various purposes like knowing the components in the program, complexity of the program etc. 4) Efficient Program Maintenance: Once a program is developed and becomes operational it needs time to time maintenance. With help of flowchart maintenance become easier. 5) Coding of the Program: Any design of solution of a problem is finally converted into computer program. Writing code referring the flowchart of the solution become easy.
(Ebook) Linear Algebra and Its Applications by Lax, Peter D ISBN 9780471751564, 9781118626924, 0471751561, 1118626923 - Quickly download the ebook to read anytime, anywhere