🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

**Introduction** Algorithm and flowchart are the powerful tools for learning programming. An algorithm is a step-by-step analysis of the process, while a flowchart explains the steps of a program in a graphical way. Algorithm and flowcharts helps to clarify all the steps for solving the problem. F...

**Introduction** Algorithm and flowchart are the powerful tools for learning programming. An algorithm is a step-by-step analysis of the process, while a flowchart explains the steps of a program in a graphical way. Algorithm and flowcharts helps to clarify all the steps for solving the problem. For beginners, it is always recommended to first write algorithm and draw flowchart for solving a problem and then only write the program. Beginners find it difficult to write algorithm and draw flowchart. The algorithm can vary from person to person to solve a particular problem. These lesson will be useful for the students to learn algorithm and flowchart. It also includes basics of how to interpret and write into psuedocodes, algorithm and flowchart along with number of examples and how these three have different ways of presenting the process of solving a problem. **Learning Outcomes:** 1. 2. 3. 4. 5. **What is a Pseudocode** - Pseudocode is an artificial and informal language that helps programmers develop algorithms. - Pseudocode is a textual description of an algorithm. - It is one of the methods which can be used to represent an algorithm for a program. It does not have a specific syntax like any of the programming languages and thus cannot be executed on a computer. In C, \"sequence statements\" are imperatives. The \"selection\" is the \"if then else\" statement, and the iteration is satisfied by a number of statements, such as the \"while,\" \" do,\" and the \"for,\" while the case-type statement is satisfied by the \"switch\" statement. The rules of Pseudocode are reasonably straightforward. All statements showing \"dependency\" are to be indented. These include while, do, for, if, switch. Examples below will illustrate this notion. **Pseudocode and Flowchart Examples** Example \#1 ![](media/image1.jpeg) Example \#2 **Algorithm** The word "algorithm" relates to the name of the mathematician Al-khowarizmi, which means a procedure or a technique. Software Engineer commonly uses an algorithm for planning and solving the problems. An algorithm is a sequence of steps to solve a particular problem or algorithm is an ordered set of unambiguous steps that produces a result and terminates in a finite time. **Algorithm has the following characteristics** - - - - **The algorithm and flowchart include following three types of control structures.** 1. **Sequence:** In the sequence structure, statements are placed one after the other and the execution takes place starting from up to down. **Branching (Selection)**: In branch control, there is a condition and according to a condition, a decision of either TRUE or FALSE is achieved. In the case of TRUE, 2. one of the two branches is explored; but in the case of FALSE condition, the other alternative is taken. Generally, the 'IF-THEN' is used to represent branch control. 3. **Loop (Repetition):** The Loop or Repetition allows a statement(s) to be executed repeatedly based on certain loop condition e.g. WHILE, FOR loops. **Advantages of algorithm** - It is a step-wise representation of a solution to a given problem, which makes it easy to understand. - An algorithm uses a definite procedure. - It is not dependent on any programming language, so it is easy to understand for anyone even without programming knowledge. - Every step in an algorithm has its own logical sequence so it is easy to debug. **HOW TO WRITE ALGORITHMS** Step 3 **Outline the algorithm\'s operations:** Use input variable for computation purpose, e.g. to find area of rectangle multiply the HEIGHT and WIDTH variable and store the value in new variable (say) AREA. An algorithm\'s operations can take the form of multiple steps and even branch, depending on the value of the input variables. a. g\. to assign value 5 to the variable HEIGHT, statement is HEIGHT \< 5 or HEIGHT = 5 The symbol '=' is used in most of the programming language as an assignment symbol, the same has been used in all the algorithms and flowcharts in the manual. The statement C = A + B means that add the value stored in variable A and variable B then assign/store the value in variable C. The statement R = R + 1 means that add I to the value stored in variable R and then assign/store the new value in variable R, in other words increase the value of variable R by 1 **Mathematical Operators:** *Note: We can use keyword INPUT or READ or GET to accept input(s) /value(s) and keywords PRINT or WRITE or DISPLAY to output the result(s).* ### How to Use Flowcharts to Represent Algorithms Now that we have the definitions of algorithm and flowchart, how do we use a flowchart to represent an algorithm? Algorithms are mainly used for mathematical and computer programs, whilst flowcharts can be used to describe all sorts of processes: business, educational, personal, and algorithms. So flowcharts are often used as a program planning tool to organize the program\'s step-by-step process visually. Here are some examples: Example 1: Print 1 to 20: ![](media/image7.png)**Algorithm** Step 1: Initialize X as 0, Step 2: Increment X by 1, Step 3: Print X, Step 4: If X is less than 20 then go back to step 2. #### Example 2: Convert Temperature from Fahrenheit (℉) to Celsius (℃) **Algorithm Flowchart** Step 1: Read temperature in Fahrenheit, Step 2: Calculate temperature with formula C=5/9\*(F-32), Step 3: Print C, What is an Algorithm ? ---------------------- The word "algorithm" relates to the name of the mathematician Al-khowarizmi, which means a procedure or a technique. Software Engineer commonly uses an algorithm for planning and solving the problems. An algorithm is a sequence of steps to solve a particular problem or algorithm is an ordered set of unambiguous steps that produces a result and terminates in a finite time. ### ![](media/image9.png)Types of Algorithm It is not surprising that algorithms are widely used in computer programming. However, it can be applied to solving mathematical problems and even in everyday life. Here comes a question: how many types of algorithms? According to Dr. Christoph Koutschan, a computer scientist working at the Research Institute for Symbolic Computation (RISC) in Austria, he has surveyed voting for the important types of algorithms. As a result, he has listed 32 crucial algorithms in computer science. Despite the complexity of algorithms, we can generally divide algorithms into six fundamental types based on their function. **1. Recursive Algorithm** **2. Divide and Conquer Algorithm** - - - **3. Dynamic Programming Algorithm** **4. Greedy Algorithm** **5. Brute Force Algorithm** **6. Backtracking Algorithm** Characteristics of an Algorithm ------------------------------- Every Algorithm must satisfy the following properties: 1. **Input**- There should be 0 or more inputs supplied externally to the algorithm. 2. **Output**- There should be at least 1 output obtained. 3. **Definiteness**- Every step of the algorithm should be clear and well defined. 4. **Finiteness**- The algorithm should have finite number of steps. 5. **Correctness**- Every step of the algorithm must generate a correct output. An algorithm is said to be efficient and fast, if it takes less time to execute and consumes less memory space. An algorithm is merely the sequence of steps taken to solve a problem. The steps are normally \"sequence,\" \"selection, \" \"iteration,\" and a case-type statement. 1. **Advantages of algorithm** It is a step-wise representation of a solution to a given problem, which makes it easy to understand. An algorithm uses a definite procedure. It is not dependent on any programming language, so it is easy to understand for anyone even without programming knowledge. Every step in an algorithm has its own logical sequence so it is easy to debug. **Assessment** Let us test how much have you learned with the Data Structure overview. Please take time to answer the test below. 1. 2. 3\. The performance of an algorithm is measured on the basis of following properties. What are these properties and explain your answer in your own understanding.

Use Quizgecko on...
Browser
Browser