Sie sind auf Seite 1von 168




Untouchability is Inhuman and a Crime

A publication under Free Textbook Programme of Government of Tamil Nadu

Department of School Education

Index.indd 1 17-05-2018 12:03:33

Government of Tamil Nadu
First Edition - 2018


Content Creation

The wise
possess all

State Council of Educational

Research and Training
© SCERT 2018

Printing & Publishing

Tamil NaduTextbook and Educational

Services Corporation


Index.indd 2 17-05-2018 12:03:33

Human civilization achieved the highest peak with the
development of computer known as “Computer era”.
Literate are those who have the
knowledge in using the computer
PREFACE whereas others are considered
illiterate inspite of the other degrees
T h e growth of the nation at present lies in the
hands of the youth, hence the content of this book is
prepared in such a way so as to attain utmost knowledge
considering the future needs of the youth.

This book does not require

prior knowledge in computer HOW
Each unit comprises of simple THE BOOK
activities and demonstrations
which can be done by the teacher
and also students.
Technical terminologies are listed
in glossary for easy understanding
The “ Do you know?” boxes enrich the knowledge of reader with
additional information
Workshops are introduced to solve the exercises using software
QR codes are used to link supporting additional
materials in digital form
How to get connected to QR Code?
o Download the QR code scanner from the google play store/
apple app store into your smartphone
o Open the QR code scanner application
o Once the scanner button in the application is clicked, camera opens
and then bring it closer to the QR code in the textbook.
o Once the camera detects the QR code, a URL appears in the screen.
Click the URL and go to the content page.


Index.indd 3 17-05-2018 12:03:33


Software Engineer, Hardware
All University and their affiliated
Engineer, Software
B.E / B.Tech Colleges and Self financing Colleges in
Development, Healthcare
India and Abroad.
Section, IT & ITEs
Science and Humanities
B.Sc (Computer Science)
B.Sc ( Maths, Physics, Chemistry, All University and their affiliated Government Job and Private
Bio-Chemistry, Geography, Colleges and Self financing Colleges in Company BPO, Geologist,
journalism, Library Sciences, India and Abroad. Journalist
Political Science, Travel and
B.A+LLB All University and their affiliated
Lawyer, Legal Officer, Govt
B.Com Colleges and Self financing Colleges in
BBM+LLB India and Abroad.
The Institute of Chartered Accountant
CA CA Private and Govt.
of India (ICAI)
Government Polytechnic and Self- Junior Engineer (Government
financing colleges and Private)
Commerce Courses, & Tax Procedure, &Tourism, Management,,
BFM- Bachelors in Financial
Private Organization ,
Markets, All University and their affiliated
Government ,Banking sectors
BMS-Bachelors in Management Colleges and Self financing Colleges in
and prospects for self –
Studies, India and Abroad.
BAF- Bachelors in Accounting &
Certified Stock Broker &
Investment Analysis,
Certified Financial Analyst,
Certified Financial Planner,
Certified Investment Banker


Index.indd 4 17-05-2018 12:03:33

Management Courses
Business Management
Bank Management
Private Organization ,
Event Management All University and their affiliated
Government ,Banking sectors
Hospital Management Colleges and Self financing Colleges in
and prospects for self –
Human Resource Management India and Abroad.
Logistics Management

Lawyer, Legal Officer, Private
B.A+LLB All University and their affiliated
Organization , Government,
B.Com Colleges and Self financing Colleges in
Banking sectors and prospects
BBM+LLB India and Abroad.
for self – employment
CA-Chartered Accountant
CA, Private Organization,
CMA-Cost Management
The Institute of Chartered Accountant Government ,Banking sectors
of India (ICAI) and prospects for self –
CS-Company Secretary
Science and Humanities
B.Sc.Dietician & Nutritionist
B.Sc.Home Science
B.Sc.Food Technology All University and their affiliated Government Job and Private
B.Sc.Dairy Technology Colleges and Self financing Colleges in Company BPO, Geologist,
B.Sc. Hotel Management India and Abroad Journalist
B.Sc. Fashion Design
B.Sc. Mass Communication
B.Sc. Multimedia
B.Sc. -3D Animation
B.A+LLB All University and their affiliated
Lawyer, Legal Officer, Govt
B.Com Colleges and Self financing Colleges in
BBM+LLB India and Abroad.
The Institute of Chartered Accountant
CA CA Private and Govt.
of India (ICAI)
Government Polytechnic and Self- Junior Engineer (Government
financing colleges and Private)

Index.indd 5 17-05-2018 12:03:33

Table of Contents

Chapter No. Title Page



1 Introduction to Computers 1

2 Number Systems 18

3 Computer Organization 51

4 Theoretical Concepts of Operating System 64

Working with typical Operating System
5 Part-I Working with Windows 78
Part-II Working with Linux 104


6 Specification and Abstraction 116

7 Composition and Decomposition 130

8 Iteration and recursion 147

E - book Assessment DIGI links


Index.indd 6 17-05-2018 12:03:33

Unit I Fundamentals of Computers CHAPTER
Introduction to Computers

Learning Objectives 1.1 Introduction to Computers

After learning the concepts in this chapter, Computers are seen everywhere
the students will be able around us, in all spheres of life, in the
field of education, research, travel and
• To know about Computers tourism, weather forecasting, social
networking, e-commerce etc. Computers
• To learn about various generations of
have now become an indispensable part of
our lives. Computers have revolutionized
• To understand the basic operations of our lives with their accuracy and speed of
computers performing a job, it is truly remarkable.
Today, no organization can function
• To know the components and their
without a computer. In fact, various
organizations have become paperless.
• To know about booting of a computer Computers have evolved over the years
from a simple calculating device to high
speed portable computers.

The growth of computer industry

started with the need for performing
fast calculations. The manual method of
Father of Computer
computing was slow and prone to errors.
Charles Babbage is considered So, attempts were made to develop fast
to be the father of computer, for calculating devices, the journey started
his invention and the concept of from the first known calculating device
Analytical Engine in 1837. The (Abacus) which has led us today to an
Analytical Engine contained an extremely high speed calculating devices.
Arithmetic Logic Unit (ALU), basic
flow control, and 1.2 Generations of Computers
integrated memory;
which led to the Growth in the computer industry
development of first is determined by the development in
t e c h n o l o g y.
computer concept. Based on various stages of
development, computers can be
categroized into different generations.

Chapter 1 Page 001-017.indd 1 17-05-2018 11:47:52

Main Component
SN Generation Period Merits/Demerits

• Big in size
First 1942- • Consumed more power
Generation 1955 • Malfunction due to overheat
• Machine Language was used
Vacuum tubes
First Generation Computers - ENIAC , EDVAC , UNIVAC 1
ENIAC weighed about 27 tons, size 8 feet × 100 feet × 3 feet and consumed around 150
watts of power
• Smaller compared to First
• Generated Less Heat
• Consumed less power
compared to first generation
Second 1955- • Punched cards were used
Generation 1964 • First operating system was
developed - Batch Processing
Transistors and Multiprogramming
Operating System
• Machine language as well as
Assembly language was used.
Second Generation Computers IBM 1401, IBM 1620, UNIVAC 1108

• Computers were smaller,

faster and more reliable
Third 1964
3 • Consumed less power
Generation -1975
• High Level Languages were
Integrated used
Circuits (IC)
Third Generation Computers IBM 360 series, Honeywell 6000 series

• Smaller and Faster

• Microcomputer series such
as IBM and APPLE were
4 1975-1980 developed
Generation Microprocessor
• Portable Computers were
Very Large Scale
Integrated Circuits

Chapter 1 Page 001-017.indd 2 17-05-2018 11:47:54

• Parallel Processing
• Super conductors
• Computers size was drastically
• Can recognize Images and
Fifth 1980 - till Graphics
Generation date • Introduction of Artificial
Intelligence and Expert
Ultra Large Systems
Scale Integration • Able to solve high complex
(ULSI) problems including decision
making and logical reasoning
• Parallel and Distributed
• Computers have become
Sixth smarter, faster and smaller
6 In future
Generation • Development of robotics
• Natural Language Processing
• Development of Voice
Recognition Software
Table1.1 Generations of computers
The first digital computer

The ENIAC (Electronic Numerical Integrator

And Calculator) was invented by J. Presper
Eckert and John Mauchly at the University of Pennsylvania
and began construction in 1943 and was not completed
until 1946. It occupied about 1,800 square feet and used
about 18,000 vacuum tubes, weighing almost 50 tons.
ENIAC was the first digital computer because it was fully

1.3 Sixth Generation Computing

In the Sixth Generation, computers could be defined as the era of intelligent

computers, based on Artificial Neural Networks. One of the most dramatic changes in
the sixth generation will be the explosive growth of Wide Area Networking. Natural
Language Processing (NLP) is a component of Artificial Intelligence (AI). It provides the
ability to develop the computer program to understand human language.

Chapter 1 Page 001-017.indd 3 17-05-2018 11:47:55

Optical Character and even playing games.
Recognition (Optical Grapheme
Computer - man or machine?
Recognition) engine for the
Indus Scripts has been developed Before 19th century, the term
using Deep Learning Neural Networks (a “Computer” was referred to humans
sub-field of Artificial Intelligence). who performed calculations using
Abacus and Slide Rule and not to
Given photographs, scans, or any image machine.
feed of an Indus Valley Civilization
The term “computer” is derived
artifact, the system will be able to
from the word “compute” which means
recognize the inscriptions (the symbol/
to calculate. The person who performs
grapheme sequences) from the image.
calculation is called as Computer. This
There are totally 417 term was later given to mechanical
Symbols/Graphemes/ device as they began replacing the
Characters in the Indus human computers.
Scripts and just 3700+
text inscriptions of data Today's computers are electronic
devices that accept data as input, process
for the machine to learn
it, produce output and stores it for future
and attain expert-level status. reference.

I am a good

Data: Data is defined as an un-

1.4. Data and Information processed collection of raw facts, suitable
for communication, interpretation or
We all know what a computer is? It pro cessing.
is an electronic device that processes the
For example, 134, 16 ‘Kavitha’, ‘C’
input according to the set of instructions
are data. This will not give any meaningful
provided to it and gives the desired output
at a very fast rate. Computers are very
versatile as they do a lot of different tasks Information: Information is a
such as storing data, weather forecasting, collection of facts from which conclusions
booking airlines, railway or movie tickets may be drawn. In simple words we can say

Chapter 1 Page 001-017.indd 4 17-05-2018 11:47:55

that data is the raw facts that is processed Let us first have a look at the
to give meaningful, ordered or structured functional components of a computer.
information. For example Kavitha is Every task given to a computer follows an
16 years old. This information is about Input- Process- Output Cycle (IPO cycle).
Kavitha and conveys some meaning. This It needs certain input, processes that
conversion of data into information is input and produces the desired output.
called data processing. The input unit takes the input, the central
processing unit does the processing of
data and the output unit produces the
INPUT PROCESS OUTPUT output. The memory unit holds the data
DATA and instructions during the processing.

Figure 1.1 Data and Information Control Unit

“A Computer is an electronic device that Input Unit

Output Unit
takes raw data (unprocessed) as an input Internal
Memory Data Path
from the user and processes it under the Control Path
control of a set of instructions (called Main Memory

program), produces a result (output), and

Secondary Storage
saves it for future use.”
Figure 1.3 components of a computer
1.5 Components of a Computer
1.5.1 Input Unit
The computer is the combination of
hardware and software. Hardware is the Input unit is used to feed any form
physical component of a computer like of data to the computer, which can be
motherboard, memory devices, monitor, stored in the memory unit for further
keyboard etc., while software is the set of processing. Example: Keyboard, mouse,
programs or instructions. Both hardware etc.
and software together make the computer
system to function. 1.5.2 Central Processing Unit

CPU is the major component

which interprets and executes software
instructions. It also control the operation
of all other components such as memory,
input and output units. It accepts binary
data as input, process the data according
to the instructions and provide the result
as output.

Figure 1.2: Computer The CPU has three components

Chapter 1 Page 001-017.indd 5 17-05-2018 11:47:56

which are Control unit, Arithmetic and Access Memory (RAM) is an example of
logic unit (ALU) and Memory unit. a main memory. The Secondary memory
is non volatile, that is, the content is Arithmetic and Logic Unit available even after the power supply is
switched off. Hard disk, CD-ROM and
The ALU is a part of the CPU DVD ROM are examples of secondary
where various computing functions are memor y.
performed on data. The ALU performs
arithmetic operations such as addition, 1.5.5. Input and Output Devices
subtraction, multiplication, division
and logical operations. The result of an Input Devices:
operation is stored in internal memory
of CPU. The logical operations of ALU (1) Keyboard: Keyboard (wired /
promote the decision-making ability of a wireless, virtual) is the most common input
computer. device used today. The individual keys for
letters, numbers and special characters Control Unit are collectively known as character keys.
This keyboard layout is derived from the
The control unit controls the flow of keyboard of original typewriter. The data
data between the CPU, memory and and instructions are given as input to
I/O devices. It also controls the entire the computer by typing on the keyboard.
operation of a computer. Apart from alphabet and numeric keys,
it also has Function keys for performing
1.5.3. Output Unit different functions. There are different set
of keys available in the keyboard such as
An Output Unit is any hardware
character keys, modifier keys, system and
component that conveys information to
GUI keys, enter and editing keys, function
users in an understandable form. Example:
keys, navigation keys, numeric keypad
Monitor, Printer etc.
and lock keys.
1.5.4. Memory Unit

The Memory Unit is of two types

which are primary memory and secondary
memory. The primary memory is used
to temporarily store the programs and
Figure 1.4 Keyboard
data when the instructions are ready to
execute. The secondary memory is used
(2) Mouse: Mouse (wired/wireless)
to store the data permanently.
is a pointing device used to control the
movement of the cursor on the display
The Primary Memory is volatile,
screen. It can be used to select icons,
that is, the content is lost when the power
menus, command buttons or activate
supply is switched off. The Random
something on a computer. Some mouse

Chapter 1 Page 001-017.indd 6 17-05-2018 11:47:56

actions are move, click, double click, right click, drag and drop.

Different types of mouse available are: Mechanical Mouse, Optical, Laser Mouse,
Air Mouse, 3D Mouse, Tactile Mouse, Ergonomic Mouse and Gaming Mouse.


Developed and
SN Type of Mouse Mechanism

• A small ball is kept inside and touches

Mechanical Mouse the pad through a hole at the bottom Telefunken,
of the mouse. German
1 • When the mouse is moved, the ball
rolls. 02/10/1968

• This movement of the ball is converted

into signals and sent to the computer.

Optical Mouse • Measures the motion and acceleration

of pointer. • In 1988,
Richard Lyon,
• It uses light source instead of ball to Steve Krish
judge the motion of the pointer. independently
• Optical mouse has three buttons. different
versions of
• Optical mouse is less sensitive towards Optical Mouse.

• Measures the motion and acceleration

Laser Mouse
of pointer.

3 • Laser Mouse uses Laser Light

• Laser Mouse is highly sensitive and

able to work on any hard surface.

Table 1.2 Commonly used Mouse

Chapter 1 Page 001-017.indd 7 17-05-2018 11:47:56

Who invented

The computer
mouse as we know it today
was invented and developed
by Douglas Engelbart,
with the assistance of
Bill English, during the
1960's and was patented
Figure 1.6 Fingerprint Scanner
on November 17, 1970.
(5) Track Ball: Track ball is similar
to the upside- down design of the mouse.
(3) Scanner: Scanners are used The user moves the ball directly, while
to enter the information directly into the device itself remains stationary. The
the computer’s memory. This device user spins the ball in various directions to
works like a Xerox machine. The scanner navigate the screen movements.
converts any type of printed or written
information including photographs into a
digital format, which can be manipulated
by the computer.

Figure 1.7 Track Ball

(6) Retinal Scanner: This performs

a retinal scan which is a biometric
technique that uses unique patterns on a
person's retinal blood vessels.
Figure 1.5 Scanner

(4)Fingerprint Scanner: Finger

print Scanner is a fingerprint recognition
device used for computer security,
equipped with the fingerprint recognition
feature that uses biometric technology.
Fingerprint Reader / Scanner is a very safe Figure 1.8 Retinal Scanner
and convenient device for security instead
of using passwords, which is vulnerable to (7) Light Pen: A light pen is a pointing
fraud and is hard to remember. device shaped like a pen and is connected to

Chapter 1 Page 001-017.indd 8 17-05-2018 11:47:56

a monitor. The tip of the light pen contains a scans the information on the bar codes
light-sensitive element which detects the light transmits to the Computer for further
from the screen enabling the computer to processing. The system gives fast and error
identify the location of the pen on the screen. free entry of information into the computer.
Light pens have the advantage of ‘drawing’ QR (Quick response) Code: The QR
directly onto the screen, but this becomes code is the two dimension bar code which
hard to use, and is also not accurate. can be read by a camera and processed to
interpert the image

Figure 1.11 Bar code Reader

Figure 1.9 Light Pen
(10) Voice Input Systems:
(8) Optical Character Reader: Microphone serves as a voice Input
It is a device which detects characters device. It captures the voice data and send
printed or written on a paper with OCR, it to the Computer. Using the microphone
a user can scan a page from a book. The along with speech recognition software
Computer will recognize the characters in can offer a completely new approach to
the page as letters and punctuation marks input information into the Computer.
and stores. The Scanned document can be
edited using a wordprocessor.

Figure 1.12 Voice input System

(11) Digital Camera: It captures

Figure 1.10 Optical Character Reader images / videos directly in the digital
form. It uses a CCD (Charge Coupled
(9) Bar Code / QR Code Reader: Device) electronic chip. When light falls
A Bar code is a pattern printed in lines of on the chip through the lens, it converts
different thickness. The Bar code reader light rays into digital format.

Chapter 1 Page 001-017.indd 9 17-05-2018 11:47:57

one or more switches. Modern keyers
have a large number of switches but not
as many as a full size keyboard. Typically,
this number is between 4 and 50. A keyer
differs from a keyboard, which has "no
board", but the keys are arranged in a

Figure 1.13 Digital Camera

(12) Touch Screen: A touch screen

is a display device that allows the user
to interact with a computer by using
the finger. It can be quite useful as an Figure 1.15 Keyer
alternative to a mouse or keyboard for
Output Devices:
navigating a Graphical User Interface
(GUI). Touch screens are used on a wide
(1) Monitor: Monitor is the most
variety of devices such as computers,
commonly used output device to display
laptops, monitors, smart phones, tablets,
the information. It looks like a TV.
cash registers and information kiosks.
Pictures on a monitor are formed with
Some touch screens use a grid of infrared
picture elements called PIXELS. Monitors
beams to sense the presence of a finger
may either be Monochrome which display
instead of utilizing touch-sensitive input.
text or images in Black and White or can
be color, which display results in multiple
colors. There are many types of monitors
available such as CRT (Cathode Ray Tube),
LCD (Liquid Crystal Display) and LED
(Light Emitting Diodes). The monitor
works with the VGA (Video Graphics
Array) card. The video graphics card helps
the keyboard to communicate with the
screen. It acts as an interface between the
computer and display monitor. Usually the
recent motherboards incorporate built-in
Figure 1.14 Touch Screen video card.

(13) Keyer : A Keyer is a device The first computer monitor was part of
for signaling by hand, by way of pressing the Xerox Alto computer system, which
was released on March 1, 1973.

Chapter 1 Page 001-017.indd 10 17-05-2018 11:47:57

A Dot matrix printer that prints using
a fixed number of pins or wires. Each dot is
produced by a tiny metal rod, also called a
“wire” or “pin”, which works by the power
of a tiny electromagnet or solenoid, either
directly or through a set of small levers. It
generally prints one line of text at a time. The
printing speed of these printers varies from
30 to 1550 CPS (Character Per Second).
Figure 1.16 Monitor

(2) Plotter: Plotter is an output

device that is used to produce graphical
output on papers. It uses single color or
multi color pens to draw pictures.

Figure 1.18 Impact Printer

Line matrix printers use a fixed

print head for printing. Basically, it prints
a page-wide line of dots. But it builds up a
line of text by printing lines of dots. Line
printers are capable of printing much more
Figure 1.17 Plotter than 1000 Lines Per Minute, resulting
in thousands of pages per hour. These
(3) Printers: Printers are used to printers also uses mechanical pressure to
print the information on papers. Printers print on multi-part (using carbon papers).
are divided into two main categories:
Non-Impact Printers
• Impact Printers
These printers do not use striking
mechanism for printing. They use
• Non Impact printers
electrostatic or laser technology. Quality
Impact Printers and speed of these printers are better than
Impact printers. For example, Laser printers
These printers print with striking of and Inkjet printers are non-impact printers.
hammers or pins on ribbon. These printers
Laser Printers
can print on multi-part (using carbon
papers) by using mechanical pressure. For Laser printers mostly work with
example, Dot Matrix printers and Line similar technology used by photocopiers.
matrix printers are impact printers. It makes a laser beam scan back and

Chapter 1 Page 001-017.indd 11 17-05-2018 11:47:58

forth across a drum inside the printer, piezoelectricity in which tiny electric
building up a pattern. It can produce very currents controlled by electronic circuits
good quality of graphic images. One of are used inside the printer to spread ink
the chief characteristics of laser printer in jet speed. An Inkjet printer can spread
is their resolution – how many Dots per millions of dots of ink at the paper every
inch(DPI). The available resolution range single second.
around 1200 dpi. Approximately it can
print 100 pages per minute(PPM) Speakers: Speakers produce voice
output (audio) . Using speaker along with
speech synthesize software, the computer
can provide voice output. This has become
very common in places like airlines,
schools, banks, railway stations, etc..

Figure 1.19 Laser Printer

Inkjet Printers:
Figure 1.21 Speakers
Inkjet Printers use colour cartridges
which combined Magenta, Yellow and Cyan Multimedia Projectors:
inks to create color tones. A black cartridge
Multimedia projectors are used to
is also used for monochrome output. Inkjet
produce computer output on a big screen.
printers work by spraying ionised ink at a
These are used to display presentations in
sheet of paper. The speed of Inkjet printers
meeting halls or in classrooms.
generaly range from 1-20 PPM (Page Per

Figure 1.22 Multimedia Projector

Figure 1.20 Inkjet Printer
1.6 Booting of computer
They use the technology of firing
ink by heating it so that it explodes An Operating system (OS) is a
towards the paper in bubbles or by using basic software that makes the computer

Chapter 1 Page 001-017.indd 12 17-05-2018 11:47:58

to work. When a computer is switched 2) Warm Booting
on, there is no information in its RAM.At
Cold Booting: When the system
the same time, in ROM, the pre-written
starts from initial state i.e. it is switched
program called POST (Power on Self
on, we call it cold booting or Hard Booting.
Test) will be executed first. This program
When the user presses the Power button,
checks if the devices like RAM, keyboard,
the instructions are read from the ROM to
etc., are connected properly and ready to
initiate the booting process.
operate. If these devices are ready, then
the BIOS (Basic Input Output System) gets Warm Booting: When the system
executed. This process is called Booting. restarts or when Reset button is pressed,
Thereafter, a program called “Bootstrap we call it Warm Booting or Soft Booting.
Loader” transfers OS from hard disk into The system does not start from initial state
main memory. Now the OS gets loaded and so all diagnostic tests need not be
(Windows/Linux, etc.,) and will get carried out in this case. There are chances
executed. Booting process is of two types. of data loss and system damage as the data
might not have been stored properly.
1) Cold Booting

Points to Remember:

• Computers are seen everywhere • CPU interprets and executes software

around us, in all spheres of life. instructions.

• It is an electronic device that processes • The ALU is a part of the CPU where
the input according to the set of various computing functions are
instructions provided to it and performed on data.
gives the desired output at a very fast
rate. • The control unit controls the flow of
data between the CPU, memory and
• Based on various stages of development, I/O devices.
computers can be divided into six
different generations. • An Output Unit is any hardware
component that conveys information
• The computer is the combination of to one or more people in user
hardware and software. understandable form.

• Hardware is the physical component of • The Memory Unit is of two kinds which
a computer. are primary memory and secondary
• Input unit is used to feed any form of
data to the computer. • Booting Process is of two types – Cold
and Warm


Chapter 1 Page 001-017.indd 13 17-05-2018 11:47:58



1. Explain the classification of computers. 1. Open a CPU and explain the

components of it to students.
2. Give the details of motherboard names,
RAM capacity used in the years 1993, 2. To connect and disconnect the various
1995, 2005, 2008, 2016. components of a computer.

3. Mention two new input and output

devices that are not given in this



Choose the correct answer:

1. First generation computers used
(a) Vacuum tubes (b) Transistors
(c) Integrated circuits (d) Microprocessors
2. Name the volatile memory
(a) ROM (b) PROM (c) RAM (d) EPROM
3. Identify the output device
(a) Keyboard (b) Memory (c) Monitor (d) Mouse
4. Identify the input device
(a) Printer (b) Mouse (c) Plotter (d) Projector
5. …………… Output device is used for printing building plan, flex board, etc.
(a) Thermal printer (b) Plotter
(c) Dot matrix (d) inkjet printer


Chapter 1 Page 001-017.indd 14 17-05-2018 11:47:58

6. In ATM machines, which one of the following is used to

(a) Touch Screen (b) speaker

(c) Monitor (d) Printer

7. When a system restarts ……………….. which type of booting is used.

(a) Warm booting (b) Cold booting

(c) Touch boot (d) Real boot.

8. Expand POST

(a) Post on self Test (b) Power on Software Test

c) Power on Self Test (d) Power on Self Text

9. Which one of the following is the main memory?

(a) ROM (b) RAM

(c) Flash drive (d) Hard disk

10. Which generation of computer used IC’s?

(a) First (b) Second

(c) Third (d) Fourth


Short Answers

1. What is a computer?

2. Distinguish between data and information.

3. What are the components of a CPU?

4. What is the function of an ALU?

5. Write the functions of control unit.

6. What is the function of memory?

7. Differentiate Input and output unit.

8. Distinguish Primary and Secondary memory.


Chapter 1 Page 001-017.indd 15 17-05-2018 11:47:58

Explain in Brief
1. What are the characteristics of a computer?
2. Write the applications of computer.
3. What is an input device? Give two examples.
4. Name any three output devices.
5. Differentiate optical and Laser mouse
6. Write shortnote on impact printer
7. Write the characteristics of sixth generation.
8. Write the significant features of monitor.

Explain in detail
1. Explain the basic components of a computer with a neat diagram.
2. Discuss the various generations of computers.
3. Explain the following
a. Inkjet Printer b. Multimedia projector c. Bar code / QR code Reader


(1) Fundamentals of Computers – V. Rajaraman – PHI Publications

(2) Computer Science text book – NCERT, New Delhi

Internet Resources


Prepare a comparative study of various computers of past and present with respect
to speed, memory, size, power consumption and other features

Chapter 1 Page 001-017.indd 16 17-05-2018 11:47:58

It is an electronic device that processes the
Computer input according to the set of instructions
provided to it and gives the desired output at a very fast rate.
Vacuum tubes contain electrodes for controlling electron flow
Vacuum tube
and were used in early computers as a switch or an amplifier.
The transistor ("transfer resistance") is made up of semi-
conductors. It is a component used to control the amount of
current or voltage used for amplification/modulation of an
electronic signal.
Punch cards also known as Hollerith cards are paper cards
Punched cards containing several punched or perforated holes that were
punched by hand or machine to represent data.
Machine language is a collection of binary digits or bits that the
Machine Language
computer reads and interprets.
Assembly language An assembly language is a low-level programming language.
The IC is a package containing many circuits, pathways,
Integrated Circuits transistors, and other electronic components all working
together to perform a particular function or a series of functions.
Micro computer is used to describe a standard personal
A high-level language is a computer programming language
High-level languages that isn't limited by the computer, designed for a specific job,
and is easier to understand.
Natural Language Processing is a method used in artificial
Natural Language
intelligence to process and derive meaning from the human
Processing (NLP)
Robot is a term coined by Karel Capek in the 1921 to play
RUR (Rossum's Universal Robots). It is used to describe a
computerized machine designed to respond to input received
manually or from its surroundings.
Nanotechnology is an engineering, science, and technology that
Nanotechnology develops machines or works with one atom or one molecule
that is 100 nanometers or smaller.
A discipline that applies engineering principles of design and
analysis to biological systems and biomedical technologies


Chapter 1 Page 001-017.indd 17 17-05-2018 11:47:58

Unit I Fundamentals of Computers CHAPTER
Number Systems

Learining Objectives are called data. When the above data is

processed, we get an information “Rajesh
• To know how the computer interprets is 16 years old, studying in Class XI, has
and stores data in the memory. scored 65 marks in Computer Science
• To learn various data representations
and binary arithmetic. 2.2 Data Representations

• To learn conversion between various Computer handles data in the form

Number Systems. of ‘0’(Zero) and ‘1’ (One). Any kind of data
like number, alphabet, special character
2.1 Introduction should be converted to ‘0’ or ‘1’ which can
be understood by the Computer. ‘0’ and
The term data comes from the
‘1’ that the Computer can understand is
word datum, which means a raw fact. The
called Machine language. ‘0’ or ‘1’ are
data is a fact about people, places or some
called ‘Binary Digits’(BIT). Therefore,
the study of data representation in the
Example: computer is important.
• A bit is the short form of Binary digit
Let ‘Name’, ‘Age’, ‘Class’, ‘Marks’ which can be ‘0’ or ‘1’. It is the basic
and ‘Subject’ be some defined variables. unit of data in computers.
Now, let us assign a value to each of these
variables. • A nibble is a collection of 4 bits (Binary

Name = Rajesh • A collection of 8 bits is called Byte.

Age = 16 A byte is considered as the basic unit
Class = XI of measuring the memory size in the
Mark = 65 computer.
Subject = Computer Science
• Word length refers to the number of
bits processed by a Computer’s CPU.
Figure 2.1 Example for Data For example, a word length can have 8
bits, 16 bits, 32 bits and 64 bits (Present
In the above example, the values day Computers use 32 bits or 64 bits)
assigned to the five different variables


Chapter 2 Page 018-050.indd 18 17-05-2018 11:59:41

(0 or 1)

Nibble (4 bits)

Byte (8 bits)

KiloByte (1024 bytes)

MegaByte (1024 KB)

GigaByte (1024 MB)

TeraByte (1024 GB)

Figure 2.2 Data Representation

Computer memory (Main Memory and Secondary Storage)is normally represented

in terms of KiloByte (KB) or MegaByte (MB). In decimal system, 1 Kilo represents 1000,
that is , 103. In binary system, 1 KiloByte represents 1024 bytes that is 210. The following
table represents the various memory sizes:

Table 2.1 Memory Size (Read 2^10 as 2 power 10)

Name Abbr. Size

Kilo K 2^10 = 1,024
Mega M 2^20 = 1,048,576
Giga G 2^30 = 1,073,741,824
Tera T 2^40 = 1,099,511,627,776
Peta P 2^50 = 1,125,899,906,842,624
Exa E 2^60 = 1,152,921,504,606,846,976
Zetta Z 2^70 = 1,180,591,620,717,411,303,424
Yotta Y 2^80 = 1,208,925,819,614,629,174,706,173
Bytes are used to represent characters in a text. Different types of coding schemes
are used to represent the character set and numbers. The most commonly used coding
scheme is the American Standard Code for Information Interchange (ASCII). Each


Chapter 2 Page 018-050.indd 19 17-05-2018 11:59:41

binary value between 0 and 127 is used to represent a specific character. The ASCII value
for (blank space) is 32 and the ASCII value of numeric 0 is 48. The range of ASCII values
for lower case alphabets is from 97 to 122 and the range of ASCII values for the upper case
alphabets is 65 to 90.

The speed of a computer depends on the number of bits it can process at once.
For example, a 64- bit computer can process 64-bit numbers in one operation,
while a 32-bit computer break 64-bit numbers down into smaller pieces, making
it slower.

2.3 Different Types of Number Systems

Number Systems

Decimal Binary Octal Hexadecimal

Base value Base value

10 8
(0,1,2,3,4,5,6,7,8,9) Base value (0,1,2,3,4,5,6,7)
Base value

Figure 2.3. Number Systems

A numbering system is a way of representing numbers. The most commonly used

numbering system in real life is Decimal number system. Other number systems are
Binary, Octal, Hexadecimal number system. Each number system is uniquely identified
by its base value or radix. Radix or base is the count of number of digits in each number
system. Radix or base is the general idea behind positional numbering system.

2.3.1 Decimal Number System

It consists of 0,1,2,3,4,5,6,7,8,9(10 digits). It is the oldest and most popular number

system used in our day to day life. In the positional number system, each decimal digit is
weighted relative to its position in the number. This means that each digit in the number
is multiplied by 10 raised to a power corresponding to that digit’s position.

Chapter 2 Page 018-050.indd 20 17-05-2018 11:59:41


(123)10 = 1x102 + 2x101 + 3x100 (547)8 = 5×82 + 4×81 + 7×80

= 100 + 20 + 3 = 5×64 + 4×8 + 7×1
= (123)10 = 320 + 32 + 7
= (359)10
2.3.2 Binary Number System
2.3.4 Hexadecimal Number System
There are only two digits in the
Binary system, namely, 0 and 1. The A hexadecimal number is
numbers in the binary system are represented using base 16. Hexadecimal
represented to the base 2 and the positional or Hex numbers are used as a shorthand
multipliers are the powers of 2. The left form of binary sequence. This system is
most bit in the binary number is called as used to represent data in a more compact
the Most Significant Bit (MSB) and it has manner. Since 16 symbols are used, 0 to F,
the largest positional weight. The right the notation is called hexadecimal. The
most bit is the Least Significant Bit (LSB) first 10 symbols are the same as in the
and has the smallest positional weight. decimal system, 0 to 9 and the remaining
6 symbols are taken from the first 6 letters
1 1 0 1 of the alphabet sequence, A to F, where A
represents 10, B is 11, C is 12, D is 13, E is
14 and F is 15.

The binary sequence (1101)2 has

the decimal equivalent:

(1101)2 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20
= (13)10

2.3.3 Octal Number System

Octal number system uses digits

0,1,2,3,4,5,6 and 7 (8 digits). Each octal
digit has its own positional value or weight
as a power of 8.


The Octal sequence (547)8 has the

decimal equivalent:


Chapter 2 Page 018-050.indd 21 17-05-2018 11:59:41

Table 2.2 Binary, Octal, Hexadecimal equivalent of Decimal Numbers

Decimal Binary Octal Hexadecimal
0 0000 000 0000
1 0001 001 0001
2 0010 002 0002
3 0011 003 0003
4 0100 004 0004
5 0101 005 0005
6 0110 006 0006
7 0111 007 0007
8 1000 010 0008
9 1001 011 0009
10 1010 012 A
11 1011 013 B
12 1100 014 C
13 1101 015 D
14 1110 016 E
15 1111 017 F

Example Workshop

The hexadecimal sequence (25)16 1. Identify the number system for the
has the decimal equivalent: following numbers
S. No. Number Number system
(25)16 = 2×16 + 5×16
1 0
1 (1010)10 Decimal Number
= 32+5 system
= (37)10
2 (1010)2
3 (989)16
4 (750)8
5 (926)10

2. State whether the following numbers are valid or not. If invalid, give reason.
S.No. Statement Yes / No Reason (If invalid)
1. 786 is an Octal number
2. 101 is a Binary number
3. Radix of Octal number is 7


Chapter 2 Page 018-050.indd 22 17-05-2018 11:59:42

2.4 Number System Conversions Method 2 : Sum of Powers of 2.

2.4.1 Decimal to Binary Conversion A decimal number can be converted

into a binary number by adding up the
Generally two methods followed. powers of 2 and then adding bits as needed
to obtain the total value of the number.
Method 1: To convert Decimal to Binary
“Repeated Division by 2” method can be a) Find the largest power of 2 that is
used. Any Decimal number divided by 2 smaller than or equal to 65.
will leave a remainder of 0 or 1. Repeated
division by 2 will leave a sequence of 0s 6510 > 6410
and 1s that become the binary equivalent
of the decimal number. Suppose it is b) S et the 64’s bit to 1 and subtract 64
required to convert the decimal number from the original number
N into binary form, dividing N by 2 in the
decimal system, we will obtain a quotient 65-64=1
N1 and a remainder R1, where R1 can
c) 32 is greater than the remaining total.
have a value of either 0 or 1. The process
Therefore, set the 32’s bit to 0.
is repeated until the quotient becomes 0
or 1. When the quotient is ‘0’ or ‘1’, it d) 16 is greater than the remaining total.
is the final remainder value. Write the Therefore, set the 16’s bit to 0.
final answer starting from final remainder
e) 8 is greater than the remaining total.
value obtained to the first remainder value
Therefore, set the 8’s bit to 0.
f) 4 is greater than the remaining total.
Example Therefore, set the 4’s bit to 0.

Convert (65)10 into its equivalent g) 2 is greater than the remaining total.
binary number Therefore, set the 2’s bit to 0.
h) As the remaining value is equivalent to
2 65 Remainder 1’s bit, set it to 1.
2 32 - 1 Note :
2 16 - 0 65/2 = 32 + 1 1-1=0

2 8-0 32/2 = 16 + 0
Conversion is complete 6510 = (1000001)2
16/2 = 8 + 0
2 4-0
8/2 = 4 + 0 Example
2 2-0 4/2 = 2 + 0
1-0 2/2 = 1 + 0 The conversion steps can be given as

(65)10 = (1 0 0 0 0 0 1)2 Given Number : 65


Chapter 2 Page 018-050.indd 23 17-05-2018 11:59:42

Equivalent or value less than power of 2 Example
is : 64
Convert (31)10 into its equivalent
(1)  65 - 64 = 1 hexadecimal number.

(2)  1 - 1= 0
16 31 LSB
Power’s of 2 64 32 16 8 4 2 1 1 - 15
1 0 0 0 0 0 1
Number (16)10 = (1F)16(Refer Table 2.2 F=15)

6510 = (1000001)2
2.4.4 Conversion of fractional Decimal
2.4.2 Decimal to Octal Conversion to Binary

To convert Decimal to Octal, The method of repeated

“Repeated Division by 8” method can be multiplication by 2 has to be used to
used. The method is the same we have convert such kind of decimal fractions.
learnt in 2.4.1, but in this method, we
have to divide the given number by 8. The steps involved in the method
of repeated multiplication by 2:
Step 1: Multiply the decimal fraction by
Convert (65)10 into its equivalent 2 and note the integer part. The
Octal number integer part is either 0 or 1.

8 65 Step 2: Discard the integer part of the

LSB previous product. Multiply the
8 8 - 1
fractional part of the previous
product by 2. Repeat Step 1
until the same fraction repeats
(65)10 = (1 0 1)8 or terminates (0).

Step 3: The resulting integer part forms

2.4.3 Decimal to Hexadecimal a sequence of 0s and 1s that
Conversion become the binary equivalent of
decimal fraction.
To convert Decimal to Hexadecimal,
“Repeated division by 16” method can be Step 4: The final answer is to be written
used. The method is the same as we have from first integer part obtained
learnt in 2.4.1, but in this method, we have till the last integer part obtained.
to divide the given number by 16.


Chapter 2 Page 018-050.indd 24 17-05-2018 11:59:42

Table 2.3 Positional Notation and Weight
Integer part

0.2 × 2 = 0.4 0 (first integer part obtained) Positional Weight Positional Weight
Notation Notation
0.4 × 2 = 0.8 0
20 1 26 64
0.8 × 2 = 1.6 1 21 2 27 128
0.6 × 2 = 1.2 1 22 4 28 256
23 8 29 512
0.2 × 2 = 0.4 0 (last integer part obtained)

24 16 210 1024
Note: Fraction repeats, the product is the 25 32
same as in the first step.
Write the integer parts from
top to bottom to obtain the equivalent Convert (111011)2 into its
fractional binary number. Hence equivalent decimal number.
(0.2)10=(0.00110011…)2 = (0.00110011)2
Weight 32 16 8 4 2 1
3. Convert the following Decimal 25 24 23 22 21 20
numbers to its equivalent Binary, Octal, Given
Hexadecimal. 1 1 1 0 1 1
1) 1920
2) 255 32+16+8+0+2+1 = (59)10
(111011)2 = (59)10

2.4.5 Binary to Decimal Conversion 2.4.6 Binary to Octal Conversion

To convert Binary to Decimal we Step 1: Group the given binary number

can use positional notation method. into 3 bits from right to left.
Step 1: Write down the Binary digits
Step 2: You can add preceding 0 to make
and list the powers of 2 from
a group of 3 bits if the left most
right to left(Positional Notation)
group has less than 3 bits.
Step 2: For each positional notation
written for the digit, now write Step 3: Convert equivalent octal value
the equivalent weight. using "2's power positional weight
Step 3: Multiply each digit with its
corresponding weight
Step 4: Add all the values.


Chapter 2 Page 018-050.indd 25 17-05-2018 11:59:42

Table 2.4 Octal numbers and their Binary Step 2: You can add preceding 0’s to make
equivalent a group of 4 bits if the left most
group has less than 4 bits.
Equivalent Step 3: Convert equivalent Hexadecimal
0 000 value using "2's power positional
1 001 weight method"
2 010 Example
3 011
4 100 Convert (1111010110)2 into
5 101 Hexadecimal number
6 110
Step 1: Group the given number into 4
7 111 bits from right to left.

Example 0011 1101 0110

Convert (11010110)2 into octal Note: 0’s are added to the left most group
equivalent number to make it a group of 4 bits

Step 1: Group the given number into 3 0011 1101 0110

bits from right to left.

3 D 6
011 010 110
(1111010110)2 = (3D6)16
Note: The left most groups have less
than 3 bits, so 0 is added to its left 2.4.8 Conversion of fractional Binary to
to make a group of 3 bits. Decimal equivalent

Step-2: Find Octal equivalent of each Follow the steps to convert

group fractional Binary number to its Decimal
011 010 110
Step 1: Convert integral part of Binary


3 2 6 to Decimal equivalent using

(11010110)2 = (326)8 positional notation method
(Procedure is same as discussed
in 2.4.5)
2.4.7. Binary to Hexadecimal Conversion
Step 2: To convert the fractional part of
Step 1: Group the given number into 4 binary to its decimal equivalent.
bits from right to left.
Step 2.1: Write down the Binary
digits in the fractional part

Chapter 2 Page 018-050.indd 26 17-05-2018 11:59:42

Step 2.2: For all the digits write
powers of 2 from left to right Workshop
starting from 2-1, 2-2, 2-3...... 2-n, 4. Convert the given Binary number
into its equivalent Decimal, Octal and
now write the equivalent weight.
Hexadecimal number.
Step 2.3: Multiply each digit with
its corresponding weight 1) 101110101
2) 1011010
Step 2.4: Add all the values which
3) 101011111
you obtained in Step 2.3

2.4.9. Octal to Decimal Conversion

Table 2.5 Positional notation and weight To convert Octal to Decimal, we

can use positional notation method.
Positional Weight
notation 1. Write down the Octal digits and
2 (1/2)
0.5 list the powers of 8 from right to
2-2 (1/4) 0.25 left(Positional Notation)
2-3 (1/8) 0.125
2. For each positional notation of the
2-4 (1/16) 0.0625
digit write the equivalent weight.
2-5 (1/32) 0.03125
2-6 (1/64) 0.015625 3. Multiply each digit with its
2-7 (1/128) 0.0078125 corresponding weight

Step 3: To get final answer write the 4. Add all the values
integral part (after conversion),
followed by a decimal point(.) and
the answer arrived at Step 2.4 Convert (1265)8 to equivalent
Decimal number
Weight 512 64 8 1
Convert the given Binary number
(11.011)2 into its decimal equivalent Positional 83 82 81 80
Integer part (11)2 = 3 (Refer table 2.2) Notation
Given 1 2 6 5
21 20 2-1 2-2 2-3 number

1 1 . 0 1 1
(1265)8 = 512 ×1 + 64×2 + 8×6 +1×5
= 512 + 128 + 48 + 5
3 + . (0×0.5 + 1×0.25 + 1×0.125) (1265)8 = (693)10
= 3. 375
(11.011)2 = (3.375)10


Chapter 2 Page 018-050.indd 27 17-05-2018 11:59:42

2.4.10 Octal to Binary Conversion 4. Add all the values to get one final
For each Octal digit in the given
number write its 3 digits binary equivalent Example
using positional notation.
Convert (25F)16 into its equivalent
Example Decimal number.
Convert (6213)8 to equivalent
Binary number

6 2 1 3 Weight 256 16 1
Positional 162 161 160

110 010 001 011 Given 2 5 F(15)

(25F)16 = 2×256 + 5×16 + 15×1
Workshop = 512 + 80 +15
(25F)16 = (607)10
5. Convert the following Octal numbers
into Binary numbers. 2.4.12 Hexadecimal to Binary Conversion
(A) 472 (B) 145 (C) 347
(D) 6247 (E) 645 Write 4 bits Binary equivalent
for each Hexadecimal digit for the given
number using positional notation method.
2.4.11 Hexadecimal to Decimal
Conversion Example

To convert Hexadecimal to Decimal Convert (8BC)16 into equivalent

we can use positional notation method. Binary number

1. Write down the Hexadecimal digits 8 B C

and list the powers of 16 from right to
left(Positional Notation)

2. For each positional notation written 1000 1011 1100

for the digit, now write the equivalent (8BC)16 = (100010111100)2

3. Multiply each digit with its

corresponding weight


Chapter 2 Page 018-050.indd 28 17-05-2018 11:59:42

If this bit is 0, it is a positive number and
if it 1, it is a negative number. Therefore
6. Convert the following Hexadecimal a signed binary number has 8 bits, only 7
numbers to Binary numbers bits used for storing values (magnitude)
(A) A6 (B) BE and the 1 bit is used for sign.
(C) 9BC8 (D) BC9
+43 is represented in memory as follows:
Sign bit Magnitude (Value)
2.5 Binary Representation for Signed
0 0 1 0 1 0 1 1
Computers can handle both
positive (unsigned) and negative (signed) Least Significant Bit (LSB)
numbers. The simplest method to Most Significant Bit (MSB )
(‘0’ represent that the number is positive)
represent negative binary numbers is
called Signed Magnitude. In signed
-43 can be represented in memory as
magnitude method, the left most bit is
Most Significant Bit (MSB), is called sign
bit or parity bit. Sign bit Magnitude (Value)
The numbers are represented in
computers in different ways: 1 1 0 1 0 1 0 1

Least Significant Bit (LSB)

• Signed Magnitude representation Most Significant Bit (MSB )
(‘1’ represent that the number is negative)
• 1’s Complement
• 2’s Complement 2.5.2 1’s Complement representation

2.5.1 Signed Magnitude representation This is an easier approach to

represent signed numbers. This is for
The value of the whole numbers
negative numbers only i.e. the number
can be determined by the sign used before
whose MSB is 1.
it. If the number has ‘+’ sign or no sign
it will be considered as positive. If the The steps to be followed to find 1’s
number has ‘–’ sign it will be considered complement of a number:
as negative.
Step 1: Convert given Decimal number
Example: into Binary
+43 or 43 is a positive number Step 2: Check if the binary number
contains 8 bits , if less add 0 at the
–43 is a negative number
left most bit, to make it as 8 bits.
In signed binary representation,
Step 3: Invert all bits (i.e. Change 1 as 0
the left most bit is considered as sign bit.
and 0 as 1)

Chapter 2 Page 018-050.indd 29 17-05-2018 11:59:42

Example 2.6.1 Binary Addition

Find 1’s complement for (–24)10 The following table is useful when
adding two binary numbers.
Given Binary 1’s Compliment
Number Number A B SUM (A + B) Carry
0 0 0 -
(-24)10 00011000 11100111 0 1 1 -
1 0 1 -
2.5.3 2’s Complement representation 1 1 0 1

The 2’s-complement method for In 1 + 1 = 10, is considered as sum

negative number is as follows: 0 and the 1 as carry bit. This carry bit is
a. Invert all the bits in the binary added with the previous position of the bit
sequence (i.e., change every 0 to1 and pattern.
every 1 to 0 ie.,1’s complement)
Example Add: 10112 + 10012
b. Add 1 to the result to the Least
(Carry 1
Bit)→ 1
Significant Bit (LSB).

1 0 1 1
Example 10
+ 1 0 0 1
2’s Complement represent of (-24)10
1 0 1 0 0
Binary equivalent of +24: 11000
8bit format: 00011000 10112 + 10012 = 101002
1’s complement: 11100111 Example Perform Binary addition for the
Add 1 to LSB: +1 following: 2310 + 1210
2’s complement of -24: 11101000
Step 1: Convert 23 and 12 into binary form

Workshop 2310
7. Write the 1’s complement number and 2’s power 16 8 4 2 1
2’s complement number for the following Binary Number 1 0 1 1 1
decimal numbers: 2310 = 000101112
(A) 22 (B) -13 (C) -65 (D) -46
2.6 Binary Arithmetic
2’s power 8 4 2 1
As decimal numbers, the binary Binary Number 1 1 0 0
numbers also permit computations like 1210 = 000011002
addition, subtraction, multiplication and
division. The following session deals only Step 2: Binary addition of 23 and 12:
with binary addition and subtraction.

Chapter 2 Page 018-050.indd 30 17-05-2018 11:59:42

Carry Bit → 1 1 510
2310 = 0 0 0 1 0 1 1 1 2’s power 4 2 1
1210 = 0 0 0 0 1 1 0 0 Binary Number 1 0 1
3510 = 0 0 1 0 0 0 1 1 510 = 000001012

2.6.2 Binary Subtraction Step 2:

The table for Binary Subtraction is 2110 0 0 0 1 0 1 0 1

as follows:
1’s Compliment 1 1 1 0 1 0 1 0
2’s Compliment 1 1 1 0 1 0 1 1
A B Difference Borrow
Step 3:
0 0 0 0 Binary Addition of –21 and 5 :
1 0 1 0
1 1 0 0 Carry bit 1 1 1 1
0 1 1 1 -2110 1 1 1 0 1 0 1 1
510 0 0 0 0 0 1 0 1
When subtracting 1 from 0, borrow
-1610 (Result) 1 1 1 1 0 0 0 0
1 from the next Most Significant Bit, when
borrowing from the next Most Significant
Bit, if it is 1, replace it with 0. If the next Most Workshop
Significant Bit is 0, you must borrow from a 8. Perform the following binary
more significant bit that contains 1 and replace computations:
it with 0 and 0s upto that point become 1s. (A) 1010 + 1510 (B) –1210 + 510
Example Subtract 10010102 – 101002 (C) 1410 – 1210 (D) (–210) – (–610)

0 1 10 0 10
2.7 Representing Characters in Memory
1 0 0 1 0 1 0
(-) 1 0 1 0 0 As represented in introduction,
all the input data given to the computer
1 1 0 1 1 0 should be in understandable format. In
general, 26 uppercase letters, 26 lowercase
Example Perform binary addition for the letters, 0 to 9 digits and special characters
following: (–21)10 + (5)10 are used in a computer, which is called
Step 1: Change -21 and 5 into binary form character set. All these character set
are denoted through numbers only. All
2110 Characters in the character set needs
a common encoding system. There
2’s power 16 8 4 2 1
are several encoding systems used for
Binary Number 1 0 1 0 1
computer. They are
2110 = 000101012


Chapter 2 Page 018-050.indd 31 17-05-2018 11:59:42

• BCD – Binary Coded Decimal is formulated by International Business
Machine(IBM). The coding system can
• EBCDIC – Extended Binary Coded
handle 256 characters. The input code
Decimal Interchange Code
in ASCII can be converted to EBCDIC
• ASCII – American Standard Code for system and vice - versa.
Information Interchange
2.7.4 Indian Standard Code for
• Unicode Information Interchange (ISCII)
• ISCII - Indian Standard Code for
Information Interchange ISCII is the system of handling
the character of Indian local languages.
2.7.1 Binary Coded Decimal (BCD) This as a 8-bit coding system. Therefore
it can handle 256 (28) characters. This
This encoding system is not in the system is formulated by the department
practice right now. This is 26 bit encoding of Electronics in India in the year 1986-
system. This can handle 26 = 64 characters 88 and recognized by Bureau of Indian
only. Standards (BIS). Now this coding system
is integrated with Unicode.
2.7.2 American Standard Code for
Information Interchange (ASCII) 2.7.5 Unicode
This is the most popular encoding This coding system is used in
system recognized by United States. most of the modern computers. The
Most of the computers use this system. popular coding scheme after ASCII
Remember this encoding system can is Unicode. ASCII can represent only
handle English characters only. This can 256 characters. Therefore English and
handle 27 bit which means 128 characters. European Languages alone can be
In this system, each character has handled by ASCII. Particularly there was
individual number (Refer Appendix). a situation, when the languages like Tamil,
Malayalam, Kannada and Telugu could
The new edition (version) ASCII -8, not be represented by ASCII. Hence, the
has 2 bits and can handle 256 characters are
Unicode was generated to handle all the
represented from 0 to 255 unique numbers. coding system of Universal languages.
The ASCII code equivalent to This is 16 bit code and can handle 65536
the uppercase letter ‘A’ is 65. The binary characters.
representation of ASCII (7 bit) value is
1000001. Also 01000001 in ASCII-8 bit. Unicode scheme is denoted by
hexadecimal numbers. The Unicode table
2.7.3 Extended Binary Coded Decimal of Tamil, Malayalam, Telugu and Kannada
Interchange Code (EBCDIC) is shown Table 2.6

This is similar to ASCII Code with

8 bit representation. This coding system


Chapter 2 Page 018-050.indd 32 17-05-2018 11:59:42

Table 2.6
Unicode Table of Tamil Unicode Table of Malayalam

0B8 0B9 0BA 0BB 0BC 0BD 0BE 0BF 0D0 0D1 0D2 0D3 0D4 0D5 0D6 0D7

0 ஐ ர $ீ ௐ ௰ 0 $ഀ ഐ ഠ ര $ീ ൠ ൰
0B90 0BB0 0BC0 0BD0 0BF0 0D00 0D10 0D20 0D30 0D40 0D60 0D70

1 ற $
ு ௱ 1 $ഁ ഡ റ $ു ൡ ൱
0BB1 0BC1 0BF1 0D01 0D21 0D31 0D41 0D61 0D71

2 $ஂ ஒ $
ல ூ ௲ 2 $ം ഒ ഢ ല $ൂ $ൢ ൲
0B82 0B92 0BB2 0BC2 0BF2 0D02 0D12 0D22 0D32 0D42 0D62 0D72

3 ஃ ஓ ண ள ௳ 3 $ഃ ഓ ണ ള $ ൃ $ൣ ൳
0B83 0B93 0BA3 0BB3 0BF3 0D03 0D13 0D23 0D33 0D43 0D63 0D73

4 ஔ த ழ ௴ 4 ഔ ത ഴ $ൄ ൔ ൴
0B94 0BA4 0BB4 0BF4 0D14 0D24 0D34 0D44 0D54 0D74

5 அ க வ ௵ 5 അ ക ഥ വ ൕ ൵
0B85 0B95 0BB5 0BF5 0D05 0D15 0D25 0D35 0D55 0D75

6 ஆ ஶ $ெ ௦ ௶ 6 ആ ഖ ദ ശ $െ ൖ ൦ ൶
0B86 0BB6 0BC6 0BE6 0BF6 0D06 0D16 0D26 0D36 0D46 0D56 0D66 0D76

7 இ ஷ $ே $ௗ ௧ ௷ 7 ഇ ഗ ധ ഷ $ േ $ൗ ൧ ൷
0B87 0BB7 0BC7 0BD7 0BE7 0BF7 0D07 0D17 0D27 0D37 0D47 0D57 0D67 0D77

8 ஈ ந ஸ $ை ௨ ௸ 8 ഈഘ ന സ $ൈ ൘ ൨ ൸
0B88 0BA8 0BB8 0BC8 0BE8 0BF8 0D08 0D18 0D28 0D38 0D48 0D58 0D68 0D78

9 உ ங ன ஹ ௩ ௹ 9 ഉ ങ ഩ ഹ ൙ ൩ ൹
0B89 0B99 0BA9 0BB9 0BE9 0BF9 0D09 0D19 0D29 0D39 0D59 0D69 0D79

A ஊ ச ப $ொ ௪ ௺ A ഊ ച പ ഺ $ൊ ൚ ൪ ൺ
0B8A 0B9A 0BAA 0BCA 0BEA 0BFA 0D0A 0D1A 0D2A 0D3A 0D4A 0D5A 0D6A 0D7A

B $ோ ௫ B ഋ ഛ ഫ $഻ $ോ ൛ ൫ ൻ
0BCB 0BEB 0D0B 0D1B 0D2B 0D3B 0D4B 0D5B 0D6B 0D7B

C ஜ $ௌ ௬ C ഌ ജ ബ $഼ $ൌ ൜ ൬ ർ
0B9C 0BCC 0BEC 0D0C 0D1C 0D2C 0D3C 0D4C 0D5C 0D6C 0D7C

D $் ௭ D ഝ ഭ ഽ $് ൝ ൭ ൽ
0BCD 0BED 0D1D 0D2D 0D3D 0D4D 0D5D 0D6D 0D7D

E எ ஞ ம $ா ௮ E എ ഞ മ $ാ ൎ ൞ ൮ ൾ
0B8E 0B9E 0BAE 0BBE 0BEE 0D0E 0D1E 0D2E 0D3E 0D4E 0D5E 0D6E 0D7E

F ஏ ட ய $ி ௯ F ഏ ട യ $ി ൥ ൟ ൯ ൿ
0B8F 0B9F 0BAF 0BBF 0BEF 0D0F 0D1F 0D2F 0D3F 0D4F 0D5F 0D6F 0D7F


Chapter 2 Page 018-050.indd 33 17-05-2018 11:59:42

Table 2.6
Unicode Table of Telugu Unicode Table of Kannada

0C0 0C1 0C2 0C3 0C4 0C5 0C6 0C7 0C8 0C9 0CA 0CB 0CC 0CD 0CE 0CF

0 $ఀ ఐ ఠ ర $ీ ౠ 0 ಀ ಐ ಠ ರ $ೀ ೠ
0C00 0C10 0C20 0C30 0C40 0C60 0C80 0C90 0CA0 0CB0 0CC0 0CE0

1 $ఁ డ ఱ $ు ౡ 1 $ಁ ಡ ಱ $ು ೡ ೱ
0C01 0C21 0C31 0C41 0C61 0C81 0CA1 0CB1 0CC1 0CE1 0CF1

2 $ం ఒ ఢ ల $ూ $ౢ 2 $ಂ ಒ ಢ ಲ $ೂ $ೢ ೲ
0C02 0C12 0C22 0C32 0C42 0C62 0C82 0C92 0CA2 0CB2 0CC2 0CE2 0CF2

3 $ః ఓ ణ ళ $ృ $ౣ 3 $ಃ ಓ ಣ ಳ $ೃ $ೣ
0C03 0C13 0C23 0C33 0C43 0C63 0C83 0C93 0CA3 0CB3 0CC3 0CE3

4 ఔ త  $ౄ 4 ಔ ತ $ೄ
0C14 0C24 0C34 0C44 0C94 0CA4 0CC4

5 అ క థ వ $ౕ 5 ಅ ಕ ಥ ವ $ೕ
0C05 0C15 0C25 0C35 0C55 0C85 0C95 0CA5 0CB5 0CD5

6 ఆ ఖ ద శ $ె $ౖ ౦ 6 ಆ ಖ ದ ಶ $ೆ $ೖ ೦
0C06 0C16 0C26 0C36 0C46 0C56 0C66 0C86 0C96 0CA6 0CB6 0CC6 0CD6 0CE6

7 ఇ గ ధ ష $ే ౧ 7 ಇ ಗ ಧ ಷ $ೇ ೧
0C07 0C17 0C27 0C37 0C47 0C67 0C87 0C97 0CA7 0CB7 0CC7 0CE7

8 ఈ ఘ న స $ై ౘ ౨ ౸ 8 ಈ ಘ ನ ಸ $ೈ ೨
0C08 0C18 0C28 0C38 0C48 0C58 0C68 0C78 0C88 0C98 0CA8 0CB8 0CC8 0CE8

9 ఉ ఙ హ ౙ ౩ ౹ 9 ಉ ಙ ಹ ೩
0C09 0C19 0C39 0C59 0C69 0C79 0C89 0C99 0CB9 0CE9

A ఊ చ ప $ొ ౚ ౪ ౺ A ಊ ಚ ಪ $ೊ ೪
0C0A 0C1A 0C2A 0C4A 0C5A 0C6A 0C7A 0C8A 0C9A 0CAA 0CCA 0CEA

B ఋ ఛ ఫ $ో ౫ ౻ B ಋ ಛ ಫ $ೋ ೫
0C0B 0C1B 0C2B 0C4B 0C6B 0C7B 0C8B 0C9B 0CAB 0CCB 0CEB

C ఌ జ బ $ౌ ౬ ౼ C ಌ ಜ ಬ $಼ $ೌ ೬
0C0C 0C1C 0C2C 0C4C 0C6C 0C7C 0C8C 0C9C 0CAC 0CBC 0CCC 0CEC

D ఝ భ ఽ $్ ౭ ౽ D ಝ ಭ ಽ $್ ೭
0C1D 0C2D 0C3D 0C4D 0C6D 0C7D 0C9D 0CAD 0CBD 0CCD 0CED

E ఎ ఞ మ $ా ౮ ౾ E ಎ ಞ ಮ $ಾ ೞ ೮
0C0E 0C1E 0C2E 0C3E 0C6E 0C7E 0C8E 0C9E 0CAE 0CBE 0CDE 0CEE

F ఏ ట య $ి ౯ ౿ F ಏ ಟ ಯ $ಿ ೯
0C0F 0C1F 0C2F 0C3F 0C6F 0C7F 0C8F 0C9F 0CAF 0CBF 0CEF


Chapter 2 Page 018-050.indd 34 17-05-2018 11:59:42

American Standard Code for Information Interchange (ASCII)
(Few specific characters only)

Decimal Binary number Octal Hexadecimal

number (8 bit) number number
A 65 01000001 101 41
B 66 01000010 102 42
C 67 01000011 103 43
D 68 01000100 104 44
E 69 01000101 105 45
F 70 01000110 106 46
G 71 01000111 107 47
H 72 01001000 110 48
I 73 01001001 111 49
J 74 01001010 112 4A
K 75 01001011 113 4B
L 76 01001100 114 4C
M 77 01001101 115 4D
N 78 01001110 116 4E
O 79 01001111 117 4F
P 80 01010000 120 50
Q 81 01010001 121 51
R 82 01010010 122 52
S 83 01010011 123 53
T 84 01010100 124 54
U 85 01010101 125 55
V 86 01010110 126 56
W 87 01010111 127 57
X 88 01011000 130 58
Y 89 01011001 131 59
Z 90 01011010 132 5A
a 97 01100001 141 61
b 98 01100010 142 62
c 99 01100011 143 63
d 100 01100100 144 64
e 101 01100101 145 65


Chapter 2 Page 018-050.indd 35 17-05-2018 11:59:43

f 102 01100110 146 66
g 103 01100111 147 67
h 104 01101000 150 68
i 105 01101001 151 69
j 106 01101010 152 6A
k 107 01101011 153 6B
l 108 01101100 154 6C
m 109 01101101 155 6D
n 110 01101110 156 6E
o 111 01101111 157 6F
p 112 01110000 160 70
q 113 01110001 161 71
r 114 01110010 162 72
s 115 01110011 163 73
t 116 01110100 164 74
u 117 01110101 165 75
v 118 01110110 166 76
w 119 01110111 167 77
x 120 01111000 170 78
y 121 01111001 171 79
z 122 01111010 172 7A


Decimal Binary number Octal Hexadecimal

number (8 bit) number number
0 48 00110000 60 30
1 49 00110001 61 31
2 50 00110010 62 32
3 51 00110011 63 33
4 52 00110100 64 34
5 53 00110101 65 35
6 54 00110110 66 36
7 55 00110111 67 37
8 56 00111000 70 38
9 57 00111001 71 39


Chapter 2 Page 018-050.indd 36 17-05-2018 11:59:43

Special Characters

Special Decimal Binary number Octal Hexadecimal

symbols number (8 bit) number number
Blank 32 00100000 40 20
! 33 00100001 41 21
" 34 00100010 42 22
# 35 00100011 43 23
$ 36 00100100 44 24
% 37 00100101 45 25
& 38 00100110 46 26
' 39 00100111 47 27
( 40 00101000 50 28
) 41 00101001 51 29
* 42 00101010 52 2A
+ 43 00101011 53 2B
, 44 00101100 54 2C
- 45 00101101 55 2D
. 46 00101110 56 2E
/ 47 00101111 57 2F
: 58 00111010 72 3A
; 59 00111011 73 3B
< 60 00111100 74 3C
= 61 00111101 75 3D
> 62 00111110 76 3E
? 63 00111111 77 3F
@ 64 01000000 100 40
[ 91 01011011 133 5B
\ 92 01011100 134 5C
] 93 01011101 135 5D
^ 94 01011110 136 5E
_ 95 01011111 137 5F
` 96 01100000 140 60
{ 123 01111011 173 7B
| 124 01111100 174 7C
} 125 01111101 175 7D
~ 126 01111110 176 7E


Chapter 2 Page 018-050.indd 37 17-05-2018 11:59:43


Part I

I Choose the best answer

1. Which refers to the number of bits processed by a computer’s CPU?

A) Byte B) Nibble C) Word length D) Bit

2. How many bytes does 1 KiloByte contain?

A) 1000 B) 8 C) 4 D) 1024

3. Expansion for ASCII

A) American School Code for Information Interchange

B) American Standard Code for Information Interchange

C) All Standard Code for Information Interchange

D) American Society Code for Information Interchange

4. 2^50 is referred as

A) Kilo B) Tera C) Peta D) Zetta

5. How many characters can be handled in Binary Coded Decimal System?

A) 64 B) 255 C) 256 D) 128

6. For 11012 what is the Hexadecimal equivalent?

A) F B) E C) D D) B

7. What is the 1’s complement of 00100110?

A) 00100110 B) 11011001 C) 11010001 D) 00101001

8. Which amongst this is not an Octal number?

A) 645 B) 234 C) 876 D) 123


Chapter 2 Page 018-050.indd 38 17-05-2018 11:59:43

II Very Short Answers

1. What is data?

2. Write the 1’s complement procedure.

3. Convert (46)10 into Binary number

4. We cannot find 1’s complement for (28)10. State reason.

5. List the encoding systems for characters in memory.

III Short Answers

1. What is radix of a number system? Give example

2. Write note on binary number system.

3. Convert (150)10 into Binary, then convert that Binary number to Octal

4. Write short note on ISCII

5. Add a) -2210+1510 b) 2010+2510

IV Detail Answers

1. a) Write the procedure to convert fractional Decimal to Binary

b) Convert (98.46)10 to Binary

2. Find 1’s Complement and 2’s Complement for the following Decimal number

a) -98 b) -135

3. a) Add 11010102+1011012

b) Subtract 11010112 - 1110102


Chapter 2 Page 018-050.indd 39 17-05-2018 11:59:43

Part - II - Boolean Algebra

2.8 Introduction 3. Chennai is capital of India? Yes /

Boolean algebra is a mathematical
discipline that is used for designing 4. What did I say yesterday?
digital circuits in a digital computer. It
describes the relation between inputs The first three questions
and outputs of a digital circuit. The thrown above, the answer may be True
name Boolean algebra has been given (Yes) or False (No). But the fourth
in honor of an English mathematician one, we cannot be answer as True or
George Boole who proposed the False. Thus, sentences which can be
basic principles of this algebra. determined to be True or False are
called “Logical Statement” or “Truth
George Boole (1815-1864) Functions”. The results True or False are
was born called “Truth Values”. The truth values
to a low depicted by logical constant 1 and 0;
c l a s s 1 means True and 0 means False. The
family and only variable which can store these truth
received an values are called “Logical variable” or
elementary school “Binary valued variables” or “Boolean
education. Despite that, he taught himself Variables” as these can store one
highly advanced mathematics and of the two values of True or False.
different languages as a teenager without
any assistance. He started teaching at 2.8.2 Logical Operations:
age sixteen, and started his own school
Boolean algebra makes use of
at age nineteen. By his mid-twenties,
variables and operations (functions).
he had mastered most of the important
The basic logical operations are AND,
mathematical principles in his day.
OR and NOT, which are symbolically
represented by dot ( . ), plus ( + ),
2.8.1 Binary valued quantities: and by over bar / single apostrophe
respectively. These symbols are
Every day we have to make logical also called as “Logical Operators”.
2.8.3 Truth Table:
1. Should I carry Computer Science
book every day? Yes / No A truth table represents
all the possible values of logical
2. 8-10 = 10 is this answer correct? variable or statements along with
Yes / No all the possible results of given
combination of truth values.

Chapter 2 Page 018-050.indd 40 17-05-2018 11:59:43

2.8.4 AND operator table for a NOT operator where A is the input
variable and Y is the output is shown below:
The AND operator is defined in Boolean
algebra by the use of the dot (.) operator. It is A Y
similar to multiplication in ordinary algebra.
0 1
The AND operator combines two or more
input variables so that the output is true only 1 0
if all the inputs are true. The truth table for a
The NOT operator is represented
2-input AND operator is shown as follows:
algebraically by the Boolean expression:
0 0 0 Example:
0 1 0 Consider the Boolean equation:
1 0 0 D=A+(B.C)
1 1 1 D is equal to 1 (true) if A is 1 or if
( B . C ) is 1, that is, B = 0 and C = 1.
The above 2-input AND operation is
expressed as: Y = A . B Otherwise D is equal to 0 (false).
2.8.5 OR operator The basic logic functions AND, OR,
and NOT can also be combined to make
The plus sign is used to indicate the OR
other logic operators such as NAND and
operator. The OR operator combines two or
more input variables so that the output is true
if at least one input is true. The truth table for 2.8.7 NAND operator
a 2-input OR operator is shown as follows:
The NAND is the combination of
A B Y NOT and AND. The NAND is generated by
inverting the output of an AND operator.
0 0 0
The algebraic expression of the NAND
0 1 1 function is:
1 0 1 Y=A.B
1 1 1 The NAND function truth table is
shown below:
The above 2-input OR operation is
expressed as: Y = A + B A B Y
2.8.6 NOT operator 0 0 1

The NOT operator has one input and 0 1 1

one output. The input is either true or false, 1 0 1
and the output is always the opposite, that is, 1 1 0
the NOT operator inverts the input. The truth

Chapter 2 Page 018-050.indd 41 17-05-2018 11:59:43

2.8.8 NOR operator The output is "true" only when both
inputs are "true", otherwise, the output is
The NOR is the combination of "false". In other words the output will be 1 if
NOT and OR. The NOR is generated by and only if both inputs are 1; otherwise the
inverting the output of an OR operator. output is 0. The output of the AND gate is
The algebraic expression of the NOR represented by avariable say C, where A and
function is: B are two and if input boolean variables. In
boolean algebra, a variable can take either of
Y=A+B the values '0' or '1'. The logical symobl of the
AND gate is
The NOR function truth table is shown
below: A
0 0 1
Fig. 2.4 Logic symbol of AND Gate
0 1 0
One way to symbolize the action
1 0 0
of an AND gate is by writing the boolean
1 1 0 function.


2.9 Basic Logic Gates: In boolean algebra the multiplication

sign stands for the AND operation.
A gate is a basic electronic circuit Therefore, the output of the AND gate is
which operates on one or more signals to
produce an output signal. There are three C = A . B or
fundamental gates namely AND, OR and
NOT. The other logic gates like NAND, simply C = AB
NOR, XOR and XNOR are derived gates
which are derived from the fundamental Read this as "C equals A AND B".
gates. NAND and NOR gates are called Since there are two input variables here, the
Universal gates, because the fundamental truth table has four entries, because there
logic gates can be realized through them. are four possible inputs : 00, 01, 10 and 11.

2.9.1 AND Gate For instance if both inputs are 0,

The AND gate can have two or C = A . B

more input signals and produce an output
= 0 . 0
= 0


Chapter 2 Page 018-050.indd 42 17-05-2018 11:59:43

The truth table for AND Gate is Input Output
Input Output 0 0 0
A B C 0 1 1
0 0 0 1 0 1
0 1 0 1 1 1
1 0 0
1 1 1 Table 2.8 Truth Table for OR Gate

Table 2.7 Truth Table for AND Gate 2.9.3 NOT Gate

2.9.2 OR Gate The NOT gate, called a logical

inverter, has only one input. It reverses the
The OR gate gets its name from its logical state. In other words the output C
behaviour like the logical inclusive "OR". is always the complement of the input. The
The output is "true" if either or both of the logical symbol of the NOT gate is
inputs are "true". If both inputs are "false"
then the output is "false". In otherwords the A C=A
output will be 1 if and only if one or both
inputs are 1; otherwise, the output is 0. The
logical symbol of the OR gate is Fig. 2.6 Logic symbol of NOT Gate

A The boolean function of NOT gate is


Fig. 2.5 Logic symbol of OR Gate In boolean algerbra, the overbar stands for
NOT operation. Therefore,
The OR gate output is
C = A
C = A OR B
Read this as "C equals NOT A" or "C equals
We use the + sign to denote the OR function. the complement of A".
If A is 0,
C = A + B
C = 0 = 1
Read this as "C equals A OR B".
On the otherhand, if A is 1,
For instance, if both the inputs are 1
C = 1 = 0
C = A + B = 1 + 1 = 1
The truth table for NOT gate is
The truth table for OR gate is


Chapter 2 Page 018-050.indd 43 17-05-2018 11:59:43

Input Output Input Output
1 0 0 0 1
0 1 0
0 1
1 0 0
1 1 0
Table 2.9 Truth Table for NOT Gate
Table 2.10 Truth Table for NOR Gate
2.9.4 NOR Gate
2.9.5 Bubbled AND Gate
The NOR gate circuit is an OR gate
followed by an an inverter. Its output is
The Logic Circuit of Bubbled AND
"true" if both inputs are "false" Otherwise,
the output is "false". In other words, the
only way to get '1' as output is to have
both inputs '0'. Otherwise the output is 0.
The logic circuit of the NOR gateis
Fig. 2.7 Logic Circuit of NOR Gate
Fig. 2.9 Logic circuit of Bubbled AND Gate
C In the above circuit, invertors on the
input lines of the AND gate gives the output
Fig. 2.8 Logic symbol of NOR Gate
C = ( A . B)
The output of NOR gate is
This circuit can be redrawn as the
bubbles on the inputs, where the bubbles
C = ( A + B) represent inversion.

Read this as "C equals NOT of A OR A

B" or "C equals the complement of A OR B". C

For example if both the inputs are 0,

Fig. 2.10 Logic Symbol of Bubbled AND Gate
C = ( 0 + 0) = 0 = 1
We refer this as bubbled AND gate.
The truth table for NOR gate is Let us analyse this logic circuit for all input


Chapter 2 Page 018-050.indd 44 17-05-2018 11:59:43

If A = 0 and B = 0 C=(0.0) = 1.1 = 1 A
If A = 0 and B = 1 C=(0.1) = 1.0 = 0
Fig. 2.11 Logic Circuit of NAND Gate
If A = 1 and B = 0 C=(1.0) = 0.1 = 0
The logical symbol of NAND gate is
If A = 1 and B = 1 C=(1.1) = 0.0 = 0 A
Here the truth table is B

Input Output Fig. 2.12 Logic Symbol of NAND Gate

0 0 1 The output of the NAND gate is
0 1 0
C = (A . B)
1 0 0
1 1 0 Read this as "C" equals NOT of A
AND B" or "C" equals the complement of A
You can see that, a bubbled AND gate AND B".
produces the same output as a NOR gate. So, For example if both the inputs are 1
You can replace each NOR gate by a bubbled
AN D gate. In other words the circuits are C = (1 . 1)= 1 = 0
interchangeable. The truth table for NAND gate is
Therefore Input Output
(A + B) = A . B A B C
0 0 1
Which establishes the De Morgan's first 0 1 1
theorem. 1 0 1
1 1 0
2.9.6 NAND Gate
Table 2.11 Truth Table for NAND Gate
The NAND gate operates an AND
2.9.7 Bubbled OR Gate
gate followed by a NOT gate. It acts in the
manner of the logical operation "AND" The logic circuit of bubbled OR gate
followed by inversion. The output is "false" is
if both inputs are "true", otherwise, the A
output is "true". In otherwords the output
of the NAND gate is 0 if and only if both C=A + B
the inputs are 1, otherwise the output is 1.
The logice circuit of NAND gate is B B

Fig. 2.13 Logic Circuit of Bubbled OR Gate


Chapter 2 Page 018-050.indd 45 17-05-2018 11:59:43

The output of this circuit can be are different, but 0 if the inputs are the same.
written as C = A + B The logic circuit of XOR gate is

The above circuit can be redrawn as A A A.B

the bubbles on the input, where the bubbles B
represents the inversion. C = A.B+ A.B

Fig. 2.15 Logic Circuit of XOR Gate
Fig. 2.14 Logic Symbol of Bubbled OR Gate
The output of the XOR gate is
We refer this as bubbled OR gate. The truth
The truth table for XOR gate is
table for the bubbled OR is
Input Output
Input Output A B C
A B C 0 0 0
0 0 1 0 1 1
0 1 1 1 0 1
1 0 1 1 1 0
1 1 0
Table 2.13 Truth Table for XOR Gate
Table 2.12 Truth Table for Bubbled OR Gate
In boolean algebra. exclusive - OR operator
If we compare the truth tables of the ⊕ or "encircled plus".
bubbled OR gate with NAND gate, they are
Hence C = A ⊕B
identical. So the circuits are interchangeable.
The logical symbol of XOR gate is
Therefore, A
(A . B) = A + B C

Which establishes the De Morgan's second

Fig. 2.16 Logic Symbol of XOR Gate
2.9.9 XNOR Gate
2.9.8 XOR Gate
The XNOR (exclusive - NOR) gate
The XOR (exclusive - OR) gate acts is a combination XOR gate followed by an
in the same way as the logical "either/or." inverter. Its output is "true" if the inputs
The output is "true" if either, but not both, are the same, and "false" if the inputs are
of the inputs are "true". The output is "false" different. In simple words, the output is 1 if
if both inputs are "false" or if both inputs are the input are the same, otherwise the output
"true." Another way of looking at this circuit is 0. The logic circuit of XNOR gate is
is to observe that the output is 1 if the inputs


Chapter 2 Page 018-050.indd 46 17-05-2018 11:59:43


Fig. 2.17 Logic Circuit of XNOR Gate

The output of the XNOR is NOT of XOR



= AB + A B

(Using De Morgan's Theorem)

In boolean algebra, ⊙ or "included dot" stands for the XNOR.

Therefore, C=A⊙B

The logical symbol is

C=A ⊙ B

Fig. 2.18 Logic Symbol of XNOR Gate

The truth table for XNOR Gate is

Input Output
0 0 1
0 1 0
1 0 0
1 1 1

Table 2.14 Truth Table for XNOR Gate

Using combination of logic gates, complex operations can be performed. In theory,

there is no limit to the number of gates that can be arranged together in a single device. But in
practice, there is a limit to the number of gates that can be packed into a given physical space.
Arrays of logic gates are found in digital integrated circuits.


Chapter 2 Page 018-050.indd 47 17-05-2018 11:59:43

Theorems of
Boolean Algebra

Identity Involution
A + 0 = A (A) = A
A . 1 = A
Complement A + A = A
A+A =1 A.A=A
A . A = 0
Commutative A + (A . B) = A
A + B = B + A A . (A + B) = A
A . B = B . A
3rd Distributive
Associative A + A . B = A + B
A + (B + C) = (A + B) + C
A . (B . C) = (A . B) . C De Morgan’s
A + B = A . B
Distributive (A . B) = A + B
A . (B + C) = A . B + A . C
A + (B . C) = (A + B) . (A + C)

Null Element
A + 1 = 1
A . 0 = 0


Chapter 2 Page 018-050.indd 48 17-05-2018 11:59:43

Table 2. 15
Logic Gates and their corresponding Truth Tables

Logical Gates Symbol Truth Table

0 0 0
AND 0 1 0
1 0 0
1 1 1
0 0 0
OR 0 1 1
1 0 1
1 1 1
NOT 0 1
1 0
0 0 1
NAND 0 1 1
1 0 1
1 1 0
0 0 1
NOR 0 1 0
1 0 0
1 1 0
0 0 0
XOR 0 1 1
1 0 1
1 1 0
0 0 1
XNOR 0 1 0
1 0 0
1 1 1


Chapter 2 Page 018-050.indd 49 17-05-2018 11:59:43


Part – I
1. Which is a basic electronic circuit which operates on one or more signals?
(A) Boolean algebra (B) Gate
(C) Fundamental gates (D) Derived gates
2. Which gate is called as the logical inverter?
(A) AND (B) OR
3. A+A=?
(A) A (B) O
(C ) 1 (D) A
4. NOR is a combination of ?
5. NAND is called as …… Gate
(A) Fundamental Gate (B) Derived Gate
(C ) Logical Gate (D) Electronic gate

1. What is Boolean Algebra?
2. Write a short note on NAND Gate.
3. Draw the truth table for XOR gate.
4. Write the associative laws?
5. What are derived gates?

Part – III
1. Write the truth table of fundamental gates.
2. Write a short note on XNOR gate.
3. Reason out why the NAND an NOR are called universal gates?
4. Give the truth table of XOR gate.
5. Write the De Morgan’s law.

1. Explain the fundamental gates with expression and truth table.
2. How AND and OR can be realized using NAND and NOR gate.
3. Explain the Derived gates with expression and truth table.


Chapter 2 Page 018-050.indd 50 17-05-2018 11:59:43

Unit I Fundamentals of Computers CHAPTER
Computer Organization

Learning Objectives 3.1 Introduction

Computer organization deals with

• To know the organization of the the hardware components of a computer
computer components and their system. It includes Input / Output devices,
interconnections. the Central Processing Unit, storage devices
and primary memory. It is concerned with
• To know the processors and their how the various components of computer
characteristics. hardware operate. It also deals with how
they are interconnected to implement
• To know the importance of memory an architectural specification. The term
devices and their roles in a computer. computer organization looks similar to
the term computer architecture. But,
• To explore RAM, ROM and
computer architecture deals with the
differentiate each of them.
engineering considerations involved in
• To know about cache memory and designing a computer. On the other hand,
how it improves the performance of Computer Organization deals with the
a computer hardware components that are transparent
to the programmer.
• To know the secondary devices and
their usage 3.2. Basics of Microprocessors

• To know about the ports and The CPU is the major component of
interfaces so that external devices a computer, which performs all tasks. This
can be connected is realized by the microprocessor which
is an Integrated Circuit. Microprocessors
were first introduced in early 1970s. The
first general purpose microprocessor,
4004 was developed by Intel Inc.

The microprocessor is a
programmable multipurpose silicon chip.
It is driven by clock pulses. It accepts input
as a binary data and after processing,
it provides the output data as per the

Chapter 3 Page 051-063.indd 51 17-05-2018 12:06:13

instructions stored in the memory. A Characteristics of Microprocessors
block diagram of a microprocessor based
A Microprocessor’s performance
system is shown in Figure 3.1.
depends on the following characteristics:
Input Microprocessor Output
a) Clock speed
b) Instruction set
Memory c) Word size

Figure 3.1 A Microprocessor - Based System Speed Measurement

Hertz – abbreviated as Hz is the
The microprocessor is made up of 3
standard unit of measurement
main units. They are:
used for measuring frequency.
• Arithmetic and Logic unit (ALU): Since frequency is measured in cycles
To perform arithmetic and logical per second, one hertz equals one cycle
instructions based on computer per second.
instructions. Hertz is commonly used to
• Control unit: To control the overall measure wave frequencies, such as
operations of the computer through sound waves, light waves, and radio
signals. waves. For example, the average human
ear can detect sound waves between 20
• Registers (Internal Memory): They and 20,000 Hz. Sound waves close to 20
are used to hold the instruction and Hz have a low pitch and are called "bass"
data for the execution of the processor. frequencies. Sound waves above 5,000
Hz have a high pitch and are called
The microprocessor is able to "treble" frequencies.
communicate with the memory units
and the Input / Output devices as in While hertz can be used to
Figure 3.2. The system bus is a bunch measure wave frequencies, it is also
of wires which is the collection of used to measure the speed of computer
address bus, data bus and control bus processors. For example, each CPU
that serves as communication channels is rated at a specific clock speed. This
between the Microprocessor and other number indicates how many instruction
devices. cycles the processor can perform in
every second. Since modern processors
Input / Output
can perform millions or even billions of
ALU Register
instructions per second, clock speeds
Control Unit
System are typically measured in megahertz or
Micro Processor Memory gigahertz.

Figure 3.2 Interconnecting the Microprocessor

with Other Devices

Chapter 3 Page 051-063.indd 52 17-05-2018 12:06:13

a) Clock Speed
The first commercial
Every microprocessor has an microprocessor, Intel 4004 is a
internal clock that regulates the speed at 4 bit processor. It has 4 input
which it executes instructions. The speed pins and 4 output pins. Number
at which the microprocessor executes of output pins is always equal to the
instructions is called the clock speed. number of input pins. It can process 4
Clock speed is measured in MHz (Mega bits at a time. So it is called as a 4 bit
Hertz) or in GHz (Giga Hertz).
Intel 4004
b) Instruction Set

A command which is given to

a computer to perform an operation
on data is called an instruction. Basic
set of machine level instructions that a
microprocessor is designed to execute
is called as an instruction set. This Produced From late 1971 to
instruction set carries out the following 1981
types of operations: Manufacturer Intel Inc.
Clock Speed 740 kHZ
• Data transfer Size 10 Micrometer (µm)
Transistors 2300
• Arithmetic operations Data width 4 bits
Package 16 pin
• Logical operations
Intel Inc. released many
• Control flow microprocessors like Intel 8085 which is
an 8 bit processor, Intel 8086 which is
• Input/output a 16 bit processor and so on. Currently
most of the microprocessors use 32 bit
c) Word Size or 64 bit architecture.

• The number of bits that can be processed

by a processor in a single instruction 3.3 Data communication between
is called its word size. Word size CPU and memory
determines the amount of RAM that can
The Central Processing Unit(CPU)
be accessed by a microprocessor at one
has a Memory Data Register (MDR) and
time and the total number of pins on the a Memory Address Register (MAR). The
microprocessor. Total number of input Memory Data Register (MDR) keeps the
and output pins in turn determines the data which is transferred between the
architecture of the microprocessor. Memory and the CPU. The Program


Chapter 3 Page 051-063.indd 53 17-05-2018 12:06:13

Counter (PC) is a special register in the Register (MDR). If the processor is an
CPU which always keeps the address of 8-bit processor like Intel 8085, its MDR
the next instruction to be executed. The and the word in the RAM both have 8 bits.
Arithmetic and Logic unit of CPU places
the address of the memory to be fetched, If the size of the MDR is eight bits,
into the Memory Address Register. which can be connected with a word in
A bus is a collection of wires used the memory which is also eight bits size.
for communication between the internal The data bus has eight parallel wires to
components of a computer. The address transfer data either from MDR to word or
bus is used to point a memory location. A word to MDR based on the control(Read
decoder, a digital circuit is used to point or write). This control line is labeled as
to the specific memory location where the R/W , which becomes 1 means READ
word can be located. The address register operation and 0 means WRITE operation.
is connected with the address bus, which Figure 3.4 shows the content of MDR and
provides the address of the instruction. A the word before the READ operation.Also,
data bus is used to transfer data between
Figure 3.5 shows the content of MDR and
the memory and the CPU. The data bus
the word after the READ operation.
is bidirectional and the address bus is
unidirectional. The control bus controls MDR Memory Word
both read and write operations. The read
operation fetches data from memory and
transfers to MDR. A single control line
performs two operations like Read/Write
using 1or 0. Also, the write operation
transfers data from the MDR to memory.
Figure 3.4 Before the read operation
This organization is shown in Figure 3.3.
MDR Memory Word
Address Bus 11001010 11001010
When R/W=1

Control Unit
MAR Word
CPU R/W Memory

Data Bus Figure 3.5 After the read operation

The read operation transfers the

Figure 3.3 Bus connectivity between CPU
data(bits) from word to Memory Data
and Memory
Register. The write operation transfers the
The word in the RAM has the same data(bits) from Memory Data Register to
size (no. of bits) as the Memory Data word.


Chapter 3 Page 051-063.indd 54 17-05-2018 12:06:14

hardware was expensive as well as
If 5V is applied at one end of difficult to build. As technology had
a wire, the other end also can developed to overcome these issues, more
receive 5V. In the same way, and more complex instructions were
the buses are wires, and the added to increase the functionality of
binary data are voltages (5V as 1 and microprocessors. Let us learn more about
0V as 0), and these buses can simply the two types of microprocessors based on
pass the data as voltages from one end their instruction sets.
to other. Reduced Instruction Set
3.4 Types of Microprocessors Computers (RISC)

Microprocessors can be classified RISC stands for Reduced

based on the following criteria: Instruction Set Computers. They have a
small set of highly optimized instructions.
• The width of data that can be processed Complex instructions are also
implemented using simple instructions,
• The instruction set thus reducing the size of the instruction
3.4.1 Classification of Microprocessors
based on the Data Width Examples of RISC processors are
Pentium IV, Intel P6, AMD K6 and K7.
Depending on the data width,
microprocessors can process instructions. Complex Instruction Set
The microprocessors can be classified as Computers (CISC)
CISC stands for Complex
• 8-bit microprocessor Instruction Set Computers. They support
hundreds of instructions. Computers
• 16-bit microprocessor supporting CISC can accomplish a wide
variety of tasks, making them ideal for
• 32-bit microprocessor
personal computers.
• 64-bit microprocessor
Examples of CISC processors are
3.4.2 Classification of Microprocessors Intel 386 & 486, Pentium, Pentium II and
based on Instruction Set III, and Motorola 68000.

The size of the instruction set 3.5 Memory Devices

is another important consideration
while categorizing microprocessors. A memory is just like a human
Initially, microprocessors had very brain. It is used to store data and
small instruction sets because complex instructions. Computer memory is the
storage space in the computer, where data


Chapter 3 Page 051-063.indd 55 17-05-2018 12:06:14

and instructions are stored. There are two RAM is a volatile memory, which
types of accessing methods to access (read means that the information stored in it is
or write) the memory. They are sequential not permanent. As soon as the power is
access and random access. In sequential turned off, whatever data that resides in
access, the memory is accessed in an RAM is lost. It allows both read and write
orderly manner from starting to end. But, operations.
in random access, any byte of memory can
3.5.2 Types of RAM
be accessed directly without navigating
through previous bytes. Different There are two basic types of RAM
memory devices are arranged according
• Dynamic RAM (DRAM)
to the capacity, speed and cost as shown
in Figure 3.6. • Static RAM (SRAM)
These two types differ in the
lar ess t

technology they use to hold data. Dynamic

ger im
hig ter

RAM being a common type needs to be


cap e an
nd fas

aci d L

Cache refreshed frequently. Static RAM needs

e a ity,

ty,s ow

Memory to be refreshed less often, which makes

tim pac

low er
ess ca

it faster. Hence, Static RAM is more

er cost

Main Memory
acc aller

expensive than Dynamic RAM.


Hard Disk
3.5.3 Read Only Memory (ROM)
Figure 3.6 Memory Hierarchy
Read Only Memory refers to special
3.5.1 Random-Access Memory (RAM) memory in a computer with pre-recorded
data at manufacturing time which cannot
The main memory is otherwise
be modified. The stored programs that start
called as Random Access Memory. This
the computer and perform diagnostics are
is available in computers in the form of
available in ROMs. ROM stores critical
Integrated Circuits (ICs). It is the place in
programs such as the program that boots
a computer where the Operating System,
the computer. Once the data has been
Application Programs and the data in
written onto a ROM chip, it cannot be
current use are kept temporarily so that
modified or removed and can only be
they can be accessed by the computer’s
read. ROM retains its contents even when
processor. The smallest unit of information
the computer is turned off. So, ROM is
that can be stored in the memory is called
called as a non-volatile memory.
as a bit. The memory can be accessed by
a collection of 8 bits which is called as Read Only Memory
a byte. The bytes are referred by ‘B’. If a (PROM)
computer has 1 megabyte of memory, then
it can store 10,48,576 bytes (or characters) Programmable read only memory
of information. [Hence 1MB is 1024KB is also a non-volatile memory on which
and 1 KB is 1024 Bytes, So 1024X1024 data can be written only once. Once a
=10,48,576 Bytes]

Chapter 3 Page 051-063.indd 56 17-05-2018 12:06:14

program has been written onto a PROM,
it remains there forever. Unlike the main Most of the EPROM chips
memory, PROMs retain their contents have a transparent area at the
even when the computer is turned off. top surface which is covered
by stickers. If it gets removed, the
The PROM differs from ROM. ultraviolet light in the sunlight may
PROM is manufactured as a blank erase the contents.
memory, whereas a ROM is programmed
during the manufacturing process itself. Electrically Erasable Programmable
PROM programmer or a PROM burner is
Read Only Memory (EEPROM)
used to write data to a PROM chip. The
process of programming a PROM is called Electrically Erasable Programmable
burning the PROM. Read Only Memory is a special type of Erasable Programmable Read PROM that can be erased by exposing it
Only Memory (EPROM) to an electrical charge. Like other types of
PROM, EEPROM retains its contents even
Erasable Programmable Read Only when the power is turned off. Comparing
Memory is a special type of memory which with all other types of ROM, EEPROM is
serves as a PROM, but the content can slower in performance.
be erased using ultraviolet rays. EPROM
retains its contents until it is exposed 3.5.4 Cache Memory
to ultraviolet light. The ultraviolet light
clears its contents, making it possible to The cache memory is a very high
reprogram the memory. speed and expensive memory, which is
used to speed up the memory retrieval
An EPROM differs from a PROM,
process. Due to its higher cost, the
PROM can be written only once and
CPU comes with a smaller size of cache
cannot be erased. EPROMs are used
memory compared with the size of the
widely in personal computers because
main memory. Without cache memory,
they enable the manufacturer to change
every time the CPU requests the data, it
the contents of the PROM to replace with
has to be fetched from the main memory
updated versions or erase the contents
which will consume more time. The
before the computer is delivered.
idea of introducing a cache is that, this
extremely fast memory would store data
that is frequently accessed and if possible,
the data that is closer to it. This helps
to achieve the fast response time, Where
response Time, (Access Time) refers to
how quickly the memory can respond to a
Figure 3.7 Erasable Programmable Read read / write request. Figure 3.8 shows the
Only Memory arrangement of cache memory between
the CPU and the main memory.


Chapter 3 Page 051-063.indd 57 17-05-2018 12:06:14

CPU Cache
Fast Slow

Figure 3.8 Cache Memory Arrangement

3.6 Secondary Storage Devices Fig 3.9 Compact Disc

3.6.3 Digital Versatile Disc (DVD)

A computer generally has limited amount
A DVD (Digital Versatile Disc
of main memory which is expensive
or Digital Video Disc) is an optical disc
and volatile. To store data and programs
capable of storing up to 4.7 GB of data,
permanently, secondary storage devices more than six times what a CD can hold.
are used. Secondary storage devices serve DVDs are often used to store movies at a
as a supportive storage to main memory better quality. Like CDs, DVDs are read
and they are non-volatile in nature, with a laser.
secondary storage is also called as Backup The disc can have one or two sides,
storage and one or two layers of data per side; the
number of sides and layers determines
3.6.1 Hard Disks
how much it can hold. A 12 cm diameter
Hard disk is a magnetic disk on disc with single sided, single layer has 4.7
which you can store data. The hard disk GB capacity, whereas the single sided,
has the stacked arrangement of disks double layer has 8.5 GB capacity. The 8 cm
accessed by a pair of heads for each of the DVD has 1.5 GB capacity. The capacity of
a DVD-ROM can be visually determined
disks. The hard disks come with a single
by noting the number of data sides of the
or double sided disk.
disc. Double-layered sides are usually
3.6.2 Compact Disc (CD) gold-coloured, while single-layered sides
are usually silver-coloured, like a CD.
A CD or CD-ROM is made from 1.2
millimeters thick, polycarbonate plastic
material. A thin layer of aluminum or
gold is applied to the surface. CD data is
represented as tiny indentations known as
"pits", encoded in a spiral track moulded
into the top of the polycarbonate layer. The
Fig 3.10 Digital Versatile Disc
areas between pits are known as "lands".
A motor within the CD player rotates the 3.6.4 Flash Memory Devices
disk. The capacity of an ordinary CD- Flash memory is an electronic
ROM is 700MB. (solid-state) non-volatile computer


Chapter 3 Page 051-063.indd 58 17-05-2018 12:06:14

storage medium that can be electrically
erased and reprogrammed. They are
either EEPROM or EPROM. Examples for
Flash memories are pendrives, memory
cards etc. Flash memories can be used
in personal computers, Personal Digital
Assistants (PDA), digital audio players,
digital cameras and mobile phones. Flash
memory offers fast access times. The Fig 3.12 Blu- Ray Disc
time taken to read or write a character
in memory is called access time. The 3.7 Ports and Interfaces
capacity of the flash memories vary from
1 Gigabytes (GB) to 2 Terabytes (TB). A The Motherboard of a computer
sample of flash memory is shown in Figure has many I/O sockets that are connected
3.11. to the ports and interfaces found on the
rear side of a computer (Figure 3.13). The
external devices can be connected to the
ports and interfaces. The various types of
ports are given below:
Figure 3.11 Flash Memory
Serial Port: To connect the external
3.6.5 Blu-Ray Disc devices, found in old computers.
Blu-Ray Disc is a high-density
Parallel Port: To connect the printers,
optical disc similar to DVD. Blu-ray is the
found in old computers.
type of disc used for PlayStation games and
for playing High-Definition (HD) movies. USB Ports: To connect external devices
A double-layer Blu-Ray disc can store up like cameras, scanners, mobile phones,
to 50GB (gigabytes) of data. This is more external hard disks and printers to the
than 5 times the capacity of a DVD, and computer.
above 70 times of a CD. The format was
developed to enable recording, rewriting USB 3.0 is the third major version of the
and playback of high-definition video, as Universal Serial Bus (USB) standard to
well as storing large amount of data. DVD connect computers with other electronic
uses a red laser to read and write data. But, gadgets as shown in Figure 3.13. USB 3.0
Blu-ray uses a blue-violet laser to write. can transfer data up to 5 Giga byte/second.
Hence, it is called as Blu-Ray. USB3.1 and USB 3.2 are also released.


Chapter 3 Page 051-063.indd 59 17-05-2018 12:06:14

USB Port
Mouse Port Network Port

VGA Serial
Port Port Power Supply
Keyboard Port
Figure 3.13 USB 3.0 Ports
Fig 3.14 Ports and Interfaces
VGA Connector: To connect a monitor or
High Definition Multimedia Interface
any display device like LCD projector.
Audio Plugs: To connect sound speakers,
High-Definition Multimedia
microphone and headphones.
Interface is an audio/video interface
PS/2 Port: To connect mouse and which transfers the uncompressed video
keyboard to PC. and audio data from a video controller,
to a compatible computer monitor, LCD
SCSI Port: To connect the hard disk projector, digital television etc.
drives and network connectors.


Figure 3.15 HDMI Ports


Student Activity Teacher Activity

• Identify the components of a computer • Show the components of a computer

• Connecting external devices like • Display different ROM ICs

printer/LCD projector.
• Display the flash memory

• Demonstrate various ports and their



Chapter 3 Page 051-063.indd 60 17-05-2018 12:06:14


Part – I
Choose the correct answer
1. Which of the following is sadi to be the brain of a computer?
(a) Input devices (b) Output devices
(c) Memory device (d) Microprocessor
2. Which of the following is not the part of a microprocessor unit?
(a) ALU (b) Control unit
(c) Cache memory (d) register
3. How many bits constitute a word?
(a) 8 (b) 16
(c) 32 (d) determined by the processor used.
4. Which of the following device identifies the location when address is placed in the
memory address register?
(a) Locator (b) encoder
(c) decoder (d) multiplexer
5. Which of the following is a CISC processor?

(a) Intel P6 (b) AMD K6 (c) Pentium III (d) Pentium IV

6. Which is the fastest memory?

(a) Hard disk (b) Main memory (c) Cache memory (d) Blue-Ray dist

7. How many memory locations are identified by a processor with 8 bits address bus
at a time?

(a) 28 (b) 1024 (c) 256 (d) 8000

8. What is the capacity of 12cm diameter DVD with single sided and single layer?

(a) 4.7 GB (b) 5.5 GB (c) 7.8GB (d) 2.2 GB


Chapter 3 Page 051-063.indd 61 17-05-2018 12:06:14

9. What is the smallest size of data represented in a CD?

(a) blocks (b) sectors (c) pits (d) tracks

10. Display devices are connected to the computer through.

(a) USB port (b) Ps/2 port (c) SCSI port (d) VGA connector

Part – II
(1) What are the parameters which influence the characteristics of a microprocessor?
(2) What is an instruction?
(3) What is a program counter?
(4) What is HDMI?
(5) Which source is used to erase the content of a EPROM?

Part – III
(1) Differentiate Computer Organization from Computer Architecture.
(2) Classify the microprocessor based on the size of the data.
(3) Write down the classifications of microprocessors based on the instruction set.
(4) Differentiate PROM and EPROM.
(5) Write down the interfaces and ports available in a computer.
(6) Differentiate CD and DVD
(7) How will you differentiate a flash memory and an EEPROM?

Part – IV
(1) Explain the characteristics of a microprocessor.
(2) How the read and write operations are performed by a processor? Explain.
(3) Arrange the memory devices in ascending order based on the access time.
(4) Explain the types of ROM.


Chapter 3 Page 051-063.indd 62 17-05-2018 12:06:14

The physical parts or components of a computer, such as
Computer hardware
the CPU, mother board, monitor, keyboard, etc.

Intel Corporation is an American multinational

corporation and technology company involving in
hardware manufacturing, especially mother board and

Silicon chip is an integrated , set of electronic circuits on

Silicon chip
one small flat piece of semiconductor material, silicon.

Multipurpose Multipurposeis several purpose

Address bus is a collection of wires that carry the address

Address bus
as bits

Data bus Data bus is a collection of wires to carry data in bits

Control bus is a control line/collection of wires to control

Control bus
the operations/functions

Arithmetic operations are the mathematical operations on

Arithmetic operations
data like add, subtract etc

Data Transfer means moving data from one component to

Data Transfer

Logical operations are the operations on binary/Boolean

Logical operations
data like AND, OR , NOT

Bidirectional Bidirectional means both the directions/ways

Unidirectional Unidirectional means only one direction

Access time is the time delay or latency between a request

Access time to an electronic system, and the access being completed or
the requested data returned


Chapter 3 Page 051-063.indd 63 17-05-2018 12:06:14

Unit I Fundamentals of Computers CHAPTER
Theoretical concepts of Operating System

Learning objectives 4.2 Introduction to Operating

System (OS):
 To know the concept of Operating
Systems and their types. An Operating System (OS) is
a system software which serves as an
 To acquire the basic Knowledge of interface between a user and a computer.
Operating Systems and its functions.
This controls input, output and
4.1 Introduction to Software other peripheral devices such as disk
drives, printers and electronic gadgets.
A software is set of instructions The functions of an Operating System
that perform specific task. It interacts include file management, memory
basically with the hardware to generate management, process management and
the desired output. device management and many more.
4.1.1 Types of Software

Software is classified into

two types:
1) Application Software Monitor
Hard drive
2) System Software APPS

Application Software: Operating

System Mo
Application software is a set of
programs to perform specific task. For
Printer Keyboard
example MS-word is an application
software to create text document and VLC
player is familiar application software to
play audio, video files and many more.
System Software: Figure: 4.1 Operating System
System software is a type of
Without an Operating System, a
computer program that is designed to run
computer cannot effectively manage all the
the computer’s hardware and application
resources. When a computer is switched
programs. For example Operating System
on, the operating system is loaded in to
and Language Processor

Chapter 4 Page 064-077.indd 64 17-05-2018 11:54:24

the memory automatically. A user cannot request into machine language(Binary
communicate directly with the computer language), processes it and then sends
hardware, unless an operating system is it back to Operating System. Operating
loaded. System converts processed information
into user readable form
Some of the popular Operating
Systems used in personal computers and Uses of Operating Systems
laptops are Windows, UNIX and Linux.
The mobile devices mostly use Android The following are few uses of Operating
and ioS as mobile OS. System

The main use of Operating System is

4.2.1 Need for Operating System
ŽŽ to ensure that a computer can be used
Operating System has become
to extract what the user wants it do.
essential to enable the users to design
applications without the knowledge of the ŽŽ Easy interaction between the users
computer’s internal structure of hardware. and computers.
Operating System manages all the Software
and Hardware. Most of the time there are ŽŽ Starting computer operation
many different computer programmes automatically when power is turned
running at the same time, they all need to on (Booting).
access the Computers, CPU, Memory and
Storage. The need of Operating System is ŽŽ Controlling Input and Output Devices
basically - an interface between the user
ŽŽ Manage the utilization of main
and hardware.

ŽŽ Providing security to user programs.

Software 4.3 Types of Operating System

Operating System are classified

System User into the following types depending on
their processing capabilities.

4.3.1 Single User Operating Systems

An operating system allows only a
Figure: 4.2 Interaction of Operating system single user to perform a task at a time. It
and user is called as a Single user and single Task
operating system. For a user, a task is a
Operating System works as function such as printing a document,
translator, while it translates the user writing a file to disk, editing a file or


Chapter 4 Page 064-077.indd 65 17-05-2018 11:54:24

downloading a file etc. MS-DOS is an 4.4.1 User Interface (UI)
example for a single user and single task
Operating System. User interface is one of the significant
feature in Operating System. The only
4.3.2 Multi-user Operating Systems way that user can make interaction with a
computer. If the computer interface is not
It is used in computers and laptops user-friendly, the user slowly reduces the
that allow same data and applications to computer usage from their normal life.
be accessed by multiple users at the same This is the main reason for the key success
time. The users can also communicate with of GUI (Graphical User Interface) based
each other. Windows, Linux and UNIX Operating System. The GUI is a window
are examples for multi-user Operating based system with a pointing device to
System. direct I/O, choose from menus, make
selections and a keyboard to enter text.Its
Build a cheap computer with vibrant colours attract the user very easily.
raspbion OS and a Raspberry Beginners are impressed by the help and
Pi. raspbion OS is a platform pop up window message boxes. Icons
that's designed to teach how are playing vital role of the particular
to build a computer, what every part application.
of a circuit board does, and finally how
to code apps or games. The platform is Now Linux distribution is also
available in pre-designed kits available as GUI based Operating System.
The following points are considered
when User Interface is designed for an
4.4 Key features of the Operating
1. The user interface should enable the
The various key features are given below
user to retain this expertise for a
longer time.
Interf M
an File 2. The user interface should also satisfy
en the customer based on their needs.

nag ity

Ma ecur

3.The user interface should save user’s

Features of

Operating precious time. Create graphical

System elements like Menus,Window,Tabs,
ess t

oc men

Icons and reduce typing work will be

P ge

an added advantage of the Operating


Faul ce
4. The ultimate aim of any product is
Figure: 4.3 Key Features of the Operating to satisfy the customer. The User
System Interface is also to satisfy the


Chapter 4 Page 064-077.indd 66 17-05-2018 11:54:25

5. The user interface should reduce • Allocation and de-allocation of
number of errors committed by the memory blocks as needed by the
user with a little practice the user program in main memory. (Garbage
should be in a position to avoid errors Collection)
(Error Log File)
4.4.3 Process management
4.4.2 Memory Management
Process management is function
Memory Management is the that includes creating and deleting
process of controlling and coordinating processes and providing mechanisms
for processes to communicate and
computer’s main memory and assigning
synchronize with each other.
memory block (space) to various running
programs to optimize overall computer A process is the unit of work
performance. The Memory management (program) in a computer. A word-
involves the allocation of specific memory processing program being run by an
blocks to individual programs based individual user on a computer is a process.
on user demands. At the application A system task, such as sending output to
level, memory management ensures the a printer or screen, can also be called as a
availability of adequate memory for each Process.
running program at all times.
A computer consists of a collection
The objective of Memory of processes, they are classified as two
Management process is to improve both categories:
the utilization of the CPU and the speed • Operating System processes which is
of the computer’s response to its users executed by system code
via main memory. For these reasons the
computers must keep several programs in • User Processes which is execute by
main memory that associates with many user code
different Memory Management schemes.
All these processes can potentially
The Operating System is responsible execute concurrently on a single CPU.
for the following activities in connection
A process needs certain resources
with memory management:
including CPU time, memory, files and
I/O devices to finish its task.
• Keeping track of which portion of
memory are currently being used and The Operating System is responsible
who is using them. for the following activities associated with
the process management:
• Determining which processes (or
parts of processes) and data to move • Scheduling processes and threads on
in and out of memory. the CPUs


Chapter 4 Page 064-077.indd 67 17-05-2018 11:54:25

• Creating and deleting both user and 1) A = 6 kilo bytes 2) B = 9 kilo bytes
system processes
First the job “A” will be assigned
• Suspending and resuming processes and then job “B” gets its turn.

• Providing mechanisms for process Round RobinScheduling

The Round Robin (RR) scheduling
• Providing mechanisms for process algorithm is designed especially for time
communication sharing systems. Jobs (processes) are
assigned and processor time in a circular
The following algorithms are method. For example take three jobs A, B,
mainly used to allocate the job (process) C. First the job A is assigned to CPU then
to the processor. job B and job C and then again A, B and C
and so on.
1. FIFO 2. SJF 3. Round Robin
Based On Priority
4. Based on Priority
The given job (process) is assigned
FIFO (First In First Out)Scheduling: based on a Priority. The job which has
higher priority is more important than
This algorithm is based on queuing
other jobs. Take two jobs A and B. Let the
technique. Assume that a student is
priority of A be 5 and priority B be 7.
standing in a queue to get grade sheet
from his/her teacher. The other student Job B is assigned to the processor
who stands first in the queue gets his/ before job A.
her grade sheet first and leaves from the
queue. Followed by the next student in the 4.4.4 Security Management
queue gets it collected and so on. This is
the basic logic of the FIFO algorithm. The major challenge in computer
and software industry is to protect
Technically, the process that enters user’s legitimate data from hackers. The
the queue first is executed first by the Operating System provides three levels of
CPU, followed by the next and so on. The securities to the user end. They are
processes are executed in the order of the
queue. (1) File access level

SJF (Shortest Job First)Scheduling: (2) System level

This algorithm works based on the (3) Network level

size of the job being executed by the CPU.
In order to access the files created
Consider two jobs A and B. by other people, you should have the
access permission. Permissions can either

Chapter 4 Page 064-077.indd 68 17-05-2018 11:54:25

be granted by the creator of the file or updates the FAT. The OS also takes care
bythe administrator of the system. of the files that are opened with proper
access rights to read or edit them. There
System level security is offered by are few other file management techniques
the password in a multi-user environment. available like Next Generation File System
(NTFS) and ext2(Linux).
Both windows and Linux offer the
password facility. 4.4.7 Multi-Processing

Network security is an indefinable This is a one of the features of

one. So people from all over the world try Operating System. It has two or more
to provide such a security. processors for a single running process
(job). Processing takes place in parallel
All the above levels of security
is known as parallel processing. Each
features are provided only by the Operating
processor works on different parts of the
same task or on two or more different
4.4.5 Fault Tolerance tasks. Since the execution takes place in
parallel, this feature is used for high speed
The Operating Systems should be execution which increases the power of
robust. When there is a fault, the Operating computing.
System should not crash, instead the
Operating System have fault tolerance 4.4.8 Time-sharing
capabilities and retain the existing state of
This is a one of the features of
Operating Systems. It allows execution of
4.4.6 File Management multiple tasks or processes concurrently.
For each task a fixed time is allocated. This
File management is an important division of time is called Time- sharing.
function of OS which handles the data The processor switches rapidly between
storage techniques. The operating various processes after a time is elapsed or
System manages the files, folders and the process is completed.
directory systems on a computer. Any
type of data in a computer is stored in For example assume that there
the form of files and directories/folders are three processes called P1, P2, P3 and
through File Allocation Table (FAT). The time allocated for each process 30, 40,
FAT stores general information about 50 minutes respectively. If the process
files like filename, type (text or binary), P1 completes within 20 minutes then
size, starting address and access mode processor takes the next process P2 for
(sequential/indexed / indexed-sequential/ the execution. If the process P2 could
direct/relative). The file manager of the not complete within 40 minutes, then the
operating system helps to create, edit, current process P2 will be paused and
copy, allocate memory to the files and also switch over to the next process P3.


Chapter 4 Page 064-077.indd 69 17-05-2018 11:54:25

4.4.9 Distributed Operating Systems 4.5 Prominent Operating Systems

This feature takes care ofthe Prominent OS are as follows:

data and application that are stored and
processed on multiple physical locations • UNIX
across the world over the digital network • Microsoft Windows
(internet/intranet). The Distributed
Operating System is used to access shared • Linux
data and files that reside in any machine • iOS
around the world. The user can handle the
data from different locations. The users • Android
can access as if it is available on their own Modern operating systems use a
computer. Graphical User Interface(GUI). A GUI lets
you use your mouse to click icons, buttons,
The advantages of distributed
menus and everything is clearly displayed
Operating System are as follows:
on the screen using a combination of
• A user at one location can make use of graphics and text elements.
all the resources available at another
OS can be either proprietary with a
location over the network.
commercial license or can be open source.
• Many computer resources can be
added easily in the network Each Operating System's GUI has a
different look and feel, so if you switch to
• Improves the interaction with the
a different Operating System, it may seem
customers and clients.
unfamiliar at first. However, modern
• Reduces the load on the host computer. Operating Systems are designed to be ease
of use and most of the basic principles are
the same.

Linux Free BSD

Mac OS
Red hat
Sun Cobalt

Figure: 4.4 Distributed Operating Systems Figure: 4.5 Various Operating Systems


Chapter 4 Page 064-077.indd 70 17-05-2018 11:54:25

Operating System
 
Open source Free
Proprietary Licence

 
• Microsoft windows • UNIX
• Apple Mac OS • LINUX
• Apple iOS [Mobile • Google's Android
Device] [Mobile Device]

Figure: 4.6 Classification of Operating Systems according to availability

4.5.1 UNIX

UNIX is a family of multitasking, multi-user operating systems that derive originally

from AT&T Bell Labs, where the development began in the 1970s by Ken Thompson and
Dennis Ritchie.

4.5.2 Linux

Linux is a family of open-source operating systems. It can be modified and

distributed by anyone around the world. This is different from proprietary software like
Windows, which can only be modified by the company that owns it. The main advantage
of Linux operating system is that it is open source. There are many versions and their
updates. Most of the servers run on Linux because it is easy to customize.

Figure: 4.7 LINUX Ubuntu Operating System


Chapter 4 Page 064-077.indd 71 17-05-2018 11:54:25

There are a few different
distributions of Linux, like Ubuntu, Unix and the C programming
Mint, Fedora, RedHat, Debian, Google's language were developed by
Android, Chrome OS, and Chromium OS AT&T and distributed to
which are popular among users. government and academic
institutions, which led to both being
The Linux operating system was ported to a wider variety of machine
originated in 1991, as a project of “Linus families than any other operating
Torvalds” from a university student of system.
Finland. He posted information about
his project on a news group for computer
4.5.3 Microsoft Windows
students and programmers. He received
support and assistance from a large pool Microsoft Windows is a family of
of volunteers who succeeded in creating proprietary operating systems designed
a complete and functional Operating by Microsoft Corporation and primarily
System. Linux is similar to the UNIX targeted to Intel and AMD architecture
operating system. based computers.

ubuntu ReactOS is a Windows-

BOSS alternative open source
operating system, which is
being developed on the principles
Linux Redhat of Windows - without using any of
Mint Distributions
Microsoft's code.

Figure: 4.8 Linux Distributions

Figure: 4.9 Microsoft WindowsFolder Screen


Chapter 4 Page 064-077.indd 72 17-05-2018 11:54:26

Figure: 4.10 Microsoft Windows Home Screen

4.5.4 Operating systems for mobile devices

Mobile devices such as phones, tablets and MP3 players are different from desktop
and laptop computers and hence they need special Operating Systems. Examples of mobile
Operating Systems are Apple iOS and Google Android. The iOS running on an iPad is
shown in Figure 4.12.

Figure: 4.11 Various Mobile Devices

Operating systems for mobile devices generally are not as fully featured as those
made for desktop and laptop computers and they are not able to run all software.

Chapter 4 Page 064-077.indd 73 17-05-2018 11:54:26

4.5.5 Android

Android is a mobile operating system developed by Google, based on Linux and

designed primarily for touch screen mobile devices such as smart phones and tablets.
Google has further developed Android TV for televisions, Android Auto for cars and
Android Wear for wrist watches, each with a specialized user interface. Variants of Android
are also used on game consoles, digital cameras, PCs and other electronic gadgets.

Alpha Beta Cupcake Donut Eclair Froyo Gingerbread


Ice Cream
Sandwich Jelly Bean Kitkat Lollipop Marshmallow Nougat

Figure: 4.12 Android Mobile Open Source versions

4.5.6 iOS - iPhone OS

iOS (formerly iPhone OS) is a Messages CalendarPhotos Camera

mobile Operating System created and

developed by Apple Inc., exclusively for its Youtube Stocks Maps Weather
hardware. It is the Operating System that
presently powers many of the company's
Clock Contacts Calculator Voice
mobile devices, including the iPhone,
iPad and iPod Touch. It is the second most
popular mobile Operating System globally iTunes App Store Settings Compass

after Android.

Phone Mail Safari iPod

Figure: 4.13 iOS - iPhone Home Screen


Chapter 4 Page 064-077.indd 74 17-05-2018 11:54:26


Student Activity
Activity 1: Draw a line between the operating system logo and the correct description.

A command-line
Is an Operating System
operating system is an
that is very popular in
example of Open Source
universities, companies,
software development and
bigenterprises etc
Free Operating System

A popular Operating
System for mobile phone
technology which is
not linked with Apple

Used with Apple computers

and works well with cloud

Designed to The most popular GUI

be used for the Operating System for
Apple iPhone personal computers.

Activity 2: Discuss and provide the suitable answers for the questions below.
One of the functions of an Operating System is multi-tasking
1) Explain one reason why multi-tasking is needed in an operating system
2) State two other function of an Operating System
Teacher Activity:
1. Install two different Operating Systems in a single computer.
2. Create a virtual Operating System using virtualization software.


Chapter 4 Page 064-077.indd 75 17-05-2018 11:54:27


Part I

1) Operating system is a

A)Application Software B) Hardware C)System Software D)Component

2) Identify the usage of Operating Systems

A)Easy interaction between the human and computer

B)Controlling input & output Devices

C)Managing use of main memory

D)All the above

3) Which of the following is not a function of an Operating System?

A)Process Management B)Memory Management

C)Security management D)Complier Environment

4) Which of the following OS is a Commercially licensed Operating system?


5) Which of the following Operating systems support Mobile Devices?

A)Windows 7  B)Linux  C)BOSS  D)iOS
6) File Management manages
A)Files  B)Folders  C)Directory systems  D)All the Above
7) Interactive Operating System provides
A)Graphics User Interface (GUI) B)Data Distribution
C)Security Management D)Real Time Processing
8) Android is a
A)Mobile Operating system BOpen Source
C)Developed by Google D)All the above

Chapter 4 Page 064-077.indd 76 17-05-2018 11:54:27

9) Which of the following refers to Android operating system’s version?

Part II
1) What are the advantages of memory management in Operating System?
2) What is the multi-user Operating system?
3) What is a GUI?
4) List out different distributions of Linux operating system.
5) What are the security management features available in Operating System ?
6) What is multi-processing?
7) What are the different Operating Systems used in computer?

Part III
8) What are the advantages and disadvantages of Time-sharing features?
9) Explain and List out examples of mobile operating system.
10) What are the differences between Windows and Linux Operating system?
11) Explain the process manangement algorithms in Operating System.
Part IV
12) Explain the concept of a Distributed Operating System.
13) Explain the main purpose of an operating system.

14) Explain advantages and disadvantages of open source operating systems.


1) Silberschatz, galvin gagne, Operating System concepts – john wiley&sons,inc

2) Andrew s. Tanenbaum, modern Operating Systems – pearson publication

3) Andrew s. Tanenbaum , Operating Systems design and implementation, prentice

hall publication

4) Tom anderson, Operating Systems: principles and practice, recursive books

5) Thomas w. Doeppner, Operating Systems in depth: design and programming, john

wiley & sons, inc


Chapter 4 Page 064-077.indd 77 17-05-2018 11:54:27

Unit I Fundamentals of Computers CHAPTER
Working with typical operating systems
Part - I : Working with Windows

Learning Objectives 5.1. Introduction to Operating System

After learning the concepts in this An Operating System (OS) is

chapter, the students will be able a system software (Figure 5.1) that
enables the hardware to communicate
• To know the concepts of Operating and operate with other software. It also
Sy ste m . acts as an interface between the user and
the hardware and controls the overall
• To know the versions of the windows execution of the computer.
operating system.
User 1 User 2 User n
• To know the concepts like desktop
and the elements of window.

• To explore the document window.

System Application
• To compare the different types of Softwares Softwares
icons. Software

• To explore the windows directory Operating System


• To practice creating files and folders Hardware CPU RAM I/O

in specific drives.

• To manage the files and folders. Figure 5.1. Overview of an Operating

• To know the procedure to start and
shutdown the computer. Following are some of the important
functions of an Operating System as
discussed in the previous chapter:

• Memory Management
• Process Management
• Device Management
• File Management


Chapter 5 Page 078-115.indd 78 17-05-2018 11:53:58

• Security Management Windows Operating System uses
both Keyboard and mouse as input
• Control overall system performance
devices. Mouse is used to interact with
• Error detecting aids
Windows by clicking its icons. Keyboard
• Coordination between other software is used to enter alphabets, numerals and
and users special characters.
The most popular Operating System are
Some of the functions of Windows
as follows:
Operating System are:
• Windows Series - for desktop and • Access applications (programs) on the
laptop computers. computer (word processing, games,
• Android - for smart phones. spread sheets, calculators and so on).
• iOS - for Apple phones, i-Pad and • Load any new program on the
i - Po d . c o m p u t e r.
• Linux - Open source Operating • Manage hardware such as printers,
System for desktop and server. scanners, mouse, digital cameras etc.,
• File management activities (For
5.2. Introduction to Windows Operating
example creating, modifying, saving,
deleting files and folders).
Every computer needs an Operating
System to function. Microsoft Windows is • Change computer settings such as
one of the most popular Graphical User colour scheme, screen savers of your
Interface (GUI). Multiple applications can monitor, etc.
execute simultaneously in Windows, and With reference to the Table 5.1, let us see the
this is known as “Multitasking”. versions of Windows Operating System.

5.3. Various versions of Windows

Versions Logo Year Specific features

• Introduction of GUI in 16 - bit. processor

1985 • Mouse was introduced as an input

• Supports to minimize or maximize

1987 • Control panel feature was introduced
with various system settings and
customising options.
• Introduced the concept of multitasking.
Windows • Supported 256 colours which brought
3.x a more modern, colourful look to the

Chapter 5 Page 078-115.indd 79 17-05-2018 11:53:58

• Introduced Start button, the taskbar,
Windows Windows Explorer and Start menu.
95 • Introduced 32 - bit processor and
focused more on multitasking.

• Integration of the Web browser (Internet

Explorer) with the Operating System.
1998 • DOS gaming began to disappear as
Windows based games improved.
• Plug and play feature was introduced.

• Designed to act as servers in network.

• It introduced automated system

2000 diagnostics and recovery tools.

• Served as an Operating System for

business desktop and laptop systems.
• Four versions of Windows 2000 were
released: Professional (for business
2000 desktop and laptop systems), Server
(both a Web server and an office server),
Advanced Server (for line-of-business
applications) and Data Centre Server
(for high-traffic computer networks).

• Introduced 64-bit Processor.

2001 • Improved Windows appearance with
themes and offered a stable version.

2006 • Updated the look and feel of Windows.


Chapter 5 Page 078-115.indd 80 17-05-2018 11:53:59

• Booting time was improved, introduced
new user interfaces like Aero Peek,
Windows 7 2009 pinning programs to taskbar,
handwriting recognition etc. and
Internet Explorer 8.
• Windows 8 is faster than previous
versions of Windows.
• Start button was removed.
• Windows 8 takes better advantage of
Windows 8 2012 multi-core processing, solid state drives
(SSD), touch screens and other alternate
input methods.
• Served as common platform for mobile
and computer.
• Start Button was added again.
• Multiple desktop.
2015 • Central Notification Center for App
notification and quick actions.
• Cortana voice activated personal assistant.
Table 5.1 Versions of Windows Operating System.

5.4. Handling the mouse The following are the mouse actions:

Before learning Window Operating System, Action Reaction

you should know more about mouse and its
Point to an Move the mouse pointer over
actions. item the item.
Right Click Point to the item on the
Click screen, press and release the
left mouse button.
Point to the item on the
screen, press and release the
Right click right mouse button. Clicking
the right mouse button
displays a pop up menu with
Left Click various options.
Point to the item on the
Double-click screen, quickly press twice
the left mouse button.
Point to an item then hold
the left mouse button as you
Drag and drop move the pointer press and
Figure 5.2.Mouse actions you have reached the desired
position, release the mouse


Chapter 5 Page 078-115.indd 81 17-05-2018 11:54:00

5.5. Windows Desktop 5.5.1. The Icons
The opening screen of Windows is Icon is a graphic symbol
called “Desktop”. representing the window elements like
files, folders, shortcuts etc., Icons play a
The desktop of your computer may vital role in GUI based applications.
look different from what is seen in Figure
5.3. Icons
The icons which are available
This is because Windows allows you
on desktop by default while installing
to change the appearance of the desktop.
Windows OS are called standard icons. The
In Figure 5.3, the desktop shows standard icons available in all Windows
the Start button, Taskbar, Notification OS are My Computer, Documents and
Area and date and time. Recycle Bin.

You can move to the Desktop any time by pressing the Winkey + D or using
Aero Peek while working in any application. You can see Figure 5.4 to know
where Aero peek lies in the Taskbar.



Task bar

Start Button Notification Area

Figure 5.3. Microsoft Windows 7 Desktop

Aero peek button

Figure 5.4. Aero peek button

Chapter 5 Page 078-115.indd 82 17-05-2018 11:54:00 Shortcut Icons:
Shortcut icons can be
created for any application or
file or folder. By double clicking
the icon, the related application
or file or folder will open.
This represents the shortcut to
open a particular application.
(Figure5.5) Folder
Icon Disk drive icons:

The disk drive icons

graphically represent five disk
drive options. (i) Hard disk
(ii) CD-ROM/DVD Drive (iii)
Pen drive (iv) Other removable
storage such as mobile, smart
phone, tablet etc., (v) Network
drives if your system is
connected with other system.
(Figure 5.6)

Figure 5.5.The types of Icons

Hard disk drives with

Various Disk drive
total and remaining
space available

Removable Storage (pen drive)

Figure 5.6.Disk drive Icons

5.6. The Window

Window is a typical rectangular area in an application or a document. It is an area

on the screen that displays information for a specific program.

Chapter 5 Page 078-115.indd 83 17-05-2018 11:54:01

5.7. Application Window A document window is a section of
the screen used to display the contents of
It is an area on a computer screen
a document. Figure 5.9 is an example of a
with defined boundaries, and within which
document window.
information is displayed. Such windows Note
can be resized, maximized, minimized, When you open any
placed side by side, overlap, and so on. application, such as OpenOffice
An Application Window contains Writer, OpenOffice Impress or
an open application i.e. current application OpenOffice Calc etc., you will find
such as Word or Paint. When two or more two Windows on the screen. The larger
windows are open, only one of them is Window is called the Application
active and the rest are inactive. Figures 5.7 Window. This Window helps the user
and 5.8 display the Application Window to communicate with the Application
of OpenOffice Writer and the appearance program. The smaller window, which
of the Multiple Windows opened is inside the Application Window, is
(overlapped) in the Desktop. called the Document window. This
Window is used for typing, editing,
5.8. Document Window drawing, and formatting the text and

Title bar with title of the document

Window Control buttons

Menu bar

Tools bar

w or k a re a
lica t i o n
Scroll bars

Figure 5.7. Application Window


Chapter 5 Page 078-115.indd 84 17-05-2018 11:54:01

Figure 5.8. Multiple Windows opened in Desktop
Application Window
Document window


Document Area

Figure 5.9.Document Window


Chapter 5 Page 078-115.indd 85 17-05-2018 11:54:01

5.9. Elements of a window
Figure 5.10 helps to understand the elements of a window.

5.9.1. Title Bar – The title bar will display the name of the application and the name of the
document opened. It will also contain minimize, maximize and close button.
Title Bar
Corners Borders Corners

Menu Bar

Scroll Bar


Corners Borders Corners

Figure 5.10 The elements of a window.

5.9.2 Menu Bar

The menu bar is seen under the title
bar. Menus in the menu bar can be
accessed by pressing Alt key and the
letter that appears underlined in the
menu title. Additionally, pressing
Alt or F10 brings the focus on the
first menu of the menu bar.
In Windows 7, in the
absence of the menu bar, click
Organize and from the drop
down menu, click the Layout Figure 5.11. To display Menu Bar
option and select the desired Figure 5.11 helps to understand how to make menu
item from that list. bar visible in its absence.


Chapter 5 Page 078-115.indd 86 17-05-2018 11:54:01

5.9.3. The Workspace arrow when positioned over a border or a
corner. Drag the border or corner in the
The workspace is the area in the
direction indicated by the double headed
document window to enter or type the text
arrow to the desired size as shown in
of your document. Figure 5.10 Shows the
Figure 5.10. The window canbe resized
workspace area in the document window.
by dragging the corners diagonally across
5.9.4. Scroll bars - The scroll bars are the screen.
used to scroll the workspace horizontally
5.10. Explore the Computer
or vertically. Figure 5.10 shows the Scroll
bars. 5.10.1. Start Menu
5.9.5. Corners and borders In the lower left-hand corner of the
windows screen is the Start button. When
The corners and borders of the window
you click on the button, the Start menu
helps to drag and resize the windows. The
will appear. Using the start menu, you can
mouse pointer changes to a double headed
start any application.

This symbol
Sub menu is
attached to this
Modify system
View a list of Add / Modify
installed devices and
Programs Printer settings

Get Help
Search Box

Log off / Restart /

Start Shutdown

Figure 5.12 - Start Menu


At the bottom of the screen is a horizontal bar called the taskbar. This bar contains
(from left to right) the Start button, shortcuts to various programs, minimized programs
and in the extreme right corner you can see the system tray which consist of volume


Chapter 5 Page 078-115.indd 87 17-05-2018 11:54:01

control, network, date and time etc. Next to the Start button is the quick Launch Toolbar
which contains task for frequently used applications.
Start Button

Minimized program /
hidden icons

Default Network Adjustment
Language icon Aero peek
Time and button
Figure 5.13.Taskbar

5.10.2. Computer Icon

By clicking this icon, the user can see the disk drivers mounted in the system. In
windows XP, Vista, this icon is called "My computer" in Windows 8 and 10, it is called
"This PC". The functionality of computer icon reamins the same in all versions of windows
as shown in Figure 5.14.
5.10.3. Starting and Closing Applications
Most of the applications installed on your computer are available through the start
menu. Depending on the system setup, the applications in the Start menu varies. To start
an application:

1. Click the Start button and then point to All Programs. The Program menu appears.
(Figure 5.15)

2. Point to the group that contains the application you want to start, and then click the
application name.

Figure 5.14. Computer icon in versions of Windows OS


Chapter 5 Page 078-115.indd 88 17-05-2018 11:54:01

Figure 5. 15.Starting a applicatioin using Start menu
3. You can also open an application by clicking Run on the Start menu, and the name of
the application. (Figure 5.16)

Figure 5.16.Starting a program using Run option

4. To quit a application, click the Close button in the upper right corner of the application
window. (Figure 5.17)


Chapter 5 Page 078-115.indd 89 17-05-2018 11:54:01

Close button

Exit Option

Figure 5.17.Closing the application using Close button and Exit option

5. You can also quit an application by clicking on File → Exit and File → Close option in
Windows 7. (Figure 5.17)

1.  Start the application Wordpad using Start menu and Run option.
 Close the Wordpad application using File menu.

5.11. Managing Files and Folders

In Windows 7, you can organize your documents and programs in the form of files
and folders. You can move, copy, rename, delete and search the files and folders.

5.11.1. Creating files and Folders Creating Folders

You can store your files in many locations – on the hard disk or in other devices. To
better organise your files, you can store them in folders.


Chapter 5 Page 078-115.indd 90 17-05-2018 11:54:01

There are two ways in which you can
create a new folder:

Method I:

Step 1: Open Computer Icon.

Step 2: Open any drive where you want to
create a new folder. (For example
select D:)
Step 3: Click on File → New → Folder.
Step 4: A new folder is created with the
default name “New folder”. (Figure
Step 5: Type in the folder name and press
Enter key. (Figure 5.20 shows the
newly created Folder named “Test
Figure 5.18. Creating a Folder using File
Folder ").

Figure 5.19. New Folder created with the default name

Figure 5.20. Renaming the new Folder


Chapter 5 Page 078-115.indd 91 17-05-2018 11:54:02

Method II: Step 4: The name of the folder will change.

In order to create a folder in the Workshop

desktop: 2. Create a Folder in My Documents
with your name using any one of the
Step 1: In the Desktop, right click → New methods discussed.
→ Folder. (Figure 5.21 Shown the
procedure) Creating Files (Wordpad)
Step 2: A Folder appears with the default
name “New folder” and it will be Wordpad is an in-built word processor
highlighted as shown in the Figure application in Windows OS to create and
5.22. manipulate text documents.

Step 3: Type the name you want and press In order to create files in wordpad
Enter Key. you need to follow the steps given below.

Figure 5.21. Creating a folder in the desktop


Chapter 5 Page 078-115.indd 92 17-05-2018 11:54:02

1. Click Start → All Programs →
Accessories → Wordpad or Run →
type Wordpad, click OK. Wordpad
window will be opened as shown in
Figure 5.23.

2. Type the contents in the workspace

and save the file using File → Save or
Ctrl + S.

3. Save As dialog box will be opened.

4. In the dialog box, select the location

where you want to save the file by
using look in drop down list box.

5. Type the name of the file in the file

name text box.

6. Click save button.

3. Open the Wordpad application and Figure 5.22 New folder icon on the dektop
save it under a folder created with
your name in My Documents.

5.11.2. Finding Files and Folders

You can use the search box on the Start menu to quickly search a particular folder
or file in the computer or in a specific drive.

To find a file or folder:

1. Click the Start button, the search box appears at the bottom of the start menu.

2. Type the name of the file or the folder you want to search. Even if you give the part
of the file or folder name, it will display the list of files or folders starting with the
specified name. (Figure 5.24)

3. The files or the folders with the specified names will appear, if you click that file, it
will directly open that file or the folder.

Chapter 5 Page 078-115.indd 93 17-05-2018 11:54:02

Figure 5.23. Wordpad - Word Processor application

4. There is another option called “See

more results” which appears above
the search box.

5. If you click it, it will lead you to a

Search Results dialog box where you
can click and open that file or the

Searching Files or folders using

Computer icon

1. Click Computer Icon from desktop

or from Start menu.

2. The Computer disk drive screen will

appear and at the top right corner
of that screen, there is a search box
option. (Figure 5.25)

3. Type the name of the file or the folder

you want to search. Even if you give
the part of the file or folder name, it
will display the list of files or folders Figure 5.24. Finding a File/Folder using
starting with the specified name. Start button

Chapter 5 Page 078-115.indd 94 17-05-2018 11:54:02

Figure 5.25. Finding a File/Folder in the Computer icon screen

4. Just click and open that file or the folder.

4. Find the file created in Workshop-3 using the above

5.11.3. Opening existing Files or Folders

The most common way of opening a file or a Folder is to double click on it.

5.11.4. Renaming Files or Folders

There are number of ways to rename files or folders. You can rename using the File menu,
left mouse button or right mouse button.

Method 1

Using the FILE Menu

1. Select the File or Folder you wish to Rename.

2. Click File→ Rename.

3. Type in the new name.

4. To finalise the renaming operation, press Enter as in Figure 5.26.


Chapter 5 Page 078-115.indd 95 17-05-2018 11:54:02

Figure 5.26. Renaming File/Folders using the File menu

Figure 5.27.Folder renamed

Figure 5.27, you can see that the folder is renamed as SCERT-DPI from SCERT.


Chapter 5 Page 078-115.indd 96 17-05-2018 11:54:02

Method 2

Using the Right Mouse Button

1. Select the file or folder you wish to


2. Click the right mouse button over the

file or folder. (Figure 5.28)

3. Select Rename from the pop-up menu. Figure 5.29. New Folder is renamed as C++
4. Type in the new name.
Method 3
5. To finalise the renaming operation,
press Enter. Using the Left Mouse Button

6. Figure 5.29. Shows that the folder "New

Folder" is renamed as C++. 1. Select the file or folder you wish to

2. Press F2 or click over the file or folder.

A surrounding rectangle will appear
around the name.

3. Type in the new name.

4. To finalise the renaming operation,

press Enter.

5. Rename the file created by you using
the File menu, left mouse button or
right mouse button.

5.11.5. Moving/Copying Files and


Figure 5.28. Renaming File/Folders using You can move your files or folders to other
the Right Mouse Button areas using variety of methods.

Chapter 5 Page 078-115.indd 97 17-05-2018 11:54:02

Moving Files and Folders to move files or folders using drag and
drop method.
Method I-CUT and PASTE

To move a file or folder, first select the

file or folder and then choose one of
the following:

• Click on the Edit → Cut or Ctrl + X

Or right click → cut from the pop-up

• To move the file(s) or folder(s) in the

new location, navigate to the new
location and paste it using Click Edit
→ Paste from edit menu or Ctrl + V
using keyboard.

• Or Right click → Paste from the pop-

up menu. The file will be pasted in the
new location. Figure 5.30.Moving the File/Folder using
drag and drop
Method II – Drag and Drop
Copying Files and Folders
In the disk drive window, we have two
panes called left and right panes. In
There are variety of ways to copy files
the left pane, the files or folders are
and folders:
displayed like a tree structure. In the
right pane, the files inside the specific Method I - COPY and PASTE
folders in the left pane are displayed
with various options. To copy a file or folder, first select the
file or folder and then choose one of
• In the right pane of the Disk drive the following:
window, select the file or folder you
want to move. • Click Edit → Copy or Ctrl + C or right
click→ Copy from the pop-up menu.
• Click and drag the selected file or folder
from the right pane, to the folder list • To paste the file(s) or folder(s) in the
on the left pane. new location, navigate to the target
location then do one of the following:
• Release the mouse button when the
target folder is highlighted (active). • Click Edit → Paste or Ctrl + V.

• Your file or folder will now appear in • Or Right click → Paste from the
the new area. Figrue 5.30 shows how pop-up menu.


Chapter 5 Page 078-115.indd 98 17-05-2018 11:54:02

Method II – Drag and Drop

• In the RIGHT pane, select the file or

folder you want to copy.

• Click and drag the selected file and/or

folder to the folder list on the left, and
drop it where you want to copy the file
and/or folder.

• Your file(s) and folder(s) will now

appear in the new area.

If you want to select multiple files
or folders, use Ctrl + Click.

Figure 5.31. Selecting Computer option

5.11.6. Copying Files and Folders to from Start menu
removable disk
• Double-click on the Removable Disk
There are several methods of associated with the USB flash drive.
(Figure 5.32)
transferring files to or from a removable

• Copy and Paste

• Send To

METHOD I - Copy and Paste

• Plug the USB flash drive directly into

an available USB port.

• If the USB flash drive or external drive

folder does NOT open automatically,
follow these steps:
Figure 5.32. Double Clicking Removable
• Click Start→Computer. (Figure 5.31) Disk


Chapter 5 Page 078-115.indd 99 17-05-2018 11:54:03

• Navigate to the folders in your METHOD II - Send To
computer containing files you want to
transfer. • Plug the USB flash drive directly into an

Right-click on the file you want to copy, available USB port.

then select Copy. (Figure 5.33)
• Navigate to the folders in your computer

containing files you want to transfer.

• Right-click on the file you want to

transfer to your removable disk.

• Click Send To and select the Removable

Disk associated with the USB flash drive.

(Figure 5.35)
Figure 5.33. Copying File using right click
• Return to the Removable Disk window, 6.  Move the file created by you in My
right-click within the window, then Documents to Drive D:.
select Paste. (Figure 5.34)
 Copy the file created by you from
drive D: to a removable disk.

5.11.7. Deleting Files and Folders

• When you delete a file or folder, it will

move into the Recycle Bin.

To delete a file or folder:

Figure 5.34. Pasting File using right click Select the file or folder you wish to delete.


Chapter 5 Page 078-115.indd 100 17-05-2018 11:54:03

Removable disk
Figure 5.35. Copying File using Send to option
1. Right- click the file or folder, select Recycle Bin
Delete option from the po-pup menu or
Recycle bin is a special folder to
Click File → Delete or press Delete key
keep the files or folders deleted by the user,
from the keyboard.
which means you still have an opportunity
to recover them. The user cannot access the
2. The file will be deleted and moved to the
files or folders available in the Recycle bin
Recycle bin.
without restoring it. To restore file or folder
from the Recycle Bin
7. Delete the file created by you after • Open Recycle bin.
duplicating the same under My
D o c uments. • Right click on a file or folder to be
restored and select Restore option from
the pop-up menu.
To permanently delete a file or folder • To restore multiple files or folders, select
(i.e. to avoid sending a file or folder to Restore all items.
the Recycle Bin), hold down the SHIFT
key, and press delete on the keyboard. • To delete all files in the Recycle bin, select
Empty the Recycle Bin.

Chapter 5 Page 078-115.indd 101 17-05-2018 11:54:03

5.12. Creating Shortcuts on the Desktop

Shortcuts to your most often used folders and files may be created and placed on the
Desktop to help automate your work.

• Select the file or folder that you wish to have as a shortcut on the Desktop.

• Right click on the file or folder.

• Select Send to from the shortcut menu, then select Desktop (create shortcut) from the sub-

• A shortcut for the file or folder will now appear on your desktop and you can open it from
the desktop in the same way as any other icon. Figure 5.36.

Figure 5.36 Creating Shortcut

5.13. Shutting down or Logging off a Computer

Once you have closed all open applications, you can either log off your computer or shut down
the computer.


Chapter 5 Page 078-115.indd 102 17-05-2018 11:54:03

Log Off

To Log off/Shut down the computer:

Figure 5.37. Log off option

• Click start → log off (click the arrow next to Shut down) or Start → Shutdown . (Figure

• If you have any open programs, then you will be asked to close them or windows will
Force shut down, you will lose any un-saved information if you do this.

• Switch User: Switch to another user account on the computer without closing your open
programs and Windows processes.

• Log Off: Switch to another user account on the computer after closing all your open
programs and Windows processes.

• Lock: Lock the computer while you're away from it.

• Restart: Reboot the computer. (This option is often required as part of installing new
software or Windows update.)

• Sleep: Puts the computer into a low-power mode that retains all running programs and
open Windows in computer memory for a super-quick restart.

• Hibernate (found only on laptop computers): Puts the computer into a low-power mode
after saving all running programs and open Wwindows on the machine's hard drive for
a quick restart.

Chapter 5 Page 078-115.indd 103 17-05-2018 11:54:03

Unit I Fundamentals of Computers CHAPTER
Part - II : Working with Linux (Ubuntu)

Learning Objectives 5.15. Linux

• To compare Windows Operating Linux is one of the popular Open

System with Ubuntu. Source versions of the UNIX Operating
System. It is Open Source as its source
• To differentiate the Window elements code is freely available.
or icons from Ubuntu Launcher.
The most popular Linux server distributors
• To explore how to copy, delete and are:
rename files or folders in Ubuntu.
• Ubuntu Linux
• To explore the differences in Windows
• Linux Mint
7, Windows 8 and Windows 10.
• Arch Linux
• To compare the Windows elements
between Windows 7, Windows 8 and • Deepin
Windows 10.
• Fedora
• To format Files and folders in Windows
7, Windows 8 and Windows 10. • Debian

5.14. Open Source Operating System • CentOS

5.16. Ubuntu
Open Source refers to a program
Ubuntu is a Linux-based operating
or software in which the source code is
system. It is designed for computers,
available in the web to the general public smartphones, and network servers.
free of cost. The system is developed by a UK based
company called Canonical Ltd.
Open Source code is typically
created as a collaborative effort in which Ubuntu was conceived in 2004 by
programmers continuously improve upon Mark Shuttleworth, a successful South
the source code in the web and share the African entrepreneur, and his company
changes within the community. Canonical Ltd.

Chapter 5 Page 078-115.indd 104 17-05-2018 11:54:03

5.16.1. Significant features of • The best feature is, it is a free operating
Ubuntu system and is backed by a huge open
source community.
• The desktop version of Ubuntu supports
all normal software like Windows such 5.17. Ubuntu desktop
as Firefox, Chrome, VLC, etc.
There are many similarities between
• It supports the office suite called Ubuntu and other operating systems, such
LibreOffice. as Microsoft Windows, Apple. This is
because they are all based on the concept
• Ubuntu has in-built email software of a Graphical User Interface (GUI).
called Thunderbird, which gives the
user access to email such as Exchange, The following are the names of the icons
Gmail, Hotmail, etc. in the Ubuntu OS.

• There are free applications for users to • Search your Computer

view and edit photos, to manage and
share videos. • Files

• It is easy to find content on Ubuntu • Firefox Webbrowser

with the smart searching facility.

Menu bar Indicator area / Notification area



Tha Lanucher = Task Bar in Dindows

Figure 5.38.The Ubuntu 16.04 default desktop.


Chapter 5 Page 078-115.indd 105 17-05-2018 11:54:03

• LibreOffice Writer Messaging indicator- This
incorporates your social applications.
• LibreOfficeCalc
From here, you can access instant
• LibreOffice Impress messenger and email clients.

• Ubuntu Software Sound indicator - This provides an

• Amazon easy way to adjust the volume as well as
access your music player.
• System Settings

• Trash Clock - This displays the current

time and provides a link to your calendar
Figure 5.40 explains the icons in
and time and date settings.
the Ubuntu operating system and their
equivalent ones in the Windows operating Session indicator - This is a link
to the system settings, Ubuntu Help,
Menu bar The menu bar is located and session options (like locking your
at the top of the screen. The menu bar computer, user/guest session, logging out
incorporates common functions used of a session, restarting the computer, or
in Ubuntu. The frequently used icons in shutting down completely).
the menu bar are found on the right. The
most common indicators in the Menu bar Title bar - The title bar shows the
are located in the indicator or notification name of the currently selected directory.
area (Figure 5.39) It also contains the Close, Minimize, and
Maximize buttons.

Figure 5.39 Indicators in the Menu bar Toolbar - The toolbar displays
your directory browsing history (using
Network indicator - This manages two arrow buttons), your location in the
network connections, allowing you to
file system, a search button, and options
connect to a wired or wireless network.
for your current directory view.
Text entry settings - This shows
5.18.The desktop background
the current keyboard layout (such as
En, Fr,Ku, and so on) . If more than one
Below the menu bar at the top
keyboard layout is shown, it allows you
of the screen is an image covering the
to select a keyboard layout out of those
choices. The keyboard indicator menu entire desktop. This is the default desktop
contains the following menu items: background, or wallpaper, belonging to
Character Map, Keyboard Layout Chart, the default Ubuntu 16.04 theme known
and Text Entry Settings. as Ambiance. (Figure 5.38)

Chapter 5 Page 078-115.indd 106 17-05-2018 11:54:03

Search your computer = Search option in window

Files = My Computer icon

Firefox Web Browser
LibreOffice writer - MS word
LibreOffice Calc = MS Excel
LibreOffice Impress = MS Powerpoint
Ubuntu Software
Amazon Online shopping app (customize)
System Settings = Control Panel

Trash - Recycle bin

Figure 5.40 Ubuntu Desktop elements

5.19. The Launcher (Equivalent to Task bar)

The vertical bar of icons on the left side of the desktop is called the Launcher.
The Launcher provides easy access to applications, mounted devices, and the Trash. All
current applications on your system will place an icon in the Launcher. (Figure 5.40)

5.20. Elements of Ubuntu

5.20.1.Search your Computer Icon

This icon is equal to search button in Windows OS. Here, you have to give the name
of the File or Folder for searching them. (Figure 5.40)


This icon is equivalent to My Computer icon. From here, you can directly go to
Desktop, Documents and so on. (Figure 5.40)

Chapter 5 Page 078-115.indd 107 17-05-2018 11:54:03

5.20.3.Firefox Web Browser application like MS Word in Windows.
By clicking this icon, you can (Figure 5.41)
directly browse the internet. This is
equivalent to clicking the Web Browser 5.20.5.Libre Office Calc
in Task bar in Windows. (Figure 5.40)
This icon will open LibreOffice
5.20.4.LibreOffice Writer
Calc application. It is similar to MS Excel
This icon will directly take
you to document preparation in Windows. (Figure 5.42)

Figure 5.41 LibreOffice Writer Window

Figure 5.42 LibreOffice Calc Window


Chapter 5 Page 078-115.indd 108 17-05-2018 11:54:03

5.20.6 LibreOffice Impress can be done by clicking the Update option
at the top right corner of that screen.
By clicking this icon, you can open
(Figure 5.40)
LibreOffice Impress to prepare any presentations
in Ubuntu like MS PowerPoint. (Figure5.43)
5.20.8. Online Shopping icon
5.20.7.Ubuntu Software Icon
This icon will let you add any Using this icon user can buy and
additional applications you want. This sell any products online. (Figure 5.40)

Figure 5.43 LibreOffice Impress Window

5.20.9. System Settings Icons

Figure 5.44 System Settings Icons


Chapter 5 Page 078-115.indd 109 17-05-2018 11:54:04

This icon is similar to the Control 5.21 Creating, Deleting Files/Folders
panel in the Windows Operating System.
But here, you need to authenticate the Similar to Windows OS, you can
changes by giving your password. You create, delete the files and folders with
cannot simply change as you do in the same procedure by clicking Files
Windows. (Figure 5.44) icon. Figure 5.46 shows the method of
5.20.10 Trash creating File or Folder by right clicking
This icon is the equivalent of Recycle in the Desktop. A new File or new Folder
bin of windows OS. All the deleted Files and can also be created by using File menu
Folders are moved here. (Figure 5.40) (Figure 5.47)

Figure 5.45 VBox_GAs_5.2.2 Icons

Figure 5.46 Creating a File or Folder by right clicking


Chapter 5 Page 078-115.indd 110 17-05-2018 11:54:04

Figure 5.47 Creating a File or Folder by using File Menu

Deleting a File/Folder

A file / folder created by you can be moved to trash by using right click or by using
menu. (Figure 5.48 & Figure 5.49)

Figure 5.48 Deleting a File or Folder by right clicking

Figure 5.49 Deleting a File or Folder by using Edit menu


Chapter 5 Page 078-115.indd 111 17-05-2018 11:54:04

5.22 Shutting down Ubuntu using Session options

When you have finished working on your computer, you can choose to
Log Out, Suspend or Shut down through the Session Indicator on the far right side
of the top panel.

Figure 5.50 Session Options


Student Activity

1. Create files and folders using Windows and Ubuntu and compare them.

2. Prepare an Assignment on the topic “Popular Linux distributions”.

3. Customise few applications using Ubuntu. Write the procedure.

4. Create a File/Folder in Windows 7, Windows 8 and Windows 10. Prepare a report on

the differences you face while creating the same.

5. Prepare a table on the difference in views of Windows 7, Windows 8 and Windows 10

operating system.


Chapter 5 Page 078-115.indd 112 17-05-2018 11:54:04

Teacher Activity

The teacher can adopt the following methodologies to incorporate inside the classroom.

1. Laboratory method – the teacher can take the entire class to the computer lab and
demonstrate the concept using projector.

2. Demonstration using laptop and projector – The teacher can demonstrate the same
inside the classroom using a laptop and projector.


Choose the Best Answer

From the options given below, choose the operations managed by the operating
a. Memory
b. Processor
c. I/O devices
d. all of the above
2. Which is the default folder for many Windows Applications to save your file?
a. My Document
b. My Pictures
c. Documents and Settings
d. My Computer
3. Under which of the following OS, the option Shift + Delete – permanently deletes a
file or folder?
a. Windows 7
b.Windows 8
d. None of the OS
4. What is the meaning of "Hibernate" in Windows XP/Windows 7?
a. Restart the Computer in safe mode
b. Restart the Computer in hibernate mode
c. Shutdown the Computer terminating all the running applications
d. Shutdown the Computer without closing the running applications
5. Which of the following OS is not based on Linux?
a. Ubuntu b. Redhat c.CentOs d.BSD


Chapter 5 Page 078-115.indd 113 17-05-2018 11:54:04

6. Which of the following in Ubuntu OS is used to view the options for the devices
a. Settings b. Files c. Dash d. VBox_GAs_5.2.2
7. Identify the default email client in Ubuntu.
a. Thunderbird b. Firefox c.Internet Explorer d. Chrome
8. Which is the default application for spreadsheets in Ubuntu? This is available in the
software launcher.
a. LibreOffice Writer b. LibreOffice Calc
c. LibreOffice Impress d. LibreOffice Spreadsheet
9. Which is the default browser for Ubuntu?
a. Firefox b. Internet Explorer
c. Chrome d. Thunderbird
10. Where will you select the option to log out, suspend, restart, or shut down from the
desktop of Ubuntu OS?
a. Session Indicator b. Launcher c. Files d. Search

1. Differentiate cut and copy options.
2. What is the use of a file extension?
3. Differentiate Files and Folders.
4. Differentiate Save and save As option.
5. What is Open Source?
6. What are the advantages of open source?
7. Mention the different server distributions in Linux OS.
8. How will you log off from Ubuntu OS?

1. Analyse: Why the drives are segregated?
2. If you are working on multiple files at a time, sometimes the system may hang.
What is the reason behind it. How can you reduce it?
3. Are drives such as hard drive and floppy drives represented with drive letters? If so
why, if not why?
4. Write the specific use of Cortana.
5. List out the major differences between Windows and Ubuntu OS.
6. Are there any difficulties you face while using Ubuntu? If so, mention it with
7. Differentiate Thunderbird and Firefox in Ubuntu OS.
8. Differentiate Save, Save As and Save a Copy in Ubuntu OS.


Chapter 5 Page 078-115.indd 114 17-05-2018 11:54:04

1. Explain the versions of Windows Operating System.
2. Draw and compare the icon equivalence in Windows and Ubuntu.
3. Complete the following matrix

Navigational method Located on Ideally suited for

Start button Task bar
Desktop Exploring your disk drives and using
system tools
Windows Explorer Seeing hierarchy of all computer contents
and resources in one window.
Quick Launch

4. Observe the figure and mark all the window elements. Identify the version of the
Windows OS.
5. Write the procedure to create, rename, delete and save a file in Ubuntu OS. Compare it
with Windows OS.

System software that enables the harware to communicate

Operating System (OS)
and operate with other software.
Handheld hardware input device that control a cursor
Mouse in a GUI and can move and slect text, icons, files, and
Windows Familer operating system developed by Microsoft corpn.
Desktop Opening screen of windows operating system.
Icon Tiny image represent a command.
Folder Container of files
Linux An operating system.
Ubuntu A flavour of Linux operating System.
Firefox One of the familiar web browser.
LibreOffice Office automation tool available with Ubuntu by default.
Trash A special folder contains deleted files.


Chapter 5 Page 078-115.indd 115 17-05-2018 11:54:04

Unit II Algorithmic Problem
Specification and Abstraction

Learning Objectives be expressed using statements of a

programming language.
After learning the concepts in this
chapter, the students will be able A problem is specified by given in
put data, desired output data and a relation
• To understand the concept of
between the input and the output data. An
algorithmic problem solving.
algorithm starts execution with the input
• To apply the knowledge of algorithmic data, executes the statements, and finishes
technique in problem solving.
execution with the output data. When it
finishes execution, the specified relation
A number of processes performed
between the input data and the output
in our daily life follow the step-by-step
data should be satisfied. Only then has the
execution of a sequence of instructions.
algorithm solved the given problem.
Getting ready to school in the morning,
drawing "kolams", cooking a dish, adding G Polya was a Hungarian
two numbers are examples of processes. Pro- mathematician. He made
cesses are generated by executing algorithms. fundamental contributions to
In this chapter, we will see how algorithms combinatorics, number theory,
are specified and how elements of a process numerical analysis and probability theory.
are abstracted in algorithms. He is also noted for his work in heuristics
6.1 Algorithms and mathematics education, identifying
systematic methods of problem solving
An algorithm is a sequence of to further discovery and invention in
instructions to accomplish a task or solve a mathematics for students and teachers.
problem. An instruction describes an action. In "How to Solve It", he
When the instructions are executed, a process suggests the following
evolves, which accomplishes the intended steps when solving a
task or solves the given problem. We can mathematical problem: 1.
compare an algorithm to a recipe, and the Understand the problem.
resulting process to cooking. 2. Devise a plan. 3. Carry
out the plan. 4. Review
We are interested in executing
your work.
ouralgorithms in a computer. A computer
can only execute instructions in a An algorithm is a step by step
programming language. Instructions of a sequence of statements intended to solve a
computer are also known as statements. problem. When executed with input data, it
Therefore, ultimately, algorithms must generates a computational process, and ends

Chapter 6 Page 116-129.indd 116 17-05-2018 11:53:32

with output data, satisfying the specified can the farmer achieve the task? Initially, we
relation between the input data and the assume that all the four are at the same side of
output data. the river, and finally, all the four must be in the
opposite side. The farmer must be in the boat
Example 6.1. Add two numbers: To add when crossing the river. A solution consists
two numbers, we proceed by adding the of a sequence of instructions indicating who
right most digits of the two numbers, then or what should cross. Therefore, this is an
the next right most digits together with algorithmic problem. Instructions may be
carry that resulted from the previous (right) like
position, and so on. The computational
process for adding 2586 and 9237 is Let the farmer cross with
illustrated in Table 6.1. the wolf.

Step 1 2 3 4 5 or
Carry 1 0 1 1 - Let the farmer cross alone.
Number 1 2 5 8 6 However, some algorithmic problems
Number 2 9 2 3 7 do not require us to construct algorithms.
Sum 1 1 8 2 3 Instead, an algorithm is provided and we are
required to prove some of its properties.
Table 6.1: The process for adding two
numbers Example 6.3. Consider The Chameleons
of Chromeland problem: On the island
6.2 Algorithmic Problems of Chromeland there are three different
types of chameleons: red chameleons,
There are some principles and green chameleons, and blue chameleons.
techniques for constructing algorithms. We Whenever two chameleons of different
usually say that a problem is algorithmic colors meet, they both change color to the
in nature when its solution involves the third color. For which number of red, green
construction of an algorithm. Some types of and blue chameleons is it possible to arrange
problems can be immediately recognized as a series of meetings that results in all the
algorithmic. chameleons displaying the same color? This
is an algorithmic problem, because there is
Example 6.2. Consider the well-known
an algorithm to arrange meetings between
Goat, grass and wolf problem: A farmer
chameleons. Using some properties of
wishes to take a goat, a grass bundle and a
the algorithm, we can find out for which
wolf across a river. However, his boat can take
initial number of chameleons, the goal is
only one of them at a time. So several trips
are necessary across the river. Moreover, the
goat should not be left alone with the grass 6.3 Building Blocks of Algorithms
(otherwise, the goat would eat the grass), and
the wolf should not be left alone with the goat We construct algorithms using basic
(otherwise, the wolf would eat the goat). How building blocks such as


Chapter 6 Page 116-129.indd 117 17-05-2018 11:53:32

• Data represented by a single variable signal
• Variables which can have one of the three values:
green, amber, or red.
• Control flow
6.3.3 Control flow
• Functions

6.3.1 Data An algorithm is a sequence of

statements. However, after executing a
Algorithms take input data, statement, the next statement executed
process the data, and produce output need not be the next statement in the
data. Computers provide instructions to algorithm. The statement to be executed
perform operations on data. For example, next may depend on the state of the
there are instructions for doing arithmetic process. Thus, the order in which the
operations on numbers, such as add, statements are executed may differ from
subtract, multiply and divide. There are the order in which they are written in
different kinds of data such as numbers the algorithm. This order of execution of
and text. statements is known as the control flow.
6.3.2 Variables There are three important control
flow statements to alter the control flow
Variables are named boxes for
depending on the state.
storing data. When we do operations
on data, we need to store the results in • In sequential control flow, a sequence
variables. The data stored in a variable is of statements are executed one after
also known as the value of the variable. We another in the same order as they are
can store a value in a variable or change written.
the value of variable, using an assignment
statement. • In alternative control flow, a condition
of the state is tested, and if the condition
Computational processes in the is true, one statement is executed; if
real-world have state. As a process evolves, the condition is false, an alternative
the state changes. How do we represent the statement is executed.
state of a process and the change of state,
in an algorithm? The state of a process • In iterative control flow, a condition of
can be represented by a set of variables the state is tested, and if the condition
in an algorithm. The state at any point is true, a statement is executed. The
of execution is simply the values of the two steps of testing the condition and
variables at that point. As the values of the executing the statement are repeated
variables are changed, the state changes. until the condition becomes false.

Example 6.4. State: A traffic signal may 6.3.4 Functions

be in one of the three states: green, amber,
or red. The state is changed to allow a Algorithms can become very
smooth flow of traffic. The state may be complex. The variables of an algorithm


Chapter 6 Page 116-129.indd 118 17-05-2018 11:53:32

and dependencies among the variables 2. Abstraction: A problem can involve a
may be too many. Then, it is difficult lot of details. Several of these details are
to build algorithms correctly. In such unnecessary for solving the problem.
situations, we break an algorithm into Only a few details are essential. Ignoring
parts, construct each part separately, and or hiding unnecessary details and
then integrate the parts to the complete modeling an entity only by its essential
algorithm. properties is known as abstraction.
For example, when we represent the
The parts of an algorithm are state of a process, we select only the
known as functions. A function is like variables essential to the problem and
a sub algorithm. It takes an input, and ignore inessential details.
produces an output, satisfying a desired
input output relation. 3. Composition: An algorithm is
composed of assignment and control
Example 6.5. Suppose we want to calculate flow statements. A control flow
the surface area of a cylinder of radius r statement tests a condition of the state
and height h. and, depending on the value of the
condition, decides the next statement
A = 2πr2 + 2πrh to be executed.

We can identify two functions, one 4. Decomposition: We divide the main

for calculating the area of a circle and the algorithm into functions. We construct
other for the circumference of the circle. each function independently of the
If we abstract the two functions as circle_ main algorithm and other functions.
area(r) and circle_circumference(r), then Finally, we construct the main
cylinder_area(r, h) can be solved as algorithm using the functions. When
we use the functions, it is enough to
cylinder_area (r,h) = 2 X circle_area (r) + know the specification of the function.
circle_circumference (r) X h It is not necessary to know how the
function is implemented.
6.4 Algorithm Design Techniques
6.5 Specification
There are a few basic principles and
techniques for designing algorithms. To solve a problem, first we must
state the problem clearly and precisely. A
1. Specification: The first step in problem problem is specified by the given input and
solving is to state the problem precisely. the desired output. To design an algorithm
A problem is specified in terms of the for solving a problem, we should know
input given and the output desired. The the properties of the given input and the
specification must also state the properties properties of the desired output. The goal
of the given input, and the relation of the algorithm is to establish the relation
between the input and the output. between the input and the desired output.

Chapter 6 Page 116-129.indd 119 17-05-2018 11:53:32

Inputs our algorithmic notation, we use double
dashes (—) to start a comment line. (In
Algorithm C++, a double slash // indicates that the rest
of the line is a comment).
Example 6.6. Write the specification of
Figure 6.1: Input-output relation an algorithm to compute the quotient and
remainder after dividing an integer A by
An algorithm is specified by the
another integer B. For example,
properties of the given input and the relation
between the input and the desired output. In divide (22, 5) = 4, 2
simple words, specification of an algorithm
is the desired input-output relation. divide (15, 3) = 5 , 0

The inputs and outputs are passed Let A and B be the input variables.
between an algorithm and the user through We will store the quotient in a variable q and
variables. The values of the variables when the remainder in a variable r. So q and r are
the algorithm starts is known as the initial the output variables.
state, and the values of the variables when
the algorithm finishes is known as the final What are the properties of the inputs
state. A and B?

Let P be the required property of the 1. A should be an integer. Remainder is

inputs and Q the property of the desired meaningful only for integer division, and
outputs. Then the algorithm S is specified as
2. B should not be 0, since division by 0 is
1. algorithm_name (inputs) not allowed.

2. -- inputs : P We will specify the properties of the

inputs as
3. -- outputs: Q
— inputs: A is an integer and B ≠ 0
This specification means that if the algorithm
starts with inputs satisfying P, then it will What is the desired relation between
finish with the outputs satisfying Q. the inputs A and B, and the outputs q and r?

A double dash -- indicates that the 1. The two outputs q (quotient) and r
rest of the line is a comment. Comments (remainder) should satisfy the property
are statements which are used to annotate
a program for the human readers and not A = q X B + r, and
executed by the computer. Comments at
2. The remainder r should be less than the
crucial points of flow are useful, and even
divisor B,
necessary, to understand the algorithm. In


Chapter 6 Page 116-129.indd 120 17-05-2018 11:53:32

0≤r<B Example 6.7. Write the specification of an
algorithm for computing the square root of
Combining these requirements, we a number.
will specify the desired input-output relation
as 1. Let us name the algorithm square_root.

— outputs: A = q X B + r and 0 < r < B. 2. It takes the number as the input. Let
us name the input n. n should not be
The comment that starts with — inputs: negative.
actually is the property of the given inputs.
The comment that starts with — outputs: 3. It produces the square root of n as the
is the desired relation between the inputs output. Let us name the output y. Then n
and the outputs. The specification of the should be the square of y.
algorithm is
Now the specification of the
1. divide (A , B) algorithm is

2. -- inputs: A is an integer and B ≠ 0 square_root(n)

3. -- outputs : A = q X B + r and 0 ≤ r < B -- inputs: n is a real number, n ≥ 0.

Specification format: We can write the -- outputs: y is a real number such that
specification in a standard three part format: y 2= n.

• The name of the algorithm and the 6.5.1 Specification as contract

Specification of an algorithm
• Input: the property of the inputs. serves as a contract between the designer
of the algorithm and the users of the
• Output: the desired input-output algorithm, because it defines the rights and
relation.  responsibilities of the designer and the user.

The first part is the name of the Ensuring that the inputs satisfy the
algorithm and the inputs. The second part required properties is the responsibility
is the property of the inputs. It is written of the user, but the right of the designer.
as a comment which starts with — inputs: The desired input-output relation is the
The third part is the desired input-output responsibility of the designer and the right
relation. It is written as a comment which of the user. Importantly, if the user fails
starts with — outputs:. The input and to satisfy the properties of the inputs, the
output can be written using English and designer is free from his obligation to satisfy
mathematical notation. the desired input-output relation.


Chapter 6 Page 116-129.indd 121 17-05-2018 11:53:32

Property of rider can ignore. Those details are irrelevant
for the purpose of riding a bicycles.
Responsibility Right
A problem can involve a lot of
User Algorithm (designer) details. Several of these details are irrelevant
Right Responsibility for solving the problem. Only a few details
are essential. Abstraction is the process of
Input - output ignoring or hiding irrelevant details and
modeling a problem only by its essential
features. In our everyday life, we use
Figure 6.2: Input property and the input-
abstractions unconsciously to handle
output relation as rights and responsibilities
complexity. Abstraction is the most effective
Example 6.8. Consider the specification of mental tool used for managing complexity.
the algorithm square_root. If we do not abstract a problem adequately,
we may deal with unnecessary details and
square_root(n) complicate the solution.

-- inputs: n is a real number, n ≥ 0. Example 6.9. A map is an abstraction of

the things we find on the ground. We do
-- outputs : y is a real number such that not represent every detail on the ground.
y2 = n. The map-maker picks out the details that
we need to know. Different maps are drawn
The algorithm designer can assume for different purposes and so use different
that the given number is non-negative, and abstractions, i.e., they hide or represent
construct the algorithm. The user can expect different features. A road map is designed
the output to be the square root of the given for drivers. They do not usually worry about
number. hills so most hills are ignored on a road map.
A walker's map is not interested in whether
The output could be the negative a road is a one-way street, so such details are
square root of the given number. The ignored.
specification did not commit that the output
is the positive square root. If the user passes Example 6.10. In medicine, different
a negative number as the input, then the specialists work with different abstractions
output need not be the square root of the of human body. An orthopaedician works
number. with the abstraction of skeletal system, while
a gastroenterologist works with digestive
6.6 Abstraction system. A physiotherapist abstracts the
human body by its muscular system.
To ride a bicycle, it is sufficient to
understand the functioning of the pedal, We use abstraction in a variety of
handlebar, brakes and bell. As a rider, we ways while constructing algorithms — in the
model a bicycle by these four features. A specification of problems, representing state
bicycle has a lot more details, which the

Chapter 6 Page 116-129.indd 122 17-05-2018 11:53:33

by variables, and decomposing an algorithm choosing a piece and breaking it along one
to functions. An algorithm designer has to of its grooves. Thus a cut divides a piece into
be trained to recognize which features are two pieces. How many cuts are needed to
essential to solve the problem, and which break the bar into its individual squares?
details are unnecessary. If we include
unnecessary details, it makes the problem In this example, we will abstract the
and its solution over-complicated. essential variables of the problem. We solve
the problem in Example 8.6.
Specification abstracts a problem by
the properties of the inputs and the desired Essential variables: The number of pieces
input-output relation. We recognize the and the number of cuts are the essential
properties essential for solving the problem, variables of the problem. We will represent
and ignore the unnecessary details. them by two variables, p and c, respectively.
Thus, the state of the process is abstracted by
State: In algorithms, the state of a two variables p and c.
computation is abstracted by a set of
variables. Irrelevant details:

Functions: When an algorithm is very 1. The problem could be cutting a chocolate

complex, we can decompose it into bar into individual pieces or cutting a
functions and abstract each function by its sheet of postage stamps into individual
specification. stamps. It is irrelevant. The problem
is simply cutting a grid of squares into
6.6.1 State individual squares.

State is a basic and important

abstraction. Computational processes have
state. A computational process starts with
an initial state. As actions are performed,
its state changes. It ends with a final state. 2. The sequence of cuts that have been made
State of a process is abstracted by a set of and the shapes and sizes of the resulting
variables in the algorithm. The state at any pieces are irrelevant too. From p and c,
point of execution is simply the values of the we cannot reconstruct the sizes of the
variables at that point. individual pieces. But, that is irrelevant
to solving the problem.
Example 6.11. Chocolate Bars: A
rectangular chocolate bar is divided into Example 6.12. Consider Example 1.2, Goat,
squares by horizontal and vertical grooves. grass and wolf problem. In this example,
We wish to break the bar into individual
we will write a specification of the problem.
We will solve it in Example 2.1. The problem
To start with, we have the whole of involves four individuals, and each is at one
the bar as a single piece. A cut is made by of the two sides of the river. This means that


Chapter 6 Page 116-129.indd 123 17-05-2018 11:53:33

we can represent the state by four variables, value in a variable. It is written with the
and each of them has one of the two values. variable on the left side of the assignment
Let us name the variables farmer, goat, grass operator and a value on the right side.
and wolf, and their possible values L and R.
A value of L means "at the left side". A value variable := value
of R means "at the right side". Since the boat
is always with the farmer, it is important When this assignment is executed,
to not introduce a variable to represent its the value on the right side is stored in the
position. variable on the left side. The assignment

In the initial state, all four variables m := 2

farmer, goat, grass, wolf have the value L.
stores value 2 in variable m.
farmer, goat, grass, wolf = L, L, L, L m
In the final state, all four variables
should have the value R.
If the variable already has a value
farmer, goat, grass, wolf = R, R, R, R stored in it, assignment changes its value to
the value on the right side. The old value of
The specification of the problem is the variable is lost.
The right side of an assignment can
-- inputs: farmer, goat, grass, wolf = L, L, be an expression.
L, L
variable := expression
-- outputs: farmer, goat, grass, wolf = R, R,
R, R In this case, the expression is
evaluated and the value of the expression is
subject to the two constraints that stored in the variable. If the variable occurs
in the expression, the current value of the
1. the goat cannot be left alone with the
variable is used in evaluating the expression,
and then the variable is updated. For
if goat = grass then farmer = goat example, the assignment

2. the goat cannot be left alone with the m := m + 3

evaluates the expression m + 3 using
if goat = wolf then farmer = goat the current value of m.

6.6.2 Assignment statement m+3

Variables are named boxes to store values. =2+3

Assignment statement is used to store a


Chapter 6 Page 116-129.indd 124 17-05-2018 11:53:33

=5 an assignment statement, first evaluate all
the expressions on the right side using the
and stores the value 5 in the variable m. current values of the variables, and then
store them in the corresponding variables
m on the left side.
Example 6.13. What are the values of
The two sides of an assignment
variables m and n after the assignments in
statement are separated by the symbol :=,
known as assignment operator, and read as line (1) and line (3)?
"becomes" or "is assigned". The assignment
statement 1. m, n := 2 , 5

v := e 2. -- m, n = ? , ?

is read as v "becomes" e. Note that assignment 3. m,n:=m+3,n-1

operator is not equality operator1. The
meanings of v := e and v = e are different. 4. -- m, n = ? , ?
Assignment does not state a mathematical
equality of a variable, but changes the value The assignment in line (1) stores 2 in variable
of a variable. The assignment m := m + m, and 5 in variable n.
3 does not state that m is equal to m + 3.
Rather, it changes the value of the variable m
to the value of the expression m + 3.
m n
An assignment statement can 2 5
change the values of multiple variables
simultaneously. In that case, the number The assignment in line (3) evaluates the
of variables on the left side should match expressions m + 3 and n - 1 using the current
the number of expressions on the right values of m and n as
side. For example, if we wish to assign to
three variables v1, v2 and v3, we need 3 m+3,n-1
expressions, say, el, e2, e3.
vl, v2, v3 := el, e2 , e3
= 5,4
The left side is a comma-separated
list of variables. The right side is a comma- and stores the values 5 and 4 in the variables
separated list of expressions. To execute m and n, respectively.

m n
^Unfortunately, several programming languages,
5 4
including C++, use the symbol = as assignment
operator, and therefore, another symbol, == as
1. m, n := 2,5
equality operator.

Chapter 6 Page 116-129.indd 125 17-05-2018 11:53:33

2. -- m, n = 2 , 5 variables p and c. The next step is to model
the process of cutting the chocolate bar.
3. m, n := m + 3, n - 1 When we make a single cut of a piece, the
number of pieces (p) and the number of cuts
4. -- m, n = 2 + 3, 5-1 = 5, 4 (c) both increase by 1. We can model it by an
assignment statement.
Values of the variables after the two
assignments are shown in in line (2) and p, c := p + 1, c+1
which is read as p and c "become" p + 1 and
Example 6.14. In Example 6.11, we c + 1, respectively.
abstracted the state of the process by two

Points to Remember:

• A programming language provides basic • Specification of an algorithm is a contract

statements and a notation for composing between the designer and users of the
compound statements. algorithm.

• An algorithm is a step-by-step sequence • Abstraction is the process of hiding or

of statements to solve a problem. ignoring the details irrelevant to the
task so as to model a problem only by its
• As an algorithm is executed, a process essential features.
evolves which solves the problem.
• Specification abstracts a problem by the
• Algorithmic problem solving involves essential variables of the problem.
construction of algorithms as well as
proving properties of algorithms. • The values of the variables in an
algorithm define the state of the process.
• The specification of an algorithm consists
of the name of the algorithm (together • Assignment statement changes the
with its inputs), the input property, and values of variables, and hence the state.
the desired input-output relation. 


Chapter 6 Page 116-129.indd 126 17-05-2018 11:53:33


Part I Choose the Best Answer

1. Which of the following activities is algorithmic in nature?
(a) Assemble a bicycle. (b) Describe a bicycle.
(c) Label the parts of a bicycle. (d) Explain how a bicycle works.
2. Which of the following activities is not algorithmic in nature?
(a) Multiply two numbers. (b) Draw a kolam.
(c) Walk in the park. (d) Braid the hair.
3. Omitting details inessential to the task and representing only the essential
features of the task is known as
(a) specification (b) abstraction (c) composition (d) decomposition
4. Stating the input property and the as :-output relation a problem is known
(a) specification (b) statement (c) algorithm (d) definition
5. Ensuring the input-output relation is
(a) the responsibility of the algorithm and the right of the user.
(b) the responsibility of the user and the right of the algorithm.
(c) the responsibility of the algorithm but not the right of the user.
(d) the responsibility of both the user and the algorithm.
6. If i = 5 before the assignment i := i-1 after the assignment, the value of i is
(a) 5 (b) 4 (c) 3 (d) 2
7. If 0 < i before the assignment i := i-1 after the assignment, we can conclude that
(a) 0 < i (b) 0 ≤ i (c) i = 0 (d) 0 ≥i

Part II Very Short Answers

1. Define an algorithm.
2. Distinguish between an algorithm and a process.
3. Initially,
farmer, goat, grass, wolf = L, L, L, L


Chapter 6 Page 116-129.indd 127 17-05-2018 11:53:33

and the farmer crosses the river with goat. Model the action with an assignment
4. Specify a function to find the minimum of two numbers.
5. If √2 = 1.414, and the square_root() function returns -1.414, does it violate the
following specification?
-- square_root (x)
-- inputs: x is a real number , x ≥ 0
-- outputs: y is a real number such that y2=x

Part III Short Answers

1. When do you say that a problem is algorithmic in nature?
2. What is the format of the specification of an algorithm?
3. What is abstraction?
4. How is state represented in algorithms?
5. What is the form and meaning of assignment statement?
6. What is the difference between assignment operator and equality operator?

Part IV Explain
1. Write the specification of an algorithm hypotenuse whose inputs are the lengths of the
two shorter sides of a right angled triangle, and the output is the length of the third side.
2. Suppose you want to solve the quadratic equation ax2 + bx + c = 0 by an algorithm.
quadratic_solve (a, b, c)
-- inputs : ?
-- outputs: ?
You intend to use the formula and you are prepared to handle only real number roots.
Write a suitable specification.

— b ± √b2 — 4ac
x= ----------------------


Chapter 6 Page 116-129.indd 128 17-05-2018 11:53:33

3. Exchange the contents: Given two glasses marked A and B. Glass A is full of apple
drink and glass B is full of grape drink. For exchanging the contents of glasses A and B,
represent the state by suitable variables, and write the specification of the algorithm.
1. Roland Backhouse, Algorithmic Problem Solving, John Wiley & Sons Ltd, 2011.
2. Krysia Broda, Susan Eisenbach, Hessam Khoshnevisan, Steve Vickers, Reasoned
Programming, Prentice Hall, 1994 


Chapter 6 Page 116-129.indd 129 17-05-2018 11:53:33

Unit II Algorithmic Problem
Composition and Decomposition

Learning Objectives • Flowchart is a diagrammatic notation

for representing algorithms. They give
After learning the concepts in this a visual intuition of the flow of control,
chapter, the students will be able when the algorithm is executed.
• To know the notations used in algorithmic
techniques. 7.1.1 Programming language

• To understand Composition and A programming language is a notation

Decomposition in algorithmic techniques. for expressing algorithms so that a computer
can execute the algorithm. An algorithm
In Chapter 1, we saw that algorithms expressed in a programming language is called
are composed of statements. Statements can a program. C, C++ and Python are examples
be grouped into compound statements, giving of programming languages. Programming
rise to a hierarchical structure of algorithms. language is formal. Programs must obey the
Decomposition is one of the elementary grammar of the programming language exactly.
problem-solving techniques.An algorithm Even punctuation symbols must be exact.
may be broken into parts, expressing only high They do not allow the informal style of natural
level details. Then, each part may be refined languages such as English or Tamil. There is a
into smaller parts, expressing finer details, or translator which translates the program into
each partmay be abstracted as a function. instructions executable by
the computer. If our program
7.1 Notations for Algorithms has grammatical errors, this
translator will not be able to
We need a notation to represent do the translation.
algorithms. There are mainly three different
notations for representing algorithms. 7.1.2 Pseudo-code
Pseudo code is a mix of programming-
• A programming language is a notation
language-like constructs and plain English.
for expressing algorithms to be executed
This notation is not formal nor exact. It uses
by computers.
the same building blocks as programs, such
• Pseudo code is a notation similar to as variables and control flow. But, it allows
programming languages. Algorithms the use of natural English for statements
expressed in pseudo code are not and conditions. An algorithm expressed
intended to be executed by computers, as pseudo code is not for computers to
but for communication among people. execute directly, but for human readers


Chapter 7 Page 130-146.indd 130 17-05-2018 11:53:00

to understand. Therefore, there is no need 3. Parallelogram boxes represent inputs given
to follow the rules of the grammar of a and outputs produced.
programming language. However, even
pseudo code must be rigorous and correct.
Pseudo code is the most widely used Inputs Outputs
notation to represent algorithms.

7.1.3 Flowcharts 4. Special boxes marked Start and the End are
Flowchart is a diagrammatic notation used to indicate the start and the end of an
for representing algorithms. They show the execution:
control flow of algorithms using diagrams in a
visual manner. In flowcharts, rectangular boxes
represent simple statements, diamond-shaped Start End
boxes represent conditions, and arrows describe
how the control flows during the execution of
the algorithm. A flowchart is a collection of The flowchart of an algorithm to
boxes containing statements and conditions compute the quotient and remainder after
which are connected by arrows showing the dividing an integer A by another integer B is
order in which the boxes are to be executed. shown in Figure 7.1, illustrating the different
boxes such as input, output, condition, and
1. A statement is contained in a rectangular assignment, and the control flow between the
box with a single outgoing arrow,which boxes. The algorithm is explained in Example
points to the box to be executed next. 7.4.


2. A condition is contained in a diamond-
shaped box with two outgoing arrows,
labeled true and false. The true arrow r >B q,r:=q+1,r-B
points to the box to be executed next if
the condition is true, and the false arrow false
points to the box to be executed next if the r,q
condition is false. 

true Figure 7.1: Flowchart for integer division


Flowcharts also have disadvantages.

false (1) Flowcharts are less compact
than representation of algorithms in

Chapter 7 Page 130-146.indd 131 17-05-2018 11:53:00

programming language or pseudo code. of a sequence of statements. The statements
(2) They obscure the basic hierarchical in the sequence are executed one after
structure of the algorithms. (3) Alternative another, in the same order as they are
statements and loops are disciplined written in the algorithm, and the control
control flow structures. Flowcharts do flow is said to be sequential. Let S1 and
not restrict us to disciplined control flow S2 be statements. A sequential statement
structures. composed of S1 and S2 is written as

7.2 Composition S1

A statement is a phrase that
commands the computer to do an action. In order to execute the sequential
We have already seen assignment statement. statement, first do S1 and then do S2.
It is a simple statement, used to change
the values of variables. Statements may The sequential statement given
be composed of other statements, leading above can be represented in a flowchart as
to ahierarchical structure of algorithms. shown in in Figure 7.2. The arrow from
Statements composed of other statements S1 to S2 indicates that S1 is executed, and
are known as compound statements. after that, S2 is executed. 

Control flow statements are S1

compound statements. They are used
to alter the control flow of the process
depending on the state of the process.
There are three important control flow
Figure 7.2: Sequential control flow
• Sequential
Let the input property be P, and the
• Alternative input-output relation be Q, for a problem.
If statement S solves the problem, it is
• Iterative written as

1. -- P
When a control flow statement is
executed, the state of the process is tested, 2. S
and depending on the result, a statement
is selected for execution. 3. -- Q

7.2.1 Sequential statement If we decompose the problem into two

components, we need to compose S as a
A sequential statement is composed


Chapter 7 Page 130-146.indd 132 17-05-2018 11:53:00

sequence of two statements S1 and S2 such to construct a statement S so as to move
that the input-output relation of S1, say R, from the initial state to the final state.
is the input property of S2.
1. -- farmer, goat, grass, wolf = L, L, L,
1. -- P L

2. S1 2. S
3. -- R 3. -- farmer , goat , grass , wolf = R, R,
4. S2 R, R

5. -- Q We have to compose S as a sequence

of assignment statements such that in
Example 7.1. Let us solve the Farmer,
none of the intermediate states
Goat, Grass, and Wolf problem of Example
6.12. We decided to represent the state 1. goat and wolf have the same value but
of the process by four variables farmer, farmer has the opposite value, or
goat, grass, and wolf, representing the
2. goat and grass have the same value but
sides of the farmer, goat, grass and wolf,
farmer has the opposite value.Subject
respectively. In the initial state, all four
to these constraints, a sequence of
variables have the value L (Left side). In
assignments and the state after each
the final state, all four variables should
assignment are shown in Figure 7.3.
have the value R (Right side). The goal is

1. -- farmer, goat, grass, wolf = L, L, L, L

2. farmer, goat := R, R
3. -- farmer , goat , grass , wolf = R, R, L, L
4. farmer := L
5. farmer, goat, grass, wolf = L, R, L, L
6. farmer, grass := R, R
7. -- farmer , goat , grass , wolf = R, R, R, L
8. farmer, goat := L, L
9. -- farmer, goat, grass, wolf = L, L, R, L
10. farmer, wolf := R, R
11. -- farmer , goat , grass , wolf = R, L, R, R
12. farmer : = L
13. -- farmer , goat , grass , wolf = L, L, R, R
14. farmer , goat : = R, R
15. -- farmer , goat , grass , wolf = R, R, R, R

Figure 7.3: Sequence of assignments for goat, grass and wolf problem


Chapter 7 Page 130-146.indd 133 17-05-2018 11:53:00

Other than lines (1) and (15), in
line (7), goat and grass have the same
value, but farmer also has the same value C
as they. In line (9), goat and wolf have the
same value, but farmer also has the same
value as they. Thus, the sequence has
achieved the goal state, without violating S2

the constraints.

7.2.2 Alternative statement Figure 7.4: Alternative control flow

A condition is a phrase that Conditional statement: Sometimes we

describes a test of the state. If C is a need to execute a statement only if a
condition and both condition is true and do nothing if the
condition is false. This is equivalent to the
S1 and S2 are statements, then alternative statement in which the else-
clause is empty. This variant of alternative
if C statement is called a conditional statement.
If C is a condition and S is a statement,
S1 then

else if C

S2 S

is a statement, called an alternative is a statement, called a conditional

statement, that describes the following statement, that describes the following
action: action:

1. Test whether C is true or false. 1. Test whether C is true or false.

2. If C is true, then do S1; otherwise do 2. If C is true then do S; otherwise do

S2. nothing.

In pseudo code, the two alternatives S1 The conditional control flow is depicted
and S2 are indicated by indenting them in the flowchart of Figure 2.5.
from the keywords if and else, respectively.
Alternative control flow is depicted in the
flowchart of Figure 2.4. Condition C has true
two outgoing arrows, labeled true and false.
The true arrow points to the S1 box. The
false arrow points to the S2 box. Arrows out
of S1 and S2 point to the same box, the box Figure 7.5: Conditional control flow
after the alternative statement.

Chapter 7 Page 130-146.indd 134 17-05-2018 11:53:00

Example 7.2. Minimum of two numbers: 2. S1
Given two numbers a and b, we want to
find the minimum of the two using the 3. case C2 
alternative statement. Let us store the
minimum in a variable named result. Let 4. S2
a ↓ b denote the minimum of a and b (for
instance, 4 ↓ 2 = 2, —5 ↓ 6 = -5). Then, 5. case C3
the specification of algorithm minimum is
6. S3
minimum(a, b)
7. else
-- input s : a , b
8. S4
-- outputs: result = a ↓ b

Algorithm minimum can be defined as The conditions C1, C2, and C3 are
evaluated in turn. For the first condition
1. minimum(a, b) that evaluates to true, the corresponding
statement is executed, and the case analysis
2. -- a, b statement ends. If none of the conditions
evaluates to true, then the default case S4
3. if a < b is executed.

4. result : = a 1. The cases are exhaustive: at least one

of the cases is true. If all conditions are
5. else
false, the default case is true.
6. result = b
2. The cases are disjoint: only one of the
7. -- result = a ↓ b cases is true. Though it is possible for
more than one condition to be true,
7.2.3 Case analysis the case analysis always executes only
one case, the first one that is true. If
Alternative statement analyses the the three conditions are disjoint, then
problem into two cases. Case analysis the four cases are (1) C1, (2) C2, (3)
statement generalizes it to multiple cases. C3, (4) (not C1) and (not C2) and (not
Case analysis splits the problem into an C3).
exhaustive set of disjoint cases. For each
case, the problem is solved independently. Example 7.3. We want an algorithm that
If C1, C2, and C3 are conditions, and S1, compares two numbers and produces the
S2, S3 and S4 are statements, a 4-case result as
analysis statement has the form,

1. case C1


Chapter 7 Page 130-146.indd 135 17-05-2018 11:53:00

1- if a < b C and executing S, are repeated until C
compare (a, b) = 0 if a = b becomes false. When C becomes false, the
1 if a > b loop ends, and the control flows to the
statement next to the iterative statement.
We can split the state into an exhaustive The condition C and the statement S
set of 3 disjoint cases: a < b, a = b, and a> are called the loop condition and the
b. Then we can define compare() using a loop body, respectively. Testing the loop
case analysis. condition and executing the loop body
once is called an iteration. not C is known
1. compare(a, b) as the termination condition.

2. case a < b Iterative control flow is depicted in

the flowchart of Figure 7.6. Condition C
3. result := -1 has two outgoing arrows, true and false.
The true arrow points to S box. If C is true,
4. case a = b S box is executed and control flows back
to C box. The false arrow points to the box
5. result := 0
after the iterative statement (dotted box).
6. else -- a > b If C is false, the loop ends and the control
flows to the next box after the loop.
7. result : = 1

7.2.4 Iterative statement

An iterative process executes C S
the same action repeatedly, subject to a
condition C. If C is a condition and S is a
statement, then

while C Figure 7.6: Iterative control flow

Example 7.4. Construct an iterative
is a statement, called an iterative statement, algorithm to compute the quotient and
that describes the following action: remainder after dividing an integer A by
another integer B.
1. Test whether C is true or false.
We formulated the specification of
2. If C is true, then do S and go back to the algorithm in Example 6.6 as
step 1; otherwise do nothing.
divide (A , B)
The iterative statement is commonly
known as a loop. These two steps, testing -- inputs: A is an integer and B ≠ 0


Chapter 7 Page 130-146.indd 136 17-05-2018 11:53:00

-- outputs : q and r such that A = q X B iteration q q+1 r r-B A B
+ r and 0 0 22 22 5
1 1 0+1 17 22-5
-- 0≤r<B
2 2 1 + 1 12 17-5
Now we can construct an iterative 3 3 2+1 7 12-5
algorithm that satisfies the specification. 4 4 3+1 2 7-5
Table 7.1: Step by step execution of divide
divide (A , B)
(22, 5)
-- inputs: A is an integer and B ≠ 0
Example 7.5. In the Chameleons of
-- outputs : q and r such that A = q X B Chromeland problem of Example 1.3,
+ r and suppose two types of chameleons are equal
in number. Construct an algorithm that
-- 0<r<B arranges meetings between these two types
so that they change their color to the third
q := 0, A
type. In the end, all should display the same
while r ≥ B color.

q, r := q + 1, r - B Let us represent the number of

chameleons of each type by variables a, b
The algorithm is presented as a and c, and their initial values by A, B and C,
flowchart in Figure 7.1. respectively. Let a = b be the input property.
The input-output relation is a = b = 0 and
We can execute the algorithm step- c = A+B+C. Let us name the algorithm
by-step for a test input, say, (A, B) = (22, 5). monochromatize. The algorithm can be
Each row of Table 7.1 shows one iteration specified as
— the evaluation of the expressions and
the values of the variables at the end of an monochromatize(a, b, c)
iteration. Note that the evaluation of the
expression uses the values of the variables -- inputs: a=A, b=B, c=C, a=b
from the previous row. Output variables q -- outputs : a = b = 0 , c = A+B+C
and r change their values in each iteration.
Input variables A and B do not change In each iterative step, two chameleons
their values. Iteration 0 shows the values of the two types (equal in number) meet
just before the loop starts. At the end of and change their colors to the third one. For
iteration 4, condition (r ≥ B) = (2 ≥ 5) is example, if A, B, C = 4, 4, 6, then the series
false, and hence the loop ends with (q, r) of meetings will result in
= (4, 2).


Chapter 7 Page 130-146.indd 137 17-05-2018 11:53:00

iteration a b c smaller and more manageable problems,
0 4 4 6 and combining the solutions of the smaller
1 3 3 8 problems to solve the original problem. 
2 2 2 10 Often, problems have structure. We can
3 1 1 12 exploit the structure of the problem and
4 0 0 14 break it into smaller problems. Then, the
smaller problems can be further broken until
Table 7.2: Series of meetings between two they become sufficiently small to be solved
types of chameleons equal in number. by other simpler means. Their solutions
are then combined together to construct a
In each meeting, a and b each decreases by 1, and solution to the original problem.
c increases by 2. The solution can be expressed
as an iterative algorithm. 7.3.1 Refinement

monochromatize(a, b, c) After decomposing a problem into

smaller subproblems, the next step is either
-- inputs: a=A, b=B, c=C, a=b to refine the subproblem or to abstract the
-- outputs: a = b = 0, c = A+B+C
1. Each subproblem can be expanded into
while a > 0 more detailed steps. Each step can be
further expanded to still finer steps, and
a, b, c := a-1, b-1, c+2 so on. This is known as refinement.
The algorithm is depicted in the flowchart of 2. We can also abstract the subproblem.
Figure 7.7. We specify each subproblem by its input
property and the input-output relation.
While solving the main problem, we
a=b, a=A, b=B, c=C
only need to know the specification of
True the subproblems. We do not need to
a>0 a, b, c,: = a-1, b-1, c+2 know how the subproblems are solved.
a= b = 0, c = A + B + C
Example 7.6. Consider a school goer's action
in the morning. The action can be written as

1 Get ready for school

Figure 7.7: Algorithm monochromatize
We can decompose this action into
7.3 Decomposition smaller, more manageable action steps
which she takes in sequence:
Problem decomposition is one of the
elementary problem-solving techniques. 1 Eat breakfast
It involves breaking down a problem into


Chapter 7 Page 130-146.indd 138 17-05-2018 11:53:01

2 Put on clothes 3 Eat eggs

3 Leave home 4 Eat bananas

We have refined one action into a 5

detailed sequence of actions. However, each
of these actions can be expanded into a 6 -- Put on clothes
sequence of actions at a more detailed level,
and this expansion can be repeated. The 7 Put on blue dress
action "Eat breakfast" can be expanded as
8 Put on socks and shoes
1 -- Eat breakfast
9 Wear ID card
2 Eat idlis
3 Eat eggs
11 -- Leave home
4 Eat bananas
12 Take the bicycle out
The action "Put on clothes" can be
13 Ride the bicycle away
expanded as
Refinement is not always a sequence
1 -- Put on clothes
of actions. What the student does may
2 Put on blue dress depend upon the environment. How she
eats breakfast depends upon how hungry
3 Put on socks and shoes she is and what is on the table; what clothes
she puts on depends upon the day of the
4 Wear ID card week. We can refine the behaviour which
depends on environment, using conditional
and "Leave home" expanded as and iterative statements.

1 -- Leave home 1 -- Eat breakfast

2 Take the bicycle out 2 if hungry and idlis on the table

3 Ride the bicycle away 3 Eat idlis

Thus, the entire action of "Get ready for 4 if hungry and eggs on the table
school" has been refined as
5 Eat eggs
1 -- Eat breakfast
6 if hungry and bananas on the table
2 Eat idlis
7 Eat bananas

Chapter 7 Page 130-146.indd 139 17-05-2018 11:53:01

8 18 Take the bicycle out

8 -- Put on clothes 19 Ride the bicycle away

10 if Wednesday The action "Eat idlis" can be further refined

as an iterative action:
11 Put on blue dress
1 -- Eat idlis
12 else
2 Put idlis on the plate
13 Put on white dress
3 Add chutney
14 Put on socks and shoes
4 while idlis in plate
15 Wear the ID card
5 Eat a bite of idli
How "Get ready for school" is refined in
17 -- Leave home successive levels is illustrated in Figure 2.8.

Gross Detailed More detailed

Eat breakfast Eat idlis Put idlis on plate
Add chutney
Eat eggs Eat a bite of idli
Eat bananas Eat a bite of idli
Eat a bite of idli
Put on clothes Put on blue dress

Put on socks and shoes

Wear ID card

Leave home Take the bicycle out

Ride the bicycle away

Figure 7.8: Refinement at various levels of details

The action "Eat breakfast" is depicted in a flowchart shown in Figure 2.9.


Chapter 7 Page 130-146.indd 140 17-05-2018 11:53:01


true Put idlis
idlis on on plate
false chutney

Idli in true Eat a bite

plate? of idli


and Eat eggs
eggs on


and true Eat
banabas bananas
on table



Figure 7.9: Flowchart for Eat breakfast

Note that the flowchart does not show the hierarchical structure of refinement.

7.3.2 Functions

After an algorithmic problem is decomposed into subproblems, we can abstract the

subproblems as functions. A function is like a sub-algorithm. Similar to an algorithm, a
function is specified by the input property, and the desired input-output relation.
Main Function
algorithm (sub-
outputs algorithm)

Figure 7.10: Function definition


Chapter 7 Page 130-146.indd 141 17-05-2018 11:53:01

To use a function in the main square(y)
algorithm, the user need to know only the
specification of the function — the function -- inputs : y
name, the input property, and the input-
output relation. The user must ensure that -- outputs : y2
the inputs passed to the function will satisfy
the specified property and can assume we can use this function three times
that the outputs from the function satisfy to test whether a triangle is right-angled.
the input-output relation. Thus, users of square() is a "black box" — we need not know
the function need only to know what the how the function computes the square. We
function does, and not how it is done by only need to know its specification.
the function. The function can be used a a y
"black box" in solving other problems.

Ultimately, someone implements the Square

function using an algorithm. However, users
of the function need not know about the y2
algorithm used to implement the function.
Figure 7.11: square function
It is hidden from the users. There is no need
for the users to know how the function is
1 right_angled(a, b, c)
implemented in order to use it.
2 -- inputs: c ≥ a, c ≥ b
An algorithm used to implement a
function may maintain its own variables. 3 -- outputs: result = true if c2 = a2 + b2;
These variables are local to the function
4 -- result = false , otherwise
in the sense that they are not visible to the
user of the function. Consequently, the user 5 if square (c) = square (a) + square (b)
has fewer variables to maintain in the main
algorithm, reducing the clutter of the main 6 result := true
7 else
Example 7.7. Consider the problem of
8 result := false
testing whether a triangle is right-angled,
given its three sides a, b, c, where c is the
longest side. The triangle is right-angled, if

c2 = a2 + b2

We can identify a subproblem of

squaring a number. Suppose we have a
function square(), specified as


Chapter 7 Page 130-146.indd 142 17-05-2018 11:53:01

Points to Remember

• Compound statements are • Programming language, pseudo

composed of sequential, code, and flowchart are notations
alternative and iterative control for expressing algorithms.
flow statements.
• Decomposition breaks down a
• The value of a condition is true or problem into smaller subproblems
false, depending on the values of and combine their solutions to
the variables. solve the original problem.

• Alternative statement selects and • A function is an abstraction of

executes exactly one of the two a subproblem, and specified by
statements,depending on the value its input property, and its input-
of the condition. output relation. 

• Conditional statement is executed • Users of function need to know

only if the condition is true. only what the function does, and
Otherwise, nothing is done. not how it is done.

• Iterative statement repeatedly • In refinement, starting at a high

evaluates a condition and executes level, each statement is repeatedly
a statement as long as the condition expanded into more detailed
is true. statements in the subsequent levels.

Part I
1. Suppose u, v = 10 ,5 before the assignment. What are the values of u and
v after the sequence of assignments?
1 u := v
2 v := u
(a) u, v = 5 ,5 (c) u, v = 10 ,5
(b) u, v = 5 ,10 (d) u, v = 10 ,10


Chapter 7 Page 130-146.indd 143 17-05-2018 11:53:01

2. Which of the following properties is true after the assignment (at line 3?
1 -- i+j = 0
2 i, j := i+1, j-1
3 -- ?
(a) i+j >0 (b) i+j < 0 (c) i+j =0 (d) i = j
3. If C1 is false and C2 is true, the compound statement
1 if C1
2  S1
3 else
4 if C2
5  S2
6 else
7  S3
(a) S1 (b) S2 (c) S3 (d) none
4. If C is false just before the loop, the control flows through
1 S1
2 while C
3 S2
4 S3
(a) S1 ; S3 (b) S1 ; S2 ; S3
(c)S1 ; S2 ; S2 ; S3 (d) S1 ; S2 ; S2 ; S2 ; S3
5. If C is true, S1 is executed in both the flowcharts, but S2 is executed in

true true
C S1 C S1

false false

S2 S2

(1) (2)
(a) (1) only (b) (2) only
(c) both (1) and (2) (d) neither (1) nor (2)


Chapter 7 Page 130-146.indd 144 17-05-2018 11:53:01

6. How many times the loop is iterated?
i := 0
while i ≠ 5
i := i + 1
(a) 4 (b) 5 (c) 6 (d) 0

Part II
1. Distinguish between a condition and a statement.
2. Draw a flowchart for conditional statement.
3. Both conditional statement and iterative statement have a condition and a
statement. How do they differ?
4. What is the difference between an algorithm and a program?
5. Why is function an abstraction?
6. How do we refine a statement?

Part III
1. For the given two flowcharts write the pseudo code.
2. If C is false in line 2, trace the control flow in this algorithm.
1 S1
2 -- C is false
3 if C
4 S2
5 else
6 S3
7 S4
3. What is case analysis?
4. Draw a flowchart for -3case analysis using alternative statements.
5. Define a function to double a number in two different ways: (1) n + n, (2) 2 x n

Part IV
1. Exchange the contents: Given two glasses marked A and B. Glass A is full of apple drink


Chapter 7 Page 130-146.indd 145 17-05-2018 11:53:01

and glass B is full of grape drink. Write the specification forexchanging the contents of
glasses A and B, and write a sequence of assignments to satisfy the specification.
2. Circulate the contents: Write the specification and construct an algorithm to circulate the
contents of the variables A, B and C as shown below: The arrows indicate that B gets the
value of A, C gets the value of B and A gets the value of C.


3. Decanting problem. You are given three bottles of capacities 5 ,8, and 3 litres. The 8L bottle
is filled with oil, while the other two are empty. Divide the oil in 8L bottle into two equal
quantities. Represent the state of the process by appropriate variables. What are the initial
and final states of the process? Model the decanting of oil from one bottle to another by
assignment. Write a sequence of assignments to achieve the final state.
4. Trace the step-by-step execution of the algorithm for factorial(4).
-- inputs : n is an integer , n ≥ 0
-- outputs : f = n!
f, i := 1 ,1
while i ≤ n
f, i := f × i, i+1


Chapter 7 Page 130-146.indd 146 17-05-2018 11:53:01

Unit II Algorithmic Problem
Iteration and recursion

Learning Objectives E W Dijkstra was one of the most

influential pioneers of Computing
After learning the
Science. He made fundamental
concepts in this chapter, the
contributions in diverse areas such
students will be able
as programming language design, operating
• To know the concepts of systems, and program design. He coined the
variants and invariants phrase "structured programming" which
used in algorithmic techniques. helped lay the foundations for the discipline
• Apply algorithmic techniques in of software engineering. In 1972, he was
iteration and recursion process. awarded ACM Turing Award, considered
the highest distinction in
There are several problems which can computer science. Dijkstra
be solved by doing the same action repeatedly. is attributed to have said
Both iteration and recursion are algorithm "Computer science is no
design techniques to execute the same action more about computers
repeatedly. What is the use of repeating the than astronomy is about
same action again and again? Even though the telescopes."
action is the same, the state in which the action
is executed is not the same. Each time we but more powerful.Using recursion, we solve
execute the action, the state changes. Therefore, a problem with a given input, by solving the
the same action is repeatedly executed, but same problem with a part of the input, and
in different states. The state changes in such a constructing a solution to the original problem
way that the process progresses to achieve the from the solution to the partial input.
desired input-output relation.
8.1 Invariants
Iteration: In iteration, the loop body is
repeatedly executed as long as the loop condition Example 8.1. Suppose the following
is true. Each time the loop body is executed, assignment is executed with (u, v) =
the variables are updated. However, there is (20,15). We can annotate before and after
also a property of the variables which remains the assignment.
unchanged by the execution of the loop body. -- before: u, v = 20, 15
This unchanging property is called the loop
u, v :=u+5,v-5
invariant. Loop invariant is the key to construct
and to reason about iterative algorithms. -- after: u, v = 25, 10
After assignment (u, v) = (25, 10).
Recursion: Recursion is another algorithm
But what do you observe about the value
design technique, closely related to iteration,

Chapter 8 Page 147-162.indd 147 17-05-2018 11:52:35

of the function u + v? after an assignment, it is an invariant of the
assignment. Let P(u, v) be an expression
before: u + v = 20 + 15 = 35 involving variables u and v. P(u, v)[u, v:= el,
e2] is obtained from P(u, v) by replacing u
after: u + v = 25 + 10 = 35
by el and v by e2 simultaneously. P(u, v) is
The assignment has not changed an invariant of assignment u, v := el, e2 if
the value of u + v. We say that u + v is
P(u,v) [u,v := el, e2] = P(u,v)
an invariant of the assignment. We can
annotate before and after the assignment Example 8.3. Show that p - c is an invariant
with the invariant expression. of the assignment
-- before: u + v = 35 p, c := p + 1, c + 1
u, v : = u + 5, v - 5 Let P(p, c) = p - c. Then
-- after : u + v = 35 P (p, c) [p, c := p + 1, c + l]
We can say, u + v is an invariant: it = p — c [p, c := p + 1, c + l]
is 35 before and after. Or we can say u +
v =35 is an invariant: it is true before and = (p + 1) — (c + 1)
Example 8.2. If we execute the following
assignment with (p, c = 10, 9), after the = P(P , c)
assignment, (u, v) = (11, 10).
Since (p - c)[p, c := p+l, c+l] =    p
-- before : p, c = 10 , 9 - c, p - c is an invariant of the assignment  
p, c := p + 1, c + 1.
p, c := p + 1, c+1
Example 8.4. Consider two variables m
-- after: p, c = 11 , 10 and n under the assignment

Can you discover an invariant? What is m, n := m + 3, n - 1

the value of p - c before and after?
Is the expression m + 3n an invariant?
before: p — c = 10 — 9 = 1
Let P(m, n) = m + 3n. Then
after: p — c = 11 — 10 = 1
P(m, n) [m, n := m + 3, n — l]
We find that p - c = 1 is an invariant.
= m + 3n [m, n := m + 3, n — l]
In general, if an expression of the
variables has the same value before and = (m + 3) + 3(n — l)


Chapter 8 Page 147-162.indd 148 17-05-2018 11:52:35

= m + 3 + 3n — 3 4. at the end of the loop (just after the
= m + 3n
1. -- L, start of loop
= P(m, n)
Since (m + 3n) [ m, n : = m + 3, n-
1] = m + 3n, m + 3n is an invariant of the
assignment m, n := m + 3, n - l. 2. -- L, start of iteration

8.2 Loop invariant B

In a loop, if L is an invariant of the 3. -- L, end of iteration

loop body B, then L is known as a loop
4. -- L, end of loop
while C L 1 start of loop

-- L
L 2 start of iteration
-- L
L 3 end of iteration
The loop invariant is true before L 4 end of loop
the loop body and after the loop body,
each time. Since L is true at the start of
the first iteration, L is true at the start of
Figure 8.1: The points where the loop
the loop also (just before the loop). Since
invariant is true
L is true at the end of the last iteration, L
is true when the loop ends also (just after To construct a loop,
the loop). Thus, if L is a loop variant, then
it is true at four important points in the 1. Establish the loop invariant at the start
algorithm, as annotated in the algorithm of the loop.
and shown in Figure 3.1.
2. The loop body should so update the
1. at the start of the loop (just before the variables as to progress toward the
loop) end, and maintain the loop invariant,
at the same time.
2. at the start of each iteration (before
3. When the loop ends, the termination
loop body)
condition and the loop invariant should
3. at the end of each iteration (after loop establish the input-output relation.


Chapter 8 Page 147-162.indd 149 17-05-2018 11:52:35

8.3 Invariants — Examples i at the end of an iteration, and how they
are calculated. We see that p = ai is true at
the start of the loop, and remains true in
The loop invariant is true in four each row. Therefore, it is a loop invariant.
crucial points in a loop. Using the loop
invariant, we can construct the loop iteration p pxa i i+1 ai
and reason about the properties of the 0 1 0 20
variables at these points.
1 2 1x2 1 0+1 21
Example 8.5. Design an iterative algorithm 2 4 2x2 2 1+1 22
to compute an. Let us name the algorithm 3 8 4x2 3 2+1 23
power(a, n). For example,
4 16 8x2 4 3+1 24
power(10, 4) = 10000 5 32 16x2 5 4+1 25
power (5 , 3) = 125
Table 8.1: Trace of power (2, 5)
power (2 , 5) = 32
When the loop ends, p = a1 is
Algorithm power(a, n) computes a n
still true, but i = 5. Therefore, p = a5. In
by multiplying a cumulatively n times. general, when the loop ends, p = an. Thus,
an = ax ax ... x a we have verified that power(a, n) satisfies
its specification.

n times
Example 8.6. Recall the Chocolate bar
The specification and the loop problem of Example 1.11. How many
invariant are shown as comments. cuts are needed to break the bar into its
individual squares?
power (a, n)
We decided to represent the
-- inputs: n is a positive integer number of pieces and the number of
cuts by variables p and c respectively.
-- outputs: p = an
Whenever a cut is made, the number of
p, i := 1 , 0 cuts increases by one and the number of
pieces also increases by one. We decided
while i ≠ n to model it by an assignment.

-- loop invariant: p = ai p, c := p + 1, c+1

p, i :=p X a, i+1 The process of cutting the bar can

be modeled by a loop. We start with one
The step by step execution of power
piece and zero cuts, p = 1 and c = 0. Let n be
(2, 5) is shown in Table 8.1. Each row
the number of individual squares. When
shows the values of the two variables p and
the number of pieces p equals the number

Chapter 8 Page 147-162.indd 150 17-05-2018 11:52:35

of individual squares n, the process ends. p,c : =1,0
p-c : = k 1 start of loop
p, c : = 1 , 0

while p ≠ n p≠n

p, c := p + 1, c+1 p-c = k 2 start of iteration

p, c: =p + 1, c+ 1
We have observed (in Example 8.2) p-c = k 3 end of iteration
that p - c is an invariant of the assignment p-c = k 4 end of loop
p, c := p + 1, c + 1. Let p - c = k, where k p,c
is a constant. The points in the algorithm
where p - c = k is true are shown in the
Figure 8.2: The points where the loop
algorithm below, and in the flowchart of
invariant is true
Figure 8.2.
When the loop ends (line 4), the
p, c : = 1 , 0
loop invariant is still true (p - c = 1).
Moreover, the loop condition is false (p =
1. -- p - c = k
n). From p - c = 1 and p = n,
while p ≠ n
1. p — c = 1 loop invariant
2. -- p - c = k
2. p = n end of the loop
p, c := p+1, c+1
3. n — c = 1 from 1, 2
3. -- p - c = k
4. c = n — 1 from 3
4. --p-c=k,p=n
When the process ends, the number
The loop invariant p- c = k is True of cuts is one less than the number of
at the start of the loop (line 1). Moreover, squares.
at the start of the loop, p- c = 1. Therefore,
Example 8.7. There are 6 equally spaced
k = 1, and the loop invariant is p - c = 1
trees and 6 sparrows sitting on these
trees,one sparrow on each tree. If a sparrow
flies from one tree to another, then at the
same time, another sparrow flies from its
tree to some other tree the same distance
away, but in the opposite direction. Is it
possible for all the sparrows to gather on
one tree?


Chapter 8 Page 147-162.indd 151 17-05-2018 11:52:35

Let us index the trees from 1 to if a red and a green meet, both become
6. The index of a sparrow is the index of blue). Is it possible to arrange meetings
the tree it is currently sitting on. A pair that result in all chameleons displaying
of sparrows flying can be modeled as an blue color?
iterative step of a loop. When a sparrow at
tree i flies to tree i + d, another sparrow at Let r, g, and b be the numbers of
tree j flies to tree j — d. Thus, after each red, green and blue chameleons. We can
iterative step, the sum S of the indices of model the meetings of two types as an
the sparrows remains invariant. Moreover, iterative process. A meeting changes (r, g,
a loop invariant is true at the start and at b) into (r-1, g-1, b+2) or (r-1, g+2, b-1) or
the end of the loop. (r+2, g-1, b-1). Consider, for example, the
meeting of a red and a green chameleon.
At the start of the loop, the value of
the invariant is r, g, b := r-1, g-1, b+2

S = 1 + 2 + 3 + 4 + 5 + 6 = 21 The difference in the numbers of

any two types either do not change or
When the loop ends, the loop changes by 3. This is an invariant.
invariant has the same value. However,
when the loop ends, if all the sparrows r - 1 - (g - 1) = r - g
were on the same tree, say k, then S = 6k.
r - 1 - (b + 2) = (r - b) - 3
S = 21, loop invariant at the start of
the loop g - 1 - (b + 2) = (g - b) - 3

S = 6k, loop invariant at end of the This is true for all three cases. If any
loop two types differ in number by a multiple
6k= 21, loop invariant has the same of 3 at the start of the iterative process,
value at the start and the end the difference can be reduced in steps of
21 is a multiple of 6 3, to 0, when the iterative process ends.
However, at the start,
It is not possible — 21 is not a multiple
of 6. The desired final values of the r - g = 13 - 15 = -2
sparrow indices is not possible with the
loop invariant. Therefore, all the sparrows g - b = 15 - 17 = -2
cannot gather on one tree.
g - r = 17 - 13 =4
Example 8.8. Consider the Chameleons
of Chromeland of Example 6.3. There are No two colors differ in number
13 red, 15 green, and 17 blue chameleons by a multiple of 3. Therefore, all the
on Chromeland. When two chameleons chameleons cannot be changed to a single
of different colors meet they both change color.
their color to the third one (for example,


Chapter 8 Page 147-162.indd 152 17-05-2018 11:52:35

Example 8.9. Jar of marbles: You are 10    put a black marble back
given a jar full of two kinds of marbles, 11    --b = b'+1, w = w'-2, --b+w = b'+w'-1
white and black, and asked to play this 12 else --BW
game. Randomly select two marbles from 13    throw away the black one
the jar. If they are the same color, throw 14    put the white one back
them out, but put another black marble
15    -- b = b'-1, w = w', b+w = b'+w'-1
in (you may assume that you have an
endless supply of spare marbles). If they For each case, how b, w and b+w
are different colors, place the white one change is shown in the algorithm, where
back into the jar and throw the black one b' and w' are values of the variables before
away. If you knew the original numbers of taking out two marbles. Notice the way
white and black marbles, what is the color w changes. Either it does not change, or
of the last marble in the jar? decreases by 2. This means that the parity
of w, whether it is odd or even, does not
change. The parity of w is invariant.

Suppose, at the start of the game,

WW w is even. When the game ends, w is still
even. Moreover, only one marble is left,
w+b = 1.

1 w+b=1 end of the loop

Figure 8.3: State changes in the jar marbles 2 w = 0orw = 1 from 1
3 w is even loop invariant
The number of white and black marbles in
4 w=0 from 2,3
the jar can be represented by two variables
5 b=1 from 1,4
w and b. In each iterative step, b and w
change depending on the colors of the Last marble must be black. Similarly,
two marbles taken out: Black Black, Black if at the start of the game, there is an odd
White or White White. It is illustrated in number of whites, the last marble must be
Figure 8.3 and annotated in the algorithm white.
One last question: do we ever reach
1 while at least two marbles in jar a state with only one marble? Yes, because
2   -- b , w the total number of marbles b+w always
3   take out any two marbles decreases by one at each step, it will
4   case both are black -- BB eventually become 1.
5    throw away both the marbles
6    put a black marble back 8.4 Recursion
7    -- b = b '-1, w = w', b+w = b'+w' -1
8   case both are white --WW Recursion is an algorithm design
9    throw away both the marbles technique, closely related to induction. It


Chapter 8 Page 147-162.indd 153 17-05-2018 11:52:35

is similar to iteration, but more powerful. Solver length breaks the sequence
Using recursion, we can solve a problem [A,B,C,D,E] into its first customer and the
with a given input, by solving the instances rest of the sequence.
of the problem with a part of the input.
first [A ,B,C,D,E] = A
Example 8.10. Customers are waiting in a
line at a counter. The man at the counter rest [A ,B,C,D,E] = [B ,C,D,E]
wants to know how many customers are
waiting in the line. To solve a problem recursively,
solver length passes the reduced sequence
Length? Length? Length? Length? Length? [B,C,D,E] as input to a sub-solver, which
is another instance of length. The solver
1+4 1+3 1+2 1+1 1 assumes that the sub-solver outputs the
length of [B,C,D,E], adds 1, and outputs it
Figure 8.4: Length of a line as the length of [A,B,C,D,E].

Instead of counting the length length [A,B,C,D,E] = 1 + length

himself, he asks customer A for the length [B,C,D,E]
of the line with him at the head, customer
A asks customer B for the length of the line Each solver
with customer B at the head, and so on.
1. receives an input,
When the query reaches the last customer
in the line, E, since there is no one behind
2. passes an input of reduced size to a
him, he replies 1 to D who asked him. D
replies 1+1 = 2 to C, C replies 1+2 = 3 to B,
B replies 1+3 = 4 to A, and A replies 1+4= 3. receives the solution to the reduced
5 to the man in the counter input from the sub-solver, and produces
the solution for the given input
8.4.1 Recursive process
as illustrated in Figure 8.5.
Example 8.10 illustrates a recursive
process. Let us represent the sequence of Inputs solution for the input
5 customers A, B, C, D and E as 1 4
2 3
The problem is to calculate the reduced input solution for the reduced
length of the sequence [A,B,C,D,E]. Let input
us name our solver length. If we pass a Figure 8.5: One instance of a solver in a
sequence as input, the solver length should recursive process
output the length of the sequence.
Figure 8.6 shows the input received and
length [A,B,C,D,E] = 5 the solution produced by each


Chapter 8 Page 147-162.indd 154 17-05-2018 11:52:35

solver for Example 8.10. Each solver reduces the size of the input by one and passes it on
to a sub-solver, resulting in 5 solvers. This continues until the input received by a solver
is small enough to output the solution directly. The last solver received [E] as the input.
Since [E] is small enough, the solver outputs the length of [E] as 1 immediately, and the
recursion stops.

[ A, B, C, D, E] 1+4
[ B, C, D, E] 1+3
[C, D, E] 1+2
[D, E] 1+1
[E] 1

Figure 8.6: Recursive process with solvers and sub-solvers

The recursive process for length [A,B,C,D,E] is shown in Figure 8.7.

1 length [A,B,C,D,E]
2 = 1 + 1 length [B,C,D,E]
3 = 1 +1 + length [C,D,E]
4 = 1 + 1+ 1 + length [D,E]
5 = 1 + 1+ 1 + 1 + length [E]
6 = 1 + 1 + 1 + 1 +1
7 = 1 +1 +1 + 2
8 = 1+1+3
9 = 1+4
10 = 5
Figure 8.7: Recursive process for computing the length of a sequence

8.4.2 Recursive problem solving

Each solver should test the size of the input. If the size is small enough, the solver
should output the solution to the problem directly. If the size is not small enough, the
solver should reduce the size of the input and call a sub-solver to solve the problem with
the reduced input. For Example 8.10, solver's algorithm can be expressed as

1 if sequence has only one customer
length of sequesce =
1 + length of tail, otherwise


Chapter 8 Page 147-162.indd 155 17-05-2018 11:52:35

To solve a problem recursively, construct solution
the solver reduces the problem to sub-
problems, and calls another instance of else
the solver, known as sub-solver, to solve find sub_problems of reduced
the sub-problem. The input size to a sub- input
problem is smaller than the input size to
the original problem. When the solver solutions to sub_problems =
calls a sub-solver, it is known as recursive solver for each sub_problem
call. The magic of recursion allows the
solver to assume that the sub-solver construct solution to the 2 × 16
(recursive call) outputs the solution to the problem from
sub-problem. Then, from the solution to
the sub-problem, the solver constructs the solutions to the sub_
solution to the given problem. problems

As the sub-solvers go on reducing Whenever we solve a problem using

the problem into sub-problems of smaller recursion, we have to ensure these two
sizes, eventually the sub-problem becomes cases: In the recursion step, the size of
small enough to be solved directly, without the input to the recursive call is strictly
recursion. Therefore, a recursive solver smaller than the size of the given input,
has two cases: and there is at least one base case.

1. Base case: The problem size is small 8.4.3 Recursion — Examples

enough to be solved directly. Output
the solution. There must be at least one Example 8.11. The recursive algorithm
base case. for length of a sequence can be written as

2. Recursion step: The problem size is length (s)

not small enough. Deconstruct the
problem into a sub-problem, strictly -- inputs : s
smaller in size than the given problem.
Call a sub-solver to solve the sub- -- outputs : length of s
problem. Assume that the sub-solver
if s has one customer -- base case
outputs the solution to the sub-
problem. Construct the solution to the 1
given problem.
This outline of recursive problem solving
technique is shown below. 1 + length(tail(s)) -- recursion step
solver (input)
Example 8.12. Design a recursive
if input is small enough algorithm to compute an. We constructed
an iterative algorithm to compute an in


Chapter 8 Page 147-162.indd 156 17-05-2018 11:52:35

Example 8.5. an can be defined recursively The recursive process resulting
as from power(2, 5) is shown in Figure 8.9.

an =
a × a n - 1 {if n = 0
The recursive definition can
power (2,5)
= 2 × power (2,4)
= 2 × 2 × power(2,3)
= 2 × 2 × 2 × power(2, 2)
= 2 × 2 × 2 × 2 × power (2,1)
be expressed as a recursive solver for = 2 × 2 × 2 × 2 × 2 × power (2,0)
computing power(a, n). =2 ×2 ×2 × 2×2×1
=2 ×2 ×2 × 2×2
power (a, n) =2 ×2 ×2 × 4
2 × 16 =2 ×2 ×8
-- inputs: n is an integer , n ≥ 0 = 2 × 16
= 32

-- outputs : an
Figure 8.9: Recursive process for power(2, 5)
if n = 0 -- base case Example 8.13. A corner-covered board is a
board of 2n × 2n squares in which the square
at one corner is covered with a single square
else --recursion step tile. A triominoe is a L-shaped tile formed
with three adjacent squares (see Figure
a × power (a, n-1) 8.10). Cover the corner-covered board with
the L-shaped triominoes without overlap.
The recursive process with solvers Triominoes can be rotated as needed.
for calculating power(2, 5) is shown in
Figure 8.8. 
2, 5 2 × 16
n=5 Power
2, 4 2×8
n=4 Power
2, 3 2×4
n=3 Power
2, 2 2×2
n=2 Power
2, 1 2×1
n=1 Power
2, 0 1
n=0 Power

Figure 8.8: Recursive process with solvers

for calculating power(2, 5)

Figure 8.10: Corner-covered board and triominoe


Chapter 8 Page 147-162.indd 157 17-05-2018 11:52:35

The size of the problem is n (board
of size 2n × 2n). We can solve the problem by
recursion. The base case is n = 1. It is a 2 × 2
corner-covered board. We can cover it with
one triominoe and solve the problem. In the
recursion step, divide the corner-covered
board of size 2n × 2n into 4 sub-boards, each
of size 2n-1 × 2n-1, by drawing horizontal and
vertical lines through the centre of the board.
Place atriominoe at the center of the entire
board so as to not cover the corner-covered
sub-board, as shown in the left-most board
of Figure 8.11. Now, we have four corner-
covered boards, each of size 2n-1 × 2n-1.

We have 4 sub-problems whose size

is strictly smaller than the size of the given
problem. We can solve each of the sub-
problems recursively.

tile corner_covered board of size n

if n = 1 -- base case

cover the 3 squares with one


else -- recursion step

divide board into 4 sub_boards of

size n-1

place a triominoe at centre of board ,

leaving out the corner_covered sub


tile each sub_board of size n-1

The resulting recursive process for

covering a 23 x 23 corner-covered board is
illustrated in Figure 8.11.
Figure 8.11: Recursive process of covering a
corner-covered board of size 2 x 23

Chapter 8 Page 147-162.indd 158 17-05-2018 11:52:35

Points to Remember

• Iteration repeats the two steps of • (d) at the end of the loop (just after the
evaluating a condition and executing loop)
a statement, as long as the condition is
true. • When a loop ends, the loop invariant
is true. In addition, the termination
• An expression involving variables, condition is also true.
which remains unchanged by an
assignment to one of these variables, is • Recursion must have at least one base
called an invariant of the assignment. case.

• An invariant for the loop body is known • Recursion step breaks the problem into
as a loop invariant. sub-problems of smaller size, assumes
solutions for sub-problems are given by
• A loop invariant is true at recursive calls, and constructs solution
to the given problem.
• (a) at the start of the loop (just before
the loop) • In recursion, the size of input to a sub-
problem must be strictly smaller the
• (b) at the start of each iteration (before
size of the given input.
loop body)

• (c) at the end of each iteration (after

loop body)

Part I
1. A loop invariant need not be true
(a) at the start of the loop. (b) at the start of each iteration
(c) at the end of each iteration (d) at the start of the algorithm
2. We wish to cover a chessboard with dominoes, the number of black squares and
the number of white squares covered by dominoes, respectively, placing a domino can
be modeled by
(a) b := b + 2 (b) w := w + 2 (c) b, w := b+1, w+1 (d) b := w


Chapter 8 Page 147-162.indd 159 17-05-2018 11:52:35

3. If m x a + n x b is an invariant for the assignment a, b : = a + 8, b + 7, the values of m
and n are
(a) m = 8, n = 7 (b) m = 7, n = -8 (c) m = 7, n = 8 (d) m = 8, n = -7
4. Which of the following is not an invariant of the assignment?
m, n := m+2, n+3
(a) m mod 2 (b) n mod 3 (c) 3 X m - 2 X n (d) 2 X m - 3 X n
5. If Fibonacci number is defined recursively as

F (n)=
{ 0

F(n — 1) + F(n — 2) otherwise

to evaluate F(4), how many times F() is applied?

(a) 3 (b) 4 (c) 8 (d) 9
6. Using this recursive definition

a n=
{ 1
a x an -1
if n = 0

how many multiplications are needed to calculate a10?

(a) 11 (b) 10 (c) 9 d) 8

Part II
1. What is an invariant?
2. Define a loop invariant.
3. Does testing the loop condition affect the loop invariant? Why?
4. What is the relationship between loop invariant, loop condition and the input-
output recursively
5. What is recursive problem solving?
6. Define factorial of a natural number recursively.


Chapter 8 Page 147-162.indd 160 17-05-2018 11:52:35

Part III
1. There are 7 tumblers on a table, all standing upside down. You are allowed to turn any
2 tumblers simultaneously in one move. Is it possible to reach a situation when all the
tumblers are right side up? (Hint: The parity of the number of upside down tumblers is
2. A knockout tournament is a series of games. Two players compete in each game; the
loser is knocked out (i.e. does not play any more), the winner carries on. The winner
of the tournament is the player that is left after all other players have been knocked out.
Suppose there are 1234 players in a tournament. How many games are played before the
tournament winner is decided?
3. King Vikramaditya has two magic swords. With one, he can cut off 19 heads of a dragon,
but after that the dragon grows 13 heads. With the other sword, he can cut off 7 heads, but
22 new heads grow. If all heads are cut off, the dragon dies. If the dragon has originally
1000 heads, can it ever die? (Hint:The number of heads mod 3 is invariant.)

Part IV
1. Assume an 8 × 8 chessboard with the usual coloring. "Recoloring" operation changes the
color of all squares of a row or a column. You can recolor re-peatedly. The goal is to attain
just one black square. Show that you cannot achieve the goal. (Hint: If a row or column has
b black squares, it changes by (|8 - b) - b|).
2. Power can also be defined recursively as

a =

{ 1
a × an -1
a n/2 × a n/2
if n = 0
if n is odd
if n is even

Construct a recursive algorithm using this definition. How many multiplications are
needed to calculate a10?
3. A single-square-covered board is a board of 2n x 2n squares in which one square is covered
with a single square tile. Show that it is possible to cover the this board with triominoes
without overlap.


Chapter 8 Page 147-162.indd 161 17-05-2018 11:52:35

List of Authors and Reviewers

Domain Experts Reviewers

Dr. Chitra Babu Dr. Ranjani Parthasarathi 
Professor and Head of the Department, Dept of Computer Science and Professor, Dept of Info Sci and Tech, College of Engineering, Guindy,
Engineering, SSN College of Engineering , Chennai Anna University, Chennai

Mrs. Bagyalakshmi P Mr. Munivel E

Asst. Professor and Head of the Department, Dept of Computer Scientist/Engineer ‘C’ IT Group (Information Security), NIELIT
Applications, Queen Mary’s College, Chennai Calicut (MeitY, Govt. of India), NIT Campus, Calicut - KL (IN).

Mrs. Sasikala k Authors

Associate Professor, Dept of Computer Science, Queen Mary’s College,
Chennai Mr. Kannan K
Post Graduate Teacher, Chennai Girls Hr Sec School,
Dr. Radha P Rotler street , Chennai
Assistant Professor, Dept of Information Technology,
Govt. Arts & Science College (A), Coimbatore Mr. Ramakrishnan V G
Post Graduate Teacher, Karnataka Sangha Hr Sec School,
Dr. Nester Jeyakumar M T Nagar, Chennai
Associate Professor and Head Of the Department,
Dept of Computer Science, Loyola College, Chennai Mrs. Bindhu Mohandas
Post Graduate Teacher, Vijayanta Model Hr Sec School,
Dr. Srinivasan N H.V.F Estate , Avadi, Chennai
Professor, Dept of Computer Science and Engineering,
Sathyabama Institute of Science & Technology, Chennai Mr. Gowrisankar N.V
Post Graduate Teacher, Chennai Girls Hr Sec School,
Dr. Chandra Mohan B Nungambakkam, Chennai
Associate Professor, School of Computer Science and Engineering,
Vellore Institute of Technology, Vellore Mr. Sreenivasan R
Post Graduate Teacher, Santhome Hr Sec School, Mylapore, Chennai
Mr. Sethuraman R
Assistant Professor, Dept of Computer Science and Engineering, Mr. Lenin K
Sathyabama Institute of Science & Technology, Chennai Post Graduate Teacher, Chennai Girls Hr Sec School, Saidapet, Chennai

Mr. Sankar K Miss. Sangeetha A

Assistant Professor, Dept of Computer Science, Post Graduate Teacher, Govt. Hr Sec School, Rajanthangal,
RKM Vivekananda College, Mylapore, Chennai Thiruvannamalai Dt

Dr. Valarmathi K E
Post Graduate Teacher, Velammal Vidhyashram, Surapet, Chennai

Experts Co-ordinator Mrs. Gajalakshmi R

Post Graduate Teacher, Jaigopal Garodia Hindu Vidyalaya Hr Sec School,
Mr. Ravikumar Arumugam West Mambalam, Chennai
Deputy Director,
SCERT, Chennai
Academic Coordinators
Mrs. Nevedha Selvaraj
Assistant Professor, SCERT, Chennai

Mrs. Tamil Selvi R

B.T. Assistant,

Art and Design Team

Government High School, Poonampalayam, Trichy District

Chief Co-ordinator and Creative Head

Srinivasan Natarajan

THY designers and computers This book has been printed on 80 G.S.M.
Chennai Elegant Maplitho paper.
In-House Printed by offset at:
QC - Gopu Rasuvel
- Rajesh Thangapan
- Raghupathy, TamilKumaran. C
- Wrapper Design - Kathir Arumugam

Ramesh Munisamy


Chapter 8 Page 147-162.indd 162 17-05-2018 11:52:36