The document discusses algorithms, flowcharts, and pseudocode which are tools used in program design. It describes algorithms as step-by-step methods for solving problems, flowcharts as graphical representations of algorithm steps, and pseudocode as a detailed description of what a program must do using natural language. Control structures like sequence, branching, and loops are also explained which are common elements used in algorithms and flowcharts.
The document discusses algorithms, flowcharts, and pseudocode which are tools used in program design. It describes algorithms as step-by-step methods for solving problems, flowcharts as graphical representations of algorithm steps, and pseudocode as a detailed description of what a program must do using natural language. Control structures like sequence, branching, and loops are also explained which are common elements used in algorithms and flowcharts.
The document discusses algorithms, flowcharts, and pseudocode which are tools used in program design. It describes algorithms as step-by-step methods for solving problems, flowcharts as graphical representations of algorithm steps, and pseudocode as a detailed description of what a program must do using natural language. Control structures like sequence, branching, and loops are also explained which are common elements used in algorithms and flowcharts.
The document discusses algorithms, flowcharts, and pseudocode which are tools used in program design. It describes algorithms as step-by-step methods for solving problems, flowcharts as graphical representations of algorithm steps, and pseudocode as a detailed description of what a program must do using natural language. Control structures like sequence, branching, and loops are also explained which are common elements used in algorithms and flowcharts.
Download as PPTX, PDF, TXT or read online from Scribd
Download as pptx, pdf, or txt
You are on page 1of 32
Artificial Intelligence
Chapter 4
Program Design Aids
ALGORITHMS • The word Algorithms relates to the name of the mathematician Al-Khwarizmi, which means a procedure or a technique. • An Algorithms is a step by step method of solving a problem. • It is commonly used for data processing , calculations and other related computer and mathematical operations. Characteristics of Algorithm. • Input: An algorithm may or may not require an input. • Output: each algorithm is expected to produce at least one result. • Definiteness: Each instruction must be clear and unambiguous. • Finiteness: An algorithm should terminate after a finite number of steps. • Effectiveness: Every step must be basic and essential. • Feasibility: Should be feasible with the available resources. • Independent: It should have step by step directions ,which should be independent of any programming code. Advantage of Algorithm • It is a step – wise representation of a solution to a given problem, which makes it easy to understand. • It is not dependent on any programming language. • 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. Disadvantage • Time consuming. • Space consuming. Examples of Algorithms
Step 1 • Take a pan and boil approx. 200 ml of
water. Step 2 • Add noodles and tastemaker to the boiling water. Step 3 • Stir constantly and cook in the open pan till the water is soaked by the noodles. Step 4 • Serve Hot. Examples of Algorithms Algorithm to find the sum of two numbers Algorithm Step-1 Start Step-2 Input first numbers say A Step-3 Input second number say B Step-4 SUM = A + B Step-5 Display SUM Step-6 Stop How to Design an Algorithm? • The problem that is to be solved by this algorithm. • The constraints of the problem that must be considered while solving the problem. • The input to be taken to solve the problem. • The output to be expected when the problem the is solved. • The solution to this problem, in the given constraints. Example: Consider the example to add three numbers and print the sum.
• The problem that is to be solved by this
algorithm: Add 3 numbers and print their sum. • The constraints of the problem that must be considered while solving the problem: The numbers must contain only digits and no other characters. • The input to be taken to solve the problem: The three numbers to be added. • The output to be expected when the problem the is solved: The sum of the three numbers taken as the input. • The solution to this problem, in the given constraints: The solution consists of adding the 3 numbers. It can be done with the help of ‘+’ operator, or bit-wise, or any other method. Algorithm Step1:START Step2: Declare 3 integer variables num1, num2 and num3. Step 3: Take the three numbers, to be added, as inputs in variables num1, num2, and num3 respectively. Step4: Declare an integer variable sum to store the resultant sum of the 3 numbers. Step5:Add the 3 numbers and store the result in the variable sum. Step6:Print the value of variable sum Step7:END Write the algorithm for the following problems 1. Algorithm to bake a cake. 2.Algorithm to make coffee. 3.Algorithm to find Area and Perimeter of Square. 4. Algorithm to find Area and Perimeter of Triangle. 5.Algorithm to check the entered number is prime or not. Flow Charts • A simple graphical representation of steps. • Shows steps in sequential order. • Used in presenting the flow of algorithm , workflow or process. Uses boxes of various kinds and their order by connecting them with arrow. •The first flowchart was designed by John Von Neumann in 1945. •Flowchart uses different symbols to design a solution to a problem. •Flowchart is considered as a blue print of a design used for solving specific problem. • Flowcharts are also known as flow diagrams, process Chart , process map , work flow diagram. • Flow chart can run horizontally or vertically. • Symbols are divided and standardised into different shapes. • Label for each steps are written inside the shapes. Disadvantages of Flowchart • Time and Space consuming • Logic Complexity – When a process is relatively complex, this can make a process flowchart look messy and clumsy. ... • Reproduction of a Flowchart – The last major drawback pertaining to flowcharts is that flowchart symbols cannot be typed. Requires template r special software. HW: • Find the difference between Algorithm and Flowcharts. Control Structures in Algorithm and Flow charts • The algorithms and flowcharts include the following types of algorithms, –Sequence –Branching(selection) –Loop (Repetition) • Sequence: statements are placed one after the other an the execution takes place starting from up to down. • Branching: According to the condition , a decision of either TRUE or FALSE achieved. • If true--- one branch • If false--- another branch. • Loop( Repetition): allows a statement to be executed repeatedly based on certain loop condition.
• https://www.draw.io :free online
software for making flowcharts and process diagrams PSEUDOCODE • A detailed readable description of what a computer program or algorithm must do. • Use natural language • Used to express the intent of the program without being syntactically correct. • Intended for Human rather than machines. • Algorithm: step by step procedure to solve a problem. • Pseudocode : a method of writing algorithm. Advantages of Pseudocode • it can be quickly and easily converted into an actual programming language as it is similar to a programming language • it is fairly easy to understand, even for non- programmers • it does not matter if there are errors in the syntax - it is usually still obvious what is intended • changes to the design can be incorporated quite easily Disadvantages of Pseudocode • It can be hard to see how a program flows. For example, where does following one path as opposed to another take the program? • It can be time consuming to produce. • It cannot be compiled nor executed. HW: • Refer and make a note on Holography. • https://www.youtube.com/watch?v=auJ JrHgG9Mc visit the link to view Demo: The magic of AI neural TTS and holograms at Microsoft Inspire 2019