CSE1021-Introduction To Problem Solving and Programming
CSE1021-Introduction To Problem Solving and Programming
UNIT-1 Content
Introduction
What is problem solving
1. Analysing the
problem
2.
5. Debugging
Developing
the problem
the algorithm
3. CODING 4.Testing
1. Analysing the problem
It is important to clearly understand a problem before we begin to find the
solution for it.
If we are not clear as to what to be solved, we may end up developing a
program which may not solve our purposes.
Thus, we need to read and analyse the problem statement carefully in order to
list the principal components of the problem and decide the core functionalities
that our solution should have.
By analysing a problem , we would be able to figure out what are inputs that our
program should accept and the outputs that it should produce.
2. Developing An Algorithm
• JavaScript.
• Python. ...
• SQL. ...
• PHP. ...
• Ruby. ...
• C++ ...
• C Sharp. ...
• Visual Basic.
4. Testing and Debugging
The program should be created on various parameters. The
program should meet the requirements of the user. It must
respond within the expected time.it should generate correct
output for all possible inputs.
In the presence of syntax erors , no output will be obtained.
In case the output generated is incorrect, then the program
should be checked for logical errors.
Software industry follows standardized testing methods:-
Unit or component testing
Integration testing
System testing
Acceptance testing while developing complex applications.
UNIT-1 CONTENTS
Algorithm
Examples
Step for this examples are
Characteristics of a good algorithm
Difference between algorithm and
program
Algorithm
Algorithm
Start
peddling
Characteristics of a good algorithm
Algorithm
Start
peddling
Characteristics of a good algorithm
Q4. Find the area of a square if the length of the diagonal is 12cm?
Q5. The length of each side of a square is 5cm and the cost of painting
it is Rs. 5 per sq. cm. Find the total cost to paint the square?
Q1. Write an algorithm to find area of a square?
SOLUTION 1:
Step 1- Start
Step 2- Input side
Step 3- Area of square
Step 4- Print area
Step 5- Stop
Q3. Write an algorithm to find GCD (Greatest
Common Division) of two numbers 45 and 54?
It has been proven that any algorithm can be constructed from just three
basic building blocks. These three building blocks are:-
Sequence
Selection
Iteration.
sequence
INSTRUCTION
INSTRUCTION
INSTRUCTION
SELECTION
A selection ( also called a decision)is also one of the basic logic structures
in computer programming. In a selection structure, a question is asked, and
depending on the answer, the program takes one of two courses of action,
after which the program moves on to the next event.
selection
choice
instruction instruction
ITERATION
An iteration is a single pass through a group/set of instructions. Most programs
often contain loops of instructions that are executed over and over again. The
computer repeatedly executes the loop, iterating through the loop.
LOOPING
CHOICE
INSTRUCTION
REPRESENTATION OF ALGORITHM
PSEUDO
FLOWCHART
CODE
ALGORITHM
FLOWCHART
C=A+B
PRINT(C)
END
Q2. DRAW THE FLOWCHART TO FIND
SIMPLE INTEREST
START Input p ,r , t
Si= p*r*t/100
Si= p*r*t/100
Print(Si)
STOP
Q. DRAW THE FLOWCHART by using raptor
tool TO FIND AREA OF TRIANGLE WITH
ALGORITHM
FLOW CHART
IF…. Else
Decision
q. Draw the flow chart to print the smallest
number of two numbers
Input A, B
If A<B
Print(A)
Else
Print(B)
START
Input A,B
If
A<B YES Print A
?
Else
N
O
Print B
STOP
Q1. DRAW THE FLOW CHART TO FIND EVEN
OR ODD NUMBER
Pseudocode steps:-
Step 1:- input num 1
Step 2:- input num 2
Step 3:- compute result = num 1+ num 2
Step 4:- print result
START
Result= num1+num2
Print Result
Stop
Difference between algorithm and
pseudo code
Algorithm Pseudo code
1.Systematic logic approach to solve any 1.It is simple version of programming code
program. that does not require any strict programming
It is written in natural language. language syntax.
2. It has specific syntax of the programming 2. It does not have specific syntax like any of
language and can be executed on the programming language and thus
computer. cannot be executed on computer.
Q. Write an algorithm to calculate area and perimeter of a
rectangle, using both pseudocode and flowchart. Pseudocode for
calculating area and perimeter of a rectangle?
Q. Write an algorithm to calculate area and perimeter of a rectangle,
using both pseudocode and flowchart. Pseudocode for calculating
area and perimeter of a rectangle?
input length
input breadth
compute Area = length * breadth
print Area
compute Perimeter = 2 * (length + breadth)
Print perimeter
Programming language
•Machine
1.
language
•Assembly
2.
language
Machine language
ADA
C
C++
JAVA
BASIC
COBOL
PASCAL
PHYTON
Basic
#include<stdio.h>
int main(void)
{
printf("hello, world\n");
return 0;
}
C++
#include<iostream.h>
Int main
{
cout<<“hello world”<<endl;
return 0;
}
Pascal
Program HelloWorld(output);
begin
writeLn('Hello, World!’)
end.
Java
Hello, world!
Comparison between machine language,
assembly language and high level
language
Machine language Assembly language High level language
Time to Since it is the basic language of the A program called an A program called a
execute computer, it does not require any ‘assembler’ is required to compiler or interpreter is
translation, and hence ensures convert the program into required to convert the
better machine efficiency. This machine language. Thus, it program into machine
means the programs run faster. takes longer to execute than language. Thus, it takes
a machine language more time for a computer
program. to execute.
Time to Needs a lot of skill, as instructions are Simpler to use than machine Easiest to use. Takes less
develop very lengthy and complex. Thus, it language, though instruction time to develop programs
takes more time to program. codes must be memorized. It and, hence, ensures better
takes less time to develop program efficiency.
programs as compared to
machine language.
Language translator
compiler
An algorithm is said to have a logarithmic time complexity when it reduces the size of
the input data in each step.
This indicates that the number of operations is not the same as the input size. The
number of operations gets reduced as the input size increases.
Algorithms with Logarithmic time complexity are found in binary trees or binary search
functions.
This involves the search of a given value in an array by splitting the array into two and
starting searching in one split. This ensures the operation is not done on every
element of the data.
Quadratic time complexity
Best Averag
case e case
Worst
case
Space complexity
Big-oh
Big omega
theta
Example of big oh
Example:-f(n)= 2n+3<=10 *n
N=1
F(n)= 2*1+3<=10*1
5<=10 f(n)=o(n)
UNIT -1 END