UNIT 1 PSCP
UNIT 1 PSCP
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 3
Week - 1 Course
Outline
Lesson 1. What is Problem Solving? Why
should I learn?
Lesson 3. Algorithms
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 4
Course
Progress
Lesson 1.
Lesson 2.
Lesson 3.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 5
Problem solving is a general way to write solutions in
an orderly way to find solutions for problems.
This includes analyzing the potential causes of a problem and
finding action plan / solutions to the problem.
Everyone uses problem-solving skills both in their personal and
professional lives.
A good problem solving method involves a step by
procedure
step in giving solutions.
We will see some examples and solutions to the same in the
coming slides.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 6
Not all problems are solvable!
A problem is solvable only when there exist a procedure /
algorithm / steps that can be followed to solve it with definite
boundaries.
A problem is unsolvable if there is no definite procedure or
boundaries (where to start and stop) on the problem.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 7
Not all problems are solvable!
Number Scrabble Problem:
Number Scrabble is a game which is played with a set of
numbers from 1 to 9.
Every player picks a number from the list in their turn.
The number once taken cannot be taken again.
When a player picks and arranges the number in a way the
total horizontal, vertical or diagonal sums to 15, the player
wins.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 8
Not all problems are solvable!
Number Scrabble Problem:
As an example game between player A and player B:
• A picks 9.
• B picks 8.
• A picks 2.
• B has no choice but to pick 4 (otherwise, A could get
9+2+4=15).
• A has no choice but to pick 3 (otherwise, B could get
8+4+3=15).
• B picks 6, and thereby confirms to win by either picking 1
• Boundaries are defined (numbers from
(8+6+1=15) or 5 (4+6+5=15).
1- 9 can be used) and total 15
• Steps in the Game is defined
• This problem is solvable
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 9
Not all problems are solvable!
Tic-tac-toe:
Tic-tac-toe / noughts and crosses / Xs and Os, is a paper and
a pencil game played by two players, X and O are two
symbols that can be chosen by the player as their marks, who
take turns marking the spaces in a 3×3 grid.
A player who can successfully place the three of their own
symbols in a diagonal, horizontal, or vertical row wins the
game.
• computer buyers often spend too much time comparing hardware, and don't do enough
thinking and planning about the types of jobs their new computer will do.
• The textile manufacturer hadn't pinpointed his problem -- whether it was inventory
control or invoicing or process management -- so the computer couldn't be of much help.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 11
Not all problems are solvable!
A computer won't solve a poorly written or a big comprehensive problems.
Assume that one of your friend is depressed and not even ready to speak with you.
Can you give a solution by yourself?
Or Can you find a solution by programming a computer?
• No!
• Cannot find solutions for an undefined problem.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 12
Not all problems are solvable!
A computer won't solve any problems without proper boundaries for the data.
Assume that you are assigned to give a solution for car parking problem in Chennai.
Now we can see some of real word solvable problems with solutions.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 13
Let’s learn with real word examples
Assume that, one day suddenly lights go off during night.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 15
The Intelligence Quotient (I.Q) of a computer is zero!
A Computer will do the tasks accurately in the way in which we
tell them to do it.
In order for the system to do the task accurately, it is the
responsibility of the user to provide a clear instruction to the
computer.
A proper set of instructions comes only by understating the
problem and defining a well defined solution.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 16
Course
Progress
Lesson 1.
Lesson 2.
Lesson 3.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 17
From the previous examples, we can see that there is
a
Analyzing the
sequence of common process that happens in giving a solution.
Problem
The key steps can be classified and ordered as
Analyzing the problem
Developing a solution / algorithm Test the code / Developing an
debug Algorithm
Converting the solution to computer language(code)
Test the code for proper working
Convert to
Again, this process is not complete. The problems can arise
again / new problem may also arise / needs some Computer
maintenance Language
/ additions etc.. May happen.
The same cycle of steps need to be followed again to get the
new solutions
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 18
Analyzing the Problem
The first and the most important step in solving problem is
analyzing the problem
Analyzing the
If you are not clear in what need to be solved, you may end up Problem
with false solutions / creates new problems
At this point, there are two components that need Test the code / Developing an
to debug Algorithm
understood very clearly
The inputs that we use to identify the problem or in the
other way, the inputs the problem can understand Convert to
(the sound produced from the bicycle in previous example)
Computer
Exact expected solution / the outputs Language
(smooth and clear cycling for the previous example)
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 19
Developing an Solution / Algorithm
It is a best practice to formularize a solution before actually
implementing it.
Analyzing the
This can be represented in natural language Problem
or diagrammatically known as algorithms and flowcharts.
An algorithm is a set of well defined steps, to be followed to
Test the code / Developing an
achieve a solution. debug Algorithm
The diagrammatic representation of the steps involved is called
flowchart.
Convert to
There can be multiple ways to provide solution to a single
problem. Computer
Language
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 20
Developing an Solution / Algorithm
What do you think about making a Coffee?
Identify your inputs – coffee powder, sugar, milk, hot water, a cup,
spoon
Step 1: Add a teaspoon of Instant Coffee powder to your cup.
Step 2: If you like sugar you can add it now.
Step 3: Carefully pour the hot boiled water over the cup contents
almost to the half.
Step 4: Stir to ensure coffee and sugar are fully dissolved.
Step 5: Add your milk, cold/hot and stir.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 21
Developing an Solution / Algorithm
What do you think about making a Coffee?
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 22
Converting to computer language
Computer cannot understand a human language.
Analyzing the
It can understand only electronic signals as voltage levels, a Problem
representation in binary 0 is low voltage and a 1 is high voltage
In order to make the human computer interaction easier, we
are now provided with lot of programming languages like C, C++, Test the code / Developing an
C#, Java, Python etc., debug Algorithm
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 23
Converting to computer language
Converting the algorithm to computer understandable format,
a code/program is very easy once we learn the language Analyzing the
Problem
But it is very important to follow the syntax semantics and the
coding procedure
Test the code / Developing an
debug Algorithm
Convert to
Computer
Language
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 24
Testing and Debugging
Once the algorithms are converted to programs, the process is
not over. Analyzing the
Problem
We have met some solutions, but we have to test the same to
see whether we achieved the expected results, like what we did
in the Step 6 of coffee making. (Tasting to add / reduce coffee
power / sugar in the next preparation) Test the code / Developing an
debug Algorithm
We should always test for all the extreme conditions and inputs
that we can provide to know the proper working.
Convert to
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 25
Course
Progress
Lesson 1.
Lesson 2.
Lesson 3.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 26
All the activities in our life has some sequence of steps.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 27
Some important factors to be considered while writing algorithm
Algorithm must be Finite
Any algorithm written must terminate after a finite number of steps
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 28
Example : 1
Compute the area and perimeter of a rectangle. length=10
breadth=20
Step 1: Analyze and find the inputs length and breadth
Area =length * breadth
Compute the solution Area = length * breadth =10 * 20
Print the result - Area =200
Perimeter =2 (length + breadth)
Compute the Solution Perimeter = 2 * (length + breadth)
=2 * (10+20)
Print the result – Perimeter =2 * 30
= 60
End of the program
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 29
Example : 2
Find the average of three numbers. a = 10, b=20, c=30
sum =a+b+c
Step 1: Get the inputs. Let it be a, b, c
=10+20+30
Compute the sum of a,b,c =60
Divide the sum by 3 (number of numbers) Average=sum / 3
=60 / 3
Print the result
=20
End of the program
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 30
Example : 3
Find the largest of three numbers. a = 10, b=20, c=30
If 10 > 20
Step 1: Get the inputs. Let it be a, b, c
greatest = 10
Check if a>b, then greatest =a else greatest =b else
Check if greatest < c, then greatest =c greatest = 20
Print greatest
If greatest < 30
End of program greatest =30
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 31
Course
Progress
Lesson 1.
Lesson 2.
Lesson 3.
Lesson 4.
Lesson 5. Flow
Control
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 32
Once the algorithm is defined, there are two common methods
to represent the algorithm
Flowcharts
This is a visual representation of an algorithm
This uses some specific shapes for specific operation tin the
algorithm
Examples for the same in future slides
Pseudocode
This is a non formal language
It uses some keywords to represent the algorithm in a non
formal way.
We will see the examples in next slide
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 33
Flowcharts
Symbols are used to represent operations
Symbol Function Description
Start / End This symbol indicates where the flow of the problem starts
and ends
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 34
Pseudocode
A simple implementation of algorithm in terms of annotations and text
written in plain English.
This improves the readability, makes the code conversion easier
There are some frequently used keywords to represent a pseudocode
INPUT -> to get inputs
COMPUTE -> to do arithmetic calculations or computations
INCREMENT -> increment a value
DECREMENT -> decrement a value
IF/ELSE -> to check conditions
WHILE -> to repeat some statements
PRINT -> to show outputs
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 35
Pseudocode
Pseudo code for the previous example: finding area
and perimeter of a rectangle:
INPUT length
INPUT breadth
COMPUTE Area = length * breadth
PRINT Area
COMPUTE Perimeter = 2 * (length
+ breadth)
PRINT Perimeter
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 36
Flowcharts
Lets see the flowchart for the Start
previous example to calculate area
and perimeter of a rectangle Input: length,
breadth Perimeter =2 * (length +
breadth)
INPUT length
INPUT breadth Area=length * breadth
COMPUTE Area = length * breadth
Print Perimeter
PRINT Area
COMPUTE Perimeter = 2 * (length
+ Print Area
breadth) Stop
PRINT Perimeter
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 37
Activiti
es
Write an pseudocode, flowchart to find the area of the triangle. – Pseudocode
START
INPUT A,B,C
CALCULATE S = (A + B + C ) / 2
CALCULATE AREA = SQRT( S*(S-A)*(S-B)*(S-C))
PRINT AREA OF TRIANGLE= AREA
END
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 38
Activiti
es
Start
Write an pseudocode, flowchart to find the
area of the triangle.
Input: a,b,c
-- Flowchart s=(a+b+c)/2
Area=sqrt(s*(s-a)*(s-b)*(s-c))
Print Area
End
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 39
Activiti
es
Write an pseudocode, flowchart to find the largest of three numbers X, Y,Z.
STEP 1 : START
STEP 2 : INPUT A, B, C
STEP 3 : IF A > B GOTO STEP 4, OTHERWISE GOTO STEP 5
STEP 4 : IF A > C GOTO STEP 6, OTHERWISE GOTO STEP 8
STEP 5 : IF B > C GOTO STEP 7, OTHERWISE GOTO STEP 8
STEP 6 : OUTPUT "A IS THE LARGEST", GOTO STEP 9 STAR
STEP 7 : OUTPUT "B IS THE LARGEST", GOTO STEP 9
START STEP 8 : OUTPUT " C IS THE LARGEST", GOTO STEP
9 START 9 : STOP
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 40
Activiti
es
Write an pseudocode, flowchart to find the largest of three numbers X, Y,Z.
Start
Ye
b>c s
Input: a,b,c
No
Ye A>b No
Print C Print b
s
and
Print A
a>c End
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 41
Activities –
to do
Write an algorithm, pseudocode, flowchart which will test whether a given integer value is prime or
not.
Write algorithm pseudocode, flowchart to find the factorial of a given number N
Write a pseudo code to perform the basic arithmetic operations.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 42
Course
Progress
Lesson 1.
Lesson 2.
Lesson 3.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 43
Flow
Control
Flow control represents some sequence of events as represented in flowchart
Computer executes the program sequentially one after the another in the prescribed steps, we code to
follow.
While writing algorithms and programs too, we should strictly follow the flow control.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 44
Flow
Control
Start
Sequential Execution:
Examine this case.
The statements are executed one after Input: a,b,c
the another in a sequence
Such kind of execution is called s=(a+b+c)/2
sequential execution
This may not be case for all the time,
Area=sqrt(s*(s-a)*(s-b)*(s-c))
there are cases where some statements
need to executed and some need to be
skipped Print Area
We will see those in next slide
End
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 45
Flow
Control
Selection:
There may be some cases where we
have to follow one route in the
flowchart / algorithm and skip the other
This is similar to finding one of the START
INPUT number
possible 3-4 routes in a google map to
IF number MOD 2 == 0 THEN
reach a destination from a source
PRINT "Number is Even"
let us see this with an example. ELSE
Assume that we need to find whether a PRINT "Number is Odd"
given number is odd / even END
See the steps involved in this.
See the if-else part only one statement
is executed at any point of time
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 46
Flow
Control
Start
Flowchart representing the selection
Input: number
STAR
TINPUT number No
Ye If number
IF number MOD 2 == 0 THEN s mod 2==0 ?
PRINT "Number is Even"
ELSE
PRINT "Number is Odd"
END Print “Even” Print “ODD”
End
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 47
Flow
Control
Let us see an another example where multiple conditions are checked to categorize a person as
either child (<13), teenager (>=13 but <20) or adult (>=20),based on age specified
INPUT Age
IF Age < 13 THEN
PRINT "Child"
ELSE IF Age < 20
THEN
PRI
NT
"Teenager"
ELSE
PRI
NT "Adult"
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 48
Flow
Control
Flow chart representation Start
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 50
Flow
Control
Repetition
Finding the average of five numbers:
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 51
Flow
Control
Repetition Start
End
Count = count + 1
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 52
Flow
Control
Repetition
accept numbers till the user enters 0 and then find their average:
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 53
Flow
Control
Start
Repetition
accept numbers till the user enters 0 count=0, sum=0
and then find their average:
Input number
Step 1: SET count = 0, sum = 0 Ye
Step 2: INPUT num Number == 0?
s
Step 3: WHILE num is not equal to 0,
REPEAT Steps 4 to 6 No Average=sum/count
Step 4: sum = sum + num Sum = sum + number
Step 5: count = count +
Print average
1 Step 6: INPUT num
Step 7: COMPUTE average = sum/count Count = count + 1
Step 8: PRINT average End
Input number
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 54
Course
Progress
Lesson 1.
Lesson 2.
Lesson 3.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 55
Verifying
Algorithms
Image a situation where your solution / the algorithm goes wrong
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 56
Verifying
Algorithms
So, how can we verify the algorithm / code is working fine?
This is an important part to be done by every software engineer before releasing the application.
For example, assume we are finding the sum of natural numbers. We use the formula n(n+1)/2 to get
the results.
How will we check the correctness in the equation?
We use to provide some sample inputs to check it, possibly small numbers
For n= 3, => 1+2+3=6
3(3+1)/2 => 3(4)/2 => 12/2 => 6
The results will be verified with multiple inputs
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 57
Verifying
Algorithms
Similar to this way, we have to provide all possible inputs to the algorithm and check the proper working
Task:
Take any two previous algorithms and check for correctness
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 58
Verifying Algorithms – Multiple
Solutions
There may be more than one method to solve a given problem
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 59
Verifying Algorithms – An
Example
Find whether a given number is prime or not.
There can be four different ways to write algorithms to check whether a given number is prime or not
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 60
Verifying Algorithms – Example
Algorithm i,ii
Algorithm (i)
Starting with divisor 2, divide the given number (dividend) and check if there are any factors.
Increase the divisor in each iteration and repeat the previous steps as long as divisor < dividend.
If there is a factor, then the given number is not prime
Algorithm (ii)
In (i), instead of testing all the numbers till the dividend, only test up to half of the given
value(dividend) because the divisor can not be more than half of the dividend
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 61
Verifying Algorithms – Example
Algorithm iii,iv
Algorithm (iii)
In method (i), only test up to the square root of the dividend (numbers)
Algorithm (iv)
Given a prior list of prime number till 100, divide the given number by each number in the list.
If not divisible by any number, then the number is a prime else it is not prime
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 62
Comparison of
Algorithm
Algorithm (i) requires large number of calculations
(means more processing time) as it checks for all the numbers as long as the divisor is less than the
number.
If the given number is large, this method will take more time to give the output.
Algorithm (ii) is more efficient than (i) as it checks for divisibility till half the number, and thus it reduces
the time for computation of the prime number.
Algorithm (iii) is even more efficient as it checks for divisibility till square root of the number, thereby
further reducing the time taken
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 63
Comparison of
Algorithm
As algorithm (iv) uses only the prime numbers smaller than the given number for divisibility, it further
reduces the calculations.
But in this method we require to store the list of prime numbers first.
Thus it takes additional memory even though it requires lesser calculations.
Hence, algorithms can be compared and analyzed on the basis of the amount of processing time they
need to run and the amount of memory that is needed to execute the algorithm.
These are termed as time complexity and space complexity, respectively.
The choice of an algorithm over another is done depending on how efficient they are in terms of
processing time required (time complexity) and the memory they utilize (space complexity).
The best choice is Minimal time complexity with Minimal Memory usage
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 64
Codi
ng
Once an algorithm is finalized, it should be coded in a high-level programming language as selected by
the programmer.
The ordered set of instructions are written in that programming language by following its syntax.
Syntax is the set of rules or grammar that governs the formulation of the statements in the language,
such as spellings, order of words, punctuation, etc.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 65
Codi
ng
The machine language or low level language consisting of 0s and 1s only is the ideal way to write a
computer program.
Programs written using binary digits are directly understood by the computer hardware, but they are
difficult to deal with and comprehend by humans.
This led to the invention of high-level languages which are close to natural languages and are easier
to
read, write, and maintain, but are not directly understood by the computer hardware.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 66
UNIT-1: Overall
Problem Solving
Summary
Algorithm
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 67
WEEK – 3 / IMPORTANCE
Problem Solving OF PROGRAMMING IN
PROBLEM SOLVING,
using Computer EXPRESSING
ALGORITHMS IN
Programming PSEUDOCODE .
© Kalasalingam Academy of Research and Education
Course
Progress
Lesson 1.
Lesson 2.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 69
Computer is an electronic device which is used to store the
data,
as per given instructions it gives results quickly and accurately.
Data : Data is a raw material of information.
Information : Proper collection of the data is
called
information.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 70
Characteristics of Computer
Speed of Computer:
Computers in general can work very fast.
For the calculations we do for hours, computers can easily
solve in few seconds.
Computers can execute millions of instructions ie., 1,00,000
instructions or even more in a second.
This is the reason why speed of the computers
are represented in milliseconds.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 71
Characteristics of Computer
Accuracy of a computer:
The accuracy of the computers are very high. Each and every
calculations are done with same accuracy in minimal time.
The level of accuracy always depends on the design of the
computer.
There may be some errors in the accuracy. This is mainly
due
to the improper data and logic fed to the computer
systems.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 72
Characteristics of Computer
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 73
Characteristics of Computer
Versatility of a computer:
This the capability of a computer to do different kinds of
work following the same logic/solution.
Assume you may use your computer to do some arithmetic.
See the next time this same arithmetic operations may be
used in Mark average calculations, CGPA calculations, etc..
Same arithmetic module can be now reused in different
places in different applications.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 74
Characteristics of Computer
Power of Remembering:
The big plus point of computer is its memory power. It can
store any amount od data.
Any kind of information can be stored and retrieved from a
computer even if you require it after years.
This entirely depends on how you store the information and
in what methods you retrieve and how frequent you access
the information.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 75
Characteristics of Computer
No IQ:
As already discussed, computer cannot think by itself or it is
a dumb machine.
It can compete the tasks faster and accurate. But you have to
tell the machine how to do it!
So it is with the designer of the computer system to decide
how to give instructions, and in which sequence it need to be
processed.
So it cannot a decision by its own. You are the decision makes
of a computer.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 76
Characteristics of Computer
Storage Devices:
A Computer system has built-in memory called RAM, ROM
where it can store a large amount of data.
The data can be also stored in secondary storage devices lik e
floppies, hard disc compact disc which can be kept outside
and even can be moved to other computers.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 77
Course
Progress
Lesson 1.
Lesson 2.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 78
Computers in Education :
Nowadays computer are playing a major role in
education.
We use computers to learn classes through online mode
We use computers to search for learning courses
materials and videos resources in learning new
technology
We use computer to register for courses
We use computers to check results and download
statements
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 79
Computers in Health and Medicine
Medical field is changing drastically with introduction to computer
devices.
Nowadays all medical information are available in digital format.
Several softwares are available to analyze the information and
predict the diseases and cause of diseases.
One example is treatment for a paralyzed patients. A paralyzed
patient is implanted with devices that can allow communication
between the brain of the patient and a computer systems; there by
the messages from the patient can be understood.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 80
Computers in Science :
Scientists are the users of computers for a long time.
The idea of scientists is doing collaborative works on the
same field. By doing so, researches all over the word can
participate and share their idea and views and work together
to find solutions to complex research problems.
One such example is the space research. To analyze the
ionosphere from all the parts of the world, a single
researcher sitting on s single location cannot solve the
problem. Now researchers from all over the world doing the
task and communicate through a web platform can solve the
problem very easily.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 81
Computer in Business :
All the business is now on the internet or on computers. This
enhances their productivity and enhance their business.
Some examples of business that are completed dependent
on computers are Banks, sales and marketing, retailing, stock,
trading, etc.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 82
Computer in Government:
Various departments of the Government use computer for
their planning, control and law enforcement activities.
To name a few – Police, Tourism, Information & Broadcasting,
Education, Aviation and many others.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 83
Course
Progress
Lesson 1.
Lesson 2.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 84
Types of
Computer
TYPES OF COMPUTERS or Classification of Computers
Super Computers
Main Frame Computers
Mini Computers
Micro Computers
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 85
Types of
Computer
Super Computers
Most powerful Computer system - needs a large room
Minimum world length is 64 bits
CPU speed: 100 MIPS
Equivalent to 4000 computers
High cost: 4 – 5 millions E.g.:-
Able to handle large amount of data CRAY Research :- CRAY-1 & CRAY-2,
Fujitsu (VP2000),
High power consumption
Hitachi (S820),
High precision NEC (SX20),
PARAM 10000 by
C-DAC,
Anupam by BARC,
PACE Series by DRDO
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 86
Types of
Computer
Supercomputer - Applications
petroleum industry – In order to explore where petroleum
products are rich in the earth, the volume the quality etc are
analyzed by super computers.
In Aerospace industry - to simulate airflow around an aircraft at
different speeds and altitude. This helps in producing an
effective aerodynamic design for superior performance
In Automobile industry – to do crash simulation of the design E.g.:-
CRAY Research :- CRAY-1 & CRAY-2,
of an automobile before it is released for manufacturing – for Fujitsu (VP2000),
better automobile design Hitachi (S820),
NEC (SX20),
PARAM 10000 by
C-DAC,
Anupam by
BARC,
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 87
PACE Series by
Types of
Computer
Mainframe Computers
Able to process large amount of data at very high speed
Supports multi-user facility
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 88
Types of
Computer
Mainframe Computers - Applications
Used to process large amount of data at very high speed such
as in the case of Banks/ Insurance Companies/ Hospitals/
Railways
Large number of requests can be processed at the same time
and Massive storage capability
Used as controlling nodes in WANs (Wide Area Networks)
E.g.:-
Used to mange large centralized databases IBM 3000 series,
Burroughs B7900,
Univac 1180, DEC
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 89
Types of
Computer
Minicomputers
Perform better than micros
Large in size and costlier than micros
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 90
Types of
Computer
Minicomputers – Applications
When there is a large requirement for processing large
volume of information. e.g. Data processing for a medium sized
organization
Used to control and monitor production processes
C
o
m
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING m 91
Types of
Computer
Microcomputers
As compared to supercomputers, mainframes and minicomputers,
microcomputers are the least powerful.
It is having single processor but these are very widely used and
rapidly gaining in popularity.
It comprises of a keyboard, mouse, monitor and system unit. The
system unit is also known as cabinet or chassis.
It is the container that houses most of the components such as
motherboard, disk drives, ports, switch mode power supply and
add-on cards etc.
The desktop computers are available in two models- horizontal
model and tower model.
E
.
g
.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING : 92
Types of
Computer
Microcomputers - Applications
Used in the field of desktop publishing, accounting,
analysis,
statistical graphic designing, investment analysis, project
management, teaching, entertainment etc
Personal computers:- The name PC was given by the IBM for its
microcomputers. PCs are used for word processing, spreadsheet
calculations, database management etc.
Note book or Lap Top:- Very small in terms of size – can be folded
and carried around – Monitor is made up of LCD and the keyboard
and system units are contained in a single box. Got all the facilities
of a personal computer (HDD, CDD, Sound card, N/W card, Modem
etc) and a special connection to connect to the desktop PC which
can be used to transfer data. E.g.:-
Normal Desktops / Laptops
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 93
Course
Progress
Lesson 1.
Lesson 2.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 94
The first computer technology was Vacuum Tubes
designed by University of Pennsylvania.
Vacuum tubes were used to perform logic operations
and also to store information.
Generations of computers has been divided into five
according to technologies used to fabricate the
processors, memories and I/O units.
I Generation : 1945 – 55
II Generation : 1955 – 65
III Generation : 1965 – 75
IV Generation : 1975 – 89
V Generation : 1989 to present
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 95
I Generation : 1945 –
55
Vacuum tubes were used – basic arithmetic operations took
few milliseconds
Bulky, Consume more power with limited performance, High
cost
Uses assembly language – to prepare programs. These were
translated into machine level language for execution.
Mercury delay line memories and Electrostatic memories were ENIAC - Electronic Numerical Integrator And
Calculator
used
Fixed point arithmetic was used ENIAC - Electronic Numerical Integrator And Calculator
EDSAC – Electronic Delay Storage Automatic Calculator
EDVAC – Electronic Discrete Variable Automatic Computer
UNIVAC – Universal Automatic Computer
IBM 701
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 96
I Generation : 1945 –
55
100 to 1000 fold increase in speed relative to the earlier
mechanical and relay based electromechanical technology
Punched cards and paper tape were invented to feed programs
and data and to get results.
Magnetic tape and magnetic drum were used
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 97
II Generation : 1955 –
65
Transistors were used in place of vacuum tubes. (invented at
AT&T Bell lab in 1947)
Small in size, Lesser power consumption and better
performance, Lower cost
Magnetic ferrite core memories were used as main
memory
which is a random-access nonvolatile memory
Magnetic tapes and magnetic disks were used as secondary
IBM 7030
memory
Manufacturers – IBM 7030,
Hardware for floating point arithmetic operations was Digital Data Corporation’s PDP 1/5/8
developed. Honeywell 400
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 98
II Generation : 1955 –
65
Index registers were introduced which increased flexibility of
programming.
Compilers were introduced to translate high level to machine
code. High level languages FORTRAN, COBOL were used
1000 fold increase in speed.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 99
III Generation : 1965 –
75
ICs were used
Small Scale Integration and Medium Scale Integration
technology were implemented in CPU, I/O processors etc.
Smaller & better performance Comparatively lesser cost,
Faster processors
In the beginning magnetic core memories were used. Later
they were replaced by semiconductor memories (RAM & ROM)
Introduced microprogramming, Microprogramming, parallel IBM System 360
processing (pipelining, multiprocessor system System 360 Mainframe from IBM,
multiprogramming,
etc), multi-user system (time shared system) etc PDP-8 Mini Computer from Digital
were introduced. Equipment Corporation
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 100
III Generation : 1965 –
75
Operating system software were introduced (efficient sharing
of a computer system by several user programs)
A small memory in the chip called Cache and virtual memory
concepts were introduced
High level languages were standardized by ANSI eg. ANSI
FORTRAN, ANSI COBOL etc
Database management, multi-user application, online systems
like closed loop process control, airline reservation, interactive
IBM System 360
query systems, automatic industrial control etc emerged during
this period. System 360 Mainframe from IBM,
PDP-8 Mini Computer from Digital
Equipment Corporation
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 101
IV Generation : 1975 –
89
Single Chip units called Microprocessors were ues as CPU
Tens of thousands of transistors can be placed in a single chip
(VLSI design implemented)
Mani memory were developed using Semiconductor chips.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 102
IV Generation : 1975 –
89
Introduced C language and Unix OS
Introduced Graphical User Interface
IBM PC AT
Intel’s 8088,80286,80386,80486 ..,
Motorola’s 68000, 68030, 68040,
Apple II,
CRAY I/2/X/MP etc
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 103
V Generation : 1989 to present
Generation after IV and to current are Generation V computers.
Computers based on artificial intelligence are available
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 105
Course
Progress
Lesson 1.
Lesson 2.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 106
Common Organization of
Computer
Basic Computer Organization
Basic elements of a computer system are
Mouse,
Keyboard,
Monitor,
Memory,
CPU,
Motherboard,
Hard Disk,
Speakers,
Modem,
power supply and
processor.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 107
Common Organization of
Computer
Basic Computer Organization – The Block Diagram
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 108
Common Organization of
Computer
Basic Computer Organization – The Block Diagram
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 109
Course
Progress
Lesson 1.
Lesson 2.
Lesson 4.
Lesson 6.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 110
As seen earlier, follow the initial steps:
Step 1: Identify and define the problem
State the problem as clearly as possible.
For example: “I have to register for my
upcoming semester courses.”
Analyze the behavior, situation, timing,
and circumstances that made it as a
problem.
For example: The number of slots available, courses available, maximum strength of a batch are
boundaries or conditions
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 111
As seen earlier, follow the initial steps:
Step 2: Generate possible solutions
List all the possible solutions; don’t worry about the quality of the solutions at this stage.
Try to list at least 5-10 solutions, be creative and forget about the quality of the solution.
Always allow yourself creative and fid some solutions
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 112
As seen earlier, follow the initial steps:
Step 3: Evaluate alternatives
Eliminate less required or irrational solutions.
Find the best optimal solutions from the set of solutions
Take care of memory limits
Take care of Speed (No of lines for execution)
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 113
Modular Approach for Programming :
The process of breaking a large problem into subproblems and then treating these individual parts
as different functions is called modular programming.
Each function behaves independent of another and there is minimal inter-functional
communication. There are two methods to implement modular programming :
Top Down Approach
Bottom Up Approach
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 114
Modular Approach for Programming :
Top Down Design :
In this method, the original problem is divided into subparts.
These subparts are further divided.
The chain continues till we get the very fundamental subpart of the problem
which can’t be further divided.
Then we draw a solution for each of these fundamental parts.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 115
Modular Approach for Programming :
Bottom Up Design :
In this style of programming, an application is written by using the pre-
existing primitives of programming language.
These primitives are then amalgamated with more complicated features,
till the application is written.
This style is just the reverse of the top-down design style.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 116
Pseudocodes:
Pseudocode is a way to represent the required steps to solve any problem in
a way that it is easy to understand any one with minimal programming
knowledge.
Main constructs
SEQUENCE this denotes linear tasks that need to be sequentially performed one after the other.
WHILE a loop with a condition at its beginning.
REPEAT-UNTIL a loop with a condition at the bottom.
FOR another way of looping.
IF-THEN-ELSE a conditional statement that can change the flow of the sequence.
CASE the generalization form of IF-THEN-ELSE.
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 117
Pseudocodes - Examples:
Create a program to add 2 numbers together and then display the
result.
Start Program
Enter two numbers, A, B
Add the numbers together
Print Sum
End Program
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 118
Pseudocodes - Examples:
Compute the area of a rectangle:
Get the length, l, and width, w
Compute the area = l*w
Display the area
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 119
Pseudocodes - Examples:
Compute the perimeter of a rectangle:
Enter length, l
Enter width, w
Compute Perimeter = 2*l + 2*w
Display Perimeter of a rectangle
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 120
Overall
UNIT-1:
Summary
Basic of Computer
Problem Solving
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 121
Referenc
es
• https://onlinecourses.nptel.ac.in/noc21_cs01/preview (Problem solving through Programming In C By Prof.
Anupam Basu, IIT Kharagpur )
• https://www.coursera.org/learn/computational-thinking-problem-solving (Computational Thinking for
Problem Solving By Susan Davidson, Penn University [coursera])
© Kalasalingam academy of research and education PROBLEM SOLVING USING COMPUTER PROGRAMMING 122
Thank
You!
© Kalasalingam Academy of Research and Education PROBLEM SOLVING USING COMPUTER PROGRAMMING 123