Problem Problem Solving Algorithm Flow Charts Presented By
Problem , Problem Solving, Algorithm & Flow Charts Presented By Dr. Yousef Daradkeh 1
Objectives of the Session n n Defining Problem Solving Need for Problem Solving Strategy Define-Algorithms- Rules of Algorithms Examples of Algorithms Define-Flowcharts-Rules of Flowchart Examples of Flowcharts Model Exercises Take Away Tutorials 2
Problem and Problem Solving Definitions n The state of feeling difficulty in completing any task is called problem n The process of working through details of a problem to reach a solution. Problem solving may include mathematical or systematic operations and can be a gauge of an individual's critical thinking skills. 3
Need for Problem Solving n n n A computer is a tool that can be used to implement a plan for solving a problem. A computer program is a set of instructions for a computer. These instructions describe the steps that the computer must follow to implement a plan. An algorithm is a plan for solving a problem. A person must design an algorithm. A person must translate an algorithm into a computer program. 4
ALGORITHMS AND FLOWCHARTS n Algorithm ¨ Step n by step method to solve a problem is algorithm Flow Chart ¨ Diagrammatic representation of algorithm 5
Divide and conquer strategy n A divide and conquer algorithm works by recursively breaking down a problem into two or more subproblems of the same (or related) type, until solved 6
7
Steps in development of Algorithms 1. 2. 3. 4. 5. 6. 7. 8. 9. Define Problem Adopt Problem solving Method Specify of Algorithm Design an Algorithm Check correctness of Algorithm Analysis of Algorithm Implementation of Algorithm Test Algorithm Documentation Preparation 8
Qualities of a good algorithm n n Inputs and outputs should be defined precisely. Each steps in algorithm should be clear and unambiguous. Algorithm should be most effective among many different ways to solve a problem. An algorithm shouldn't have computer code. Instead, the algorithm should be written in such a way that, it can be used in similar programming languages. 9
Algorithm Problem: How to brush your teeth n Real life Example n Step 1: Start Step 2: Wake up Step 3: Wash mouth Step 4: Wash brush, apply toothpaste Step 5: Brush your teeth Step 6. Wash mouth and brush Step 7: Put brush back to holder Step 8: Stop 10
Problem: Add two numbers Algorithm Step 1: Step 2: Step 3: Step 4: Step 5: Start Read A, B C=A+B Print C Stop 11
Algorithm Problem: Multiply 2 numbers Step 1: Start Step 2: Read A, B Step 3: C=A*B Step 4: Print C Step 5: Stop Problem: Subtract 2 numbers Step 1: Step 2: Step 3: Step 4: Step 5: Start Read A, B C=A-B Print C Stop 12
Algorithm Problem: Average of 3 numbers Step 1: Step 2: Step 3: Step 4: Step 5: Start Read A, B, C Avg=(A+B+C)/3 Print Avg Stop 13
Algorithm Problem: Find your Age Step 1: Step 2: Step 3: Step 4: Step 5: Start Read Byear Age=2019 -Byear Print Age Stop 14
Algorithm Problem: Area of Circle Step 1: Step 2: Step 3: Step 4: Step 5: Start Read Radius Area=3. 14*Radius Print Area Stop 15
Algorithm Problem: Find even or odd Step 1: Step 2: Step 3: Start Read N If (N%2=0) then Print “N is even number ” else Print “N is odd number ” Step 4: Stop 16
Algorithm Problem: Find +ve or -ve Step 1: Step 2: Step 3: Start Read N If (N>0) then Print “ N is +ve number” else Print “N is -ve Number” Step 4: Stop 17
Algorithm Problem: Find Pass or Fail n Detailed Algorithm Step 1: Start Step 2: Read Mark Step 3: If (Mark>=60) then Print “PASS” else Print “Fail” Step 4: Stop 18
The Flowchart A Flowchart is the graphical representation of an algorithm. ¨ shows logic solution ¨ emphasizes individual steps and their interconnections ¨ A flowchart must have a start and stop ¨ A steps in a flowchart must connect. 19
Flowchart Symbols General Used Symbols 20
Flow Chart: Add Two Numbers Algorithm Start Flowchart Read A, B C=A+B Print C Stop 21
DECISION STRUCTURES n n n The expression A>B is a logical expression it describes a condition we want to test if A>B is true (if A is greater than B) we take the action on left print the value of A if A>B is false (if A is not greater than B) we take the action on right print the value of B 22
DECISION STRUCTURES Y Print A is A>B N Print B 23
Flow Chart: Find Even or Odd Start Read N Y If N%2=0 ? N Print “Odd” Print “Even” Stop 24
Flow Chart: Find Largest of two numbers Start Read A, B Y if A>B ? N Print “B is large” Print “A is large” Stop 25
Problem: Write Algorithm and Flowchart to find solution of Quadratic equation START n Algorithm: n Step 1: Step 2: Step 3: Step 4: Step 5: Step 6: Step 7: n n n Start Read a, b, c d sqrt ( x 1 (–b + d) / (2 x a) x 2 (–b – d) / (2 x a) Print x 1, x 2 Stop Read a, b, c ) d sqrt(b x b – 4 x a x c) x 1 (–b + d) / (2 x a) X 2 (–b – d) / (2 x a) Print X 1, X 2 STOP 26
Assignment Draw algorithm and flowchart 1. 2. 3. 4. Find area of triangle (area=(1/2)*breadth*height) Convert Celsius to Fahrenheit temperature f = (1. 8*c) + 32; Find Area of Rectangle (area= b*h) Find Volume of cylinder(V= 3. 14*R*R*Height) Find volume of sphere (4/3* 3. 14*R*R*R) Find biggest of three numbers. 27
Instructions to students Study definition well n Study different algorithms well n Study how to draw flowchart for specific problems. n Work-out various assignment problems n Approach me for any doubt clarifications n 28
- Slides: 28