24
Problem , Problem Solving, Algorithm & Flow Charts Presented By Khozema Ali Shabbar Course:101 CS

Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Embed Size (px)

Citation preview

Page 1: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Problem , Problem Solving,

Algorithm & Flow Charts

Presented By

Khozema Ali Shabbar

Course:101 CS

Page 2: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Problem and Problem Solving

Definitions

The state of feeling difficulty in completing any task is

called problem

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.

Page 3: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Problem Solving Techniques

ALGORITHMS AND FLOWCHARTS Algorithm

Step by step method to solve a problem is algorithm

Flow Chart

Diagrammatic representation of algorithm

Page 4: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Divide and conquer strategy

A divide and conquer algorithm works

by recursively breaking down a

problem into two or more sub-

problems of the same (or related)

type, until solved

Mr.Mohammed Rahmath

Page 5: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Mr.Mohammed Rahmath

Page 6: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Steps in development of Algorithms

1. Problem definition

2. Development of a modal

3. Specification of Algorithm

4. Designing an Algorithm

5. Checking the correctness of Algorithm

6. Analysis of Algorithm

7. Implementation of Algorithm

8. Program testing

9. Documentation Preparation

Mr.Mohammed Rahmath

Page 7: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Algorithm

Problem: How to brush your teeth

Real life Example 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

Page 8: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Problem: Add two numbers

Algorithm

Step 1: Start

Step 2: Read A, B

Step 3: C=A+B

Step 4: Print C Step 5: Stop

Page 9: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

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: Start

Step 2: Read A, B

Step 3: C=A-B

Step 4: Print C

Step 5: Stop

Page 10: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Algorithm

Problem: Average of 3 numbers

Step 1: Start

Step 2: Read A, B, C

Step 3: Avg=(A+B+C)/3

Step 4: Print Avg Step 5: Stop

Page 11: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Algorithm

Problem: Find your Age

Step 1: Start

Step 2: Read Byear

Step 3: Age=2015-Byear

Step 4: Print Age

Step 5: Stop

Page 12: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Algorithm

Problem: Area of Circle

Step 1: Start

Step 2: Read Radius

Step 3: Area=3.14*Radius *Radius

Step 4: Print Area

Step 5: Stop

Page 13: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Algorithm

Problem: Find even or odd

Step 1: Start

Step 2: Read N

Step 3: Is (N%2=0) then

Print “Even”

else

Print “Odd”

Step 4: Stop

Page 14: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Detailed Algorithm

Step 1: Start

Step 2: Read Mark

Step 3: Is (Mark>=60) then

Print “PASS”

else

Print “Fail”

Step 4: Stop

Algorithm

Problem: Find Pass or Fail

Page 15: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

The Flowchart A Flowchart is another algorithm but graphical.

shows logic solution

emphasizes individual steps and their interconnections

A flowchart must have a start and stop

A steps in a flowchart must connect.

Page 16: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Flowchart Symbols General Used Symbols

Page 17: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Flow Chart: Add Two Numbers Start

Read A, B

C=A+B

Print C

Stop

Algorithm

Flowchart

Page 18: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

DECISION STRUCTURES

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

Page 19: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

DECISION STRUCTURES

is

A>B

Y N

Print A Print B

Page 20: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Flow Chart: Find Even or Odd Start

Read N

Print “Odd”

Stop

Print “Even”

Is

N%2=0

N Y

Page 21: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Flow Chart: Find Largest of two numbers Start

Read A, B

Print “B is large”

Stop

Print “A is large”

Is

A>B

N Y

Page 22: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Problem: Write Algorithm and Flowchart to find

solution of Quadratic equation

Algorithm: Step 1: Start

Step 2: Read a, b, c

Step 3: d sqrt ( )

Step 4: x1 (–b + d) / (2 x a)

Step 5: x2 (–b – d) / (2 x a)

Step 6: Print x1, x2

Step 7: Stop

START

Read

a, b, c

d sqrt(b x b – 4 x a x c)

STOP

x1 (–b + d) / (2 x a)

X2 (–b – d) / (2 x a)

4b b a c

Print X1, X2

Page 23: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Assignment 1

Draw algorithm and flowchart

1. Find area of triangle

(area=(1/2)*breadth*height)

2. Convert Celsius to Fahrenheit

temperature f = (1.8*c) + 32;

3. Volume of cylinder(V= 3.14*R*R*Height)

4. Find volume of sphere (4/3* 3.14*R*R*R)

5. Find biggest of three numbers.

Page 24: Problem , Problem Solving, Algorithm & Flow Charts · Problem , Problem Solving, Algorithm & Flow Charts ... Write Algorithm and Flowchart to find ... Volume of cylinder

Instructions to students

Study definition well

Study different algorithms well

Study how to draw flowchart for specific

problems.

Work-out various assignment problems

Approach me for any doubt clarifications