[go: up one dir, main page]

0% found this document useful (0 votes)
62 views25 pages

Problem Solving Techniques: Co Co

This document discusses problem solving techniques and algorithms. It covers steps in problem solving, algorithms and flowcharts, using flowcharts to represent algorithms with a tool called RAPTOR, and programming paradigms. It also discusses how computation is represented through algorithms, flowcharts, and pseudocode. Flowcharts provide a graphical representation of computation while pseudocode resembles English statements but has additional structure.

Uploaded by

Rathish Ragoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views25 pages

Problem Solving Techniques: Co Co

This document discusses problem solving techniques and algorithms. It covers steps in problem solving, algorithms and flowcharts, using flowcharts to represent algorithms with a tool called RAPTOR, and programming paradigms. It also discusses how computation is represented through algorithms, flowcharts, and pseudocode. Flowcharts provide a graphical representation of computation while pseudocode resembles English statements but has additional structure.

Uploaded by

Rathish Ragoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

F -X C h a n ge F -X C h a n ge

PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

PROBLEM SOLVING TECHNIQUES


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
Problem Solving Techniques
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Steps involved in problem solving

Part -II

• Algorithms and Flowcharts

• Flowcharts implementation through RAPTOR tool

• Introduction to programming paradigms and


methodologies

6/21/2012 Department of CSE 2


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
Representation of computation
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

• Representation of computation is known as


algorithm
• In Computer Science following notations are
used to represent algorithm
– Flowchart : is a graphical/pictorial representation
of computation
– Pseudo code: they usually look like English
statements but have additional qualities.

6/21/2012 Department of CSE 3


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
Algorithm
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

•An algorithm is a step by step procedure to solve a


particular problem.

•Named after Arabic Mathematician

Abu Jafar Mohammed Ibn Musa Al Khowarizmi

6/21/2012 Department of CSE 4


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
Algorithm
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

6/21/2012 Department of CSE 5


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
Properties of an algorithm
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

6/21/2012 Department of CSE 6


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.c .c

Steps to develop an algorithm


.d o .d o
c u -tr a c k c u -tr a c k

6/21/2012 Department of CSE 7


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.c .c

Advantages of algorithm
.d o .d o
c u -tr a c k c u -tr a c k

• Very easy to understand as it is a step-by-step solution to the


given problem

• It has got a definite procedure that can be executed within a


definite period of time

• Independent from any programming language syntax

• Very easy to find the errors as every step is clearly mentioned

6/21/2012 Department of CSE 8


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.c .c

Algorithmic Notations
.d o .d o
c u -tr a c k c u -tr a c k

• Name of the algorithm [mandatory]


[gives a meaningful name to the algorithm based on the
problem]
• Step Number [mandatory]
[indicate each individual simple task]
• Explanatory comment [optional]
[gives an explanation for each step, if needed]
• Termination [mandatory]
[tells the end of algorithm]

6/21/2012 Department of CSE 9


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.c .c

Algorithm to compute the area of


.d o .d o
c u -tr a c k c u -tr a c k

circle
Name of the algorithm : Compute the area of a circle

Step1: Input radius

Step 2: [Compute the area]


Area 3.1416 * radius * radius

Step 3: [Print the Area]


Print ‘Area of a circle =‘, Area

Step 4: [End of algorithm]


Stop

6/21/2012 Department of CSE 10


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
Algorithm for arithmetic operations
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Name of the algorithm: Perform various Arithmetic operations

Step1: [Read the value of numbers (n1 and n2)]


Input n1, n2
Step2: [Compute the sum, difference and
product and quotient]
sum n1 + n2
difference n1 – n2
product n1 * n2
quotient n1 / n2

6/21/2012 Department of CSE 11


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
Algorithm for arithmetic operations
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Step 3: [Print the contents of sum, diff, prod


and quotient]
Print ‘The result’
Print ‘Sum =‘, sum
Print ‘Difference =‘, difference
Print ‘Product =‘, product
Print ‘Quotient =‘, quotient
Step4: [End of Algorithm]
Stop

6/21/2012 Department of CSE 12


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to calculate Simple Interest


and Compound Interest
where P=amount deposited T=duration R=rate of interest
SI=(P*R*T)/100 and CI P*(1+ R/100)T - P

Name of the algorithm: Calculate SI and CI

Step1: [ Read the values of P, T and R]


Input P,R,T

Step 2: [Compute the simple interest]


SI ( P*R*T)/100

6/21/2012 Department of CSE 13


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to calculate Simple Interest


and Compound Interest
Step 3: [Compute the compound interest]
CI P*(1+ R/100)T - P

Step 4: [Print the simple and compound interest]


Print ‘Simple Interest=‘,SI
Print ‘Compound Interest=‘,CI

Step 5: [End of Algorithm]


Stop

6/21/2012 Department of CSE 14


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to interchange the values


of two variables
Name of the algorithm: Interchange of 2 values
Step1: Input A,B
Step 2: temp A
Step 3: A B

Step 4: B temp

Step 5: Print ‘A=’ , A


Print ‘B=’ , B
Step 6: [End of Algorithm]
Stop

6/21/2012 Department of CSE 15


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to interchange the values of two


variables without using another variable
Name of the algorithm: Interchange two values
Step1: Input A,B
Step 2: A A+B
Step 3: B A-B
Step 4: A A-B
Step 5: Print A,B
Step 6: [End of Algorithm]
Stop

6/21/2012 Department of CSE 16


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.c .c

Largest of 3 Numbers
.d o .d o
c u -tr a c k c u -tr a c k

Name of the algorithm: Find largest of 3 numbers


Step 1: [Read the values of A, B and C]
Read A, B, C
Step 2: [Compare A and B]
IF A>B go to step 4
Step 3: [Otherwise compare B with C]
IF B>C then
Print ‘B’ is largest’
Else
Print ‘C’ is largest’
Go to Step 5

6/21/2012 Department of CSE 17


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.c .c

Largest of 3 Numbers
.d o .d o
c u -tr a c k c u -tr a c k

Step 4: [Compare A and C for largest]


IF A>C then
Print ‘A’ is largest’
Else
Print ‘C’ is largest’
Step 5: [End of the algorithm]
Stop

6/21/2012 Department of CSE 18


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to find the sum and mean


of first N natural numbers
Name of the algorithm: Sum and Mean of natural
numbers.
Step1: [Read the maximum value of N]
Input N

Step 2: [Set sum equal to 0]


Sum 0
Step 3: [Compute the sum of all first N natural
numbers]
For I=1 to N in step of 1 do
begin
Sum Sum + I
end
6/21/2012 Department of CSE 19
F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to find the sum and mean


of first N natural numbers
Step 4: [Compute mean value of N natural numbers]
Mean Sum / N

Step 5: [Print Sum and Mean]


Print ‘Sum of N natural numbers=‘,Sum
Print ‘Mean of N natural numbers =‘,Mean

Step6: [End of algorithm]


Stop

6/21/2012 Department of CSE 20


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to compute factorial of


a number
Name of the algorithm: Compute the factorial of a
number
Step1: Input N
Step 2: fact 1
Step 3: For count=1 to N in step of 1 do
begin
fact fact*count
end
Step 4: Print ‘fact of N=‘, fact
Step 5: [End of algorithm]
Stop

6/21/2012 Department of CSE 21


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Name of the algorithm: Check whether prime number


Step1: Input N1, N2
Step2: For N = N1 to N2 in step of 1 do
Step 3: Begin
Step 4: prime 1
Step 5: For I =2 to N/2 in step of 1 do
begin
IF N MOD I = 0 Then
Begin
prime 0
goto step 6
end
Step 6: if prime=1 Print N
Step 7: end
6/21/2012 Department of CSE 22
Step 5: [End of algorithm]
Stop
F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to generate Fibonacci series


up to a given limit
Name of the algorithm : Generate Fibonacci Series
Step 1 : Input Limit
Step 2: A 0,B 1
Step 3: print A
Step 4: While B< limit Fibonacci series:
begin
Print ‘B=‘,B 0, 1, 1, 2, 3, 5, 8, 13, 21, …
C B
B A+B
A C
end
Step 5:[End of Algorithm]
Stop

6/21/2012 Department of CSE 23


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to count the no of digits of a


number
Name of the algorithm: Count the no of digits of a
number
Step 1: Input N
Step 2: count 0
Step 3: While N>0
begin
N N/10 (integer )
count count+1
end
Step 4 : Print ‘No. of digits=‘,count
Step 5: [End of Algorithm]
Stop

6/21/2012 Department of CSE 24


F -X C h a n ge F -X C h a n ge
PD PD

!
W

W
O

O
N

N
y

y
bu

bu
to

to
k

k
lic

lic
C

C
w

w
m

m
w w
w

w
o

o
.d o .c .d o .c
c u -tr a c k c u -tr a c k

Algorithm to calculate sum of digits of a


number
Name of the algorithm: Find sum of the digits of a
number
Step 1: Input N
Step 2: sum 0
Step 3: While N>0
begin
rem N mod 10
sum sum + rem
N N/10 (integer)
end
Step 4: Print ‘Sum of the digits of the number=‘,sum
Step 5: Stop
6/21/2012 Department of CSE 25

You might also like