0% found this document useful (0 votes)
47 views50 pages

Unit 1 Probelm Solving Fundamentals

Unit 1

Uploaded by

Kalai Chelvan G
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)
47 views50 pages

Unit 1 Probelm Solving Fundamentals

Unit 1

Uploaded by

Kalai Chelvan G
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/ 50

Problem Solving Fundamentals

Problem Solving Fundamentals

Programs and Algorithms – Problem Definition – Flow Chart –


Fundamental Algorithms (Exchange of values of two variables,
Counting, Summation of a set of numbers, Factorial Computation, Sine
Function Computation, Generation of Fibonacci Sequence, Reversing
the Digits of an Integer, Base Conversion): Problem – Algorithm
Development – Algorithm Description – Design Consideration –
Applications.
Introduction

 The computer is the symbol – manipulating machine that follows the


set of instructions called a program. Any computing has to be
performed independently without depending on the programming
language and the computer.
Procedure

 A computer cannot solve a problem on its own.

 One has to provide step by step solutions of the problem to the


computer.

 In fact, the task of problem solving is not that of the computer. It is the
programmer who has to write down the solution to the problem in
terms of simple operations which the computer can understand and
execute
Step by Step Procedure
 Understanding the problem : Here we try to understand the problem to be
solved in totally. Before with the next stage or step, we should be absolutely sure
about the objectives of the given problem.

 Analyzing the problem: After understanding thoroughly the problem to be


solved, we look different ways of solving the problem and evaluate each of these
methods. The idea here is to search an appropriate solution to the problem under
consideration. The end result of this stage is a broad overview of the sequence of
operations that are to be carries out to solve the given problem.
Step by Step Procedure
 Developing the solution: Here the overview of the sequence of operations
that was the result of analysis stage is expanded to form a detailed step by
step solution to the problem under consideration.

 Coding and implementation: The last stage of the problem solving is the
conversion of the detailed sequence of operations in to a language that the
computer can understand. Here each step is converted to its equivalent
instruction or instructions in the computer language that has been chosen for
the implantation.
Problem Definition

 The problem solving techniques involves the following steps.


 Define the problem

 Formulate the mathematical model

 Develop an algorithm.

 Write the Code for the problem

 Test the program.


Problem Definition – Define the Problem

A clear and concise problem statement is provided.

The problem definition should specify the input and


output.

Full knowledge about the problem is needed.

Example : To find the Average of Two Numbers


Problem Definition – Formulate the
Mathematical Problem
Any technical problem provided can be solved
mathematically.

Full knowledge about the problem should be provided


along with the underlying mathematical concept.

Example : (data1+data2)/2
Problem Definition – Develop an
Algorithm
An algorithm is the sequence of operations to be
performed.

It gives the precise plan of the problem.

An algorithm can be of flowchart or pseudo code.


Problem Definition – Example
 Problem Definition : To find the Average of Two Numbers

 Algorithm :
STEP 1 : START
STEP 2 : Declare Three variables a, b, avg
STEP 3 : Define Values of a & b
STEP 4 : ADD Values of a & b then compute the average, divide the sum by two
STEP 5 : Store Output of Step 4 to avg
STEP 6 : Print avg
STEP 7 : STOP

 Task : To find the average of 20 and 30 manually


20 + 30 = 50; 50/2 = 25
Problem Definition – Write the code for
problem
 The algorithm developed must be converted to any programming
language.

 The compiler will convert the program code to the machine language
which the computer can understand.
Problem Definition – Test the Program

 Testing involves checking errors both syntactically and semantically.

 The errors are called as “Bugs”

 When the compiler find the bugs, it prevents compiling the code from
programming language to machine language.

 Check the program by providing a set of data for testing.


Programs

 A program consists of a series of instructions that a computer process


to perform the required operation.

 Set of software programs that describe the program are called


software.

 The process of software development is called programming and the


person who develops the computer program are called programmer
Programs

Thus in order to design a program, a programmer must


determine three basic requirements:
 The instructions to be performed

 The order in which those instructions are to be performed

 The data required to perform those instructions


Program - Example

Write a program to add two numbers:

 Input to numbers

 Add these two numbers

 Display the output

A, B C =A+ B C
Input Processing Output
Characteristics of a Programs
 Portability:- Portability refers to an application to run on a different platform, which or
without minimum changes.

 Readability:- The programmer should be written in with a more user-friendly approach


or in such a way that it makes other programmer users follow the logic of the program
without much effort. If the programmer is written structurally, it helps the programmer to
follow their own program in a better way.

 Efficiency:- Live program at required certain processing time and memory to process the
instruction and data a program should be let out in such a manner, that it utilized the least
amount of memory and processing time.
Characteristics of a Programs
 Flexibility:-A program is flexible enough to handle most of the changes without having the rewrite
the entire program, most of the program is dependent on a certain period and their required
modification from time to time.

 Generality:-Apart from the flexibility of the program should also be general. By Generality, we
mean that, if a program is developed for a particular task, then it should also be used for all similar
tasks of the same domain.

 Documentation:-Documentation is one of the most important components of application


development, even if a program is developed following the best programming packages it will be
rendered useless if the and user is not able to fully utilize the functionality of the application level.
Program Development Cycle
 Any program has to broken into series of smaller steps.

 These series are independent of programming language

 The programmer should have wide knowledge about the problem and the way to
solve it.

 Generally any problem solving involves.


 Defining the problem

 Understanding the Problem

 Providing the solution.


Program Development Cycle

 Problem Analysis.

 Design – Algorithm and Flowchart development

 Program coding

 Program compilation and execution.

 Program debugging and testing

 Documentation.
Program Development Cycle – Problem
Analysis
 Define the problem by identifying the input and output of it.

 Variable name is assigned for each item.

 After analyzing the programmer has to develop various solution for


the given problem.

 Optimal Solution is taken from the set of solution obtained.


Program Development Cycle : Design –
Algorithm and Flowchart Development

 Algorithm and Flowchart are developed to provide a sequence of actions to be performed

 Algorithm provides a basic logic in solving the problem by providing sequence of


instructions.

 Algorithm can be of
 Flow Chart
 Pseudo Code

 Program Design Language (PDL) : It has no specific standard rules for defining the PDL
statements. PDL is independent of any programming language. It is also called as Pseudo
Code.
Program Development Cycle : Program
Coding
 Code the algorithm in the selected programming language

 The Process of translating the algorithm or the flowchart into


an exact instruction that will make up the program are called
program code.
Program Development Cycle : Program
Compilation and Execution
 After program coding the program has to be compiled and
executed.
 During compilation, if no error is produced, then the program is
executed successfully.

 If errors are available, then the errors are displayed in the


terminal, and corrected later with correct syntax and then
compiled.
Program Development Cycle : Program
Debugging and Testing
 Errors are called as “Bugs”

 Errors can be categorized as follows


 Syntax Errors (during compilation)

 Example : Program does not compile, missing bracket, bad punctuation.


 Run time (during execution)

 Example : Program crashes, Check input data


 Logical (incorrect or illogical answers) Example : Program runs and give wrong
output.
Program Development Cycle :
Documentation
 Once the programmer is free from the errors, it is the duty of
the programmer to document all the necessary document
which is provided to the users as manual.

 Helps the user to operate correctly.


Algorithm - Definition
 An algorithm is defined as a finite sequence of explicit instructions that, when
provided with a set of input values produces an output and then terminates.

 In algorithm, after a finite number of steps, solution of the problem is achieved.

 It may be possible to solve problem in more than one ways, resulting in more than
one algorithm.

 The choice of various algorithms depends on the factors like reliability, accuracy
and easy to modify.
Algorithm

 The most important factor in the choice of algorithm is the time


requirement to execute it, after writing code in High-level language
with the help of a computer.

 The algorithm which will need the least time when executed is
considered the best.
Steps Involved in Algorithm Development

 An algorithm can be defined as “a complete, unambiguous, finite


number of logical steps for solving a specific problem”.

 Identification of input: For an algorithm, there are quantities to be


supplied called input and these are fed externally. The input is to be
identified first for any specified problem.

 Identification of output: From an algorithm, at least one quantity is


produced, called for any specified problem.
Steps Involved in Algorithm Development
 Identification the processing operations: All the calculations to be performed in
order to lead to output from the input are to be identified in an orderly manner.

 Processing Definiteness: The instructions composing the algorithm must be clear


and there should not be any ambiguity in them.

 Processing Finiteness: If we go through the algorithm, then for all cases, the
algorithm should terminate after a finite number of steps.

 Possessing Effectiveness: The instructions in the algorithm must be sufficiently


basic and in practice they can be carries out easily
Characteristics of Algorithm

 It should have finite number of inputs

 Terminates after a finite number of steps

 Instructions are precise and unambiguous

 Operations are done exactly and in a finite amount of time.

 Outputs are derived from the input by applying the algorithm.


Properties of Algorithm

 Finiteness: An algorithm must terminate in a finite number of steps

 Definiteness: Each step of the algorithm must be precisely and


unambiguously stated

 Effectiveness: Each step must be effective, in the sense that it should


be primitive easily convert able into program statement) can be
performed exactly in a finite amount of time.
Properties of Algorithm

 Generality: The algorithm must be complete in itself so that it can be


used to solve problems of a specific type for any input data.

 Input/output: Each algorithm must take zero, one or more quantities


as input data produce one or more output values. An algorithm can be
written in English like sentences or in any standard representation
sometimes, algorithm written in English like languages are called
Pseudo Code.
Algorithm - Example

 To determine the largest number out of three numbers A,B and C


 Step 1 : START

 Step 2 : Read three numbers say A, B, C

 Step 3 : Find the larger number between A and B and Store it in MAX_AB

 Step 4 : Find the larger number between MAX_AB and C and Store it in MAX.

 Step 5 : Display MAX

 Step 6 : Stop
Flowchart
 Flowchart is a diagrammatic representation of an algorithm that illustrates
the sequence of operations to be performed to get a solution.

 The different boxes are interconnected with the help of arrows.

 The boxes represent operations and the arrows represent the sequence in
which the operations are implemented.

 The primary purpose of flowchart is to help the programmer in


understanding the logic of the program.
Flowchart - Symbols

Symbol
Symbol Description
Name
Flow Lines are used to connect symbols. These lines
Flow Line indicate the sequence of steps and the direction of flow
of control.

This symbol is used to represent the beginning (start).


Terminal The termination (end) or halt (pause) in the program
logic.

It represent information entering or leaving the system.


Input / Output
Such as customer order (input) and servicing (output).
Flowchart - Symbols

Symbol
Symbol Description
Name
Process symbol used for representing arithmetic and
data movement instructions. It can represent single
Processing
step (add two cups of flour) or an entire sub process
(make bread) within a larger process.
Decision symbol denotes (or branch) to be made. The
program should continue along one of the two routes
(if/else).
Decision
This symbol has one entry and two exit paths. The path
chosen depends on whether the answer to a question is
yes or no.
Flowchart - Symbols

Symbol
Symbol Description
Name

Connector Connector symbol is used to join different flow lines.

This symbol is used to indicate that the flowchart


Off Page Connector
continues on the next page.

Documents is used to represent a paper document


Document
produced during the flowchart process.
Flowchart - Symbols

Symbol
Symbol Description
Name

Manual Input symbol represents input to be given by a


Manual Input
developer / programmer.

Manual operation symbol shows that the process has to


Manual Operation
be done by a developer / programmer.

This symbol represents the online data storage such as


Online Storage
hard disks, magnetic drums or other storage devices.
Flowchart - Symbols

Symbol
Symbol Description
Name

Communication
Communication link symbol is used to represent data
Link

This symbol is used to represents data input or output


Magnetic Disk
from and to a magnetic disks.
Guidelines for Preparing Flowcharts

 The flowchart should be clear, neat and easy to follow.

 The flowchart must have a logical start and finish

 In drawing proper flowchart, all necessary requirements should be listed in logical order.

 Only one flow line should come out from a process symbol.

 Only one flow line should enter a decision symbol. However, two or three flow lines (one for each
possible answer) may leave the decision symbol.

 Only one flow line is used with a terminal symbol.

 In case of complex flowcharts, connector symbols are used to reduce the number of flow lines.
Benefits of Flowcharts

 A flowchart helps to clarify how things are currently working and how they could be
improved. The reasons for using flowcharts as a problem solving tool are given below.
 Makes Logic Clear
 Communication

 Effective Analysis
 Useful in Coding
 Proper Testing and Debugging
 Appropriate Documentation
Limitations of Flowcharts

 Flowchart can be used for designing the basic concept of the program in
pictorial form but cannot be used for programming purposes. Some of the
limitations of the flowchart are given as follows.
 Complex

 Costly

 Difficult to Modify

 No Update.
Control Structure of Flowcharts - Sequence

Start
Example of Flowchart
(Product of any two Numbers)
Start

Read A, B

C =A* B

Print C

Stop
Control Structure of Flowcharts - Selection

Is No
Condition is
True
Yes
Start

Read A, B, C

Example of Is A > B
No

Flowchart Yes
MAX = A MAX = B
(Finds the
Maximum of No
Is MAX > C
Three Numbers) Yes
Print MAX Print C

Stop
Control Structure of Flowcharts - Iteration

No Is
Condition is
True
Yes
Start

SUM = 0 & I = 0

Example of I=I+1
Flowchart SUM = SUM + I

(Find the
No
Sum of First Is I >=100

100 Integers) Yes


Print Sum

Stop
Thank You

You might also like