Introduction to problem solving: Steps for problem solving (analysing the problem, developing an algorithm, coding, testing and debugging). representation of algorithms using flow chart and pseudo code, decomposition
Problem Analysis in Computer programming is a way where problems are discussed for giving the solution. We define data ,input and output of our program
Debugging:-
Debugging refers to the process of locating the place of error. cause of error, and correcting the code accordingly.
Coding
The coding is the process of translate the algorithm into a programming language. This coding phase of software development is concerned with software translating design specification into the source code. Coding is done by the coder or programmers who are independent people than the designer. The cost of testing and maintenance can be significantly reduced with efficient coding.
Testing
Testing is the process of executing a program with the aim of finding errors. To make our software perform well it should be error-free. If testing is done successfully it will remove all the errors from the software.
Algorithm
An Algorithm is a step by step procedure to solve a given problem.
For example, the algorithm to find the remainder of given two numbers is:
1. Input first the number.
2. Input second number.
3. Divide first number with second number and store the remainder as
third number.
4. Display the result.
It is a set of ordered and finite steps to solve a given problem.
An algorithm should always have a clear stopping point.
Qualities of a good algorithm
1.Inputs and outputs should be well defined .
2.Each steps in algorithm should be clear.
3.Algorithm should be most effective to solve a problem.
4.An algorithm shouldn't have computer code. Instead, the algorithm should be written in such a way that, it can be used in all programming languages.
Write an algorithm to add two numbers entered by user.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2 Step
Stop 5: Display sum
Step 6: Stop
Write an algorithm to find the factorial of a number entered by user.
Step 1: Start
Step 2: Declare variables n,factorial and i.
Step 3: Initialize variables
factorial=1
i=1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
factorial=factorial*i
i=i+1
Step 6: Display factorial
Step 7: Stop
Flow diagram of an algorithm
Flowchart is a diagrammatic or pictorial representation of an step by step solution of a problem.
Flowchart are very helpful in writing program and explaining program to others.
It show the flow of program execution.
Flowchart are useful in efficient coding, debugging and analysis of a program, drawing flowchart in very complicated in case of complex programs and often ignored.
Symbols Used in Flow Chart
Flow chart to add 2 numbers
Calculate average of 5 numbers
Problem Solving using Decomposition
The process of breaking down a complex problem into smaller parts that are more manageable and easier to understand a problem or situation better is known as decomposition .
The smaller parts can then be examined and solved, or designed individually, as they are simpler to work with.
Pseudocode :
Is informal way of describing the steps of a program's solution without using any strict programming language syntax.
In Pseudocode , usually the instructions are written in upper case , variables in lowercase and messages are in sentence case.
Advantages of pseudocode –
• Pseudocode is understood by the programmers of all types.
• it enables the programmer to concentrate only on the algorithm part of the code development.
• It cannot be compiled into an executable program.
Disadvantages :
It is not a visual tool like flowchart
It is an informal representation of an algorithm
Example,
Java code : if (i < 10) { i++; }
pseudocode :
if i is less than 10, increment i by 1.
Another example
Example:
if "1"
print response
"I am case 1"
if "2"
print response
"I am case 2"