Problem Solving, Algorithms and Flowchart: Learning Objectives ..
Problem Solving, Algorithms and Flowchart: Learning Objectives ..
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
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-
• 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:
Problem Solving & Programming in C 1.4 Problem Solving, Algorithms & flowci.
I IQ"
; '. '.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~
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
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
0 Preparation
i
rJ
I
u -
Magnetic disk
{database)
Flow Line
A database.
:
-
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 . ~
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.