Computational
Problem Solving
Introduction
Amrita School of Computing, Amritapuri
Background
• Computer Science: the study of computational processes
• Data: a collection of information, facts, or statistics.
• Data can be the digital information that computers process,
store, and manipulate.
• Computation: manipulation of data by some systematic
procedure carried out by some computing agent.
Computational Problem Solving
● Computational problem solving
○ Using techniques to express problems and their solutions in ways
that a computer could execute.
● Why?
○ To automate the problem solving process
○ Harness the tremendous computing power
○ Less manpower
○ Can be used to solve really big problems
What is a computer?
• A computer is an electronic device that manipulates information, or
data.
• Computers execute instructions that are written in a programming
language.
• It consists of various hardware components and software programs
• that work together to perform a wide range of tasks, from simple calculations to
complex data analysis and simulations
Computer Hardware
• Computer hardware comprises the
physical part of a computer system.
• It includes the all-important components
of the central processing unit (CPU) and
main memory.
• It also includes peripheral components
such as a keyboard, monitor, mouse, and
printer.
• Software is a set of instructions that can
be stored and run by hardware.
• A combination of hardware and software
forms a usable computing system.
Fundamental hardware components
CPU – The brain of the computer that interprets and executes digital
instructions from various programs.
RAM/Main memory/Temporary memory –
Currently executing programs reside in RAM
CPU can directly and very quickly access RAM
Volatile memory
Secondary memory:
Nonvolatile
Long-term storage of programs and data.
Eg: Hardrive, CD or DVD, USB
• Input/output devices
Buses - transfer data between components within a computer system, such as
between the CPU and main memory
Fundamental hardware components
Operating Systems—Bridging Software and Hardware
• Referred to as system software.
• Managing and interacting with the hardware
resources of a computer.
• Acts as the “middle man” between the
hardware and executing application
programs.
• Determines the “look and feel” of the user
interface and how the user interacts with the
system,
What is a Computer Program
• What is a computer program?
• A detailed, step-by-step set of instructions telling a computer
what to do.
• If we change the program, the computer performs a different
set of actions or a different task.
• The machine stays the same, but the program changes!
• It is easier to change the Software than the Hardware.
10
About Algorithm
Recipe of a tea Algorithm Looks like:
First heat a pan and add water. Step 1: heat pan
Boil it and add the tea powder. Step 2: Add water
Step 3: Boil water
Boil it few seconds and strain it.
Step 4: Add tea powder
Add milk and sugar if desired! Step 5: Boil again
Step 6: Strain it
Step 7: Add milk if desired
Step 8: add sugar if desired
Algorithm vs. Program?
An algorithm is an ordered A program is a translated
set of simple instructions version of an algorithm, into
to solve a problem some programming
correctly. language (Python, Java, Cpp)
Algorithms - Human friendly
Programs - Computer friendly
An example
Algorithm to check whether a number is prime
1 Take an integer number n
2 Divide the number with integers (n-1 to 2)
3 If n is divisible by any value (n-1 to 2), then it is not prime
4 Otherwise n is prime
Python Implementation
Computer Software
• Computer software is a set of program instructions that can be executed by a
computer.
• Application software fulfills users’ needs, such as a photo-editing program.
• The syntax of a language is a set of characters and the acceptable arrangements
(sequences) of those characters.
• The semantics of a language is the meaning associated with each syntactically
correct sequence of characters.
Types of Programming Languages
• Programming language like a code for writing the instructions the computer
will follow.
• Programmers will often refer to their program as computer code.
• Process of writing an algorithm in a programming language often called
coding.
• High-level computer languages
• Designed to be used and understood by humans
• the programming languages - Java, C, C++, Python etc.
Low-level computer languages - machine languages/assembly languages
• Computers can only execute/run a code that is written in a low level
language.
• Hence, programs written in a high level language should be converted to
a low level language.
19
High level languages
Language Types ● Programmer friendly
● Easy to understand
● Portable
Low level languages ● Less time to read/write, shorter
● Machine friendly
● Difficult to understand
(probably will have to learn
everything about
processors/CPUs)
● Not portable
● More time to write
Programming Languages
• Add two numbers:
• Load the number from memory location 2001 into the CPU
• Load the number from memory location 2002 into the CPU
• Add the two numbers in the CPU
• Store the result in location 2003
• In reality, these low-level instructions are represented in binary (1’s and 0’s)
• High-level language -> c = a + b
• This needs to be translated into machine language that the computer can
execute.
• Compilers convert programs written in a high-level language into the
machine language of some computer.
21
Program Translation
• A central processing unit (CPU) is designed to interpret and execute a specific set of
instructions represented in binary form (i.e., 1s and 0s) called machine code.
• Writing programs at this “low level” is tedious and error-prone.
• Therefore, most programs are written in a “high-level” programming language such as
Python.
• A compiler, translates programs directly into machine code to be executed by the CPU
eg: C, C++
Program Translation
• An Interpreter directly executes instructions written in a
programming language without previously converting them to an
object code or machine code.
eg: Python, Matlab, Perl
• Interpreter, which executes program instructions in place of
(“running on top of”) the CPU.
• Interactive mode : An interpreter can immediately execute
instructions as they are entered.
• Compiled programs generally execute faster than interpreted
programs.
Program Debugging: Syntax Errors vs. Semantic Errors
• Program debugging is the process of finding and correcting errors ( “bugs” ) in a
computer program.
• Syntax errors are caused by invalid syntax
eg: prnt instead of print
• Translators cannot understand instructions containing syntax errors.
• Semantic errors/logic errors are errors in program logic.
eg: if a program computed the average of three numbers
• Computers do not understand what a program is meant to do, they only follow the
instructions given
Different Approaches to Problem Solving
The four pillars of computational thinking
1. Decomposition
2. Pattern recognition
3. Abstraction
4. Algorithms
Decomposition
Decomposition is the process of breaking a complex problem
into several manageable sub-problems
Pattern Recognition
Patterns are similarities exhibited by some of the sub-
problems.
Finding the patterns in the decomposed problems can help us
solve problems efficiently.
“A pattern is the opposite of a chaos”
Satoshi Watanabe
Pattern Recognition
Example 1: Each member of a meeting shook hands with every other
member and there were 45 handshakes, in total. How many members were
present in the meeting?
Decompose the problem and look for patterns.
n HS
2 1
3 3 The pattern is that of nC2.
4 6 nC2= 45 and hence n = 10
5 10
6 15
Abstraction
Abstraction – using relevant details and filtering out irrelevant
details
Two types of abstraction
1. Control abstraction – usage of subroutines
2. Data abstraction – real-world objects are explained in terms of what they are, and
what they can do.
Data abstraction involves simplifying complex data structures by
defining new data types and hiding the implementation details.
Procedural (Control) abstraction involves simplifying complex
processes or algorithms by breaking them down into smaller,
manageable procedures or functions.
Algorithms
Algorithm is a sequence well-defined instructions that takes input
and produces a correct output.
Each step in an algorithm will possibly be solving a sub-problem
obtained after several levels of decomposition.
Most important factor is the sequence in which the instructions
are executed.
Computational Problem Solving
•Computational problem solving does not simply involve the act of computer programming
Thank You!
Thought for the day:
“Use your freedom in a manner that benefits society.”
~~~AMMA~~~