0% found this document useful (0 votes)
5 views

Computation

Uploaded by

Maniacal Danger
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Computation

Uploaded by

Maniacal Danger
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Computation

Dr. Prasenjit Choudhury


&
Rajib Kumar Chatterjee
Dept. of Computer Science and Engineering
National Institute of Technology, Durgapur
West Bengal, India
Outline
• Computation
• Layers of a Computing System
• The Basic Model of Computation
• Algorithm
• Characteristics of an Algorithm
• How to Design an Algorithm?
• Algorithms and Flowcharts
• Steps in Problem Solving
• Pseudocode & Algorithm
• Flowchart
• If-then-else Structure
• Nested Ifs
Computers everywhere
• Ovens, washing machines and toys
• Banks & Hospitals
• Transport Reservations, Signalling
• Aircraft and industrial plant controllers
• Missiles and satellites,
• and many more
Why so prevalent
• They solve a variety of problems
• Efficient maintenance of large no. of data
• Precise control of movements
• Automation of many boring manual processes

In all
• They improve the quality of life
Your Job
• Many improvements are made and many more to
come

• You, tomorrow's quality scientists and Engineers,


are responsible for this

• You need to develop expertise in using computers,

• Ability to solve more problems using computers


What is computation?
• Computing has been defined as a branch of engineering science that
deals with the systematic study of algorithmic processes, which are
used to describe and transform information.

• It also has specific meanings depending on the context and field in


which it is used.
• For example, cloud computing, social
computing, ubiquitous computing, parallel
computing and grid computing all fall
under the umbrella of the general
meaning of computing while still having a
specific purpose and definition separate
from each other. Essentially, these are
different applications of computing.
• Algorithmic technique is a general approach for implementing a
process or computation.
Layers of a Computing System
Layers of a Computing System (contd.)
• The innermost layer, information, reflects the way we represent
information on a computer.
• In many ways, this is purely conceptual.
• Information on a computer is managed using binary digits, 1s and 0s.
• To understand computer processing, one must first understand the binary
number system and its relationship to other number systems.

• The next layer, hardware, consists of the physical hardware of a


computer system.
• Computer hardware includes devices such as gates and circuits, which
control the flow of electricity in fundamental ways.
• The core electronic circuit gives rise to specialized hardware components
such as the computer's central processing unit (CPU) and memory.
• In domestic environments where computer play a practical part in day-to-
day affairs, hardware also consists of external peripherals such as the
mouse, keyboard, and screen.
Layers of a Computing System (contd.)
• The programming layer deals with software, the instructions used to
accomplish computations and manage data.
• Programs can take many forms, be performed at many levels, and
be implemented in many different languages.
• Yet, despite the enormous variety of programming issues, the goal
remains the same: to solve problems.

• Every computer has an operating system (OS) to help manage the


computer's resources.
• Operating systems, such as Linux, help us interact with the
computer system and manage the way hardware devices,
programs, and data interact.
• Knowing what an operating system does is key to understanding
the computer in general.
Layers of a Computing System (contd.)
• The applications layer, by contrast, focuses on using the computer to
solve specific real-world problems.
• We run application programs to take advantage of the computer's
abilities in other areas, such as helping us design a building or play
a game.
• The spectrum of area-specific computer software tools is far-
reaching and involves specific sub disciplines of computing, such as
information systems, artificial intelligence, and simulation.
The Basic Model of Computation
A model of computing specifies:
1. What operations an algorithm can do (like addition, subtraction, moving data
from one memory location to another), and
2. Cost of operation. The main resources of a computer are the CPU time and
memory (random access memory). So, an efficient algorithm should require
the smallest possible memory and execute as quickly as possible. A
programmer should write a program that uses these two resources efficiently.
So, the cost of computation involves CPU time and memory. Certain operations
are faster than others, e.g., addition is faster than multiplication and
subtraction is faster than division. Sometimes addition and subtraction will
also require lesser memory.
3. A model of computation is not a physical device, it is a mathematical idea.
Based on this model of computation we build an algorithm.
4. A computer does not only do calculations, it also communicates with its
environment. The environment of a computer is its memory and CPU. So a
computer exchanges data between memory and CPU.
5. Ofcourse, a model of computing should be implementable by a physical
machine.
The Basic Model of Computation
(contd.)
We can study the model of computing with the following diagram.
• We know that a program is written
in a computer language (like
Python, Java, etc) and a computer
is needed to run a program.
• This relation between program,
programming language and a
computer is shown on the left side
in the above diagram.
• In a similar way, the relation
between an algorithm, pseudocode
and model of computation is
shown on the right side of this
diagram.
The Basic Model of Computation
(contd.)

From above diagram, we see that:


(i) the mathematical equivalent of a program is an algorithm (and vice-versa),
(ii) the mathematical equivalent of a programming language is pseudocode or
statements steps in structured English, and
(iii) the mathematical equivalent of a computer is the model of computation.
The Basic Model of Computation
(contd.)
A few models of computation are:
• Random Access Machine
• Turing machine
• Combinatory logic.
• Finite State Machine
The Basic Model of Computation
(contd.)
Random Access Machine (RAM):
• The abbreviation RAM also stands for Random Access Memory, but
here we are using the abbreviation for Random Access Machine.
• A Random Access Machine is a mathematical model of a computer.
• Such a Random Access Machine consists of a stored program, a central
processing unit and a computer memory.
• Any location in the memory can be accessed directly without having to
read the earlier locations and that is why the word ‘random’ is used.
• Such a mathematical model of computing allows the following
operations: addition, subtraction, multiplication, division and
comparison.
• Each operation is assumed to take a constant time.
The Basic Model of Computation
(contd.)
Need for studying models of computation:
1. Natural languages like English, Hindi are rich languages because a
wide variety of ideas can be expressed through these languages. But
the drawback of these languages are that they can be ambiguous. So a
word or a sentence may have more than one meaning which can cause
confusion.

2. A programming language should be able to express complex ideas in a


simple and unambiguous way.

3. Expressiveness of a programming language means how easily the


programmer can express a complex idea.

4. For example, in many programming languages we come across the


statement x = x + 1. This can also be written as “ADD 1 TO X GIVING X”
or in a simple way as x++.
The Basic Model of Computation
(contd.)
Need for studying models of computation:
5. So we see that expressiveness is concerned with the meaning not with
the way a statement is written.

6. The expressiveness of a programming language is concerned with its


semantics and not with syntax. Syntax is concerned with grammar of
the language like whether to put a semicolon or colon, etc.) and
semantics is concerned with the meaning of the statement.

7. Expressiveness of a programming language is what you can make a


machine do; expressiveness is not concerned with how a human being
understands the statement.

8. Different languages have different levels of expressiveness.

9. A language like Python or R is more expressive than C language.


The Basic Model of Computation
(contd.)
• A complicated software may be developed using more than
one programming language.
• For example, many IoT systems may be developed using
two languages because one language (like C) will be easier
to program in (more expressive) for some tasks, and
another language like assembly language will be faster to
execute.
• A system that uses two or more languages is called a
heterogeneously programmed system.
• Modules of the system developed in one language must
communicate without errors with modules developed in
another language. We say that the modules are
interoperable.
Algorithm
&
Flowchart
Algorithm
• An algorithm is a step-by-step procedure to solve a
given problem
• Alternatively, we can define an algorithm as a set
or list of instructions for carrying out
• some process step by step. A recipe in a cookbook
is an excellent example of an
• algorithm. The recipe includes the requirements
for the cooking or ingredients and the methods of
cooking until you end up a nice cooking dish..
Algorithm (contd.)
• Algorithms can be expressed using natural language, flowcharts,
etc.
• Let’s take a look at an example for a better understanding. As a
programmer, we are all aware of the Linear Search program.
(Linear Search)
▪ Algorithm of linear search :
1. Start from the leftmost element of arr[] and one by one compare
x with each element of arr[].
2. If x matches with an element, return the index.
3. If x doesn’t match with any of elements, return -1.
Pseudocode
• It is one of the methods which can be used to represent an algorithm for a
program
• It does not have a specific syntax like any of the programming languages and
thus cannot be executed on a computer.
• There are several formats which are used to write pseudo-codes and most of
them take down the structures from languages such as C, Lisp, FORTRAN, etc.
• Many time algorithms are presented using pseudocode since they can be read
and understood by programmers who are familiar with different programming
languages.
• Pseudocode allows us to include several control structures such as While, If-
then-else, Repeat-until, for and case, which is present in many high-level
languages.
• Many time algorithms are presented using pseudocode since they can be read
and understood by programmers who are familiar with different programming
languages.
• Pseudocode allows us to include several control structures such as While, If-
then-else, Repeat-until, for and case, which is present in many high-level
languages.
Pseudocode (contd.)
• Note: Pseudocode is not an actual programming language.
• Pseudocode for Linear Search :
FUNCTION linearSearch(list, searchTerm):
FOR index FROM 0 -> length(list):
IF list[index] == searchTerm THEN
RETURN index
ENDIF
ENDLOOP
RETURN -1
END FUNCTION
Flowchart for linear search
Thank You

You might also like