The document discusses algorithms and problem solving. It explains that algorithms are sets of steps to solve problems and mentions some common algorithm development steps and expressions. It also provides an example algorithm for calculating an average and discusses concepts like pseudo code and flowcharts.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
29 views
Lecture 02 - Problem Solving Steps
The document discusses algorithms and problem solving. It explains that algorithms are sets of steps to solve problems and mentions some common algorithm development steps and expressions. It also provides an example algorithm for calculating an average and discusses concepts like pseudo code and flowcharts.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18
Algorithms and Problem
Solving Lecture 02 – Problem Solving Steps
AL-Zaiem AL-Azhari University
Faculty of Computer Sciences and Information Technology Mohammed Mahmoud Overview • A computer cannot solve a problem on its own. • One has to provide step by step solutions of the problem to the computer. • In fact, the task of problem solving is not that of the computer. It is the programmer who has to write down the solution to the problem in terms of simple operations which the computer can understand and execute. Problem Solving Steps • In order to solve a problem by the computer, one has to pass though certain stages or steps. They are • Understanding the problem • Analyzing the problem • Developing the solution • Coding and implementation. • Code Validation and Verfication Using Algorithms to Solve a Problem • A set of sequential steps usually written in Ordinary Language to solve a given problem is called Algorithm. • It may be possible to solve to problem in more than one ways, resulting in more than one algorithm. • The choice of various algorithms depends on the factors like reliability, accuracy and easy to modify. Using Algorithms to Solve a Problem • The most important factor in the choice of algorithm is the time requirement to execute it, after writing code in High- level language with the help of a computer. The algorithm which will need the least time when executed is considered the best. Steps involved in algorithm development • An algorithm can be defined as “a complete, unambiguous, finite number of logical steps for solving a specific problem “ • Step1. Identification of input • Step2: Identification of output • Step3 : Identification the processing operations • Step4 : Processing Definiteness • Step5 : Processing Finiteness • Step6 : Possessing Effectiveness Example • Suppose we want to find the average of three numbers, the algorithm is as follows • Step 1 Read the numbers a, b, c • Step 2 Compute the sum of a, b and c • Step 3 Divide the sum by 3 • Step 4 Store the result in variable d • Step 5 Print the value of d • Step 6 End of the program Example • Suppose we want to find the average of three numbers, the algorithm is as follows • Step 1 Read the numbers a, b, c • Step 2 Compute the sum of a, b and c • Step 3 Divide the sum by 3 • Step 4 Store the result in variable d • Step 5 Print the value of d • Step 6 End of the program Algorithms Expression • Use Natural Language • Flowchart • Pseudo Code Natural Language • Natural language is a popular choice, since it comes so naturally to us and can convey the steps of an algorithm to a wide audience. • When we're developing algorithms, we are often working both with people who know programming and those who don't —but they all know natural language. Flowchart • A flow chart is a step by step diagrammatic representation of the logic paths to solve a given problem. Or A flowchart is visual or graphical representation of an algorithm. • The flowcharts are pictorial representation of the methods to b used to solve a given problem and help a great deal to analyze the problem and plan its solution in a systematic and orderly manner. • A flowchart when translated in to a proper computer language, results in a complete program. Advantages of Flowcharts 1. The flowchart shows the logic of a problem displayed in pictorial fashion which felicitates easier checking of an algorithm. 2. The Flowchart is good means of communication to other users. It is also a compact means of recording an algorithm solution to a problem. 3. The flowchart allows the problem solver to break the problem into parts. These parts can be connected to make master chart. 4. The flowchart is a permanent record of the solution which can be consulted at a later time. Symbols used in Flow- Charts The symbols that we make use while drawing flowcharts as given below are as per conventions followed by International Standard Organization (ISO). 1. Oval: Rectangle with rounded sides is used to indicate either START/ STOP of the program. 2. Input and output indicators: Parallelograms are used to represent input and output operations. Statements like INPUT, READ and PRINT are represented in these Parallelograms. Symbols used in Flow- Charts 3. Process Indicators: - Rectangle is used to indicate any set of processing operation such as for storing arithmetic operations. 4. Decision Makers: The diamond is used for indicating the step of decision making and therefore known as decision box. Decision boxes are used to test the conditions or ask questions and depending upon the answers, the appropriate actions are taken by the computer. Symbols used in Flow- Charts 5. Flow Lines: Flow lines indicate the direction being followed in the flowchart. In a Flowchart, every line must have an arrow on it to indicate the direction. The arrows may be in any direction Pseudo code • The Pseudo code is neither an algorithm nor a program. It is an abstract form of a program. It consists of English like statements which perform the specific operations. It is defined for an algorithm. • It does not use any graphical representation. In pseudo code, the program is represented in terms of words and phrases, but the syntax of program is not strictly followed. • Advantages: * Easy to read, * Easy to understand, * Easy to modify. General Problem Solving Strategies • Divide and Conquer • Decrease and Conquer • Transform and Conquer • Greedy Method • Dynamic Programming END!