0% found this document useful (0 votes)
73 views11 pages

Problem Solving, Algorithms and Flowchart: Learning Objectives ..

Bca
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)
73 views11 pages

Problem Solving, Algorithms and Flowchart: Learning Objectives ..

Bca
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/ 11

/ h

I " ' I /

1...
Problem Solving,
Algorithms and Flowchart
ILearning Objectives...
1
"i1 To und erstand the Concept of Problem Solving.
~ To understand the Steps involved in Algorithm Development.
l!J To understand the Concept of Algorithm.
t!J To understand the Concept of Flowchart Development.
[!I To learn the Flowchart Symbols.

• A computer performs many tasks exactly in the same manner as it is told to do. This
places responsibility on the user, to instruct the computer in a correct and precise
manner so that the machine is able to perform the required job in a proper way.
• In order to instruct a computer correctly, the user must have a clear understanding of
the problem to be solved.
• To write an effective computer program, first plan the logic of the program. This logic
is written into steps. It is necessary that, every instruction is written in the proper
sequence. The programmer has to write each and every step for solving a given
problem. This process is known as algorithm writing.
• "A problem is an issue or obstacle which makes it difficult to achieve a desired goal,
objective or purpose".
ifj DEFINl)'lON1>Fjlitt'11~Ef.f , ~'; _ .· .. , ..,
• We can define a problem as "a state of desire for reaching a definite goal from a
present condition".
OR
• Problem is a critical condition or scenario, where we can understand that situation
and find various alternatives to solve that problem.
OR
• "Problem refers to a situation, condition or issue that is yet unresolved" .
OR
• A problem is "a question or situation raised for considera tion or solution ''.
(1 .1)
!:..
P~ro~b:'..le
'. :~m
~ S:.:.
o~lv~ln.:..::g~&
~ P_ro_.::g:.___r_a,_n_m_ln
_.:g~ ln_C
______ _1_. 2_ _ _ _P_r_o b
_ l_e_m_S
_ o_l_v _
l n_g_, _A_lg_o_rl_th_m
_ s _&._..:._
Flowc1i1

1!11] Types of Problem s


"\

Decision Problems
• A decision pi'oblem is a problem, for wh ich th e ans wer for every va lid input is Yes
no. Deciding v.rhether a number is prime, odd or even are both examples of decisir'.·
problems.
Search Problen1s
• A s e.arc.h problem is a problem, that requires _the id~ntificat ion of~ solution from:
infi nite set of possible solutions. The answer IS a string representa tion of other d ,
. d.
types. For e:x.ram ple, finding the factors of a number or f In th th . at1
Ing en pnme nurnb~.
Counting Problems .
• A counting problem requires a total number of the solutions to a search problern. Pc·
c'\.rample, 'how many of the first 100 integers are prime?'. ·
Optimizati on Problems
• Optimizatio n problems require, the identificati on of the best solution to a searer.
problem from a given set of solutions.
Tractable & Intractable Problems
• If a problem is algorithmic and computable , being able to produce a solution rna,
depend on the size of the input or the limitations of the hardware used to implemeuJ
it.
• If a problem has a reasonable time solution, that is to say that it can be solved in n;
more than polynomial time, it is said to be tractable.
• Some problems can only be solved with algorithms whos.e execution time grows to.
quickly in relation to their input to be solved in polynomia l time. These algorithrr.:
are said to be intractable .
P & NP Problems
• If .a problem can be solved in polynomia l time, it is said to belong to the P class c'.
problems. P-type problems are tractable.
Undecidab le Problem.s
• If a decision problem proves to be uncomputa ble then it is said to be undecidabli
Usually, the undecidabi lity in the problem comes down to some sort of contradiction-

PROBLEM soiVIN,G USING COMPUTER


1111 Definition
• P.robl~m s.olving is the sequential process of analyzing infonnatio n, related to a gi(t"
s1tuat10n and generating appropriate response options.
OR
• Problem solving is "the process of worldng through deta.ils of a problern to reach i
solution".
• A computer performs many tasks exa ctly in the same m a nner as it is told to do. rh1
places responsibi lity on t_he ~ser to instruct the con1puter in a correct and preciS
manner, so that the machine 18 able to perform the required job in a proper way.
Problem Solving & Programm ing In c 1.3 Problem Solving , Algorlthms & Flowchart

• In order to instruct a computer correctly, the user must have a clear understanding of
the problem to be solved.
• once the problem is well-defined and a method of solving is developed, then
instructing the computer to solve the problem.
• Problem solving is a thinking process includes:
1. Understand the problem (communication and analysis).
2. Plan a solution (modeling and design).
3. Carry out the plan (code generation).
4. Examine the result for accuracy (testing and quality assurance).
IIIJ rhe steps involved in Problem Solving
• Fig. 1.1 shows the steps involved in problem solving using computers.
:~}!~tep''.1~1:

Fig. 1.1: Steps for Problem Solving


• The following are the sequence of steps involved in solving a problem using
computers:
Step 1 Problem Definition: Before a program is written for solving a problem, it is
important to define the problem clearly for its solution..
Step 2 Problem Analysis: In this phase, requirements are first gathered, i.e. we
have to understand what exactly has to be done. What is the input, what is
expected output.
Step 3 Algorithm Design: It involves the design of the procedura l solution for the
problem, i.e. step by step procedure to arrive at the expected outputs by
giving the available inputs in the problem dom ai n.
Step 4 : Coding: In this step, the algorithm desig ned is converted into a prog ra m
using a programming language. Each step in the algorithm is reali zed by
means of one or more statements in th e programming language. In this
book, we use the C language as the coding tool.
' /

Problem Solving & Programming in C 1.4 Problem Solving, Algorithms & flowci.
I IQ"

Steps : Testing and Debugging: Testing involves verification of the correctness


the program created. Testing is normally done by running the program
all types of sample data and then observing the output. Debugging is th '
Wi:
process of detection and correction of errors in the program code like
syntax errors, runtime errors and logical errors. e
Step 6 Documentation: It includes recording the general description of th
progra1n's behaviour under different situations and its special featurese
There are two types of documentation as discussed below: ·
(i) Technical Documentation: It involves the technical details of the
program which are of use for its further maintenance by the
programmers.
(ii) User Documentation: It involves instructions about the usage of the
program.
Step 7 Maintenance: Maintenance of programs is another important step. Due to
the fact that the user requirements keep changing, the programs also need
to be changed to meet the changing requirements. Proper documentation of
the programs would be of big help to programmers in charge of
maintenance.
Problem Solving Techniques
• There are many approaches to problem solving, d~pending on the nature of the
problem and the people involved in the problem.
• Fig. 1.2 shows various problem solving techniques.
_ Problem sol vi ng tech niques

; '. '.t-,.
- Brainstorm ing techn ique Divide and conquer technfque +, ·
,. - _' -£!::. /i ,
Fig. 1.2: Various problem solving techniques
{I) Trial and Error Method (Technique):
•Trial and error, or trial by error, is a general method of problem solving.
•This method is also called as "generate and test". Trial and Error approach is more
successful with simple problems.
• Trial and Error approach can be seen as one of the two basic approaches to
problem solving and is contrasted with an approach using insight and theory.
• A trial and error approach to problem solving involves trying a number of
different solutions and cut out those that do not work.
• This approach can be a good option if you have a very limite9- number of options
available.
• This method is often used by people who have little knowledge of the problel11
area.
Advantages:
1. Easy to implement.
2. This method is best in situations where you have more test sub jects .
Problem Solving & Programming In c 1.5 Problem Solvlng, Algorithms & Flowchart

Disadvantage:
Time consuming because of the need to run each and every test.
1.
(II) Brainstorming Method (Technique):
• Brainstorm.ing is a group creativity technique designed to generate a large
number of ideas for the solution to a problem.
• Brainstorming is problem solving technique that uses a group of people to solve a
problem.
• The p_urpose of a brainstorming session is to work as a group to define a problem
and fmd a plan of action to solve it.
• Brainstorming process involves a group working together and stating ideas,
arguing the merits of those idea~, supplementing those ideas or rejecting those
ideas.
• Brainstorming is often seen in the workplace when a work group meets to
consider and create multiple ideas.
• It is a method of shared problem solving in which all members of a group easily
contribute ideas for the solution of a problem.
Advantages of Brainstorming:
1. Easy to understand i.e. it is not a complicated technique.
2. It is inexpensive. _
3. If controlled properly it is a quick way of generating ideas.
4. Encourages creative thinking and thinking "out of the box".
5. It generates ideas and solutions that can be used elsewhere.
6. It provides an opportunity for widespread participation and involvement.
Disadvantages of Brainstorming:
1. As this is a group activity, participants have to listen patiently and have to spend
more time by sharing their ideas until they are noticed by others.
2. More discrete or introvert ·participants might find it difficult to express their
crazy or unorthodox ideas.
{III) Divide and Conquer Method {Technique):
• The name divide and conquer is because the problem is conquered by dividing it
into several sn1aller problems.
• Divide and conquer is an approach to solving a problem that is a special case of
means-ends analysis.
• In divide and conquer, one solves a problem by first defining a subgoal that
involves solving a smaller version of the same kind of problem.
• In other words, divide and conquer is the explicit use of recursion to solve a
problem.
• The divide and conquer strategy solves a problem by:
1. Breaking it into sub problems that are them se lves s m aller in st a n ces of the
same type of problem.
2. Solving these subproblems indep endently.
3. Appropriately combining their answers.
J~

1.6 Pro blem solving, Algorlthms & Flowc1.


~
Problem Solving & Program ming In C p
r Technique: 1
Advantages of Divide and c onque d "'onquer is a powerful too for solvil\ ~,-
l . Divide an c bl · t
Solving difficult prob ems. . f breaking the pro em mto SIJb . •
1. All 't reqtures a way o . h . .
difficult problems . l . . d combining sub -problems tot e ortgin~l
problems. of solving the n11nor cases an .
problem. . . d onquer technique often helps in th~
, .
2. Algo.rithm e ffi c1ency.
The
. d1v1de an c

discovery of efficient algonthms. .h re naturally adapted for execution


. 'd
3. Parallelism: D1v1 e an
in multi- processor ma
d conquer algont ms a
. 11
chines espec1a Y s
' b
hared-memory systems. In th~
n processors does not need to ~
,
I
. tion of data etwee
systems the commumca . . b roblems can be executed on different
planned in advance, because d1stmct su -p

processors. . . . l orithms naturally tend to make efficient


4 Memory access: Divide and conquer a g . 11 .
· ,c::e . that once a sub-problem
· of memory caches. The reason is . 1s sma enough,
. it
u.., b
and its all sub-problems can e so1ve d within the cache, Without accessing the
slower main memory.
Disadvantages of Divide and Conqu~r Technique: . . .
1. Slow Recursion: The overhead of the repeated subroutine calls, alongwith that~!
storing the call stack, can outweigh any advantages of the approach. T~is,
however, depends upon the implementation style, with large enough recursive
base cases, the overhead of recursion can become negligible for many problems.
2. Complicated for simple problems: For simple problems, it may be more
complicated than an iterative approach, especially if large base cases are to be
implemented for performance reasons. • ·
11!1 Problem Solving Aspects
• People have many problems with problem solving. Some have not been taught how to
solve problems. Others are afraid to make a decision for fear it will be the wrong one.
Often, when people go through the problem solving process, they complete one or
more of the steps shortly. They may not define the problem correctly or may not
generate sufficient list of alternatives. When choosing the best alternative, they maY
eliminate alternatives or list the pros and cons too quickly.
• Computer problem solving is a creative process that largely defies systematizatio!1
and mechanization.
• Even if someone is not naturally skilled at problem solvin g there are a number of
steps that can be taken to raise the level of someone's performance. It is not implied
(int~nded) that ~he suggestions in wh at follows are in any way a recipe for probleITl
solvmg. The plain fact of the matter is that there is no universal method. Differenl
strategies appear to work for different people.
Problem Solving & Programming In C 1.7 Problem Solving, Algorithms & Flowchart

Em Difficult~es with Problem Solving


• In Problem Solvmg, students are required to apply and integrate many mathematical
concepts and skills during the process of making a decision and problem -solving.
0 Lack of problem solving experience.
o Inadequate solution steps.
o Incorrect problem definition.
o Alternatives choose incorrectly.
o Invalid logic.
o Incorrect solution evaluation.

iii TOP•~WM DE~IqJj ,



,
The goal of problem-solving is to implement an algorithm which is capable to design
-
efficient computer program.
• Top-down design is a strategy that can be applied to the computer problem to find the
solution.
• I.n this design, complex problem can be solved in a stepwise fashion.
• We take general statements that we have about the solution, one at a time and break
them down into set of more accurately defined subtasks.
• The process of repeatedly breaking a task down into subtasks and then each subtask
into still smaller subtasks must continue until we get subtasks that can be
implemented as a program statements.
• Fig. 1.3 shows the Top-Down Design Approach.

l ~:~,~~~il
/-Ariput cond1t1orifjjj ltl ~f~ut requirem~n~ :

/ ~ /" ,,,... ~ 0~

S!Jbtask 1,':~
Fig. 1.3: Top-Down Design with breakdown of Problem into Subtasks

Iii it'fo.mHMs
• An Algorithm is a finite set of instructions for performing a computation or for
solving a problem.
• An algorithm is a sequence of activities to be processed for getting desi red output
(solution) from a given input (problem).
• An algorithm can be thought of as the detailed instructions for carrying out some
operation. A computer program has to follow a sequence of exact instructions to
accomplish this. This sequence of instructi ons is called an Algorithrn.
Problem Solving, Algorithms & Flowcha~
. C . 1.8
• & programming ,n d .
t of underlying languages, I.e.
Problem so 1ving ;i.
t d indepen en 'll
• Algorithms are generally ere~ e ore than one programming language.
algorithm can be implement~d mm utational procedure that takes some value,°'
• An algorithm is any well-defined comp value or set of values, as output. .
set of values, as input and produces someutatio~al steps that transform the mput int,
• An algorithm is thus a sequence of comp
the output.
• For example, Task: to make a cup of tea.

Algorithm:
Step 1: Add water and milk to the kettle,
Step 2: Boil it, add tea leaves,
Step 3: Add sugar, and then serve it in the cup.

11111 Definition . . ,
• we can define algorithm is "a set ofinstruct10ns for solving a problem .
OR
• A step-by-step procedure for solving a particular problem is an Algorithm.
OR
• An algorithm can be defined as "a process that performs some sequence of cperatioru
in order to solve a given problem". [W-17, 22, S-22]
11!1 Characteristics
algorithm must satisfy the following characteristics:
• Every
1. Input An algorithm must have zero or more input.
2. Output Must produced atleast one output.
3. Definiteness Each instruction must be clear and distinct.
4. Finiteness The algorithm must terminate after a finite number of steps.
S. Effectiveness Each operation must be definite also it should be feasible
i.e. practically it should be possible.
1111 Advantages and Disadvantages of Algorithms
Advantages of Algorithms:
1. It is a stepwise representation of a solution to a given problem which makes it
easy to understand. '
2. An algorithm uses a definite procedure.
3. It is not dependent on any programmin 1 . .
anyone even without progtamm· k g language, so It Is easy to understand for
. mg now edge.
4. Every step m an algorithm has its own lo ical . .
s. By using algorithm, the problem is b gk sequen~e so It IS easy to debug.
hence, it is easier for programmer to ro en_ down mto smaller pieces or steps
Disadvantages of Algorithms: convert It into an actual program.
1. A~g~rithms is time consuming.
2. D1ff1cult to show Branching and Loop. .
m Algorithms.
3. Big tasks are difficult to put in Algori:~gms.
y I
1.9 Problem Solving, Algo rithm s & Flow char t
Problem Solving & Programming in C

Ii i FLOWCHARTS . iflii}J,.
eren t types of acti ons or step s in a
• Flowcharts use special shap es to repr esen t diff
process.
by prog ram mer s and anal ysts for
• Flowchart is an imp orta nt tool which is used
ence for data proc essi ng.
tracing the info rma tion flow and the logical sequ
of the problem.
• It helps us in und erst and ing of logical stru ctur e
with the help of flowchart.
• Every problem can be repr esen ted symbolically
an algo rith m that uses boxes of
• Flowchart is a pictorial repr esen tatio n of
ruct ions . These boxes are con nect ed
diff eren t shap es to den ote diff eren t types of inst
the flow of ope ratio n and the exac t
by solid lines having arrows mar ks to indi cate
uted.
sequence in which the inst ruct ions are to be exec
ess, whi ch incl ude s the data inpu ts,
• Flowchart shows the flow of the whole proc
take n and outp ut gen erat ed.
operations or com puta tion s performed, decision
1111 Types of Flowcharts
ts:
• Computer professionals use two types of flowchar
o Program Flowcharts.
o System Flowcharts
1. Program Flowcharts :
s the prog ram stru ctur e,
• These are used by prog ram mer s. A program flowchart show
form s an imp orta nt part of the
logic flow and ope ratio ns performed. It also
doc ume ntat ion of the system.
• It broadly includes the following:
o Prog ram Stru ctur e.

o Program Logic.
o Data Inpu ts at vari ous stages.
o Data Processing

o Com puta tion s and Calculations.

o Conditions on whi ch decisions are based.


o Branching & Looping Sequences.
o Results.
o Various Outputs.
c.
The emphasis in a prog ram flowchart is on the logi
2 · System Flowcharts :
• System flowcharts are used by system anal yst to show various processes, sub systems,
outputs and ope ratio ns on data in a syst em.
10 Pr~ .
blem Solving , Algorlthms & Flowch
-~..:...:E.:..__~ - -- -~
lving & Programmi ng In
Problem So '·
c____ 1. -----

IW9!I Flowchart Symbols .b l


&lila T- ble t 1· flowchart sym o_s___ - •
a · · - - Me·an1ng
Nl'tm-~{;-itcrnatea) ---
f Symbol
r1~ocess
An opera tior; ~; a ction step . ------1
\ D. - -- -- --
Terminator
----- - A start
-
_
- top point in a
ors
-

process.
I

1
C) - - - - -- - - - - - - - . or b ranch in the process.
--I
I
Decision A quest10n '.

l
0 A forma 11Y defined sub-process.
D Predefined process
Indicates data inputs an~ outputs (IIO)
0 Data (I /0)
to and from process.
'
A document or report.
CJ Documen t
Same as document but well multiple ,
I

-.:

CJ Multi -document
document. I

A preparation or set-up process step.


I
I

0 Preparation
i

0 Display A machine display. I


I

0 Connector A jump from one point to another.

rJ
I

Off-page connector Continuation-onto another page.

D Stored data Data storage symbol in flowchart.

u -
Magnetic disk
{database)
Flow Line
A database.

Indicates the direction of data flows .


-
I

:
-
1111,Advantages and Disadvantages of Flowcharts
Advantages:
• Th e benefits (advantages) of flowcha r ts are as follows:
1. Proper Documentation: Flowch a rts serv,e as good program docu ment at ion, whid',
is needed fo r various purposes.
2. Efficient Coding: The flowcharts act as a guide ·or blueprint during the sy stenif
a n alysis an d program developmen t phase.
3. Efficient Progr~m Maintenance: Th e maintenance of op e rating progra 111
becomes easy with the help of the flow chart. It h elps th t• prog ra mm er to pul
efforts more efficiently on that pa rt.
4 . Proper Debuggin g : The flow chart helps in d ebu gging process.
s. system
Communication: Flowcharts are b,>tter w ~y of co nmnmi ca t ln p t h e logic of 1
to a ll concern ed . ~

6. Effective Analysis: W ith th e h e l p of flowc h a rt·, probl e m ca n be analysed in rnor 2


effective way .
1.11 Problem Solving , Algorithms & Flowchart
Problem Solving & Programming In C

Disadvantage:
• The disadvantages (limitations) of flowchart are as follows :
1. Loss of techn ical details: The essent ials of what is done can easily
be lost in the
technical details of how it is done.
2. complex logic: Sometimes, the progra m logic is quite complicated . In
that case,
flowchart becomes complex and clumsy.
art may
3. Alterations and Modifications: If altera tions are required, the flowch
requ ire redraw ing completely.
4. Reproduction: As the flowchart symbols canno t be typed, reprod
uction of
flowchart becomes a problem.
ming.
5. Time consuming: Developing and constr ucting a flowchart is time consu
Flowchart requir es more time to construct.
Table 1.2: Difference betwe en Algorithm and Flowchart
Sr. No.
l
1. An algori thm is a finite set of precise A flowchart is a graph ical/p ictoria
instru ctions for solving a problem. repres entati on of an algori thm.
It refers to the logic fo~ solving It is a tool which shows flow
of
2.
problem. problem solving.
3. An algori thm is a precise rule (or set A flowchart is a diagra m of the
of rules) specifying how to solve sequence of operat ion in proble m
some problem. Algorithm is stepwise solving.
analysis of the work to be done.
Algorithm gives langua ge Flowchart gives logical flow of
4.
indep enden t layout of the problem. problem.
5. Easy to update. Difficult to update .
a
6. Less time requir ed for write an Time consu ming to write and draw
algori thm. flowchart.

1111 Addition of Integers m of the


• Following algori thm and flowchart explains the steps for solving the proble
rs say x
program for the additi on of two integers. Suppose we take two positive intege
in third
and Ythen one can add both positive intege rs as x + y and the result is stored
integer z using formu la z = x + y.

You might also like