0% found this document useful (1 vote)
838 views11 pages

Unit 1: JR CSE Unit-I Introduction To Problem Solving Techniques

This document discusses problem solving techniques in computer science, including algorithms, flowcharts, and pseudocode. It defines an algorithm as a step-by-step method for solving a problem and lists properties like being finite, definite, effective, and able to solve all problems of a specific type. Examples of algorithms for basic math operations are provided. Flowcharts are described as using graphic symbols to represent the steps in an algorithm, with advantages being they clearly show logic but can be difficult to modify. Pseudocode is an informal high-level description of an algorithm, sitting between an algorithm and actual code. The document concludes by comparing algorithms and flowcharts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
838 views11 pages

Unit 1: JR CSE Unit-I Introduction To Problem Solving Techniques

This document discusses problem solving techniques in computer science, including algorithms, flowcharts, and pseudocode. It defines an algorithm as a step-by-step method for solving a problem and lists properties like being finite, definite, effective, and able to solve all problems of a specific type. Examples of algorithms for basic math operations are provided. Flowcharts are described as using graphic symbols to represent the steps in an algorithm, with advantages being they clearly show logic but can be difficult to modify. Pseudocode is an informal high-level description of an algorithm, sitting between an algorithm and actual code. The document concludes by comparing algorithms and flowcharts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Jr CSE Unit-I Introduction to problem solving techniques

UNIT 1
INTRODUCTION TO PROBLEM SOLVING TECHNIQUES:
Before going to solve a problem by using computer,first we have to write an
algorithm,flow chart and then write a program in computer and the computer
gives the solution to the given problem.
1.ALGORITHM:
Algorithm is a method of representing the step-by-step logical procedure for
solving a problem. An algorithm is a recipe for finding the right-answer to a
problem or to a difficult problem by breaking down the problem into simple
cases.
Properties of an algorithm:
(i)Finiteness: An algorithm must terminate in a finite number of steps.
(ii)Definiteness: Each step of the algorithm must be precisely and
unambiguously stated.
(iii)Effectiveness: Each step must be effective, in the sense that it should be
primitive (easily convertable into program statement) can be performed exactly
in a finite amount of time.
(iv)Generality: The algorithm must be complete in itself so that it can be used
to solve all problems of a specific type for any input data.
(v)Input/Output: Each algorithm must take zero, one or more quantities as
input data produce one or more output values.
Advantages of algorithm:
1.It is a step by step solution to the given problem which is very easy to
understand.
2.It is easy to first develop an algorithm and then convert into a flow chart and
then into a computer program.
3.It is easy to debug.
4.It is independent of programming language.

National Junior college Programming in C


Page 1
Jr CSE Unit-I Introduction to problem solving techniques

Examples:
1.Write an algorithm to display the sum of two numbers.
Solution:
Step 1 : START
Step 2 : Read a,b and sum;
Step 3 : sum=a+b;
Step 4 : Display sum;
Step 5 : STOP
2.Write an algorithm to display the subtraction of two numbers.
Solution:
Step 1 : START
Step 2 : Read a,b and sub;
Step 3 : sub=a-b;
Step 4 : Display sub;
Step 5 : STOP
3.Write an algorithm to display the multiplication of two numbers.
Solution:
Step 1 : START
Step 2 : Read a,b and mul;
Step 3 : mul=a*b;
Step 4 : Display mul;
Step 5 : STOP
4.Write an algorithm to display the division of two numbers.
Solution:
Step 1 : START
Step 2 : Read a,b and div;
Step 3 : div=a/b;

National Junior college Programming in C


Page 2
Jr CSE Unit-I Introduction to problem solving techniques

Step 4 : Display div;


Step 5 : STOP
5.Write an algorithm to display the modulo division of two numbers.
Solution:
Step 1 : START
Step 2 : Read a,b and mod;
Step 3 : mod=a%b;
Step 4 : Display mod;
Step 5 : STOP
6.Write an algorithm to display the total and average of two numbers.
Solution:
Step 1 : START
Step 2 : Read a,b,c,total and average;
Step 3 : total=a+b+c;
Step 4 : average=total/3;
Step 5 : Display total and average;
Step 6 : STOP
7.Write an algorithm to display the square and cube of a number.
Solution:
Step 1 : START
Step 2 : Read n,sq and cu;
Step 3 : sq=n*n;
Step 4 : cu=n*n*n;
Step 5 : Display sq and cu;
Step 6 : STOP
8.Write an algorithm to display the equation c=(a+b)/(a-b).
Solution:
Step 1 : START

National Junior college Programming in C


Page 3
Jr CSE Unit-I Introduction to problem solving techniques

Step 2 : Read a,b and c;


Step 3 : c=(a+b)/(a-b);
Step 4 : Display c;
Step 5 : STOP
9.Write an algorithm to find the biggest numbers among the given three
numbers.
Solution:
Step 1 : START
Step 2 : Read a,b and c;
Step 3 : if a>b and a>c then goto step 4 else goto step 5;
Step 4 : Display a is the biggest number;
Step 5 : if b>c then goto step 6 else goto step 7;
Step 6 : Display b is the biggest number;
Step 7 : Display c is the biggest number;
Step 8 : STOP
10.Write an algorithm to find the smallest number among the given three
numbers.
Solution:
Step 1 : START
Step 2 : Read a,b and c;
Step 3 : if a<b and a<c then goto step 4 else goto step 5;
Step 4 : Display a is the smallest number;
Step 5 : if b<c then goto step 6 else goto step 7;
Step 6 : Display b is the smallest number;
Step 7 : Display c is the smallest number;
Step 8 : STOP
11.Write an algorithm for finding the biggest number among the given four
numbers.

National Junior college Programming in C


Page 4
Jr CSE Unit-I Introduction to problem solving techniques

Solution:
Step 1 : START
Step 2 : Read a,b,c and d;
Step 3 : if a>b and a>c and a>d then goto step 4 else goto step 5;
Step 4 : Display a is the biggest number;
Step 5 : if b>c and b>d then goto step 6 else goto step 7;
Step 6 : Display b is the biggest number;
Step 7 : if c>d then goto step 8 else goto step 9;
Step 8 : Display c is the biggest number;
Step 9 : Display d is the biggest number;
Step 10: STOP
12.Write an algorithm for finding the smallest number among the given
four numbers.
Solution:
Step 1 : START
Step 2 : Read a,b,c and d;
Step 3 : if a<b and a<c and a<d then goto step 4 else goto step 5;
Step 4 : Display a is the smallest number;
Step 5 : if b<c and b<d then goto step 6 else goto step 7;
Step 6 : Display b is the smallest number;
Step 7 : if c<d then goto step 8 else goto step 9;
Step 8 : Display c is the smallest number;
Step 9 : Display d is the smallest number;
Step 10: STOP
13.Write an algorithm for finding the given number is postitive or not.
Solution:
Step 1 : START
Step 2 : Read n;

National Junior college Programming in C


Page 5
Jr CSE Unit-I Introduction to problem solving techniques

Step 3 : if n>0 then goto step 4 else goto step 5;


Step 4 : Display n is the positive number;
Step 5 : Display n is the negative number;
Step 6 : STOP

14.Write an algorithm to print first 10 numbers.


Solution:
Step 1 : START
Step 2 : Read n=1;
Step 3 : Display n;
Step 4 : n=n+1;
Step 5 : if n<=10 then goto step 3 else goto step 6;
Step 6 : STOP
15.Write an algorithm to print the even numbers between 1-50.
Solution:
Step 1 : START
Step 2 : Read n=2;
Step 3 : Display n;
Step 4 : n=n+2;
Step 5 : if n<=50 then goto step 3 else goto step 6;
Step 6 : STOP
15.Write an algorithm to print the odd numbers between 1-50.
Solution:
Step 1 : START
Step 2 : Read n=1;
Step 3 : Display n;
Step 4 : n=n+2;
Step 5 : if n<=50 then goto step 3 else goto step 6;

National Junior college Programming in C


Page 6
Jr CSE Unit-I Introduction to problem solving techniques

Step 6 : STOP
FLOW CHART:
A flowchart is a graphical or pictorial representation of an algorithm.Each step
in the process is represented by a different symbol and contains a short
description of the process step. The flow chart symbols are linked together with
arrows showing the process flow direction. Some common flowcharting
symbols are listed below.
SHAPE NAME SHAPE MEANING
Terminal START/STOP

parellellogram INPUT/OUTPUT

Rhombus DECISION MAKING

Connector CONNECTING LINK


BETWEEN TWO SYMBOLS

Rectangle PROCESSING

Arrow keys STATEMENT LINKS

Important points in drawing flowcharts:


1. Flow chart should be clear, neat and easy to follow.
2. Flow chart should be logically correct.
3. Flow chart should be verified for its validity with some test data.

National Junior college Programming in C


Page 7
Jr CSE Unit-I Introduction to problem solving techniques

Limitations of flow charts:


1. Flow charts are difficult to modify. Re-drawing of flowchart may be
Necessary.
2. Translation of flowchart into computer program is always not easy.

Advantage of flowcharts:
1. Logical of program is clearly represented.
2. It is easy to follow logically the flow chart.
Psuedo code:
It is a high level informal description of an algorithm.
Examples:
1.Write a pseudo to display the sum of two numbers.
Solution:
Begin
Accept a,b,sum;
sum=a+b;
Print sum;
End
2.Write a pseudo to display the subtraction of two numbers.
Solution:
Begin
Accept a,b,sub;
sub=a-b;
Print sub;
End
3.Write a pseudo to display the multiplication of two numbers.
Solution:
Begin

National Junior college Programming in C


Page 8
Jr CSE Unit-I Introduction to problem solving techniques

Accept a,b,mul;
mul=a*b;
Print mul;
End
4.Write a pseudo to display the division of two numbers.
Solution:
Begin
Accept a,b,div;
div=a/b;
Print div;
End
5.Write a pseudo to display the modulo division of two numbers.
Solution:
Begin
Accept a,b,mod;
mod=a%b;
Print mod;
End
6.Write a pseudo code to display the total and average of two numbers.
Solution:
Begin
Accept a,b,c,total and average;
total=a+b+c;
average=total/3;
Print total and average;
End
7.Write a pseudo code to display the square and cube of a number.
Solution:

National Junior college Programming in C


Page 9
Jr CSE Unit-I Introduction to problem solving techniques

Begin
Accept n,sq,cu;
sq=n*n;
cu=n*n*n;
Print sq and cu;
End

8.Write a pseudo code to display the equation c=(a+b)/(a-b).


Solution:
Begin
Accept a,b and c;
c=(a+b)/(a-b);
Print c;
End;
Differences between algorithm and flow chart:
Algorithm Flow chart
1.An algorithm is a step by step 1.A flow chart is a diagrammatical
problem solving technique that can be representation of an algorithm
carried out by computer.
2.Here to solve a problem we use 2.Here to solve a problem we use
English like language. symbols.
3.Algorithms do not have any 3.To draw the flow charts we must use
standards. the symbols that can be developed by
ISO(International Standard
Organization)
4.Here each step consists English like 4.Here we must use ISO symbols to
languages. represent the steps.
5.Algorithms are used mostly to solve 5.Flow charts are used mostly to solve
the small problems. the complex problems.
6.It is difficult to solve complex 6.It is easy to solve complex problems.

National Junior college Programming in C


Page 10
Jr CSE Unit-I Introduction to problem solving techniques

problems.

National Junior college Programming in C


Page 11

You might also like