PPS 123
PPS 123
FOR PROBLEM
SOLVING
Lecture – 1, 2 & 3
Dr. S.Kanungo
Dept. of CSE, BIT Mesra
Course Objectives
• This course enables the students:
➢ To learn computer language
➢ To learn coding for problems
➢ To learn the problem-solving process
through computer
➢ To know the limitations of system during
program execution
Problem Solving
• It is an intricate process requiring much
thought, careful planning, logical precision,
persistence, and attention to detail.
• It can be a challenging, exciting, and satisfying
experience with considerable room for personal
creativity and expression.
• It is about understanding the problem
• Focus on: What must be done rather than how to
do it.
• Problem definition phase: Preliminary
Investigation
• Note: “Sooner you start coding your program the
longer it is going to take”
• The success of a computer in solving a
problem depends on how correctly and
precisely we define the problem, design
a solution (algorithm) and implement
the solution (program) using a
programming language.
• It is the process of identifying a
problem, developing an algorithm for
the identified problem and finally
implementing the algorithm to develop
a computer program.
Steps for Problem Solving
• Analysing the problem: To read and analyse
the problem statement carefully to list the
principal components of the problem and decide
the core functionalities that our solution should
have.
• Developing an algorithm: The solution is
represented in natural language and is called an
algorithm.
• Coding: To convert the algorithm into the format
which can be understood by the computer to
generate the desired solution.
• Testing and debugging: Error handling
Elements of a Computer System
• Hardware
➢ Equipment used to perform the
necessary computations and includes
the central processing unit (CPU),
monitor, keyboard, mouse, printer and
speakers.
• Software
➢ Consists of the programs that enable us
to solve problems with a computer by
providing it with lists of instructions to
perform.
Components of a Computer
• Memory
➢Ordered sequence of storage locations
called memory cells.
➢Each memory cell has a unique address
that indicates its relative position in
memory.
➢Data stored in a memory cell are called the
contents of the cell.
➢The ability to store programs as well as data is
called the stored program concepts: A program’s
instructions must be stored in main memory
before they can be executed.
➢A memory cell is a grouping of smaller units
• Central Processing Unit (CPU)
➢Two roles: Coordinating all computer
operations and performing arithmetic and
logical operations on data.
➢To process a program stored in main
memory:
➢ It retrieves each instruction in sequence,
interprets the instruction to determine what
should be done, and then retrieves any data
needed to carry out that instruction.
➢Next, it performs the actual manipulation,
or processing of the data it retrieved.
➢It stores the results in main memory
Operating System
• The collection of computer programs that control
the interaction of the user and the computer
hardware.
• Some responsibilities
➢Communicating with the computer user: receiving commands
and carrying them out or rejecting them with an error message.
➢ Managing allocation of memory, of processor time, and of
other resources for various tasks.
➢ Collecting input from the keyboard, mouse, and other input
devices, and providing this data to the currently running
program.
➢Conveying program output to the screen, printer, or other
output device.
➢ Accessing data from secondary storage.
➢Writing data to secondary storage.
• Entering, Translating, and Running a HLL Program
• Flow of information during the execution of a
water bill program
Programs and Algorithms
• Program: A set of explicit and unambiguous
instructions expressed in a programming
language.
• Algorithm
➢Solution to a problem that is independent
of any programming language.
➢Consists of a set of explicit and
unambiguous finite steps which, when
carried out for a given set of initial
conditions, produce the corresponding
output and terminate in a finite time.
➢Example: Find Greatest Common Divisor
(GCD) of two numbers 45 and 54.
Note: GCD is the largest number that divides both
the given numbers.
Step 1: Find the numbers (divisors) which can
divide the given numbers
Divisors of 45 are: 1, 3, 5, 9, 15, and 45
Divisors of 54 are: 1, 2, 3, 6, 9, 18, 27, and 54
Step 2: Then find the largest common number from
these two lists.
Therefore, GCD of 45 and 54 is 9
➢ We need to follow a sequence of steps to
accomplish the task.
➢Algorithm has a definite beginning and a definite
end and consists of a finite number of steps.
➢The programmer first prepares a roadmap of the
program to be written, before writing the code.
➢Characteristics of a good algorithm
▪ Precision: the steps are precisely stated or
defined.
▪ Uniqueness: results of each step are uniquely
defined and only depend on the input and the
result of the preceding steps.
▪ Finiteness: the algorithm always stops after a
finite number of steps.
▪ Input: the algorithm receives some input.
▪ Output: the algorithm produces some output.
➢While writing an algorithm, it is required to clearly
identify the following:
▪ The input to be taken from the user
▪ Processing or computation to be performed to
get the desired result
▪ The output desired by the user
➢ Representation of Algorithms
▪ Flowchart and Pseudocode
• it showcases the logic of the problem solution,
excluding any implementational details
• it clearly reveals the flow of control during
execution of the program
• Flowchart
➢A visual representation of an algorithm
➢Shapes or symbols to draw flow charts:
Start/End: Also called “Terminator” symbol.
It indicates where the flow starts and ends.
Process: Also called “Action Symbol,” it
represents a process, action, or a single step.
Decision: A decision or branching point, usually a
yes/no or true/ false question is asked, and based
on the answer, the path gets split into two
branches.
Input/Output: Also called data symbol, this
parallelogram shape is used to input or output data
Arrow: Connector to show order of flow between
shapes.
• Write an algorithm to find the square of a number
➢Input: Number whose square is required
➢Process: Multiply the number by itself to get its
square
➢ Output: Square of the number
• printf()
• scanf()
• return()
• Arithmetic operators
• Mathematical Formulas as C Expressions