PSPP UNIT-1
PSPP UNIT-1
PSPP UNIT-1
Fundamentals of Computing
Definitions- Computer
o A computer is a machine that manipulates data accordingly to a set of instructions
o Computer is fast operating electronic device that receives data (input), process the data,
stores data, and produces resultant data (output)
o A computer is a device that accepts information (in the form of digitized data), manipulates
and processes the data based on a program, or sequence of instructions
Overview of Computers
o It is an electronic machine for data storage and processing, processes the given input and
generates output in the form of useful information
o A computer accepts input in different forms such as data, programs and user reply
o Programs refer to set of instructions that can be executed by the computer in a sequential or
non-sequential manner
o The main task of a computer system is to process the given input of any type in an efficient
manner
o Computers are the combination of two things. They are
Hardware
Software
1. Hardware
Computer Hardware is the visible components of the computer that enables the
computer system to function properly
It is the framework on which the computer software operates
Computer Hardware is made up of various components.
Examples
A computer includes various devices that function as an integrated system to
perform several tasks described above. The devices are
o CPU, MOINTOR, Keyboard, Mouse, Printer etc.
Central Processing Unit (CPU)
It is the processor of the computer that is responsible for controlling and
executing instructions in the computer
1
It is considered as the most important component of the computer
It is the “brain” of the computer
The process of the data are been done according to the instructions by the users
Monitor
It is a screen, which displays information in visual form, after receiving the
video signals from the computer
It is the display (or) output unit of the computer. The information’s are
displayed on the screen
Keyboard
It is an input device having different sets of keys for operating
It is like typewriter keyboard
It has character keys, numeric keys, Indo-Arabian numeric keys, etc., Most of
the key performs dual functions
Mouse
It is also an input device to move the cursor on the screen
It is also known as pointing device
It is also used to give commands through it’s right and left keys
2. Software
A set of programs that are executed sequentially is called software.
Software is generic term for organized collection of computer data and instruction
It is responsible for controlling integrating and managing the hardware components of a computer
and for accomplishing specific tasks
Software can be classified into two types: They are
o System Software
These software are inbuilt software to boot the system, for example Operating
System. Users can’t run the computer without these system softwares. These
softwares are mandatory to start a computer
Examples: LINUX, UNIX, DOS, etc.
o Application Software
These softwares are optional and can be used along with the system softwares.
But used can use computer without application softwares
The application software are used for specific purpose.
2
There are thousands of applications available to help the user to perform the desired
tasks.
It helps the user to work faster
Examples: Tally, CAD, games software, etc.
Characteristics of a Computer
Speed
A computer works with much higher speed and accuracy compared to humans while performing mathematical
calculations. Computers can process millions (1,000,000) of instructions per second. The time taken by
computers for their operations is microseconds and nanoseconds.
3
Accuracy
Computers perform calculations with 100% accuracy. Errors may occur due to data inconsistency or
inaccuracy.
Diligence
A computer can perform millions of tasks or calculations with the same consistency and accuracy. It doesn’t
feel any fatigue or lack of concentration. Its memory also makes it superior to that of human beings.
Versatility
Versatility refers to the capability of a computer to perform different kinds of works with same accuracy and
efficiency.
Reliability
A computer is reliable as it gives consistent result for similar set of data i.e., if we give same set of input any
number of times, we will get the same result.
Automation
Computer performs all the tasks automatically i.e. it performs tasks without manual intervention.
Memory
A computer has built-in memory called primary memory where it stores data. Secondary storage are removable
devices such as CDs, pen drives, etc., which are also used to store data.
1. Input Unit
2. Output Unit
3. Memory Unit
4. Control Unit
5. Arithmetical and Logical Unit
4
Input Unit
o A computer will only respond when a command is given to the device. These commands can be
given using the input unit or the input devices.
o For example: Using a keyboard we can type things on a Notepad and the computer processes the
entered data and then displays the output of the same of the screen.
o The data entered can be in the form of numbers, alphabet, images, etc. We enter the information
using an input device, the processing units convert it into computer understandable languages and
then the final output is received by a human-understandable language.
Output Unit
o When we command a computer to perform a task, it reverts for the action performed and gives us
a result. This result is called output. There are various output devices connected to the computer.
The most basic of which is a monitor. Whatever we write using a keyboard or click using a mouse,
is all displayed on the monitor.
o Thus, the output unit gives us the final result once the entire processing is done within the
mechanism of a device.
Memory Unit
o When we enter the data into the computer using an input device, the entered information
immediately gets saved in the memory unit of the Central Processing Unit (CPU). Because of the
presence of some existing programming, the Memory Unit transmits the data further to the other
parts of the CPU.
5
o Similarly, when the output of our command is processed by the computer, it is saved in the memory
unit before giving the output to the user.
Memory Unit
Control Unit
Arithmetic and Logical Unit
All these three units are elements of CPU and together help in the efficient working and processing of data. It
is also known as the “Brain of Computer” and no action can be conducted by a device without the execution
and permission of the Central Processing Unit.
Identification of Computational Problems
What is Computation?
It is any type of calculation that includes both arithmetical and non-arithmetical steps and follows a well-
defined model
E.g.: Algorithm.
Decision Problems
Search Problems
Counting Problems
Optimization Problems
Decomposition
Pattern recognition
Abstraction
Algorithmic design
Algorithm
o Algorithm is an ordered sequence of finite, well defined, unambiguous instructions for completing a
task.
o Finiteness
o The algorithm must terminate after a finite number of steps.
o Definiteness
o Each instruction must be clear, well-defined and precise. There should not be any ambiguity.
o Effectiveness
7
o Each instruction must be simple and carried out in finite amount of time.
o Input
o Output
Qualities of an Algorithm
o Accuracy
o Memory
o Time
o Sequence
o Result
Example:
Let us take a very simple example of an algorithm which adds the two numbers and store the result in a third
variable.
Step 1: Start.
Step 4: Perform the addition of both the numbers and store the result in variable 'c'.
Step 6: Stop.
Solution:
8
Radius r of the Circle.
Expected output:
Algorithm:
Step 1: Start
Step 5: Stop
Solution:
Step 1: Start
Step 5: If i%2=0, then goto step 5.1, 5.2 else goto step 6
Step 7: Stop
Statements
State
Control Flow
Functions
Statements / Instructions
State
Transition from one process to another process under specified condition with ina time is called state
Control flow
The process of executing the individual statements in a given order is called control flow.
1. Sequence
2. Selection
3. Iteration
Sequence
In short, sequence is a series of steps that are followed one after the other.
When an instruction is executed the execution control moves to the next immediate step.
Selection Statements
Selection is the program construct that allows a program to choose between different actions. Choose
at most one action from several alternative conditions.
A selection statement causes the program control to be transferred to a specific part of the program
based upon the condition.
If the conditional test is true, one part of the program will be executed, otherwise it will execute the
other part of the program.
Functions
Any complex problem will be simpler if the problem is broken smaller and the smaller problems are
solved.
Hence writing functions would increase the readability and efficiency of the algorithm.
Once a function is written, it can be used over and over and over again
o Pseudo means imitation and code refers to instructions written in programming language.
o Pseudo code is a set of statements in plain English which may be translated later into a programming
language.
o It is easy for a programmer and non-programmer to understand the general working of the program,
because it is not based on any programming language.
12
Input Read, obtain, Get, Prompt
Output Print, Display, Show
Calculations Compute, Calculate, Determine
Initiate Set, Initialize
Add one Increment
o Readability improves if just one action for the computer is written in one statement.
o A Pseudo code to add two numbers and display results.
READ num1, num2
Result = num1+num2
Write Result
– Example 1
If a>b then
PRINT a
ELSE
PRINT b
13
– Example 2
Total=m1+m2+m3
Average=Total/3
Rank=Distinction
ENDIF
o The programmer must never use the syntax of any programming language.
o There are three control structures used in Pseudo code. They are,
o Sequence control structure.
o Selection control structure.
o Iteration control structure.
o In sequence control structure, the steps are executed in a linear order one after another.
o They are executed in the order in which they are written, from top to bottom.
STOP
IF condition THEN
Sequence 1
ELSE
Sequence 2
END IF
o Example
READ values of A, B, C
ASSIGN A to MAX
ELSE
ASSIGN B to MAX
ELSE
PRINT C is greatest
STOP
It is a loop (iteration) based on the satisfaction of some condition(s). It comprises of the following
constructs:
o WHILE…END WHILE
o REPEAT…UNTIL
15
o FOR…ENDFOR
Disadvantages
Flowcharts
16
Symbol Symbol Name Description
o Only one flow line should enter a decision symbol. However, two or three flow lines may leave a
decision symbol.
17
o Only one flow line is used in conjunction with terminal symbol.
Advantages of Flowcharts
a. Communication
o Flowcharts are better way of communicating the logic of a system to all concerned.
b. Effective Analysis
o With the help of flowchart, problem can be analyzed in more effective way.
c. Effective Coding
o The flowcharts act as a guide or blueprint during the system analysis and program development
phase.
d. Proper Testing and Debugging
o The flowchart helps in debugging process.
e. Effective Program Maintenance
o Maintenance of running program becomes easy with the help of flow chart
Disadvantages of Flowcharts
o A complex and long flow chart may run into multiple pages, which becomes difficult to understand
and follow
o Updating the flowchart with changing requirements is a challenging job.
Programming Languages
A programming language is a set of rules that provides a way of telling a computer what operations
to perform.
Types of Programming Languages
– Assembly Language
Advantages
Translation free
o Machine language is the only language which the computer understands
o In this case conversion is not required
– High Speed
o The machine language program is translation free.
o Since conversion time is saved, the execution of machine language is faster.
Disadvantages
– Hard to find errors in a program written in machine language.
– Writing program in machine language is time consuming process.
Assembly Language
An assembly language consists of (English like) mnemonics
Assembly languages use keywords and symbols, much like English, to form a programming language but
same time introduce a new problem
The problem is that the computer doesn’t understand the assembly code, so we need a way to convert
to machine code, which computer does understand.
Assembly level programs are translated into machine language by a program called assembler
Example
ADD a,b
Mnemonic Opcode
• Advantages
• Disadvantages
– Machine dependent
• Normally the assembly language program are machine dependent / written based on the
particular machine language like 8085/8086.
– Hard to learn
• Programmer should know hardware knowledge to create applications using assembly
language.
19
– Less efficient
High Level Languages
High-level languages allow us to write computer code using instructions resembling everyday spoken
language (for example: print, if, while)
Programs written in high level language need to be translated into machine language before they can be
executed
Since programming languages use a compiler to perform this translation and others use interpreter
Examples: C,C++,BASIC,PYTHON,JAVA,PASCAL,COBOL
Advantages
o Readability
High level language is closer to natural language so they are easier to learn and understand
o Machine independent
High level language program have the advantage of being portable between machines
o Easy debugging
Easy to find and correct error in high level language
Disadvantages
o Less efficient
Takes more memory and more time to execute
Some of the Programming languages are
An interpreted language is a programming language for which executes the program directly,
translating each statement into a sequence of one or more subroutines already compiled into machine
code
20
Procedural Programming language
A procedure is a group of statements referenced through a procedure call
Procedures help in the reuse of code
Eg: CLIST, Hyper Talk, MATLAB
Algorithmic Problem Solving means solving problems that require the formulation of an algorithm for
their solution.
It includes mainly nine steps they are:
o Understanding the Problem
o Ascertain the capabilities of the computational device
o Choosing between Exact and Approximate Problem Solving
o Deciding a data structure
o Algorithm Design Techniques
o Methods of Specifying an Algorithm
o Proving an Algorithm’s Correctness
o Analyzing an Algorithm
o Coding an Algorithm
21
Understanding the Problem
It is the process of finding the input of the problem that the algorithm solves.
It is very important to specify exactly the set of inputs the algorithm needs to handle.
A correct algorithm is not one that works most of the time, but one that works correctly for all
legitimate inputs.
Once a problem is understood the capabilities of the computing device has to be ascertained.
This can be done by knowing the type of the architecture, speed & memory availability.
Once algorithm is devised, it is necessary to show that it computes answer for all the possible legal
inputs.
This solution is stated in two forms: Exact solution and approximate solution.
Some examples of problems where an exact solution cannot be obtained are:
o Finding square root of a number
o Solutions of non-linear equations
Data structure plays a vital role in designing and analysis the algorithms.
Some of the algorithm design techniques also depend on the structuring data specifying a problem’s
22
instance.
Algorithm+ Data structure=programs.
An algorithm design technique (or “strategy” or “paradigm”) is a general approach to solving problems
algorithmically that is applicable to a variety of problems from different areas of computing.
They provide guidance for designing algorithms for new problems.
Example: Divide and conquer, brute force, Backtracking, Dynamic programming, greedy techniques,
etc.
Once an algorithm has been specified, you have to prove its correctness.
That is, you have to prove that the algorithm yields a required result for every legitimate input in a
finite amount of time.
A common technique for proving correctness is to use mathematical induction because an algorithm’s
iterations provide a natural sequence of steps needed for such proofs.
Analysing an Algorithm
1. Efficiency
a. Time Efficiency: Indicating how fast the algorithm runs.
b. Space Efficiency: Indicating how much extra memory it uses.
2. Simplicity
a. An algorithm should be precisely defined and investigated with mathematical expressions.
b. Simpler algorithms are easier to understand and easier to program.
c. Simple algorithms usually contain fewer bugs.
Coding an Algorithm
Coding is the process of translating the algorithm into a syntax of a given programming language.
Formal verification is done for small programs.
Validity is done through testing and debugging.
Iterations
Recursions
23
A sequence of statements is executed until a specific condition is true is called iterations.
I. For loop
II. While loop
Recursions
24
Step 5: Stop
Iteration Recursion
The process is repeated until the condition fails The function calls itself until the base
condition is satisfied
It consumes less memory It consumes more memory
It is faster It is slower
The code is long The code is short
Tracing is easier if any problem occurs Tracing is difficult if any problem
occurs
Illustrative Problems
1. In Python, list is a data structure which consists of sequence of elements. Each element in a sequence
is assigned with a number called as position or index.
Example
Minimum Element
Algorithm to Find Minimum in a List Pseudo code for finding minimum in a List
Step 1: Start the program SET initial i
Step 2: Read n READ n
Step 3: Read an list a[] of ‘n’ numbers READ an list a[ ] of ‘n’ numbers
Step 4: Assign first list value to min SET min=a[0]
a[0] FOR i=1 to n
Step 5: For i=1 to n IF a[i]<min THEN
Step 6: if a[i]<min min=a[i]
then min=a[i] END IF
END FOR
Step 7: Repeat step 5 to step 6 until loop
reaches ‘n’
Step 8: Print min
Step 9: Stop
25
Description
1. To insert a card in the sorted card we must increase the list size with
2. We can insert a new card in the appropriate position by comparing each elements value.
Example: Initially N=5
10<11, Now increase list size by1 and store 11 in 5th position
START
READ number of elements in the sorted list, n
SET i=0
WHILE i<n
READ the sorted list element as list[i]
SET i=i+1
END WHILE
READ element to be inserted as x
SET i= n-1
WHILE i>=0 AND x<list[i]
list[i+1] = list[i]
SET i = i-1
END WHILE
list [i+1] = x
END
Step 1: Start
Step 3: Initialize i = 0
26
Step 4: Repeat steps 5 and 6 WHILE i<n
Description
Range (1,20)
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
Computer has selected random number 16
Algorithm
4) Tower of Hanoi
Description
28
N denotes the number of disks
T (N,Beg,Aux,End)
Beg is the initial peg
Steps
1. T(N-1,Beg,End,Aux)
2. T(1,Beg,Aux,End)
3. T(N-1,Aux,Beg,End)
Step 1 says: Move top (N-1) disks from Beg to Aux peg.
Step 2 says: Move 1 disk from Beg to End peg.
Step 3 says: Move top (N-1) disks from Aux to End peg.
A->C
A->B
29
C->B
A->C
B->A
30
B->C
A->C
31
Step 1: Start BEGIN
Step 2: Get l,b values READ l,b
Step 3: Calculate A=l*b CALCULATE A=l*b
Step 4: Display A DISPLAY A
Step 5: Stop END
32
Step 1: Start BEGIN
Step 2: get P, n, r value READ P, n, r
Step3: Calculate SI=(p*n*r)/100 CALCULATE S
Step 4: Display S SI=(p*n*r)/100
Step 5: Stop DISPLAY SI
END
35