0% found this document useful (0 votes)
217 views1,277 pages

Propositional Logic and Truth Tables

Uploaded by

Nemesis Punisher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
217 views1,277 pages

Propositional Logic and Truth Tables

Uploaded by

Nemesis Punisher
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CONTENT TABLE

Unit 1 Discrete Structures and Optimization

Unit 2 Computer System Architecture

Programming Languages and Computer


Unit 3
Graphics Unit

Unit 4 Database Management Systems

Unit 5 System Software and Operating System


Propositional Logic
The rules of logic give precise meaning to mathematical statements. These rules are used to
distinguish between valid and invalid mathematical arguments.
Propositions
A proposition is a declarative sentence that is either true or false, but not both.
• Propositional logic the area of logic that deals with propositions.
• Propositional variables that represent propositions: p, q, r, s.
• Truth values T, F

DEFINITION 1
Let p be a proposition. The negation of p, denoted by ¬p (also denoted by p) is thestatement. “It is
not the case that p.”
The Proposition ¬ p is read “not p.” The truth value of the negation of p, ¬p, is the opposite of the
truth value of p.
The Truth Table for the Negation of a Proposition

p ¬p
T F
F T

Example: Find the negation of the proposition “Today is Friday.”


Solution: The negation is “It is not the case that today is Friday.” In simple English, “Today is not
Friday.” Or “It is not Friday today.”

Let p and q be propositions. The conjunction of p and q, denoted by p 𝖠 q, is the proposition “p


and q.”
The conjunction p 𝖠 q is true when both p and q are true and is false otherwise.

The Truth Table for the Disjunction of Two Propositions

p q p∨q

TTF FFT TTT


F T F

1
The truth table for the
Conjunction ofPropositions two
p q p𝖠q
T F T
T F F
F T F
F T F

DEFINITION 3
Let p and q be propositions. The
disjunction of p and q, denoted by p ∨ q, is
the proposition “p or q.” The disjunction p ∨ q is false when both p and q are false and is true
otherwise.

The common binary connectives are:


Conjunction p and q
p𝖠q Disjunction p or q
p∨ qp→qp↔q Implication if p then q
p⊕q Bi-conditional p if and only if q
Exclusive or p x-or q
p↓q not or p nor q
p | q or p ↑ q not and p n-and q

In the conditional p → q, p is the antecedent and q is the consequent. Theconditional p → q


is often read informally as “p implies q”.

Converse, Contra-positive and Inverse


• The proposition q → p is called the converse of p →q. The contra-positive of p → q is the
proposition ¬q → ¬p. The proposition ¬p → ¬q is called the inverse of p → q.
• We will see that of these three conditional statements formed from p → q, only the contra-
positive always has the same truth value as p → q.

EXAMPLE: What are the contra-positive, the converse, and the inverse of the conditional-
statement? “The home team wins whenever it is raining?”
Solution:
“If it is raining, then the home team wins.”
The contra-positive of this conditional statement is
“If the home team does not win, then it is not raining.”
The converse is - “If the home team wins, then it is raining.”
The inverse is - “If it is not raining, then the home team does not win.”

Bi-conditionals

DEFINITION 4
Let p and q be propositions. The bi-conditional statement p ↔ q is the proposition “p if and only if
q.” The bi-conditional statement p ↔ q is true when p and q have the same truth values, and is

2
false otherwise. Bi-conditional statements are also called bi-implications.

Truth Table for the Bi-conditional p ↔ q


p q p↔q
T T T
T F F
F T F
F F T

The Truth Table for the Bi-conditional p ↔ q


The statement p ↔ q is true when both the conditional statements are p → q and q → p are true
and is false otherwise.
Example: Let p be the statement “You can take the flight,” and let q be the statement “You buy a
ticket.” Then p ↔ q is the statement
Answer “You can take the flight if and only if you buy a ticket.”

Precedence of Logical Operator


Operator precedence is an ordering of logical operators designed to allow the dropping of
parenthesis in logical expression.

Precedence of Logical Operators


Operator Precedence
¬ 1
𝖠 2
∨ 3
→ 4
↔ 5

Logic and Bit Operations


• A bit is a symbol with two possible values, 0 (zero) and 1 (one).
• A bit can be used to represent a truth value, because there are two truth values, true and
false.
• A variable is called a Boolean variable if its value is either true or false.

Truth
Bit
Value
1
T
F
0

Bit Operators OR, AND, and XOR

x y x∨y x𝖠y x⊕y

0 0 0 0 0

3
0 1 1 0 1

1 0 1 0 1
1 1 1 1 0

DEFINITION5-A bit string is a sequence of zeroor more bits. The length of this string is the number
of bits in thestring.

EXAMPLE Find the bitwise OR, bitwise AND, and bitwise XOR of the bit strings 011011 0110 and 11
0001 1101.
Solution: The bitwise OR, bitwise AND, and bitwise XOR are:
01 1011 0110
11 0001 1101
11 1011 1111 Bitwise OR
01 0001 0100 Bitwise AND
10 1010 1011 Bitwise XOR

Propositional Equivalences Tautologies and contradictions


A compound proposition that is always true, regardless of the truth values of the
individual propositions involved, is called a tautology.
Example: 𝑝 ∨ ¬𝑝 is a tautology.

A compound proposition that is always false, regardless of the truth values of the individual
propositions involved, is called a contradiction.
Example: 𝑝 𝖠 ¬𝑝 is a contradiction.

A compound statement that is neither a tautology nor a contradiction is called acontingency.

Logical Equivalences
• Compound propositions that have the same truth values in all possible cases are called
logically equivalent.
• The compound propositions p and q are called logically equivalent if p ↔ q is a tautology.
The notation p ≡ q denotes that p and q are logically equivalent.

Examples of Tautology & Contradiction.

p ¬p p ∨ ¬p p 𝖠 ¬p
T F T F

F T T F
Logicalequivalence

4
De Morgan’s Laws.

¬(p 𝖠 q) ≡ ¬p ∨ ¬q

¬(p ∨ q) ≡ ¬p 𝖠 ¬q
• The two algebraic expressions equal if they have the same value for each possible value of the
input variables.
• For example, for all real numbers 𝑥, the left side and the right side have thesame value.
𝑥 2 − 1 = (𝑥 + 1) (𝑥 − 1)
• The two compound statements 𝑝 and 𝑞 “equal” if they always share the same truth value. 𝑝 ≡ 𝑞
means that 𝑝 ↔ 𝑞 is a tautology.
• In these equivalences, T denotes the compound proposition that is always true and F denotes
the compound proposition that is always false.

Logical Equivalences
Equivalence Name
p𝖠T≡p
Identity laws
p∨F≡p
p∨T≡T
Domination laws
p𝖠F≡F
p∨p≡p
Idempotent laws
p𝖠p≡p
¬(¬p) ≡ p Double negation law
p∨q≡q∨p
Commutative laws
p𝖠q≡q𝖠p
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r)(p 𝖠 q)
Associative laws
𝖠 r ≡ p 𝖠 (q 𝖠 r)
p ∨ (q 𝖠 r) ≡ (p ∨ q) 𝖠 (p
∨ r)
Distributive laws
p 𝖠 (q ∨ r) ≡ (p 𝖠 q) ∨ (p
𝖠 r)
¬(p 𝖠 q) ≡ ¬p ∨ ¬q
De Morgan’s laws
¬(p ∨ q) ≡ ¬p 𝖠 ¬q
p ∨ (p 𝖠 q) ≡ p
Absorption laws
p 𝖠 (p ∨ q) ≡ p
p ∨ ¬p ≡ T
Negation laws
p 𝖠 ¬p ≡ F

Logical Equivalences Involving Bi-conditional Statements.

5
p ↔ q ≡ (p → q) 𝖠 (q → p)p ↔ q ≡ ¬p ↔ ¬q
p ↔ q ≡ (p 𝖠 q) ∨ (¬p 𝖠 ¬q)
¬(p ↔ q) ≡ p ↔ ¬q

Logical Equivalences involvingConditional Statements.


p → q ≡ ¬p ∨ q

p → q ≡ ¬q → ¬pp ∨ q ≡ ¬p → q
p 𝖠 q ≡ ¬(p → ¬q)

¬(p → q) ≡ p 𝖠 ¬q

(p → q) 𝖠 (p → r) ≡ p → (q 𝖠 r)(p → r) 𝖠 (q → r) ≡ (p ∨ q) → r(p → q) ∨ (p → r) ≡ p → (q ∨ r)
(p → r) ∨ (q → r) ≡ (p 𝖠 q) →r

Using De Morgan’s Laws


The two logical equivalences known as De Morgan’s laws are particularly important. In particular,
the equivalence ¬ (p ∨ q) ≡ ¬p 𝖠 ¬q tells us that the negation of a disjunction is formed by taking
the conjunction of the negations of the component propositions.
Example Show that ¬ (p ∨ (¬p 𝖠 q)) and ¬p 𝖠 ¬q are logically equivalent by developing a series of
logical equivalences.
Sol ¬ (p ∨ (¬p 𝖠 q)) ≡ ¬p 𝖠 ¬ (¬p 𝖠 q) 2nd De Morgan law
≡ ¬p 𝖠 [¬ (¬p) ∨ ¬q] 1st De Morgan law
≡ ¬p 𝖠 (p ∨ ¬q) double negation law
≡ (¬p 𝖠 p) ∨ (¬p 𝖠 ¬q) 2nd distributive law
≡ F ∨ (¬p 𝖠 ¬q) because ¬p 𝖠 p ≡ F
≡ (¬p 𝖠 ¬q) ∨ F commutative law for disjunction
≡ ¬p 𝖠 ¬q identity law for F

Normal Form
• Suppose, A (P1, P2, ... , P n) is a statements formula where P1, P2, ..., P6 are the atomic
variables if we consider all possible assignments of the truth value to P1, P2, ..., P n and
obtain the resulting truth values of the formula A then we get the truth table for A, such a
truth table contains 2^6 rows.
• The formula may have the truth value T for all possible assignments of the truth values to
the variables P1, P2... P n. In this case, A is called identically true or tautology.
• If A has the truth value T for at least one combination of truth values assigned to P1, P2... P
n then A is called Satisfiable.

Product in place of Conjunction

Sum in place of Disjunction

Disjunctive Normal form Conjunctive Normal form


Types of Normal form
6
Disjunctive Normal form
A product of the variable and their negations in a formula is called an elementary product.
Similarly, a sum of the variables and their negations is called as an elementary sum.

Some statements hold for elementary sums and product:


1. For any elementary product, the necessary condition is false is when it contains at least one
pair of a factor in which one is the negation of the other.
2. For any elementary sum, the necessary condition is true when it contains at least one pair of
factors in which one is the negations of the other.

1) Conjunctive Normal Form


The conjunctive normal form of a given formula is the one which contains the product of
elementary sums (that formula is equivalent in the given formula).
2) Principle Disjunctive normal form
Suppose, P and Q is two variables. We construct all possible formulas which consist of a
conjunction of P or in negation and conjunction of Q or its negation. Now of the formulas
should contain both a variable and its negation. For two variables P and Q there is 2^2 such
formula.

These formulas are called min-terms or Boolean conjunction of P and Q from the truth tables of
theses min-terms, it is clear that no two min-terms are equivalent. Each min-term has the truth
value T for exactly one combination of the truth value of the variables P and Q.
For a given formula an equivalent formula consisting of a disjunction of min- terms only is
known as its principle disjunction normal form. Such a normal form is also said to be the sum-
product canonical form.

3) Principle conjunctive normal form


Given a number of variables max-term of these variables is a formula which consists of disjunction
in which each variable or its negations but not both appear only once.
Observe that the max-term are the duals of min-terms. Therefore each of the max-term has the
truth value F for exactly one combination of the truth values of the variables.
The principle of conjunctive normal form or the product-sum canonical form, the equivalent
formula consists of only the conjunction of the max-terms only.

Predicates and QuantifiersPredicates


A predicate is an expression of one or more variables defined on some specific
domain. A predicate with variables can be made a proposition by either assigning a value to the
variable or by quantifying the variable.

For Example: Let P (x) denote the statement “x > 3.” What are the truth values ofP (4) and P (2)?

Solution: We obtain the statement P (4) by setting x = 4 in the statement “x > 3.” Hence, P (4),
which is the statement “4 > 3,” is true. However, P (2), which is the statement “2 > 3,”is false.

The following are some examples of predicates −


• Let E(x, y) denote "x = y"
• Let X(a, b, c) denote "a + b + c = 0"
• Let M(x, y) denote "x is married to y"
7
Well Formed Formula
Well Formed Formula is a predicate holding any of the following −
• All propositional constants and propositional variables are WFF.
• If x is a variable and Y is a WFF, ∀X y and ∃x Y are also WFF. Truth value andfalse values are
WFF.

Quantifiers
The variable of predicates is quantified by quantifiers.

There are two types of quantifier in predicate logic − Universal Quantifier and Existential
Quantifier.

Denoted by Quantifiers Denoted by


symbol ∀ symbol ∃

Universal Quantifier Existential Quantifier

Universal Quantifier
Universal quantifier states that the statements within its scope are true for every value of the
specific variable. It is denoted by the symbol ∀.
∀x P(x) is read as for every value of x, P(x) is true.

Statement When True? When False?

P (x) is true for every x


∀x P(x) There is an x for which P (x) isfalse.
There is an x for which P (x)is
∃x P(x) P (x) is false for every x.
true.

Example Let P (x) be the statement “x + 1 > x.” What is the truth value of thequantification ∀ x
P (x), where the domain consists of all real numbers?
Solution: Because P (x) is true for all real numbers x, the quantification ∀ x P (x) isTrue.

Existential Quantifier
Existential quantifier states that the statements within its scope are true for some values of
the specific variable. It is denoted by the symbol ∃.
∃x P(x) is read as for some values of x, P(x) is true.

Example
Let P (x) be the statement “x > 3” .What is the truth value of the quantification ∃x P (x), where the
domain consists of all real numbers?
Solution: x > 3 is true, when x = 4—the existential quantification of P (x), which is
∃x P (x), is true.

Precedence of Quantifiers
The quantifier’s ∀ and ∃ have higher precedence than all logical operators from propositional
8
calculus.
For example, ∀x P (x) ∨ Q(x) is the disjunction of ∀x P (x) and Q(x). In other words, it means (∀x P
(x)) ∨ Q(x) rather than ∀x (P (x) ∨ Q(x)).

Negating Quantified Expressions


Consider the negation of the statement
“Every student in your class has taken a course in calculus.”
This statement is a universal quantification, namely,∀x P(x), where P(x) is the statement “x has
taken a course in calculus” and the domain consists of the students in your class.
• The negation of this statement is “It is not the case that every student inyour class has taken
a course in calculus.”
• This is equivalent to “There is a student in your class who has not taken a course in
calculus.”
• And this is simply the existential quantification of the negation of the original propositional
function, namely, ∃x ¬P (x).

De Morgan’s laws for quantifiers


Equivalent
Negation When Is Negation True? When False?
Statement
There is an x forwhich P(x) is
¬∃x P (x) ∀x ¬P (x) For every x, P (x) is false.
true.
¬∀x P (x) ∃x ¬P (x) There is an x for which P(x)is false.
P (x) is true for everyx.

Example What are the negations of the statements “There is an honestpolitician”.


Solution: Let H (x) denote “x is honest.” Then the statement “There is an honest politician” is
represented by ∃x H(x), where the domain consists of all politicians.
The negation of the statement is ¬∃x H(x), which is equivalent to ∀x¬ H(x). “Every politician is
dishonest.”

Nested Quantifiers
Nested quantifiers, where one quantifier is within the scope of another, such as:
∀x ∃y (x + y = 0). Everything within the scope of a quantifier can be thought of as a propositional
function.

For example, ∀x ∃y(x + y = 0) is the same thing as ∀x Q(x), where Q(x) is ∃y P (x,y), where P (x, y) is
x + y = 0.
Understanding Statements Involving Nested Quantifiers
For example, assume that the domain for the variables x and y consists of all realnumbers.
• The statement ∀x ∀y(x + y = y + x) says that x + y = y + x for all real numbers x and y.
(Commutative law)
• Likewise, the statement ∀x ∃y (x + y = 0) says that for every real number x there is a real
number y such that x+ y = 0. (Additive Inverse)
• Similarly, the statement ∀x ∀y ∀z(x+(y+ z) = (x + y) + z) (Associative law)

Example: Let Q(x, y) denote “x + y = 0.” What are the truth values of the quantifications ∃y ∀x Q(x,
y) and ∀x ∃y Q(x, y), where the domain for all variables consists of all real numbers?
Solution: The quantification ∃y ∀x Q(x, y) denotes the proposition. “There is a real number y such
that for every real number x, Q(x, y).”
9
Quantification of two variables
Statement When True? When False?
∀x ∀y P(x,y)
P(x, y) is true for every pairx, y. There is a pair x, y for which P(x, y) isfalse.
∀y ∀x P(x,y)
For every x there is a y forwhich P There is an x such that P(x, y) is falsefor every
∀x ∃y P(x,y)
(x, y) is true. y.
There is an x for which P (x,y) is For every x there is a y for which P(x, y) is
∃x ∀y P(x,y)
true for every y. false.
There is a pair x, y forwhich P (x,
∃x ∃y P(x,y) P (x, y) is false for every pair x, y
y) is true.

Translating Mathematical Statements into StatementsInvolving Nested Quantifiers


Mathematical statements expressed in English can be translated into logicalexpressions.
Example
Translate the statement “The sum of two positive integers is always positive” into a logical
expression.
Solution
“For all positive integers x and y, x + y is positive.” Consequently, we can express this statement as:
∀x ∀y((x > 0) 𝖠 (y > 0) → (x + y > 0)), where the domain for both variables consists of all integers.

Translating from Nested Quantifiers into English


Example Translate the statement ∀x(C(x) ∨ ∃y(C(y) 𝖠 F (x, y))) into English, where C(x) is “x has a
computer,” F (x, y) is “x and y are friends,” and the domain for both x and y consists of all students
in your school.
Solution Every student in your school has a computer or has a friend who has a computer.
Every Theorem in Mathematics, or any subject for that matter, is supported byunderlying proofs.
These proofs are nothing but a set of arguments that are conclusive evidence of the validity of the
theory.
The arguments are chained together using Rules of Inferences to deduce new statements and
ultimately prove that the theorem is valid.

Important Definitions :
1. Argument – A sequence of statements, premises, that end with aconclusion.
2. Validity – A deductive argument is said to be valid if and only if it takes a form that makes it
impossible for the premises to be true and the conclusionnevertheless to be false.
3. Fallacy – An incorrect reasoning or mistake which leads to invalidarguments.

Structure of an Argument :
As defined, an argument is a sequence of statements called premises which end with a
conclusion.

10
Rules of Inference :
Simple arguments can be used as building blocks to construct more complicated valid arguments.
Certain simple arguments that have been established as valid are very important in terms of their
usage. These arguments are called Rules of Inference.

The most commonly used Rules of Inference are tabulated below

Similarly, we have Rules of Inference for quantified statements –

11
how Rules of Inference can be used to deduce conclusions from given arguments or check the
validity of a given argument.

Example : Show that the hypotheses


“It is not sunny this afternoon and it is colder than yesterday”, “We will go swimming only if it is
sunny”,
“If we do not go swimming, then we will take a canoe trip”, and“If we take a canoe trip, then we will
be home by sunset”
lead to the conclusion

“We will be home by sunset”.


The first step is to identify propositions and use propositional variables torepresent them.

To deduce the conclusion we must use Rules of Inference to construct a proof using the given
hypotheses.

12
Resolution Principle :
To understand the Resolution principle, first we need to know certain definitions.

For example,

We can use the resolution principle to check the validity of arguments or deduce conclusions from
them. Other Rules of Inference have the same purpose, but
Resolution is unique. It is complete by it’s own. You would need no other Rule of Inference to
deduce the conclusion from the given argument.

To do so, we first need to convert all the premises to clausal form. The next step is to apply the
resolution Rule of Inference to them step by step until it cannot be applied any further.

13
For example, consider that we have the following premises –

Note:Implecations can also be visualised on octagon as,

It shows how implecation changes on changing order of there exists and for allsymbols.
Set and Relations
Set
Sets are used to group objects together.

DEFINITION 1 A set is an unordered collection of objects, called elements or members of the set. A
set is said to contain its elements. We write a ∈ A to denote that a is an element of the set A. The
notation a ∈ A denotes that a is not an element of the set A.
It is common for sets to be denoted using uppercase letters. Lowercase letters are usually used to
denote elements of sets.

EXAMPLE 1 The set V of all vowels in the English alphabet can be written as V =
{a, e, i, o, u}.

EXAMPLE 2 The set O of odd positive integers less than 10 can be expressed by O
= {1, 3, 5, 7, 9}.

14
DEFINITION 2 Two sets are equal if and only if they have the same elements. Therefore, if A
and B are sets, then A and B are equal if and only if ∀x(x ∈ A ↔ x
∈ B). We write A = B if A and B are equal sets.

EXAMPLE The sets {1, 3, 5} and {3, 5, 1} are equal, because they have the sameelements.

THE EMPTY SET


There is a special set that has no elements. This set is called the empty set, or null set, and is
denoted by ∅.

Venn diagrams
In Venn diagrams the universal set U, which contains all the objects under consideration, is
represented by a rectangle.

EXAMPLE 7 Draw a Venn diagram set of vowels in the English alphabet.

Venn diagram for the Set of Vowels

Subsets
It is common to encounter situations where the elements of one set are also the elements of a
second set.

DEFINITION 3: The set A is a subset of B if and only if every element of A is also an element of B.
We use the notation A ⊆ B to indicate that A is a subset of theset B.
We see that A ⊆ B if and only if the quantification ∀x(x ∈ A → x ∈ B) is true.
• Showing that A is a Subset of B To show that A ⊆ B, show that if x belongs to A then x also
belongs to B.
• Showing that A is Not a Subset of B To show that A ⊆ B, find a single x ∈ Asuch that x ∈ B.

Venn diagram Showing that A is a Subset of B.

THEOREM 1 For every set S, (i) ∅ ⊆ S and (ii) S ⊆ S.


15
Proof: Let S be a set. To show that ∅ ⊆ S, we must show that ∀x(x ∈∅→ x ∈ S) istrue. Because the
empty set contains no elements, it follows that x ∈ ∅ is always false. It follows that the conditional
statement x ∈∅→ x ∈ S is always true, because its hypothesis is always false and a conditional
statement with a falsehypothesis is true. Therefore, ∀x(x ∈∅→ x ∈ S) is true.

Showing Two Sets are Equal


To show that two sets A and B are equal, show that A ⊆ B and B ⊆ A.

The Size of a Set


DEFINITION 4 Let S be a set. If there are exactly n distinct elements in S where n is a non negative
integer, we say that S is a finite set and that n is the cardinality of
S. The cardinality of S is denoted by |S|.
EXAMPLE Let A be the set of odd positive integers less than 10. Then |A| = 5.

Power Sets
DEFINITION 6 Given a set S, the power set of S is the set of all subsets of the set [Link] power set
of S is denoted by P(S).
EXAMPLE What is the power set of the set {0, 1, 2}?
Solution: The power set P({0, 1, 2}) is the set of all subsets of {0, 1, 2}. Hence, P({0, 1, 2}) =
{∅,{0},{1},{2},{0, 1},{0, 2},{1, 2},{0, 1, 2}}.

Cartesian Products
The order of elements in a collection is often important. Because sets are unordered, a different
structure is needed to represent ordered collections. Thisis provided by ordered n-tuples.

DEFINITION 7 The ordered n-tuple (a1, a2... a n) is the ordered collection that has a1 as its first
element, a2 as its second element... and a n as its nth element.

DEFINITION 8 Let A and B be sets. The Cartesian product of A and B, denoted by A


× B, is the set of all ordered pairs (a, b), where a ∈ A and b ∈ B. Hence,A × B = {(a, b) | a ∈ A 𝖠 b ∈ B}.

EXAMPLE What is the Cartesian product of A = {1, 2} and B = {a, b, c}?


Solution: The Cartesian product A × B is A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2,c)}.
Cartesian products A × B and B × A are not equal, unless A = ∅ or B = ∅ or A = B.

DEFINITION 9 The Cartesian product of the sets A1, A2,...,A n, denoted by A1 × A2


×···× An, is the set of ordered n-tuples (a1, a2,...,a n), where a i belongs to Ai for i =1, 2,...,n.
In other words, A1 × A2 ×···× A n = {(a1, a2,...,a n) | a i ∈ Ai for i = 1, 2,...,n}.

EXAMPLE What is the Cartesian product A × B × C, where A = {0, 1}, B = {1, 2}, andC = {0, 1, 2} ?
Solution: A × B × C = {(0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 2, 0), (0, 2, 1), (0, 2, 2), (1, 1, 0),
(1, 1, 1),(1, 1, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2)}.

Operations on Sets
The basic set operations are:
1. Union of Sets: Union of Sets A and B is defined to be the set of all those elements which
belong to A or B or both and is denoted by A𝖴B.
1. A𝖴B = {x: x ∈ A or x ∈ B}
16
Example: Let A = {1, 2, 3}, B= {3, 4, 5, 6}
A𝖴B = {1, 2, 3, 4, 5, 6}.

2. Intersection of Sets: Intersection of two sets A and B is the set of all those elements which
belong to both A and B and is denoted by A ∩ B.
1. A ∩ B = {x: x ∈ A and x ∈ B}
Example: Let A = {11, 12, 13}, B = {13, 14, 15}A ∩ B = {13}.

3. Difference of Sets: The difference of two sets A and B is a set of all those elements which
belongs to A but do not belong to B and is denoted by A - B.
1. A - B = {x: x ∈ A and x ∉ B}
Example: Let A = {1, 2, 3, 4} and B = {3, 4, 5, 6} then A - B = {3, 4} and B - A = {5, 6}

2. Complement of a Set: The Complement of a Set A is a set of all those elementsof the universal

17
set which do not belong to A and is denoted by Ac.
Ac = U - A = {x: x ∈ U and x ∉ A} = {x: x ∉ A}

Example: Let U is the set of all natural numbers.A = {1, 2, 3}


Ac = {all natural numbers except 1, 2, and 3}.

3. Symmetric Difference of Sets: The symmetric difference of two sets A and B is the set
containing all the elements that are in A or B but not in both and is denoted by A ⨁ B i.e.
1. A ⨁ B = (A 𝖴 B) - (A ∩ B)

Example: Let A = {a, b, c, d}B = {a, b, l, m}


A ⨁ B = {c, d, l, m}

Set Identities

Idempotent laws: A𝖴A=A A∩A=A


Associative laws: (A 𝖴 B) 𝖴 C = A 𝖴 (B 𝖴C) (A ∩ B) ∩ C = A ∩ (B ∩ C)
Commutative A𝖴B=B𝖴A A∩B=B∩A
laws:
Distributive laws: A 𝖴 (B ∩ C) = (A 𝖴 B) ∩(A 𝖴 A ∩ (B 𝖴 C) = (A ∩ B) 𝖴
C) (A ∩ C)

Identity laws: A 𝖴∅= A A ∩ U = A A∩U=A


A𝖴U=U

18
Complement laws: A 𝖴 A`= UU` = ∅ A ∩ A` = ∅
∅` = U

Involution laws: (A`)` = A

De Morgan’s (A 𝖴 B)` = A` ∩ B` (A ∩ B)` = A` 𝖴 B`


laws:

EXAMPLE Use set builder notation and logical equivalences to establish the first De Morgan law A
∩ B =A 𝖴 B.
Solution: A ∩ B = {x | x /∈ A ∩ B} definition of complement
= {x | ¬(x ∈ (A ∩ B))} definition of does not belong symbol
= {x | ¬(x ∈ A 𝖠 x ∈ B)} definition of intersection
= {x | ¬(x ∈ A) ∨ ¬(x ∈ B)} first De Morgan law
= {x | x /∈ A ∨ x /∈ B} by definition of does not belong symbol
= {x | x ∈ A ∨ x ∈ B} definition of complement
= {x | x ∈ A 𝖴 B} definition of union
=A𝖴B

A membership table for the distributive property

A B C B𝖴C A ∩ (B 𝖴 C) A∩B A∩C (A ∩ B) 𝖴 (A ∩C)

1 1 1 1 1 1 1 1
1 1 0 1 1 1 0 1
1 0 1 1 1 0 1 1
1 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0
0 1 0 1 0 0 0 0
0 0 1 1 0 0 0 0
0 0 0 0 0 0 0 0

EXAMPLE Let A, B, and C be sets. Show thatA 𝖴 (B ∩ C) = (C 𝖴 B) ∩ A.


Solution: A 𝖴 (B ∩ C) = A ∩ (B ∩ C) First De Morgan law
= A ∩ (B 𝖴 C) Second De Morgan law
= (B 𝖴 C) ∩ A Commutative law
= (C 𝖴 B) ∩ A by the commutative law for unions.

Generalized Unions and Intersections


Unions and intersections of sets satisfy associative laws, the sets A 𝖴 B 𝖴 C and A
∩ B ∩ C are well defined; that is, the meaning of this notation is unambiguouswhen A, B, and C
are sets.

19
FIGURE The Union and Intersection of A, B, and C.

DEFINITION 6 The union of a collection of sets is the set that contains those elements that
are members of at least one set in the collection.

DEFINITION 7 The intersection of a collection of sets is the set that contains those elements that
are members of all the sets in the collection. A1 ∩ A2 ∩···∩ A n to denote the intersection of the sets
A1, A2... A n.

Relations Introduction
An ordered pair of elements a and b, where a is designated as the first element
and b as the second element, is denoted by (a, b). In particular, (a, b) = (c, d) if andonly if a = c and b
= d. Thus (a, b) = (b, a) unless a = b.

Definition 1 Let A and B be sets. A binary relation or, simply, relation from A to Bis a subset of A ×
B.
(i) (a, b) ∈ R; we then say “a is R-related to b”, written a R b.
(ii) (a, b) /∈ R; we then say “a is not R-related to b”, written a R b.

If R is a relation from a set A to itself, that is, if R is a subset of A2 = A × A, then we say that R is a
relation on A.
EXAMPLE Set inclusion ⊆ is a relation on any collection of sets. For, given any pair of set A and B,
either A ⊆ B or A ⊆ B.

Inverse Relation
Let R be any relation from a set A to a set B. The inverse of R, denoted by R−1, is the relation from
B to A which consists of those ordered pairs which, whenreversed, belong to R; that is,
R−1 = {(b, a)|(a, b) ∈ R}
For example, let A = {1, 2, 3} and B = {x, y, z}. Then the inverse ofR = {(1, y), (1, z), (3, y)} is R−1 = {(y,
1), (z, 1), (y, 3)}

Representation of Relations
Mij = 0 if (ai,bj) ∉ R

1 if (ai,bj )∈ R
Relations can be represented in many ways. Some of which are as follows:
1. Relation as a Matrix: Let P = [a1,a2,a3,.......am] and Q = [b1,b2,b3......bn] are finite sets, containing m
20
and n number of elements respectively. R is a relation from P to Q. The relation R can be
represented by m x n matrix M = [Mij], defined as

Example
1. Let P = {1, 2, 3, 4}, Q = {a, b, c, d}
2. and R = {(1, a), (1, b), (1, c), (2, b), (2, c), (2, d)}.
The matrix of relation R is shown as fig:

2. Relation as a Directed Graph: There is another way of picturing a relation R when R is a


relation from a finite set to itself.
Example
1. A = {1, 2, 3, 4}
2. R = {(1, 2) (2, 2) (2, 4) (3, 2) (3, 4) (4, 1) (4, 3)}

3. Relation as an Arrow Diagram: If P and Q are finite sets and R is a relation fromP to Q. Relation
R can be represented as an arrow diagram as follows.
Draw two ellipses for the sets P and Q. Write down the elements of P and elements of Q column-
wise in three ellipses. Then draw an arrow from the first ellipse to the second ellipse if a is related
to b and a ∈ P and b ∈ Q.
Example
1. Let P = {1, 2, 3, 4}
2. Q = {a, b, c, d}
3. R = {(1, a), (2, a), (3, a), (1, b), (4, b), (4, c), (4, d)
The arrow diagram of relation R is shown in fig:

21
4. Relation as a Table: If P and Q are finite sets and R is a relation from P to [Link] R can
be represented in tabular form.
Make the table which contains rows equivalent to an element of P and columns equivalent to the
element of Q. Then place a cross (X) in the boxes which represent relations of elements on set P
to set Q.
Example
1. Let P = {1, 2, 3, 4}
2. Q = {x, y, z, k}
3. R = {(1, x), (1, y), (2, z), (3, z), (4, k)}.
The tabular form of relation as shown in fig:

Composition of Relations
Let A, B, and C be sets, and let R be a relation from A to B and let S be a relationfrom B to C. That is,
R is a subset of A × B and S is a subset of B × C. Then R and S give rise to a relation from A to C
indicated by R◦S and defined by:
(i) a (R◦S)c if for some b ∈ B we have aRb and bSc.
(ii) is,
(iii) R ◦ S = {(a, c)| there exists b ∈ B for which (a, b) ∈ R and (b, c) ∈ S}

The relation R◦S is known the composition of R and S; it is sometimes denotedsimply by RS.
Let R is a relation on a set A, that is, R is a relation from a set A to itself. Then R◦R, the composition
of R with itself, is always represented. Also, R◦R is sometimes denoted by R2. Similarly, R3 = R2◦R =
R◦R◦R, and so on. Thus Rn is defined for all positive n.

Example1: Let X = {4, 5, 6}, Y = {a, b, c} and Z = {l, m, n}. Consider the relation R1 from X to Y and R2

22
from Y to Z.

R1 = {(4, a), (4, b), (5, c), (6, a), (6, c)}
R2 = {(a, l), (a, n), (b, l), (b, m), (c, l), (c, m), (c, n)}

Find the composition of relation (i) R1 o R2 (ii) R1o R -1


1
Solution:
1. The composition relation R1 o R2 as shown in fig:

R1 o R2 = {(4, l), (4, n), (4, m), (5, l), (5, m), (5, n), (6, l), (6, m), (6, n)}
2. The composition relation R1o R -1 as shown in fig:
3. 1

R1o R1-1 = {(4, 4), (5, 5), (5, 6), (6, 4), (6, 5), (4, 6), (6, 6)}
Composition of Relations and Matrices
There is another way of finding R◦S. Let MR and MS denote respectively the matrix representations
23
of the relations R and S. Then

Example
1. Let P = {2, 3, 4, 5}. Consider the relation R and S on P defined by
2. R = {(2, 2), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5), (5, 3)}
3. S = {(2, 3), (2, 5), (3, 4), (3, 5), (4, 2), (4, 3), (4, 5), (5, 2), (5, 5)}.
4. Find the matrices of the above relations.
5. Use matrices to find the following composition of the relation R and S.
6. (i)RoS (ii)RoR (iii)SoR

Solution: The matrices of the relation R and S are a shown in fig:

(i) To obtain the composition of relation R and S. First multiply MR with MS to obtain the matrix MR
x MS as shown in fig:

The non zero entries in the matrix MR x MS tells the elements related in RoS. So,
Hence the composition R o S of the relation R and S is
1. R o S = {(2, 2), (2, 3), (2, 4), (3, 2), (3, 3), (4, 2), (4, 5), (5, 2), (5, 3), (5, 4), (5, 5)}.
(ii) First, multiply the matrix MR by itself, as shown in fig
(iii)

Hence the composition R o R of the relation R and S is


24
1. R o R = {(2, 2), (3, 2), (3, 3), (3, 4), (4, 2), (4, 5), (5, 2), (5, 3), (5, 5)}
(iv) Multiply the matrix MS with MR to obtain the matrix MS x MR as shown in fig:

The non-zero entries in matrix MS x MR tells the elements related in S o R.

Hence the composition S o R of the relation S and R is


1. S o R = {(2, 4) , (2, 5), (3, 3), (3, 4), (3, 5), (4, 2), (4, 4), (4, 5), (5, 2), (5, 3), (5,
4), (5, 5)}.

Types of Relations
1. Reflexive Relation: A relation R on set A is said to be a reflexive if (a, a) ∈ R forevery a ∈ A.
Example: If A = {1, 2, 3, 4} then R = {(1, 1) (2, 2), (1, 3), (2, 4), (3, 3), (3, 4), (4, 4)}. Is
a relation reflexive?
Solution: The relation is reflexive as for every a ∈ A. (a, a) ∈ R, i.e. (1, 1), (2, 2), (3, 3), (4, 4) ∈ R.

2. Irreflexive Relation: A relation R on set A is said to be irreflexive if (a, a) ∉ R forevery a ∈ A.


Example: Let A = {1, 2, 3} and R = {(1, 2), (2, 2), (3, 1), (1, 3)}. Is the relation R reflexive or irreflexive?
Solution: The relation R is not reflexive as for every a ∈ A, (a, a) ∉ R, i.e., (1, 1) and (3, 3) ∉ R. The
relation R is not irreflexive as (a, a) ∉ R, for some a ∈ A, i.e., (2, 2) ∈ R.

3. Symmetric Relation: A relation R on set A is said to be symmetric iff (a, b) ∈ R


- (b, a) ∈ R.
Example: Let A = {1, 2, 3} and R = {(1, 1), (2, 2), (1, 2), (2, 1), (2, 3), (3, 2)}. Is a
relation R symmetric or not?
Solution: The relation is symmetric as for every (a, b) ∈ R, we have (b, a) ∈ R, i.e.,(1, 2), (2, 1), (2, 3),
(3, 2) ∈ R but not reflexive because (3, 3) ∉ R.

Example of Symmetric Relation:


1. Relation ⊥r is symmetric since a line a is ⊥r to b, then b is ⊥r to a.
2. Also, Parallel is symmetric, since if a line a is ∥ to b then b is also ∥ to a.

Antisymmetric Relation: A relation R on a set A is antisymmetric iff (a, b) ∈ R and(b, a) ∈ R then a


= b.
Example1: Let A = {1, 2, 3} and R = {(1, 1), (2, 2)}. Is the relation R antisymmetric?
Solution: The relation R is antisymmetric as a = b when (a, b) and (b, a) bothbelong to R.

Example2: Let A = {4, 5, 6} and R = {(4, 4), (4, 5), (5, 4), (5, 6), (4, 6)}. Is the relationR antisymmetric?
Solution: The relation R is not antisymmetric as 4 ≠ 5 but (4, 5) and (5, 4) bothbelong to R.

25
5. Asymmetric Relation: A relation R on a set A is called an Asymmetric Relation if for every (a, b)
∈ R implies that (b, a) does not belong to R.
6. Transitive Relations: A Relation R on set A is said to be transitive iff (a, b) ∈ Rand (b, c) ∈ R
⟺ (a, c) ∈ R.
Example1: Let A = {1, 2, 3} and R = {(1, 2), (2, 1), (1, 1), (2, 2)}. Is the relationtransitive?
Solution: The relation R is transitive as for every (a, b) (b, c) belong to R, we have (a, c) ∈ R i.e, (1,
2) (2, 1) ∈ R ⇒ (1, 1) ∈ R.

Note1: The Relation ≤, ⊆ and / are transitive, i.e.,


(i) a ≤ b, b ≤ c then a ≤ c
(ii) Let a ⊆ b, b ⊆ c then a ⊆ c
(iii) Let a/b, b/c then a/c.

Note2: ⊥r is not transitive since a ⊥r b, b ⊥r c then it is not true that a ⊥r c. Since no line
is ∥ to itself, we can have a ∥ b, b ∥ a but a ∦ a. Thus ∥ is not
transitive, but it will be transitive in the plane.

7. Identity Relation: Identity relation I on set A is reflexive, transitive andsymmetric. So identity


relation I is an Equivalence Relation.
Example: A= {1, 2, 3} = {(1, 1), (2, 2), (3, 3)}

8. Void Relation: It is given by R: A →B such that R = ∅ (⊆ A x B) is a null relation. Void Relation R


= ∅ is symmetric and transitive but not reflexive.

9. Universal Relation: A relation R: A →B such that R = A x B (⊆ A x B) is a universal relation.


Universal Relation from A →B is reflexive, symmetric and transitive. So this is an equivalence
relation.

CLOSURE PROPERTIES
A relation with property P will be called a P-relation. The P-closure of an arbitrary relation R on A,
written P (R), is a P-relation such that
R ⊆ P (R) ⊆ S for every P-relation S containing R, For the reflexive, symmetric, and transitive
closures of R.

Reflexive and Symmetric Closures


Suppose P is a property such that there is at least one P-relation containing R and that the
intersection of any P-relations is again a P-relation.
P (R) = ∩(S | S is a P-relation and R ⊆ S) P (R) from the “top-down,” that is, as the intersection of
relations. A = {(a, a)| a ∈ A} is the diagonal or equality relation on A.
Theorem: Let R be a relation on a set A. Then:
(i) R 𝖴 A is the reflexive closure of R.
(ii) R 𝖴 R−1 is the symmetric closure of R.

In other words, reflexive(R) is obtained by simply adding to R those elements (a, a) in the diagonal
which do not already belong to R, and symmetric(R) is obtained by adding to R all pairs (b, a)
whenever (a, b) belongs to R.
26
Transitive Closure Let R be a relation on a set A. R2 = R◦R and R n = R n−1◦[Link] following theorem
applies:

Theorem: R∗ is the transitive closure of R.

Theorem: Let R be a relation on a set A with n elements. ThenTransitive(R) = R 𝖴 R^2 𝖴 ... 𝖴 R n

EXAMPLE Consider the relation R = {(1, 2), (2, 3), (3, 3)} on A = {1, 2, 3}. Then: R^2
= R◦R = {(1, 3), (2, 3), (3, 3)} and R^3 = R^2◦R = {(1, 3), (2, 3), (3, 3)}
Transitive (R) = {(1, 2), (2, 3), (3, 3), (1, 3)}

EQUIVALENCE RELATIONS
Consider a nonempty set S. A relation R on S is an equivalence relation if R is reflexive, symmetric,
and transitive. That is, R is an equivalence relation on S if it has the following three properties:
1. For every a ∈ S, a R a.
2. If a R b, then b R a.
3. If a R b and b R c, then a R c.

S is an equivalence relation; that is:


1. a = a, for every a ∈ S.
2. If a = b, then b = a.
3. If a = b, b = c, then a = c.

Equivalence Relations and Partitions


This subsection explores the relationship between equivalence relations and partitions on a non-
empty set S.
Partition P of S is a collection {Ai} of nonempty subsets of S with the following twoproperties:
1. Each a ∈ S belongs to some Ai.
2. If Ai = A j then Ai ∩ A j = ∅.

Theorem: Let R be an equivalence relation on a set S. Then S/R is a partition of S.


(i) For each a in S, we have a ∈ [a].
(ii) [a]=[b] if and only if (a, b) ∈ R.
(iii)If [a] = [b], then [a] and [b] are disjoint.

Conversely, given a partition {Ai} of the set S, there is an equivalence relation R on S such that the
sets Ai are the equivalence classes.

EXAMPLE
Consider the relation R = {(1, 1), (1, 2), (2, 1), (2, 2), (3, 3)} on S = {1, 2, 3}.
One can show that R is reflexive, symmetric, and transitive, that is, that R is an equivalence
relation. Also: [1]={1, 2}, [2]={1, 2}, [3]={3} Observe that [1] = [2] and that S/R = {[1], [3]} is a partition
of S.

Partial Order Relations


A relation R on a set A is called a partial order relation if it satisfies the followingthree properties:
1. Relation R is Reflexive, i.e. aRa ∀ a∈A.
27
2. Relation R is Antisymmetric, i.e., aRb and bRa ⟹ a = b.
3. Relation R is transitive, i.e., aRb and bRc ⟹ aRc.

Example1: Show whether the relation (x, y) ∈ R, if, x ≥ y defined on the set of +veintegers is a partial
order relation.
Solution: Consider the set A = {1, 2, 3, 4} containing four +ve integers. Find the relation for this set
such as R = {(2, 1), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3), (1, 1), (2, 2),
(3, 3), (4, 4)}.

Reflexive: The relation is reflexive as for every a ∈ A. (a, a) ∈ R, i.e. (1, 1), (2, 2), (3,3), (4, 4) ∈ R.

Antisymmetric: The relation is antisymmetric as whenever (a, b) and (b, a) ∈ R,we have a = b.

Transitive: The relation is transitive as whenever (a, b) and (b, c) ∈ R, we have (a,c) ∈ R.

Example: (4, 2) ∈ R and (2, 1) ∈ R, implies (4, 1) ∈ R.


As the relation is reflexive, antisymmetric and transitive. Hence, it is a partialorder relation.
Example2: Show that the relation 'Divides' defined on N is a partial order relation.

Solution:
Reflexive: We have a divides a, ∀ a∈N. Therefore, relation 'Divides' is reflexive.
Antisymmetric: Let a, b, c ∈N, such that a divides b. It implies b divides a iff a = [Link], the relation is
antisymmetric.
Transitive: Let a, b, c ∈N, such that a divides b and b divides c.
Then a divides c. Hence the relation is transitive. Thus, the relation being reflexive, antisymmetric
and transitive, the relation 'divides' is a partial orderrelation.

Example3: (a) The relation ⊆ of a set of inclusion is a partial ordering or anycollection of sets since
set inclusion has three desired properties:
1. A ⊆ A for any set A.
2. If A ⊆ B and B ⊆ A then B = A.
3. If A ⊆ B and B ⊆ C then A ⊆ C
(b) The relation ≤ on the set R of real no that is Reflexive, Antisymmetric andtransitive.
(c) Relation ≤ is a Partial Order Relation.

n-Ary Relations
By an n-ary relation, we mean a set of ordered n-tuples. For any set S, a subset ofthe product set Sn
is called an n-ary relation on S. In particular, a subset of S3 is called a ternary relation on S.
Partial Order Set (POSET):
The set A together with a partial order relation R on the set A and is denoted by (A, R) is called a
partial orders set or POSET.

Total Order Relation


Consider the relation R on the set A. If it is also called the case that for all, a, b ∈ A, we have either
(a, b) ∈ R or (b, a) ∈ R or a = b, then the relation R is known totalorder relation on set A.

Example: Show that the relation '<' (less than) defined on N, the set of +ve integers is neither an
equivalence relation nor partially ordered relation but is atotal order relation.
28
Solution:
Reflexive: Let a ∈ N, then a < a
⟹ '<' is not reflexive.
As, the relation '<' (less than) is not reflexive, it is neither an equivalence relationnor the partial order
relation.
But, as ∀ a, b ∈ N, we have either a < b or b < a or a = b. So, the relation is a totalorder relation.

Equivalence Class
Consider, an equivalence relation R on a set A. The equivalence class of an element a ∈ A, is the
set of elements of A to which element a is related. It isdenoted by [a].

Example: Let R be an equivalence relations on the set A = {4, 5, 6, 7} defined byR = {(4, 4), (5, 5), (6,
6), (7, 7), (4, 6), (6, 4)}.
Determine its equivalence classes.

Solution: The equivalence classes are as follows:


{4} = {6} = {4, 6}
{5} = {5}
{7} = {7}.

Circular Relation
Consider a binary relation R on a set A. Relation R is called circular if (a, b) ∈ R and(b, c) ∈ R implies
(c, a) ∈ R.
Example: Consider R is an equivalence relation. Show that R is reflexive andcircular.
Solution: Reflexive: As, the relation, R is an equivalence relation. So, reflexivity is the property of an
equivalence relation. Hence, R is reflexive.
Circular: Let (a, b) ∈ R and (b, c) ∈ R
⇒ (a, c) ∈ R (∵ R is transitive)
⇒ (c, a) ∈ R (∵ R is symmetric)Thus, R is Circular.

Compatible Relation
A binary relation R on a set A that is Reflexive and symmetric is called CompatibleRelation.
Every Equivalence Relation is compatible, but every compatible relation need notbe an equivalence.
Example: Set of a friend is compatible but may not be an equivalence relation.
Friend Friend
a → b, b → c but possible that a and c are not friends.

Counting
Counting problems arise throughout mathematics and computer science. For example, we must
count the successful outcomes of experiments and all the possible outcomes of these
experiments to determine probabilities of discrete events.

Basic Counting Principles


THE PRODUCT RULE
Product rule
Basic Counting
Principles Sum rule
29
If the events occur one after the other, then all the events can occur in the order indicated in: n1 · n2
· n3 · ...ways.

EXAMPLE
How many different license plates can be made if each plate contains a sequence of three
uppercase English letters followed by three digits?
Solution: By the product rule there are a total of 26·26·26·10·10·10 = 17,576,000 possible license
plates.

THE SUM RULE


Suppose some event E can occur in m ways and a second event F can occur in n ways, and
suppose both events cannot occur simultaneously. Then E or F can occur in m + n ways.

EXAMPLE Suppose a college has 3 different history courses, 4 different literature courses, and 2
different sociology courses.
Solution:
(a) The number m of ways a student can choose one of each kind of courses is: m = 3(4)(2) = 24
(b) The number n of ways a student can choose just one of the courses is: n = 3 +4 + 2 = 9
(1) Sum Rule Principle: Suppose A and B are disjoint sets. Thenn (A 𝖴 B) = n(A) + n(B)
(2) Product Rule Principle: Let A × B be the Cartesian product of sets A and B. Then n (A × B) = n
(A) · n (B)

MATHEMATICAL FUNCTIONS
Two important mathematical functions frequently used are:
Factorial Function
The product of the positive integers from 1 to n inclusive is denoted by n!, read “n factorial.”
Namely:
n! = 1 · 2 · 3 · ... · (n−2)(n−1)n = n(n−1)(n−2) · ... · 3 · 2 · 1
Accordingly, 1! = 1 and n! = n (n − l) !. It is also convenient to define 0! = 1.
EXAMPLE: 3! = 3·2·1 = 6, 4! = 4·3·2·1 = 24, 5 = 5·4! =5(24) = 120.

Binomial Coefficients: The symbol (n r), read “n C r” or “n Choose r,” where r and n are positive
integers with r ≤ n, is defined as follows:
= n(n − 1)···(n − r + 1/ r(r − 1)... 3·2·1 or = n! / r! (n − r)!

Binomial Coefficients and Pascal’s Triangle


The numbers (n r) are called binomial coefficients, since they appear as the coefficients in the
expansion of (a + b) ^n.

The Subtraction Rule (Inclusion–Exclusion for Two Sets)


If a task can be done in either n1 ways or n2 ways, then the number of ways to do the task is n1 +
n2 minus the number of ways to do the task that are common to the two different ways.

The subtraction rule is also known as the principle of inclusion exclusion, especially when it is
used to count the number of elements in the union of two sets.
Formula: |A1 𝖴 A2|=|A1|+|A2|−|A1 ∩ A2|.

30
THE DIVISION RULE
There are n/d ways to do a task if it can be done using a procedure that can be carried out in n
ways, and for every way w, exactly d of the n ways correspond to way w.
Division rule in terms of sets: “If the finite set A is the union of n pair wise disjoint subsets each
with d elements, then n = |A|/d.”

The Pigeonhole Principle


Pigeonhole principle, which states that if there are more pigeons than pigeonholes, then there
must be at least one pigeonhole with at least two pigeons in it.

THEOREM 1 THE PIGEONHOLE PRINCIPLE If k is a positive integer and k + 1 or more objects are
placed into k boxes, then there is at least one box containing two or more of the objects.
(a) Figure there are more Pigeons than Pigeonholes
Proof: We prove the pigeonhole principle using a proof by contraposition. Suppose that none of
the k boxes contains more than one object. Then the total number of objects would be at most k.
This is a contradiction, because there is at least k + 1 objects. The pigeonhole principle is also
called the Dirichlet drawer principle.

COROLLARY 1 A function f from a set with k + 1 or more elements to a set with k elements is not
one-to-one.
EXAMPLE Among any group of 367 people, there must be at least two with the same birthday,
because there are only 366 possible birthdays.

The Generalized Pigeonhole Principle


THEOREM 2 If N objects are placed into k boxes, then there is at least one box containing at least
N/k objects.
Proof: Suppose that none of the boxes contains more than N/k − 1 objects. Then, the total number
of objects is at most
K ( [ N/k ] – 1) < k ( ( N/ k + 1 ) –1) = N , where the inequality N/k < (N/k) + 1 has been used.

EXAMPLE
What is the minimum number of students required in a discrete mathematics class to be sure that
at least six will receive the same grade, if there are five possible grades, A, B, C, D, and F?
Solution: The smallest integer N such that N/5 = 6. The smallest such integer is N =5 · 5 + 1 = 26.

Permutations and CombinationsPermutations


A permutation of a set of distinct objects is an ordered arrangement of these objects. An ordered
arrangement of r elements of a set is called an r- permutation.

31
EXAMPLE Let S = {1, 2, 3}. The ordered arrangement 3, 1, 2 is a permutation of S. The ordered
arrangement 3, 2 is a 2-permutation of S.
The number of r-permutations of a set with n elements is denoted by P (n, r). P (n, r) using the
product rule.

THEOREM 1 If n is a positive integer and r is an integer with 1 ≤ r ≤ n, then there are P (n, r) = n (n −
1)(n − 2)···(n − r + 1) r-permutations of a set with n distinct elements.
n − (r − 1) = n − r + 1 ways to choose the r th element. By the product rule, there are n (n − 1) (n −
2)···(n − r + 1) r-permutations of the set.

COROLLARY If n and r are integers with 0 ≤ r ≤ n, thenP (n, r) = n! / (n − r)!


Proof: When n and r are integers with 1 ≤ r ≤ n, by Theorem 1 we haveP (n, r) = n (n − 1) (n − 2)···(n −
r + 1) = n!/(n − r)!
n! / (n − 0)! = n!/n! = 1 whenever n is a nonnegative integer

EXAMPLE How many ways are there to select a first-prize winner, a second-prize winner, and a
third-prize winner from 100 different people who have entered a contest?
Solution: Number of 3-permutations of a set of 100 elements.P (100, 3) = 100 · 99 · 98 = 970,200.
Combinations
An r-combination of elements of a set is an unordered selection of r elements from the set.
Thus, an r-combination is simply a subset of the set with r elements.

EXAMPLE Let S be the set {1, 2, 3, 4}. Then {1, 3, 4} is a 3-combination from S.
The number of r-combinations of a set with n distinct elements is denoted by C (n,r).

THEOREM 2 The number of r-combinations of a set with n elements, where n is a nonnegative


integer and r is an integer with 0 ≤ r ≤ n, equals C (n, r) = n! / r! (n − r)!

EXAMPLE How many poker hands of five cards can be dealt from a standard deck of 52 cards?
Also, how many ways are there to select 47 cards from a standard deck of 52 cards?
Solution: C (52, 5) = 52! / (5! 47!)
First divide the numerator and denominator by 47! to obtainC (52, 5) = (52 · 51 · 50 · 49 · 48) / (5 · 4
· 3 · 2 · 1 ) = 2,598,960.

COROLLARY 2: Let n and r be non-negative integers with r ≤ n. Then C (n, r) = C(n,n − r).
DEFINITION 1 A combinatorial proof of an identity is a proof that uses counting arguments to
prove that both sides of the identity count the same objects but in different ways or a proof that is
based on showing that there is a bi-ejection between the sets of objects counted by the two sides
of the identity.
EXAMPLE How many ways are there to select five players from a 10-member tennis team to
make a trip to a match at another school?
Sol: Number of such combinations is C (10, 5) = 10! / 5! 5! = 252.
Combinations and Permutations with and without Repetition.

Type Repetition Allowed? Formula

32
r-permutations No n! / (n − r)!

r-permutations No n! / r! ( n − r)!

r-permutations Yes nr

r-combinations Yes (n + r − 1)! /r! (n − 1)!

Mathematical Induction
The process to establish the validity of an ordinary result involving natural numbers is the principle
of mathematical induction.

Working Rule
Let n0 be a fixed integer. Suppose P (n) is a statement involving the natural number n and we wish
to prove that P (n) is true for all n ≥n0.
1. Basic of Induction: P (n0) is true i.e. P (n) is true for n = n0.
2. Induction Step: Assume that the P (k) is true for n = [Link] P (K+1) must also be true.
Then P (n) is true for all n ≥n0.
Example 1:
Prove the follo2wing by Mathematical Induction:1 + 3 + 5 +. + 2n - 1 = n2.
Solution: let us assume that.
P (n) = 1 + 3 + 5 +..... + 2n - 1 = [Link] n = 1, P (1) = 1 = 12 = 1
It is true for n = 1 (i)
Induction Step: For n = r,
P (r) = 1 + 3 + 5 +..... +2r-1 = r2 is true.
(ii) Adding 2r + 1 in both sides
P (r + 1) = 1 + 3 + 5 +. +2r-1 + 2r +1
= r2 + (2r + 1) = r2 + 2r +1 = (r+1)2 (iii)
As P(r) is true. Hence P (r+1) is also [Link] (i), (ii) and (iii) we conclude that.
1 + 3 + 5 +..... + 2n - 1 =n2 is true for n = 1, 2, 3, 4, 5 Hence Proved.

Example 2:
12 + 22 + 32 +.......+ n2 =

Solution: For n = 1,
P (1) = 12 = = 1
It is true for n = 1.

Induction Step: For n = r, (i)


P (r) = 12 + 22 + 32 +........ + r2 = is true. (ii)
Adding (r+1)2 on both sides, we get
P (r+1) = 12 + 22 + 32 +.......+ r2+ (r+1)2 = + (r+1)2
33
As P (r) is true, hence P (r+1) is true. From (i), (ii) and (iii) we conclude that
12 + 22 + 32 +......+ n2= is true for n = 1, 2, 3, 4, 5 Hence Proved.
Example3: Show that for any integer n
11n+2 + 122n+1 is divisible by 133.
Solution:
Let P (n) = 11n+2+122n+1
For n = 1,
P (1) = 113+123=3059=133 x 23
So, 133 divide P (1) (i)
Induction Step: For n = r,
P (r) = 11r+2+122r+1=133 x s (ii)
Now, for n = r + 1,
P (r+1) = 11r+2+1+122(r)+3=11[133s-122r+1] + 144. 122r+1
= 11 x 133s + 122r+1.133=133[11s+122r+1]=133 x t (iii)
As (i), (ii), and (iii) all are true, hence P (n) is divisible by 133.

PROVING RESULTS ABOUT SETS


Mathematical induction can be used to prove many results about sets.

a•
X

X
54

a•

X𝖴 {a}
T

FIGURE:
34
Generating subsets of a set with k+[Link] T = S 𝖴 {a}.

Strong Induction and Well-Ordering


Strong induction, which can often be used when we cannot easily prove a result using
mathematical induction.

To prove that P (n) is true for all positive integers n, where P (n) is a propositional function, we
complete two steps:
BASIS STEP: We verify that the proposition P (1) is true. INDUCTIVE STEP: Conditional statement
[P (1) 𝖠 P (2) 𝖠···𝖠P (k)] → P (k + 1) is true for all positive integers k.

Using Strong Induction in Computational Geometry A polygon is called convex if every line
segment connecting two points in the interior of the polygon lies entirely inside the polygon. (A
polygon that is not convex is said to be non- convex.)

FIGURE Convex and Non-convex Polygons.

THEOREM 1 A simple polygon with n sides, where n is an integer with n ≥ 3, can be triangulated
into n − 2 triangles.
LEMMA 1 Every simple polygon with at least four sides has an interior diagonal.
Proof (of Theorem 1): We will prove this result using strong induction. Let T (n) be the statement
that every simple polygon with n sides can be triangulated into n − 2 triangles.
BASIS STEP: T (3) is true because a simple polygon with three sides is a triangle. Consequently,
every simple polygon with n = 3 has can be triangulated into n − 2 =3 − 2 = 1triangle.

INDUCTIVE STEP: For the inductive hypothesis,T(j ) is true for all integers j with 3 ≤j ≤ k. That is, we
assume that we can triangulate a simple polygon with j sides intoj − 2 triangles whenever 3 ≤ j ≤ k.
To complete the inductive step, we must show that when we assume the inductive hypothesis, P (k
+ 1) is true, that is, that every simple polygon with k + 1 sides can be triangulated into (k + 1) − 2 =
k − 1 triangles.

Proofs Using the Well-Ordering Property


The validity of both the principle of mathematical induction, strong induction follows from a
fundamental axiom of the set of integers, the well-ordering property.

EXAMPLE Use the well-ordering property to prove the division algorithm. Recall that the division
algorithm states that if a is an integer and d is a positive integer, then there are unique integers q
and r with 0 ≤ r<d and a = d q + r.
Solution: Let S be the set of nonnegative integers of the form a – d q, where q is an integer. This
set is nonempty because –d q can be made as large as desired (taking q to be a negative integer
with large absolute value).
By the well-ordering property, S has a least element r = a − dq0. The integer r is nonnegative. It is
also the case that r<d.
35
Recursively Defined Functions
BASIS STEP: Specify the value of the function at zero.
RECURSIVE STEP: Give a rule for finding its value at an integer from its values at smaller
integers.
Such a definition is called a recursive or inductive definition.

EXAMPLE Suppose that f is defined recursively by f (0) = 3,f (n + 1) = 2f (n) + [Link] f (1), f (2), and f
(4).
Solution: f (1) = 2f (0) + 3 = 2 · 3 + 3 = 9,
f (2) = 2f (1) + 3 = 2 · 9 + 3 = 21,f (4) = 2f (3) + 3 = 2 · 45 + 3 = 93.

Probability
The word 'Probability' means the chance of occurring of a particular event. It is generally possible
to predict the future of an event quantitatively with a certain probability of being correct. The
probability is used in such cases wherethe outcome of the trial is uncertain.

Probability Definition:
The probability of happening of an event A, denoted by P(A), is defined as

Thus, if an event can happen in m ways and fails to occur in n ways and m+n ways is equally
likely to occur then the probability of happening of the event Ais given by

And the probability of non-happening of A is

Note:
1. The probability of an event which is certain to occur is one.
2. The probability of an event which is impossible to zero.
3. If the probability of happening of an event P(A) and that of nothappening is P(A), then
P(A)+ P(A) = 1, 0 ≤ P(A) ≤ 1,0≤ P(A)≤1.

Important Terms related to Probability:


1. Trial and Event: The performance of an experiment is called a trial, and theset of its outcomes
is termed an event.
Example: Tossing a coin and getting head is a trial. Then the event is {HT, TH,HH}
2. Random Experiment: It is an experiment in which all the possible outcomes of the experiment
are known in advance. But the exact outcomes of any specific performance are not known in
advance.
Example:
1. Tossing a Coin
2. Rolling a die
3. Drawing a card from a pack of 52 cards.
4. Drawing a ball from a bag.
36
3. Outcome: The result of a random experiment is called an Outcome.
Example: 1. Tossing a coin is an experiment and getting head is called anoutcome.
2. Rolling a die and getting 6 is an outcome.

4. Sample Space: The set of all possible outcomes of an experiment is called sample space
and is denoted by S.
Example: When a die is thrown, sample space is S = {1, 2, 3, 4, 5, 6}
It consists of six outcomes 1, 2, 3, 4, 5, 6
Note1: If a die is rolled n times the total number of outcomes will be 6 n. Note2: If 1 die rolled n
times then n die rolled 1 time.

5. Complement of Event: The set of all outcomes which are in sample spacebut not an event is
called the complement of an event.

6. Impossible Events: An event which will never be happened.


Example1: Tossing double-headed coins and getting tails in an impossibleevent.
Example2: Rolling a die and getting number > 10 in an impossible outcome.
P (impossible outcome) =0

7. Sure Outcome/Certain Outcome: An Outcome which will definitely behappen


Example1: Tossing double-headed coins and getting heads only.
Example2: Rolling a die and getting number < 6P (sure outcome) = 1
{1, 2, 3, 4, 5 6} is called sure eventP (sure outcome) = 1

8. Possible Outcome: An outcome which is possible to occur is called PossibleOutcome.


Example1: Tossing a fair coin and getting a head on it.

Example2: Rolling a die and getting an odd number.

9. Equally Likely Events: Events are said to be equally likely if one of them cannot be expected
to occur in preference to others. In other words, it means each outcome is as likely to occur
as any other outcome.
Example: When a die is thrown, all the six faces, i.e., 1, 2, 3, 4, 5 and 6 areequally likely to occur.

Mutually Exclusive or Disjoint Events: Events are called mutually exclusive if they cannot occur
simultaneously.
Example: Suppose a card is drawn from a pack of cards, then the events getting a jack and
getting a king are mutually exclusive because they cannotoccur simultaneously.

[Link] Events: The total number of all possible outcomes of an experiment is called
exhaustive events.
Example: In the tossing of a coin, either head or tail may turn up. Therefore, there are two possible
outcomes. Hence, there are two exhaustive events in tossing a coin.

[Link] Events: Events A and B are said to be independent if theoccurrence of any one
event does not affect the occurrence of any other event.
37
P (A ∩ B) = P (A) P (B).
Example: A coin is tossed thrice, and all 8 outcomes are equally likely A: "The first throw results
in heads."
B: "The last throw results in Tails."Prove that event A and B are independent.
Solution:

[Link] Event: Events are said to be dependent if occurrence of oneaffect the occurrence
of other events.

Addition Theorem
Theorem1: If A and B are two mutually exclusive events, thenP(A 𝖴B)=P(A)+P(B)
Proof: Let the n=total number of exhaustive cases n1= number of cases favorable to A. n2=
number of cases favorable to B.
Now, we have A and B two mutually exclusive events. Therefore, n1+n2 is the number of cases
favorable to A or B.

Example: Two dice are tossed once. Find the probability of getting an even number on first dice
or a total of 8.
Solution: An even number can be got on a die in 3 ways because any one of 2 , 4,6 , can come. The
other die can have any number. This can happen in 6 ways. ∴ 𝑃( an even number on Ist die ) =
3×6 18 1
= =
36 36 2
A total of 8 can be obtained in the following cases:

{(2,6), (3,5), (4,4), (5,3), (6,2)}


5
∴ 𝑃( a total of 8) =
36
1 5 23
∴ Total Probability = + =
2 36 36
Theorem2: If 𝐴 and 𝐵 are two events that are not mutually exclusive, then

𝑃(𝐴 ∪ 𝐵) = 𝑃(𝐴) + 𝑃(𝐵) − 𝑃(𝐴 ∩ 𝐵).


38
Proof: Let n = total number of exhaustive cases
n1 = number of cases favorable to 𝐴
𝑛2 = number of cases favorable to 𝐵
𝑛3 = number of cases favorable to both 𝐴 and 𝐵
But 𝐴 and 𝐵 are not mutually exclusive. Therefore, 𝐴 and 𝐵 can occur
simultaneously. So, 𝑛1 + 𝑛2 − 𝑛3 is the number of cases favorable to 𝐴 or 𝐵.
𝑛1 +𝑛2 −𝑛3 𝑛1 𝑛2 𝑛3
Therefore, 𝑃(𝐴 ∪ 𝐵) = = + −
𝑛 𝑛 𝑛 𝑛
𝑛 𝑛 𝑛
But we have, 𝑃(𝐴) = 𝑛1 , 𝑃(𝐵) = 𝑛2 and 𝑃(𝐴 ∩ 𝐵) = 𝑛3
Hence, 𝑃(𝐴 ∪ 𝐵) = 𝑃(𝐴) + 𝑃(𝐵) − 𝑃(𝐴 ∩ 𝐵).
Example1: Two dice are tossed once. Find the probability of getting an even number on first dice
or a total of 8 .

Solution: 𝑃( even number on Ist die or a total of 8) = 𝑃 (even number on Ist die ) + 𝑃( total of 8) =
𝑃( even number on Ist die and a total of 8)
18 1
∴ Now, 𝑃( even number on Ist die ) = =
36 2
Ordered Pairs showing a total of 8 = {(6,2), (5,3), (4,4), (3,5), (2,6)} = 5 ∴ Probability;
5
𝑃( total of 8) = 36
3
𝑃( even number on Ist die and total of 8) = 36
18 5 3 20 5
∴ Required Probability = 36 + 36 − 36 = 36 = 9
Example2: Two dice are thrown. The events 𝐴, 𝐵, 𝐶, 𝐷, 𝐸, 𝐹
𝐴 = getting even number on first die.
𝐵 = getting an odd number on the first die.
𝐶 = getting a sum of the number on dice ≤ 5
𝐷 = getting a sum of the number on dice > 5 but less than 10 .
𝐸 = getting sum of the number on dice ≥ 10.
𝐹 = getting odd number on one of the dice

Show the following:


1. A, B are a mutually exclusive event and Exhaustive Event.
2. A, C are not mutually exclusive.
3. C, D are a mutually exclusive event but not Exhaustive Event.
4. C, D, E are a mutually exclusive and exhaustive event.
5. A'∩B' are a mutually exclusive and exhaustive event.
6. A, B, F are not a mutually exclusive event.

Solution:
A: (2,1),(2,2),(2,3),(2,4),(2,5),(2,6)
(4,1),(4,2),(4,3),(4,4),(4,5),(4,6)
(6,1),(6,2),(6,3),(6,4),(6,5),(6,6)
39
B: (1,1), (1,2),(1,3),(1,4),(1,5),(1,6)
(3,1),(3,2),(3,3),(3,4),(3,5),(3,6)
(5,1),(5,2),(5,3),(5,4),(5,5),(5,6)

C: (1,1),(1,2),(1,3),(1,4),(2,1),(2,2),(2,3),(3,1),(3,2),(4,1)

D: (1,5),(1,6),(2,4),(2,5),(2,6)
(3,3),(3,4),(3,5),(3,6)
(4,2),(4,3),(4,4),(4,5)
(5,1),(5,2),(5,3),(5,4)
(6,1),(6,2),(6,3)

E: (4,6),(5,5),(5,6),(6,5),(6,6),(6,4)

F: (1,2),(1,4),(1,6)
(2,1),(2,3),(2,5)
(3,2),(3,4),(3,6)
(4,1),(4,3),(4,5)
(5,2),(5,4),(5,6)
(6,1),(6,3),(6,5)

1. (A∩B) =∅ and (A𝖴B)=S


A, B are a mutually exclusive and exhaustive event.
2. (A∩C) are not mutually exclusive(2,1),(2,3),(4,1)≠ ∅
3. C∩D are a mutually exclusive but not exhaustive event.C∩D=∅ C𝖴 D≠S
4. C∩D=∅,D∩E=∅, C∩E=∅ are mutually exclusive and exhaustive event.
5. A'∩B' =(A𝖴B)' are a mutually exclusive and exhaustive event.
6. (A∩B) =∅ are a mutually exclusive
A, B, F are not mutually exclusive events.

Multiplication Theorem
Theorem: If A and B are two independent events, then the probability that both will occur is
equal to the product of their individual probabilities.
P(A∩B)=P(A)xP(B)
Proof: Let event7
A can happen is n1ways of which p are successful
B can happen is n2ways of which q are successful
Now, combine the successful event of A with successful event of B.
Thus, the total number of successful cases = p x q
We have, total number of cases = n1 x n2.
Therefore, from definition of probability

P (A and B) =P(A∩B)=

We have P(A) = ,P(B)=


40
So, P(A∩B)=P(A)xP(B)

If, there are three independent events A, B and C, then


P(A∩B∩C)=P((A∩B)∩C)= P(A∩B)xP(C)
=P(A) x P(B) x P(C).

In general, if there are n independent events, then

Example: A bag contains 5 green and 7 red balls. Two balls are drawn. Find the probability that
one is green and the other is red.

Solution: P(A) =P(a green ball) = P(B) =P(a red ball) =

By Multiplication Theorem

P(A) and P(B) = P(A) x P(B) =

CONDITIONAL PROBABILITY
Suppose E is an event in a sample space S with P (E) > 0. The probability that an event A occurs
once E has occurred or, specifically, the conditional probability ofA given E. written P (A|E), is
defined as follows: P (A|E) = P (A ∩ E) / P (E)

Theorem: Suppose S is an equi-probable space and A and E are events. Then


P (A|E) = number of elements in A ∩ E / number of elements in E = n (A ∩ E) / n(E)
Example: A couple has two children; the sample space is S = {bb, b g, g b, g g} with probability 1/4
for each point. Find the probability p that both children are boys ifit is known that: (i) at least one of
the children is a boy; (ii) the older child is a boy.
Solution: Here the reduced space consists of three elements, {bb, b g, g b}; hencep = 1/3
Here the reduced space consists of only two elements {b b, b g}; hence p = ½

Multiplication Theorem for Conditional ProbabilityTheorem: P (A ∩ B) = P (A) P (B|A)


The multiplication theorem gives us a formula for the probability that events A and B both occur. It
can easily be extended to three or more events A1, A2...A m;that is,
P (A1 ∩ A2 ∩··· Am) = P (A1) · P (A2|A1)··· P (Am|A1 ∩ A2 ∩···∩ Am−1)

INDEPENDENT EVENTS
Definition 7.2: Events A and B are independent if P(A ∩ B) = P(A)P(B); otherwisethey are dependent.
P (A ∩ B) = P (A) P (B) implies both P (B|A) = P (B) and P (A|B) = P (A)

EXAMPLE A fair coin is tossed three times yielding the equi-probable space. S = {HHH, HHT, HTH,
HTT, THH, THT, TTH, TTT}
Solution Consider the events: A = {first toss is heads} = {HHH, HHT, HTH, HTT} B = {second toss is
heads) = {HHH, HHT, THH, THT}
C = {exactly two heads in a row} = {HHT, THH}
P (A) = 4 /8 = 1 / 2, P (B) = 4 / 8 = 1 / 2, P (C) = 2 / 8 = 1/4
P (A ∩B) = P ({HHH, HHT}) = 1 / 4, P (A ∩C) = P ({HHT}) = 1 / 8, P (B ∩ C) = P ({HHT,THH}) = 1 / 4

41
INDEPENDENT REPEATED TRIALS, BINOMIAL DISTRIBUTION
Definition: Let S be a finite probability space. By the space of n independent repeated trials, we
mean the probability space S n consisting of ordered n-tuples of elements of S, with the probability
of an n-tuples defined to be the product ofthe probabilities of its components:
P ((S1, S2,..., S n)) = P (S1)P (S2) . . . P (S n)

RANDOM VARIABLES
Definition: A random variable X is a rule that assigns a numerical value to each outcome in a
sample space S.
EXAMPLE A pair of fair dice is tossed. The sample space S consists of the 36 ordered pairs (a, b)
where a and b can be any of the integers from 1 to 6.
Solution: Let x assign to each point in S the sum of the numbers; then x is a random variable with
range space
Rx = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
Let y assign to each point the maximum of the two numbers; then y is a randomvariable with range
space R y = {1, 2, 3, 4, 5, 6}
Probability Distribution of a Random Variable
Theorem: Let S be an equiv.-probable space, and let f be the distribution of a random variable X on
S with the range space Rx = {x1, x2,...,x t}.
P i = f (x i) = No. of points in S whose image is x i /No. of points in S
EXAMPLE Let X be the random variable in Example 7.13 which assigns the sum tothe toss of a pair
of dice. Note n(S) = 36, and Rx = {2, 3,..., 12}.
Solution: Using Theorem, we obtain the distribution f of X as follows:f (2) = 1/36, since there is one
outcome (1, 1) whose sum is 2.
f (3) = 2/36, since there are two outcomes, (1, 2) and (2,1), whose sum is 3.
f (4) = 3/36, since there are three outcomes, (1, 3), (2, 2) and (3, 1), whose sum is 4.
Similarly, f (5) = 4/36, f (6) = 5/36... f (12) = 1/36. Thus the distribution of Xfollows:
x 2 3 4 5 6 7 8 9 10
F(x) 1/36 2/36 3/36 4/36 5/36 6/36 7/36 8/36 7/36

Binomial Distribution
Theorem: Consider the binomial distribution B (n, p). Then:
(i) Expected value E(X) = μ = n p.
(ii) Variance V a r(X) = σ2 = n p q.
(iii)Standard deviation σ = √n p q.

EXAMPLE
The probability that a man hits a target is p = 1/5. He fires 100 times. Find theexpected number μ of
times
Solution: Man will hit the target and the standard deviation σ.
Here p = 1/5 and so q = 4/5. Hence
μ = n p = 100 *1/5 = 20 and σ = √n p q =√ 100 *1/5 *4/5 = 4

Bayes' theorem in Artificial intelligence


Bayes' theorem:
Bayes' theorem is also known as Bayes' rule, Bayes' law, or Bayesian reasoning, which determines
the probability of an event with uncertain knowledge.
42
In probability theory, it relates the conditional probability and marginal probabilities of two random
events.

Bayes' theorem was named after the British mathematician Thomas Bayes.
The Bayesian inference is an application of Bayes' theorem, which is fundamental to Bayesian
statistics.
It is a way to calculate the value of P(B|A) with the knowledge of P(A|B).
Bayes' theorem allows updating the probability prediction of an event byobserving new information
of the real world.

Example: If cancer corresponds to one's age then by using Bayes' theorem, we can determine the
probability of cancer more accurately with the help of age.
Bayes' theorem can be derived using product rule and conditional probability of event A with known
event B:
As from product rule we can write:
1. P(A ⋀ B)= P(A|B) P(B) or
Similarly, the probability of event B with known event A:
1. P(A ⋀ B)= P(B|A) P(A)
Equating right hand side of both the equations, we will get:

The above equation (a) is called as Bayes' rule or Bayes' theorem. This equation is basic of most
modern AI systems for probabilistic inference.
It shows the simple relationship between joint and conditional probabilities. Here,
P(A|B) is known as posterior, which we need to calculate, and it will be read as Probability of
hypothesis A when we have occurred an evidence B.
P(B|A) is called the likelihood, in which we consider that hypothesis is true, then we calculate the
probability of evidence.
P(A) is called the prior probability, probability of hypothesis before consideringthe evidence
P(B) is called marginal probability, pure probability of an evidence.
In the equation (a), in general, we can write P (B) = P(A)*P(B|Ai), hence the Bayes' rule can be
written as0:

Where A1, A2, A3, , An is a set of mutually exclusive and exhaustive events.
Applying Bayes' rule:

Bayes' rule allows us to compute the single term P(B|A) in terms of P(A|B), P(B), and P(A). This is
very useful in cases where we have a good probability of these three terms and want to determine
the fourth one. Suppose we want to perceive the effect of some unknown cause, and want to
compute that cause, then the Bayes' rule becomes:

43
Example-1:
Question: what is the probability that a patient has diseases meningitis with astiff neck?
Given Data:
A doctor is aware that disease meningitis causes a patient to have a stiff neck, andit occurs 80% of
the time. He is also aware of some more facts, which are given asfollows:
• The Known probability that a patient has meningitis disease is 1/30,000.
• The Known probability that a patient has a stiff neck is 2%.
Let a be the proposition that patient has stiff neck and b be the proposition thatpatient has
meningitis. , so we can calculate the following as:
P(a|b) = 0.8
P(b) = 1/30000
P(a)= .02

Hence, we can assume that 1 patient out of 750 patients has meningitis diseasewith a stiff neck.

Example-2:
Question: From a standard deck of playing cards, a single card is drawn. The probability that the
card is king is 4/52, then calculate posterior probability P(King|Face), which means the drawn
face card is a king card.

Solution:
P(king): probability that the card is King= 4/52= 1/13 P(face): probability that a card is a face card=
3/13

P(Face|King): probability of face card when we assume it is a king = 1Putting all values in equation
(i) we will get:

Application of Bayes' theorem in Artificial intelligence:


Following are some applications of Bayes' theorem:
• It is used to calculate the next step of the robot when the already executedstep is given.
• Bayes' theorem is helpful in weather forecasting.
• It can solve the Monty Hall problem.

Group Theory
Group
Let G be a non-void set with a binary operation * that assigns to each ordered pair
(a, b) of elements of G an element of G denoted by a * b. We say that G is a group under the binary
operation * if the following three properties are satisfied:
1. Associativity: The binary operation * is associative i.e. a*(b*c)=(a*b)*c , ∀ a,b,c
∈G
44
2. Identity: There is an element e, called the identity, in G, such that a*e=e*a=a,
∀a∈G
3. Inverse: For each element a in G, there is an element b in G, called an inverse of a such that
a*b=b*a=e, ∀ a, b ∈ G
Note: If a group has the property that a*b=b*a i.e., commutative law holds then the group is called
an abelian.

Properties of Groups:
The following theorems can understand the elementary features of Groups:
Theorem1:-
1. Statement: - In a Group G, there is only one identity element (uniqueness ofidentity)
Proof: - let e and e' are two identities in G and let a ∈ G
∴ ae = a ⟶(i)
∴ ae' = a ⟶(ii)
R.H.S of (i) and (ii) are equal ⇒ae =ae'
Thus by the left cancellation law, we obtain e= e'
There is only one identity element in G for any a ∈ G. Hence the theorem isproved.

2. Statement: - For each element a in a group G, there is a unique element b in G such that ab=
ba=e (uniqueness if inverses)
Proof: - let b and c are both inverses of a a∈ G
Then ab = e and ac = e
∵ c = ce {existence of identity element}
⟹ c = c (ab) {∵ ab = e}
⟹ c = (c a) b
⟹ c = (ac) b { ∵ ac = ca}
⟹ c = eb
⟹ c = b { ∵ b = eb}
Hence inverse of a G is unique.

Theorem 2:-
1. Statement: - In a Group G,(a-1)-1=a,∀ a∈ G
Proof: We have a a-1=a-1 a=e
Where e is the identity element of GThus a is inverse of a-1∈ G
i.e., (a-1)-1=a,∀ a∈ G

2. Statement: In a Group G,(a b-1)=b-1 a-1,∀ a,b∈ G


Proof: - By associatively we have(b-1 a-1)ab=b-1 (a-1 a)b
⟹(b-1 a-1)ab=b-1 (e)b {∵a-1 a=e}
⟹(b-1 a-1)ab=b-1 b {∵eb=b}
⟹(b-1 a-1)ab=e, {∵b-1 b=e}
Similarly
(ab) (b-1 a-1)=a(b b-1) a-1
⟹(ab) (b-1 a-1)=a (e) a-1
⟹(ab) (b-1 a-1)=a a-1
⟹(ab) (b-1 a-1)=e {∵aa-1=e}
Thus ( b-1 a-1)ab=(ab)(b-1 a-1)=e
∴ b-1 a-1 is the inverse of abi.e., b-1 a-1= a b-1
45
Hence the theorem is proved.

Theorem3:-
In a group G, the left and right cancellation laws hold i.e.
(i) ab = ac implies b=c
(ii) ba=ca implies b=c

Proof
(i) Let ab=ac
Premultiplying a-1 on both sides we geta-1 (ab)=a-1 (ac)
⟹ (a-1a) b=(a-1 a)c
⟹eb=ec
⟹b=c Hence Proved.
(ii) Let ba=ca
Post-multiplying a-1 on both sides
⟹(ba) a-1=(ca) a-1
⟹b(aa-1 )=c(aa-1 )
⟹be=ce
⟹b=c
Hence the theorem is proved.

Finite and Infinite Group:


A group (G, *) is called a finite group if G is a finite set.
A group (G, *) is called a infinite group if G is an infinite set.
Example1: The group (I, +) is an infinite group as the set I of integers is an infiniteset.
Example2: The group G = {1, 2, 3, 4, 5, 6, 7} under multiplication modulo 8 is afinite group as the set
G is a finite set.

Order of Group:
The order of the group G is the number of elements in the group G. It is denoted by |G|. A group of
order 1 has only the identity element, i.e., ({e} *).
A group of order 2 has two elements, i.e., one identity element and one someother element.
Example1: Let ({e, x}, *) be a group of order 2. The table of operation is shown infig:

* e x
e e x
x x e

The group of order 3 has three elements i.e., one identity element and two otherelements.

Symmetric Group S n
A one-to-one mapping σ of the set {1, 2...n} onto itself is called a permutation. σ =
1 2 3_ _ _ n
j1 j2 j3_ _ _ j n
The set of all such permutations is denoted by S n, and there are n! = n (n − 1) · ...
· 2 · 1 of them.

Subgroup
46
If a non-void subset H of a group G is itself a group under the operation of G, wesay H is a subgroup
of G.
Theorem: - A subset H of a group G is a subgroup of G if:
• the identity element a∈ H.
• H is closed under the operation of G i.e. if a, b∈ H, then a, b∈ H and
• H is closed under inverses, that is if a∈ H then a-1∈ H.

Cyclic Subgroup:-
A Subgroup K of a group G is said to be cyclic subgroup if there exists an element x∈ G such that
every element of K can be written in the form xn for some n ∈Z.
The element x is called generator of K and we write K= <x>Cyclic

Group:-
In the case when G=, we say G is cyclic and x is a generator of G. That is, a group G is said to be
cyclic if there is an element x∈ G such that every element of G can be written in the form xn for the
some n∈ Z.

Example: The group G= {1, -1, i,-i} under usual multiplication is a finite cyclic group with i as
generator, since i1=i,i2=-1,i3=-i and i4=1
Abelian Group:

Let us consider an algebraic system (G,*), where * is a binary operation on G. Then the system (G,*)
is said to be an abelian group if it satisfies all the propertiesof the group plus a additional following
property:
1. The operation * is commutative i.e.,a * b = b * a ∀ a,b ∈G
Example: Consider an algebraic system (G, *), where G is the set of all non-zero real numbers and *
is a binary operation defined by

Show that (G, *) is an abelian group.


Solution:

Closure Property: The set G is closed under the operation *, since a * b = is areal number. Hence,
it belongs to G.
Associative Property: The operation * is associative. Let a,b,c∈G, then we have

Identity: To find the identity element, let us assume that e is a +ve real number.
Then e * a = a, where a ∈G.

47
Thus, the identity element in G is 4.

Inverse: let us assume that a ∈G. If a-1∈Q, is an inverse of a, then a * a-1=4

Thus, the inverse of element a in G is

Commutative: The operation * on G is commutative.

Thus, the algebraic system (G, *) is closed, associative, identity element, inverse and commutative.
Hence, the system (G, *) is an abelian group.

Product of Groups:
Theorem: Prove that if (G1,*1)and (G2,*2) are groups, then G = G1 x G2 i.e., (G, *) is a group with
operation defined by (a1,b1)*( a2,b2 )=(a1,*1,a2, b1 *2 b2).
Proof: To prove that G1 x G2 is a group, we have to show that G1 x G2 has the associativity operator,
has an identity and also exists inverse of every element.
Associativity. Let a, b, c ∈ G1 x G2,then
So, a * (b * c) = (a1,a2 )*((b1,b2)*(c1,c2))
= (a1,a2 )*(b1 *1 c1,b2 *2 c2)
= (a1 *1 (b1 *1 c1 ),a2 *2 (b2 *2 c2)
= ((a1 *1 b1) *1 c1,( a2 *2 b2) *2 c2)
= (a1 *1 b1,a2 *2 b2)*( c1,c2)
= ((a1,a2)*( b1,b2))*( c1,c2)
= (a * b) * c.

Identity: Let e1 and e2 are identities for G1 and G2 respectively. Then, the identity for G1 x G2 is
e=(e1,e2 ).Assume same a ∈ G1 x G2
Then, a * e = (a1,a2)*( e1,e2)
= (a1 *1 e1,a2 *2 e2)
= (a1,a2)=a Similarly, we have e * a = a.

Inverse: To determine the inverse of an element in G1 x G2, we will determine itcomponent wise i.e.,
a-1=(a1,a2)-1=(a -1,a -1 )
Now to verify that this is the exact inverse, we will compute a * a-1 and a-1*[Link], a * a-1=(a1,a2 )*(a
-1,a -1 )

= (a1 *1 a -1,a2 *2 a -1)=( e1,e2)=eSimilarly, we have a-1*a=e.


Thus, (G1 x G2,*) is a group.
In general, if G1,G2,....Gn are groups, then G = G1 x G2 x. x Gn is also a group.

Cosets:

48
Let H be a subgroup of a group G. A left coset of H in G is a subset of G whose elements may be
expressed as xH={ xh | h ∈ H } for any x∈ G. The element x is called a representation of the coset.
Similarly, a right coset of H in G is a subset that may be expressed as Hx= {hx | h ∈H } , for any x∈G.
Thus complexes xH andHx are called respectively a left coset and a right coset.
If the group operation is additive (+) then a left coset is denoted as x + H={x+h | h
∈H} and a right coset is denoted by H + x = {h+x | h ∈ H}

Normal SubGroup
Let G be a group. A subgroup H of G is said to be a normal subgroup of G if for allh∈ H and x∈ G, x
h x-1∈ H
If x H x-1 = {x h x-1| h ∈ H} then H is normal in G if and only if xH x-1⊆H, ∀ x∈ G
Statement: If G is an abelian group, then every subgroup H of G is normal in G.
Proof: Let any h∈ H, x∈ G, thenx h x-1= x (h x-1)
x h x-1= (x x-1) hx h x-1 = e h
x h x-1 = h∈ H
Hence H is normal subgroup of G.

Group Homomorphism:
A homomorphism is a mapping f: G→ G' such that f (xy) =f(x) f(y), ∀ x, y ∈ G. The mapping f
preserves the group operation although the binary operations of the group G and G' are different.
Above condition is called the homomorphism condition.

Kernel of Homomorphism: - The Kernel of a homomorphism f from a group G to a group G' with
identity e' is the set {x∈ G | f(x) =e'}
The kernel of f is denoted by Ker f.
If f: G→G' is a homomorphism of G intoG', then the image set of f is the range, denoted by f (G), of
the map f. Thus
Im (f) = f (G) = {f(x)∈ G'| x ∈G}
If f (G) =G', then G' is called a homomorphic image of [Link]: - A group homomorphism

Isomorphism:
Let (G1,*) and (G2,0) be two algebraic system, where * and 0 both are binary operations. The
systems (G1,*) and (G2,0) are said to be isomorphic if there existsan isomorphic mapping f: G1→G2
When two algebraic systems are isomorphic, the systems are structurally equivalent and one can
be obtained from another by simply remaining theelements and operation.
Example: Let (A1,*) and (A2,⊡) be the two algebraic systems as shown in [Link] whether the
two algebraic systems are isomorphic.

49
Solution: The two algebraic system (A1,*) and (A2,⊡) are isomorphic and (A2,⊡) is an isomorphic
image of A1, such that
f( a)=1
f (b)=w f (c)= w2
Automorphism:
Let (G1,*) and (G2,0) be two algebraic system, where * and 0 both are binary operations on G1 and
G2 respectively. Then an isomorphism from (G1,*) to (G2,0) iscalled an automorphism if G1= G2

Rings:
An algebraic system (R, +,) where R is a set with two arbitrary binary operations + and ., is called
aring if it satisfies the following conditions
1. (R, +) is an abelian group.
2. (R,·) is a semigroup.
3. The multiplication operation, is distributive over the addition operation +i.e.,
a (b+c)=ab +ac and (b+c)a = ba + ca for all a, b, c ∈ R.

Example1: Consider M be the set of all matrices of the type over integers under matrix
addition and matrix multiplication. Thus M form a ring.
Example2: The set Z9 = {0, 1, 2, 3, 4, 5, 6, 7, 8} under the operation addition and multiplication
modulo 9 forms a ring.

Types of Rings:
1. Commutative Rings: A ring (R, +,) is called a commutative ring if it holds the commutative law
under the operation of multiplication i.e., a. b = b. a, for every a,b∈ R
Example1: Consider a set E of all even integers under the operation of addition and
multiplication. The set E forms a commutative ring.

2. Ring with Unity: A ring (R, +,) is called a ring with unity, if it has a multiplicativeidentity i.e,
Example: Consider a set M of all 2 x 2 matrices over integers under matrix multiplication and

matrix addition. The set M forms a ring with unity .

3. Ring with Zero Divisions: If a.b=0, where a and b are any two non-zero elements of R in the ring
(R, +) then a and b are called divisions of zero and thering (R, +) is called ring with zero division.

4. Rings without Zero Division: An algebraic system (R, +) where R is a set with two arbitrary
binary operation + and is called a ring without divisors of zero if forevery a, b ∈R, we have a.b≠0
⟹a≠0 and b ≠0

SubRings:
A subset A of a ring (R, +) is called a subring of R, if it satisfies following conditions: (A, +) is a
subgroup of the group (R,+)
A is closed under the multiplication operation i.e., a.b ∈A,for every a,b ∈A.
Example: The ring (I, +) of integers is a subring of ring (R, +) of real numbers.
Note:
1. If R is any ring then {0} and R are subrings of R.
50
2. Sum of two subrings may not be a subring.
3. Intersection of subring is a subring.

SemiGroup
Let us consider, an algebraic system (A, *), where * is a binary operation on A. Then, the system (A,
*) is said to be semi-group if it satisfies the following properties:
1. The operation * is a closed operation on set A.
2. The operation * is an associative operation.

Example: Consider an algebraic system (A, *), where A = {1, 3, 5, 7, 9 }, the set
of positive odd integers and * is a binary operation means multiplication. Determine whether (A, *)
is a semi-group.
Solution: Closure Property: The operation * is a closed operation because multiplication of two +ve
odd integers is a +ve odd number.

Associative Property: The operation * is an associative operation on set A. Since every a, b, c ∈ A,


we have
(a * b) * c = a * (b * c)
Hence, the algebraic system (A, *), is a semigroup.

Subsemigroup:
Consider a semigroup (A, *) and let B ⊆ A. Then the system (B, *) is called asubsemigroup if the set
B is closed under the operation *.
Example: Consider a semigroup (N, +), where N is the set of all natural numbersand + is an addition
operation. The algebraic system (E, +) is a subsemigroup of (N, +), where E is a set of +ve even
integers.

Free Semigroup:
Consider a non empty set A = {a1,a2, an}.
Now, A* is the set of all finite sequences of elements of A, i.e., A* consist of all words that can be
formed from the alphabet of A.
If α,β,and,γ are any elements of A*, then α,(β. γ)=( α.β).γ.
Here ° is a concatenation operation, which is an associative operation as shownabove.
Thus (A*,°) is a semigroup. This semigroup (A*,°) is called the free semigroupgenerated by set A.

Product of Semigroup:
Theorem: If (S1,*)and (S2,*) are semigroups, then (S1 x S2*) is a semigroup, where
* defined by (s1',s2')*( s1'',s2'')=(s1'*s1'',s2'*s2'' ).
Proof: The semigroup S1 x S2 is closed under the operation *.Associativity of *.Let a, b, c ∈ S1 x S2
So, a * (b * c) = (a1,a2 )*((b1,b2)*(c1,c2))
= (a1,a2 )*(b1 *1 c1,b2 *2 c2)
= (a1 *1 (b1 *1 c1 ),a2 *2 (b2 *2 c2)
= ((a1 *1 b1) *1*1,( a2 *2 b2) *2 c2)
= (a1 *1 b1,a2 *2 b2)*( c1,c2)
= ((a1,a2)*( b1,b2))*( c1,c2)
= (a * b) * c.
Since * is closed and associative. Hence, S1 x S2 is a semigroup.

51
Monoid:
Let us consider an algebraic system (A, o), where o is a binary operation on A. Then the system (A,
o) is said to be a monoid if it satisfies the following properties:
1. The operation o is a closed operation on set A.
2. The operation o is an associative operation.
3. There exists an identity element, i.e., the operation o.

Bridge (Cut Edges): Consider a graph G=(V, E).A bridge for a graph G, is an edge esuch that G-e has
more connected components than G or disconnected.
Example: Consider the graph shown in fig. Determine the subgraphs

(i) G-e1 (ii) G-e3 (iii) G-e4

Solution:
1. The subgraph G-e1 is shown in fig
2. The subgraph G-e3 is shown in fig
3. The subgraph G-e4 is shown in fig

52
Types of Graphs:
1. Null Graph: A null graph is defined as a graph which consists only the isolatedvertices.
Example: The graph shown in fig is a null graph, and the vertices are isolatedvertices.

2. Undirected Graphs: An Undirected graph G consists of a set of vertices, V and a set of edge E.
The edge set contains the unordered pair of vertices. If (u, v)∈E then we say u and v are
connected by an edge where u and v are vertices in the set V.

Example: Let V = {1, 2, 3, 4} and E = {(1, 2), (1, 4), (3, 4), (2, 3)}.Draw the graph.
Solution: The graph can be drawn in several [Link] of which are as follows:

3. Multigraph: If in a graph multiple edges between the same set of vertices are allowed, it is
known as Multigraph. In other words, it is a graph having at least oneloop or multiple edges.

53
4. Directed Graphs: A directed graph or digraph G is defined as an unordered pair(V, E), where V is
the set of points called vertices and E is the set of edges. Each edge in the graph G is assigned
a direction and is identified with an ordered pair (u, v), where u is the initial vertex, and v is the
end vertex.

Example: Consider the graph G = (V, E) as shown in fig. Determine the vertex set and edge set of
graph G

.
Solution: The vertex and edge set of graph G =(V, E) is as follow
G={{1,2,3},{(1,2),(2,1),(2,2),(2,3),(1,3)}}.
5. Undirected Complete Graph: An undirected complete graph G=(V,E) of n vertices is a
graph in which each vertex is connected to every other vertex i.e.,and edge exist between every pair
of distinct vertices. It is denoted by Kn.A
complete graph with n vertices will have edges.

Example: Draw Undirected Complete Graphs k4and k6.


Solution: The undirected complete graph of k4 is shown in fig1 and that of k6isshown in fig2.

54
6. Connected and Disconnected Graph:
Connected Graph: A graph is called connected if there is a path from any vertex uto v or vice-versa.
Disconnected Graph: A graph is called disconnected if there is no path between any two of its
vertices.
Example: Consider the graph shown in fig. Determine whether the graphs are
(a) Disconnected Graph
(b) Connected Graph.
Also, write their connected components.

Solution:
(i) The graph is shown in fig is a Disconnected Graph, and its connectedcomponents are
{V1,V2,V3,V4},{V5,V6,V7,V8} and {V9,V10}.
(ii) The graph shown in fig is a Disconnected Graph and its connected componentsare
{V1,V2},{V3,V4},{V5,V6},{V7,V8},{V9,V10}and {V11,V12}.

55
(iii) The graph shown in fig is a connected graph

7. Connected Component: A subgraph of graph G is called the connected component of G, if it is


not contained in any bigger subgraph of G, which isconnected. It is defined by listing its vertices.
Example: Consider the graph shown in fig. Determine its connected components.

Solution: The connected components of this graph is {a, b, c}, {d, e, f}, {g, h ,i} and {j}.
8. Directed Complete Graph: A directed complete graph G = (V, E) on n vertices isa graph in which
each vertex is connected to every other vertex by an arrow. It is denoted by Kn.
Example: Draw directed complete graphs K3 and K5.
Solution: Place the number of vertices at the appropriate place and then draw an arrow from each
56
vertex to every other vertex as shown in fig:

9. Complementary Graph: The complement of a graph G is defined to be a graph which has the
same number of vertices as in graph G and has two vertices connected if and only they are not
related in the graph.
Example: Consider the graph G shown in fig. Find the complement of this graph.

Solution: The complement of the above graph is shown in Fig:

57
10. Labeled Graphs: A graph G=(V, E) is called a labeled graph if its edges are labeled with some
name or data. So, we can write these labels in place of anordered pair in its edges set.
Example: The graph shown in fig is labeled graphs.
G= {{a, b, c, d}, {e1,e2,e3,e4}}

11. Weighted Graphs: A graph G=(V, E) is called a weighted graph if each edge of graph G is
assigned a positive number w called the weight of the edge e.
Example: The graph shown in fig is a Weighted Graph.

58
Degree of a Vertex
The degree of a vertex v in a graph G, written deg (v), is equal to the number ofedges in G which
contain v, that is, which are incident on v.

Bipartite Graphs
DEFINITION: A simple graph G is called bipartite if its vertex set V can be partitioned into two
disjoint sets V1 and V2 such that every edge in the graph connects a vertex in V1 and a vertex in V2.

• C6 is bipartite, as shown in Figure, because its vertex set can be partitioned into the two sets V1
and V2.
• V1 = {v1, v3, v5} and V2 = {v2, v4, v6}, and every edge of C6 connects a vertex in V1 and a vertex in
V2.

Complete Bipartite Graphs: The complete bipartite graphs K2,3, K3, 3, and are displayed in
Figure

K2, 3 K3, 3

New Graphs from Old


DEFINITION: A sub-graph of a graph G = (V, E) is a graph.
H = (W, F), where W ⊆ V and F ⊆ E. A sub-graph H of G is a proper sub-graph of Gif H = G.

DEFINITION: Let G = (V, E) be a simple graph.


The sub-graph induced by a subset W of the vertex set V is the graph (W, F), where the edge set F
contains an edge in E if and only if both endpoints of this edge are in W.
The graph G is a sub-graph of K5. If we add the edge connecting c and e to G, W ={a, b, c, e}.

A Sub-graph of K5

DEFINITION
The union of two simple graphs G1 = (V1, E1) G2 = (V2, E2) is the simple graph with vertex set V1 𝖴 V2
and edge set E1 𝖴 E2. The union of G1 and G2 is denoted by G1 𝖴 G2.

EXAMPLE: Find the union of the graphs G1 and G2.


Solution: The vertex set of the union G1 𝖴 G2 is the union of the two vertex sets
as: {a, b, c, d, e, f}.

59
FIGURE (a) The Simple Graphs G1 and G2; (b) Their Union G1 𝖴 G2.
Isomorphism of Graphs
The simple graphs G1 = (V1, E1) and G2 = (V2, E2) are isomorphic.
• If there exists a one-to-one and onto function f from V1 to V2 with theproperty that a, b
are adjacent in G1.
• If and only if f (a) and f (b) are adjacent in G2, for all a, b in V1. Such a function f is
called an isomorphism.
• Two simple graphs that are not isomorphic are called non-isomorphic.

Example: Show that the graphs G = (V, E) and H = (W, F), displayed in figure, areisomorphic.

Paths
A path is a sequence of edges that begins at a vertex of a graph and travels fromvertex to vertex
along edges of the graph.
• Let n be a nonnegative integer and G an undirected graph.
• A path of length n from u to v in G is a sequence of n edges e1,...,e n of G.
• The path is a circuit if it begins and ends at the same vertex, that is, if u = v, and has length
greater than zero.

Connectedness in Undirected Graphs


• An undirected graph is called connected if there is a path between every pair of distinct
vertices of the graph.
• An undirected graph that is not connected is called disconnected.

60
Connectedness in Directed Graphs
A directed graph is strongly connected if there is a path from a to b and from b to a whenever a
and b are vertices in the graph.
A directed graph is weakly connected if there is a path between every two vertices in the
underlying undirected graph.
FIGURE: The directed graphs G and H.
Figure: The Directed Graphs G and H

Paths and Isomorphism


A path in a multi-graph G consists of an alternating sequence of vertices and edges of the form v0,
e1, v1, e2, v2 ... e n−1, v n−1, e n, v n , where each edge e i contains the vertices v i−1 and vi (which appear
on the sides of e i in the sequence). The number n of edges is called the length of the path. The
path is said to be closed if v 0 = v n. Otherwise, we say the path is from v 0, to v n or between v 0 and v
n, or connects v0 to v n.

Isomorphic Graphs
Graphs G (V, E) and G (V ∗, E∗) are said to be isomorphic if there exists a one-to- one
correspondence f : V → V ∗ such that {u, v} is an edge of G if and only if {f (u), f (v)} is an edge of
G∗.
Figure: A and T are isomorphic graphs

Theorem: There is a path from a vertex u to a vertex v if and only if there exists asimple path from
u to v.
Connectivity, Connected Components

61
A graph G is connected if there is a path between any two of its vertices.

The graph in Figure (a) is connected, but the graph in Figure (b) is not connected since, for
example, there is no path between vertices D and E.
• The graph G in Fig. 8-8(b) has three connected components, the sub-graphs induced by the
vertex sets {A, C, D}, {E, F}, and {B}.
• The vertex B in Figure (b) is called an isolated vertex since B does not belong to any edge or,
in other words, deg (B) = 0. Therefore, as noted, B itself forms a connected component of
the graph.

Euler and Hamilton Paths


DEFINITION 1 An Euler circuit in a graph G is a simple circuit containing every edge of G. An
Euler path in G is a simple path containing every edge of G.
C

Figure: Multi-graph Model of the Town of Konigsberg


THEOREM 1: A connected multi-graph with at least two vertices has an Euler circuit if and only if
each of its vertices has even degree.
THEOREM 2: A connected multi-graph has an Euler path but not an Euler circuit if and only if it has
exactly two vertices of odd degree.

Figure: Two Undirected Graph

62
Hamilton Paths and Circuits
DEFINITION: A simple path in a graph G that passes through every vertex exactly once is called a
Hamilton path, and a simple circuit in a graph G that passes through every vertex exactly once is
called a Hamilton circuit.

That is, the simple path x0, x1...x n−1, x n in the graph G = (V, E) is a Hamilton path if V = {x0, x1,...,x
n−1, x n} and xi = x j for 0 ≤ i<j ≤ n, and the simple circuit x 0, x1,...,x n−1, x n, x0 (with n > 0) is a Hamilton
circuit if x0, x1,...,x n−1, x n is a Hamilton path.
AB

Labeled and Weighted graphs


A graph G is called a labeled graph if its edges and/or vertices are assigned data of one kind or
another. In particular, G is called a weighted graph if each edge e of G is assigned a non negative
number w (e) called the weight or length of v.

The weight (or length) of a path in such a weighted graph G is defined to be the sum of the weights
of the edges in the path. One important problem in graph theory is to find a shortest path, that
is, a path of minimum weight (length),

between any two given vertices. The length of a shortest path between P and Q in figure is 14; one
such path is (P, A1, A2, A5, A3, A6, Q)

Complete, Regular, and Bipartite graphs


There are many different types of graphs. This section considers three of them: complete, regular,
and bipartite graphs.
63
Complete Graphs
A graph G is said to be complete if every vertex in G is connected to every other vertex in G. Thus a
complete graph G must be connected. The complete graph with n vertices is denoted by Kn. Figure
shows the graphs K1 through K4.

Regular Graphs
A graph G is regular of degree k or k-regular if every vertex has degree k. In other words, a graph is
regular if every vertex has the same degree.

Bipartite Graphs
A graph G is said to be bipartite if its vertices V can be partitioned into two subsets M and N such
that each edge of G connects a vertex of M to a vertex of N.

By a complete bipartite graph, we mean that each vertex of M is connected to each vertex of N; this
graph is denoted by K m, n where m is the number of vertices in M and n is the number of vertices in
N, and, for standardization, we will assume m ≤ n.

Figure shows the graphs K2, 3,


K3, 3, and K2, 4, clearly the graph K m, n has m n edges.

Tree Graphs
• A graph T is called a tree if T is connected and T has no cycles. Examples of trees are
shown in Figure.
• A forest G is a graph with no cycles; hence the connected components of a forest G are
trees.
• A graph without cycles is said to be cycle-free. The tree consisting of a single vertex
64
with no edges is called the degenerate tree.

Theorem: Let G be a graph with n > 1 vertices. Then the following are equivalent:
(i) G is a tree.
(ii) G is a cycle-free and has n − 1 edges.
(iii) G is connected and has n − 1 edges.

This theorem also tells us that a finite tree T with n vertices must have n − 1 edges. For
example, the tree in
Fig. 8-17(a) has 9 vertices and 8 edges, and the tree in Figure has 13 vertices and12 edges.

Spanning Tree
A subgraph T of a connected graph G is called spanning tree of G if T is a tree and T include all
vertices of G.

Minimum Spanning Tree:


Suppose G is a connected weight graph i.e., each edge of G is assigned a non- negative number
called the weight of edge, then any spanning tree T of G is assigned a total weight obtained by
adding the weight of the edge in T.
A minimum spanning tree of G is a tree whose total weight is as small as possible.

Kruskal's Algorithm to find a minimum spanning tree: This algorithm finds the minimum spanning
tree T of the given connected weighted graph G.
1. Input the given connected weighted graph G with n vertices whoseminimum spanning tree T, we
want to find.
2. Order all the edges of the graph G according to increasing weights.
3. Initialize T with all vertices but do include an edge.
4. Add each of the graphs G in T which does not form a cycle until n-1 edgesare added.

Example1: Determine the minimum spanning tree of the weighted graph shownin fig:

65
Solution: Using kruskal's algorithm arrange all the edges of the weighted graph in increasing order
and initialize spanning tree T with all the six vertices of G. Now start adding the edges of G in T
which do not form a cycle and having minimum weights until five edges are not added as there are
six vertices.
Edges Weights Added or Not
(B, E) 2 Added
(C, D) 3 Added
(A, D) 4 Added
(C, F) 4 Added
(B, C) 5 Added
(E, F) 5 Not added
(A, B) 6 Not added
(D, E) 6 Not added
(A, F) 7 Not added

Step1:

Step2:

66
Step3:

Step4:

Step5:

Step6: Edge (A, B), (D, E) and (E, F) are discarded because they will form the cyclein a graph.
So, the minimum spanning tree form in step 5 is output, and the total cost is 18.

67
Example2: Find all the spanning tree of graph G and find which is the minimal spanning tree of G
shown in fig:

Solution: There are total three spanning trees of the graph G which are shown infig:

68
To find the minimum spanning tree, use the KRUSKAL’S ALGORITHM. The minimalspanning tree is
shown in fig:
Edges Weights Added or Not
(E, F) 1 Added
(A, B) 2 Added
(C, D) 2 Added
(B, C) 3 Added
(D, E) 3 Added
(B, D) 6 Not Added

The first one is the minimum spanning having the minimum weight = 11.

Planner Graphs
A graph or multi-graph which can be drawn in the plane so that its edges do not cross is said to
be planar.

69
A

The complete graph with four vertices K4 is usually pictured with crossing edgesas in Figure A, it
can also be drawn with non-crossing edges as in Figure B; hence K4 is planar. Tree graphs form an
important class of planar graphs.

Maps, Regions
A particular planar representation of a finite planar multi-graph is called a map. The map is
connected if the underlying multi-graph is connected. A given map divides the plane into various
regions.
Non-planar Graphs, Kuratowski’s Theorem
1. Consider first the utility graph; that is, three houses A1, A 2 and A3 are to be connected to outlets
for water, gas and electricity, B1, B2 and B3, as in Figure.
2. Observe that this is the graph K3, 3 and it has p = 6 vertices and q = 9 edges.

• Suppose the graph is planar. By Euler’s formula a planar representation has r = 5 regions.
Observe that no three vertices are connected to each other; hence the degree of each region
must be 4 or more and so the sum of the degrees of the regions must be 20 or more.
• Consider next the star graph in Figure. This is the complete graph K5 on p = 5 vertices and has q
= 10 edges.10 = q ≤ 3p − 6 = 15 − 6 = 9 which is impossible. Thus K5 is non-planar.

Graph Coloring
A coloring of a simple graph is the assignment of a color to each vertex of the graph so that no two
adjacent vertices are assigned the same color.

70
FIGURE 2 Dual Graphs of the Maps in Figure 1
DEFINITION: The chromatic number of a graph is the least number of colors needed for a coloring
of this graph. The chromatic number of a graph G is denoted by χ (G).

THEOREM 1 THE FOUR COLOR THEOREM The chromatic number of a planar graph is no greater
than four.

Rooted trees
• A rooted tree T is a tree graph with a designated vertex r called the root of the tree.
• Consider a rooted tree T with root r. The length of the path from the root r to any vertex v is
called the level (or depth) of v, and the maximum vertex level is called the depth of the tree.
• Those vertices with degree 1, other than the root r, are called the leaves of T, and a directed
path from a vertex to a leaf is called a branch.
• The tree has five leaves, d, f, h, i, and j. Observe that: level (a) = 1, level (f) = 2, level (j) =
3. Furthermore, the depth of the tree is 3.

• The fact that a rooted tree T gives a direction to the edges means that we can give a
precedence relationship between the vertices.
• Specifically, we will say that a vertex u precedes a vertex v or that v follows u if there is a
(directed) path from v to u.
• In particular, we say that v immediately follows u if (u, v) is an edge, that is,if v follows u and
v is adjacent to u.

EXAMPLE
Suppose Marc and Erik are playing a tennis tournament such that the first person to win two
games in a row or who wins a total of three games wins the tournament. Find the number of ways

71
the tournament can proceed.

Solution: The rooted tree in Figure (b) shows the various ways that the tournament could proceed.
There are 10 leaves which correspond to the 10 ways that the tournament can occur:
MM, MEMM, MEMEM, MEMEE, MEE, EMM, EMEMM, EMEME, EMEE, EE
Specifically, the path from the root to the leaf describes who won which games in the particular
tournament.

Ordered Rooted Trees


Consider a rooted tree T in which the edges leaving each vertex are ordered. Then we have the
concept of an ordered rooted tree.
Boolean algebra Boolean Functions
Boolean algebra provides the operations and the rules for working with the set {0,
1}.The complement of an element, denoted with a bar, is defined by bar 0 = 1andbar 1 = 0.
The Boolean sum, denoted by + or by OR, has the following values:1+ 1 = 1, 1 + 0 = 1, 0 + 1 = 1, 0 +
0=0
The Boolean product, denoted by · or by AND, has the following values:1· 1 = 1, 1 · 0 = 0, 0 · 1 = 0, 0 ·
0=0

EXAMPLE 1 Find the value of 1 · 0 + (0 + 1).


Solution: 1 · 0 + (0 + 1) = 0 + 1 = 0 + 0 = 0.
EXAMPLE 2 Translate 1 · 0 + (0 + 1) = 0, the equality into a logical equivalence.

Solution:
• Translate each 1 into a T, 0 into an F,
• Boolean sum into a disjunction, each Boolean product into a conjunction, and each
complementation into a negation.
(T 𝖠 F) ∨ ¬ (T ∨ F) ≡ F

Boolean Expressions and Boolean Functions


• Let B = {0, 1}. Then B n = {(x1, x2... x n) | xi ∈ B for 1 ≤ i ≤ n} is the set of all possible n-
tuples of 0s and 1s.
• The variable x is called a Boolean variable if it assumes values only from B, that is, if its
only possible values are 0 and 1.
• A function from B n to B is called a Boolean function of degree n.
EXAMPLE: The function F (x, y) = x y from the set of ordered pairs of Booleanvariables to the
set {0, 1} is a Boolean function of degree 2 with F (1, 1) = 0, F (1,
0) = 1, F (0, 1) = 0, and F (0, 0) = 0.

We display these values of F in Table.


x y F(x, y)
1 1 0
1 0 1
0 1 0
0 0 0

72
The Boolean expressions in the variables x1, x2...x n are defined recursively as 0, 1, x1, x 2...x n are
Boolean expressions;

If E1 and E2 are Boolean expressions, then E1, (E1E2), and (E1 + E2) are Booleanexpressions.

Identities of Boolean algebra


Law of the double complement: x`` = x
Idempotent laws: x + x = x, x · x = x Identity laws: x + 0 = x, x · 1 = x Domination laws: x + 1 = 1, x · 0
= 0 Commutative laws: x + y = y + x, x y = y x
Associative laws: x + (y + z) = (x + y) + z, x (y z) = (x y)z Distributive laws: x + y z = (x + y)(x + z), x(y
+ z) = x y + x zDe Morgan’s laws: (x y) = x + y, (x + y) = x y
Absorption laws: x + x y = x, x (x + y) = xUnit property: x + x = 1
Zero property x x = 0

EXAMPLE: Prove the absorption law x(x + y) = x using the other identities ofBoolean algebra.
Solution: x(x + y) = (x + 0) (x + y) Identity law for the Boolean sum
= x + 0 · y Distributive law
= x + y · 0 Commutative law
= x + 0 Domination law
= x Identity law

Duality
The dual of a Boolean expression is obtained by interchanging Boolean sums and Boolean
products and interchanging 0s and 1s.
EXAMPLE: Find the duals of x(y + 0) and x · 1 + (y + z).
Solution: Interchanging · signs and + signs and interchanging 0s and 1s. The duals are x + (y · 1)
and (x + 0) (y z), respectively.

The Abstract Definition of a Boolean Algebra


DEFINITION: A Boolean Algebra is a set B with two binary operations ∨ and 𝖠, elements 0 and 1,
and a unary operation such that these properties hold for all x, y, and z in B:
Identity laws: x ∨ 0 = x, x 𝖠 1 = x Complement laws: x ∨ x = 1, x 𝖠 x = 0
Associative laws: (x ∨ y) ∨ z = x ∨ (y ∨ z), (x 𝖠 y) 𝖠 z = x 𝖠 (y 𝖠 z)Commutative laws: x ∨ y = y ∨ x, x 𝖠
y=y𝖠x
Distributive laws: x ∨ (y 𝖠 z) = (x ∨ y) 𝖠 (x ∨ z), x 𝖠 (y ∨ z) = (x 𝖠 y) ∨ (x 𝖠 z)

Sum-of-Products Expansions
EXAMPLE: Find Boolean expressions that represent the functions F (x, y, z ) and G(x, y, z).
x y z F G

73
1 1 1 0 0
1 1 0 0 1
1 0 1 1 0
1 0 0 0 0
0 1 1 0 0
0 1 0 0 1
0 0 1 0 0
0 0 0 0 0

Solution: An expression that has the value 1 when x = z = 1 and y = 0, and the value 0 otherwise, is
needed to represent F.
To represent G, we need an expression that equals 1 when x = y = 1 and z = 0, or x
= z = 0 and y = 1.

DEFINITION: A literal is a Boolean variable or its complement.


A Min-term of the Boolean variables x1, x2,..., x n is a Boolean product y1y2 ··· y n, where y i = xi or y i =
x i. Hence, a min-term is a product of n literals, with one literal for each variable.
EXAMPLE: Find a min-term that equals 1 if x1 = x3 = 0 and x2 = x4 = x5 = 1, and equals 0 otherwise.
Solution: The midterm x1x2x3x4x5 has the correct set of values.

Functional Completeness
• Each min-term is the Boolean product of Boolean variables or their complements.
• Shows that every Boolean function can be represented using the Boolean operators ·, +, and
−. Because every Boolean function can be represented using these operators we say that
the set {·, +, −} is functionally complete.
We can eliminate all Boolean sums using the identity x + y = x y.

Optimization
Linear Programming
• Problems which seek to maximize (or, minimize) profit (or, cost) form ageneral class of
problems called optimization problems.
• A special but a very important class of optimization is linear programmingproblem.
A linear programming (LP) problem is an optimization problem that can bewritten

Maximize: c x
Subject to: Ax ≤ b
Where A is a given q × n matrix, c is a given row vector of length n, and b is a givencolumn vector of
length q.

Linear programming problem


A linear programming problem is one that is concerned with finding the optimal value (maximum
or minimum) of a linear function of several variables (called objective function) subject to the
conditions that:
1. The variables are non-negative and satisfy a set of linear inequalities (called linear constraints).
2. Variables are sometimes called decision variables and are non-negative.

74
Objective function: Linear function Z = ax+ by, where a, b are constants, which has to be
maximized or minimized is called a linear objective function.
Constraints: The linear inequalities or equations or restrictions on the variables of a linear
programming problem are called constraints.

Optimization problem: A problem which seeks to maximize or minimize a linear function subject to
certain constraints as determined by a set of linear inequalitiesis called an Optimization problem.
The common region determined by all the constraints including the non-negative constraints x ≥ 0,
y ≥ 0 of a linear programming problem is called feasible region (or solution region) for the
problem.
1. Points within and on the boundary of the feasible region represent feasible solutions of the
constraints.
2. Any point outside the feasible region is an infeasible [Link] Solution
Any point in the feasible region that gives the optimal value (maximum or minimum) of the
objective function is called an optimal solution.

Theorem 1 Let R be the feasible region (Convex Polygon) for a linear programming problem and
let Z = ax+ by be the Objective function. When Z has an optimal value (maximum or minimum),
where the variables x and y are subject to constraints described by linear inequalities, this optimal
value must occur at a corner point (vertex) of the feasible region.

Theorem 2 Let R be the feasible region for a linear programming problem and letZ = ax+ by be the
Objective function. If R is bounded, then the objective function Z has both a maximum and a
minimum value on R and each of these occurs at a corner point (vertex) of R. A corner point of a
feasible region is a point in the region which is the intersection of two boundary lines.

X ≥ 0 ConstraintsY ≥ 0

Bounded and Unbounded


A feasible region of a system of linear inequalities is said to be bounded.
• If it can be enclosed within a circle. Otherwise, it is called unbounded.
• Unbounded means that the feasible region does not extend indefinitely inany direction.

Corner Point Method (Steps)


1. Find the feasible region of the linear programming problem and determine its corner point
either by inspection or by solving the two equations of the lines intersecting at that point.
2. Evaluate the objective function Z = ax+ by at each corner point. Let M and m, respectively
denote the largest and smallest values of these points.
3. When the feasible region is bounded, M and m are the maximum and minimum value of Z.
4. In case feasible region is unbounded, we have:
(a) M is the maximum value of Z, if the open half plane determined by ax + by > M has no point in
common with the feasible region. Otherwise, Z has no maximum value.
(b) Similarly, m is the minimum value of Z, if the open half plane determined by ax + by > M has no
75
point in common with the feasible region. Otherwise, Z has no minimum value.

Corner Point Solution


The optimal solution to LPP, if it exists, occurs at the corners of the feasibleregion.
The method includes the following steps:
• Step 1: Find the feasible region of the LPP.
• Step 2: Find the co-ordinates of each vertex of the feasible region. These co-ordinates can be
obtained from the graph or by solving the equation of the line s.
• Step 3: At each vertex (corner point) compute the value of the objective function.
• Step 4: Identify the corner point at which the value of the objective function maximum (or
minimum depending on the LP).
• The co-ordinates of this vertex are the optimal solution and the value of Z isthe optimal value.

Different types of linear programmingExample: Maximize y


-x + y ≤ 1 3x +2y ≤ 12
2x +3y ≤ 12x, y ≥ 0
• The feasible integer points are shown in red, and the red dashed lines indicate their convex hull,
which is the smallest convex polyhedron that contains all of these points.
• The blue lines together with the coordinate axes define the polyhedron of the LP relaxation,
which is given by the inequalities without theintegrality constraint.
• The goal of the optimization is to move the black dotted line as far upward while still touching
the polyhedron. The optimal solutions of the integer problem are the points and which both
have an objective value of 2.
• The unique optimum of the relaxation is with objective value of 2.8. If the solution of the
relaxation is rounded to the nearest integers, it is notfeasible for the ILP.

LINEAR PROGRAMMING – SIMPLEX METHOD


• If the linear programming problem has larger number of variables, the suitable method for
solving is Simplex Method.
The Simplex method also helps the decision maker/manager to identify thefollowing:
➢ Redundant Constraints
➢ Multiple Solutions
76
➢ Unbounded Solution
➢ Infeasible Problem

Basics of Simplex Method


The basic of simplex method is explained with the following linear programmingproblem.
Example:
Maximize
60x1 + 70x2
Subject to:
2x1 + x2 ≤ 300
3x1 + 4x2 ≤ 509
4x1 + 7x2 ≤ 812
x1, x2 ≥ 0
Solution: First we introduce the variables s3, s4, s5 ≥ 0 So that the constraints becomes equations,
thus
2x1 + x2 + s3 = 300
3x1 + 4x2 + s4 = 509
4x1 + 7x2 +s5 = 812
Corresponding to the three constraints, the variables s3, s4, s5 are called as slack variables.
There are two types of solutions they are basic and basic feasible, which are discussed as
follows:

Basic Solution
• We may equate any two variables to zero in the above system of equations, and then the
system will have three variables.
• Thus, if this system of three equations with three variables is solvable such a solution is
called as basic solution.
• The variables s3, s4, and s5 are known as basic variables where as the variables x1,
x2 are known as non-basic variables.

Basic Feasible Solution


• A basic solution of a linear programming problem is called as basic feasiblesolutions if it is
feasible it means all the variables are non-negative.
• The solution s3=300, s4=509 and s5=812 is a basic feasible solution.

Simplex Method Computation


Consider the following linear programming problemMaximize
60x1 + 70x2
Subject to:
2x1 + x2 + s3 = 300
3x1 + 9x2 + s4 = 509
4x1 + 7x2 +s5 = 812
x1, x2, s3, s4, s5 ≥ 0
The profit Z = 60x1 + 70x2 i.e. Maximize 60x1 + 70x2
The standard form can be summarized in a compact table form as

CB Basic CJ 60 70 0 0 0

77
Variables XB x1 x2 s3 s4 s5
0 s3 300 2 1 1 0 0
0 s4 509 3 4 0 1 0
0 s5 812 4 7 0 0 1

Z -60 -70 0 0 0 0

Consider the first equation 2x1 + x2 + s3 = 3002x1 + s3 = 300 – x2 (x1 = 0, s3 ≥ 0)


300 - x2 ≥ 0 i.e. x2 ≤ 300
Second equation: 3x1 + 9x2 + s4 = 5093x1 + s4 = 509 - 4x2 (x1 = 0, s4 ≥ 0)
509 – 9x2 ≥ 0
So, x 2 ≥ 509/9
Third equation: 4x1 + 7x2 +s5 = 8124x1 + s5 = 812 - 7x2 (x1 = 0, s5 ≥ 0)
812 - 7x2 ≥ 0
So, x2 ≥ 812/7
Therefore the three equations: x2 ≤ 300, x 2 ≥ 509/9, x2 ≥ 812/7Thus x2=Min (x2 ≤ 300, x 2 ≥ 509/9, x2 ≥
812/7)
So, x2=Min (x2 ≤ 300/1, x 2 ≥ 509/9, x2 ≥ 812/7) = 116
Therefore x2 = 116, if x2=116, you may be note from the third equation7x2 +s5 = 812 i.e. s5=0 So, x2 =
812/7 = 116
Thus, the variable s5 becomes non-basic in the next [Link] other two basic variables are
S3=300 - x2 = 184 S4=509 - 4*116 = 45

Using the following rules the Table 2 is computed from the Table 1.
(i) The revised basic variables are s3, s4 and x2. Accordingly, we make CB1=0, CB2=0 and CB3=70.
(ii) As x2 is the incoming basic variable we make the coefficient of x2 one by dividing each element
of row-3 by 7. Thus the numerical value of the element corresponding to x1 is 4/7,
corresponding to s5 is 1/7 in Table 2.
(iii) The incoming basic variable should appear only in the third row. So we multiply the third-row of
Table 2 by 1 and subtract it from the first-row of Table 1 element by element. Thus the element
corresponding to x2 in the first-row of Table 2 is 0.
Therefore the element corresponding to x1 is 2-1*4/7=10/7 and the element corresponding to s5
is 0-1*1/7=-1/7
In this way we obtain the elements of the first and the second row in Table 2. In Table 2 the
numerical values can also be calculated in a similar way.

CB Basic CJ 60 70 0 0 0
Variables XB x1 x2 s3 s4 s5
0 s3 184 10/7 1 1 0 -1/7
0 s4 45 5/7 4 0 1 -4/7
0 s5 116 4/7 7 0 0 1/7

Zj–Cj -140/7 0 0 0 70/7

z1 - c1 = 10/7*0 + 5/7*0 + 70*4/7 - 60 = -140/7z5 – c5 = -1/7*0 - 4/7*0 + 1/7*70 - 0 = 70/7


78
(i) Now we apply rule (1) to Table 2. Here the only negative zj-c j is z1-c1 = -140/7
Hence x1 should become a basic variable at the next iteration.
(ii) This minimum occurs corresponding to s4, it becomes a non basic variablein next iteration.

CB Basic Cj 60 70 0 0 0
Variables XB x1 x2 s3 s4 s5
0 s3 94 10/7 1 1 -2 1
0 s4 63 5/7 4 0 7/5 -4/5
0 s5 80 4/7 7 0 -4/5 3/5

Zj–Cj 0 0 0 28 -6

1. Now we apply rule (1) to Table 2. Here the only negative Z j-C j is z1-c1 = -140/7
2. We compute the minimum of the ratio
Min (180/10/7, 45/5/7, 116/4/7) = Min (644/5, 63, 203) = 63
This minimum occurs corresponding to s4; it becomes a non basic variablein next iteration.
1. z 5 – c5 < 0 should be made a basic variable in the next iteration.
2. Now compute the minimum ratiosMin (94/1, 80/3/5) = 94
Since y25 = -4/5 < 0, the corresponding ratio is not taken for comparison. The variable s3 becomes
non basic in the next iteration.

CB Basic CJ 60 70 0 0 0
Variables XB x1 x2 s3 s4 s5
0 s3 94 10/7 1 1 2 1
0 s4 691/5 5/7 4 4/5 -1/5 0
0 s5 118/5 4/7 7 -3/5 2/5 0

Zj–Cj 0 0 6 16 0

Thus, the objective function is maximized for x1 = 691/5 and x2=118/5 and themaximum value
of the objective function is 9944.

Key Terms
Basic Variable: Variable of a basic feasible solution has n non-negative value.
Non Basic Variable: Variable of a feasible solution has a value equal to zero.
Artificial Variable: A non-negative variable introduced to provide basic feasible solution and
initiate the simplex procedures.
Slack Variable: A variable corresponding to a ≤ type constraint is a non-negative variable
introduced to convert the inequalities into equations.
Surplus Variable: A variable corresponding to a ≥ type constraint is a non- negative variable
introduced to convert the constraint into equations.
Basic Solution: System of m-equation and n-variables i.e. m<n is a solution where at least n-m
variables are zero.
Basic Feasible Solution: System of m-equation and n-variables i.e. m<n is a solution where m
variables are non-negative and n-m variables are zero.
79
Optimum Solution: A solution where the objective function is minimized ormaximized.

DUAL LINEAR PROGRAMMING PROBLEMS


For every linear programming problem there is a corresponding linear programming problem called
the dual.
Dual Problem Formulation
If the original problem is in the standard form then the dual problem can beformulated using
the following rules:
• The number of constraints in the original problem is equal to the number of dual variables. The
number of constraints in the dual problem is equal to the number of variables in the original
problem.
• The original problem profit coefficients appear on the right hand side of the dual problem
constraints.
• If the original problem is a maximization problem then the dual problem is a minimization
problem. Similarly, if the original problem is a minimization problem then the dual problem is a
maximization problem.
• The original problem has less than or equal to (≤) type of constraints while the dual problem
has greater than or equal to (≥) type constraints.
• The coefficients of the constraints of the original problem which appear from left to right are
placed from top to bottom in the constraints of the dual problem and vice versa.

Simple Way of Solving Dual Problem


Minimize: P = x1 + 2x2Subject to: x1 + x2 ≥ 8
2x1 + x2 ≥12X1 ≥1
Solution: Step 1: Set up the P-matrix and its transpose

Step 2: Form the objective function and constraints for the dual w1 + 2w 2 + w 1 ≤ 1
w1 + w 2 + w 1 ≤ 2 Z = 8w1 = 12w 2 +2
Step 3: Construct the initial simplex tableau for the dual
w1 W2 W3 S1 S2 g z
1 2 1 1 0 0 1
1 1 0 0 1 0 2
-8 -12 -1 0 0 1 0

The most negative number in the bottom row to the left of the last column is -12. This establishes
the pivot column. The smallest non- negative ratio is ½.

80
Step 4: Pivoting
Pivoting about the 2 we get:
w1 W2 W3 S1 S2 g z
1 2 1 1 0 0 1
1/2 0 -1/25 -1/26 1 0 3/2
-2 0 0 1 6

w1 W2 W3 S1 S2 g z
1/2 1 1/2 1/2 0 0 1/2
1 1 0 0 1 0 2
-8 -12 -1 0 0 1 0

The most negative entry in the bottom row to the left of the last column is -2Pivoting about the 1/ 2

w1 W2 W3 S1 S2 g z
1/2 1 1/2 1/2 0 0 1/2
1/2 0 -1/25 -1/26 1 0 3/2
-2 0 0 1 6

Therefore, the optimum solution providing by x1 = 8 and x2 = 0


w1 W2 W3 S1 S2 g z
1 2 1 1 0 0 1
0 -1 -1 -1 1 0 1
0 4 7 8 0 1 8

Therefore, the optimum solution providing by x1 = 8 and x2 = [Link] minimum valueis 8.

81
MCQs
1. Which of the following statement is a proposition?
a) Get me a glass of milkshake.
b) God bless you!
c) What is the time now?
d) The only odd prime numberis 2
Answer: d

Explanation: Only this statement has got the truthvalue which is false.
2. The truth value of ‘4+3=7 or 5 isnot prime’.
a) False
b) True
Answer: b
Explanation: Compound statement with ‘or’ is true
when either of the statement is true. Here the first part of the statement is true, hence the whole is
true.

3. Which of the following option istrue?


a) If the Sun is a planet,elephants will fly
b) 3 +2 = 8 if 5-2 = 7
c) 1 > 3 and 3 is a positiveinteger
d) -2 > 3 or 3 is a negativeinteger
Answer: a
Explanation: Hypothesis isfalse, thus the whole statement is true.

4. What is the value of x after thisstatement, assuming the initialvalue of x are 5?


‘If x equals to one then x=x+2else x=0’.
a) 1
b) 3
c) 0
d) 2
Answer: c
Explanation: If condition is false so value decided according to else condition.

5. Let P: I am in Bangalore; Q: Ilove cricket; then q -> p(q implies p) is?


a) If I love cricket then I am inBangalore
b) If I am in Bangalore then Ilove cricket
c) I am not in Bangalore
d) I love cricket
Answer: a
Explanation: Q is hypothesis and P is conclusion. So the compound statement will be if hypothesis
then conclusion.

6. Which of the following bits is thenegation of the bits “010110”?

82
a) 111001
b) 001001
c) 101001
d) 111111
Answer: c
Explanation: Flip each of the bits to get the negationof the required string.

7. Which of the following option is suitable, if A is “10110110”, B is”11100000” and C


is”10100000”?
a) C=A or B
b) C=~A
c) C=~B
d) C=A and B
Answer: d
Explanation: Output of and is1 when both other inputs are one.

8. How many bits string of length 4are possible such that they contain 2 ones and 2 zeroes?
a) 4
b) 2
c) 5
d) 6
Answer: d
Explanation: The strings are {0011, 0110, 1001, 1100, 1010 and 0101}.

9. If a bit string contains {0, 1} only, having length 5 has no more than 2 ones in it. Then how many
such bit strings are possible?
a) 14
b) 12
c) 15
d) 16
Answer: d
Explanation: The total stringsare 1(having no one in it)
+5(having 1 one in it) +10(having 2 ones in it) = 16.

10. If A is “001100” and B is “010101” then what is the valueof A (Ex-or) B?


a) 000000
b) 111111
c) 001101
d) 011001
Answer: d
Explanation: In Ex-or if boththe inputs are same then output is 0 otherwise 1.

11. Let P and Q be statements, thenP<->Q is logically equivalent to


a) P<->~Q
b) ~P<->Q
c) ~P<->~Q
83
d) None of the mentioned
Answer: c
Explanation: Both of them have same truth table, hencethey are equal.

12. What is the negation of thestatement A-> (B v (or) C)?


a) A 𝖠 ~B 𝖠 ~C
b) A->B->C
c) ~A 𝖠 B v C
d) None of the mentioned
Answer: a
Explanation: A->P is logicallyequivalent to ~ A v P.

13. The compound statement A->(A->B) is false, then the truth values of A, B are respectively
a) T, T
b) F, T
c) T, F
d) F, F
Answer: c
Explanation: For implications to be false hypothesis should be true and conclusion shouldbe false

14. The statement which is logicallyequivalent to A𝖠 (and) B is?


a) A->B
b) ~A 𝖠 ~ B
c) A 𝖠 ~B
d) ~(A->~B)
Answer: d
Explanation: The truth table ofboth statements is same.

15. Let P, Q, R be true, false true,respectively, which of the following is true?


a) P𝖠Q𝖠R
b) P𝖠~Q𝖠~R
c) Q->(P𝖠R)
d) P->(Q𝖠R)
Answer: c
Explanation: Hypothesis is false, hence statement is true.

16. If there are ‘M’ switches in


series numbered from 1, 2, …,
M. For circuit to be complete and bulb to glow which of thefollowing is necessary?
a) 1𝖠 2𝖠 3 𝖠 … 𝖠M should beon.
b) 1𝖠 2𝖠 3 𝖠 … 𝖠M should beoff.
c) 1 v 2 v 3 v … v M should beon.
d) None of the mentioned.
Answer: a
Explanation: All should be onin-order to complete the circuit.

84
17. Which of the following statements is the negation of the statements “4 is odd or -9 ispositive”?
a) 4 is even or -9 is not negative.
b) 4 is odd or -9 is not negative.
c) 4 is even and -9 is negative.
d) 4 is odd and -9 is notnegative.
Answer: c
Explanation: Using De Morgan’s Law ~ (A V B) ↔ ~A
𝖠 ~B
.
18. Which of the following represents: ~A (negation of A) if A stands for “I like badminton but hate
math’s”?
a) I hate badminton and math’s
b) I do not like badminton ormath’s
c) I dislike badminton but lovemath’s
d) I hate badminton or likemath’s
Answer: d
Explanation: De Morgan’s Law
~ (A 𝖠 B) ↔ ~A V ~B.

19. The compound statement A v


~(A 𝖠 B).
a) True
b) False
Answer: a
Explanation: Applying De- Morgan’s law we get A v ~ A ΞTautology.

20. Which of the following is De-Morgan’s law?


a) P 𝖠 (Q v R) Ξ (P 𝖠 Q) v (P 𝖠 R)
b) ~(P 𝖠 R) Ξ ~P v ~R, ~(P v R) Ξ
~P 𝖠 ~R
c) P v ~P Ξ True, P 𝖠 ~P Ξ False
d) None of the mentioned
Answer: b
Explanation: Definition of De–Morgan’s Law.

21. A compound proposition that isalways is called a tautology.


a) True
b) False
Answer: a
Explanation: Tautology isalways true.

22. If A is any statement, thenwhich of the following is atautology?


a) A 𝖠 F
b) A ∨ F
c) A ∨ ¬A
85
d) A 𝖠 T
Answer: c
Explanation: A ∨ ¬A is alwaystrue.

23. A compound proposition thatis neither a tautology nor a contradiction is called a


a) Contingency
b) Equivalence
c) Condition
d) Inference
Answer: a
Explanation: Definition ofcontingency.

24. ¬ (A ∨ q) 𝖠 (A 𝖠 q) is a
a) Tautology
b) Contradiction
c) Contingency
d) None of the mentioned
Answer: b
Explanation: ≡ (¬A 𝖠 ¬q) 𝖠 (A 𝖠
q)
≡ (¬A 𝖠 A) 𝖠 (¬q 𝖠 q)
≡ F 𝖠 F ≡ F.

25. The contra positive of p → qis the proposition of


a) ¬p → ¬q
b) ¬q → ¬p
c) q → p
d) ¬q → p
Answer: b
Explanation: Definition ofcontra positive.

26. The inverse of p → q is the proposition of


a) ¬p → ¬q
b) ¬q → ¬p
c) q → p
d) ¬q → p
Answer: a
Explanation: Definition ofinverse.

27. The converse of p → q is the proposition of


a) ¬p → ¬q
b) ¬q → ¬p
c) q → p
d) ¬q → p
Answer: c
Explanation: Definition ofconverse.
86
28. What is the contra positive of the conditional statement? “Thehome team misses whenever it is
drizzling?”
a) If it is drizzling, then hometeam misses
b) If the home team misses, thenit is drizzling
c) If it is not drizzling, then thehome team does not misses
d) If the home team wins, then itis not drizzling
Answer: d
Explanation: q whenever pcontra positive is ¬q → ¬p.

29. What is the converse of the conditional statement “If it ices today, I will play ice hockey
tomorrow.”
a) “I will play ice hockey tomorrow only if it ices today.”
b) “If I do not play ice hockey tomorrow, then it will not haveiced today.”
c) “If it does not ice today, then Iwill not play ice hockey tomorrow.”
d) “I will not play ice hockey tomorrow only if it ices today.”
Answer: a
Explanation: If p, then q hasconverse q → p.

30. What are the converse of the 32. p → q is logically equivalent to conditional statement “When
Raj stay up late, it is necessarythat Raj sleep until noon.”
a) “If Raj stay up late, then Rajsleep until noon.”
b) “If Raj does not stay up late,then Raj does not sleep until noon.”
c) “If Raj does not sleep until noon, then Raj does not stay uplate.”
d) “If Raj sleep until noon, thenRaj stay up late.”
Answer: d
Explanation: Necessarycondition for p is q has converse q → p.

31. The compound propositions pand q are called logically equivalent if is a tautology.
a) p ↔ q
b) p → q
c) ¬ (p ∨ q)
d) ¬p ∨ ¬q
Answer: a
Explanation: Definition oflogical equivalence.

32. p → q is logically equivalent to


a) ¬p ∨ ¬q
b) p ∨ ¬q
c) ¬p ∨ q
d) ¬p 𝖠 q
Answer: c
Explanation: (p → q) ↔ (¬p ∨ q) is tautology.

33. Let P (x) denote the statement “x >7.” Which of these have truth value true?
87
a) P (0)
b) P (4)
c) P (6)
d) P (9)
Answer: d
Explanation: Put x=9, 9>7which is true.

34. Let Q(x, y) denote “M + A = 0.” What is the truth value of the quantifications ∃A∀M Q (M, A).
a) True
b) False
Answer: b
Explanation: For each A there exist only one M, because there is no real number A such that M + A
= 0 for all realnumbers M.

35. Which rule of inference is used in each of these arguments, “If it is Wednesday, then the Smart-
mart will be crowded. It is Wednesday. Thus, the Smart- mart is crowded.”
a) Modus Tollens
b) Modus ponens
c) Disjunctive syllogism
d) Simplification
Answer: b
Explanation: (M 𝖠 (M → N)) →N is Modus ponens.

36. Let the statement be “If n is not an odd integer then square of n is not odd.”, then if P(n) is “n is
an not an odd integer” and Q(n)is “(square of n) is not odd.” Fordirect proof we should prove
a) ∀ n P ((n) → Q(n))
b) ∃ n P ((n) → Q(n))
c) ∀n~(P ((n)) → Q(n))
d) ∀ n P ((n) → ~(Q(n)))
Answer: a
Explanation: Definition ofdirect proof.

37. {x: x is an integer neither positivenor negative} is


a) Empty set
b) Non-empty set
c) Finite set
d) Non- empty and Finite set
Answer: d
Explanation: Set = {0} non-empty and finite set.

38. A is an orderedcollection of objects.


a) Relation
b) Function
c) Set
d) Proposition
Answer: c
88
Explanation: By the definitionof set.

39. The union of the sets {1, 2, 5}


and {1, 2, 6} is the set
a) {1, 2, 6, 1}
b) {1, 2, 5, 6}
c) {1, 2, 1, 2}
d) {1, 5, 6, 3}
Answer: b
Explanation: The union of the sets A and B is the set that contains those elements that are either in
A or in B.

40. Let the set A is {1, 2, 3} and B is


{2, 3, 4}. Then the number ofelements in A U B is?
a) 4
b) 5
c) 6
d) 7
Answer: a
Explanation: AUB is {1, 2, 3, 4}.

41. In which of the following sets A –B is equal to B – A?


a) A = {1, 2, 3}, B = {2, 3, 4}
b) A = {1, 2, 3}, B = {1, 2, 3, 4}
c) A = {1, 2, 3}, B = {2, 3, 1}
d) A = {1, 2, 3, 4, 5, 6}, B = {2, 3,
4, 5, 1}
Answer: c
Explanation: A- B= B-A = Emptyset.

42. If A has 4 elements B has 8 elements then the minimum andmaximum number of elements in A
U B are
a) 4, 8
b) 8, 12
c) 4, 12
d) None of the mentioned
Answer: b
Explanation: Minimum wouldbe when 4 elements are sameas in 8, maximum would be when all are
distinct.

43. The shaded area of figure is bestdescribed by?

89
a) A∩B
b) AUB
c) A
d) B
Answer: a
Explanation: The region is Aintersection B.

44. If n (A) = 20 and n (B) = 30 and n(A U B) = 40 then n(A ∩ B) is?


a) 20
b) 30
c) 40
d) 10
Answer: d
Explanation: n (A U B) = n (A) +n(B) – n(A ∩ B).

45. The relation between sets A, B, Cas shown by Venn diagram is


a) A is subset of B and B is subsetof C
b) C is not a subset of A and A issubset of B
c) C is subset of B and B is subsetof A
d) None of the mentioned
Answer: c
Explanation: As set C is totally

[Link] n (A) = 10, n (B) = 30, n (C) =50


and if set A, B, C are pair-wisedisjoint then which of the following is correct?
a) n(A U B)=0
b) n(B U C)=0
c) n(A U B U C)=90
d) All of the mentioned
Answer: d
Explanation: All the statementsare true based on definition.

47. Let C and D be two sets then C –D is equivalent to


a) C’ ∩ D
b) C‘∩ D’
c) C ∩ D’
d) None of the mentioned
Answer: c
90
Explanation: Set C-D will be having those elements whichare in C but not in D.

48. Let set A = {1, 2} and C be {3, 4} then A X B (Cartesian product ofset A and B) is?
a) {1, 2, 3, 4}
b) {(1, 3),(2, 4)}
c) {(1, 3), (2, 4), (1, 4), (2, 3)}
d) {(3, 1), (4, 1)}
Answer: c
Explanation: In set A X B: {(c, d)
|c ∈ A and d ∈ B}.

49. If set A has 4 elements and B has3 elements then set n(A X B) is?
a) 12
b) 14
c) 24
d) 7
Answer: a Explanation: The total
elements in n (A X B) = n (A) * n(B).

50. Which of the following statements regarding sets is


false?
a) A X B = B X A
b) A X B ≠ B X A
c) n (A X B) = n (A) * n (B)
d) All of the mentioned
Answer: a
Explanation: The Cartesianproduct of sets is not commutative.

51. If a set contains 3 elements thenthe number of subsets is?


a) 6
b) 3
c) 12
d) 8
Answer: d
Explanation: For elements withn elements the numbers of subsets are 2n.

52. The set containing all the collection of subsets is known as


a) Subset
b) Power set
c) Union set
d) None of the mentioned
Answer: b Explanation: Power set
contains all the subsets as itselements.

53. If a set is empty then number ofsubsets will be


a) 1
91
b) 2
c) 0
d) 4
Answer: a
Explanation: The set has zeroelements so 2o = 1.

54. What is the base case for the inequality 7n > n3, where n = 3?a) 652 > 189
b) 42 < 132
c) 343 > 27
d) 42 <= 431
Answer: c
Explanation: By the principle ofmathematical induction, we have 73 > 33 ⇒ 343 > 27 as a base case
and it is true for n = 3.

55. In the principle of mathematicalinduction, which of the followingsteps is mandatory?


a) induction hypothesis
b) inductive reference
c) induction set assumption
d) minimal set representation
Answer: a
Explanation: The hypothesis ofStep is a must for
mathematical induction that is the statement is true for n = k, where n and k are any natural
numbers, which is also called induction assumption or induction hypothesis.

[Link] m = 1, 2, …, 4m+2 is amultiple of


a) 3
b) 5
c) 6
d) 2
Answer: d
Explanation: For n = 1, 4 * 1 + 2
= 6, which is a multiple of 2. Assume that 4m+2 is true for m=k and so 4k+2 is true based on the
assumption. Now, to prove that 4k+2 is also a multiple of 2 ⇒ 4(k+1) + 2 ⇒ 2 * 4k – 4k + 6 ⇒
2*4k+4 – 4k+2 ⇒ 2(4k+2) – 2(2k+1). Here, the first term 2(4k+2) is true as per assumption and the
second term 2(4k+2) is must to be a multiple of 2. Hence, 4(k+1)+2 is a multiple of 2. So, by
induction hypothesis, (4m+2) isa multiple of 2, for m = 1, 2, 3…
polygon with 7 sides can betriangulated into _
a) 7
b) 14
c) 5
d) 0
Answer: c
Explanation: A simple polygonwith n sides can be triangulated into n-2 triangles,where n > 2.

60. Every simple polynomial has aninterior diagonal.


a) True
92
b) False
Answer: a
Explanation: By using StrongInduction.

61. polygon with 12 sides can be triangulated into


a) 7
b) 10
c) 5
d) 12
Answer: b
Explanation: A simple polygonwith n sides can be triangulated into n-2 triangles,where n > 2.

62. Which of the following iscontained in a recursive grammar?


a) semantic rules
b) production rules
c) recursive language
d) recursive function
Answer: b Explanation: In natural
language semantics, recursivegrammar plays a vital role as well as in syntax. A recursive grammar
in a context free language is a formal grammarwhich consists of recursive production rules.

63. is the consequence ofdynamic programming.


a) Bellman equation
b) Fresenius equation
c) Linear equation
d) Boolean expression
Answer: a Explanation: Dynamic
programming can lead to recursive optimization that can restate a multistep optimization problem
in its recursive form. The Bellman equation that writes the value of the optimization problem at an
earlier time in terms of its value at a later time is the result of dynamic programming.

64. How many types of self- referential recursive data arethere in computer programs?
a) 6
b) 2
c) 10
d) 4
Answer: b
Explanation: There are two types of self-referential definitions and these are inductive and
conductive definitions. An inductively defined recursive data definition must have to specifyhow to
construct instances of the data. For example, linked lists are defined as an inductively recursive
data definition.

65. How many even 4 digit wholenumbers are there?


a) 1358
b) 7250

93
c) 4500
d) 3600
Answer: c
Explanation: The thousands digit cannot be zero, so there are 9 choices. There are 10 possibilities
for the hundreds digit and 10 possibilities for the tens digit. The units digit can be 0, 2, 4, 6 or 8, so
there are 5choices. By the basic counting principle, the number of even five digit whole numbers is
9 × 10 × 10 × 5 = 45,00.

66. In a multiple-choice question paper of 15 questions, the answers can be A, B, C or D. The


number of different ways of answering the question paper are
a) 65536 x 47
b) 194536 x 45
c) 23650 x 49
d) 11287435
Answer: a
Explanation: There are 415 = 65536 x 47 different ways of answering the exam paper of15 MCQs.

67. How many words with seven letters are there that start with a vowel and end with an A? Note
that they don’t have to be real words and letters can be repeated.
a) 45087902
b) 64387659
c) 12765800
d) 59406880
Answer: d
Explanation: The first letter must be a vowel, so there are 5choices. By the basic counting principle,
the number of ‘words’ is 5 × 26 × 26 × 26 × 26
× 26 × 1 = 59406880.

68. A drawer contains 12 red and 12 blue socks, all unmatched. A person takes socks out at
random in the dark. How many socks must he take out to be sure that he has at least two blue
socks?
a) 18
b) 35
c) 28
d) 14
Answer: d
Explanation: Given 12 red and 12 blue socks so, in order to take out at least 2 blue socks, first we
need to take out 12 shocks (which might end up red in worst case) and then take out 2 socks
(which would be definitely blue). Thus we need to take out total 14 socks.

69. The least number of computers required to connect 10 computers to 5 routers to guarantee 5
computers can directly access 5 routers is
a) 74
b) 104
c) 30
d) 67
Answer: c
94
Explanation: Since each 5 computers need directly connected with each router. So 25 connections
+ now remaining 5 computer, each connected to 5 different routers, so 5 connections = 30
connections. Hence,
c1->r1, r2, r3, r4, r5 c2->r1, r2, r3, r4, r5 c3->r1, r2, r3, r4, r5 c4->r1, r2, r3, r4, r5 c5->r1, r2, r3, r4, r5 c6-
>r1 c7->r2 c8->r3 c9->r4 c10->r5
Now, any pick of 5 computers will have a direct connection toall the 5 routers.

70. In a group of 267 people how many friends are there who havean identical number of friends in
that group?
a) 266
b) 2
c) 138
d) 202
Answer: b
Explanation: Now, consider the numbers from 1 to n-1 as holes and the n members as pigeons.
Since there is n-1 holes and n pigeons there must exists a hole which must contain more than one
pigeon. So, in a group of n members there must exist at least two persons having equal number of
friends. A similar case occurs when thereexist a person having no friends.

71. How many substrings (of all lengths inclusive) can be formed from a character string of length
8? (Assume all characters to bedistinct)
a) 14
b) 21
c) 54
d) 37
Answer: d
Explanation: Total no of substrings possible in n lengthstring (All length inclusive) = 1
+ [n (n+1)/2] = 8(8+1)/2 = 37.

72. The number of diagonals can bedrawn in a hexagon is_____________


a) 9
b) 32
c) 16
d) 21
Answer: a
Explanation: A hexagon has 6 sides. We obtain the diagonalsby joining the vertices in [Link]
number of sides and diagonals = 6C2 = 6∗5/2∗1 = 5×3 = 15. This includes its 6 sides also. So,
Diagonals = 15 – 6 = [Link], the number of diagonals is 9.

73. The number of binary strings of 17 zeros and 8 ones in which no two ones are adjacent
is_________
a) 43758
b) 24310
c) 32654
d) 29803
Answer: a
95
Explanation: First place 17 zeroes side by side _ 0 _ 0 _ 0
… 0 _ and 8 1’s can be placed inany of the (17+1) available gaps hence the number of ways = n+1Ck
= 43758

74. How many numbers of three digits can be formed with digits1, 3, 5, 7 and 9?
a) 983
b) 120
c) 345
d) 5430
Answer: b
Explanation: Here number of digits, n = 5 and number of places to be filled-up r = 3. Hence, the
required numberis 5P3 = 5! /2!*3! = 120.

75. In how many ways 6 pens can be selected from 15 identical black pens?
a) 9*3!
b) 21
c) 14!
d) 1
Answer: d
Explanation: Here the pens areidentical; the total number of ways of selecting 6 pens is 1.

76. Find the number of ways in which 4 people E, F, G, H, A, C can be seated at a round table, such
that E and F must always sittogether.
a) 32
b) 290
c) 124
d) 48
Answer: d
Explanation: E and F can sit together in all arrangements in2! Ways. Now, the arrangement of the 5
people ina circle can be done in (5 – 1)! or 24 ways. Therefore, the total number of ways will be 24
x 2 = 48.

77. There are 6 equally spaced points A, B, C, D, E and F markedon a circle with radius R. How many
convex heptagons of distinctly different areas can be drawn using these points as vertices?
a) 7! * 6
b) 7C5
c) 7!
d) same areaAnswer: d
Explanation: Since all the points are equally spaced; hence the area of all the convex heptagons
will be thesame.

78. The number of words of 4 consonants and 3 vowels can be made from 15 consonants and 5
vowels, if all the letters are different is
a) 3! * 12C5
b) 16C4 * 4C4
c) 15! * 4
d) 15C4 * 5C3 * 7!
96
Answer: d
Explanation: There are 4 consonants out of 15 can be selected in 15C4 ways and 3 vowels can be
selected in 5C3 ways. Therefore, the total number of groups each containing 4 consonants and 3
vowels = 15C4 * 4C3. Each groupcontains 7 letters which can bearranged in 7! Ways. Hence, required
number of words = 15C4 * 5C3 * 7!

79. There are six movie parts numbered from 1 to 6. Find the number of ways in which they be
arranged so that part-1 and part-3 are never together.
a) 876
b) 480
c) 654
d) 237
Answer: b
Explanation: The total numberof ways in which 6 part can be arranged = 6! = 720. The total number
of ways in which part-1 and part-3 are always together: = 5!*2! = 240.
Therefore, the total number ofarrangements, in which they are not together is = 720 − 240
= 480.

80. Calculate sum of divisors of n =1900.


a) 6530
b) 5346
c) 3387
d) 4123
Answer: d
Explanation: The prime factorization of 1800 is 19 *
22 * 52 and
S (22) = 1 + 2 + 4 = 7
S (52) = 1 + 5 + 25 = 31
Therefore, S (1800) = 19 * 7 *31 = 4123.

81. The number of even positiveintegers of 3200 is


a) 24
b) 32
c) 164
d) 209
Answer: a
Explanation: To find the number of even factors, we canmultiply the number of even factors by the
power of 2. For 3200, we have (5 + 1) (1 + 1)(2)
= 24 even factors.

82. What is the sum of divisors ofthe number 1872?


a) 12493
b) 5438
c) 45862
d) 654
Answer: a
Explanation: The prime factorization of 1872 is 13 *32 * 24 and S (24) = 1 + 2 + 4 + 8+ 16 = 31, S (52)
= 1 + 5 + 25 =31. Therefore, S (1872) = 31 *31 * 13 = 12493.
97
83. Calculate sum of divisors of n =8620.
a) 7549
b) 54201
c) 18102
d) 654
Answer: c
Explanation: The prime factorization of 1800 is 431 *
22 * 5 and
S (22) = 1 + 2 + 4 = 7
S (52) = 1 + 5 = 6
Therefore, S (1800) = 6 * 7 *431 = 18102.

84. Assume that it is an afternoon. What is the time on the 24 hourclock after 146 hours?
a) 12:10 pm
b) 8:30 am
c) 3 am
d) 2 pm Answer: d
Explanation: Divide 146 with 24. The remainder is the time on the 24 hour clock. So, 146 = 6*24 + 2
and the result is 2pm.

85. Suppose, there are 7 of your friends who want to eat pizza (8 distinct people in total). You order
a 16-cut pizza (16 identical slices). How many distributions of pizza slices are there if each person
gets at least one slice of pizza?
a) 346
b) 6435
c) 3214
d) 765
Answer: b
Explanation: This problem can be viewed as identical objects distributed into distinct non- empty
bins. Using the formula for these kind of distributions n- 1Cr-1 = 15C7 = 6435. Thus, there are
distributions of the pizza slices.

86. The linear system C x = d is known as if d! = 0.


a) homogeneous
b) heterogeneous
c) non-homogeneous
d) augmented system
Answer: c
Explanation: A linear system C x = d is known as a homogeneous system if d! = 0. The
homogeneous linear system Ax = 0 is called its corresponding homogeneous linear system.

87. Every linear equation determines a in n-dimensional space for n variables.


a) shipshape
b) hyper-plane
c) cone
d) pyramid Answer: b
98
Explanation: In an m- dimensional space, every linear equation produces a hyper- plane for n
variables. The solution set is the intersection of these hyper-planes and is planar which may have
any dimension smaller than m.

88. Determine all possibilities for the solution set of the homogeneous system of 5 equations in 3
unknowns and the rank of the system is 3.
a) more than two
b) only one
c) zero
d) infinite Answer: c
Explanation: Since the rank of this homogeneous system (which is always consistent) and the
number of unknownsare equal, the only possible solution is zero and it is a unique solution.

89. Computational complexity of derangements is of


a) NP-complete
b) NP-hard
c) NP
d) P
Answer: a
Explanation: Computational complexity of derangements is NP-complete in order to determine
whether a given permutation group consists ofany derangements or not.

90. Determine the number of ways In a single competition a singing couple from 5 boys and 5 girls
can be formed so that no girl cansing a song with their respective boy?
a) 123
b) 44
c) 320
d) 21
Answer: b
Explanation: This is a case of derangement of 5 boys and 5 girls. The required number of ways can
be described as D = 5!(1 – 1/1! + 1/2!–1/3! + 1/4! – 1/5!) = 120(11/30) = 44 ways.

91. A fair coin is tossed 15 [Link] the probability in which no heads turned up. a) 2.549 *
10-3
b) 0.976
c) 3.051 * 10-5
d) 5.471
Answer: c
Explanation: According to the null hypothesis it is a fair coin and so in that case the probability of
flipping at least 59% tails is = 15C0(0.5)15 = 3.051
* 10-5.

92. Find the value of a4 for the recurrence relation an=2an-1+3,with a0=6.
a) 320
b) 221
c) 141
d) 65
99
Answer: c
Explanation: When n=1, a1=2a0+3, Now a2=2a1+3. Bysubstitution, we get a2=2(2a0+3) +3.
Regrouping the terms, we geta4=141, where a0=6.

93. How many positive integers less than or equal to 100 are divisibleby 2, 4 or 5?
a) 12.3
b) 87.2
c) 45.3
d) 78.2
Answer: d
Explanation: To count the number of integers = 100/2 + 100/4 + 100/5 –100/8 – 100/20
+1 00/100
= 50 + 25 + 20 – 12.8 – 5 + 1 =78.2.

94. How many binary relations arethere on a set S with 9 distinctelements?


a) 290
b) 2100
c) 281
d) 260
Answer: c
Explanation: S is the set with 9elements. A relation on S is defined as S x S. There are
92 numbers of ordered pairs inrelation. So, the number of binary relations is 2(9*9) = 281.

95. Synonym for binary relation is____________


a) equivalence relation
b) dyadic relation
c) orthogonal relation
d) one to many relationsAnswer: b
Explanation: A binary relation on a set S is a set of ordered pairs of elements of S. It is a subset of
the Cartesian product S2 = S x S. The terms correspondence, dyadic relation and 2-place relation
are synonyms for the binary relation.

96. R is a binary relation on a set Sand R is reflexive if and only if_______________


a) r(R) = R
b) s(R) = R
c) t(R) = R
d) f(R) = R Answer: a
Explanation: Let reflexive closure of R: r(R) = R. If R is reflexive, it satisfies all the condition in the
definition of reflexive closure. So, a reflexiveclosure of a relation is the smallest number of reflexive
relation contain in R. Hence, R
= r(R).

97. Amongst the properties


{reflexivity, symmetry, anti- symmetry, transitivity} the relation R= {(a, b) ∈ N2 | a! = b} satisfies
property.
a) symmetry

100
b) transitivity
c) anti-symmetry
d) reflexivityAnswer: a
Explanation: It is not reflexiveas a Ra is not possible. It is symmetric as if a R b then b R
a. It is not anti-symmetric as aR b and b Ra are possible and we can have a! = b. It is not transitive
as if a R b and b R c then a R c need not be true. This is violated when c = a. So the answer is
symmetry property.

98. The binary relation U = Φ (emptyset) on a set A = {11, 23, 35} is


a) Neither reflexive norsymmetric
b) Symmetric and reflexive
c) Transitive and reflexive
d) Transitive and symmetricAnswer: d
Explanation: U = Φ (empty set)on a set A = {11, 23, 35} need to be hold Ir-reflexive, symmetric, anti-
symmetric, asymmetric and transitive closure property, but it is not Reflexive as it does not contain
any self loop in itself.

99. The binary relation {(1,1), (2,1), (2,2), (2,3), (2,4), (3,1),(3,2)} on the set {1, 2, 3} is
a) reflective, symmetric andtransitive
b) ir-reflexive, symmetric andtransitive
c) neither reflective, nor ir-reflexive but transitive
d) ir-reflexive and anti-symmetric
Answer: c
Explanation: Not reflexive ->(3,3) not present; not ir- reflexive -> (1, 1) is present;
not symmetric -> (2, 1) is present but not (1, 2); not anti-
symmetric – (2, 3) and (3, 2) are present; not asymmetric -> asymmetry requires both anti-
symmetry and ir-reflexivity. So,it is transitive closure of relation.

100. Consider the relation: R’ (x, y) if and only if x, y>0 over the set of non-zero rational numbers
,thenR’ is
a) not equivalence relation
b) an equivalence relation
c) transitive and asymmetryrelation
d) reflexive and anti-symmetricrelation
Answer: b
Explanation: Reflexive: a, a>0 Symmetric: if a, b>0 then bothmust be +ve or -ve, which means b, a >
0 also exists Transitive: if a, b>0 and b, c>0 then to have b as same number, both pairs must be
positive or negative which implies a, c>0. Hence, R’ is an equivalence relation.

101. Consider the binary relation, A =


{(a, b) | b = a – 1 and a, b belongto {1, 2, 3}}. The reflexive transitive closure of A is?
a) {(a, b) | a >= b and a, b belongto {1, 2, 3}}
b) {(a, b) | a > b and a, b belongto {1, 2, 3}}
c) {(a, b) | a <= b and a, b belongto {1, 2, 3}}
d) {(a, b) | a = b and a, b belongto {1, 2, 3}}
101
Answer: a
Explanation: By definition of Transitive closure we have that a is related to all smaller b (as every a
is related to b – 1) and from the reflexive property a isrelated to a.

102. The less-than relation, <, on a setof real numbers is


a) not a partial ordering becauseit is not asymmetric and ir- reflexive equals anti- symmetric
b) a partial ordering since it isasymmetric and reflexive
c) a partial ordering since it isanti-symmetric and reflexive
d) not a partial ordering becauseit is not anti-symmetric and reflexive
Answer: a
Explanation: Relation less thana set of real numbers is not anti-symmetric and reflexive.
Relation is not POSET becauseit is ir-reflexive. Again, a R b! =
b R a unless a=b and so it is anti-symmetric. A relation may be ‘not asymmetric and not reflexive
but still anti- symmetric, as {(1, 1) (1, 2)}. So, the relation is not a partial ordering because it is not
asymmetric and ir-reflexive equals anti-symmetric.

103. Let a set S = {2, 4, 8, 16, 32} and


<= be the partial order defined by S <= R if a divides b. Number of edges in the Hasse diagram ofis
a) 6
b) 5
c) 9
d) 4
Answer: b
32
Explanation: Hass Diagram is:
/
16
/8
/ \
2 4

104. Suppose X = {a, b, c, d} and π1 is the partition of X, π1 = {{a, b, c}, d}. The number of ordered
pairsof the equivalence relations induced by _
a) 15
b) 10
c) 34
d) 5
Answer: b
Explanation: The ordered pairs of the equivalence relations induced = {(a, a), (a, b), (a, c), (b, a), (b,
b), (b, c), (c, a), (c, b),(c, c), (d, d)}. Po-set -> equivalence relations = each partition power set – Φ.

105. Suppose a relation R = {(3, 3), (5,5), (5, 3), (5, 5), (6, 6)} on S = {3, 5, 6}. Here R is known as
a) equivalence relation
b) reflexive relation
c) symmetric relation
d) transitive relationAnswer: a
Explanation: Here, [3] = {3, 5},
102
[5] = {3, 5}, [5] = {5}. We can
see that [3] = [5] and that S/Rwill be {[3], [6]} which is a partition of S. Thus, we can
choose either {3, 6} or {5, 6} asa set of representatives of theequivalence classes.

106. Consider the congruence 45≡3(mod 7). Find the set of equivalence class representatives.
a) {…, 0, 7, 14, 28, …}
b) {…, -3, 0, 6, 21, …}
c) {…, 0, 4, 8, 16, …}
d) {…, 3, 8, 15, 21, …}
Answer: a
Explanation: Now, for integers n, a and b, we have congruencea ≡ b (mod n), then the set of
equivalence classes are {…, -2n,
-n, 0, n, 2n, …}, {…, 1-2n, 1-n, 1,
1+n, 1+2n,…}. The required answer is {…, 0, 7, 14, 28 …}.

107. Which of the following relationsis the reflexive relation over theset {1, 2, 3, 4}?
a) {(0,0), (1,1), (2,2), (2,3)}
b) {(1,1), (1,2), (2,2), (3,3), (4,3),
(4,4)}
c) {,(1,1), (1,2), (2,1), (2,3), (3,4)}
d) {(0,1), (1,1), (2,3), (2,2), (3,4),
(3,1)
Answer: b
Explanation: {(1,1), (1,2), (2,2),
(3,3), (4,3), (4,4)} is a reflexive relation because it contains set
= {(1,1), (2,2), (3,3), (4,4)}.

108. A directed graph or digraph canhave directed cycle in which


a) starting node and ending nodeare different
b) starting node and endingnode are same
c) minimum four vertices can bethere
d) ending node does not existAnswer: b
Explanation: If the start node and end node are same in the path of a graph then it is termed as
directed cycle i.e.,
c0 = c n. For instance, a c b a is asimple cycle in which start and end nodes are same (a). But, a c b
b a is not a simple cycle as there is a loop <b, b>.

109. Let, D = <A, R> be a directed graph or di-graph, then D’ = <A’,


R’> is a sub-graph if
a) A’ ⊂ A and R’ = R ∩ (A’ x A’)
b) A’ ⊂ A and R ⊂ R’ ∩ (A’ x A’)
c) R’ = R ∩ (A’ x A’)
d) A’ ⊆ A and R ⊆ R’ ∩ (A’ x A’)
Answer: a
Explanation: The relation R is called the incidence relation on
D. Now, a digraph is a sub-graph of D if
i) A’ ⊂ A
103
ii) R’ = R ∩ (A’ x A’). If D’ D,D’ is a proper sub-graphof D.

110. The graph representing universalrelation is called


a) complete digraph
b) partial digraph
c) empty graph
d) partial sub-graphAnswer: a
Explanation: Consider, A is a graph with vertices {a, b, c, d} and the universal relation is A x
A. The graph representing universal relation is called a complete graph and all ordered pairs are
present there.

111. Hass diagrams are first made by


a) A.R. Hass
b) Helmut Hass
c) Dennis Hass
d) T.P. HassAnswer: b
Explanation: Hass diagrams can be described as the transitive reduction as an abstract directed
acyclic [Link] graph drawing techniquesare constructed by Helmut Hass (1948).

112. If a partial order is drawn as a Hass diagram in which no two edges cross, its covering graph
iscalled _
a) upward planar
b) downward planar
c) lattice
d) bi-connected componentsAnswer: a
Explanation: In a Hass diagram if no two edges cross each other in the drawing of partial order
Hass diagram, then its covering graph called the upward planar.

113. If the partial order of a set has at most one minimal element, thento test whether it has a non-
crossing Hass diagram its time complexity
a) NP-complete
b) O(n2)
c) O(n+2)
d) O(n3)
Answer: a
Explanation: If the partial order has at most one minimal element, or it has at most one maximal
element, then to test whether a partial order with multiple sources and sinks can be drawn as a
crossing-free Hass diagram or not it’s time complexity is NP-complete.

114. A Po-set in which every pair of elements has both a least upper bound and a greatest lower
bound is termed as
a) sub-lattice
b) lattice
c) trail
d) walk Answer: b
104
Explanation: A Po-set in which every pair of elements has both a least upper bound and a greatest
lower bound is called a lattice. A lattice can contain sub-lattices which are subsets of that lattice.

115. In the Po-set (Z+, |) (where Z+ is the set of all positive integers and | is the divides relation) are
the integers 9 and 351 comparable?
a) comparable
b) not comparable
c) comparable but notdetermined
d) determined but notcomparable
Answer: a
Explanation: The two integers9 and 351 are comparable
since 9|351 i.e., 9 divides 351.
But 5 and 127 are not comparable since 5 | 127 i.e. 5does not divide 127.

116. If every two elements of a Po-setare comparable then the Po-set is called
a) sub ordered Po-set
b) totally ordered Po-set
c) sub lattice
d) semi-group
Answer: b
Explanation: A Po-set (P, <=) is known as totally ordered if every two elements of the Po- set are
comparable. “<=” is called a total order and a totally ordered set is also termed as a chain.

117. The maximum number of edgesin a bipartite graph on 14 vertices is


a) 56
b) 14
c) 49
d) 87
Answer: c
Explanation: Number of edges in a complete bipartite graph is a*b, where a and b are no. of
vertices on each side. This quantity is maximum when a = b i.e. when there are 7 vertices on each
side. So answer is 7 * 7 = 49.

118. In a the degree of eachand every vertex is equal.


a) regular graph
b) point graph
c) star graph
d) Euler graph
Answer: c
Explanation: A regular graph has the same degree in each of its vertices. In a regular bipartite
graph, if the commondegree of each vertex is 1, the two parts are of the same size.

119. The time complexity to test whether a graph is bipartite or not is said to be using depth first
search.
a) O(n3)
b) linear time
105
c) O(1)
d) O(nlogn)
Answer: b

120. In a 7-node directed cyclicgraph, the number of Hamiltonian cycle is to be


a) 728
b) 450
c) 360
d) 260
Answer: c
Explanation: In an n-complete graph, there is (n-1)! /2 Hamiltonian cycles and so the answer is 360.
(7-1)! /2

121. If each and every vertex in G has degree at most 23 then G can have a vertex coloring of
_________
a) a simple cycle
a) 24
b) 23
c) 176
d) 54
Answer: a
Explanation: A vertex coloring of a graph G = (V’, E’) with m colors is a mapping f: V’ -> {1, m} such
that f (u)! = f (v) for every (u, v) belongs to E’. Since in worst case the graph can be complete, d+ 1
color are necessary for graph containing vertices with degree at must’s’. So, the required answer is
24.

122. Triangle free graphs have theproperty of clique number is


a) less than 2
b) equal to 2
c) greater than 3
d) more than 10
Answer: d
Explanation: In an undirected triangle-free graph no three vertices can form a triangle of edges. It
can be described as graphs with clique number lessthan 2 and the graphs with girth greater than 4.

123. A bridge cannot be a part of


b) a tree
c) a clique with size ≥ 3 whoseevery edge is a bridge
d) a graph which contains cycles
Answer: a
Explanation: In a connected graph, a bridge is an edge whose removal disconnects the graph. In a
cycle if we remove an edge, it will still be connected. So, bridge cannot be part of a cycle. A clique
is any complete sub-graph of a graph.

124. Any subset of edges that connects all the vertices and has minimum total weight, if all the
edge weights of an undirected graph are positive is called

106
a) sub-graph
b) tree
c) Hamiltonian cycle
d) grid
Answer: b
Explanation: If all the edge weights of an undirected graph are positive, any subset of edges that
connects all the vertices and has minimum totalweight is termed as a tree. In this case, we need to
have a minimum spanning tree need to be exact.

125. G is a simple undirected graph and some vertices of G are of odd degree. Add a node n to G
and make it adjacent to each odd degree vertex of G. The resultant graph is
a) Complete bipartite graph
b) Hamiltonian cycle
c) Regular graph
d) Euler graphAnswer: d

126. A graph which has the same number of edges as its complement must have number of
vertices congruent to___________or________ modulo 4(for integral values of number of edges).
a) 6k, 6k-1
b) 4k, 4k+1
c) k, k+2
d) 2k+1, k
Answer: c
Explanation: By using invariant of isomorphism and property of edges of graph and its
complement.

127. Every Isomorphic graph must have _ representation.


a) cyclic
b) adjacency list
c) tree
d) adjacency matrix
Answer: d
Explanation: Two graphs G1 and G2 are said to be isomorphic if −> 1) their number of components
(vertices and edges) are same and 2) their edge connectivity is retained. Isomorphic graphs must
have adjacency matrix representation.

128. A cycle on n vertices is isomorphic to its [Link] is the value of n?


a) 5
b) 32
c) 17
d) 8
Answer: a
Explanation: A cycle with n vertices has n edges. Number of edges in cycle = n and number of
edges in its complement = (n*(n−1)/2) – n.

129. Which algorithm efficiently calculates the single source shortest paths in a Directed Acyclic
107
Graph?
a) topological sort
b) hash table
c) binary search
d) radix sort
Answer: a
Explanation: For Directed Acyclic graph, single source shortest distances can be calculated in O
(V+E) time. Topological Sorting of any graph represents a linear ordering of the graph.

130. The of a graph G consists of all vertices and edgesof G.


a) edge graph
b) line graph
c) path complement graph
d) Eulerian circuit
Answer: d
Explanation: we know that he Eulerian circuit in a graph G is a circuit that includes all vertices and
edges of G. A graph that can have Eulerian circuit also can have a Eulerian graph.

131. A in a graph G is a circuit which consists of every vertex (except first/last vertex) of G exactly
once.
a) Euler path
b) Hamiltonian path
c) Planar graph
d) Path complement graph
Answer: b
Explanation: A Hamiltonian path is a walk that contains every vertex of the graph exactly once.
Hence, a Hamiltonian path is not a circuit.

132. The chromatic number of agraph is the property of


a) graph coloring
b) graph ordering
c) group ordering
d) group coloring
Answer: b
Explanation: A graph coloring is an assignment of labels to the vertices of a graph such that no
two adjacent vertices share the same labels is called the colors of the graph. Now, the chromatic
number of any graph is the minimal number ofcolors for which such an assignment is possible.

133. If a graph G is k-colorableand k<n, for any integer n then it is


a) n-colorable
b) n2 nodes
c) (k + n)-colorable
d) (k3+n3+1) nodes
Answer: a
Explanation: The chromatic number of a graph is the minimal number of colors for which a graph

108
coloring is possible. A graph G is termed as k-colorable if there exists a graph coloring on G with k
colors. If a graph is k-colorable,then it is n-colorable for any n>k.

134. If C n is the nth cyclic graph,where n>3 and n is odd. Determine the value of X (C n).
a) 32572
b) 16631
c) 3
d) 310
Answer: c
Explanation: Here n is odd and X (C n)! = 2. Since there are twoadjacent edges in C n. Now, a graph
coloring for C n exists where vertices are colored red and blue alternatively and another edge is
with a differentcolour say orange, then the value of X (C n) becomes 3.

135. A direct product of a group G possesses which of the followingcharacteristics?


a) a multiplication of subgroupsof G
b) a factorization via subgroupsof G
c) a superset of subgroups of G
d) a maximal power set ofsubgroups
Answer: b
Explanation: A direct product of a group G is a factorization via subgroups of G when the
intersection is nontrivial, say X and Y, such that G = XY, X intersect Y = 1, and [X, Y] =1 and X, Y are
normal in G.

136. In invariant algebra, some generators of group G1 that goes either into itself or zero under
with any other elementof the algebra.
a) commutation
b) permutation
c) combination
d) lattice
Answer: a
Explanation: Some generators of group G1 in group theory which goes either into itself or zero
under commutation with any other element of the wholealgebra is called invariant sub- algebra.

137. Which of the following can beembedded in an algebraicallyclosed group?


a) infinite group
b) star-graph
c) a countable group
d) a semi-lattice
Answer: c
Explanation: We know that anycountable group can always be embedded in an algebraically closed
group.

138. An undirected graph G which isconnected and acyclic is called


a) bipartite graph
b) cyclic graph
c) tree
109
d) forest Answer: c
Explanation: An undirected graph G which is connected and acyclic is termed as a tree. G contains
no cycles and if any edge is added to G a simple cycle is formed.

139. An n-vertex graph has edges.


a) n2
b) n-1
c) n*n
d) n*(n+1)/2Answer: b
Explanation: Suppose G is a connected graph which has no cycles. Every sub-graph of G includes
at least one vertex withzero or one incident edges. It has n vertices and n-1 edges.
Generally, the order-zero graphis not considered to be a tree.

140. What is a star tree?


a) A tree having a single internalvertex and n-1 leaves
b) A tree having n verticesarranged in a line
c) A tree which has 0 or moreconnected sub-trees
d) A tree which contains n vertices and n-1 cyclesAnswer: a
Explanation: A star tree of order n is a tree with as many leaves as possible or in other words a
star tree is a tree that consists of a single internal vertex and n-1 leaves. However,an internal vertex
is a vertex of degree at least 2.

141. If two cycle graphs Gm and Gn are joined together with a vertex, the number of spanning
trees in the new graph is
a) m+n-1
b) m-n
c) m*n
d) m*n+1 Answer: c
Explanation: As there are n possible edges to be removed from G and m edges to be removed
from G and the rest from a spanning tree so the number of spanning tree in thenew graph is m*n.

142. For an n-vertex undirected graph, the time required to finda cycle is
a) O(n)
b) O(n2)
c) O(n+1)
d) O(log n)Answer: a
Explanation: In an undirected graph, finding any already visited vertex will indicate a back edge. All
the back edges which DFS skips over are part of cycles. In the case of undirected graphs, only O(n)
time is required to finda cycle in an n-vertex graph, since at most n − 1 edges can be tree edges.

143. A binary cycle space forms a


over the two elementfield.
a) triangular graph
b) vector space
c) binary tree

110
d) Hamiltonian graphView Answer
Answer: b
Explanation: The term cycle refers to an element of the cycle space of a graph. There are many
cycle spaces. The most common is the binary cycle space, which contains the edge sets that have
even degrees at every vertex and it forms a vector space over the two- element field.

144. In preorder traversal of a binary tree the second step is


a) traverse the right sub-tree
b) traverse the left sub-tree
c) traverse right sub-tree andvisit the root
d) visit the rootAnswer: b
Explanation: In a preorder traversal of a binary tree first is to visit the root, second traverse the left
sub-tree of the tree and third traverse the right sub-tree of the tree.

145. An important application ofbinary tree is


a) Huffman coding
b) stack implementation
c) queue implementation
d) traverse a cyclic graphAnswer: a
Explanation: A binary tree is used to sort a list of elements; the in-order traversal will do this
automatically. Better tree sorting algorithm will involve balancing the trees. The binary coding, in
particular for the Huffman coding is an immediateapplication of binary trees.

146. From the following code identify the which traversal of abinary tree is this
//if node has left childOrder (node. left)
//if node has right childOrder (node. right) Visit (node)
a) In-order traversal
b) preorder traversal
c) post-order traversal
d) Euler tour traversalAnswer: c
Explanation: In a post-order traversal of a binary tree first is to traverse the left sub-tree, second
traverse the right sub- tree of the tree and third is to visit the node.

147. Evaluation of expression a/b+c*d-e in postfix notation.


a) ab+cd/*-e
b) a b/c d*+e-
c) a b c/+d*-e
d) a b c d/+*-eAnswer: b
Explanation: The expression=a/b+c*d-e
={(a b/)+(c d*)}-e
={(a b/)(c d*)+}-e
={(a b/)( c d*)+}e-
So the output is: a b/c d*+e-

148. Evaluation of 4*5+3/2-9 inprefix notation.

111
a) *45-/32+9
b) *+453/-29
c) -+*45/329
d) *+/45932Answer: c
Explanation: The expression=4*5+3/2-9
={(4*5)+(3/2)-9}
={(*45)+(/32)-9}
={+(*45)(/32)}-9
=-{+(*45)(/32)9
So the output is; -+*45/329.

149. Infix to prefix conversion canbe done using


a) two queues
b) two stacks
c) one stack and two queues
d) one stackAnswer: b
Explanation: In the infix expression, the operator appears between the operands and in infix
notation if the operator appears before the operands in the expression. For the conversion
between them two stacks are used efficiently. The
idea is to use one stack for operators and other to storeoperands.

150. Spanning trees have a specialclass of depth-first search treesnamed


a) Euclidean minimum spanningtrees
b) Tremaux trees
c) Complete bipartite graphs
d) Decision treesAnswer: b
Explanation: A tremaux tree of an undirected graph G is a spanning tree of G which is rooted at
one of its vertices withthe property that every two adjacent vertices in G are relatedto each other as
an ancestor anddescendant in the tree.

151. If the weight of an edge e of cycle C in a graph is larger than the individual weights of all other
edges of C, then that edge
a) belongs to an minimumspanning tree
b) cannot belong to an minimumspanning tree
c) belongs to all MSTs of thegraph
d) can not belong to the graph
Answer: b
Explanation: For any cycle C inthe graph, if the weight of an edge e of C is larger than the individual
weights of all other edges of C, then this edge cannot belong to an MST.

152. For every spanning tree with n vertices and n edges what is the least number of different
Spanning trees can be formed?
a) 2
b) 5
c) 3
d) 4
112
Answer: c
Explanation: The minimum cyclelength can be 3. So, there must be at least 3 spanning trees in any
such Graph. Consider a Graph with n = 4, then 3 spanning trees possible at maximum (removing
edges of cycle one at a time, alternatively). So, any Graph with minimum cycle length ‘3’ will have
at least 3 spanning trees.

153. Algebra of logic is termed as


a) Numerical logic
b) Boolean algebra
c) Arithmetic logic
d) Boolean number
Answer: c
Explanation: The variables that can have two discrete values False (0) and True (1) and the
operations of logical significanceare dealt with Boolean algebra.

154. Boolean algebra can be used__


a) For designing of the digital computers
b) In building logic symbols
c) Circuit theory
d) Building algebraic functions
Answer: a
Explanation: For designing digital computers and building different electronic circuits Boolean
algebra is accepted widely.

155. What is the definition ofBoolean functions?


a) An arithmetic function with kdegrees such that f:Y–>Y k
b) A special mathematical function with n degrees suchthat f:Yn–>Y
c) An algebraic function with ndegrees such that f:Xn–>X
d) A polynomial function with k degrees such that f:X2–>X n
Answer: b
Explanation: A Boolean function is a special mathematical function with n degrees and where Y =
{0, 1} is the Boolean domain with being a non- negative integer. It helps in describing the way in
which the Boolean output is derived from Boolean inputs.

156. What is the use of Booleanidentities?


a) Minimizing the Booleanexpression
b) Maximizing the Booleanexpression
c) To evaluate a logical identity
d) Searching of an algebraicexpression
Answer: a
Explanation: Boolean identities are used for minimizing the Boolean expression and transforming
into an equivalentexpression.

157. A ____ is a Booleanvariable.


a) Literal
b) String
113
c) Keyword
d) IdentifierAnswer: a
Explanation: A literal is a Boolean variable or its complement. A max-term is a sum of n literals and
a min-termis a product of n literals.

158. Minimization of functionF(A,B,C) = A*B*(B+C) is


a) AC
b) B+C
c) B`
d) AB Answer: d
Explanation: AB(B+C)
= ABB + ABC [Applyingdistributive rule]
= AB + ABC [ApplyingIdempotent law]
= AB (1+C)
= AB*1 [As, 1+C=1]
= AB.

159. Find the simplified expressionA’BC’+AC’.


a) B
b) A+C
c) (A+B)C’
d) B’C
Answer: c
Explanation: Given: A’BC’ + AC’
= C’ (A’B + A)
= C’(A + B).

160. Evaluate the expression: (X +Z)(X + XZ’) + XY + Y.


a) XY+Z’
b) Y+XZ’+Y’Z
c) X’Z+Y
d) X+Y Answer: d
Explanation: (X + Z)(X + XZ’) + XY+ Y [Original Expression]
= (x + z)X(1 + Z’) + XY + Y [Distributive]
= (X + Z)X + XY + Y [Complement,Identity]
= (X+Z)X + Y(X+1) [ Distributive]
= (X+Z)X + Y [Idempotent]
= XX + XZ + Y [Distributive]
= X + XZ + Y [Identity]
= X(1+Z) + Y
= X + Y [Idempotent].

161. Simplify the expression: A’(A +BC) + (AC + B’C).


a) (AB’C+BC’)
b) (A’B+C’)
c) (A+ BC)
114
d) AC Answer: b
Explanation: Given: A’(A + BC) +(AC + B’C)
= A’A + A’BC + AC + B’C
= A’BC + C(A + B’)
= C(A’B + A + B’)
= C(A + B + B’)
= C(A + 1)
= AC.

162. K-map is used for


a) logic minimization
b) expression maximization
c) summing of parity bits
d) logic gate creationAnswer: a
Explanation: K-map (Maurice Karnaugh of Bell labs in 1953) It is more efficient than Boolean
algebra. K-map is a diagram made up of squares in which each square represents a min- term or
max-term of the logic function.

163. To display time in railway stations which digital circuit isused?


a) seven segment decoder
b) eight segment encoder
c) 8:3 multiplexer
d) 9 bit segment driverAnswer: a
Explanation: A seven segment decoder is a digital circuit which is used to construct a common
type of digital display device.

164. Simplify the expression usingK-maps: F(A,B,C,D)=Σ (1,3,5,6,7,11,13,14).


a) AB+BC’D+A’B’C
b) BCD’+A’C’D+BD’
c) A’D+BCD+A’BC+AB’C’
d) AC’D’+BC+A’BD+C’D’Answer: c
Explanation: By solving the givenexpression we have min-terms such as A’D+BCD+A’BC+AB’C’.
So, we can get the requiredexpression A’D+BCD+A’BC+AB’C’.

165. In Boolean algebra, the data isa bit-representation of information consists of


a) 0 and 1
b) 2 and 5
c) 1 and 15
d) 4 and 8Answer: a
Explanation: The data, in Boolean algebra must be in a bit-representation form which can
be in between two values 0 and1.

166. How many cells are there foran 8-variable K-Map?


a) 421
b) 1048
c) 256
115
d) 375
Answer: c
Explanation: Any Boolean expression or a function comprising of 8 variables can be solved using
an 8-variable K- Map. So, an 8-variable K-Map must contain 28 = 256.

167. Determine the number of essential prime implicates of thefunction f(a, b, c, d) = Σ m (1, 3, 4, 8,
10, 13) + d(2, 5, 7, 12), where m denote the min-term and d denotes the don’t care condition.
a) 23
b) 3
c) 643
d) 128
Answer: b
Explanation: A prime implicit that cannot be replaced by any other implicit for getting the output is
called the essential prime implicates. Here, we have 3 essential prime implicates by using the K-
map representation.

168. How many number of prime implicates are there in the expression F(x, y, z) = y’ z’ + x y + is
called a semi-
x’ z.
a) 7
b) 19
c) 3
d) 53 Answer: c
Explanation: An implicit of a function is a product term whichis included in the function.
Hence, for the given function, y’z’, x y and x’ z all are prime implicates.

169. A non empty set A is termed as an algebraic structure ______


a) with respect to binary operation*
b) with respect to ternary operation?
c) with respect to binary operation +
d) with respect to unary operation –
Explanation: A non empty set A is called an algebraic structure w. r. t binary operation “*” if (a*b)
belongs to S for all (a*b)belongs to S. Therefore “*” is closure operation on ‘A’.

170. An algebraic structure___________ is called a semi-group.


a) (P, *)
b) (Q, +, *)
c) (P, +)
d) (+, *)
Answer: a
Explanation: An algebraic structure (P,*) is called a semi- group if a*(b*c) = (a*b)*c for all a, b, c
belongs to S or the elements follow associative property under “*”. (Matrix,*) and (Set of integers,
+) are examples of semi-group.

171. Condition for monoid is_______


a) (a + e)=a
b) (a*e)=(a + e)
116
c) a=(a*(a + e)
d) (a*e)=(e*a)=aAnswer: d
Explanation: A Semi-group (S,*) is defined as a monoid if there exists an element e in S such that
(a*e) = (e*a) = a for all a in S.
This element is called identityelement of S w. r. t *.

172. How many properties can beheld by a group?


a) 2
b) 3
c) 5
d) 4 Answer: c
Explanation: A group holds fiveproperties simultaneously –
i) Closure
ii) associative
iii) Commutative
iv) Identity element
v) Inverse element.
173. ___________are called grouppostulates.
a) Group lemmas
b) Group theories
c) Group axioms
d) Group Answer: c
Explanation: The group axioms are also called the group postulates. A group with an identity (that
is, a monoid) in which every element has an inverse is termed as semi group.

174. A subgroup has the propertiesof


a) Closure, associative
b) Commutative, associative,closure
c) Inverse, identity, associative
d) Closure, associative, Identity,Inverse
Answer: d
Explanation: A subgroup S is a subset of a group G (denoted by S <= G) if it holds the four
properties simultaneously – Closure, Associative, Identity andInverse element.

175. If a * b = a such that a ∗ (b ∗ c)


= a ∗ b = a and (a * b) * c = a * b
= a then
a) * is associative
b) * is commutative
c) * is closure
d) * is aphelionAnswer: a
Explanation: ‘∗’ can be defined by the formula a ∗ b = a for any aand b in S. Hence, (a ∗ b) ∗ c = ∗c
= a and a ∗(b ∗ c)= a ∗ b = a. Therefore,”∗” is associative.
Hence (S, ∗) is a semi-group. On the contrary, * is not associativesince, for example, (b • c) • c = a•c
= c but b • (c • c) = b • a = bThus (S, •) is not a semi-group.

117
176. Let (A7, ⊗7) = ({1, 2, 3, 4, 5, 6},
⊗7) is a group. It has two sub groups X and Y. X = {1, 3, 6}, Y =
{2, 3, 5}. What is the order ofunion of subgroups?
a) 65
b) 5
c) 32
d) 18 Answer: b
Explanation: Given, (A7, ⊗7) =({1, 2, 3, 4, 5, 6}, ⊗7) and the
union of two sub groups X and Y,X = {1, 3, 6} Y={2, 3, 5} is X𝖴Y =
{1, 2, 3, 5, 6} i.e., 5. Here, the order of the union cannot be divided by order of the group.

177. A relation (34 × 78) × 57 = 57 ×


(78 × 34) can have property.
a) distributive
b) associative
c) commutative
d) closureAnswer: b
Explanation: For any three elements (numbers) a, b and c associative property describes a
× (b × c) = (a × b) × c [for
multiplication]. Hence associative property is true for multiplication and it is true for multiplication
also.

178. If group G has 65 elements and it has two subgroups namely K and L with order 14 and 30.
What can be order of K intersection L?
a) 10
b) 42
c) 5
d) 35 Answer: c
Explanation: As it is an intersection so the order must divide both K and L. Here 3, 6, 30 does not
divide 14. But 5 must be the order of the group as it divides the order of intersection of K and L as
well as the order ofthe group.

179. In a group there must be only


element.
a) 1
b) 2
c) 3
d) 5 Answer: a
Explanation: There can be only one identity element in a group and each element in a group has
exactly one inverse element.
Hence, two important consequences of the group axioms are the uniqueness of the identity
element and the uniqueness of inverse elements.

180. is the multiplicative identity of natural numbers.


a) 0
118
b) -1
c) 1
d) 2 Answer: c
Explanation: 1 is the multiplicative identity of natural numbers as a⋅1=a=1⋅a ∀a ∈ N. Thus, 1 is the
identity of multiplication for the set of integers (Z), set of rational numbers (Q), and set of real
numbers (R).

181. An identity element of a grouphas element.


a) associative
b) commutative
c) inverse
d) HomomorphismAnswer: c
Explanation: By the definition of all elements of a group have an inverse. For an element, a in a
group G, an inverse of a is an element b such that a b = e, where e is the identity in the group. The
inverse of an elementis unique and usually denoted as -a.

182. A trivial subgroup consists of


Identity element
a) Co-set
b) Inverse element
c) Ring Answer: a
Explanation: Let G be a group under a binary operation * and a subset H of G is called a subgroup
of G if H forms a group under the operation *. The trivial subgroup of any group is the subgroup
consisting of only the Identity element.

183. Minimum subgroup of a groupis called____________


a) a commutative subgroup
b) a lattice
c) a trivial group
d) a monoidAnswer: c
Explanation: The subgroups of any given group form a complete lattice under inclusion termed asa
lattice of subgroups. If o is the Identity element of a group(G), then the trivial group(o) is the
minimum subgroup of that group and G is the maximum subgroup.

184. Let K be a group with 8 elements. Let H be a subgroup of K and H<K. It is known that the size
of H is at least 3. The size of H is____________
a) 8
b) 2
c) 3
d) 4
Answer: d
Explanation: For any finite groupG, the order (number of elements) of every subgroup L of G divides
the order of G. G has 8 elements. Factors of 8 are 1, 2, 4 and 8. Since given the size of L is at least
3(1 and 2 eliminated) and not equal to G(8 eliminated), the only size left is 4. Size of L is 4.

185. a * H is a set of co-set.


119
a) right
b) left
c) sub
d) semi
Answer: b
Explanation: Let (H, *) be the semi-group of the group (G, *). Let a belongs to G. (a * H) is theset of
a left co-set of H in G and(H * a) be the set of a right co- set of H in G.

186. a * H = H * a relation holds if__________


a) H is semi-group of an Abeliangroup
b) H is monoid of a group
c) H is a cyclic group
d) H is subgroup of an Abeliangroup
Answer: d
Explanation: If h is the subgroup of an Abelian group G, then the set of left co-sets of H in G is to
be set of right co-sets i.e., a * H =H * a. Hence, subgroup is called the normal subgroup.

187. Lagrange’s theorem specifies


a) the order of semi-group isfinite
b) the order of the subgroup divides the order of the finitegroup
c) the order of an Abelian groupis infinite
d) the order of the semi-group is added to the order of the group
Answer: b
Explanation: Lagrange’s theorem satisfies that the order of the subgroup divides the order of the
finite group.

188. An infinite cyclic group doesnot have a series.


a) AP
b) GP
c) Composite
d) Finite Answer: c
Explanation: Suppose that any finite group of order less than n has a composition series. Let G be
a finite group of order n. If G is simple, then G ⊳ {e}, where e is the identity element of G and hence,
it is a composition [Link], any infinite cyclic group does not have a composite series.

189. Every cyclic group is a/an


a) infinite subgroup
b) Abelian group
c) monoid
d) commutative semi-group
Answer: b
Explanation: Let C be a cyclic group with a generator g ∈ C. Namely, we have G = {g. Let x and y be
arbitrary elements in [Link], there exists n, m ∈ Z such that x = g n and y = g m. It follows that x*y
= g n * g m = g n + m = gm * g n = y x. Hence, wefind that x y = y x for any x, y belongs to G. Thus, G
is an Abelian group.

120
190. What is an irreduciblemodule?
a) A cyclic module in a ring withany non-zero element as its generator
b) A cyclic module in a ring withany positive integer as its generator
c) An acyclic module in a ringwith rational elements as its generator
d) A linearly independent module in a semigroup with aset of real numbers
Answer: a
Explanation: Let a ∈ M be any nonzero element and consider the sub-module (a) generated by the
element a. Since a is a nonzero element, the sub- module (a) is non-zero. Since M
is irreducible, this implies that M = (a). Hence M is a cyclic module generated by a. Since a is any
nonzero element, the module Mis a cyclic module with any nonzero element as its generator.

191. Consider an integer 23 such that 23 >= 3p for a 2p-cycle in apermutation group, then p is
a) odd prime
b) even prime
c) rational number
d) negative primeAnswer: a
Explanation: Let n an integer such that n>=3p and m is a 2p- cycle in the permutation group, then p
is an odd prime.

192. Which one of the following istrue?


a) The resolvent of two Hornclauses is not a Horn clause
b) The resolvent of two Hornclauses is a Horn clause
c) If we resolvent a negated goal G against a fact or rule A to get clause C then C has positive
literal or non-null goal
d) If we resolvent a negated goal G against a fact or rule A toget clause C then C has positive
literal or null goal
Answer: b
Explanation: a)The resolvent oftwo Horn clauses is not a Horn clause. False
b) The resolvent of two Hornclauses is a Horn clause. True
c) If we resolve a negated goal G against a fact or rule A to get clause C then C has positive literal
or non-null goal. False
d) If we resolve a negated goal G against a fact or rule A to get clause C then C has positive literal
or null goal. False
So, option (B) is correct.

193. Which of the following statements is the negation of the statements “4 is odd or -9 is
positive”?
a) 4 is even or -9 is not negative
b) 4 is odd or -9 is not negative
c) 4 is even and -9 is negative
d) 4 is odd and -9 is not negativeAnswer: c
Explanation: Using De Morgan’sLaw ~ (A V B) ↔ ~A 𝖠 ~B.

194. Consider the following LPP :Min Z = 2x1+x2+3x3


Subject to:
121
x1−2x2+x3 ≥ 4
2x1+x2+x3 ≤ 8
x1−x3 ≥ 0 x1, x2, x3 ≥ 0

The solution of this LPP usingDual Simplex Method is:


a) x1=0, x2=0, x3=3 and Z=9
b) x1=0, x2=6, x3=0 and Z=6
c) x1=4, x2=0, x3=0 and Z=8
d) x1=2, x2=0, x3=2 and Z=10
Answer: c

195. Consider the following LPP :Max Z = 15x1+10x2 Subject to:


4x1+6x2 ≤ 360
3x1+0x2 ≤ 180
0x1+5x2 ≤ 200
x1, x 2 ≥ 0
The solution of the LPP using Graphical solution technique is :
a) x1=60, x2=0 and Z=900
b)x1=60, x2=20 and Z=1100
c) x1=60, x2=30 and Z=1200
d)x1=50, x2=40 and Z=1150
Answer: b

Explanation:

X1/90 + X2/60 ≤ 1X1 / 60 ≤ 1


X2 / 40≤1
Z max = 15X1 + 10X2
ZB = 15 × 60 + 10 × 20 = 1100
ZC = 15 × 30 + 10 × 40 = 850
ZA = 15 × 60 + 10 × 0 = 900
ZD = 15 × 0 + 10 × 40 = 400

196. Let P, Q, R and S be Propositions. Assume that the equivalences P ⇔ (Q ∨ ¬ Q) and Q ⇔ R


hold. Then the truth value of the formula (P 𝖠 Q) ⇒ ((P 𝖠 R) ∨ S) is always:
a) True
122
b) False
c) Same as truth table of Q
d) Same as truth table of S
Answer: a
Explanation: P ⇔ (Q ∨ ¬ Q) "P should be true because RHS willbe TRUE always”
Q ⇔ R "when Q is true R is true" and” when Q is false R is false" (P𝖠Q) ⇒ ((P𝖠R) ∨ S) (P𝖠Q) ⇒
((P𝖠R) ∨ S) there can be only 2 cases (value of S doesn't matter)
a) P = True, Q = True and R =True
(T𝖠T) ⇒ ((T𝖠T) ∨ S) (T𝖠T) ⇒
((T𝖠T)∨S) so this case is True
b) P =True, Q = R = False (T𝖠F) ⇒ ((P𝖠R) ∨ S) (T𝖠F) ⇒((P𝖠R) ∨ S)
In case implication if the premise is false then whole statement is true this case is also true. The
given expression is true in both the cases.

197. The relation between sets A, B,C as shown by venn diagram is____________.
a) A is subset of B and B is subsetof C
b) C is not a subset of A and A issubset of B
c) C is subset of B and B is subsetof A
d) None of the mentioned
Answer: c
Explanation: As set C is totally inside set B, set B is totally inside set A.

198. If in sets A, B, C, the set B ∩ C consists of 8 elements, set A ∩ B consists of 7 elements and
set C
∩ A consists of 7 elements then the minimum element in set A UB U C will be?
a) 8
b) 14
c) 22
d) 15
Answer: a
Explanation: For minimum elements set B and C have 8 elements each and all of the elements are
same, also set A should have 7 elements whichare already present in B and [Link] A U B U C ≡ A ≡
B.

199. The set of positive integers is____________.


Infinite
a) Finite
b) Subset
c) Empty
Answer: a
Explanation: The set of positiveintegers is not finite.

200. “Match will be played only if itis not a humid day.” The negation of this statement is?
a) Match will be played but it is a humid day
b) Match will be played or it is a humid day
c) All of the mentionedstatement are correct
123
d) None of the mentionedAnswer: a
Explanation: Negation of P->Q isP𝖠~Q.

201. Which of the following statements is the negation of the statements “4 is odd or -9 is
positive”?
a) 4 is even or -9 is not negative
b) 4 is odd or -9 is not negative
c) 4 is even and -9 is negative
d) 4 is odd and -9 is not negative
Answer: c
Explanation: Using De Morgan’s Law
~(A V B) ↔ ~A 𝖠 ~B.

202. Which of the following represents: ~A (negation of A) if A stands for “I like badminton but
hatemaths”?
a) I hate badminton and maths
b) I do not like badminton or maths
c) I dislike badminton but love maths
d) I hate badminton or like maths
Answer: d
Explanation: De Morgan’s Law ~ (A 𝖠 B) ↔ ~A V ~B.

203. The compound statement A v ~(A 𝖠 B).


a) True
b) False
Answer: a
Explanation: Applying De-Morgan’slaw we get A v ~ A Ξ Tautology.

204. Which of the following is De-Morgan’s law?


a) P 𝖠 (Q v R) Ξ (P 𝖠 Q) v (P 𝖠 R)
b) ~(P 𝖠 R) Ξ ~P v ~R, ~(P v R) Ξ ~P 𝖠~R
c) P v ~P Ξ True, P 𝖠 ~P Ξ False
d) None of the mentioned
Answer: b
Explanation: Definition of De–Morgan’s Law.

205. What is the dual of (A 𝖠 B) v (C 𝖠 ?


a) (A V B) v (C v D)
b) (A V B) ^ (C v D)
c) (A V B) v (C 𝖠 D)
d) (A 𝖠 B) v (C v D)
Answer: b
Explanation: In dual 𝖠 is replaced by vand vice – versa.

206. ~ A v ~ B is logically equivalent


to?
124
a) ~ A → ~ B
b) ~ A 𝖠 ~ B
c) A → ~B
d) B V A
Answer: c
Explanation: By identity A → B Ξ ~A VB.

207. Negation of statement (A 𝖠 B) →(B 𝖠 C) is


a) (A 𝖠 B) →(~B 𝖠 ~C)
b) ~(A 𝖠 B) v ( B v C)
c) ~(A →B) →(~B 𝖠 C)
d) None of the mentioned
Answer: a
Explanation: ~(A →B) Ξ A 𝖠 ~B usingthis we can easily fetch the answer.

208. Which of the following satisfiescommutative law?


a) 𝖠
b) v
c) ↔
d) All of the mentioned
Answer: d
Explanation: All of them satisfiescommutative law.

209. If the truth value of A v B is true,then truth value of ~A 𝖠 B can be________


a) True if A is false
b) False if A is false
c) False if B is true and A is false
d) None of the mentioned
Answer: a
Explanation: If A is false then boththe condition are obeyed.

210. If P is always against the testimony of Q, then the compoundstatement P→(P v ~Q) is a
a) Tautology
b) Contradiction
c) Contingency
d) None of the mentioned
Answer: a
Explanation: Since either hypothesis is false or both (hypothesis as well asconclusion) are true.

211. Let P (x) denote the statement“x >7.” Which of these have truth value true?
a) P (0)
b) P (4)
c) P (6)
d) P (9)
Answer: d
Explanation: Put x=9, 9>7 which is true.
125
212. Let Q(x) be the statement “x < 5.” What is the truth value of the quantification ∀xQ(x), having
domains as real numbers.
a) True
b) False
Answer: b
Explanation: Q(x) is not true for everyreal number x, because, for instance, Q(6) is false. That is, x =
6 is a counterexample for the statement
∀xQ(x). This is false.

213. Determine the truth value of ∀n(n + 1 > n) if the domain consists ofall real numbers.
a) True
b) False
Answer: a
Explanation: There are no elementsin the domain for which the statement is false.

214. Let P(x) denote the statement “x = x + 7.” What is the truth value of the quantification ∃xP(x),
where thedomain consists of all real numbers?
a) True
b) False
Answer: b
Explanation: Because P(x) is false for every real number x, the existential quantification of Q(x),
which is ∃xP(x), is false.

215. Let R (x) denote the statement “x > 2.” What is the truth value of the quantification ∃xR(x),
having domainas real numbers?
a) True
b) False
Answer: a
Explanation: Because “x > 2” is sometimes true—for instance, when x = 3–the existential
quantification ofR(x), which is ∃xR(x), is true.

216. The statement,” Every comedianis funny” where C(x) is “x is a


comedian” and F (x) is “x is funny” and the domain consists of all people.
a) ∃x(C(x) 𝖠 F (x))
b) ∀x(C(x) 𝖠 F (x))
c) ∃x(C(x) → F (x))
d) ∀x(C(x) → F (x))
Answer: d
Explanation: For every person x, ifcomedian then x is funny.

217. The statement, “At least one of your friends is perfect”. Let P (x) be “x is perfect” and let F (x)
be “x is your friend” and let the domain be all people.
a) ∀x (F (x) → P (x))
b) ∀x (F (x) 𝖠 P (x))
c) ∃x (F (x) 𝖠 P (x))
d) ∃x (F (x) → P (x))
126
Answer: c
Explanation: For some x, x is friendand funny.

218. ”Everyone wants to learn cosmology.” This argument may betrue for which domains?
a) All students in your cosmologyclass
b) All the cosmology learningstudents in the world
c) Both of the mentioned
d) None of the mentioned
Answer: c
Explanation: Domain may be limited to your class or may be whole world both are good as it
satisfies universalquantifier.

219. Let domain of m includes all students, P (m) be the statement “m spends more than 2 hours
in playingpolo”. Express ∀m ¬P (m) quantification in English.
a) A student is there who spends more than 2 hours in playing polo
b) There is a student who does not spend more than 2 hours in playingpolo
c) All students spends more than 2hours in playing polo
d) No student spends more than 2hours in playing polo
Answer: d
Explanation: There is no student whospends more than 2 hours in playing polo.

220. Determine the truth value of statement ∃n (4n = 3n) if the domainconsists of all integers.
a) True
b) False
Answer: a
Explanation: For n=0, 4n=3n hence, itis true.

221. Let Q(x, y) denote “M + A = 0.”What is the truth value of the quantifications ∃A∀M Q(M, A).
a) True
b) False
Answer: b
Explanation: For each A there exist only one M, because there is no realnumber A such that M + A =
0 for allreal numbers M.

222. Translate ∀x∃y(x < y) in English,considering domain as a real numberfor both the variable.
a) For all real number x there exists areal number y such that x is less thany
b) For every real number y there exists a real number x such that x isless than y
c) For some real number x there exists a real number y such that x isless than y
d) For each and every real number xand y such that x is less than y
Answer: a
Explanation: Statement is x is less than y. Quantifier used are for each x,there exists a y.

223. “The product of two negativereal numbers is not negative.” Is given by?
a) ∃x ∀y ((x < 0) 𝖠 (y < 0) → (xy > 0))
b) ∃x ∃y ((x < 0) 𝖠 (y < 0) 𝖠 (xy > 0))
c) ∀x ∃y ((x < 0) 𝖠 (y < 0) 𝖠 (xy > 0))
127
d) ∀x ∀y ((x < 0) 𝖠 (y < 0) → (xy > 0))
Answer: d
Explanation: For every negative real number x and y, the product of theseinteger is positive.

224. Let Q(x, y) be the statement “x + y = x − y.” If the domain for both variables consists of all
integers, whatis the truth value of ∃xQ(x, 4).
a) True
b) False
Answer: b
Explanation: There exist no integerfor which x+4=x-4.

225. Let L(x, y) be the statement “x loves y,” where the domain for both x and y consists of all
people in the world. Use quantifiers to express, “Joy is loved by everyone.”
a) ∀x L(x, Joy)
b) ∀y L(Joy,y)
c) ∃y∀x L(x, y)
d) ∃x ¬L(Joy, x)
Answer: a
Explanation: Joy is loved by all thepeople in the world.

226. Let T (x, y) mean that student x likes dish y, where the domain for x consists of all students at
your schooland the domain for y consists of all dishes. Express ¬T (Amit, South Indian) by a simple
English sentence.
a) All students does not like SouthIndian dishes.
b) Amit does not like South Indianpeople.
c) Amit does not like South Indiandishes.
d) Amit does not like some dishes.
Answer: d
Explanation: Negation of the statement Amit like South Indiandishes.

227. Express, “The difference of a realnumber and itself is zero” using required operators.
a) ∀x(x − x! = 0)
b) ∀x(x − x = 0)
c) ∀x∀y(x − y = 0)
d) ∃x(x − x = 0)
Answer: b
Explanation: For every real number x,difference with itself is always zero.

228. Which rule of inference is used in each of these arguments, “If it is Wednesday, then the
Smartmart willbe crowded. It is Wednesday. Thus, the Smartmart is crowded.”
a) Modus tollens
b) Modus ponens
c) Disjunctive syllogism
d) Simplification
Answer: b
Explanation: (M 𝖠 (M → N)) → N isModus ponens.
128
229. Which rule of inference is used in each of these arguments, “If it hailstoday, the local office
will be closed. The local office is not closed
today. Thus, it did not hailed today.”
a) Modus tollens
b) Conjunction
c) Hypothetical syllogism
d) Simplification Answer: a
Explanation: (¬N 𝖠 (M → N)) → ¬M isModus tollens.

230. Which rule of inference is used, ”Bhavika will work in an enterprise this summer. Therefore,
this summerBhavika will work in an enterprise or he will go to beach.”
a) Simplification
b) Conjunction
c) Addition
d) Disjunctive syllogism
Answer: c
Explanation: p → (p ∨ q) argument is‘Addition’.

231. What rule of inference is usedhere?


“It is cloudy and drizzling [Link], it is cloudy now.”
a) Addition
b) Simplification
c) Resolution
d) Conjunction
Answer: b
Explanation: (p 𝖠 q) → p argument isSimplification.

232. What rule of inference is used inthis argument?


“If I go for a balanced diet, then I willbe fit. If I will be fit, then I will remainhealthy. Therefore, if I go
for a balanced diet, then I will remain
healthy.”
a) Modus tollens
b) Modus ponens
c) Disjunctive syllogism
d) Hypothetical syllogism
Answer: d
Explanation: ((p → q) 𝖠 (q → r)) → (p→ r) argument is ‘Hypotheticalsyllogism’.

233. What rules of inference are usedin this argument?


“All students in this science class has taken a course in physics” and “Marry is a student in this
class” imply the conclusion “Marry has taken a coursein physics.”
a) Universal instantiation
b) Universal generalization
c) Existential instantiation

129
d) Existential generalization
Answer: a
Explanation: ∀xP (x), ∴ P (c) Universalinstantiation.

234. What rules of inference are usedin this argument?


“It is either colder than Himalaya today or the pollution is harmful. It ishotter than Himalaya today.
Therefore, the pollution is harmful.”
a) Conjunction
b) Modus ponens
c) Disjunctive syllogism
d) Hypothetical syllogism
Answer: c
Explanation: ((p ∨ q) 𝖠 ¬p) → q argument is Disjunctive syllogism.

235. The premises (p 𝖠 q) ∨ r and r →s implies which of the conclusion?


a) p ∨ r
b) p ∨ s
c) q ∨ s
d) q ∨ r
Answer: b
Explanation: The premises (p 𝖠 q) ∨ r as two clauses, p ∨ r and q ∨ r. We can also replace r → s by
the equivalent clause ¬r ∨ s. using the two clauses p ∨ r and ¬r ∨ s, we can use resolution to
conclude p ∨ s.

236. {x: x is an integer neither positive nor negative} is


a) Empty set
b) Non-empty set
c) Finite set
d) Non- empty and Finite set
Answer: d
Explanation: Set = {0} non-empty andfinite set.

237. {x: x is a real number between 1and 2} is an


a) Infinite set
b) Finite set
c) Empty set
d) None of the mentioned
Answer: a
Explanation: It is an infinite set as there are infinitely many real number between any two different
real numbers.

238. Write set {1, 5, 15, 25,…} in set-builder form.


a) {x: either x=1 or x=5n, where n is areal number}
b) {x: either x=1 or x=5n, where n is ainteger}
c) {x: either x=1 or x=5n, where n isan odd natural number}
130
d) {x: x=5n, where n is a naturalnumber}
Answer: c
Explanation: Set should include 1 oran odd multiple of 5.

239. Express {x: x= n/ (n+1), n is a natural number less than 7} in rosterform.


a) {1⁄2, 2⁄3, 4⁄5, 6⁄7}
b) {1⁄2, 2⁄3, 3⁄4, 4⁄5, 5⁄6, 6⁄7, 7⁄8}
c) {1⁄2, 2⁄3, 3⁄4, 4⁄5, 5⁄6, 6⁄7}
d) Infinite set
Answer: c
Explanation: n/(n+1) = 1/(1+1)
= 1⁄2 and n>7.

240. Number of power set of {a, b}, where a and b are distinct elements.
a) 3
b) 4
c) 2
d) 5
Answer: b
Explanation: Power set of {a, b} = {∅,
{a, b}, {a}, {b}}.

241. Which of the following is subsetof set {1, 2, 3, 4}?


a) {1, 2}
b) {1, 2, 3}
c) {1}
d) All of the mentioned
Answer: d
Explanation: There are total 16subsets.

242. A = {∅,{∅},2,{2,∅},3}, which ofthe following is true?


a) {{∅,{∅}} ∈ A
b) {2} ∈ A
c) ∅ ⊂ A
d) 3 ⊂ A
Answer: c
Explanation: Empty set is a subset ofevery set.

243. Subset of the set A= { } is?


a) A
b) {}
c) ∅
d) All of the mentioned
Answer: d
Explanation: Every set is subset of itself and Empty set is subset of eachset.

244. A____________is an orderedcollection of objects.


131
a) Relation
b) Function
c) Set
d) Proposition
Answer: c
Explanation: By the definition of set.

245. The set O of odd positiveintegers less than 10 can be expressed by a) {1, 2, 3}
b) {1, 3, 5, 7, 9}
c) {1, 2, 5, 9}
d) {1, 5, 7, 9, 11}
Answer: b
Explanation: Odd numbers less than10 is {1, 3, 5, 7, 9}.

246. Power set of empty set hasexactly subset.


a) One
b) Two
c) Zero
d) Three
Answer: a
Explanation: Power set of null set hasexactly one subset which is empty set.

247. What is the Cartesian product ofA = {1, 2} and B = {a, b}?
a) {(1, a), (1, b), (2, a), (b, b)}
b) {(1, 1), (2, 2), (a, a), (b, b)}
c) {(1, a), (2, a), (1, b), (2, b)}
d) {(1, 1), (a, a), (2, a), (1, b)}
Answer: c
Explanation: A subset R of the Cartesian product A x B is a relationfrom the set A to the set B.

248. The Cartesian Product B x A is equal to the Cartesian product A x B.


a) True
b) False
Answer: b
Explanation: Let A = {1, 2} and B = {a, b}. The Cartesian product A x B = {(1, a), (1, b), (2, a), (2, b)}
and the Cartesian product B x A = {(a, 1), (a, 2), (b, 1), (b, 2)}. This is not equal to Ax B.

249. The union of the sets {1, 2, 5}and {1, 2, 6} is the set
a) {1, 2, 6, 1}
b) {1, 2, 5, 6}
c) {1, 2, 1, 2}
d) {1, 5, 6, 3}
Answer: b
Explanation: The union of the sets Aand B, is the set that contains those elements that are either in
A or in B.

250. The intersection of the sets {1, 2,5} and {1, 2, 6} is the set
132
a) {1, 2}
b) {5, 6}
c) {2, 5}
d) {1, 6}
Answer: a
Explanation: The intersection of the sets A and B, is the set containing those elements that are in
both A and B.

251. Two sets are called disjoint if there is the emptyset.


a) Union
b) Difference
c) Intersection
d) Complement
Answer: c
Explanation: By the definition of thedisjoint set.

252. Which of the following two setsare disjoint?


a) {1, 3, 5} and {1, 3, 6}
b) {1, 2, 3} and {1, 2, 3}
c) {1, 3, 5} and {2, 3, 4}
d) {1, 3, 5} and {2, 4, 6}
Answer: d
Explanation: Two sets are disjoint ifthe intersection of two sets is the empty set.

253. The difference of {1, 2, 3} and {1,2, 5} is the set


a) {1}
b) {5}
c) {3}
d) {2}
Answer: c
Explanation: The difference of the sets A and B denoted by A-B, is the set containing those
elements thatare in A not in B.

254. The complement of the set A is____________.


a) A – B
b) U – A
c) A – U
d) B – A
Answer: b
Explanation: The complement of theset A is the complement of A with respect to U.

255. The bit string for the set {2, 4, 6, 8, 10} (with universal set of natural numbers less than or
equal to 10) is
a) 0101010101
b) 1010101010
c) 1010010101
d) 0010010101
133
Answer: a
Explanation: The bit string for the set has a one bit in second, fourth, sixth, eighth, tenth positions,
and a zero elsewhere.

256. Let Ai = {i, i+1, i+2, …..}. Then set {n, n+1, n+2, n+3, …..} is the____________ of the set Ai.
a) Union
b) Intersection
c) Set Difference
d) Disjoint
Answer: b
Explanation: By the definition of thegeneralized intersection of the set.

257. Let the set A is {1, 2, 3} and B is


{2, 3, 4}. Then the number ofelements in A U B is?
a) 4
b) 5
c) 6
d) 7
Answer: a
Explanation: AUB is {1, 2, 3, 4}.

258. Let the set A is {1, 2, 3} and B is {2, 3, 4}. Then number of elements in A ∩ B is?
a) 1
b) 2
c) 3
d) 4
Answer: b
Explanation: A ∩ B is {2, 3}.

259. Let the set A is {1, 2, 3} and B is


{2, 3, 4}. Then the set A – B is?a) {1, -4}
b) {1, 2, 3}
c) {1}
d) {2, 3}
Answer: c
Explanation: In A – B the commonelements get cancelled.

260. In which of the following sets A –B is equal to B – A?


a) A = {1, 2, 3}, B = {2, 3, 4}
b) A = {1, 2, 3}, B = {1, 2, 3, 4}
c) A = {1, 2, 3}, B = {2, 3, 1}
d) A = {1, 2, 3, 4, 5, 6}, B = {2, 3, 4, 5,
1}
Answer: c
Explanation: A- B= B-A = Empty set.

134
261. Let A be set of all prime numbers, B be the set of all even prime numbers, C be the set of all
odd prime numbers, then which ofthe following is true?
a) A ≡ B U C
b) B is a singleton set.
c) A ≡ C U {2}
d) All of the mentioned
Answer: d
Explanation: 2 is the only even primenumber.

262. If A has 4 elements B has 8 elements then the minimum and maximum number of elements
in A UB are
a) 4, 8
b) 8, 12
c) 4, 12
d) None of the mentioned
Answer: b
Explanation: Minimum would be when 4 elements are same as in 8, maximum would be when all
are distinct.

263. The shaded area of figure is best described by?

a) A∩B
b) AUB
c) A
d) B
Answer: a
Explanation: The region is Aintersection B.

264. The shaded area of figure is bestdescribed by?

a. A‘ (Complement of A)
b. A U B -B
c. A ∩ B
d. B
Answer: b
Explanation: The region iscomplement of B.
135
265. If n(A)=20 and n(B)=30 and n(AU B) = 40 then n(A ∩ B) is?
a) 20
b) 30
c) 40
d) 10
Answer: d
Explanation: n(A U B) = n(A) + n(B) –n(A ∩ B).

266. A function is said to be


if and only if f(a) = f(b) implies that a = b for all a and b inthe domain of f.
a) One-to-many
b) One-to-one
c) Many-to-many
d) Many-to-one
Answer: b
Explanation: A function is one-to-oneif and only if f(a)≠f(b) whenever a≠b.

267. The function f(x)=x+1 from theset of integers to itself is onto. Is it True or False?
a) True
b) False
Answer: a
Explanation: For every integer “y” there is an integer “x ” such that f(x) =y.

268. The value of ⌊1/2.⌊5/2⌋ ⌋ is________________.


a) 2
b) 3
d) 0.5
Answer: a
Explanation: The value of ⌊5/2⌋ is 2so, the value of ⌊1/2.2⌋ is 1.

269. Which of the following function f: Z X Z → Z is not onto?


a) f(a, b) = a + b
b) f(a, b) = a
c) f(a, b) = |b|
d) f(a, b) = a – b
Answer: c
Explanation: The function is not ontoas f(a)≠b.

270. The domain of the function that assign to each pair of integers the maximum of these two
integers is_____________.
a) N
b) Z
c) Z +
d) Z+ X Z+
136
Answer: d
Explanation: The domain of theintegers is Z+ X Z+.

271. How many even 4 digit wholenumbers are there?


a) 1358
b) 7250
c) 4500
d) 3600
Answer: c
Explanation: The thousands digit cannot be zero, so there are 9 choices. There are 10 possibilities
for the hundreds digit and 10 possibilities for the tens digit. The units digit can be 0, 2, 4, 6 or 8, so
there are 5 choices. By the basic counting principle, the number of even five digit whole numbers is
9 × 10 × 10 × 5 = 45,00.

272. In a multiple-choice question paper of 15 questions, the answers can be A, B, C or D. The


number of different ways of answering the question paper are
a) 65536 x 47
b) 194536 x 45
c) 23650 x 49
d) 11287435
Answer: a
Explanation: There are 415 = 65536 x47 different ways of answering the exam paper of 15 MCQs.

273. How many words with seven letters are there that start with a vowel and end with an A? Note
that they don’t have to be real words andletters can be repeated.
a) 45087902
b) 64387659
c) 12765800
d) 59406880
Answer: d
Explanation: The first letter must be a vowel, so there are 5 choices. The second letter can be any
one of 26, the third letter can be any one of 26, the fourth letter can be any one of 26 and fifth and
sixth letters can be any of 26 choices. The last letter must bean A, so there is only 1 choice. By the
basic counting principle, the numberof ‘words’ is 5 × 26 × 26 × 26 × 26 × 26 × 1 = 59406880.

274. Neela has twelve different skirts, ten different tops, eight different pairs of shoes, three
different necklaces and five different [Link] how many ways can Neela dress up?
a) 50057
b) 14400
c) 34870
d) 56732
Answer: b
Explanation: By the basic counting principle, the number of different ways = 12 × 10 × 8 × 3 × 5 =
14400. Note that shoes come in pairs. So she must choose one pair of shoes from ten pairs, not
one shoe from twenty.

275. How many five-digit numbers can be made from the digits 1 to 7 ifrepetition is allowed?
a) 16807
137
b) 54629
c) 23467
d) 32354
Answer: a
Explanation: 75 = 16807 ways of making the numbers consisting of five digits if repetition is
allowed.

276. For her English literature course, Ruchika has to choose one novel to study from a list of ten,
one poem from a list of fifteen and one short story from a list of seven. How many different
choices does Rachel have? a) 34900
b) 26500
c) 12000
d) 10500
Answer: d
Explanation: By the Basic Counting Principle, the number of different choices is 10 × 15 × 7 =
10500.

277. There are two different Geography books, five different Natural Sciences books, three
different History books and four different Mathematics books on a shelf. In how many different
ways canthey be arranged if all the books of the same subjects stand together?
a) 353450
b) 638364
c) 829440
d) 768700
Answer: c
Explanation: There are four groups of books which can be arranged in 4! different ways. Among
those books, two are Geography books, five are Natural Sciences books, three are History books
and four are Mathematics books. Therefore, thereare 4! × 2! × 5! × 3! × 4! = 829440 ways to arrange
the books.

278. The code for a safe is of the form PPPQQQQ where P is any number from 0 to 9 and Q
represents the letters of the alphabet. How many codes are possible for each of the following
cases? Note that the digits and letters of the alphabet can be repeated.
a) 874261140
b) 537856330
c) 549872700
d) 456976000
Answer: d
Explanation: 103 × 264 = 456976000 possible codes are formed for the safe with the alphanumeric
digits.

279. Amit must choose a seven-digit PIN number and each digit can be chosen from 0 to 9. How
many different possible PIN numbers can Amit choose?
a) 10000000
b) 9900000
c) 67285000
d) 39654900
Answer: a
138
Explanation: By the basic counting principle, the total number of PIN numbers Amit can choose is
10 × 10 ×10 × 10 × 10 × 10 × 10 = 10,000000.

280. A head boy, two deputy head boys, a head girl and 3 deputy head girls must be chosen out of
a studentcouncil consisting of 14 girls and 16 boys. In how many ways can they arechosen?
a) 98072
b) 27384
c) 36428
d) 44389
Answer: b
Explanation: There are 16 × 15 × 14 + 14 × 13 × 12 × 11 = 27384 ways to choose from a student
council.

281. A drawer contains 12 red and 12 blue socks, all unmatched. A person takes socks out at
random in the dark. How many socks must he take out to be sure that he has at least two blue
socks?
a) 18
b) 35
c) 28
d) 14

282. How many substrings (of all lengths inclusive) can be formed from a character string of
length 8? (Assume all characters to be distinct)
a) 14
b) 21
c) 54
d) 37
Answer: d
Explanation: Let’s consider the given string is CLEAN, so set of string of length 1 = {C,L,E,A,N} ;
cardinality of set = 5 set of string of length 2 = {CL,EE,EA,NN}, set of string of length 3 =
{CLE,LEE,EAN}, set of strings of length 4 = {CLEN,LEAN}, set of strings of length 5 = {CLEAN} and
set of stringof length 0 = {} and we cannot have any substring of length 6 as given string has only 5
length. So total no of substrings are possible = 0 length substring + 1 length substring + 2 length
substrings +3 length substrings + 4 length substrings + 5 length substrings = 1 + 5 + 4 + 3 + 2 + 1 =
16means for 1 length string to n lengthsubstrings it will sum of the n naturalno from 1 to n.
so 1+2+3+…+n = n(n+1)2 so total no substrings possible = 0 length strings + n(n+1)2 = 1+ [n(n+1)2]
so total no of substrings possible in n length string (All length inclusive )= 1 + [n(n+1)2]=8(8+1)2 =
37.

283. The number of diagonals can bedrawn in a hexagon is


a) 9
b) 32
c) 16
d) 21
Answer: a
Explanation: A hexagon has 6 [Link] obtain the diagonals by joining the vertices in pairs.

139
Total number of sides and diagonals
= 6C2 = 6∗52∗1 = 5×3 = 15. This
includes its 6 sides also. So, Diagonals
= 15 – 6 = 9. Hence, the number ofdiagonals is 9.

284. The number of binary strings of 17 zeros and 8 ones in which no two ones are adjacent is a)
43758
b) 24310
c) 32654
d) 29803
Answer: a
Explanation: First place 17 zeroes sideby side _ 0 _ 0 _ 0 … 0 _ and 8 1’s can be placed in any of the
(17+1) available gaps hence the number ofways = n+1Ck = 43758.

285. How many words that can be formed with the letters of the word ‘SWIMMING’ such that the
vowels donot come together? Assume that words are of with or without meaning.
a) 430
b) 623
c) 729
d) 1239
Answer: c
Explanation: The word ‘SWIMMING contains 8 letters. Of which, I occurs twice and M occurs twice.
Therefore, the number of words formed by this word = 8!2!∗2! = 10080. In order to find the number
of permutations that can be formed where the two vowels I and I come together, we group the
letters that should come together and consider that group as one letter. So, the letters are S, W, M,
M, N, G, (I, I). So, the number of letters are 7 the number of ways in which 7 letters can be arranged
is 7! = 5040. In I and I, the number of ways in which I and I can be arranged is 2!. Hence, the total
number of ways in which the letters of the ‘SWIMMING’ can be arranged such that vowels are
always together are 7!2!∗2! = 5040 ways. The number of words in which the vowels do not come
together is = (10080 – 5040) = 5040.

286. In a playground, 3 sisters and 8 other girls are playing together. In a particular game, how
many ways can all the girls be seated in a circular order so that the three sisters are not seated
together?
a) 457993
b) 3386880
c) 6544873
d) 56549
Answer: b
Explanation: There are 3 sisters and 8other girls in total of 11 girls. The number of ways to arrange
these 11 girls in a circular manner = (11– 1)! = 10!. These three sisters can now rearrange
themselves in 3! ways. By the multiplication theorem, the number of ways so that 3 sisters always
come together in the arrangement = 8! × 3!. Hence, the required number of ways in which the
arrangement can take place if none of the 3 sisters is seated together: 10! – (8! × 3!) = 3628800 –
(40320 * 6) = 3628800 – 241920 =
3386880.

287. How many numbers of three digits can be formed with digits 1, 3,5, 7 and 9?
140
a) 983
b) 120
c) 345
d) 5430
Answer: b
Explanation: Here number of digits, n
= 5 and number of places to be filled-up r = 3. Hence, the required numberis 5P3 = 5!/2!*3! = 120.

288. The size of a multiset is 6 which is equal to the number of elements in it with counting
repetitions (a multiset is an unordered collection of elements where the elements may repeat any
number of times). Determine the number of multisets can be grouped from n distinct elements so
that at least one elementoccurs exactly twice?
a) 326
b) 28
c) 45
d) 62
Answer: c
Explanation: There are six places to
be filled in the multiset using the n distinct elements. At least one element has to occur exactly
twice and that would leave 4 more places in the multiset means that at most four elements can
occur exactly once. Thus there are two mutually exclusive cases as follows: 1) Exactly one element
occurs exactly twice and select this element in n ways. Fill up the remaining four spots using 5
distinct elements from the remaining n−1 elements in n-1C4 ways. 2) Exactly four elements that
occur at least once each. Hence, the total number of ways to form the multiset is
nC + n * n-1C = 6C + 6 * 6-1C = 45.
2 4 2 4

289. There are 6 equally spaced points A, B, C, D, E and F marked on a circle with radius R. How
many convex heptagons of distinctly different areas can be drawn using these points as vertices?
a) 7! * 6
b) 7C5
c) 7!
d) same area
Answer: d
Explanation: Since all the points are equally spaced; hence the area of all the convex heptagons
will be thesame.

290. There are 2 twin sisters among a group of 15 persons. In how many ways can the group be
arranged made from 15 consonants and 5 vowels, if all the letters are differentis
a) 3! * 12C5
b) 16C4 * 4C4
around a circle so that there is exactlyone person between the two sisters?
c) 15! * 4
d) 15C4 * 5C3
* 7!
a) 15 *12! * 2!
b) 15! * 2!
c) 14C2
141
d) 16 * 15!
Answer: a
Explanation: We know that n objectscan be arranged around a circle
in (n−1)!2. If we consider the two sisters and the person in between the
Answer: d

Explanation: There are 4 consonants out of 15 can be selected in 15C4 ways and 3 vowels can be
selected
in 5C3 ways. Therefore, the total number of groups each containing 4 consonants and 3 vowels =
15C * 4C .Each group contains 7 letters which can be arranged in 7! ways. Hence,
4 3
required number of words
brothers as a block, then there will 12
others and this block of three people
= 15C4
* 5C3
* 7!.
to be arranged around a circle. The number of ways of arranging 13 objects around a circle is in
12! ways. Now the sisters can be arranged on either side of the person who is in between the
sisters in 2! ways. The person who sits in between the two sisters can be any of the 15 in the group
and can be selected in 15 [Link], the total number of ways 15 *12! * 2!.
291. The number of words of 4 consonants and 3 vowels can be
292. How many ways are there to arrange 7 chocolate biscuits and 12 cheesecake biscuits into a
row of 19biscuits?
a) 52347
b) 50388
c) 87658
d) 24976
Answer: b
Explanation: Consider the situation as having 19 spots and filling them with 7 chocolate biscuits
and 19 cheesecake biscuits. Then we just

choose 7 spots for the chocolate biscuits and let the other 10 spotshave cheesecake biscuits. The
number of ways to do this job
is 19C7 = 50388.

293. If a, b, c, d and e are five natural numbers, then find the number of ordered sets(a, b, c, d, e)
possible such that a+b+c+d+e=75.
a) 65C5
b) 58C6
c) 72C7
d) 74C4
Answer: d
Explanation: Let assumes that there are 75 identical balls which are to be arranged in 5 different
compartments (Since a, b, c, d, e are distinguishable). If the balls are arranged in the row. We have
74 gaps where we can place a ball in each gap since we need 5 compartments we need to place
only 4 balls. We can do this in 74C4 ways.
142
294. There are 15 people in a committee. How many ways are there to group these 15 people into
3, 5, and 4?
a) 846
b) 2468
c) 658
d) 1317
Answer: d
Explanation: The number of ways to choose 3 people out of 9 is 15C3. Then, number of ways to
choose 5 people out of (15-3) = 12 is 12C5. Finally, the number of ways to choose 4 people out of
(12-4) = 8 is 8C4. Hence, by the rule of product, 15C3 + 12C5 + 8C4 = 1317.

295. There are six movie parts numbered from 1 to 6. Find the number of ways in which they be
arranged so that part-1 and part-3are never together.
a) 876
b) 480
c) 654
d) 237
Answer: b
Explanation: The total number of ways in which 6 part can be arranged
= 6! = 720. The total number of ways in which part-1 and part-3 are always together: = 5!*2! = 240.
Therefore, the total number of arrangements, in which they are not together is = 720 −240 = 480.

296. How many ways are there to divide 4 Indian countries and 4 China countries into 4 groups of
2 each suchthat at least one group must have only Indian countries?
a) 6
b) 45
c) 12
d) 76
Answer: a
Explanation: The number of ways todivide 4+4=8 countries into 4 groupsof 2 each is as follows:
(10C2 * 10C2 * 10C2 * 10C2)/4! = 30. Since
it is required that at least one group must have only Indian countries, we need to subtract 30 from
the number of possible groupings where all 4 groups have 1 Indian country and 1 China country
each. This is equivalent to the number of ways to match each of the 4 Indian countries with one
China country: 4! = 24. Therefore, theanswer is 30 – 24 = 6.

297. Find the number of factors ofthe product 58 * 75 * 23 which are perfect squares.
a) 47
b) 30
c) 65
d) 19
Answer: b
Explanation: Any factor of this number should be of the form 5a * 7b * 2c. For the factor to be a
perfectsquare a, b, c has to be even. a can take values 0, 2, 4, 6, 8, b can take
values 0, 2, 4 and c can take values 0,
2. Total number of perfect squares =5 * 3 * 2 = 30.
143
297. From a group of 8 men and 6 women, five persons are to be selected to form a committee so
thatat least 3 women are there on the committee. In how many ways can itbe done?
a) 686
b) 438
c) 732
d) 549
Answer: a
Explanation: We may have (2 men and 3 women) or (1 men and 4 woman) or (5 women only). The
Required number of ways = (8C2 × 6C3) + (8C1 × 6C4) + (6C5) = 686.

298. What is the base case for theinequality 7n > n3, where n = 3?
a) 652 > 189
b) 42 < 132
c) 343 > 27
d) 42 <= 43
Answer: c
Explanation: By the principle of mathematical induction, we have 73 >33 ⇒ 343 > 27 as a base case
and it is true for n = 3.

299. In the principle of mathematicalinduction, which of the following steps is mandatory?


a) induction hypothesis
b) inductive reference
c) induction set assumption
d) minimal set representation
Answer: a
Explanation: The hypothesis of Step is a must for mathematical induction that is the statement is
true for n = k, where n and k are any natural numbers, which is also called induction assumption or
induction hypothesis.

300. For m = 1, 2, …, 4m+2 is amultiple of


a) 3
b) 5
c) 6
d) 2
Answer: d
Explanation: For n = 1, 4 * 1 + 2 = 6, which is a multiple of 2. Assume that4m+2 is true for m=k and
so 4k+2 is true based on the assumption. Now, to prove that 4k+2 is also a multiple of 2 ⇒
4(k+1)+2 ⇒ 2 * 4k – 4k + 6 ⇒2*4k+4 – 4k+2 ⇒ 2(4k+2) – 2(2k+1).
Here, the first term 2(4k+2) is true as per assumption and the second term 2(4k+2) is must to be a
multiple of 2. Hence, 4(k+1)+2 is a multiple of 2. So,by induction hypothesis, (4m+2) is a multiple of
2, for m = 1,2,3,…

301. For any integer m>=3, the series2+4+6+…+(4m) can be equivalent to


a) m2+3
b) m+1
c) mm
144
d) 3m2+4
Answer: a
Explanation: The required answer is m2+3. Now, by induction assumption, we have to prove
2+4+6+…+4(k+1) = (k+1)2+3 also can be true, 2+4+6+…+4(k+1) = 2+4+6+⋯+(4k+4)
and by the subsequent steps, we canprove that (m+1)2+3 also holds for m=k. So, it is proved.

302. A non empty set A is termed asan algebraic structure _


a) with respect to binary operation *
b) with respect to ternary operation ?
c) with respect to binary operation +
d) with respect to unary operation –
Answer: a
Explanation: A non empty set A is called an algebraic structure w.r.t binary operation “*” if (a*b)
belongsto S for all (a*b) belongs to S.
Answer: d
Explanation: A Semigroup (S,*) is defined as a monoid if there exists an element e in S such that
(a*e) = (e*a)
= a for all a in S. This element is calledidentity element of S w.r.t *.

305. A monoid is called a group if


Therefore “*” is closure operation on
‘A’.
303. An algebraic structure
is called a semigroup.
a) (P, *)
b) (Q, +, *)
c) (P, +)
d) (+, *)
Answer: a
Explanation: An algebraic structure (P,*) is called a semigroup if a*(b*c) = (a*b)*c for all a,b,c
belongs to S or the elements follow associative property under “*”. (Matrix,*) and (Set of
integers,+) are examples of semigroup.

304. Condition for monoid is


a) (a+e)=a
b) (a*e)=(a+e)
c) a=(a*(a+e)
d) (a*e)=(e*a)=a
a) (a*a)=a=(a+c)
b) (a*c)=(a+c)
c) (a+c)=a
d) (a*c)=(c*a)=e
Answer: d
Explanation: A monoid(B,*) is called Group if to each element there exists an element c such that
(a*c)=(c*a)=e. Here e is called an identity element and c is defined as the inverse of the
corresponding element.

145
306. A group (M,*) is said to beabelian if
a) (x+y)=(y+x)
b) (x*y)=(y*x)
c) (x+y)=x
d) (y*x)=(x+y)
Answer: b
Explanation: A group (M,*) is said to be abelian if (x*y) = (x*y) for all x, y belongs to M. Thus
Commutative property should hold in a group.

307. Matrix multiplication is a/an


property.
a) Commutative
b) Associative
c) Additive
d) Disjunctive
Answer: b
Explanation: The set of two M*M non-singular matrices form a groupunder matrix multiplication
operation. Since matrix multiplicationis itself associative, it holds associative property.

308. A cyclic group can be generatedby a/an element.


a) singular
b) non-singular
c) inverse
d) multiplicative
Answer: a
Explanation: A singular element can generate a cyclic group. Every element of a cyclic group is a
powerof some specific element which is known as a generator ‘g’.

309. How many properties can beheld by a group?


a) 2
b) 3
c) 5
d) 4
Answer: c
Explanation: A group holds fiveproperties simultaneously –
i) Closure
ii) associative
iii) Commutative
iv) Identity element
v) Inverse element.

310. A cyclic group is always


a) abelian group
b) monoid
c) semigroup
146
d) subgroup
Answer: a
Explanation: A cyclic group is always an abelian group but every abelian group is not a cyclic
group. For instance, the rational numbers underaddition is an abelian group but is nota cyclic one.

311. {1, i, -i, -1} is


a) semigroup
b) subgroup
c) cyclic group
d) abelian group
Answer: c
Explanation: The set of complex numbers {1, i, -i, -1} under multiplication operation is a cyclic
group. Two generators i and -i will covers all the elements of this [Link], it is a cyclic group.

312. A trivial subgroup consists of


a) Identity element
b) Coset
c) Inverse element
d) Ring
Answer: a
Explanation: Let G be a group under abinary operation * and a subset H of G is called a subgroup of
G if H forms a group under the operation *. The trivial subgroup of any group is the subgroup
consisting of only the Identity element.

313. Minimum subgroup of a group iscalled


a) a commutative subgroup
b) a lattice
c) a trivial group
d) a monoid
Answer: c
Explanation: The subgroups of any given group form a complete lattice under inclusion termed as
a lattice of subgroups. If o is the Identity element of a group(G), then the trivial group(o) is the
minimum subgroup of that group and G is themaximum subgroup.

314. Let K be a group with 8 elements. Let H be a subgroup of K and H<K. It is known that the size
of His at least 3. The size of H is
a) 8
b) 2
c) 3
d) 4
Answer: d
Explanation: For any finite group G, the order (number of elements) of every subgroup L of G
divides the order of G. G has 8 elements. Factors of 8 are 1, 2, 4 and 8. Since given the size of L is
at least 3(1 and 2 eliminated) and not equal to G(8 eliminated), the only size left is 4. Sizeof L is 4.
315. is not necessarily aproperty of a Group.
147
a) Commutativity
b) Existence of inverse for everyelement
c) Existence of Identity
d) Associativity
Answer: a
Explanation: Grupoid has closure property; semigroup has closure and associative; monoid has
closure, associative and identity property; group has closure, associative, identity and inverse; the
abelian group has group property and commutative.

316. A group of rational numbers isan example of


a) a subgroup of a group of integers
b) a subgroup of a group of realnumbers
c) a subgroup of a group of irrationalnumbers
d) a subgroup of a group of complexnumbers
Answer: b
Explanation: If we consider the abelian group as a group rational numbers under binary operation +
then it is an example of a subgroup ofa group of real numbers.

317. Intersection of subgroups is a


a) group
b) subgroup
c) semigroup
d) cyclic group
Answer: b
Explanation: The subgroup property is intersection closed. An arbitrary (nonempty) intersection of
subgroupswith this property, also attains the similar property.

318. The group of matrices with determinant is a subgroup of the group of invertible matrices
under multiplication.
a) 2
b) 3
c) 1
d) 4
Answer: c
Explanation: The group of real matrices with determinant 1 is a subgroup of the group of invertible
real matrices, both equipped with matrix multiplication. It has to be shown that the product of two
matrices with determinant 1 is another matrix with determinant 1, but this is immediate from the
multiplicative property of the determinant. This group is usually denoted by(n, R).

319. What is a circle group?


a) a subgroup complex numbers having magnitude 1 of the group ofnonzero complex elements
b) a subgroup rational numbers having magnitude 2 of the group ofreal elements
c) a subgroup irrational numbers having magnitude 2 of the group ofnonzero complex elements
d) a subgroup complex numbers having magnitude 1 of the group ofwhole numbers
Answer: a
148
Explanation: The set of complex numbers with magnitude 1 is a subgroup of the nonzero complex
numbers associated with multiplication. It is called the circle group as its elements form the unit
circle.

320. Which algorithm efficiently calculates the single source shortest paths in a Directed Acyclic
Graph?
a) topological sort
b) hash table
c) binary search
d) radix sort
Answer: a
Explanation: For Directed Acyclic graph, single source shortest distances can be calculated in
O(V+E) time. For that purpose Topological Sorting can be used. Topological Sorting of any graph
represents alinear ordering of the graph.

321. The of a graph G consists of all vertices and edges of G.


a) edge graph
b) line graph
c) path complement graph
d) eulerian circuit
Answer: d
Explanation: we know that he Eulerian circuit in a graph G is a circuit that includes all vertices and
edges of G. A graph that can have Eulerian circuit, also can have a Eulerian graph.

322. A in a graph G is a circuit which consists of every vertex (exceptfirst/last vertex) of G exactly
once.
a) Euler path
b) Hamiltonian path
c) Planar graph
d) Path complement graph
Answer: b
Explanation: The Eulerian path in a graph say, G is a walk from one vertex to another, that can pass
through all vertices of G as well as traverses exactly once every edge of G. Therefore, an Eulerian
path can not be a circuit. A Hamiltonian path is a walk that contains every vertex of the graph
exactly once. Hence, a Hamiltonian path is not a circuit.

323. A walk has Closed property if


a) v0=vk
b) v0>=vk
c) v < 0
d) vk > 1
Answer: a
Explanation: A walk in a graph is said to be closed if the starting vertex is the same as the ending
vertex, that isv0=vk, it is described as Open otherwise.

149
324. A trail in a graph can be described as
a) a walk without repeated edges
b) a cycle with repeated edges
c) a walk with repeated edges
d) a line graph with one or morevertices
Answer: a
Explanation: Suppose in a graph G a trail could be defined as a walk with no repeated edges.
Suppose a walk can be defined as efgh. There are norepeated edges so this walk is a trail.

325. Let a graph can be denoted asncfkedn a kind of


a) cycle graph
b) line graph
c) hamiltonian graph
d) path graph
Answer: a
Explanation: In the graph ncfkedn, noedges are repeated in the walk, whichmakes it a trail and then
start and end vertex n is same making it a cyclegraph.

326. Determine the edge count of apath complement graph with 14 vertices.
a) 502
b) 345
c) 78
d) 69
Answer: c
Explanation: Let, an n-path complement graph Pn’ is the graph complement of the path graph Pn.
Since Pn is self-complementary, P4’ is isomorphic to P4. Now, Pn’ has an edge count = 1⁄2(n-2)(n-1).
So, the required edge count is=78.

327. The sum of an n-node graph andits complement graph produces a graph called _
a) complete graph
b) bipartite graph
c) star graph
d) path-complement graph
Answer: a
Explanation: Suppose, the
complement G’ of a graph G is known as edge-complement graph which consists of with the same
vertex set but whose edge set contains the edges not present in G. The graph sum G+G’ on an n-
node graph G is called the complete graph say, Kn.

328. The maximum number of edgesin a bipartite graph on 14 vertices is


a) 56
b) 14
c) 49
d) 87
Answer: c
150
Explanation: Maximum number of edges occur in a complete bipartite graph when every vertex
has an edgeto every opposite vertex in the [Link] of edges in a complete bipartite graph is
a*b, where a and b are no. of vertices on each side. This quantity is maximum when a = b i.e. when
there are 7 vertices on each side. So answer is 7 * 7 = 49.

329. In a _ the degree of eachand every vertex is equal.


a) regular graph
b) point graph
c) star graph
d) euler graph
Answer: c
Explanation: A regular graph has the same degree in each of its vertices. In a regular bipartite
graph, if the common degree of each vertices is 1,the two parts are of the same size.

330. The time complexity to test whether a graph is bipartite or not is said to be using depth first
search.
a) O(n3)
b) linear time
c) O(1)
d) O(nlogn)Answer: b
Explanation: It is possible to test whether a graph is bipartite, and to return either a two-coloring (if
it is bipartite) or an odd cycle (if it is not) in linear time i.e, O(n) using depth first search. In case of
the intersection of n line segments or other simple shapes in the Euclidean graph, it is possible to
test whether the graph is bipartite and it will return either a two-coloring or an odd cycle in time
O(nlogn), even though the graph itself has up to O(n2) edges.

331. The partition V = V1 𝖴 V2 in a bipartite graph G1 is called


a) bipartition of G1
b) 2-vertex set of G1
c) sub bipartite graphs
d) disjoint vertex set
Answer: b
Explanation: A graph G1(V, E) is called bipartite if its vertex set V(G) can be decomposed into two
non-empty disjoint subsets V1(G1) and V2(G1) in such a way that each edge e ∈ E(G) has its one
end joint in V1(G1) and other endpoint in V2(G1). The partition V = V1 𝖴 V2 in a bipartite graph G1 is
called bipartition of G1.

332. What is the maximum numberof edges in a bipartite graph on 14 vertices?


a) 78
b) 15
c) 214
d) 49
Answer: d
Explanation: By definition, the maximum possible number of edges
in a bipartite graph on ‘n’ vertices =(1/4) x n2.
Substituting n = 14, we get maximum number of edges in a bipartite graph on 14 vertices,= (1/4) x
151
(14)2
= (1/4) x 14 x 14
= 49
∴ Maximum number of edges in a bipartite graph on 14 vertices = 49.

333. In a complete bipartite graph, the intersection of two sub graphs is


a) 1
b) null
c) 210
d) 412
Answer: b
Explanation: In a complete Bipartite graph, there must exist a partition say, V(G)=X𝖴Y and X∩Y=∅,
that means all edges share a vertex fromboth set X and Y.

334. Bipartite graphs are used in


a) modern coding theory
b) colouring graphs
c) neural networks
d) chemical bonds
Answer: a
Explanation: All types of cyclic graphs are examples of cyclic graphs. A cyclic graph is considered
bipartite if all thecycles involved are of even length.
Bipartite graphs are widely used in modern coding theory apart from being used in modeling
relationships.

335. The chromatic number of agraph is the property of


a) graph coloring
b) graph ordering
c) group ordering
d) group coloring
Answer: b
Explanation: A graph coloring is an assignment of labels to the vertices ofa graph such that no two
adjacent vertices share the same labels is called the colors of the graph. Now, the chromatic
number of any graph isthe minimal number of colors for which such an assignment is possible.

336. If a graph G is k-colorable andk<n, for any integer n then it is


a) n-colorable
b) n2 nodes
c) (k+n)-colorable
d) (k3+n3+1) nodes
Answer: a
Explanation: The chromatic number
of a graph is the minimal number of colors for which a graph coloring is possible. A graph G is
termed as k- colorable if there exists a graph coloring on G with k colors. If a graph is k-colorable,
then it is n-colorable for any n>k.

152
337. If Cn is the nth cyclic graph, where n>3 and n is odd. Determinethe value of X(Cn).
a) 32572
b) 16631
c) 3
d) 310
Answer: c
Explanation: Here n is odd and X(Cn)!
= 2. Since there are two adjacent edges in Cn. Now, a graph coloring forCn exists where vertices are
colored red and blue alternatively and another edge is with a different colour say orange, then the
value of X(Cn) becomes 3.

338. Determine the density of a planar graph with 34 edges and 13nodes.
a) 22/21
b) 12/23
c) 328
d) 576
Answer: a
Explanation: The density of a planar graph or network is described as the ratio of the number of
edges(E) to the number of possible edges in a
network with(N) nodes. So, D = E − N
+ 1/ 2 N − 5. Hence, the required answer is: D=(34-13+1)/(2*13-5) = 22/21. A completely sparse
planar graph has density 0 and a completelydense planar graph has degree 1.

339. If the number of vertices of a chromatic polynomial PG is 56, whatis the degree of PG?
a) 344
b) 73
c) 265
d) 56
Answer: d
Explanation: The chromatic polynomial PG of a graph G is a polynomial in which every natural
number k returns the number PG(k) of k-colorings of G. Since, the degree of PG is equal to the
number of vertices of G, the required answer is 56.

340. An undirected graph G which isconnected and acyclic is called


a) bipartite graph
b) cyclic graph
c) tree
d) forest
Answer: c
Explanation: An undirected graph G which is connected and acyclic is termed as a tree. G contains
no cyclesand if any edge is added to G a simplecycle is formed.

341. An n-vertex graph has edges.


a) n2
b) n-1

153
c) n*n
d) n*(n+1)/2
Answer: b
Explanation: Suppose G is a connected graph which has no [Link] subgraph of G includes at
least one vertex with zero or one incident edges. It has n vertices and n-1 edges. Generally, the
order-zero graph is notconsidered to be a tree.

342. What is a star tree?


a) A tree having a single internalvertex and n-1 leaves
b) A tree having n vertices arrangedin a line
c) A tree which has 0 or moreconnected subtrees
d) A tree which contains n verticesand n-1 cycles
Answer: a
Explanation: A star tree of order n is atree with as many leaves as possible or in other words a star
tree is a tree that consists of a single internal vertex and n-1 leaves. However, an internal vertex is
a vertex of degree at least 2.

343. A polytree is called


a) directed acyclic graph
b) directed cyclic graph
c) bipartite graph
d) connected graph
Answer: a
Explanation: A directed acyclic graph is known as a polytree whose underlying undirected graph is
a [Link] other words, a directed tree is a directed graph which would be tree ifthe directions on the
edges were ignored.

344. The tree elements are called


a) vertices
b) nodes
c) points
d) edges
Answer: b
Explanation: Every tree element is called a node and the lines connecting the elements are called
branches. A finite tree structure has a member that has no superior and is called the “root” Or root
node. Nodesthat have no child are called leaf nodes.

345. In an n-ary tree, each vertex hasat most children.


a) n
b) n4
c) n*n
d) n-1
Answer: a
Explanation: An n-ary tree is a rooted tree in which each vertex has at most n children. 2-ary trees
are termed as binary trees, 3-ary trees are sometimes called ternary trees.
154
346. A linear graph consists ofvertices arranged in a line.
a) false
b) true
c) either true or false
d) cannot determined
Answer: b
Explanation: A linear graph also known as a path graph is a graph
which consists of k vertices arranged in a line, so that vertices from i and i+1 are connected by an
edge for i=0,…, k-1.

347. Two labeled trees are isomorphic if


a) graphs of the two trees areisomorphic
b) the two trees have same label
c) graphs of the two trees are isomorphic and the two trees havethe same label
d) graphs of the two trees are cyclic
Answer: c
Explanation: The number of labeled trees of k number of vertices is kn-2. Two labeled trees are
isomorphic if their graphs are isomorphic and the corresponding points of the two trees have the
same labels.

348. A graph which consists ofdisjoint union of trees is called


a) bipartite graph
b) forest
c) caterpillar tree
d) labeled tree
Answer: b
Explanation: A forest is an undirectedacyclic graph in which all the
connected components are individualtrees. This graph contains a disjoint union of trees.

349. What is a bipartite graph?


a) a graph which contains only onecycle
b) a graph which consists of morethan 3 number of vertices
c) a graph which has odd number ofvertices and even number of edges
d) a graph which contains no cycles ofodd length
Answer: d
Explanation: A graph is called a bipartite graph if and only if it contains no cycle of odd length.
Everytree is a bipartite graph and a mediangraph.

350. If two cycle graphs Gm and Gn are joined together with a vertex, the number of spanning
trees in the newgraph is
a) m+n-1
b) m-n
c) m*n
d) m*n+1
155
Answer: c
Explanation: As there are n possible edges to be removed from G and m edges to be removed from
G and the rest from a spanning tree so the number of spanning tree in the newgraph is m*n.

351. For an n-vertex undirected graph, the time required to find acycle is
a) O(n)
b) O(n2)
c) O(n+1)
d) O(logn)
Answer: a
Explanation: The existence of a cycle in directed and undirected graphs can be determined by
depth-first search (DFS) of the graph finds an edge that points to an ancestor of the current vertex.
In an undirected graph, finding any already visited vertex will indicate a back edge. All the back
edges which DFS skips over are part of cycles. In the case of undirected graphs, only O(n) time is
required to find a cycle in an n-vertex graph, since at most n − 1 edges can be tree edges.

352. A binary cycle space forms a


over the two element field.
a) triangular graph
b) vector space
c) binary tree
d) hamiltonian graph
Answer: b
Explanation: The term cycle refers to an element of the cycle space of a graph. There are many
cycle spaces. The most common is the binary cycle space, which contains the edge sets that have
even degrees at every vertex and it forms a vector space over the two-element field.
1. In preorder traversal of a binary tree the second step is
a) traverse the right subtree
b) traverse the left subtree
c) traverse right subtree and visit theroot
d) visit the rootView Answer Answer: b
Explanation: In a preorder traversal of a binary tree first is to visit the root, second traverse the left
subtreeof the tree and third traverse the right subtree of the tree.

353. An important application ofbinary tree is


a) Huffman coding
b) stack implementation
c) queue implementation
d) traverse a cyclic graph
Answer: a
Explanation: A binary tree is used to sort a list of elements; the inorder traversal will do this
automatically. Better tree sorting algorithm will involve balancing the trees. The binary coding, in
particular for theHuffman coding is an immediate application of binary trees.

354. From the following code identifythe which traversal of a binary tree isthis

156
//if node has left childorder([Link])
//if node has right childorder([Link]) visit(node)
a) Inorder traversal
b) preorder traversal
c) postorder traversal
d) Euler tour traversal
Answer: c
Explanation: In a postorder traversal of a binary tree first is to traverse the left subtree, second
traverse the rightsubtree of the tree and third is to visitthe node.

355. What is the minimum height fora binary search tree with 60 nodes?
a) 1
b) 3
c) 4
d) 2
Answer: d
Explanation: If there are k nodes in a binary tree, maximum height of that tree should be k-1, and
minimum height should be floor(log2k). By
a) Inorder traversal
b) Euler Tour traversal
c) Post-order traversal
d) Pre-order Traversal
Answer: b
Explanation: The code signifies Euler Tour traversal which is a generic traversal of a binary tree. In
this treetraversal we have to walk around thetree and visit each node three times:
1. On the left (pre-order), 2. From below (in-order), 3. On the right (post-order) and Create subtrees
forall the nodes.

356. For the expression (7- (4*5))+(9/3) which of the following is the post order tree traversal?
a) *745-93/+
b) 93/+745*-
c) 745*-93/+
d) 74*+593/-
Answer: c
Explanation: First build a binary tree for the expression then find out the postorder traversal of that
tree and after that the answer will be 745*- 93/+.

357. The time complexity of calculating the sum of all leaf nodesin an n-order binary tree is
a) O(n2)
b) O(n+1)
c) O(1)
d) O(n)
Answer: d
Explanation: The approach is to traverse the binary tree in any fashion and check if the node is the
leaf node(child node)or not. After that, add node data to the sum variable. So, after summing up all
157
leafnodes, the time complexity of the operation should be O(n).

358. An immediate application of aDepth First Search traversal is


a) count the number of leaf nodes
b) perform Inorder traversal in easyway
c) count number of nodes
d) implement preorder traversal
Answer: a
Explanation: Given an n-ary binary tree, by performing DFS traversal on that tree number of leaf
nodes can becalculated and for that we need to maintain an array for the leaf count.

359. Breadth First Search traversal ofa binary tree finds its application in
a) Cloud computing
b) Peer to peer networks
c) Weighted graph
d) Euler path
Answer: b
Explanation: Breadth First Search traversal has diverse applications such as in the peer to peer
networks like BitTorrent, BFS traversal is used to find all the neighbour nodes of thenetwork.

360. Worst case complexity ofBreadth First Search traversal


a) O(n*n)
b) O(nlogn)
c) O(n2 logn)
d) O(n3)
Answer: b
Explanation: In an n-ary binary tree, we must have to visit all nodes from an adjacent node and
repeat the
same for next unvisited [Link], in worst case the time complexity should be O(nlogn).
361. Evaluation of expressiona/b+c*d-e in postfix notation.
a) ab+cd/*-e
b) ab/cd*+e-
c) abc/+d*-e
d) abcd/+*-e
Answer: b Explanation: The expression=a/b+c*d-e
={(ab/)+(cd*)}-e
={(ab/)(cd*)+}-e
={(ab/)(cd*)+}e-
So the output is: ab/cd*+e-

362. Evaluation of 4*5+3/2-9 in prefixnotation.


a) *45-/32+9
b) *+453/-29
c) -+*45/329
d) *+/45932
158
Answer: c Explanation: The expression=4*5+3/2-9
={(4*5)+(3/2)-9}
={(*45)+(/32)-9}
={+(*45)(/32)}-9
=-{+(*45)(/32)9
So the output is; -+*45/329.

363. What is the output of thefollowing if funct1(7)?


{
int n;
long int func; scanf(“%d”,&n); func=func1 (n) printf(“%ld!=%ld”,n,func);
}
long int func1(int n)
{
if(n==0)
{
Return 1;
}
else
{
return(n*func1(n-1));
}
}
a) 128
b) 4320
c) 720
d) 5040
Answer: d
Explanation: This is a factorial function of an integer using recursive approach. By running the
function oninteger 7 we get 5040.

364. Infix to prefix conversion can bedone using


a) two queues
b) two stacks
c) one stack and two queues
d) one stack
Void main()
Answer: b
Explanation: In the infix expression, the operator appears between the operands and in infix
notation if the operator appears before the operands in the expression. For the conversion
between them two stacks are used efficiently. The idea is to use one stack for operators and other
to store operands.
365. Conversion from prefix to postfixexpression can be done
a) using bubble sort
159
b) using radix sort
c) using two queues
d) in a direct manner
Answer: d
Explanation: In a postfix expression, the operators appear after the operands. Conversion from
prefix to postfix is done directly which is better than converting the prefix expression in infix and
then infix to postfix expression. It gives better efficiency.

366. What is the postfix expression of9+3*5/(10-4)?


a) 9 3 + * 5 / 10 4 –
b) 9 3 5 + * / 10 4 –
c) 9 3 + 5 * / 10 4 –
d) 9 3 5 * / + 10 – 4
Answer: c
Explanation: The expression,9+3*5/(10-4)
= 9+3*5/(10 4-)
= 9+35/*(10 4-)
= 935/*+(10 4-)
So the output is:9 3 5 / * + 10 4 -.

367. What is the postfix expression of(A+B)-C*(D/E))+F?


a) A B + C D E / * – F +
b) A B C D E + / * F – +
c) A B C + * D E / F + –
d) A B + C – * D E / F +
Answer: a
Explanation: The expression is (A+B)-C*(D/E))+F
= (A+B)-C*(DE/)+F
= (A+B)-C*(DE/)F+
= (A+B)-C(DE/)*F+
= (A+B)C(DE/)*-F+
= (AB+)C(DE/)*-F+
So the output is: AB+CDE/*-F+.

368. Algebra of logic is termed as


a) Numerical logic
b) Boolean algebra
c) Arithmetic logic
d) Boolean number
Answer: c
Explanation: The variables that can have two discrete values False(0) and True(1) and the
operations of logical significance are dealt with Boolean algebra.

369. Boolean algebra can be used


a) For designing of the digitalcomputers
b) In building logic symbols
160
c) Circuit theory
d) Building algebraic functions
Answer: a
Explanation: For designing digital computers and building different electronic circuits boolean
algebra isaccepted widely.

370. What is the definition ofBoolean functions?


a) An arithmetic function with kdegrees such that f:Y–>Yk
b) A special mathematical functionwith n degrees such that f:Yn–>Y
c) An algebraic function with ndegrees such that f:Xn–>X
d) A polynomial function with kdegrees such that f:X2–>Xn
Answer: b
Explanation: A Boolean function is a special mathematical function with n degrees and where Y =
{0,1} is the Boolean domain with being a non- negative integer. It helps in describing the way in
which the Boolean output is derived from Boolean inputs.

371. F(X,Y,Z,M) = X`Y`Z`M`. The degree of the function is _


a) 2
b) 5
c) 4
d) 1
Answer: c
Explanation: This is a function of degree 4 from the set of ordered pairs of Boolean variables to the
set {0,1}.

372. A value is representedby a Boolean expression.


a) Positive
b) Recursive
c) Negative
d) Boolean
Answer: d
Explanation: A Boolean value is given by a Boolean expression which is formed by combining
Boolean variables and logical connectives.

373. What is the use of Booleanidentities?


a) Minimizing the Boolean expression
b) Maximizing the Booleanexpression
c) To evaluate a logical identity
d) Searching of an algebraicexpression
Answer: a
Explanation: Boolean identities are used for minimizing the Boolean expression and transforming
into anequivalent expression.

374. is used to implementthe Boolean functions.


a) Logical notations
161
b) Arithmetic logics
c) Logic gates
d) Expressions
Answer: c
Explanation: To implement a Boolean function logic gates are used. Basic logic gates are AND, OR
and NOT.

375. Inversion of single bit input to asingle bit output using


a) NOT gate
b) NOR gate
c) AND gate
d) NAND gate
Answer: a
Explanation: A NOT gate is used toinvert a single bit input (say A) to asingle bit of output (~A).

376. There are numbersof Boolean functions of degree n.


a) n
b) 2(2*n)
c) n3
d) n(n*2)
Answer: b
Explanation: There are 2n different n- tuples of 0’s and 1’s. A Boolean function is an assignment of
0’s or 1’sto each of these 2 n different n- tuples. Hence, there are 2(2*n) different Boolean functions.

377. A is a Booleanvariable.
a) Literal
b) String
c) Keyword
d) Identifier
Answer: a
Explanation: A literal is a Boolean variable or its complement. A maxterm is a sum of n literals and
aminterm is a product of n literals.

378. Find the simplified expressionA’BC’+AC’.


a) B
b) A+C
c) (A+B)C’
d) B’C
Answer: c
Explanation: Given: A’BC’ + AC’
= C’(A’B + A)
= C’(A + B).

379. Evaluate the expression: (X +Z)(X + XZ’) + XY + Y.

162
a) XY+Z’
b) Y+XZ’+Y’Z
c) X’Z+Y
d) X+Y
Answer: d
Explanation: (X + Z)(X + XZ’) + XY + Y[Original Expression]
= (x + z)X(1 + Z’) + XY + Y [Distributive]
= (X + Z)X + XY + Y [Complement,Identity]
= (X+Z)X + Y(X+1) [ Distributive]
= (X+Z)X + Y [Idempotent]
= XX + XZ + Y [Distributive]
= X + XZ + Y [Identity]
= X(1+Z) + Y
= X + Y [Idempotent].

380. Simplify the expression: A’(A +BC) + (AC + B’C).


a) (AB’C+BC’)
b) (A’B+C’)
c) (A+ BC)
d) AC
Answer: b
Explanation: Given: A’(A + BC) + (AC +B’C)
= A’A + A’BC + AC + B’C
= A’BC + C(A + B’)
= C(A’B + A + B’)
= C(A + B + B’)
= C(A + 1)
= AC.

381. What is the simplification valueof MN(M + N’) + M(N + N’)?


a) M
b) MN+M’N’
c) (1+M)
d) M+N’
Answer: b
Explanation: Given: MN(M + N’) +M(N + N’)
= MN(M+N’) + M.1
= MNM + MNN’ + M
= MN + 0 +M
= M(N + 1)
= M.

382. Simplify the expression XZ’ + (Y +Y’Z) + XY.


a) (1+XY’)
b) YZ + XY’ + Z’
c) (X + Y +Z)
163
d) XY’+ Z’
Answer: c
Explanation: Given: X Z’ + (Y + Y’Z) +XY
= XZ’ + (Y + Z) + XY
= XZ’ + Y + Z + XY
= (XZ’ + Z) + (Y + XY)
= (X + Z) + Y (1 + X)
= X + Y + Z.

383. How many binary relations arethere on a set S with 9 distinct elements?
a) 290
b) 2100
c) 281
d) 260
Answer: c
Explanation: S is the set with 9 elements. A relation on S is definedas S x S. There are 92 number of
ordered pairs in relation. So, the number of binary relations is 2(9*9) =281.

384. number of reflexiverelations are there on a set of 11 distinct elements.


a) 2110
b) 3121
c) 290
d) 2132
Answer: a
Explanation: Let A be a set consists ofn distinct elements. There are 2(n*n)-
n number of reflexive relations that can be formed. So, here the answer is (11*11)-11
2 = 2110.

385. The number of reflexive as wellas symmetric relations on a set with14 distinct elements is
a) 4120
b) 270
c) 3201
d) 291
Answer: d
Explanation: Let A be a set consists of n distinct elements. There are 2(n*(n- 1))/2 number of reflexive
and symmetric relations that can be formed. So, here the answer is 214*(14-1)/2 = 291.

386. The number of symmetric relations on a set with 15 distinctelements is


a) 2196
b) 250
c) 2320
d) 278
Answer: a
Explanation: Let S be a set consists of n distinct elements. There are 2(n-1)*(n- 1) number of reflexive
and symmetric relations that can be formed. So, herethe answer is 2(15-1)*(15-1) = 2196.

164
387. R is a binary relation on a set Sand R is reflexive if and only if
a) r(R) = R
b) s(R) = R
c) t(R) = R
d) f(R) = R
Answer: a
Explanation: Let reflexive closure of R:r(R) = R. If R is reflexive, it satisfies all the condition in the
definition of reflexive closure. So, a reflexive closure of a relation is the smallest number of
reflexive relation containin R. Hence, R = r(R).

388. If R1 and R2 are binary relations from set A to set B, then the equality
holds.
a) (Rc)c = Rc
b) (A x B)c = Φ
c) (R1 U R2)c = R c 𝖴 R1 c 2
c) R = Rc
d) f(R) = R
Answer: c
Explanation: If <a,b> ∈ R then <b,a> ∈ R, where a and b belong to two different sets and so its
symmetric. Rc also contains <b,a>Rc = R.

389. number of reflexive closure exists in a relation R = {(0,1),(1,1), (1,3), (2,1), (2,2), (3,0)} where
{0, 1, 2, 3} ∈ A.
a) 26
b) 6
c) 8
d) 36
d) (R1 U R2)c = R c ∩ R c
1 2
Answer: c
Explanation: To proof (R1 U R2)c =R c 𝖴 R c,1 2
390. The binary relation {(1,1), (2,1),(2,2), (2,3), (2,4), (3,1), (3,2)} on the1 2
set {1, 2, 3} is if <x,y> belongs to (R1 U R2)c
a) <y,x> ∈ (R1 U R2)
b) <y,x> ∈ R1 or <y,x> ∈ R2
c) <x,y> ∈ R c or <x,y>1 ∈R c 2
d) <x,y> ∈ R c 𝖴 R c.
Answer: b
Explanation: The reflexive closure of R is the relation, R 𝖴 Δ = { (a,b) | (a,b)R (a,a) | a A }. Hence, R 𝖴
Δ = {(0,1), (1,1), (1,3), (2,1), (2,2), (3,0)} and the answer is 6.

391. The condition for a binary relation to be symmetric is _


a) s(R) = R
b) R 𝖴 R = R
a) reflective, symmetric and transitive
165
b) irreflexive, symmetric andtransitive
c) neither reflective, nor irreflexive but transitive
d) irreflexive and antisymmetric
Answer: c
Explanation: Not reflexive -> (3,3) notpresent; not irreflexive -> (1, 1) is present; not symmetric -> (2,
1) is present but not (1, 2); not antisymmetric – (2, 3) and (3, 2) are present; not asymmetric ->
asymmetry requires both antisymmetry and irreflexivity. So, itis transitive closure of relation.

392. Let S be a set of n>0 elements. Let be the number Br of binary relations on S and let Bf be the
number of functions from S to S. Theexpression for Br and Bf, in terms of nshould be
a) n2 and 2(n+1)2
b) n3 and n(n+1)
c) n and n(n+6)
d) 2(n*n) and nn
Answer: d
Explanation: For a set with n elements the number of binary relations should be 2(n*n) and the
number of functions should be [Link] Br = 2(n*n) and Bf = nn.

393. Consider the relation: R’ (x, y) if and only if x, y>0 over the set of non- zero rational
numbers,then R’ is
a) not equivalence relation
b) an equivalence relation
c) transitive and asymmetry relation
d) reflexive and antisymmetricrelation
Answer: b
Explanation: Reflexive: a, a>0 Symmetric: if a, b>0 then both mustbe +ve or -ve, which means b, a >
0 also exists
Transitive: if a, b>0 and b, c>0 then to have b as same number, both pairs must be +ve or -ve which
implies a, c>0. Hence, R’ is an equivalence relation.

394. Spanning trees have a specialclass of depth-first search trees named


a) Euclidean minimum spanning trees
b) Tremaux trees
c) Complete bipartite graphs
d) Decision trees
Answer: b
Explanation: A tremaux tree of an undirected graph G is a spanning treeof G which is rooted at one
of its vertices with the property that every two adjacent vertices in G are relatedto each other as an
ancestor and descendant in the tree.

395. If the weight of an edge e of cycle C in a graph is larger than the individual weights of all
other edgesof C, then that edge
a) belongs to an minimum spanningtree
b) cannot belong to an minimumspanning tree
c) belongs to all MSTs of the graph
166
d) can not belong to the graph
Answer: b
Explanation: For any cycle C in the graph, if the weight of an edge e of Cis larger than the individual
weights of all other edges of C, then this edgecannot belong to an MST.

396. For every spanning tree with n vertices and n edges what is the least number of different
Spanning trees can be formed?
a) 2
b) 5
c) 3
d) 4
Answer: c
Explanation: If graph is connected and has ‘n’ edges, there will be exactly one cycle, if n vertices
are there. A different spanning tree can be constructed by removing one edgefrom the cycle, one at
a time. The minimum cycle length can be 3. So, there must be at least 3 spanning trees in any such
Graph. Consider a Graph with n = 4, then 3 spanning trees possible at maximum (removingedges of
cycle one at a time, alternatively). So, any Graph with minimum cycle length ‘3’ will have at least 3
spanning trees.

397. Time complexity of Prim’salgorithm is


a) O((V+E)logV)
b) O(E+V)
c) O(E)
d) O(V+1)
Answer: a
Explanation: In Prim’s Algorithm, we will start with an arbitrary node (take any point to start) and
mark it. In each iteration, a new vertex is marked that is adjacent to the one that we have already
marked. Each vertex is inserted in the priority queue only once and insertion in priority queue take
logarithmic [Link], the time complexity of Prim’sAlgorithm is O((V+E)logV).

398. What is the time complexity ofKruskal’s algorithm?


a) O(ElogV)
b) O(V+logE)
c) O(E+1)
d) O(V2)
Answer: a
Explanation: In Kruskal’s algorithm, at each iteration, we will select the edgewith the lowest weight.
So, we will start with the lowest weighted edge first. After that we will select the second lowest
weighted edge. In Kruskal’s algorithm, most time consuming operation is sorting because the total
complexity of the Disjoint-Set operations will be O(ElogV) and it is the overall Time Complexity of
the algorithm.

399. An immediate application ofminimum spanning tree


a) gesture analysis
b) handwriting recognition

167
c) fingerprint detection
d) soft computing
Answer: b
Explanation: Minimum spanning tree is the spanning tree where the cost is minimum among all the
spanning trees. It is used in network designing,in the algorithms predicting the travelling salesman
problem,multi- terminal minimum cut problem and minimum-cost weighted perfect matching. It
can also used in Handwriting recognition and imagesegmentation.

400. The spanning tree will be maximally acyclic if


a) one additional edge makes a cyclein the tree
b) two additional edges makes a cyclein the tree
c) removing one edge makes the treecycle free
d) removing two edges make the treecycle free
Answer: a
Explanation: A connected graph G can have more than one spanning tree. Removing one edge
from the spanning tree will make the graph disconnected and the spanning tree is minimally
connected. Adding one edge to the spanning tree will create a circuit or loop and the spanning tree
is maximally acyclic.

401. In a maximum spanning tree theweighted graph is of


a) maximum number of edges
b) maximum number of cyclic trees
c) minimum number of vertices
d) maximum weightAnswer: d
Explanation: A maximum spanning tree can be computed by negating the weights for each edge
and applying Kruskal’s algorithm. Thus, it is a spanning tree of a weighted graph having maximum
weight assigned to all the edges.

402. Prim’s algorithm can beimplemented using


a) a stack data structure
b) radix sort
c) priority queue data structure
d) bubble sort
Answer: c
Explanation: The time complexity of Prim’s algorithm depends on the data structures used for the
graph and for ordering the edges by weight, which can be done using a priority queue. In general, a
priority queue will be quicker at finding the vertex in the spanning tree with minimum cost.
The choice of data structures for implementation will lead to varyingtime complexity.

403. Let a set S = {2, 4, 8, 16, 32} and <= be the partial order defined by S <= R if a divides b. Number
of edgesin the Hasse diagram of is
a) 6
b) 5
c) 9
d) 4
168
Answer: b
Explanation: Hasse Diagram is:
32
/16
/8
/ \
24
So, the number of edges should be: 4.

404. The less-than relation, <, on aset of real numbers is _


a) not a partial ordering because it is not asymmetric and irreflexive equalsantisymmetric
b) a partial ordering since it isasymmetric and reflexive
c) a partial ordering since it isantisymmetric and reflexive
d) not a partial ordering because it isnot antisymmetric and reflexive
Answer: a
Explanation: Relation less than a set of real numbers is not antisymmetricand reflexive. Relation is
not POSET because it is irreflexive. Again, aRb != bRa unless a=b and so it is antisymmetric. A
relation may be ‘not asymmetric and not reflexive but still antisymmetric, as {(1,1) (1,2)}. So, the
relation is not a partial ordering because it is not asymmetric andirreflexive equals antisymmetric.

405. If the longest chain in a partial order is of length l, then the partial order can be written as
disjointantichains.
a) l2
b) l+1
c) l
d) ll
Answer: c
Explanation: If the length of the longest chain in a partial order is l, then the elements in the POSET
canbe partitioned into l disjoint antichains.

406. Suppose X = {a, b, c, d} and π1 is the partition of X, π1 = {{a, b, c}, d}. The number of ordered
pairs of the equivalence relations induced by
a) 15
b) 10
c) 34
d) 5
Answer: b
Explanation: The ordered pairs of theequivalence relations induced =
{(a,a), (a,b), (a,c), (b,a), (b,b), (b,c),
(c,a), (c,b), (c,c), (d,d)}. Poset -> equivalence relations = each partitionpower set – Φ.

407. A partial order P is defined on the set of natural numbers as [Link] a/b denotes integer
division. i)(0, 0) ∊ P. ii)(a, b) ∊ P if and only if a % 10 ≤ b % 10 and (a/10, b/10) ∊ P. Consider the
following ordered pairs:i. (101, 22) ii. (22, 101) iii. (145, 265) iv. (0, 153) The ordered pairs of natural
numbersare contained in P are and
a) (145, 265) and (0, 153)

169
b) (22, 101) and (0, 153)
c) (101, 22) and (145, 265)
d) (101, 22) and (0, 153)
Answer: d
Explanation: For ordered pair (a, b), to be in P, each digit in a starting from unit place must not be
larger than the corresponding digit in b. This condition is satisfied by options (iii) (145, 265) => 5 ≤
5, 4 < 6 and 1 < 2;
(i) (0, 153) => 0 < 3 and no need toexamine further.

170
Digital logic circuits
the digital logic circuits are basic building blocks of the digital systems (digital computers). these
digital logic circuits can be classified into two categories suchas combinational logic circuits and
sequential logic circuits. before studying about the difference between combinational and sequential
logic circuits, primarily, we must know what combinational logic circuit is and what are sequential
logic circuits.

Digital Computers
a digital computer can be considered as a digital system that performs various computational tasks.
the first electronic digital computer was developed in the late 1940s and was used primarily for
numerical computations.
by convention, the digital computers use the binary number system, which has two digits: 0 and 1. a
binary digit is called a bit. A computer system is subdivided into two functional entities: hardware and
software. The hardware consists of all the electronic components and electromechanical devices
that comprise the physical entity of the device. The software of the computer consists of the
instructions and data that thecomputer manipulates to perform various data-processing tasks.

the central processing unit (CPU) contains an arithmetic and logic unit for manipulating data, several
registers for storing data, and a control circuit for fetching and executing instructions.
the memory unit of a digital computer contains storage for instructions anddata.
the random-access memory (dram) for real-time processing of the data.
the input-output devices for generating inputs from the user anddisplaying the final results to the
user.
the input-output devices connected to the computer include the keyboard, mouse, terminals,
magnetic disk drives, and other communication devices.

Logic Gates

the logic gates are the main structural part of a digital system.
logic gates are a block of hardware that produces signals of binary 1 or 0 when input logic
requirements are satisfied.
each gate has a distinct graphic symbol, and its operation can be describedby means of algebraic
expressions. The seven basic logic gates include: and, or, xor, not, Nand, nor, andnor.
the relationship between the input-output binary variables for each gatecan be represented in tabular

171
form by a truth table.
each gate has one or two binary input variables designated by a and b andone binary output variable
designated by x.

And Gate:
the and gate is an electronic circuit which gives a high output only if all its inputs are high. the and
operation is represented by a dot (.) sign.

r gate:

172
the or gate is an electronic circuit which gives a high output if one or more of its inputs are high. the

operation performed by an or gate is represented by a plus (+) sign.


Not Gate:
the not gate is an electronic circuit which produces an inverted version of the input at its output. it is
also known as an inverter.

Nand Gate:
the not-and (nand) gate which is equal to an and gate followed by a not [Link] nand gate gives a
high output if any of the inputs are low. the nand gate is represented by a and gate with a small circle
on the output. the small circle represents inversion.

Nor Gate:
the not-or (nor) gate which is equal to an or gate followed by a not gate. nor gate gives a low output
if any of the inputs are high. the nor gate is represented by an or gate with a small circle on the output.
the small circle represents inversion.

Exclusive-Or/ Xor Gate:

173
the 'exclusive-or' gate is a circuit which will give a high output if one of its inputs is high but not both
of them. the xor operation is represented by an encircled plus sign.

Exclusive-Nor/Equivalence Gate:

the 'exclusive-nor' gate is a circuit that does the inverse operation to the xor gate. it will give a low
output if one of its inputs is high but not both of them. the small circle represents inversion.

Boolean Algebra
Boolean algebra can be considered as an algebra that deals with binary variables and logic
operations. boolean algebraic variables are designated by letters such asa, b, x, and y. the basic
operations performed are and, or, and complement.
the boolean algebraic functions are mostly expressed with binary variables, logic operation symbols,
parentheses, and equal sign. for a given value of variables, the boolean function can be either 1 or 0.
for instance, consider the boolean function:
f = x + y'z the logic diagram for the boolean function f = x + y'z can be represented as:

174
the boolean function f = x + y'z is transformed from an algebraicexpression into a logic diagram
composed of and, or, and inverter [Link] at input 'y' generates its complement y'.
there is an and gate for the term y'z, and an or gate is used to combinethe two terms (x and y'z).
the variables of the function are taken to be the inputs of the circuit, andthe variable symbol of the
function is taken as the output of the circuit.

the truth table for the boolean function f = x + y'z can be represented as:
Note: A truth table can represent the relationship between a function and its
binary variables. To represent a function in a truth table, we need a list of the 2^n
combinations of n binary variables.

laws of boolean algebra


the basic laws of boolean algebra can be stated as follows:
commutative law states that the interchanging of the order of operands ina boolean equation does
175
not change its result. for example:
or operator → a + b = b + a
and operator → a * b = b * a
associative law of multiplication states that the and operation are done ontwo or more than two
variables. for example:
a * (b * c) = (a * b) * c
distributive law states that the multiplication of two variables and addingthe result with a variable will
result in the same value as multiplication of addition of the variable with individual variables. for
example:
a + bc = (a + b) (a + c).
annulment law:
a.0 = 0 a + 1 = 1
identity law:
a.1 = a a + 0 = a
idempotent law:a + a = a
a.a = a
complement law:a + a' = 1
a.a'= 0
double negation law:((a)')' = a
absorption law:a.(a+b) = a
a + ab = a
de morgan's law is also known as de morgan's theorem, works depending on theconcept of duality.
duality states that interchanging the operators and variables in a function, such as replacing 0 with 1
and 1 with 0, and operator with or operator and or operator with and operator.
de morgan stated 2 theorems, which will help us in solving the algebraic problems in digital
electronics. the de morgan's statements are:
"the negation of a conjunction is the disjunction of the negations", which means that the complement
of the product of 2 variables is equal to the sum of the compliments of individual variables. for
example, (a.b)' = a' + b'.
"the negation of disjunction is the conjunction of the negations", which means that compliment of the
sum of two variables is equal to the product of the complement of each variable. for example, (a + b)'
= a'b'.

Map Simplification
the map method involves a simple, straightforward procedure for simplifyingboolean expressions.
map simplification may be regarded as a pictorial arrangement of the truth tablewhich allows an easy
interpretation for choosing the minimum number of terms needed to express the function
algebraically. the map method is also known as karnaugh map or k-map.
each combination of the variables in a truth table is called a mid-term.
note: when expressed in a truth table a function of n variables will have 2^n min-terms, equivalent to
the 2^n binary numbers obtained from n bits.
there are four min-terms in a two-variable map. therefore, the map consists offour squares, one for
each min-term. the 0's and 1's marked for each row, and each column designates the values of
variable x and y, respectively.

176
Two-Variable Map:

Representation Of Functions In The Two-Variable Map:

Three Variable Map


there are eight min-terms in a three-variable map. therefore, the map consists ofeight squares.
Three Variable Map:

the map was drawn in part (b) in the above image is marked with numbers in each row and each
column to show the relationship between the squaresand the three variables.
any two adjacent squares in the map differ by only one variable, which is primed in one square and
unprimed in the other. for example, m5 and m7lie in the two adjacent squares. variable y is primed in
m5 and unprimed inm7, whereas the other two variables are the same in both the squares.
from the postulates of boolean algebra, it follows that the sum of two min-terms in adjacent squares
177
can be simplified to a single and term consistingof only two literals. for example, consider the sum
of two adjacent squaressay m5 and m7:
m5+m7 = xy'z+xyz= xz(y'+y)= xz.

Logic Circuits Are Classified Into Two Types:


sequential logic circuits
combinational logic circuits.

Combinational Logic Circuits


the combinational logic circuits or time-independent logic circuits in digital circuit theory can be
defined as a type of digital logic circuit implemented using boolean circuits, where the output of logic
circuit is a pure function of the present inputs only. the combinational logic circuit operation is
instantaneous and these circuits do not have the memory or feedback loops.
this combinational logic is in contrast compared to the sequential logic circuit in which the output
depends on both present inputs and also on the previous inputs. thus, we can say that combinational
logic does not have memory, whereas sequential logic stores previous input in its memory. hence, if
the input of combinational logic circuit changes, then the output also changes.
Combinational Logic Circuit Design

combinational logic circuit


these combinational logic circuits are designed to produce specific outputs from certain inputs. the
combinational logic design can be done using two methods such as a sum of products and a product
of sums. combinational logic circuits are generally designed by connecting together or combining the
basic logic gates suchas nand, nor, and not. hence, these logic gates are termed as building blocks.
these logic circuits can be a very simple circuit or a very complex circuit or huge combinational circuit
can be designed using only universal logic gates such as nand and nor gates.

178
the simple time independent logic circuits that are implemented using boolean circuits whose output
logic value depends only on the input logic values can be called as combinational logic circuits.

Combinational Logic Circuit


the figure shows all the three major components of the combinational logic circuit such as logic
diagram, truth table, and boolean expression.

Functions Of Combinational Logic Circuit


the function of combinational logic circuits can be specified in three main wayssuch as:
truth table boolean algebra logic diagram

Truth Table

combinational logic function truth table


the logic gate function can be defined using its truth table which consists of outputsfor of all possible
combinations of inputs of the logic gate. an example combinational logic function truth table is
shown in the above figure.

Boolean Algebra

combinational logic function boolean expression


the output of combinational logic function can be expressed in the form expression using boolean
179
algebra and an example, boolean expression for theabove truth table is shown in the above figure.

Logic Diagram

combinational logic circuit using logic gates the graphical representation of combinational logic
functions using logic gates is called as logic diagram. the logic diagram for above discussed logic
function truthtable and boolean expression can be realized as shown in the above figure.
the combinational logic circuits can also be called as decision-making circuits,as these are designed
using individual logic gates. the combinational logic is the process of combining logic gates to
process the given two or more inputs such that to generate at least one output signal based on the
logic function of each logic gate.

Classification Of Combinational Logic

classificaiton of combinational logic


the combinational logic circuits can be classified into various types based on the purpose of usage,
such as arithmetic & logical functions, data transmission, and code converters. to solve the arithmetic
and logical functions we generally use adders, subtractors, and comparators which are generally
realized by combining various logic gates called as combinational logic circuits. similarly, for data
transmission, we use multiplexers, demultiplexers, encoders, and decoders whichare also realized
using combinational logic. the code converters such as binary, bcd, and 7-segment are designed
using various logic circuits.
180
in fact, combinational logic is most frequently used in multiplexer and demultiplexer type circuits. if
multiple inputs or outputs are connected to thecommon signal line, then the logic gates are used for
decoding an address in order to select single data input or output switch.

Sequential Logic Circuits


the combinational circuit does not use any memory. hence the previous state of input does not have
any effect on the present state of the circuit. but sequential circuit has memory so output can vary
based on input. this type of circuits uses previous input, output, clock and a memory element.
the simple logic circuits whose output logic value depends on the input logic values and also on the
stored information is called as sequential logic circuits.
combinational circuit produces an output based on input variable only, but sequential circuit
produces an output based on current input and previous input variables. that means sequential
circuits include memory elements which are capable of storing binary information. that binary
information defines the state of the sequential circuit at that time. a latch capable of storing one bit
of information.

as shown in figure there are two types of input to the combinational logic :
external inputs which not controlled by the circuit.
internal inputs which are a function of a previous output states.
secondary inputs are state variables produced by the storage elements, where as secondary outputs
are excitations for the storage elements.
types of sequential circuits – there are two types of sequential circuit :
asynchronous sequential circuit – these circuit do not use a clock signal but uses the pulses of
the inputs. these circuits are faster than synchronous sequential circuits because there is clock pulse
and change their state immediately when there is a change in the input signal. we use
asynchronous sequential circuits when speed of operation is importantand independent of internal
clock pulse.

181
but these circuits are more difficult to design and their output is uncertain.
synchronous sequential circuit – these circuit uses clock signal and level inputs (or pulsed) (with
restrictions on pulse width and circuit propagation).the output pulse is the same duration as the clock
pulse for the clocked sequential circuits. since they wait for the next clock pulse to arrive to perform
the next operation, so these circuits are bit slower compared to asynchronous. level output changes
state at the start of an input pulse and remains in that until the next input or clock pulse.

we use synchronous sequential circuit in synchronous counters, flip flops, and in the design of moore-
mealy state management machines.

182
sequential logic circuit
the figure represents the block diagram of the sequential logic circuit.
difference between synchronous and asynchronous sequential circuits
as the name suggests both synchronous and asynchronous sequential circuits are the type of
sequential circuits which uses feedback for the next output generationhowever on the basis of the
type of this feedback both circuits can be get differentiated.
following are the important differences between synchronous and asynchronous sequential circuits

sr.
key synchronous sequentialcircuits asynchronous sequential circuits
no.

synchronous sequentialcircuits on other hand asynchronous sequential


are digitalsequential circuits in circuits are digitalsequential circuits in
1 definition which the feedback to the input which thefeedback to the input for next
for next output generation is output generation is not governed by clock
governed by clock signals.

sr.
key synchronous sequentialcircuits asynchronous sequential circuits
no.
signals.

in synchronoussequential
on other hand unclocked flip flop or time
circuits, the memory unit which
2 memoryunit delay is used as memoryelement in case of
is being get used for
asynchronoussequential circuits.
governance is clocked flip flop.

on other hand there are chances for the


the states ofsynchronous asynchronous circuits to enter into a wrong
3 state sequentialcircuits are always state because ofthe time difference between
predictable and thus reliable. the arrivals of inputs. this is called as race
condition.

183
however on other hand the presence of
it is easy to design feedback among logic gates causes
4 complexity
synchronous sequentialcircuits instability issues making the design of
asynchronoussequential circuits difficult.
due to the propagation delay of
clock signal inreaching all
since there is no clock signal delay, these
elements of the circuit the
5 performance are fast compared to the synchronous
synchronous sequentialcircuits
sequential circuits
are slower in its operation
speed
on other hand asynchronous circuits are
synchronous circuits areused in used in low power and high speed
6 example counters, shift registers, operations such as simple microprocessors,
memory units. digitalsignal processing units and in
communication systems for email

sr.
key synchronous sequentialcircuits asynchronous sequential circuits
no.

applications, internet access and


networking.

Difference Between Combinational Logic Circuits And Sequential Logic Circuits


the difference between combinational logic circuits and sequential logic circuits can be easily
understood by knowing about each circuit in detail.

Combinational Logic Ciruits


the digital logic circuits whose outputs can be determined using thelogic function of current state
input are combinational logic circuits,hence, these are also called as time independent logic circuits.
thus, these combinational digital logic circuits don’t have the capabilityto store a state inside them.
hence, the combinational logic circuits do not contain any memoryelements.
the arithmetic operations performed on the date stored data in the computers are done using
combinational logic circuits.
the combinational digital logic circuits are fundamentally implemented using different types of
devices such as multiplexers,
demultiplexers, encoders, decoders, half adder, and full adders.
the components of arithmetic and logic unit of the computers are generally comprised of
combinational digital logic circuits.
the independent working states of the combinational logic circuits are represented with boolean
algebra and after simplification by using nor,not, and nand gates the circuit can be implemented.
the combinational digital circuits don’t require any feedbacks.
the combinational logic circuits are independent of the clock.
as there are no clocks used in these digital logic circuits, they do notneed any triggering.
the combinational logic circuit’s behavior can be defined by using theset of output functions.
in general, sum of products or products of sums method is used for theconstruction of combinational

184
logic.
Sequential Logic Circuits
the digital logic circuits whose outputs can be determined using the logic function of current state
inputs and past state inputs are called assequential logic circuits.
these sequential digital logic circuits are capable to retain the earlierstate of the system based on the
current inputs and earlier state.
hence, unlike the combinational logic circuits, these sequential digitallogic circuits are capable of
storing the data in a digital circuit.
the sequential logic circuits contain memory elements.
the latch is considered as the simplest element used to retain the earlier memory or state in the
sequential digital logic.
latches can also be called as flip-flops, but, if we consider the true structural form, then it can be
considered as a combinational circuit withone or more than one outputs fed back as inputs.
these sequential digital logic circuits are used in maximum types of memory elements and also in
finite state machines, which are replicawatches for sale digital circuit models with finite possible
states. the maximum number of sequential logic circuits uses a clock for triggering the flip flops
operation. if the flip flop in the digital logic circuit is triggered, then the circuit is called as synchronous
sequential circuit and the other circuits (which are simultaneously not triggered) are called as
asynchronous sequential circuits.
the sequential digital logic circuits utilize the feedbacks from outputs toinputs.
the sequential logic circuit’s behavior can be defined by using the set ofoutput functions and set of
next state or memory functions.
in practical digital logic circuits, combinational digital logic circuits andsequential digital logic circuits
are used.

Different Types Of Flip Flop Conversion


in electronics, flip flop is an electronic circuit and is also called as a latch. flip flopsconsist of two
stable states which are used to store the data. these are basic building blocks of a digital electronic
system which are used in various systems like communications, computers, etc. a basic flip flop can
be used to construct a cross coupled inverting elements like invert gates, fets, bjts, inverters, vacuum
tubes. conversion of one type of flip flop to another can be done by using a combinational logic circuit.
for instance, if a jk flip flop is necessary, the i/ps are given to the combinational circuit & the o/p of
the combinational circuit is given to the i/ps of the actual flip-flop. therefore, the o/p of the actual flip-
flop is the o/p of the required flip-flop.

185
flip flop conversion

Flip Flop Conversion


the main purpose of the flip flop conversion is to convert a flip flop into a desiredtype-b flip flop using
some conversion logic. the flip flop conversions are classified into different types that are
sr-ff to jk-ff conversion
jk-ff to sr-ff conversion
sr-ff to d-ff conversion
d-ff to sr-ff conversion
jk-ff to t-ff conversion
jk-ff to d-ff conversion
d-ff to jk-ff conversion

Sr-Flip Flop To Jk-Flip Flop Conversion


in jk-flipflop, j and k are given as external i/ps to s and r in sr-flip flop. here, boths & r are o/ps of the
combinational circuit. the truth tables of flip flop conversions are shown below. the current state is
denoted with qp & qp+1 is thenext state to be found when the j &k i/ps are applied.

186
Sr-Ff To Jk-Ff Conversion
there are eight possible combinations for two i/ps j and k. for every combination of j, k & qp, the
equivalent qp+1 states are found. qp+1 simply recommends thefuture values to be found by the jk-
flip flop after the importance of qp. then the table is finished by writing the values of s & r compulsory
to get each qp+1 from the equivalent qp. that is, the s and r values are compulsory to change the state
of the flip flop from qp to qp+1 are written

Jk-Flip Flop To Sr-Flip Flop Conversion


the conversion of the jk-ff to sr-ff is opposite to the sr-ff to jk-ff. here s & r will be the external i/ps to
j & k, that is shown in the below logic diagram, j & k will be the o/ps of the combinational circuit. so,
the j and k values have to be acquired in terms of s, r & qp. the logic diagram is shown below. the
conversiontable for flip flop to be written in terms of s, r, qp, qp+1, j & k. there are eight possible
combinations for two i/ps s and r.

jk-ff to sr-ff conversion

for every combination, the equivalent qp+1 o/p’s are found. the o/p’s for the combinations of s=r=1
are not acceptable for an sr-ff. therefore the o/p’s areconsidered as invalid and the j & k values are
taken as “don’t care”.

Sr-Flip Flop To D-Flip Flop Conversion


as shown in the below figure, actual inputs of the flip flop are s & r where d isthe external i/p. the four
combinations of the s & r in terms of d and qp, conversion table, logic diagram and the karnaugh map
are given below.

187
sr-ff to d-ff conversion

D-Flip Flop To Sr-Flip Flop Conversion


in this type of conversion, d is the actual i/p of the flip flop where s & r are theexternal i/[Link] are
eight possible combinations are obtained from the external i/ps s, r & qp. nevertheless, since the
combination of s=r=1 is unacceptable, the values of d and qp+1 are taken as “don’t care”. the logic
diagram of d-ff to sr-ff is showing the conversion from d-ff to sr-ff, and thekarnaugh map for d in terms
of s, r & qp are given below.

d-ff to sr-ff conversion

Jk-Flip Flop To T-Flip Flop Conversion


in this type of conversion, j & k are the actual i/ps of the flip flop where k is considered as the external
i/p. four combinations are created by t, qp, j & k that
are expressed in terms of t & qp. the karnaugh map, the logic diagram andconversion table, are given
below.

jk-ff to t-ff conversion

188
Jk-Flip Flop To D-Flip Flop Conversion
in this type of flip flop conversion, j&k are the actual inputs where d is the external input of the flip
flop. the four combinations of the flip flop will be doneby using d & qp, and in terms of these two j&k
are expressed. the conversion table with four combinations, jk-ff to d-ff conversion logic diagram and
karnaugh map for j & k in terms of d & are shown below.

jk-ff to d-ff conversion

D-Flip Flop To Jk-Flip Flop Conversion


in this type of flip flop conversion, j & k are the external i/ps of the flip flop whered is the actual input.

the eight combinations can make by using j, k and qp that isshown in the conversion table below. d is
stated in terms of j, k & qp. the karnaugh map d in terms of j, k & qp, conversion table and the logic
diagram of the d-ff to jk-ff is shown below.

d-ff to jk-ff conversion

thus, this is all about different types of flip flop conversions, that includes sr-ff to jk-ff , jk-ff to sr-ff ,
sr-ff to d-ff , d-ff to sr-ff , jk-ff to t-ff , jk-ff to d-ff and d-ff to jk-ff . we hope that you have got a better
understanding of this concept. furthermore, any doubts regarding the applications of flip-flops or
electronics projects, please give your feedback by commenting in the commentsection [Link] is
a question for you, what are the applications of flip flops?

Integrated Circuit
a microprocessor is digital is a digital circuit which is built using a combinationlogic functions. the
microprocessor package contains an integrated circuit.
an integrated circuit is electronic circuit or device that has electronic components on a small
semiconductor chip. it has functionality of logic and or amplifying of asignal. these are mainly two
types of circuits: digital or analog. analog ics handlecontinuous signals such as audio signals and
digital ics handle discrete signals such as binary [Link] integrated circuit, or ic, is small chip that
can function as an amplifier, oscillator, timer, microprocessor, or even computer memory. an ic is a
small wafer, usually made of silicon, that can hold anywhere from hundreds to millionsof transistors,
resistors, and capacitors. these extremely small electronics can perform calculations and store data
189
using either digital or analog technology.
digital ics use logic gates, which work only with values of ones and zeros. a low signal sent to to a
component on a digital ic will result in a value of 0, while a high signal creates a value of 1. digital ics
are the kind you will usually find incomputers, networking equipment, and most consumer electronics.
analog, or linear ics work with continuous values. this means a component on a linear ic can take a
value of any kind and output another value. the term "linear"is used since the output value is a linear
function of the input. for example, a component on a linear ic may multiple an incoming value by a
factor of 2.5 and output the result. linear ices are typically used in audio and radio frequency
amplification.

Types Of Integrated Circuits


there are different types of integrated circuits based various criteria. based onintended application,
the integrated circuit (ic) can be classified as following:
digital integrated circuits handle discrete signals such as binary values (0and 1). these circuits use
digital logic gates, multiplexers, flip flops [Link] circuits are easier to design and economical.
analog integrated circuits handle contiguous signals. these are two types:linear integrated circuits
(linear ics) and radio frequency integrated circuits (rf ics).
mixed integrated circuits are obtained by the combination of analog anddigital integrated circuits.
therefore, it have digital to analog (a/d) converter, digital to analog (d/a) converter, and clock/timing
integrated circuits.
general types of integrated circuits are as following: comparators, switching ic, audio amplifiers,
operational amplifiers, timers ics.

Digital Integrated Circuit


functions of digital integrated circuits to handle discrete signals such as binary values in which
“true/false” logical operations are used. basic boolean functionssuch as and, or, and not are essential
in building functionality for modern digital systems. these boolean functions are implemented using
transistors. for example, internal transistor structure of a nand gate is given in following figure.

there might ten billion or more transistors in modern digital circuit. so, we need integrated circuits
(ics) that combine a small or large number of these transistors to achieve particular functionality.
these circuits provide benefiting students, verylow cost and higher level of reliability. examples of
integrated circuits are mos, cmos, ttl etc. cmos ics are fault tolerant, reduce risk of chip failure, use
190
of anti-static foam for storage and transport of ics. ttl technology requires regulated power supply of
5 volts.

Families Of Integrated Circuits


a logic family is a group of electronic logic gates. a family has its own discrete logic level, power
supply, individual components, characteristic, advantages and disadvantages. within each family,
there is a range of voltage which may be lowlevel or high level.
these families are listed as following below:

Diode Logic (Dl)


registers and diodes are used to implement logic. the purpose of diode is to perform or and and
operation, and logic switch. it is essential that diode is forward biased so that it can conduct.
disadvantages: diodes can not perform not operation, diode cannot work for multiple states, only one
stage at a time,tend to degrade signals quickly.

Resistor-Transistor Logic (Rtl)


registers and transistors are used to implement logic. transistors are used to combine signals which
are inverted and amplified inputs. these are economicaland easy to design but slower in speed. these
require great amount of current from supply. rtl gates can be used as interface between linear circuits
and digital.

Diode Transistor Logic (Dtl)


registers and diodes are used to implement logic. it has advantages over dl and rtl. diode can perform
and and or operation along with a transistor and outputsignal can be amplified. it has logic inversion
which is signal can be restored to fulllogic level, if we add a transistor at output of logic gates. or
operation can be performed using diodes instead of resistors which removes interaction between
input signals. since input resistor to transistor, switching speed of transistor is limited. dtl was used
in tube computers.

Transistor - Transistor Logic (Ttl)


transistors are used to implement logic and bipolar transistors to contract integrated circuits. there
are standard ttl, high speed ttl, low power ttl, andschottky ttl. it is popular logic family.

Emitter Coupled Logic (Ecl)


ecl is a non-structured logic. advantages of this logic are speed, and very lowpropagation delay.
complementary metal oxide semiconductor logic (cmos)
it is known for high fan-out, low power consumption and most reliable logicfamily.

Decoders
decoder is a combinational circuit that has ‘n’ input lines and maximum of2n output lines. one of these
outputs will be active high based on the combination of inputs present, when the decoder is enabled.
that means decoderdetects a particular code. the outputs of the decoder are nothing but the min
terms of ‘n’ input variables lines, when it is enabled.

To 4 Decoder
let 2 to 4 decoder has two inputs a1 & a0 and four outputs y3, y2, y1 & [Link] block diagram of 2 to 4
decoder is shown in the following figure.

191
one of these four outputs will be ‘1’ for each combination of inputs when enable,e is ‘1’. the truth table
of 2 to 4 decoder is shown below.

enable inputs outputs

e a1 a0 y3 y2 y1 y0

0 x x 0 0 0 0

1 0 0 0 0 0 1

1 0 1 0 0 1 0

1 1 0 0 1 0 0

1 1 1 1 0 0 0

from truth table, we can write the boolean functions for each output asy3=e.a1.a0
y2=e.a1.a0′y1=e.a1′.a0y0=e.a1′.a0′

192
each output is having one product term. so, there are four product terms in [Link] can implement
these four product terms by using four and gates having three inputs each & two inverters. the
circuit diagram of 2 to 4 decoder is shownin the following figure.
therefore, the outputs of 2 to 4 decoder are nothing but the min terms of two input variables a1 & a0,
when enable, e is equal to one. if enable, e is zero, then allthe outputs of decoder will be equal to zero.
similarly, 3 to 8 decoder produces eight min terms of three input variables a2,
a1 & a0 and 4 to 16 decoder produces sixteen min terms of four input variables a3,a2, a1 & a0.
implementation of higher-order decoders
now, let us implement the following two higher-order decoders using lower-orderdecoders.
3 to 8 decoder
4 to 16 decoder

To 8 Decoder
in this section, let us implement 3 to 8 decoder using 2 to 4 decoders. we know that 2 to 4 decoder
has two inputs, a1 & a0 and four outputs, y3 to y0. whereas, 3to 8 decoder has three inputs a2, a1 & a0
and eight outputs, y7 to y0.
we can find the number of lower order decoders required for implementinghigher order decoder using
the following formula.
required number of lower order decoders =m2/m1 required number of lower order decoders =
m2/m1where,
m1/m1 is the number of outputs of lower order decoder. m2/m2 is the number of outputs of higher
order decoder.
here, m1 = 4 and m2 = 8. substitute, these two values in the above formula.
required number of 2 to 4 decoders = 8/4 =2 required number of 2 to 4decoders=8/4=2

193
therefore, we require two 2 to 4 decoders for implementing one 3 to 8 [Link] block diagram of
3 to 8 decoder using 2 to 4 decoders is shown in the following figure.

the parallel inputs a1 & a0 are applied to each 2 to 4 decoder. the complement ofinput a2 is connected
to enable, e of lower 2 to 4 decoder in order to get the outputs, y3 to y0. these are the lower four min
terms. the input, a2 is directly connected to enable, e of upper 2 to 4 decoder in order to get the
outputs, y7 to y4. these are the higher four min terms.

To 16 Decoder
in this section, let us implement 4 to 16 decoder using 3 to 8 decoders. we knowthat 3 to 8 decoder
has three inputs a2, a1 & a0 and eight outputs, y7 to y0. whereas, 4 to 16 decoder has four inputs a3, a2,
a1 & a0 and sixteen outputs,y15 to y0 we know the following formula for finding the number of lower
order decodersrequired.
required number of lower order decoders = m2/m1 required number of lowerorder decoders = m2/m1
substitute, m1 = 8 and m2 = 16 in the above formula.
required number of 3 to 8 decoders = 16/8 = 2 required number of 3 to 8decoders = 16/8 =2

194
therefore, we require two 3 to 8 decoders for implementing one 4 to 16 [Link] block diagram of
4 to 16 decoder using 3 to 8 decoders is shown in the following figure.

the parallel inputs a2, a1 & a0 are applied to each 3 to 8 decoder. the complement of input, a3 is
connected to enable, e of lower 3 to 8 decoder in order to get the outputs, y7 to y0. these are the lower
eight min terms. the input,a3 is directly connected to enable, e of upper 3 to 8 decoder in order to get
the outputs, y15 to y8. these are the higher eight min terms.

Multiplexers
multiplexer is a combinational circuit that has maximum of 2n data inputs, ‘n’ selection lines and
single output line. one of these data inputs will be connected to the output based on the values of
selection lines.
since there are ‘n’ selection lines, there will be 2n possible combinations of zeros and ones. so, each
combination will select only one data input. multiplexer is also called as mux.

4x1 Multiplexer
4x1 multiplexer has four data inputs i3, i2, i1 & i0, two selection lines s1 & s0 and one output y. the block
diagram of 4x1 multiplexer is shown in the following figure.

195
one of these 4 inputs will be connected to the output based on the combination of inputs present at
these two selection lines. truth table of 4x1 multiplexer is shown below.

selection lines output

s1 s0 y

0 0 i0

0 1 i1

1 0 i2

1 1 i3

from truth table, we can directly write the boolean function for output, y as
y=s1′s0′i0+s1′s0i1+s1s0′i2+s1s0i3
we can implement this boolean function using inverters, and gates & or [Link] circuit diagram of
4x1 multiplexer is shown in the following [Link] can easily understand the operation of the above
circuit. similarly, you can implement 8x1 multiplexer and 16x1 multiplexer by following the same
procedure.
implementation of higher-order multiplexers.
now, implement the following two higher-order multiplexers using lower-order multiplexers.
8x1 multiplexer
16x1 multiplexer

196
8x1 Multiplexer
in this section, implement 8x1 multiplexer using 4x1 multiplexers and 2x1 multiplexer. we know that
4x1 multiplexer has 4 data inputs, 2 selection lines and one output. whereas, 8x1 multiplexer has 8
data inputs, 3 selection linesand one output.
so, we require two 4x1 multiplexers in first stage in order to get the 8 data inputs. since, each 4x1
multiplexer produces one output, we require a 2x1 multiplexer in second stage by considering the
outputs of first stage as inputs and to produce the final output.
let the 8x1 multiplexer has eight data inputs i7 to i0, three selection lines s2, s1 & s0 and one output y.
the truth table of 8x1 multiplexer is shown below.

selection inputs output

s2 s1 s0 y

0 0 0 i0

0 0 1 i1

0 1 0 i2

0 1 1 i3

1 0 0 i4

1 0 1 i5

1 1 0 i6

1 1 1 i7

we can implement 8x1 multiplexer using lower order multiplexers easily byconsidering the above
truth table. the block diagram of 8x1 multiplexer is shown in the following figure.

197
the same selection lines, s1 & s0 are applied to both 4x1 multiplexers. the data inputs of upper 4x1
multiplexer are i7 to i4 and the data inputs of lower 4x1 multiplexer are i3 to i0. therefore, each 4x1
multiplexer produces an outputbased on the values of selection lines, s1 & s0.
the outputs of first stage 4x1 multiplexers are applied as inputs of 2x1 multiplexer that is present in
second stage. the other selection line, s2 is applied to 2x1 multiplexer.
if s2 is zero, then the output of 2x1 multiplexer will be one of the 4 inputsi3 to i0 based on
the values of selection lines s1 & s0.
if s2 is one, then the output of 2x1 multiplexer will be one of the 4 inputsi7 to i4 based on the values
of selection lines s1 & s0.
therefore, the overall combination of two 4x1 multiplexers and one 2x1multiplexer performs as
one 8x1 multiplexer.

16x1 Multiplexer
in this section, implement 16x1 multiplexer using 8x1 multiplexers and 2x1 multiplexer. we know that
8x1 multiplexer has 8 data inputs, 3 selection lines and one output. whereas, 16x1 multiplexer has 16
data inputs, 4 selection lines and one output.
so, we require two 8x1 multiplexers in first stage in order to get the 16 data inputs. since, each 8x1
multiplexer produces one output, we require a 2x1 multiplexer in second stage by considering the
outputs of first stage as inputs and to produce the final output.
let the 16x1 multiplexer has sixteen data inputs i15 to i0, four selection lines s3 to s0 and one output y.
the truth table of 16x1 multiplexer is shown below.

selection inputs output

s3 s2 s1 s0 y

0 0 0 0 i0

0 0 0 1 i1

198
0 0 1 0 i2

0 0 1 1 i3

0 1 0 0 i4

0 1 0 1 i5

0 1 1 0 i6
0 1 1 1 i7
1 0 0 0 i8
1 0 0 1 i9
1 0 1 0 i10
1 0 1 1 i11
1 1 0 0 i12
1 1 0 1 i13
1 1 1 0 i14
1 1 1 1 i15

we can implement 16x1 multiplexer using lower order multiplexers easily by considering the above
truth table. the block diagram of 16x1 multiplexer is shown in the following figure.

the same selection lines, s2, s1 & s0 are applied to both 8x1 multiplexers. the data inputs of upper 8x1
multiplexer are i15 to i8 and the data inputs of lower 8x1multiplexer are i7 to i0. therefore, each 8x1
multiplexer produces an outputbased on the values of selection lines, s2, s1 & s0.
199
the outputs of first stage 8x1 multiplexers are applied as inputs of 2x1 multiplexer that is present in
second stage. the other selection line, s3 is applied to 2x1 multiplexer.
if s3 is zero, then the output of 2x1 multiplexer will be one of the 8 inputs is7 to i0 based on the values
of selection lines s2, s1 & s0.
if s3 is one, then the output of 2x1 multiplexer will be one of the 8 inputs i15 to i8 based on the values
of selection lines s2, s1 & s0.
therefore, the overall combination of two 8x1 multiplexers and one 2x1 multiplexer performs as one
16x1 multiplexer.

Digital Registers
flip-flop is a 1 bit memory cell which can be used for storing the digital data. to increase the storage
capacity in terms of number of bits, we have to use a group of flip-flop. such a group of flip-flop is
known as a register. the n-bit register willconsist of n number of flip-flop and it is capable of storing
an n-bit word.
the binary data in a register can be moved within the register from one flip-flopto another. the registers
that allow such data transfers are called as shift registers. there are four mode of operations of a
shift register.
serial input serial output
serial input parallel output
parallel input serial output
parallel input parallel output

Serial Input Serial Output


let all the flip-flop be initially in the reset condition i.e. q3 = q2 = q1 = q0 = 0. if anentry of a four bit binary
number 1 1 1 1 is made into the register, this number should be applied to din bit with the lsb bit
applied first. the d input of ff-3 i.e. d3 is connected to serial data input din. output of ff-3 i.e. q3 is
connected to the input of the next flip-flop i.e. d2 and so on.

Block Diagram

Operation
before application of clock signal, let q3 q2 q1 q0 = 0000 and apply lsb bit of thenumber to be entered
to din. so din = d3 = 1. apply the clock. on the first falling
edge of clock, the ff-3 is set, and stored word in the register is q3 q2 q1 q0 =1000.

200
apply the next bit to din. so din = 1. as soon as the next negative edge of the clockhits, ff-2 will set and
the stored word change to q3 q2 q1 q0 = 1100.

apply the next bit to be stored i.e. 1 to din. apply the clock pulse. as soon as thethird negative clock
edge hits, ff-1 will be set and output will be modified to
q3 q2 q1 q0 = 1110.

similarly with din = 1 and with the fourth negative clock edge arriving, the storedword in the register is
q3 q2 q1 q0 = 1111.

201
Truth Table

Waveforms

Serial Input Parallel Output


in such types of operations, the data is entered serially and taken out inparallel fashion.
data is loaded bit by bit. the outputs are disabled as long as the data isloading.
as soon as the data loading gets completed, all the flip-flops contain theirrequired data, the outputs
are enabled so that all the loaded data is madeavailable over all the output lines at the same time.
4 clock cycles are required to load a four bit word. hence the speed ofoperation of sipo mode is same
as that of siso mode.

Block Diagram

202
Parallel Input Serial Output (Piso)
data bits are entered in parallel fashion.
the circuit shown below is a four bit parallel input serial output register.
output of previous flip flop is connected to the input of the next one via acombinational circuit.
the binary input word b0, b1, b2, b3 is applied though the samecombinational circuit.
there are two modes in which this circuit can work namely - shift mode orload mode.

Load Mode
when the shift/load bar line is low (0), the and gate 2, 4 and 6 become active they will pass b1, b2, b3
bits to the corresponding flip-flops. on the low going edgeof clock, the binary input b0, b1, b2, b3 will
get loaded into the corresponding flip- flops. thus parallel loading takes place.

Shift Mode
when the shift/load bar line is low (1), the and gate 2, 4 and 6 become inactive. hence the parallel
loading of the data becomes impossible. but the and gate 1,3and 5 become active. therefore the
shifting of data from left to right bit by bit onapplication of clock pulses. thus the parallel in serial out
operation takes place.

203
Block Diagram

Parallel Input Parallel Output (Pipo)


in this mode, the 4 bit binary input b0, b1, b2, b3 is applied to the data inputs d0, d1, d2, d3 respectively
of the four flip-flops. as soon as a negative clock edge is applied, the input binary bits will be loaded
into the flip-flops simultaneously. theloaded bits will appear simultaneously to the output side. only
clock pulse is essential to load all the bits.

Block Diagram

Bidirectional Shift Register


if a binary number is shifted left by one position then it is equivalent to multiplying the original number
by 2. similarly if a binary number is shifted right by one position then it is equivalent to dividing the

204
original number by2.
hence if we want to use the shift register to multiply and divide the givenbinary number, then we
should be able to move the data in either left or right direction.
such a register is called bi-directional register. a four bit bi-directional shiftregister is shown in fig.
there are two serial inputs namely the serial right shift data input dr, andthe serial left shift data input
dl along with a mode select input (m).

Block Diagram

Operation

s.n. condition operation


if m = 1, then the and gates1, 3, 5
and 7 are enabled whereas the
remaining andgates 2, 4, 6 and 8
will be disabled.
1 with m = 1 − shift right operation the data at dr is shifted to right bit
by bit from ff-3 toff-0 on the
application of clock pulses. thus
with m =1 we get the serial right
shift operation.

Universal Shift Register


a shift register which can shift the data in only one direction is called a uni- directional shift register.
a shift register which can shift the data in both directions is called a bi-directional shift register.
applying the same logic, a shift register which can shift the data in both directions as well as load it
parallely, is known as a universal shift register. the shift register is capable of performing thefollowing
operation −
parallel loading
left shifting
right shifting
the mode control input is connected to logic 1 for parallel loading operation whereas it is connected
to 0 for serial shifting. with mode control pin connected to ground, the universal shift register acts as

205
a bi-directional register. for serial left operation, the input is applied to the serial input which goes to
and gate-1 shown in figure. whereas for the shift right operation, the serial input is appliedto d input.

Block Diagram

Counter
in digital logic and computing, a counter is a device which stores (and sometimes displays) the
number of times a particular event or process has occurred, often inrelationship to a clock signal.
counters are used in digital electronics for countingpurpose, they can count specific event happening
in the circuit. for example, in up counter a counter increases count for every rising edge of clock. not
only counting, a counter can follow the certain sequence based on our design like any random
sequence 0,1,3,2… .they can also be designed with the help of flip flops.

Counter Classification
counters are broadly divided into two categories
asynchronous counter
synchronous counter

Asynchronous Counter
in asynchronous counter we don’t use universal clock, only first flip flop is drivenby main clock and
the clock input of rest of the following flip flop is driven by output of previous flip flops. we can
understand it by following diagram-

206
it is evident from timing diagram that q0 is changing as soon as the rising edge ofclock pulse is
encountered, q1 is changing when rising edge of q0 is encountered(because q0 is like clock pulse for
second flip flop) and so on. in thisway ripples are generated through q0,q1,q2,q3 hence it is also
called ripple counter.

Synchronous Counter
unlike the asynchronous counter, synchronous counter has one global clock which drives each flip
flop so output changes in parallel. the one advantage ofsynchronous counter over asynchronous
counter is, it can operate on higher frequency than asynchronous counter as it does not have

207
cumulative delay because of same clock is given to each flip flop.
Synchronous Counter Circuit

Timing Diagram Synchronous Counter


from circuit diagram we see that q0 bit gives response to each falling edge of clock while q1 is
dependent on q0, q2 is dependent on q1 and q0 , q3 is dependent on q2,q1 and q0.

Decade Counter
a decade counter counts ten different states and then reset to its initial states. asimple decade
counter will count from 0 to 9 but we can also make the decade counters which can go through any
ten states between 0 to 15(for 4 bit counter).

clock pulse q3 q2 q1 q0

0 0 0 0 0

1 0 0 0 1

208
2 0 0 1 0

3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
10 0 0 0 0

Truth Table For Simple Decade Counter


Decade Counter Circuit Diagram
we see from circuit diagram that we have used nand gate for q3 and q1 andfeeding this to clear input
line because binary representation of 10 is—1010
and we see q3 and q1 are 1 here, if we give nand of these two bits to clear inputthen counter will be
clear at 10 and again start from beginning.

Important point: number of flip flops used in counter are always greater thanequal to (log2 n) where
n=number of states in counter.

Representation Of Data
data and instructions cannot be entered and processed directly into computers using human
language. any type of data be it numbers, letters,special symbols, sound or pictures must first be
converted into machine- readable form i.e. binary form. due to this reason, it is important to
understand how a computer together with its peripheral devices handles data in its electronic circuits,
on magnetic media and in optical devices.
209
Data Representation In Digital Circuits
electronic components, such as microprocessor, are made up of millions ofelectronic circuits. the
availability of high voltage(on) in these circuits is interpreted as ‘1’ while a low voltage (off) is
interpreted as ‘0’.this conceptcan be compared to switching on and off an electric circuit. when the
switch is closed the high voltage in the circuit causes the bulb to light (‘1’ state).on the other hand
when the switch is open, the bulb goes off (‘0’ state). this forms a basis for describing data
representation in digital computers using the binary number system.

Data Representation On Magnetic Media


the laser beam reflected from the land is interpreted, as [Link] laser entering the pot is not reflected.
this is interpreted as [Link] reflected pattern of light from the rotating disk falls on a receiving
photoelectric

detector that transforms the patterns into digital [Link] presence of a magnetic field in one
direction on magnetic media is interpreted as 1; whilethe field in the opposite direction is interpreted
as “0”.magnetic technologyis mostly used on storage devices that are coated with special magnetic
materials such as iron oxide. data is written on the media by arranging the magnetic dipoles of some
iron oxide particles to face in the same direction and some others in the opposite direction

Data Representation On Optical Media


in optical devices, the presence of light is interpreted as ‘1’ while its absence is interpreted as
‘0’.optical devices use this technology to read or store data. take example of a cd-rom, if the shiny
surface is placed under a powerful microscope,the surface is observed to have very tiny holes called
pits. the areas that do not have pits are called land.
computer does not understand human language. any data, viz., letters, symbols, pictures, audio,
videos, etc., fed to computer should be converted to machine language first. computers represent
data in the following three forms –

Number System
we are introduced to concept of numbers from a very early age. to a computer,everything is a number,
i.e., alphabets, pictures, sounds, etc., are numbers.
number system is categorized into four types −
binary number system consists of only two values, either 0 or 1
octal number system represents values in 8 digits.
decimal number system represents values in 10 digits.
hexadecimal number system represents values in 16 digits.

number system
system base digits

binary 2 01

210
octal 8 01234567

decimal 10 0123456789

hexadecimal 16 0123456789abcdef

Bits And Bytes


bits − a bit is a smallest possible unit of data that a computer can recognize oruse. computer usually
uses bits in groups.
bytes − group of eight bits is called a byte. half a byte is called a nibble.

The following table shows conversion of bits and bytes −

byte value bit value

1 byte 8 bits

1024 bytes 1 kilobyte

1024 kilobytes 1 megabyte

1024 megabytes 1 gigabyte

1024 gigabytes 1 terabyte

1024 terabytes 1 petabyte

1024 petabytes 1 exabyte

211
1024 exabytes 1 zettabyte

1024 zettabytes 1 yottabyte

1024 yottabytes 1 brontobyte

1024 brontobytes 1 geopbytes

Text Code
text code is format used commonly to represent alphabets, punctuation marksand other symbols.
four most popular text code systems are − ebcdic ascii
extended ascii unicode
Ebcdic
extended binary coded decimal interchange code is an 8-bit code that defines256 symbols. given
below is the ebcdic tabular column

Ascii
american standard code for information interchange is an 8-bit code thatspecifies character values
from 0 to 127.

Ascii Tabular Column

212
ascii code decimal value character

0000 0000 0 null prompt

0000 0001 1 start of heading

0000 0010 2 start of text

0000 0011 3 end of text


0000 0100 4 end of transmit
0000 0101 5 enquiry
0000 0110 6 acknowledge
0000 0111 7 audible bell
0000 1000 8 backspace
0000 1001 9 horizontal tab
0000 1010 10 line feed

Extended Ascii
extended American standard code for information interchange is an 8-bit code that specifies
character values from 128 to 255.

Extended Ascii Tabular Column

Unicode
unicode worldwide character standard uses 4 to 32 bits to represent letters,numbers and symbol.

Unicode tabular column

213
Data Types
a very simple but very important concept available in almost all the programming languages which is
called data types. as its name indicates, a data type representsa type of the data which you can
process using your computer program. it can be numeric, alphanumeric, decimal, etc.
keep computer programming aside for a while and take an easy example of adding two whole
numbers 10 & 20, which can be done simply as follows −10 + 20 another problem where we want to
add two decimal numbers 10.50 & 20.50,which will be written as follows −10.50 + 20.50
the two examples are straightforward. now another example where we want to record student
information in a notebook. here we would like to record the following information −
name:
class:
section:
age:
sex:
now, put one student record as per the given requirement –
name: zara ali
class: 6th
section: j
age: 13
sex: f
the first example dealt with whole numbers, the second example added two decimal numbers,
whereas the third example is dealing with a mix of differentdata.
put it as follows −
student name "zara ali" is a sequence of characters which is also calleda string.
student class "6th" has been represented by a mix of whole number anda string of two characters.
such a mix is called alphanumeric.
student section has been represented by a single character which is 'j'.
student age has been represented by a whole number which is 13.
student sex has been represented by a single character which is 'f'.
this way, we realized that in our day-to-day life, we deal with different types of data such as strings,
characters, whole numbers (integers), and decimal numbers(floating point numbers).
similarly, when we write a computer program to process different types of data,we need to specify its
type clearly; otherwise the computer does not understand how different operations can be performed
on that given data. different programming languages use different keywords to specify different data
types. for example, c and java programming languages use int to specify integer data,whereas char

214
specifies a character data type.
subsequent chapters will show you how to use different data types in differentsituations. for now,
check the important data types available in c, java, and python and the keywords we will use to specify
those data types.

C And Java Data Types


c and java support almost the same set of data types, though java supportsadditional data types. for
now, we are taking a few common data types supported by both the programming languages −

type keyword value range which can be represented by this datatype

character char -128 to 127 or 0 to 255

number int -32,768 to 32,767 or -2,147,483,648 to


2,147,483,647

small number short -32,768 to 32,767

long number long -2,147,483,648 to 2,147,483,647

decimal number float 1.2e-38 to 3.4e+38 till 6 decimal places

these data types are called primitive data types and you can use these data types to build more
complex data types, which are called user-defined data type, for example a string will be a sequence
of characters.

Python Data Types


python has five standard data types but this programming language does not make use of any
keyword to specify a particular data type, rather python is intelligent enough to understand a given
data type automatically.
numbers
string
list
tuple
dictionary
here, number specifies all types of numbers including decimal numbers and string represents a
sequence of characters with a length of 1 or more characters. for now, proceed with these two data
types and skip list, tuple, and dictionary, which are advanced data types in python.

Number System
the technique to represent and work with numbers is called number system. decimal number system
is the most common number system. other
popular number systems include binary number system, octal number system,hexadecimal number
system, etc.

215
Decimal Number System
decimal number system is a base 10 number system having 10 digits from 0 to [Link] means that any
numerical quantity can be represented using these 10 digits. decimal number system is also a
positional value system. this means that the value of digits will depend on its position. let us take an
example to understand this.
say we have three numbers – 734, 971 and 207. the value of 7 in all threenumbers is different−
in 734, value of 7 is 7 hundreds or 700 or 7 × 100 or 7 × 102
in 971, value of 7 is 7 tens or 70 or 7 × 10 or 7 × 101
in 207, value 0f 7 is 7 units or 7 or 7 × 1 or 7 × 100
the weightage of each position can be represented as follows −

in digital systems, instructions are given through electric signals; variation is done by varying the
voltage of the signal. having 10 different voltages to implement decimal number system in digital
equipment is difficult. so, many number systemsthat are easier to implement digitally have been
developed. let’s look at them in detail.

Binary Number System


the easiest way to vary instructions through electric signals is two-state system –on and off. on is
represented as 1 and off as 0, though 0 is not actually no signal but signal at a lower voltage. the
number system having just these two digits – 0and 1 – is called binary number system.
each binary digit is also called a bit. binary number system is also positional valuesystem, where each
digit has a value expressed in powers of 2, as displayed here.

in any binary number, the rightmost digit is called least significant bit (lsb) andleftmost digit is called
most significant bit (msb).

and decimal equivalent of this number is sum of product of each digit with itspositional value.
110102 = 1×24 + 1×23 + 0×22 + 1×21 + 0×20
= 16 + 8 + 0 + 2 + 0
= 2610
computer memory is measured in terms of how many bits it can store. here is achart for memory
216
capacity conversion.
1 byte (b) = 8 bits
1 kilobytes (kb) = 1024 bytes
1 megabyte (mb) = 1024 kb
1 gigabyte (gb) = 1024 mb
1 terabyte (tb) = 1024 gb
1 exabyte (eb) = 1024 pb
1 zettabyte = 1024 eb
1 yottabyte (yb) = 1024 zb

Octal Number System


octal number system has eight digits – 0, 1, 2, 3, 4, 5, 6 and 7. octal numbersystem is also a positional
value system with where each digit has its value expressed in powers of 8, as shown here −

decimal equivalent of any octal number is sum of product of each digit with itspositional value.
7268 = 7×82 + 2×81 + 6×80
= 448 + 16 + 6
= 47010

Hexadecimal Number System


octal number system has 16 symbols – 0 to 9 and a to f where a is equal to 10, bis equal to 11 and
so on till f. hexadecimal number system is also a positional value system with where each digit has
its value expressed in powers of 16, as shown here −

decimal equivalent of any hexadecimal number is sum of product of each digitwith its positional
value.
27fb16 = 2×163 + 7×162 + 15×161 + 10×160
= 8192 + 1792 + 240 +10
= 1023410

Number System Relationship


the following table depicts the relationship between decimal, binary, octal andhexadecimal number
systems.

hexadecimal decimal octal binary

0 0 0 0000

217
1 1 1 0001

2 2 2 0010

3 3 3 0011

4 4 4 0100

5 5 5 0101

6 6 6 0110

7 7 7 0111

8 8 10 1000

9 9 11 1001

a 10 12 1010

b 11 13 1011

c 12 14 1100

d 13 15 1101

e 14 16 1110

f 15 17 1111

Ascii
besides numerical data, computer must be able to handle alphabets, punctuation marks,
mathematical operators, special symbols, etc. that form the complete character set of english
language. the complete set of characters or symbols are called alphanumeric codes. the complete
alphanumeric code typically includes −
26 upper case letters
26 lower case letters
10 digits
7 punctuation marks
20 to 40 special characters
now a computer understands only numeric values, whatever the number system used. so all
characters must have a numeric equivalent called the alphanumeric code. the most widely used
alphanumeric code is American standard code for information interchange (ascii). ascii is a 7-bit
code that has 128 (27) possible codes.

218
Iscii
iscii stands for indian script code for information interchange. iiscii was developed to support indian
languages on computer. language supported by iisci include devanagari, tamil, bangla, gujarati,
gurmukhi, tamil, telugu, etc. iisci is mostly used by government departments and before it could catch
on, a new universal encoding standard called unicode was introduced.

Unicode

219
unicode is an international coding system designed to be used with different language scripts. each
character or symbol is assigned a unique numeric value,largely within the framework of ascii. earlier,
each script had its own encodingsystem, which could conflict with each other.
in contrast, this is what unicode officially aims to do − unicode provides a uniquenumber for every
character, no matter what the platform, no matter what the program, no matter what the language.

Number System Conversion


there are many methods or techniques which can be used to convert numbers from one base to
another. here the following −
decimal to other base system
other base system to decimal
other base system to non-decimal
shortcut method − binary to octal
shortcut method − octal to binary
shortcut method − binary to hexadecimal
shortcut method − hexadecimal to binary

Decimal To Other Base SystemSteps


step 1 − divide the decimal number to be converted by the value of thenew base.
step 2 − get the remainder from step 1 as the rightmost digit (leastsignificant digit) of new base
number.
step 3 − divide the quotient of the previous divide by the new base.
step 4 − record the remainder from step 3 as the next digit (to the left) ofthe new base number.
repeat steps 3 and 4, getting remainders from right to left, until the quotientbecomes zero in step 3.
the last remainder thus obtained will be the most significant digit (msd) of thenew base number.
example −
decimal number: 2910 calculating binary equivalent –

step operation result remainder


step 1 29 / 2 14 1
step 2 14 / 2 7 0
step 3 7/2 3 1
step 4 3/2 1 1
step 5 1/2 0 1

as mentioned in steps 2 and 4, the remainders have to be arranged in the reverseorder so that the first
remainder becomes the least significant digit (lsd) and the last remainder becomes the most
significant digit (msd).
decimal number − 2910 = binary number − 111012.

Other Base System To Decimal SystemSteps


step 1 − determine the column (positional) value of each digit (this depends on the position of the
digit and the base of the number system).
step 2 − multiply the obtained column values (in step 1) by the digits in thecorresponding columns.
220
step 3 − sum the products calculated in step 2. the total is the equivalentvalue in decimal.
example
binary number − 111012 calculating decimal equivalent −
step binary number decimal number

step 1 111012 ((1 × 24) + (1 × 23) + (1 × 22) + (0 × 21) + (1 × 20))10

step 2 111012 (16 + 8 + 4 + 0 + 1)10

step 3 111012 2910

binary number − 111012 = decimal number − 2910


other base system to non-decimal systemsteps
step 1 − convert the original number to a decimal number (base 10).
step 2 − convert the decimal number so obtained to the new base number.
example
octal number − 258

Calculating Binary Equivalent −


step 1 − convert to decimal

step octal number decimal number

step 1 258 ((2 × 81) + (5 × 80))10

step 2 258 (16 + 5 )10

step 3 258 2110

octal number − 258 = decimal number − 2110step 2 − convert decimal to binary


step operation result remainder

step 1 21 / 2 10 1

step 2 10 / 2 5 0

step 3 5/2 2 1

step 4 2/2 1 0

step 5 1/2 0 1
decimal number − 2110 = binary number − 101012
221
octal number − 258 = binary number − 101012

Shortcut Method - Binary To OctalSteps


step 1 − divide the binary digits into groups of three (starting from theright).
step 2 − convert each group of three binary digits to one octal digit.
example
binary number − 101012 calculating octal equivalent –

step binary number octal number

step 1 101012 010 101

step 2 101012 28 58

step 3 101012 258

binary number − 101012 = octal number − 258

Shortcut Method - Octal To BinarySteps


step 1 − convert each octal digit to a 3-digit binary number (the octal digitsmay be treated as decimal
for this conversion).
step 2 − combine all the resulting binary groups (of 3 digits each) into asingle binary number.
example
octal number − 258 calculating binary equivalent –

step octal number binary number

step 1 258 210 510

step 2 258 0102 1012

step 3 258 0101012

octal number − 258 = binary number − 101012shortcut method - binary to hexadecimal steps
step 1 − divide the binary digits into groups of four (starting from the right).
step 2 − convert each group of four binary digits to one hexadecimalsymbol.
example
binary number − 101012
calculating hexadecimal equivalent −

222
step binary number hexadecimal number

step 1 101012 0001 0101

step 2 101012 110 510

step 3 101012 1516

binary number − 101012 = hexadecimal number − 1516

Shortcut Method - Hexadecimal To BinarySteps


step 1 − convert each hexadecimal digit to a 4 digit binary number (thehexadecimal digits may be
treated as decimal for this conversion).
step 2 − combine all the resulting binary groups (of 4 digits each) into asingle binary number.
example
hexadecimal number − 1516 calculating binary equivalent –

step hexadecimal number binary number

step 1 1516 110 510

step 2 1516 00012 01012

step 3 1516 000101012

hexadecimal number − 1516 = binary number − 101012

Complement Arithmetic
complements are used in the digital computers in order to simplify the subtraction operation and for
the logical manipulations. for each radix-r system (radix r represents base of number system) there
are two types of complements.

s.n. complement description

the radix complement isreferred to


1 radix complement
as the r's complement

223
the diminished radix complement is
2 diminished radix complement
referred toas the (r-1)'s complement

Binary System Complements


as the binary system has base r = 2. so the two types of complements for thebinary system are 2's
complement and 1's complement.

1's complement
the 1's complement of a number is found by changing all 1's to 0's and all 0's to1's. this is called as
taking complement or 1's complement. example of 1's complement is as follows.

2's complement
the 2's complement of binary number is obtained by adding 1 to the leastsignificant bit (lsb) of 1's
complement of the number.
2's complement = 1's complement + 1

Example of 2's complement is as follows.

Fixed Point And Floating Point Number Representations


digital computers use binary number system to represent all types of information inside the
computers. alphanumeric characters are represented using binary bits (i.e., 0 and 1). digital
224
representations are easier to design, storage is easy, accuracy and precision are greater.
there are various types of number representation techniques for digital number representation, for
example: binary number system, octal number system, decimal number system, and hexadecimal
number system etc. but binary numbersystem is most relevant and popular for representing numbers
in digital computersystem.

Storing Real Number


these are structures as following below −

there are two major approaches to store real numbers (i.e., numbers with fractional component) in
modern computing. these are (i) fixed point notation and (ii) floating point notation. in fixed point
notation, there are a fixed numberof digits after the decimal point, whereas floating point number
allows for a varying number of digits after the decimal point.

Fixed-Point Representation −
this representation has fixed number of bits for integer part and for fractional part. for example, if
given fixed-point representation is [Link], then you can store minimum value is 0000.0001 and
maximum value is 9999.9999. there arethree parts of a fixed-point number representation: the sign
field, integer field,and fractional field.

we can represent these numbers using:


signed representation: range from -(2(k-1)-1) to (2(k-1)-1), for k bits.
1’s complement representation: range from -(2(k-1)-1) to (2(k-1)-1), for k bits.
2’s complementation representation: range from -(2(k-1)) to (2(k-1)-1), for kbits.
2’s complementation representation is preferred in computer system because of unambiguous
property and easier for arithmetic operations.
225
Example −assume number is using 32-bit format which reserve 1 bit for the sign,15 bits for the integer
part and 16 bits for the fractional part.
then, -43.625 is represented as following:

where, 0 is used to represent + and 1 is used to represent. 000000000101011 is15 bit binary value for
decimal 43 and 1010000000000000 is 16 bit binary valuefor fractional 0.625.
the advantage of using a fixed-point representation is performance and disadvantage is relatively
limited range of values that they can represent. so, it isusually inadequate for numerical analysis as it
does not allow enough numbers and accuracy. a number whose representation exceeds 32 bits
would have to be stored inexactly.

these are above smallest positive number and largest positive number which canbe store in 32-bit
representation as given above format. therefore, the smallest positive number is 2-16 ≈ 0.000015
approximate and the largest positive number is (215-1)+(1-2-16)=215(1-2-16) =32768, and gap between
these numbers is 2-16.
we can move the radix point either left or right with the help of only integer fieldis 1.

Floating Point Representation


this representation does not reserve a specific number of bits for the integer partor the fractional part.
instead it reserves a certain number of bits for the number (called the mantissa or significand) and a
certain number of bits to say where within that number the decimal place sits (called the exponent).
the floating number representation of a number has two part: the first part represents a signed fixed
point number called mantissa. the second part of designates the position of the decimal (or binary)
point and is called the exponent. the fixed point mantissa may be fraction or an integer. floating -
pointis always interpreted to represent a number in the following form: mxre.
only the mantissa m and the exponent e are physically represented in the register(including their sign).
a floating-point binary number is represented in a similar manner except that is uses base 2 for the
exponent. a floating-point number is said to be normalized if the most significant digit of the mantissa
is 1.

226
so, actual number is (-1)s(1+m)x2(e-bias), where s is the sign bit, m is themantissa, e is the exponent
value, and bias is the bias number.
note that signed integers and exponent are represented by either sign
representation, or one’s complement representation, or two’s complementrepresentation.
the floating point representation is more flexible. any non-zero number can be represented in the
normalized form of ±(1.b1b2b3 ...)2x2n this is normalized formof a number x.
the following description explains terminology and primary details of ieee 754 binary floating point
representation. the discussion confines to single and doubleprecision formats.
usually, a real number in binary will be represented in the following format,
imim-1…i2i1i0.f1f2…fnfn-1
where im and fn will be either 0 or 1 of integer and fraction parts respectively.
a finite number can also represented by four integers components, a sign (s), a base (b), a significand
(m), and an exponent (e). then the numerical value of thenumber is evaluated as
(-1)s x m x be where m < |b|
depending on base and the number of bits used to encode various components,the ieee 754 standard
defines five basic formats. among the five formats, the binary32 and the binary64 formats are single
precision and double precision formats respectively in which the base is 2.
table – 1 precision representation

precision base sign exponent significand

single precision 2 1 8 23+1

double precision 2 1 11 52+1

Single Precision Format:


as mentioned in table 1 the single precision format has 23 bits for significand (1represents implied
bit, details below), 8 bits for exponent and 1 bit for sign.
for example, the rational number 9÷2 can be converted to single precision floatformat as following,
9(10) ÷ 2(10) = 4.5(10) = 100.1(2)
the result said to be normalized, if it is represented with leading 1 bit, i.e. 1.001(2) x 22. (similarly when
the number 0.000000001101(2) x 23 is normalized, itappears as 1.101(2) x 2-6). omitting this implied 1
on left extreme gives us
the mantissa of float number. a normalized number provides more accuracy thancorresponding de-

227
normalized number. the implied most significant bit can be used to represent even more accurate
significand (23 + 1 = 24 bits) which is called subnormal representation. the floating point numbers
are to berepresented in normalized form.
the subnormal numbers fall into the category of de-normalized numbers. the subnormal
representation slightly reduces the exponent range and can’t be normalized since that would result
in an exponent which doesn’t fit in the field. subnormal numbers are less accurate, i.e. they have less
room for nonzero bits inthe fraction field, than normalized numbers. indeed, the accuracy drops as
the size of the subnormal number decreases. however, the subnormal representationis useful in filing
gaps of floating point scale near zero.
in other words, the above result can be written as (-1)0 x 1.001(2) x 22 which yields the integer
components as s = 0, b = 2, significand (m) = 1.001, mantissa = 001 ande = 2. the corresponding
single precision floating number can be represented in binary as shown below,

where the exponent field is supposed to be 2, yet encoded as 129 (127+2) called biased exponent.
the exponent field is in plain binary format which alsorepresents negative exponents with an encoding
(like sign magnitude, 1’s complement, 2’s complement, etc.). the biased exponent is used for the
representation of negative exponents. the biased exponent has advantages over other negative
representations in performing bitwise comparing of two floating point numbers for equality.
a bias of (2n-1 – 1), where n is # of bits used in exponent, is added to the exponent
to get biased exponent (e). so, the biased exponent (e) of singleprecision number can be obtained as
e = e + 127 the range of exponent in single precision format is -128 to +127. other values areused
for special symbols.
note: when we unpack a floating point number the exponent obtained is the biased exponent.
subtracting 127 from the biased exponent we can extract unbiased exponent.

Double Precision Format:


as mentioned in table – 1 the double precision format has 52 bits for significand(1 represents implied
bit), 11 bits for exponent and 1 bit for sign. all other definitions are same for double precision format,
except for the size of various components.

Precision:
the smallest change that can be represented in floating point representation is called as precision.
the fractional part of a single precision normalized number has exactly 23 bits of resolution, (24 bits
with the implied bit). this corresponds tolog(10) (223) = 6.924 = 7 (the characteristic of logarithm)
decimal digits of accuracy. similarly, in case of double precision numbers the precision is log(10) (252)
= 15.654
= 16 decimal digits.

Accuracy:

228
accuracy in floating point representation is governed by number of significand bits, whereas range is
limited by exponent. not all real numbers can exactly be represented in floating point format. for any
numberwhich is not floating point number, there are two options for floating point approximation, say,
the closestfloating point number less than x as x_ and the closest floating point
number greater than x as x+. a rounding operation is performed on number of significant bits in the
mantissa field based on the selected mode. the round down mode causes x set to x_, the round up
mode causes x set to x+, the round towards zero mode causes x is either x_ or x+ whichever is
between zero and.
the round to nearest mode sets x to x_ or x+ whichever is nearest to x. usually round to nearest is
most used mode. the closeness of floating point representation to the actual value is called as
accuracy.

Special Bit Patterns:


the standard defines few special floating point bit patterns. zero can’t have mostsignificant 1 bit,
hence can’t be normalized. the hidden bit representation requires a special technique for storing zero.
we will have two different bit patterns +0 and -0 for the same numerical value zero. for single precision
floatingpoint representation, these patterns are given below,
0 00000000 00000000000000000000000 = +0
1 00000000 00000000000000000000000 = -0
similarly, the standard represents two different bit patters for +inf and -inf. thesame are given below,
0 11111111 00000000000000000000000 = +inf

1 11111111 00000000000000000000000 = -inf


all of these special numbers, as well as other special numbers (below) are subnormal numbers,
represented through the use of a special bit pattern in theexponent field. this slightly reduces the
exponent range, but this is quite acceptable since the range is so large.
an attempt to compute expressions like 0 x inf, 0 ÷ inf, etc. make no mathematical sense. the standard
calls the result of such expressions as not a number (nan). any subsequent expression with nan yields
nan. the representation of nan has non-zero significand and all 1s in the exponent [Link] are
shown below for single precision format (x is don’t care bits),
x 11111111 1m0000000000000000000000
where m can be 0 or 1. this gives us two different representations of nan.
0 11111111 110000000000000000000000 signaling nan (snan)
0 11111111 100000000000000000000000 quiet nan (qnan)
usually qnan and snan are used for error handling. qnan do not raise any exceptions as they propagate
through most operations. whereas snan are whichwhen consumed by most operations will raise an
invalid exception.

Overflow And Underflow:

Overflow is said to occur when the true result of an arithmetic operation is finite but larger in
magnitude than the largest floating point number which can be stored using the given precision.

Underflow is said to occur when the true resultof an arithmetic operation is smaller in magnitude
(infinitesimal) than the smallest normalized floating point number which can be stored. overflow can’t
beignored in calculations whereas underflow can effectively be replaced by zero.

Endianness:
229
the ieee 754 standard defines a binary floating point format. the architecture details are left to the
hardware manufacturers. the storage order of individualbytes in binary floating point numbers varies
from architecture to architecture.

Error Detection Codes


the binary information is transferred from one location to another location through some
communication medium. the external noise can change bits from 1to 0 or 0 to [Link] changes in
values are called errors. for efficient data transfer, there should be an error detection and correction
codes. an error detection code is a binary code that detects digital errors during transmission. a
famous error detection code is a parity bit method.

Parity Bit Method:


a parity bit is an extra bit included in binary message to make total number of 1’seither odd or even.
parity word denotes number of 1’s in a binary string. there are two parity system-even and odd. in
even parity system 1 is appended to binary string it there is an odd number of 1’s in string otherwise
0 is appended tomake total even number of 1’s.

in odd parity system, 1 is appended to binary string if there is even a number of 1’s to make an odd
number of 1’s. the receiver knows that whether sender is an odd parity generator or even parity
generator. suppose if sender is an odd parity generator then there must be an odd number of 1’s in
received binary string. if anerror occurs to a single bit that is either bit is changed to 1 to 0 or o to 1,
receivedbinary bit will have an even number of 1’s which will indicate an error.

230
the limitation of this method is that only error in a single bit would be identified.

message (xyz) p(odd) p(even)

000 1 0

001 0 1

010 0 1

011 1 0

100 0 1

101 1 0

110 1
0
111 0 1

231
figure – error detection with odd parity bit

Points To Remember:
in 1’s complement of signed number +0 and -0 has two differentrepresentation.
the range of signed magnitude representation of an 8-bit number in which1-bit is used as a signed bit
as follows -27 to +27.
floating point number is said to be normalized if most significant digit ofmantissa is one. for example,
6-bit binary number 001101 is normalizedbecause of two leading 0’s.
booth algorithm that uses two n bit numbers for multiplication gives resultsin 2n bits.
the booth algorithm uses 2’s complement representation of numbers andwork for both positive and
negative numbers.
if k-bits are used to represent exponent then bits number = (2k-1) and rangeof exponent = – (2k-1 -1) to
(2k-1).

Features Of Error Detection Codes


these are the following features of error detection codes:
these codes are used when we use message backward error correction techniques for reliable data
transmission. a feedback message is sent bythe receiver to inform the sender whether the message
is received without any error or not at the receiver side. if the message contains errors, the sender
retransmits the message.
in error detection codes, in fixed-size blocks of bits, the message iscontained. in this, the redundant
bits are added for correcting anddetecting errors.
these codes involve checking of the error. no matter how many errorbits are there and the type of
error. parity check, checksum, and crc are the error detection technique.

Computer Arithmetic
computer arithmetic is a field of computer science that investigates how computers should represent
numbers and perform operations on them. it includes integer arithmetic, fixed-point arithmetic, and
232
the arithmetic this book focuses on floating-point (fp) arithmetic, which will be more thoroughly
described in chapter 1. for now, let us say that it is the common way computers
approximate real numbers and that it is described in the ieee-754 standard [iee08]. as in scientific
notations, numbers are represented using an exponent and a significand, except that this significand
has to fit on a certain number of bits. asthis number of bits (called precision) is limited, each operation
may be inexact due to the rounding. this makes computer arithmetic sometimes inaccurate: theresult
of a long computation may be far from the mathematical result that wouldhave been obtained if all
the computations were correct. this also makes computer arithmetic unintuitive: for instance, the fp
addition is not always associative.

Register Transfer Language


a digital computer system exhibits an interconnection of digital modules such asregisters, decoders,
arithmetic elements, and control logic.
these digital modules are interconnected with some common data and control paths to form a
complete digital system.
moreover, digital modules are best defined by the registers and the operationsthat are performed on
the data stored in them.
the operations performed on the data stored in registers are called micro-operations.
the internal hardware organization of a digital system is best defined byspecifying:
the set of registers and the flow of data between them.
the sequence of micro-operations performed on the data which are storedin the registers.
the control paths that initiate the sequence of micro-operation the register transfer language is the
symbolic representation of notations usedto specify the sequence of micro-operations.
in a computer system, data transfer takes place between processor registers and memory and
between processor registers and input-output systems. these data transfer can be represented by
standard notations given below: notations r0, r1, r2..., and so on represent processor registers.
the addresses of memory locations are represented by names such as loc,place, mem, etc.
input-output registers are represented by names such as data in, dataout and so on.
the content of register or memory location is denoted by placing squarebrackets around the name of
the register or memory location.

Register Transfer
the term register transfer refers to the availability of hardware logic circuits thatcan perform a given
micro-operation and transfer the result of the operation to the same or another register.
most of the standard notations used for specifying operations on various registersare stated below.
the memory address register is designated by mar.
program counter pc holds the next instruction's address.
instruction register ir holds the instruction being executed.

r1 (processor register).
we can also indicate individual bits by placing them in parenthesis. forinstance, pc (8-15), r2 (5), etc.
data transfer from one register to another register is represented in symbolic form by means of
replacement operator. for instance, the following statement denotes a transfer of the data of register
r1 intoregister r2.
1. r2 ← r1 typically, most of the users want the transfer to occur only in a predetermined control
condition. this can be shown by following if-thenstatement:
if (p=1) then (r2 ← r1); here p is a control signal generated in the controlsection.
it is more convenient to specify a control function (p) by separating the control variables from the
233
register transfer operation. for instance, the following statement defines the data transfer operation
under a specificcontrol function (p).
1. p: r2 ← r1
the following image shows the block diagram that depicts the transfer of datafrom r1 to r2.

here, the letter 'n' indicates the number of bits for the register. the 'n' outputs ofthe register r1 are
connected to the 'n' inputs of register r2.
a load input is activated by the control variable 'p' which is transferred to theregister r2.

Bus And Memory Transfers


a digital system composed of many registers, and paths must be provided to transfer information
from one register to another. the number of wires connecting all of the registers will be excessive if
separate lines are used betweeneach register and all other registers in the system.
a bus structure, on the other hand, is more efficient for transferring informationbetween registers in a
multi-register configuration system.
a bus consists of a set of common lines, one for each bit of register, through which binary information
is transferred one at a time. control signals determinewhich register is selected by the bus during a
particular register transfer.
the following block diagram shows a bus system for four registers. it is constructed with the help of
four 4 * 1 multiplexers each having four data inputs(0 through 3) and two selection inputs (s1 and
s2).we have used labels to make it more convenient for you to understand the input- output
configuration of a bus system for four registers. for instance, output 1 of register a is connected to
input 0 of mux1.

234
the two selection lines s1 and s2 are connected to the selection inputs of all fourmultiplexers. the
selection lines choose the four bits of one register and transferthem into the four-line common bus.
when both of the select lines are at low logic, i.e. s1s0 = 00, the 0 data inputs ofall four multiplexers
are selected and applied to the outputs that forms the [Link], in turn, causes the bus lines to receive
the content of register a since the outputs of this register are connected to the 0 data inputs of the
multiplexers.
similarly, when s1s0 = 01, register b is selected, and the bus lines will receive thecontent provided by
register [Link] following function table shows the register that is selected by the bus foreach of the
four possible binary values of the selection lines.

note: the number of multiplexers needed to construct the bus is equal to the number of bits in each
235
register. the size of each multiplexer must be 'k * 1' sinceit multiplexes 'k' data lines. for instance, a
common bus for eight registers of 16 bits each requires 16 multiplexers, one for each line in the bus.
each multiplexermust have eight data input lines and three selection lines to multiplex one significant
bit in the eight registers.
a bus system can also be constructed using three-state gates instead ofmultiplexers.
the three state gates can be considered as a digital circuit that has three gates,two of which are
signals equivalent to logic 1 and 0 as in a conventional gate.
however, the third gate exhibits a high-impedance state.
the most commonly used three state gates in case of the bus system is a buffergate.
the graphical symbol of a three-state buffer gate can be represented as:

the following diagram demonstrates the construction of a bus system with three-state buffers.

the outputs generated by the four buffers are connected to form a singlebus line.
only one buffer can be in active state at a given point of time.
the control inputs to the buffers determine which of the four normal inputswill communicate with the
bus line. a 2 * 4 decoder ensures that no more than one control input is active atany given point of
time.

Memory Transfer
236
most of the standard notations used for specifying operations on memorytransfer are stated below.
the transfer of information from a memory unit to the user end is calleda read operation.
the transfer of new information to be stored in the memory is calleda write operation.
a memory word is designated by the letter m.
we must specify the address of memory word while writing the memorytransfer operations.
the address register is designated by ar and the data register by dr.
thus, a read operation can be stated as:

1. Read: DR ← M [AR]

the read statement causes a transfer of information into the data register(dr) from the memory word
(m) selected by the address register (ar).
and the corresponding write operation can be stated as:

1. Write: M [AR] ← R1

the write statement causes a transfer of information from register r1 into the memory word (m)
selected by address register (ar).

Micro-Operations
the operations executed on data stored in registers are called micro-operations.a micro-operation is
an elementary operation performed on the information stored in one or more registers.
example: shift, count, clear and load.

Types Of Micro-Operations
the micro-operations in digital computers are of 4 types:
register transfer micro-operations transfer binary information from oneregister to another.
arithmetic micro-operations perform arithmetic operations on numericdata stored in registers.
logic micro-operations perform bit manipulation operation on non-numericdata stored in registers.
shift micro-operations perform shift micro-operations performed on data.

Arithmetic Micro-Operations
in general, the arithmetic micro-operations deals with the operations performed on numeric data
stored in the registers.

The Basic Arithmetic Micro-Operations Are Classified In The Following Categories:


237
addition
subtraction
increment
decrement shift

Some Additional Arithmetic Micro-Operations Are Classified As:


add with carry
subtract with borrow
transfer/load, etc.
the following table shows the symbolic representation of various arithmeticmicro-operations.

symbolic representation description

r3 ← r1 + r2 the contents of r1 plus r2 are transferred to r3.

r3 ← r1 - r2 the contents of r1 minus r2 are transferred to r3.

r2 ← r2' complement the contents of r2 (1's complement)

r2 ← r2' + 1 2's complement the contents of r2 (negate)

r3 ← r1 + r2' + 1 r1 plus the 2's complement of r2 (subtraction)

r1 ← r1 + 1 increment the contents of r1 by one

decrement the contents of


r1 ← r1 - 1
r1 by one

Note: The increment and decrement micro-operations are symbolized by '+ 1' and
'? 1' respectively. Arithmetic operations like multiply and divide are not included
in the basic set of micro-operations.

Logic Micro-Operations
these are binary micro-operations performed on the bits stored in the registers. these operations
consider each bit separately and treat them as binary variables.
let us consider the x-or micro-operation with the contents of two registers r1and r2.
p: r1 ← r1 x-or r2
in the above statement we have also included a control function.
assume that each register has 3 bits. let the content of r1 be 010 and r2 be [Link] x-or micro-
operation will be:

238
Shift Micro-Operations
these are used for serial transfer of data. that means we can shift the contents ofthe register to the
left or right. in the shift left operation the serial input transfersa bit to the right most position and in
shift right operation the serial input transfers a bit to the left most position.

There Are Three Types Of Shifts As Follows:

Logical Shift
it transfers 0 through the serial input. the symbol "shl" is used for logical shift leftand "shr" is used for
logical shift right.
r1 ← she r1r1 ← she r1
the register symbol must be same on both sides of arrows.

Circular Shift
this circulates or rotates the bits of register around the two ends without any lossof data or contents.
in this, the serial output of the shift register is connected to its serial input. "cil" and "cir" is used for
circular shift left and right respectively.

Arithmetic Shift
this shifts a signed binary number to left or right. an arithmetic shift
left multiplies a signed binary number by 2 and shift left divides the number by 2. arithmetic shift
micro-operation leaves the sign bit unchanged because the signednumber remains same when it is
multiplied or divided by 2.

Arithmetic Logical Unit


instead of having individual registers performing the micro-operations, computersystem provides a
number of registers connected to a common unit called as arithmetic logical unit (alu). alu is the main
and one of the most important unit inisde cpu of computer. all the logical and mathematical
operations of computerare performed here. the contents of specific register is placed in the in the
input of alu. alu performs the given operation and then transfer it to the destination register.

239
registers
register is a very fast computer memory, used to store data/instruction in-execution.
a register is a group of flip-flops with each flip-flop capable of storing one bit ofinformation. an n-bit
register has a group of n flip-flops and is capable of storingbinary information of n-bits.
a register consists of a group of flip-flops and gates. the flip-flops hold the binaryinformation and
gates control when and how new information is transferred intoa register. various types of registers
are available commercially. the simplest register is one that consists of only flip-flops with no external
gates.
these days registers are also implemented as a register file.

Loading The Registers


the transfer of new information into a register is referred to as loading the register. if all the bits of
register are loaded simultaneously with a common clockpulse than the loading is said to be done in
parallel.

Instruction Codes
while a program, as we all know, is, a set of instructions that specify the operations, operands, and
the sequence by which processing has to occur.
an instruction code is a group of bits that tells the computer to perform a specificoperation part.

Instruction Code: Operation Code


the operation code of an instruction is a group of bits that define operations suchas add, subtract,
multiply, shift and compliment. the number of bits required for the operation code depends upon the
total number of operations available on thecomputer. the operation code must consist of at least n
bits for a
given 2^n operations. the operation part of an instruction code specifies the operation to be
performed.

Instruction Code: Register Part


the operation must be performed on the data stored in registers. an instruction code therefore
specifies not only operations to be performed but also the registers where the operands(data) will be
found as well as the registers where the result has to be stored.

Stored Program Organization


the simplest way to organize a computer is to have processor register and instruction code with two
parts. the first part specifies the operation to be performed and second specifies an address. the
240
memory address tells where theoperand in memory will be found.
instructions are stored in one section of memory and data in another.

computers with a single processor register is known as accumulator (ac). theoperation is performed
with the memory operand and the content of ac.

Common Bus System


the basic computer has 8 registers, a memory unit and a control unit. paths must be provided to
transfer data from one register to another. an efficient method fortransferring data in a system is to
use a common bus system. the output of registers and memory are connected to the common bus.

Load(Ld)
the lines from the common bus are connected to the inputs of each register and data inputs of
memory. the particular register whose ld input is enabled receivesthe data from the bus during the
next clock pulse transition. Before studying about instruction formats lets first study about the
operandaddress parts. when the 2nd part of an instruction code specifies the operand, the instruction
issaid to have immediate operand. and when the 2nd part of the instruction code
specifies the address of an operand, the instruction is said to have a direct address. and in indirect
address, the 2nd part of instruction code, specifies the address of a memory word in which the
address of the operand is found.

Computer Instructions
the basic computer has three instruction code formats. the operation code (opcode) part of the
instruction contains 3 bits and remaining 13 bitsdepends upon the operation code encountered.

There Are Three Types of Formats:


Memory Reference Instruction
it uses 12 bits to specify the address and 1 bit to specify the addressing mode(i). i is equal to 0 for
direct address and 1 for indirect address.

241
Register Reference Instruction
these instructions are recognized by the opcode 111 with a 0 in the left most bitof instruction. the
other 12 bits specify the operation to be executed.

Input-Output Instruction
these instructions are recognized by the operation code 111 with a 1 in the left most bit of instruction.
the remaining 12 bits are used to specify the input-outputoperation.

Format Of Instruction
the format of an instruction is depicted in a rectangular box symbolizing the bitsof an instruction.
basic fields of an instruction format are given below:
an operation code field that specifies the operation to be performed.
an address field that designates the memory address or register.
a mode field that specifies the way the operand of effective address isdetermined.
computers may have instructions of different lengths containing varying number of addresses. the
number of address field in the instruction format depends upon the internal organization of its
registers.

Addressing Modes And Instruction Cycle


the operation field of an instruction specifies the operation to be performed. thisoperation will be
executed on some data which is stored in computer registers or the main memory. the way any
operand is selected during the program execution is dependent on the addressing mode of the
instruction. the purpose of using addressing modes is as follows:
to give the programming versatility to the user.
to reduce the number of bits in addressing field of instruction.

Types Of Addressing Modes


below we have discussed different types of addressing modes one by one:

Immediate Mode
in this mode, the operand is specified in the instruction itself. an immediate modeinstruction has an
operand field rather than the address field.
for example: add 7, which says add 7 to contents of accumulator. 7 is theoperand here.

Register Mode

242
in this mode the operand is stored in the register and this register is present in cpu. the instruction
has the address of the register where the operand is stored.

Advantages
shorter instructions and faster instructions fetch.
faster memory access to the operand(s)

Disadvantages
very limited address space using multiple registers helps performance but it complicates the
instructions.

Register Indirect Mode


in this mode, the instruction specifies the register whose contents give us the address of operand
which is in memory. thus, the register contains the address ofoperand rather than the operand itself.

Auto Increment/Decrement Mode

243
in this the register is incremented or decremented after or before its value isused.

Direct Addressing Mode


in this mode, effective address of operand is present in instruction itself.
single memory reference to access data.
no additional calculations to find the effective address of the operand.

For Example: ADD R1, 4000 - In this the 4000 is effective address of operand.

NOTE: Effective Address is the location where operand is present.

Indirect Addressing Mode


in this, the address field of instruction gives the address where the effectiveaddress is stored in
memory. this slows down the execution, as this includesmultiple memory lookups to find the operand.

244
Displacement Addressing Mode
in this the contents of the indexed register is added to the address part of theinstruction, to obtain the
effective address of operand.
ea = a + (r), in this the address field holds two values, a(which is the base value)and r(that holds the
displacement), or vice versa.

Relative Addressing Mode


it is a version of displacement addressing mode.
in this the contents of pc (program counter) is added to address part ofinstruction to obtain the
effective address.
ea = a + (pc), where ea is effective address and pc is program counter. the operand is a cell away
from the current cell (the one pointed to by pc)base register addressing mode
it is again a version of displacement addressing mode. this can be defined as ea =a + (r), where a is
displacement and r holds pointer to base address.
Stack Addressing Mode
in this mode, operand is at the top of the stack. for example: add, this instructionwill pop top two items
from the stack, add them, and will then push the result tothe top of the stack.

Instruction Cycle
instruction cycle, also known as fetch-decode-execute cycle is the basic operational process of a
computer. this process is repeated continuously by cpufrom boot up to shut down of computer.

Following Are The Steps That Occur During An Instruction Cycle:


Fetch The Instruction
the instruction is fetched from memory address that is stored in pc(program counter) and stored in
the instruction register ir. at the end of the fetch operation, pc is incremented by 1 and it then points
to the next instruction to beexecuted.

decode the instruction


the instruction in the ir is executed by the decoder.

245
Read The Effective Address
if the instruction has an indirect address, the effective address is read from thememory. otherwise
operands are directly read in case of immediate operand instruction.

Execute The Instruction


the control unit passes the information in the form of control signals to the functional unit of cpu. the
result generated is stored in main memory or sent toan output device.
the cycle is then repeated by fetching the next instruction. thus in this way theinstruction cycle is
repeated continuously.

memory-reference instructions
the basic computer has 16-bit instruction register (ir) which can denote eithermemory reference or
register reference or input-output instruction.

Memory Reference – these instructions refer to memory address as an operand. the other operand
is always accumulator. specifies 12-bit address, 3-bit opcode (other than 111) and 1-bit addressing
mode for directand indirect addressing.

example –
ir register contains = 0001xxxxxxxxxxxx, i.e. add after fetching and decoding ofinstruction we find out
246
that it is a memory reference instruction for add operation.
hence, dr ← m[ar] ac ← ac + dr, sc ← 0

Input-Output Instructions
input/output – these instructions are for communication between computer andoutside environment.
the ir(14 – 12) is 111 (differentiates it from memory reference) and ir(15) is 1 (differentiates it from
register reference instructions).
the rest 12 bits specify i/o operation.

Example –
ir register contains = 1111100000000000, i.e. inp after fetch and decode cycle wefind out that it is an
input/output instruction for inputing character. hence, inputcharacter from peripheral device.
the set of instructions incorporated in16 bit ir register are:
arithmetic, logical and shift instructions (and, add, complement, circulateleft, right, etc)
to move information to and from memory (store the accumulator, load theaccumulator)
program control instructions with status conditions (branch, skip)
input output instructions (input character, output character)

Machine Language
machine language, or machine code, is a low-level language comprised
of binary digits (ones and zeros). high-level languages, such as swift and c++ mustbe compiled into
machine language before the code is run on a computer.
since computers are digital devices, they only recognize binary data. everyprogram, video, image, and
character of text is represented in binary. thisbinary data, or machine code, is processed as input by
the cpu. The resulting output is sent to the operating system or an application, which displays the
data visually. for example, the ascii value for the letter "a" is 01000001 in machine code, but this data
is displayed as "a" on the screen. an image may have thousands or even millions of binary values that
determine the color of each pixel.
while machine code is comprised of 1s and 0s, different processor architectures use different
machine code. for example, a powerpc processor, which has a risc architecture, requires different
code than an intel x86 processor,which has a cisc architecture. a compiler must compile high-level
source cod for the correct processor architecture in order for a program to run correctly.
the exact machine language for a program or action can differ by operating system. the specific
operating system dictates how a compiler writes a programor action into machine language.
computer programs are written in one or more programming languages,like c++, java, or visual basic.
a computer cannot directly understand the programming languages used to create computer
programs, so the program codemust be compiled. once a program's code is compiled, the computer
can understand it because the program's code is turned into machine language.

Machine Language Example


below is an example of machine language (binary) for the text "hello world."

247
01001000 01100101 01101100 01101100 01101111 00100000 01010111
01101111 01110010 01101100 01100100

below is another example of machine language (non-binary), which prints theletter "a" 1000 times to
the computer screen.

169 1 160 0 153 0 128 153 0 129 153 130 153 0 131 200 208 241 96

Assembly Language
sometimes referred to as assembly or asm, an assembly language is a low- level programming
language.
programs written in assembly languages are compiled by an assembler. everyassembler has its own
assembly language, which is designed for one specific computer architecture.

Why Is Asm Useful?


machine language is a series of numbers, which is not easy for humans to read. using asm,
programmers can write human-readable programs that correspond almost exactly to machine
[Link] disadvantage is that everything the computer does must be described explicitly, in
precise detail. the advantage is that the programmer has maximumcontrol over what the computer is
doing.

Why Is Asm A "Low-Level" Language?


assembly is called a low-level programming language because there's (nearly) a one-to-one
relationship between what it tells the computer to do, and what the computer does. in general, one
line of an assembly program contains a maximumof one instruction for the computer.

How Is Asm Different From A "High-Level" Language?


high-level languages provide abstractions of low-level operations which allow the programmer to
focus more on describing what they want to do, and less on how it should be done. programming this
way is more convenient and makes programseasier to read at the sacrifice of low-level control.
programs written in high-level languages never match the raw speed and efficiency of programs
written in assembly. examples of high-level languagesinclude python, java, javascript, clojure, and lisp.

What Is A "Mid-Level" Language?


mid-level languages or lower-level languages provide some high-level abstractions to make the
programmer's life easier, while still providing access to low-level operations. they are often used to
write operating systems, so they aresometimes called system programming languages.
programs written in mid-level languages can perform as well, or nearly as well, asprograms written in
assembly language. examples of mid-level programming languages include c, c++, ada, nim, and rust.

Is Asm Portable?
no. because assembly languages are tied to one specific computer architecture, they are not portable.
a program written in one assembly language would need tobe completely rewritten for it to run on
another type of machine.
portability is one of the main advantages of higher-level languages. the c programming language is

248
often called "portable assembly" because c compilers exist for nearly every modern system
architecture. a program written in c may require some changes before it will compile on another
computer, but the corelanguage is portable.
generally speaking, the higher-level a language is, the fewer changes need to be made for it to run on
another architecture. the lowest-level languages — machinelanguage and assembly language — are
not portable.

Machine Language Vs Assembly Language


machine language and assembly language are both low-level languages, butmachine code is below
assembly in the hierarchy of computer languages.
assembly language includes human-readable commands, such as mov, add, and sub, while machine
language does not contain any words or even letters. some developers manually write assembly
language to optimize a program, but they do not write machine code. only developers who write
software compilersneed to worry about machine language.
note: while machine code is technically comprised of binary data, it may also be represented in
hexadecimal values. for example, the letter "z," which
is 01011010 in binary, may be displayed as 5a in hexadecimal code.

Assembler
program used to convert or translate programs written in assembly code tomachine code. some users
may also refer to assembly language or assembler language as assembler.
an assembler is a program that converts assembly language into machine code. ittakes the basic
commands and operations from assembly code and converts them into binary code that can be
recognized by a specific type of processor.
assemblers are similar to compilers in that they produce executable code. however, assemblers are
more simplistic since they only convert low-level code (assembly language) to machine code. since
each assembly language is designedfor a specific processor, assembling a program is performed
using a simple one- to-one mapping from assembly code to machine code. compilers, on the other
hand, must convert generic high-level source code into machine code for a specific processor.
most programs are written in high-level programming languages and are compiled directly to
machine code using a compiler. however, in some cases, assembly code may be used to customize
functions and ensure they perform in a specific way. therefore, ides often include assemblers so they
can build programsfrom both high and low-level languages.

How It Works:
most computers come with a specified set of very basic instructions that correspond to the basic
machine operations that the computer can perform. for example, a "load" instruction causes the
processor to move astring of bits from a location in the processor's memory to a special holdingplace
called a register. assuming the processor has at least eight registers, each numbered, the following
instruction would move the value (string of bits of a certain length) at memory location 3000 into the
holding place called register 8:

L 8,3000

the programmer can write a program using a sequence of these assemblerinstructions.


this sequence of assembler instructions, known as the source code or source program, is then
specified to the assembler program when thatprogram is started.

249
the assembler program takes each program statement in the source program and generates a
corresponding bit stream or pattern (a series of0's and 1's of a given length).
the output of the assembler program is called the object code or object program relative to the input
source program. the sequence of 0's and 1'sthat constitute the object program is sometimes called
machine code.
the object program can then be run (or executed) whenever desired.
in the earliest computers, programmers actually wrote programs in machine code, but assembler
languages or instruction sets were soon developed to speed up programming. today, assembler
programming is used only where very efficient control over processor operations is needed. it
requires knowledge of a particular computer's instruction set, however. historically, most programs
have been written in "higher-level" languages such as Cobol, Fortran, pl/i, and c. these languages are
easier to learn and faster to write programs with than assembler language. the program that
processes the source code written in these languages is called a compiler. like the assembler, a
compiler takes higher-level language statements and reduces them to machine code.

Program Loops
loops are among the most basic and powerful of programming concepts. a loop in a computer
program is an instruction that repeats until a specified condition isreached. in a loop structure, the
loop asks a question. if the answer requires action, it is executed. the same question is asked again
and again until no furtheraction is required. each time the question is asked is called an iteration.
a computer programmer who needs to use the same lines of code many times ina program can use
a loop to save time.
just about every programming language includes the concept of a loop. high-level programs
accommodate several types of loops. c, c++, and c# are all high-level computer programs and have
the capacity to use several types of loops.

Types Of Loops
as for loop is a loop that runs for a preset number of times.
a while loop is a loop that is repeated as long as an expression is true. anexpression is a statement
that has a value.
ado while loop or repeat until loop repeats until an expression becomesfalse.
an infinite or endless loop is a loop that repeats indefinitely because it hasno terminating condition,
the exit condition is never met, or the loop is instructed to start over from the beginning. although it
is possible for a programmer to intentionally use an infinite loop, they are often mistakesmade by new
programmers.
a nested loop appears inside any other for, while or do while loop.
a goto statement can create a loop by jumping backward to a label, although this is generally
discouraged as a bad programming practice. for some complex code,it allows a jump to a common
exit point that simplifies the code.

Loop Control Statements


a statement that alters the execution of a loop from its designated sequence is a loop control
statement. c#, for example, provides two loop control statements.
a break statement inside a loop terminates the loop immediately.
a continue statement jumps to the next iteration of the loop, skipping anycode in between.

Basic Structures Of Computer Programming


loop, selection, and sequence are the three basic structures of computer programming. these three
250
logic structures are used in combination to formalgorithms for solving any logic problem. this process
is called structured programming.

Subroutine
a set of instructions which are used repeatedly in a program can be referred to assubroutine. only
one copy of this instruction is stored in the memory. when a subroutine is required it can be called
many times during the execution of a particular program. a call subroutine instruction calls the
subroutine. care shouldbe taken while returning a subroutine as subroutine can be called from a
different place from the memory.
the content of the pc must be saved by the call subroutine instruction to make acorrect return to the
calling program.

figure – process of subroutine in a program subroutine linkage method is a way in which computer
call and return the subroutine. the simplest way of subroutine linkage is saving the return address in
a specific location, such as register which can be called as link register call subroutine.

Subroutine Nesting –
subroutine nesting is a common programming practice in which one subroutine call another
subroutine.

Figure – subroutine calling another subroutine from the above figure, assume that when subroutine
1 calls subroutine 2 the return address of subroutine 2 should be saved somewhere. so if link register
stores return address of subroutine 1 this will be (destroyed/overwritten) by return address of
subroutine 2. as the last subroutine called is the first one to be returned ( last in first out format). so
stack data structure is the most efficientway to store the return addresses of the subroutines.

251
Figure – return address of subroutine is stored in stack memory

Stack Memory –
stack is a basic data structure which can be implemented anywhere in the memory. it can be used to
store variables which may be required afterwards in the program execution. in a stack, the first data
put will be last to get out of a stack. so the last data added will be the first one to come out of the
stack (last infirst out).

252
Figure – stack memory having data a, b & c
so from the diagram above first a is added then b & c. while removing first c isremoved then b & a.

Design Of Control Unit the Control Unit Is Classified Into Two Major Categories:
hardwired control microprogrammed control

Hardwired Control Unit:


when the control signals are generated by hardware using conventional logicdesign techniques, the
control unit is said to be hardwired.
the hardwired control organization involves the control logic to be implementedwith gates, flip-flops,
decoders, and other digital circuits.

The Following Image Shows The Block Diagram Of A Hardwired ControlOrganization.

a hard-wired control consists of two decoders, a sequence counter, anda number of logic gates.
an instruction fetched from the memory unit is placed in the instructionregister (ir).
the component of an instruction register includes; i bit, the operationcode, and bits 0 through 11.
253
the operation code in bits 12 through 14 are coded with a 3 x 8 decoder.
the outputs of the decoder are designated by the symbols d0 throughd7.
the operation code at bit 15 is transferred to a flip-flop designated bythe symbol i.
the operation codes from bits 0 through 11 are applied to the controllogic gates.
the sequence counter (sc) can count in binary from 0 through 15.

Micro-Programmed Control
the microprogrammed control organization is implemented by using theprogramming approach.
in microprogrammed control, the micro-operations are performed by executing aprogram consisting
of micro-instructions.
the following image shows the block diagram of a microprogrammed controlorganization.

the control memory address register specifies the address of the micro-instruction.
the control memory is assumed to be a room, within which all controlinformation is permanently
stored. the control register holds the microinstruction fetched from thememory.
the micro-instruction contains a control word that specifies one or moremicro-operations for the data
processor. While the micro-operations are being executed, the next address is computed in the next
address generator circuit and then transferred into the control address register to read the next
microinstruction.
the next address generator is often referred to as a micro-programsequencer, as it determines the
address sequence that is read fromcontrol memory.

Difference Between Hardwired Control And Microprogrammed Control

hardwired control microprogrammed control

technology is circuit based. technology is software based.

it is implemented through flip-flops, gates, microinstructions generate signals to controlthe


decoders etc. execution of instructions.

254
fixed instruction format. variable instruction format (16-64 bits perinstruction).

instructions are register based. instructions are not register based.

rom is not used. rom is used.

it is used in risc. it is used in cisc.

faster decoding. slower decoding.

difficult to modify. easily modified.

chip area is less. chip area is large.

Dynamic Microprogramming:
a more advanced development known as dynamic microprogramming permits a microprogram to be
loaded initially from an auxiliary memory such as a magnetic disk. control units that use dynamic
microprogramming employ a writable controlmemory. this type of memory can be used for writing.

Control Memory:
control memory is the storage in the microprogrammed control unit to store themicroprogram.

Writeable Control Memory:


control storage whose contents can be modified, allow the change in microprogram and instruction
set can be changed or modified is referred aswriteable control memory.

Control Word:
the control variables at any given time can be represented by a control wordstring of 1 's and 0's called
a control word.

Microoperation, Microinstruction, Micro Program, [Link]:


in computer central processing units, micro-operations (also known as a micro- ops or μops) are
detailed low-level instructions used in some designs to implement complex machine instructions
(sometimes termed macro-instructionsin this context).

Micro Instruction:
a symbolic microprogram can be translated into its binary equivalent bymeans of an assembler.
each line of the assembly language microprogram defines a symbolicmicroinstruction.
each symbolic microinstruction is divided into five fields: label,microoperations, cd, br, and ad.

Micro Program:
a sequence of microinstructions constitutes a microprogram.
since alterations of the microprogram are not needed once the control unit is in operation, the control
255
memory can be aread-only memory (rom).
rom words are made permanent during the hardwareproduction of the unit.
the use of a micro program involves placing all control variables in words of rom for use by the control
unit throughsuccessive read operations.
the content of the word in rom at a given address specifies amicroinstruction.

Microcode:
microinstructions can be saved by employing subroutines thatuse common sections of microcode.
for example, the sequence of micro operations needed to generate the effective address of the
operand for an instruction is common to all memory reference instructions.
this sequence could be a subroutine that is called from withinmany other routines to execute the
effective address computation.

Organization Of Micro Programmed Control Unit


the general configuration of a micro-programmed control unit isdemonstrated in the block diagram
of figure 4.1the control memory is assumed to be a rom, within which all control information is
permanently stored.

Figure: Micro-Programmed Control Organization


the control memory address register specifies the address of the microinstruction, and the control
data register holds the microinstructionread from memory.
the microinstruction contains a control word that specifies one or moremicrooperations for the data
processor. once these operations are executed, the control must determine the next address.
the location of the next microinstruction may be the one next in sequence, or it may be located
somewhere else in the control memory.
while the microoperations are being executed, the next address is computed in the next address
generator circuit and then transferred into the control address register to read the next
microinstruction.
thus a microinstruction contains bits for initiating microoperations in thedata processor part and bits
that determine the address sequence for thecontrol memory.
the next address generator is sometimes called a micro-program sequencer, as it determines the
address sequence that is read from controlmemory.
typical functions of a micro-program sequencer are incrementing the control address register by one,
loading into the control address register anaddress from control memory, transferring an external
address, or loading an initial address to start the control operations.
the control data register holds the present microinstruction while the nextaddress is computed and
256
read from memory.
the data register is sometimes called a pipeline register.
it allows the execution of the microoperations specified by the controlword simultaneously with the
generation of the next microinstruction.
this configuration requires a two-phase clock, with one clock applied to theaddress register and the
other to the data register.
the main advantage of the micro programmed control is the fact that oncethe hardware configuration
is established; there should be no need for further hardware or wiring changes.
if we want to establish a different control sequence for the system, all weneed to do is specify a
different set of microinstructions for control memory.

Address Sequencing
microinstructions are stored in control memory in groups, with each groupspecifying a

Routine.
to appreciate the address sequencing in a micro-program control unit, specify the steps that the
control must undergo during the execution of a single computer instruction.

step 1:
an initial address is loaded into the control address register when power isturned on in the computer.
this address is usually the address of the first microinstruction thatactivates the instruction fetch
routine.
the fetch routine may be sequenced by incrementing the control addressregister through the rest of
its microinstructions.
at the end of the fetch routine, the instruction is in the instruction registerof the computer.

step 2:
the control memory next must go through the routine that determines theeffective address of the
operand.
a machine instruction may have bits that specify various addressing modes,such as indirect address
and index registers.
the effective address computation routine in control memory can be reached through a branch
microinstruction, which is conditioned on thestatus of the mode bits of the instruction.
when the effective address computation routine is completed, the addressof the operand is available
in the memory address register.

step 3:
the next step is to generate the microoperations that execute theinstruction fetched from memory.
the microoperation steps to be generated in processor registers depend onthe operation code part of
the instruction.
each instruction has its own micro-program routine stored in a givenlocation of control memory.
the transformation from the instruction code bits to an address in controlmemory where the routine
is located is referred to as a mapping process.
a mapping procedure is a rule that transforms the instruction code into acontrol memory address.

step 4:
once the required routine is reached, the microinstructions that execute the instruction may be
sequenced by incrementing the control address register.
257
micro-programs that employ subroutines will require an external register for storing the return
address.
return addresses cannot be stored in rom because the unithas no writing capability.
when the execution of the instruction is completed, controlmust return to the fetch routine.
this is accomplished by executing an unconditional branchmicroinstruction to the first address of the
fetch routine.

in summary, the address sequencing capabilities required in a control memoryare:


incrementing of the control address register.
unconditional branch or conditional branch, depending on statusbit conditions.
a mapping process from the bits of the instruction to an addressfor control memory.
a facility for subroutine call and return.

Selection Of Address For Control Memory

Figure 4.2: Selection Of Address For Control Memory


above figure 4.2 shows a block diagram of a control memory and theassociated hardware needed for
selecting the next microinstruction address.
the microinstruction in control memory contains a set of bits to initiatemicrooperations in computer
registers and other bits to specify the method by which the next address is obtained.
the diagram shows four different paths from which the control addressregister (car) receives the
address. the incremented increments the content of the control address register byone, to select the
next microinstruction in sequence.
branching is achieved by specifying the branch address in one of the fieldsof the microinstruction.
conditional branching is obtained by using part of the microinstruction toselect a specific status bit
in order to determine its condition.
258
an external address is transferred into control memory via a mapping logiccircuit.
the return address for a subroutine is stored in a special register whosevalue is then used when the
micro-program wishes to return from the subroutine.

Central Processing Unit (Cpu)


the central processing unit (cpu) or processor, is the unit which performs most ofthe processing
inside a computer. it processes all instructions received by software running on the pc and by other
hardware components, and acts as a powerful calculator.
the cpu is placed into a specific square-shaped socket found on all motherboardsby inserting its
metallic connectors or pins found on the underside. each socket isbuilt with a specific pin layout to
support only a specific type of processor.
since modern cpus produce a lot of heat and are prone to overheating, they mustbe kept cool with
appropriate fans or ventilation systems and covered with heat sinks and thermal paste.
to control instructions and data flow to and from other parts of the computer, the cpu relies heavily
on a chipset, which is a group of microchips located on themotherboard.
this term is also known as a central processor, microprocessor or chip

The Central Processing Unit (Cpu) Has Three Components:

Control Unit
the control unit extracts instructions from memory and decodes and executesthem.
the control unit acts as an intermediary that decodes the instructions sent to theprocessor, tells the
other units such as the arithmetic logic unit (below) what to do by providing control signals, and then
sends back the processed data back to memory.

Arithmetic Logic Unit (Alu)


an arithmetic logic unit (alu) is a digital circuit inside the processor that handlesarithmetic and logical
operations by loading data from input registers.
after the control unit provides the alu with the instruction on the operations thatmust be performed,
the alu completes them by connecting multiple transistors, and then stores the results in an output
register.
the control unit will then move this data to memory.

259
to function properly, the cpu relies on the system clock, memory, secondarystorage, and data and
address buses.
smaller devices like mobile phones, calculators, held gaming systems, and tabletsuse smaller-sized
processors known as arm cpus to accommodate their reducedsize and space.
the cpu is the heart and brain of a computer. it receives data input, executes instructions, and
processes information. it communicates with input/output (i/o)devices, which send and receive data
to and from the cpu.
additionally, the microprocessor has an internal bus for communication with the internal cache
memory, called the backside bus. the main bus for data transfer toand from the cpu, memory, chipset,
and agp socket is called the front-side bus.
the cpu contains internal memory units, which are called registers. these registers contain data,
instructions, counters and addresses used in the alu'sinformation processing.
some computers utilize two or more processors. these consist of separate physical microprocessors
located side by side on the same board or on separateboards. each cpu has an independent interface,
separate cache, and individual paths to the system front-side bus.
multiple processors are ideal for intensive parallel tasks requiring multitasking. multicore cpus are
also common, in which a single chip contains multiple cpus.
since the first microprocessor was released by intel in november 1971, cpus haveincreased their
computing power severalfold.
the oldest intel 4004 processor only performed 60,000 operations per second,while a modern intel
pentium processor can perform about 188,000,000 instructions per second.

Memory Or Storage Unit/ Registers


it is called random access memory (ram). it temporarily stores data, programs, and intermediate and
final results of processing. so, it acts as a temporary storagearea that holds the data temporarily,
which is used to run the computer.

CPU clock speed


the clock speed of a cpu or a processor refers to the number of instructions it canprocess in a second.
it is measured in gigahertz. for example, a cpu with a clock speed of 4.0 ghz means it can process 4
billion instructions in a second.

Types Of CPU:
CPUs are mostly manufactured by intel and amd, each of which manufactures itsown types of cpus.
in modern times, there are lots of cpu types in the market.
some of the basic types of cpus are described below:

single core cpu: single core is the oldest type of computer cpu, which was used in the 1970s. it has
only one core to process different operations. it can start only one operation at a time; the cpu
switches back and forth between different sets of data streams when more than one program runs.
so, it is not suitable for multitasking as the performance will be reduced if more than one application
runs. the performance of these cpus is mainly dependent on the clock speed. it isstill used in various
devices, such as smartphones.

dual core CPU: as the name suggests, dual core cpu contains two cores in a single integrated circuit
(ic). although each core has its own controller and cache,they are linked together to work as a single
unit and thus can perform faster thanthe single-core processors and can handle multitasking more
efficiently than single core processors.
260
quad core CPU: this type of cpu comes with two dual-core processors in one integrated circuit (ic) or
chip. so, a quad-core processor is a chip that contains four independent units called cores. these
cores read and execute instructions ofcpu. the cores can run multiple instructions simultaneously,
thereby increases the overall speed for programs that are compatible with parallel processing.
quad core cpu uses a technology that allows four independent processing units (cores) to run in
parallel on a single chip. thus by integrating multiple cores in a single cpu, higher performance can be
generated without boosting the clock speed. however, the performance increases only when the
computer's softwaresupports multiprocessing. the software which supports multiprocessing divides
the processing load between multiple processors instead of using one processorat a time.

History Of CPU:

Some Of The Important Events In The Development Of Cpu Since Its Invention Till Date Are As
Follows:
in 1823, baron jons jackob berzelius discovered silicon that is the maincomponent of cpu till date.
in 1903, nikola tesla got gates or switches patented, which are electricallogic circuits.
in december 1947, john bardeen, william shockley, and walter brattaininvented the first transistor at
the bell laboratories and got it patented in 1948.
in 1958, the first working integrated circuit was developed by robertnoyce and jack kilby.
in 1960, ibm established the first mass-production facility for transistorsin new york.
in 1968, robert noyce and gordon moore founded intel corporation.
amd (advanced micro devices) was founded in may 1969.
in 1971, intel introduced the first microprocessor, the intel 4004, withthe help of ted hoff.
in 1972, intel introduced the 8008 processor; in 1976, intel 8086 wasintroduced, and in june 1979, intel
8088 was released.
in 1979, a 16/32-bit processor, the motorola 68000, was released. later,it was used as a processor for
the apple macintosh and amiga computers.
in 1987, sun introduced the sparc processor.
in march 1991, amd introduced the am386 microprocessor family.
in march 1993, intel released the pentium processor. in 1995, cyrix introduced the cx5x86 processor
to give competition to intel pentiumprocessors.
in january 1999, intel introduced the celeron 366 mhz and 400 mhzprocessors.
in april 2005, amd introduced its first dual-core processor.
in 2006, intel introduced the core 2 duo processor.
in 2007, intel introduced different types of core 2 quad processors.
in april 2008, intel introduced the first series of intel atom processors,the z5xx series. they were
single-core processors with a 200 mhz gpu.
in september 2009, intel released the first core i5 desktop processorwith four cores.
in january 2010, intel released many processors such as core 2 quad processor q9500, first core i3
and i5 mobile processors, first core i3 andi5 desktop processors. in the same year in july, it released
the first core i7 desktop processor with six cores.
in june 2017, intel introduced the first core i9 desktop processor.
in april 2018, intel released the first core i9 mobile processor.

General Register-Based CPU Organization


when we are using multiple general-purpose registers, instead of single accumulator register, in the
CPU organization then this type of organization is known as general register based cpu organization.
261
in this type of organization, computer uses two or three address fields in their instruction format.
each address field may specify a general register or a memory [Link] many cpu registers are
available for heavily used variables and intermediate results, we canavoid memory references much
of the time, thus vastly increasing program execution speed, and reducing program size.

For Example:
mult r1, r2, r3
this is an instruction of an arithmatic multiplication written in assembly language. it uses three
address fields r1, r2 and r3. the meaning of this instruction is:
r1 <-- r2 * r3 this instruction also can be written using only two address fields as:
mult r1, r2 in this instruction, the destination register is the same as one of the sourceregisters. this
means the operation
r1 <-- r1 * r2 the use of large number of registers results in short program with limitedinstructions.
some examples of general register based cpu organization are ibm 360 andpdp- 11.

The Advantages Of General Register Based Cpu Organization –


efficiency of cpu increases as there are large number of registers areused in this organization.
less memory space is used to store the program since the instructionsare written in compact way.

The Disadvantages Of General Register Based Cpu Organization –


care should be taken to avoid unnecessary usage of registers. thus, compilers need to be more
intelligent in this aspect.
since large number of registers are used, thus extra cost is required inthis organization.

General Register CPU Organization Of Two Type:


register-memory reference architecture (cpu with less register)– in this organisation source 1 is
always required in register, source 2 can be
present either in register or in [Link] two address instruction format is the compatible
instruction format.
register-register reference architecture (cpu with more register)– in thisorganisation alu operations
are performed only on a register data. so operands are required in the register. after manipulation
result is also placed in [Link] three address instruction format is the compatible instruction
format.

Stack Based CPU Organization


the computers which use stack-based cpu organization are based on a data structure called stack.
the stack is a list of data words. it uses last in first out (lifo) access method which is the most popular
access method in most of the cpu. a register is used to store the address of the topmost element of
the stack which is known as stack pointer (sp). in this organisation, alu operations are performed on
stack data. it means both the operands are always required on thestack. after manipulation, the result
is placed in the stack.
the main two operations that are performed on the operators of the stack are push and pop. these
two operations are performed from one end only.
push –

PUSH
this operation results in inserting one operand at the top of the stack and itdecrease the stack pointer

262
register. the format of the push instruction is:
it inserts the data word at specified address to the top of the stack. it can beimplemented as:

//decrement SP by 1

SP <-- SP - 1

//store the content of specified memory address

//into SP; i.e, at top of stack

SP <-- (memory address)

pop –
this operation results in deleting one operand from the top of the stack and it increase the stack
pointer register. the format of the pop instructionis:

POP

it deletes the data word at the top of the stack to the specified address. it can beimplemented as:

//transfer the content of SP (i.e, at top most data)

//into specified memory location

(memory address) <-- SP

//increment SP by 1

SP <-- SP + 1

operation type instruction does not need the address field in this cpu organization. this is because
the operation is performed on the two operandsthat are on the top of the stack. for example:

SUB

this instruction contains the opcode only with no address field. it pops the twotop data from the stack,
subtracting the data, and pushing the result into the stack at the top.

pdp-11, intel’s 8085 and hp 3000 are some of the examples of the stackorganized computers.

The Advantages Of Stack Based Cpu Organization –


Efficient Computation Of Complex Arithmetic Expressions.

263
execution of instructions is fast because operand data are stored inconsecutive memory locations.
length of instruction is short as they do not have address field.

The Disadvantages Of Stack Based Cpu Organization –

Note:Stack based CPU organisation uses zero address instruction.


the size of the program increases.

Computer Instructions
the basic computer has three instruction code formats. the operation code (opcode) part of the
instruction contains 3 bits and remaining 13 bitsdepends upon the operation code encountered.

There Are Three Types Of Formats:

Memory Reference Instruction


it uses 12 bits to specify the address and 1 bit to specify the addressing mode(i). i is equal to 0 for
direct address and 1 for indirect address.

Register Reference Instruction


these instructions are recognized by the opcode 111 with a 0 in the left most bitof instruction. the
other 12 bits specify the operation to be executed.

Input-Output Instruction
these instructions are recognized by the operation code 111 with a 1 in the left most bit of instruction.
the remaining 12 bits are used to specify the input-outputoperation.

Format Of Instruction
the format of an instruction is depicted in a rectangular box symbolizing the bitsof an instruction.
basic fields of an instruction format are given below:
an operation code field that specifies the operation to be performed.
an address field that designates the memory address or register.
a mode field that specifies the way the operand of effective address isdetermined.
computers may have instructions of different lengths containing varying number of addresses. the
number of address field in the instruction format depends upon the internal organization of its
registers.

Addressing Modes
the operation field of an instruction specifies the operation to be performed. thisoperation will be
executed on some data which is stored in computer registers or the main memory. the way any
operand is selected during the program execution is dependent on the addressing mode of the
instruction. the purpose of using addressing modes is as follows:
to give the programming versatility to the user.
to reduce the number of bits in addressing field of instruction.

Types Of Addressing Modes


below we have discussed different types of addressing modes one by one:

264
Immediate Mode
in this mode, the operand is specified in the instruction itself. an immediate modeinstruction has an
operand field rather than the address field.
for example: add 7, which says add 7 to contents of accumulator. 7 is theoperand here.
Register Mode
in this mode the operand is stored in the register and this register is present in cpu. the instruction
has the address of the register where the operand is stored.

Advantages
shorter instructions and faster instruction fetch.
faster memory access to the operand(s)

Disadvantages
very limited address space
using multiple registers helps performance but it complicates theinstructions.

Register Indirect Mode


in this mode, the instruction specifies the register whose contents give us the address of operand
which is in memory. thus, the register contains the address ofoperand rather than the operand itself.

265
Auto Increment/Decrement Mode
in this the register is incremented or decremented after or before its value isused.

Direct Addressing Mode


in this mode, effective address of operand is present in instruction itself.
single memory reference to access data.
no additional calculations to find the effective address of the operand.

For Example: ADD R1, 4000 - In this the 4000 is effective address of operand.

NOTE: Effective Address is the location where operand is present.

266
Indirect Addressing Mode
in this, the address field of instruction gives the address where the effectiveaddress is stored in
memory. this slows down the execution, as this includesmultiple memory lookups to find the operand.

Displacement Addressing Mode


in this the contents of the indexed register is added to the address part of theinstruction, to obtain the
effective address of operand.
ea = a + (r), in this the address field holds two values, a(which is the base value)and r(that holds the
displacement), or vice versa.

Relative Addressing Mode


it is a version of displacement addressing mode.
in this the contents of pc(program counter) is added to address part of instruction to obtain the
effective [Link] = a + (pc), where ea is effective address and pc is program counter. the operand
267
is a cells away from the current cell(the one pointed to by pc)

Base Register Addressing Mode


it is again a version of displacement addressing mode. this can be defined as ea =a + (r), where a is
displacement and r holds pointer to base address.

Stack Addressing Mode


in this mode, operand is at the top of the stack. for example: add, this instructionwill pop top two items
from the stack, add them, and will then push the result tothe top of the stack.

Risc Processor
it is known as reduced instruction set computer. it is a type of microprocessor that has a limited
number of instructions. they can execute their instructions veryfast because instructions are very
small and simple.
risc chips require fewer transistors which make them cheaper to design and produce. in risc, the
instruction set contains simple and basic instructions from which more complex instruction can be
produced. most instructions complete in one cycle, which allows the processor to handle many
instructions at same time.
in this instructions are register based and data transfer takes place from registerto register.
Cisc Processor
it is known as complex instruction set computer.
it was first developed by intel.
it contains large number of complex instructions.
in this instructions are not register based.
instructions cannot be completed in one machine cycle.
data transfer is from memory to memory.
micro programmed control unit is found in cisc.
also they have variable instruction formats.

Difference Between Cisc And Risc

architectural reduced instruction set


complex instruction setcomputer(cisc)
characterstics computer(risc)

instruction sizeand large set of instructions with variable formats small set of instructions with
format (16-64 bits perinstruction). fixed format (32 bit).

data transfer memory to memory. register to register.

268
most micro coded using control memory mostly hardwired without
cpu control (rom) but modern cisc usehardwired control. control memory.

instruction type not register based instructions. register basedinstructions.

memory access more memory access. less memory access.

clocks includes multi-clocks. includes single clock.

instructions are reducedand


instruction nature instructions are complex.
simple.

Parallel Processing
parallel processing can be described as a class of techniques which enables thesystem to achieve
simultaneous data-processing tasks to increase the computational speed of a computer system.
a parallel processing system can carry out simultaneous data-processing to achieve faster execution
time. for instance, while an instruction is being processed in the alu component of the cpu, the next
instruction can be readfrom memory.
the primary purpose of parallel processing is to enhance the computer processing capability and
increase its throughput, i.e., the amount of processing that can be accomplished during a given
interval of time.a parallel processing system can be achieved by having a multiplicity of functional
units that perform identical or different operations simultaneously. the data can be distributed among
various multiple functional units.
the following diagram shows one possible way of separating the execution unitinto eight functional
units operating in parallel.
the operation performed in each functional unit is indicated in each block if thediagram:

269
the adder and integer multiplier performs the arithmetic operation withinteger numbers.
the floating-point operations are separated into three circuits operatingin parallel.
the logic, shift, and increment operations can be performed concurrently on different data. all units
are independent of each other,
so one number can be shifted while another number is beingincremented.

Data Transfer Modes Of A Computer System


according to the data transfer mode, computer can be divided into 4 majorgroups:
sisd
simd
misd
mimd

Sisd (Single Instruction Stream, Single Data Stream)


it represents the organization of a single computer containing a control unit, processor unit and a
memory unit. instructions are executed sequentially. it can be achieved by pipelining or multiple
functional units.

Simd (Single Instruction Stream, Multiple Data Stream)


it represents an organization that includes multiple processing units under thecontrol of a common
270
control unit. all processors receive the same instruction from control unit but operate on different
parts of the data.
they are highly specialized computers. they are basically used for numerical problems that are
expressed in the form of vector or matrix. but they are notsuitable for other types of computations

Misd (Multiple Instruction Stream, Single Data Stream)


it consists of a single computer containing multiple processors connected withmultiple control units
and a common memory unit. it is capable of processing several instructions over single data stream
simultaneously. misd structure is
only of theoretical interest since no practical system has been constructed usingthis organization.

Mimd (Multiple Instruction Stream, Multiple Data Stream)


it represents the organization which is capable of processing several programs atsame time. it is the
organization of a single computer containing multiple processors connected with multiple control
units and a shared memory unit. the shared memory unit contains multiple modules to communicate
with all processors simultaneously. multiprocessors and multicomputer are the examplesof mimd. it
fulfills the demand of large scale computations.

Pipelining
the term pipelining refers to a technique of decomposing a sequential processinto sub-operations,
with each sub-operation being executed in a dedicated segment that operates concurrently with all
other segments.
the most important characteristic of a pipeline technique is that several computations can be in
progress in distinct segments at the same time. the overlapping of computation is made possible by
associating a register with each segment in the pipeline. the registers provide isolation between each
segment sothat each can operate on distinct data simultaneously.
the structure of a pipeline organization can be represented simply by including aninput register for
each segment followed by a combinational circuit.
an example of combined multiplication and addition operation to get a betterunderstanding of the
pipeline organization.
the combined multiplication and addition operation is done with a stream ofnumbers such as:

Ai* Bi + Ci for i = 1, 2, 3, ....... , 7

the operation to be performed on the numbers is decomposed into sub- operations with each sub-
operation to be implemented in a segment within apipeline.
the sub-operations performed in each segment of the pipeline are defined as:

R1 ← Ai, R2 ← Bi Input Ai, and Bi

R3 ← R1 * R2, R4 ← Ci Multiply, and input Ci

R5 ← R3 + R4 Add Ci to product

the following block diagram represents the combined as well as the sub-operations performed in each
segment of the pipeline.
271
registers r1, r2, r3, and r4 hold the data and the combinational circuits operatein a particular segment.
the output generated by the combinational circuit in a given segment is applied as an input register
of the next segment. for instance, from the block diagram, we
can see that the register r3 is used as one of the input registers for thecombinational adder circuit.
in general, the pipeline organization is applicable for two areas of computerdesign which includes:
arithmetic pipeline
instruction pipeline

Arithmetic Pipeline
arithmetic pipelines are mostly used in high-speed computers. they are used toimplement floating-
point operations, multiplication of fixed-point numbers, and similar computations encountered in
scientific problems.
to understand the concepts of arithmetic pipeline in a more convenient way, anexample of a pipeline
unit for floating-point addition and subtraction.
the inputs to the floating-point adder pipeline are two normalized floating-point binary numbers
defined as:
X = A * 2a = 0.9504 * 103

Y = B * 2b = 0.8200 * 102

272
where a and b are two fractions that represent the mantissa and a and b are theexponents.
the combined operation of floating-point addition and subtraction is divided intofour segments. each
segment contains the corresponding suboperation to be performed in the given pipeline. the
suboperations that are shown in the four segments are:
compare the exponents by subtraction. align the mantissas. Add or subtract the mantissas.
normalize the result.
the following block diagram represents the suboperations performed in eachsegment of the pipeline.

Note: Registers are placed after each suboperation to store the intermediate
results.

compare exponents by subtraction:


the exponents are compared by subtracting them to determine their [Link] larger exponent
is chosen as the exponent of the result.
the difference of the exponents, i.e., 3 - 2 = 1 determines how many times themantissa associated
with the smaller exponent must be shifted to the right.

Align The Mantissas:


the mantissa associated with the smaller exponent is shifted according to thedifference of exponents
determined in segment one.

X = 0.9504 * 103

Y = 0.08200 * 103

273
Add Mantissas:
the two mantissas are added in segment three.

Z = X + Y = 1.0324 * 103

Normalize The Result:


after normalization, the result is written as:

Z = 0.1324 * 104

Instruction Pipeline
pipeline processing can occur not only in the data stream but in the instructionstream as well.
most of the digital computers with complex instructions require instruction pipeline to carry out
operations like fetch, decode and execute instructions.
in general, the computer needs to process each instruction with the followingsequence of steps.
fetch instruction from memory.
decode the instruction.
calculate the effective address.
fetch the operands from memory.
execute the instruction.
store the result in the proper place.
each step is executed in a particular segment, and there are times when differentsegments may take
different times to operate on the incoming information.
moreover, there are times when two or more segments may require memoryaccess at the same time,
causing one segment to wait until another is finishedwith the memory.
the organization of an instruction pipeline will be more efficient if the instructioncycle is divided into
segments of equal duration. one of the most common examples of this type of organization is a four-
segment instruction pipeline.

A four-segment instruction pipeline combines two or more different segments and makes it as a
single one. for instance, the decoding of the instruction can becombined with the calculation of the
effective address into one [Link] following block diagram shows a typical example of a four-
segment instruction pipeline. the instruction cycle is completed in four segments.

274
segment 1:
the instruction fetch segment can be implemented using first in, first out (fifo)buffer.

segment 2:
the instruction fetched from memory is decoded in the second segment, andeventually, the effective
address is calculated in a separate arithmetic circuit.

segment 3:
an operand from memory is fetched in the third segment.

segment 4:
the instructions are finally executed in the last segment of the pipelineorganization.

Advantages Of Pipelining
the cycle time of the processor is reduced.
it increases the throughput of the system
it makes the system reliable.

275
Disadvantages Of Pipelining
the design of pipelined processor is complex and costly to manufacture.
the instruction latency is more.

Vector(Array) Processing
there is a class of computational problems that are beyond the capabilities of a conventional
computer. these problems require vast number of computations onmultiple data items, that will take
a conventional computer (with scalar processor)days or even weeks to complete.
such complex instructions, which operates on multiple data at the same time,requires a better way of
instruction execution, which was achieved by vector processors.
scalar CPUs can manipulate one or two data items at a time, which is not veryefficient. also, simple
instructions like add a to b, and store into c are not practically efficient.
addresses are used to point to the memory location where the data to be operated will be found,
which leads to added overhead of data lookup. so, until the data is found, the cpu would be sitting
ideal, which is a big performanceissue.
hence, the concept of instruction pipeline comes into picture, in which the instruction passes through
several sub-units in turn. these sub-units perform various independent functions, for example: the
first one decodes the instruction, the second sub-unit fetches the data and the third sub-unit performs
the math itself. therefore, while the data is fetched for one instruction, cpu doesnot sit idle, it rather
works on decoding the next instruction set, ending up working like an assembly line. Vector processor,
not only use instruction pipeline, but it also pipelines the data,working on multiple data at the same
time. A normal scalar processor instruction would be add a, b, which leads to additionof two operands,
but what if we can instruct the processor to add a group of numbers(from 0 to n memory location) to
another group of numbers(lets
say, n to k memory location). this can be achieved by vector processors.
in vector processor a single instruction, can ask for multiple data operations, which saves time, as
instruction is decoded once, and then it keeps on operatingon different data items.
applications of vector processors computer with vector processing capabilities are in demand in
specialized applications. the following are some areas where vector processing is used: petroleum
exploration.

Medical Diagnosis.
data analysis.

Weather Forecasting.
aerodynamics and space flight simulations. Image processing. Artificial intelligence.

Vector(Array) Processor And Its Types


array processors are also known as multiprocessors or vector processors. they perform
computations on large arrays of data. thus, they are used to improve theperformance of the computer.

Types Of Array Processors


there are basically two types of array processors:attached array processors simd array processors

Attached Array Processors


an attached array processor is a processor which is attached to a general purposecomputer and its
purpose is to enhance and improve the performance of that computer in numerical computational
tasks. it achieves high performance by means of parallel processing with multiple functional units.
276
simd array processors
simd is the organization of a single computer containing multiple processors operating in parallel.
the processing units are made to operate under the controlof a common control unit, thus providing
a single instruction stream and multipledata streams. A general block diagram of an array processor
is shown below. it contains a set ofidentical processing elements (pe's), each of which is having a
local memory m. each processor element includes an alu and registers. the master control unit
controls all the operations of the processor elements. it also decodes the instructions and determines
how the instruction is to be executed.
the main memory is used for storing the program. the control unit is responsible for fetching the
instructions. vector instructions are sent to all pe's simultaneously and results are returned to the
memory. The best known simd array processor is the iliac iv computer developed by the burroughs
corps. simd processors are highly specialized computers. they are only suitable for numerical
problems that can be expressed in vector or matrix form, and they are not suitable for other types of
computations.

277
Why Use The Array Processor Array Processors Increases The Overall Instruction Processing
Speed.
as most of the array processors operates asynchronously from the hostcpu, hence it improves the
overall capacity of the system.
array processors have its own local memory, hence providing extramemory for systems with low
memory.

Input/Output OrganizationInput/Output Subsystem


the i/o subsystem of a computer provides an efficient mode of communication between the central
system and the outside environment. it handles all the input- output operations of the computer
system.

Peripheral Devices
input or output devices that are connected to computer are called peripheraldevices. these devices
are designed to read information into or out of the memory unit upon command from the CPU and are
considered to be the part ofcomputer system. these devices are also called peripherals.
for example: keyboards, display units and printers are common peripheraldevices.

There Are Three Types Of Peripherals:


input peripherals allow user input, from the outside world to thecomputer. example: keyboard, mouse
etc.
output peripherals allow information output, from the computer to theoutside world. example: printer,
monitor etc.
input-output peripherals: allows both input (from outside world tocomputer) as well as, output (from
computer to the outside world).example: touch screen etc.
interfaces

interface is a shared boundary between two separate components of the computersystem which can
be used to attach two or more components to the system for communication purposes.
there are two types of interfaces:
CPU interface I/o interface

Input-Output Interface
peripherals connected to a computer need special communication links for interfacing with CPU. in
computer system, there are special hardware components between the CPU and peripherals to
control or manage the input-output transfers. these components are called input-output interface
units because they provide communication links between processor bus and peripherals. they provide
a method for transferring information between internalsystem and input-output devices.

modes of i/o data transfer data transfer between the central unit and i/o devices can be handled in
generally three types of modes which are given below:
programmed i/o interrupt initiated i/o direct memory access

Programmed I/O
programmed i/o instructions are the result of i/o instructions written in computer program. each data
item transfer is initiated by the instruction in theprogram.
usually, the program controls data transfer to and from cpu and peripheral. transferring data under
278
programmed i/o requires constant monitoring of theperipherals by the cpu.
Interrupt Initiated I/O
in the programmed i/o method the cpu stays in the program loop until the i/ounit indicates that it is
ready for data transfer. this is time consuming process because it keeps the processor busy
needlessly.
this problem can be overcome by using interrupt initiated i/o. in this when the interface determines
that the peripheral is ready for data transfer, it generates aninterrupt. after receiving the interrupt
signal, the cpu stops the task which it is processing and service the i/o transfer and then returns back
to its previous processing task.

direct memory access removing the cpu from the path and letting the peripheral device manage the
memory buses directly would improve the speed of transfer. this technique is known as dma.
in this, the interface transfer data to and from the memory through memory bus.a dma controller
manages to transfer data between peripherals and memory unit.
many hardware systems use dma such as disk drive controllers, graphic cards,network cards and
sound cards etc. it is also used for intra chip data transfer inmulticore processors. in dma, cpu would
initiate the transfer, do other operations while the transfer is in progress and receive an interrupt from
the dma controller when the transfer has been completed.

above figure shows block diagram of dam

Input/Output Processor
an input-output processor (iop) is a processor with direct memory access capability. in this, the
computer system is divided into a memory unit and numberof processors.
each iop controls and manage the input-output tasks. the iop is similar to cpu except that it handles
only the details of i/o processing. the iop can fetch and execute its own instructions. these iop
instructions are designed to manage i/otransfers only.
279
block diagram of i/o processor below is a block diagram of a computer along with various i/o
processors. the memory unit occupies the central position and can communicate with each
Processor.
the CPU processes the data required for solving the computational tasks. the iopprovides a path for
transfer of data between peripherals and memory. the cpu assigns the task of initiating the i/o
program.
the iop operates independent from CPU and transfer data between peripheralsand memory.

the communication between the iop and the devices is similar to the program control method of
transfer. and the communication with the memory is similar tothe direct memory access method.
in large scale computers, each processor is independent of other processors andany processor can
initiate the operation.
the cpu can act as master and the iop act as slave processor. the cpu assigns thetask of initiating
operations but it is the iop, who executes the instructions, and not the cpu. cpu instructions provide
operations to start an i/o transfer. the iop asks for cpu through interrupt.
instructions that are read from memory by an iop are also called commands to distinguish them from
instructions that are read by cpu. commands are preparedby programmers and are stored in memory.
command words make the program for iop. CPU informs the iop where to find the commands in
memory.

Interrupts
data transfer between the CPU and the peripherals is initiated by the CPU. but the CPU cannot start
the transfer unless the peripheral is ready to communicate with the CPU. when a device is ready to
communicate with the CPU, it generatesan interrupt signal. a number of input-output devices are
attached to the computer and each device is able to generate an interrupt request.
the main job of the interrupt system is to identify the source of the interrupt. there is also a possibility
that several devices will request simultaneously for CPUcommunication. then, the interrupt system has to
decide which device is to be serviced first.

Priority Interrupt
a priority interrupt is a system which decides the priority at which various devices, which generates
the interrupt signal at the same time, will be serviced bythe cpu. the system has authority to decide
which conditions are allowed to interrupt the cpu, while some other interrupt is being serviced.
generally, devices with high-speed transfer such as magnetic disks are given high priority and slow
280
devices such as keyboards are given low priority.
when two or more devices interrupt the computer simultaneously, the computerservices the device
with the higher priority first.
Types Of Interrupts:
following are some different types of interrupts:

Hardware Interrupts
when the signal for the processor is from an external device or hardware thenthis interrupts is known
as hardware [Link] example: when we press any key on our keyboard to do some action, then
thispressing of the key will generate an interrupt signal for the processor to perform certain action.
such an interrupt can be of two types:

Maskable Interrupt
the hardware interrupts which can be delayed when a much high priorityinterrupt has occurred at the
same time.

Non Maskable Interrupt


the hardware interrupts which cannot be delayed and should be processed by the processor
immediately. software interrupts the interrupt that is caused by any internal system of the computer
system isknown as a software interrupt. it can also be of two types:

Normal Interrupt
the interrupts that are caused by software instructions are called normalsoftware interrupts.

Exception
unplanned interrupts which are produced during the execution of some programs are called
exceptions, such as division by zero.

Daisy Chaining Priority


this way of deciding the interrupt priority consists of serial connection of all the devices which
generates an interrupt signal. the device with the highest priority isplaced at the first position followed
by lower priority devices and the device which has lowest priority among all is placed at the last in the
[Link] daisy chaining system all the devices are connected in a serial form. the interrupt line request
is common to all devices. if any device has interrupt signal in low level state then interrupt line goes
to low level state and enables the interrupt input in the cpu. when there is no interrupt the interrupt
line stays in high level state. the cpu respond to the interrupt by enabling the interrupt acknowledge
line. this signal is received by the device 1 at its pi input. the acknowledge signal passes to next device
through po output only if device 1 is notrequesting an interrupt.
the following figure shows the block diagram for daisy chaining priority system.

281
Memory Organization In Computer Architecture
a memory unit is the collection of storage units or devices together. the memoryunit stores the binary
information in the form of bits. generally, memory/storageis classified into 2 categories:
volatile memory: this loses its data, when power is switched off.
non-volatile memory: this is a permanent storage and does not lose anydata when power is switched
off.

Memory Hierarchy
a memory unit is an essential component in any digital computer since it is needed for storing
programs and data.
typically, a memory unit can be classified into two categories:
the memory unit that establishes direct communication with the CPU iscalled main memory. the main
memory is often referred to as ram (random access memory).
the memory units that provide backup storage are called auxiliary memory. for instance, magnetic
disks and magnetic tapes are the mostused auxiliary memories.

auxiliary memory access time is generally 1000 times that of the main memory,hence it is at the
bottom of the hierarchy.
the main memory occupies the central position because it is equipped to communicate directly with
the CPU and with auxiliary memory devices throughinput/output processor (i/o).
when the program not residing in main memory is needed by the CPU, they are brought in from
auxiliary memory. programs not currently needed in main memory are transferred into auxiliary
memory to provide space in main memoryfor other programs that are currently in use.
the cache memory is used to store program data which is currently being executed in the cpu.
approximate access time ratio between cache memory andmain memory is about 1 to 7~10
apart from the basic classifications of a memory unit, the memory hierarchy consists all of the
storage devices available in a computer system ranging from the slow but high-capacity auxiliary
memory to relatively faster main memory. the total memory capacity of a computer can be visualized
by hierarchy of components. the memory hierarchy system consists of all storage devices contained
in a computer system from the slow auxiliary memory to fast mainmemory and to smaller cache

282
memory.

Memory Access Methods


each memory type, is a collection of numerous memory locations. to access datafrom any memory,
first it must be located and then the data is read from the memory location. following are the methods
to access information from memorylocations:
random access: main memories are random access memories, in which each memory location has a
unique address. using this unique address anymemory location can be reached in the same amount
of time in any [Link] access: this method allows memory access in a sequence or inorder.
direct access: in this mode, information is stored in tracks, with each track having a separate
read/write head.

Main Memory The Main Memory Acts As The Central Storage Unit In A Computer System. It Is A

Relatively Large And


fast memory which is used to store programs and data duringthe run time operations.
the primary technology used for the main memory is based on semiconductorintegrated circuits.

283
the memory unit that communicates directly within the cpu, auxillary memoryand cache memory, is
called main memory. it is the central storage unit of the computer system. it is a large and fast
memory used to store data during computer operations. main memory is made up of ram and rom,
with ram integrated circuit chips holing the major share.
ram: random access memory dram: dynamic ram, is made of capacitors and transistors, and must
be refreshed every 10~100 ms. it is slower and cheaper thansram.
sram: static ram, has a six-transistor circuit in each cell and retainsdata, until powered off. nvram: non-
volatile ram, retains its data, even when turned [Link]: flash memory.
rom: read only memory read only memory, is non-volatile and is more like a permanentstorage for
information. it also stores the bootstrap
loader program, to load and start the operating system when computer is turned on. prom
(programmable rom), eprom(erasable prom) and eeprom(electrically erasable prom) are some
commonly used roms.

Auxiliary Memory
devices that provide backup storage are called auxiliary memory. For example: magnetic disks and
tapes are commonly used auxiliary devices. other devices used as auxiliary memory are magnetic
drums, magnetic bubble memoryand optical disks.
it is not directly accessible to the CPU and is accessed using the input/outputchannels.
auxiliary memory is known as the lowest-cost, highest-capacity and slowest- access storage in a
computer system. it is where programs and data are kept for long-term storage or when not in
immediate use. the most common examples ofauxiliary memories are magnetic tapes and magnetic
disks.

Magnetic Disks
a magnetic disk is a type of memory constructed using a circular plate of metal orplastic coated with
magnetized materials. usually, both sides of the disks are usedto carry out read/write operations.
however, several disks may be stacked on onespindle with read/write head available on each surface.
the following image shows the structural representation for a magnetic disk.
an auxiliary memory is known as the lowest-cost, highest-capacity and slowest- access storage in a
computer system. it is where programs and data are kept for long-term storage or when not in
immediate use. the most common examples ofauxiliary memories are magnetic tapes and magnetic
disks.

Magnetic Disks
a magnetic disk is a type of memory constructed using a circular plate of metal orplastic coated with
magnetized materials. usually, both sides of the disks are usedto carry out read/write operations.
however, several disks may be stacked on onespindle with read/write head available on each surface.
the following image shows the structural representation for a magnetic disk.

284
the memory bits are stored in the magnetized surface in spots along theconcentric circles called
tracks. the concentric circles (tracks) are commonly divided into sections calledsectors.

Magnetic Tape
magnetic tape is a storage medium that allows data archiving, collection, andbackup for different
kinds of data. the magnetic tape is constructed using a plastic strip coated with a magnetic recording
medium. The bits are recorded as magnetic spots on the tape along several tracks. usually,seven or
nine bits are recorded simultaneously to form a character together witha parity bit.
magnetic tape units can be halted, started to move forward or in reverse, or canbe rewound. however,
they cannot be started or stopped fast enough between individual characters. for this reason,
information is recorded in blocks referred to as records.

Cache Memory
the data or contents of the main memory that are used again and again by CPU,are stored in the cache
memory so that we can easily access that data in shortertime.
whenever the CPU needs to access memory, it first checks the cache memory. ifthe data is not found
in cache memory, then the CPU moves onto the main memory. it also transfers block of recent data
into the cache and keeps on deleting the old data in cache to accommodate the new one.
the data or contents of the main memory that are used frequently by CPU are stored in the cache
memory so that the processor can easily access that data in ashorter time. whenever the CPU needs
to access memory, it first checks the cache memory. if the data is not found in cache memory, then
the CPU moves into the main memory. Cache memory is placed between the CPU and the main
memory. the blockdiagram for a cache memory can be represented as:

285
the cache is the fastest component in the memory hierarchy and approaches the speed of CPU
components.

The basic operation of a cache memory is as follows: when the CPU needs to access memory, the
cache is examined. if theword is found in the cache, it is read from the fast memory.
if the word addressed by the CPU is not found in the cache, the mainmemory is accessed to read the
word. A block of words one just accessed is then transferred from main memory to cache memory.
the block size may vary from one word (theone just accessed) to about 16 words adjacent to the one
just accessed. The performance of the cache memory is frequently measured in termsof a quantity
called hit ratio. When the CPU refers to memory and finds the word in cache, it is said toproduce a hit.
If the word is not found in the cache, it is in main memory and it countsas a miss. the ratio of the
number of hits divided by the total CPU references tomemory (hits plus misses) is the hit ratio.
hit ratio the performance of cache memory is measured in terms of a quantity called hitratio. when
the CPU refers to memory and finds the word in cache it is said to produce a hit. if the word is not
found in cache, it is in main memory then it counts as a miss.
the ratio of the number of hits to the total CPU references to memory is called hitratio.

Hit Ratio = Hit/ (Hit + Miss)

Associative Memory
it is also known as content addressable memory (cam). it is a memory chip in which each bit position
can be compared. in this the content is compared in each bit cell which allows very fast table lookup.
since the entire chip can be compared, contents are randomly stored without considering addressing
[Link] chips have less storage capacity than regular memory chips.
an associative memory can be considered as a memory unit whose stored datacan be identified for
access by the content of the data itself rather than by an address or memory location. Associative
memory is often referred to as content addressable memory (cam).
when a write operation is performed on associative memory, no address or memory location is given
to the word. the memory itself is capable of finding anempty unused location to store the word.
on the other hand, when the word is to be read from an associative memory, thecontent of the word,
or part of the word, is specified. the words which match thespecified content are located by the
memory and are marked for reading.

286
the following diagram shows the block representation of an associative memory.
from the block diagram, we can say that an associative memory consists of amemory array and logic
for 'm' words with 'n' bits per word.
the functional registers like the argument register a and key register k each have n bits, one for each
bit of a word. the match register m consists of m bits,one for each memory word.
the words which are kept in the memory are compared in parallel with thecontent of the argument
register. The key register (k) provides a mask for choosing a particular field or key in the argument
word. if the key register contains a binary value of all 1's, then the entire argument is compared with
each memory word. otherwise, only those bitsin the argument that have 1's in their corresponding
position of the key register are compared. thus, the key provides a mask for identifying a piece of
information which specifies how the reference to memory is made.

the following diagram can represent the relation between the memory array andthe external registers
in an associative memory.
the cells present inside the memory array are marked by the letter c with two subscripts. the first
subscript gives the word number and the second specifies thebit position in the word. for instance,
287
the cell cij is the cell for bit j in word I.
a bit aj in the argument register is compared with all the bits in column j of thearray provided that kj =
1. this process is done for all columns j = 1, 2, 3, n. if a match occurs between all the unmasked bits
of the argument and the bits inword i, the corresponding bit mi in the match register is set to 1. if one
or more unmasked bits of the argument and the word do not match, mi is cleared to 0.

Memory mapping and concept of virtual memory he transformation of data from main memory to
cache memory is calledmapping. there are 3 main types of mapping:
associative mapping direct mapping set associative mapping

the associative memory stores both address and data. the address value of 15 bits is 5-digit octal
numbers and data is of 12 bits word in 4-digit octal number. a CPU address of 15 bits is placed in
argument register and the associative memoryis searched for matching address.
direct mapping
the CPU address of 15 bits is divided into 2 fields. in this the 9 least significant bitsconstitute the
index field, and the remaining 6 bits constitute the tag field. the number of bits in index field is equal
to the number of address bits required to access cache memory.

Set Associative Mapping

288
the disadvantage of direct mapping is that two words with same index address can't reside in cache
memory at the same time. this problem can be overcome byset associative mapping.
in this we can store two or more words of memory under the same index [Link] data word is
stored together with its tag and this forms a set.

Replacement Algorithms
data is continuously replaced with new data in the cache memory using replacement algorithms.
following are the 2 replacement algorithms used: fifo - first in first out. oldest item is replaced with
the lru - least recently used. item which is least recently used by cpu isremoved.

Virtual Memory
virtual memory is the separation of logical memory from physical memory. thisseparation provides
large virtual memory for programmers when only small physical memory is available.
virtual memory is used to give programmers the illusion that they have a very large memory even
though the computer has a small main memory. it makes thetask of programming easier because the

289
programmer no longer needs to worry about the amount of physical memory available.

Memory Management Unit (Mmu)


a computer’s memory management unit (mmu) is the physical hardware that handles its virtual
memory and caching operations. the mmu is usually located within the computer’s central processing
unit (CPU), but sometimes operates in a/ separate integrated chip (ic). all data request inputs are sent
to the mmu, whichin turn determines whether the data needs to be retrieved from ram or rom storage.
a memory management unit is also known as a paged memory management unit.

The Memory Management Unit Performs Three Major Functions: Hardware Memory Management
operating system (os) memory management
application memory management
hardware memory management deals with a system's ram and cache memory, os memory
management regulates resources among objects and data structures, and application memory
management allocates and optimizes memory among programs.
the mmu also includes a section of memory that holds a table that matches virtual addresses to
physical addresses, called the translation lookaside buffer(tab).

Multiprocessor
a multiprocessor is a computer system with two or more central processing units(cpus) share full
access to a common ram. the main objective of using a multiprocessor is to boost the system’s
execution speed, with other objectives being fault tolerance and application matching.
there are two types of multiprocessors, one is called shared memory multiprocessor, and another is
distributed memory multiprocessor. in shared memory multiprocessors, all the CPUs shares the
common memory but in a distributed memory multiprocessor, every CPU has its own private memory.

Applications Of Multiprocessor –
as a uniprocessor, such as single instruction, single data stream (sisd).
as a multiprocessor, such as single instruction, multiple data stream (simd),which is usually used for
vector processing. Multiple series of instructions in a single perspective, such as multiple instruction,
single data stream (misd), which is used for describing hyper-threading or pipelined processors.
inside a single system for executing multiple, individual series of instructions in multiple perspectives,
such as multiple instruction, multipledata stream (mimd).
290
Benefits Of Using A Multiprocessor –
enhanced performance.
multiple applications.
multi-tasking inside an application.
high throughput and responsiveness.
hardware sharing among CPUs.

Characteristics Of Multiprocessor
a multiprocessor system has two or more cpus. it is an interconnection of two or more cpus with
memory and input-output equipment. the term “processor” in multiprocessor can mean either a
central processing unit (cpu) or an input-outputprocessor (iop). however, a system with a single cpu
and one or more lops is usually not included in the definition of a multiprocessor system unless the
iop has computational facilities comparable to a cpu. as it is most commonly defined, a
multiprocessor system implies the existence of multiple cpus, although usually there will be one or
more lops as well. as mentioned earlier multiprocessors are classified as multiple instruction stream,
multiple data stream (mimd) systems.
there are some similarities between multiprocessor and multicomputer systems since both support
concurrent operations. however, there exists an important distinction between a system with multiple
computers and a system with multipleprocessors. computers are interconnected with each other by
means of communication lines to form a computer network. the network consists of several
autonomous computers that may or may not communicate with each other. a multiprocessor system
is controlled by one operating system that provides interaction between processors and all the
components of the system cooperate in the solution of a problem.
multiprocessing improves the reliability of the system so that a failure or error inone part has a limited
effect on the rest of the system. if a fault cause one processor to fail, a second processor can be
assigned to perform the functions ofthe disabled processor. the system as a whole can continue to
function correctlywith perhaps some loss in efficiency.
the benefit derived from a multiprocessor organization is an improved system performance. the
system derives its high performance from the fact that computations can proceed in parallel in one
of two ways. Multiple independent jobs can be made to operate in parallel.a single job can be
partitioned into multiple parallel tasks. an overall function can be partitioned into a number of tasks
that each processor can handle individually. system tasks may be allocated to special purpose
processors whose design is optimized to perform certain types of processing efficiently. an example
is a computer system where one processor performs the computations for an industrial process
control while other monitor and control the various parameters, such as temperature and flow rate.
multiprocessors are classified by the way their memory is organized. a multiprocessor system with
common shared memory is classified as a shared- memory or tightly coupled multiprocessor. this
does not preclude each processorfrom having its own local memory. in fact, most commercial tightly
coupled multiprocessors provide a cache memory with each cpu. in addition, there is a global
common memory that all cpus can access. information can therefore be shared among the cpus by
placing it in the common global memory.

An alternative model of microprocessor is the distributed-memory or loosely coupled system. each


processor element in a loosely coupled system has its own private local memory. the processors are
tied together by a switching scheme designed to route information from one processor to another
through a message-passing scheme. the processors relay program and data to other processors in
packets. a packet consists of an address, the data content, and some error detection code. the
291
packets are addressed to a specific processor or taken by the first available processor, depending on
the communication system used. loosely coupled systems are most efficient when the interaction
between tasks is minimal, whereas tightly coupled systems can tolerate a higher degree of interaction
between tasks.
Interconnection Structures
CPUs, tops connect’ to input-output device, and a memory unit form a multiprocessor system, they
may be partitioned into a number of separatemodules. the interconnection between the components
can have different physical configurations, depending on the number of transfer paths that are
available between the processors and memory in a shared memory system oramong the processing
elements in a loosely coupled system. there are severalphysical forms available for establishing an
interconnection network. some of these schemes are presented in this section: time-shared common
bus multiport memory crossbar switch multistage switching network hypercube system

Time Shared Common Bus


a common-bus multiprocessor system consists of a number of processors connected through a
common path to a memory unit. a time-shared common busfor five processors is shown in figure
below. only one processor can communicatewith the memory or another processor at any given time.
transfer operations are conducted by the processor that is in control of the bus at the time. any other
processor wishing to initiate a transfer must first determine the availability status of the bus, and only
after the bus becomes available can the processor address the destination unit to initiate the transfer.
a command is issued to inform the destination unit what operation is to be performed. the receiving
unit recognizes its address in the bus and responds to the control signals from the sender, after which
the transfer is initiated. the system may exhibit transfer conflicts since one common bus is shared
by all processors. these conflicts must be resolved by incorporating a bus controller that establishes
priorities among the requesting units.
a single common-bus system is restricted to one transfer at a time. this means that when one
processor is communicating with the memory, all other processors are either busy with internal
operations or must be idle waiting for the bus. as a consequence, the total overall transfer rate within
the system is limited by the speed of the single path. the processors in the system can be kept busy
more often through the implementation of two or more independent buses to permit multiple
simultaneous bus transfers. however, this increases the system cost andcomplexity.

Multiport Memory
a multiport memory system employs separate buses between each memory module and each CPU.
this is shown in figure below for four cpus and four memory modules (mms). each processor bus is
connected to each memory module. a processor bus consists of the address, data, and control lines
required to communicate with memory. the memory module is said to have four ports andeach port
accommodates one of the buses. the module must have internal control logic to determine which
port will have access to memory at any given time. memory access conflicts are resolved by
assigning fixed priorities to each memory port. the priority for memory access associated with each
processor maybe established by the physical port position that its bus occupies in each module. thus
cpu1 will have priority over cpu2, cpu2 will have priority over cpu3, and cpu4 will have the lowest
priority. the advantage of the multiport memory organization is the high transfer rate that can be
achieved because of the multiplepaths between processors and memory. the disadvantage is that it
requires expensive memory control logic and a large number of cables and connectors. as a
consequence, this interconnection structure is usually appropriate for systems with a small number
of processors.

292
Crossbar Switch
the crossbar switch organization consists of a number of cross points that are placed at intersections
between processor buses and memory module paths. figure below shows a crossbar switch
interconnection between four cpus and four memory modules. the small square in each crosspoint
is a switch that determines the path from a processor to a memory module. each switch point has
control logic to set up the transfer path between a processor and memory. it examines the address
that is placed in the bus to determine whether its particularmodule is being addressed. it also resolves
multiple requests for access to the same memory module on a predetermined priority basis.

Multistage Switching Network


the basic component of a multistage network is a two-input, two-output interchange switch. there are

control signals (not shown) associated with the switch that establish the interconnection between
the input and output terminals. the switch has the capability of connecting input a to either of the
outputs. terminal b of the switch behaves in a similar fashion. the switch also hasthe capability to
293
arbitrate between conflicting requests. if inputs a and b both request the same output terminal, only
one of them will be connected; the other will be blocked.

Hypercube Interconnection
the hypercube or binary n-cube multiprocessor structure is a loosely coupled system composed of n
= 2n processors interconnected in an n-dimensional binarycube. each processor forms a node of the
cube. although it is customary to refer to each node as having a processor, in effect it contains not
only a cpu but also local memory and i/o interface. each processor has direct communication paths
to n other neighbor processors. these paths correspond to the edges of the [Link] are 2n distinct
n-bit binary addresses that can be assigned to the processors. each processor address differs from
that of each of its n neighbors by exactly one bit position.

Interconnection Structures
System Bus
the processor uses a multidrop, shared system bus to provide four-way glue less multiprocessor
system support. no additional bridges are needed for building upo a four-way system. systems with
eight or more processors are designed through clusters of these nodes using high-speed
interconnects. note that multidrop buses are a cost-effective way to build high-performance four-way
systems for commercial transaction processing and e-business workloads. these workloads often
have highly shared writeable data and demand high throughput and low latency on transfers of
modified data between caches of multiple processors. in a four-processor system, the transaction
based bus protocol allowsup to 56 pending bus transactions (including 32 read transactions) on the
bus at any given time. an advanced mesi coherence protocol helps in reducing bus invalidation
transactions and in providing faster access to writeable data. the cache-to-cache transfer latency is
further improved by an enhanced defer mechanism, which permits efficient out-of-order data
transfers and out-of-order transaction completion on the bus. a deferred transaction on the bus can
be completed without reusing the address bus. this reduces data return latency for deferred
transactions and efficiently uses the address bus. this feature is critical for scalability beyond four-
processor systems. the 64-bit system bus uses a source-synchronous data transfer to achieve 266-
mtransfers/ s, which enables a bandwidth of 2.1 gbytes/s. the combination of these features makes
the itaniumprocessor system a scalable building block for large multiprocessor systems.

Source Synchronous Mode


in source synchronous mode, the clock to data phase relationship at the input pins is maintained at
the clock and data ports of the ioe input register. this modeis recommended for source synchronous
data transfers. data and clock signals at the ioe experience similar buffer delays as long as the same
i/o standard is used.

Intercrosses Arbitration
computer systems contain a number of buses at various levels to facilitate the transfer of information
between components. the cpu contains a number of internal buses for transferring information
between processor registers and alu.a memory bus consists of lines for transferring data, address,
and read/write information. an i/o bus is used to transfer information to and from input andoutput
devices. a bus that connects major components in a multi-processor system, such as cpus, lops, and
memory, is called a system bus. the physical circuits of a system bus are contained in a number of
identical printed circuit boards. each board in the system belongs to a particular module. the board
consists of circuits connected in parallel through connectors. each pin of each circuit connector is
connected by a wire to the corresponding pin of all other connectors in other boards. thus any board
294
can be plugged into a slot in the back-pane that forms the system bus.
the processors in a shared memory multiprocessor system request access to common memory or
other common resources through the system bus. if n otherprocessor is currently utilizing the bus,
the requesting processor may be granted access immediately. however, the requesting processor
must wait if another processor is currently utilizing the system bus. furthermore, other processors
may request the system bus at the same time. arbitration must then be performed to resolve this
multiple contention for the shared resources. the arbitration logic would be part of the system bus
controller placed between the local bus and the system bus.

System Bus
a typical system bus consists of approximately 100 signal lines. these lines are divided into three
functional groups: data, address, and control. in addition, thereare power distribution lines that supply
power to the components. for example, the ieee standard 796 multibus system has 16 data lines, 24
address lines, 26 control lines, and 20 power lines, for a total of 86 lines.
the data lines provide a path for the transfer of data between processors and common memory. the
number of data lines is usually a multiple of 8, with 16 and32 being most common. the address lines
are used to identify a memory addressor any other source or destination, such as input or output
ports. the number of address lines determines the maximum possible memory capacity in the
system. for example, an address of 24 lines can access up to 2″ (16 mega) words of memory. the
data and address lines are terminated with three-state buffers. the address buffers are unidirectional
from processor to memory. the data lines arebi- directional, allowing the transfer of data in either
direction.

data transfers over the system bus may be synchronous or asynchronous. in asynchronous bus, each
data item is transferred during a time slice known in advance to both source and destination units;
synchronization is achieved by driving both units from a common clock source. an alternative
procedure is tohave separate clocks of approximately the same frequency in each unit.
synchronization signals are transmitted periodically in order to keep all clocks asynchronous bus in
the system in step with each other. in an asynchronous bus, each data item being transferred is
accompanied by handshaking control signals to indicate when the data are transferred from the
source and received by the destination.
the control lines provide signals for controlling the information transfer betweenunits. timing signals
indicate the validity of data and address information.
command signals specify operations to be performed. typical control lines include transfer signals
such as memory read and write, acknowledge of a transfer, interrupt requests, bus control signals
such as bus request and bus grant,and signals for arbitration procedures.

Serial Arbitration Procedure


arbitration procedures service all processor requests on the basis of established priorities. a
hardware bus priority resolving technique can be established by means of a serial or parallel
connection of the units requesting control the systembus. the serial priority resolving technique is
obtained from daisy-chain connection of bus arbitration circuits similar to the priority interrupt logic.
the processors connected to the system bus are assigned priority according to their position along
the priority control line. the device closest to the priority lineis assigned the highest priority. when
multiple devices concurrently request the use of the bus, the device with the highest priority is granted
access to it.

Parallel Arbitration Logic


295
the parallel bus arbitration technique uses an external priority encoder and decoder as shown in figure
below. each bus arbiter in the parallel scheme has a bus request output line and a bus acknowledge
input line. each arbiter enables the request line when its processor is requesting access to the system
bus. the processor takes control of the bus if its acknowledge input line is enabled. the busbusy line
provides an orderly transfer of control, as in the daisy-chaining case.
Dynamic Arbitration Algorithms
the two bus arbitration procedures just described use a static priority algorithm since the priority of
each device is fixed by the way it is connected to the bus. in contrast, a dynamic priority algorithm
gives the system the capability for changingthe priority of the devices while the system is in operation.
we now discuss a few arbitration procedures that use dynamic priority algorithms.
the time slice algorithm allocates a fixed-length time slice of bus time that is offered sequentially to
each processor, in round-robin fashion. the service givento each system component with this scheme
is independent of its location alongthe bus. no preference is given to any particular device since each
is allotted thesame amount of time to communicate with the bus.
in a bus system that uses polling, the bus-grant signal is replaced by a set of linescalled poll lines,
which are connected to all units. these lines are used by the buscontroller to define an address for
each device connected to the bus. the bus controller sequences through the addresses in a
prescribed manner. when a processor that requires access recognizes its address, it activates the
bus busy- line and then accesses the bus. after a number of bus cycles, the polling process continues
by choosing a different processor. the polling sequence is normally programmable, and as a result,
the selection priority can be altered under program control.
the least recently used (lru) algorithm gives the highest priority to the requesting device that has not
used the bus for the longest interval. the prioritiesare adjusted after a number of bus cycles according
to the lru algorithm. with this procedure, no processor is favored over any other since the priorities
aredynamically changed to give every device an opportunity to access the bus.

In the first come, first-serve scheme, requests are served in the order received. toimplement this
algorithm, the bus controller establishes a queue arranged according to the time that the bus requests
arrive. each processor must wait for its turn to use the bus on a first-in, first-out (fifo) basis. the
rotating daisy-chain procedure is a dynamic extension of the daisy-chain algorithm. in this scheme
there is no central bus controller, and the priority line is connected from the priority-out of the last
device back to the priority-in of the first device in a closed loop. this is similar to the connections
shown in figure for serial arbitration exceptthat the po output of arbiter 4 is connected to the pi input
of arbiter 1.
whichever device has access to the bus serves as a bus controller for the following arbitration. each
arbiter priority for a given bus cycle is determined byits position along the bus priority line from the
arbiter whose processor is currently controlling the bus. once an arbiter releases the bus, it has the
lowestpriority.

Intercrosses Communication & Synchronization


the various processors in a multiprocessor system must be provided with a facilityfor communicating
with each other. a communication path can be established through common input-output channels.
in a shared memory multiprocessor system, the most common procedure is to set aside a portion of
memory that is accessible to all processors. the primary use of the common memory is to act as a
message center similar to a mailbox, where each processor can leave messages for other processors
and pick up messages intended for it.
the sending processor structures a request, a message, or a procedure, and places it in the memory
mailbox. status bits residing in common memory are generally used to indicate the condition of the
296
mailbox, whether it has meaningfulinformation, and for which processor it is intended. the receiving
processor can check the mailbox periodically to determine if there are valid messages for it. the
response time of this procedure can be time consuming since a processor will recognize a request
only when polling messages. a more efficient procedure is forthe sending processor to alert the
receiving processor directly by means of an interrupt signal. this can be accomplished through a
software-initiated intercrosses interrupt by means of an instruction in the program of one processor
which when executed produces an external interrupt condition in a second processor. this alerts the
interrupted processor of the fact that a new message has been inserted by the interrupting processor.
in addition to shared memory, a multiprocessor system may have other shared resources. for
example,a magnetic disk storage unit connected to an iop may be available to all CPUs.
this provides a facility for sharing of system programs stored in the [Link] prevent conflicting use of
shared resources by several processors there must be a provision for assigning resources to
processors. this task is given to the operating system. there are three organizations that have been
used in the design of operating system for multiprocessors: master-slave configuration, separate
operating system, and distributed operating system. in a master-slave mode, one processor,
designated the master, always executes the operating system functions. the remaining processors,
denoted as slaves, do not perform operating system functions. if a slave processor needs an
operating system service, it must request it by interrupting the master and waiting until the current
program can be interrupted. in the separate operating system organization, each processor can
execute the operating system routines it needs. this organization ismore suitable for loosely coupled
systems where every processor may have its own copy of the entire operating system. in the
distributed operating system organization, the operating system routines are distributed among the
available processors. however, each particular operating system function is assigned to only one
processor at a time. this type of organization is also referred to as a floating operating system since
the routines float from one processor to another and the execution of the routines may be assigned
to different processors at different times.

Inter Process Communication


inter process communication (ipc) is a mechanism that involves communicationof one process with
another process. this usually occurs only in one system.

Communication Can Be Of Two Types −


between related processes initiating from only one process, such as parentand child processes.
between unrelated processes, or two or more different processes. Following are some important
terms that we need to know before proceedingfurther on this topic.
pipes − communication between two related processes. the mechanism is halfduplex meaning the
first process communicates with the second process. to achieve a full duplex i.e., for the second
process to communicate with the first process another pipe is required.
fifo − communication between two unrelated processes. fifo is a full duplex,meaning the first process
can communicate with the second process and vice versa at the same time.
message queues − communication between two or more processes with full duplex capacity. the
processes will communicate with each other by posting amessage and retrieving it out of the queue.
once retrieved, the message is nolonger available in the queue.
shared memory − communication between two or more processes is achievedthrough a shared piece
of memory among all processes. the shared memory needs to be protected from each other by
synchronizing access to all the processes.
semaphores − semaphores are meant for synchronizing access to multiple processes. when one
process wants to access the memory (for reading or writing), it needs to be locked (or protected) and
297
released when the access isremoved. this needs to be repeated by all the processes to secure data.
signals − signal is a mechanism to communication between multiple processes byway of signaling.
this means a source process will send a signal (recognized by number) and the destination process
will handle it accordingly.
note − almost all the programs in this tutorial are based on system calls under Linux operating system
(executed in ubuntu).

Intercrosses Synchronization
the instruction set of a multiprocessor contains basic instructions that are used to implement
communication and synchronization between cooperating processes. communication refers to the
exchange of data between different processes. for example, parameters passed to a procedure in a
different processor constitute interprocessor communication. synchronization refers to the special
case where the data used to communicate between processors is control information.
synchronization is needed to enforce the correct sequence of processes and to ensure mutually
exclusive access to shared writable data.
multiprocessor systems usually include various mechanisms to deal with the synchronization of
resources. low-level primitives are implemented directly by the hardware. these primitives are the
basic mechanisms that enforce mutual exclusion for more complex mechanisms implemented in
software. a number ofhardware mechanisms for mutual exclusion have been developed. one of the
most popular methods is through the use of a binary semaphore.

Mutual Exclusion With A Semaphore


a binary variable called a semaphore is often used to indicate whether or not a processor is executing
a critical section. a semaphore is a software-controlled flagthat is stored in a memory location that
all processors can access. when the semaphore is equal to 1, it means that a processor is executing
a critical program, so that the shared memory is not available to other processors. when the
semaphore is equal to 0, the shared memory is available to any requesting processor. processors
that share the same memory segment agree by conventionnot to use the memory segment unless
the semaphore is equal to 0, indicating that memory is available. they also agree to set the semaphore
to 1 when theyare executing a critical section and to clear it to 0 when they are finished.
a semaphore can be initialized by means of a test and set instruction in conjunction with a hardware
lock mechanism. a hardware lock is a processor- generated signal that serves to prevent other
processors from using the system bus as long as the signal is active. the test-and-set instruction
tests and sets a semaphore and activates the lock mechanism during the time that the instructionis
being executed. this prevents other processors from changing the semaphore between the time that
the processor is testing it and the time that it is setting it. assume that the semaphore is a bit in the
least significant position of a memory word whose address is symbolized by sem. let the mnemonic
tell designate the “test and set while locked” operation.
the instructions seem will be executed in two memory cycles (the first to read and the second to write)
without interference as follows:

R ← M[SEM] Test semaphore


M [SEM] ← 1 Set semaphore

the semaphore is tested by transferring its value to a processor register r and then it is set to 1. the
value in r determines what to do next. if the processor finds that r = 1, it knows that the semaphore
was originally set (the fact that it is set again does not change the semaphore value). that means
298
another processor isexecuting a critical section, so the processor that checked the semaphore does
not access the shared memory. r = 0 means that the common memory (or the shared resource that
the semaphore represents) is available. the semaphore is set to 1 to prevent other processors from
accessing memory. the processor can now execute the critical section. the last instruction in the
program must clear location sem to zero to release the share resource to other processors.

Cache Coherence
we know that the primary advantage of cache is its ability to reduce the average access time in
uniprocessor systems. when the processor finds a word in cache during a read operation, the main
memory is not involved in the transfer. if the operation is to write, there are two commonly used
procedures to update memory. in the write-through policy, both cache and main memory are updated
with every write operation. in the write-back policy, only the cache is updated and the location is
marked so that it can be copied later into main memory. in a shared memory multiprocessor system,
all the processors share a common memory. in addition, each processor may have a local memory,
part or all of which may be a cache. the compelling reason for having separate caches for each
processor is to reduce the average access time in each processor .the same information may reside
in a number of copies in some caches and main memory. to ensure the ability of the system to
execute memory operations correctly, the multiple copies must be kept identical. this requirement
imposes a cache coherence problem. a memory scheme is coherent if the value returned on a load
instruction is always the value given by the latest store instruction with the same address. without a
proper solution to the cache coherence problem, caching cannot be used in bus-oriented
multiprocessor with two or more processors.

Conditions For Incoherence


cache-coherence problems occur in multiprocessors with private caches becauseof the need to share
writable data. read-only data can safely be replicated without cache coherence enforcement
mechanism to illustrate the problem, consider the three-processor configuration with private caches

Solution To The Cache Coherence System


there are various schemes to solve the cache coherence problem in sharedmemory multiprocessors.
a simple scheme is to disallow private caches for each processor and have a shared cache memory
associated with main memory. every data access is madeto the shared cache. this method violates
the principle of closeness of cpu toache and increases the average memory access time. in effect,
this schemesolves the problem by avoiding it. for performance considerations it is desirable to attach
a private cache to each processor. one scheme that has been used allows only non-shared and read-
only to be stored in caches. such items are called cacheable. shared writable data are non-cachable.
the compiler must tag data as either cachable or non-cachable, and the system hardware makes sure
that only cachable data are stored in caches. the non-cachable data remain in main memory. this
method restricts thetype of data stored in caches and introduces an extra software overhead that
maydegrade performance. a scheme that allows writable data to exist in at least one cache is a
method thatemploys a centralized global table in its compiler. the status of memory blocks isstored
in the central global table. each block is identified as read-only (ro) or read-write (rw). all caches can
have copies of blocks identified as [Link] one cache can have a copy of an rw block. thus, if the data
are updated in the cache with an rw block, the other caches are not affected because they do not
have a copy of this block. the cache coherence problem can be solved by means of a combination of
software and hardware or by means of hardware-only schemes. the two methods mentioned
previously use software-based proceduresthat require the ability to tag information in order to disable
caching of shared writable data. hardware-only solutions are handled by the hardware automatically
299
and have the advantage of higher speed and program [Link] the hardware solution, the
cache controller is speedily designed to allow it to monitor all bus requests from cpus and iops. all
caches attached to the bus constantly monitor the network for possible write operations. depending
on the method used, they must then either update or invalidate their own cache copies when a match
is detected. the bus controller that monitors this action is referred to snoopy cache as a snoopy cache
controller. this is basically a hardware unit designed to maintain a bus-watching mechanism over all
the caches attached to the bus. various schemes have been proposed to solve the cache coherence
problem by means of snoopy cache protocol. the simplest method is to adopt a write-throughpolicy
and use the following procedure. all the snoopy controllers watch the bus for memory store
operations. when a word in a cache is updated by writing into it, the corresponding location in main
memory is also updated. the local snoopy controllers in all other caches check their memory to
determine if they have a copy of the word that has been overwritten. if a copy exists in a remote
cache, that location is marked invalid. because all caches snoop on all bus writes, whenever a word
is written, the net effect is to update it in the original cache and main memory and remove it from all
other caches. if at some future time a processor accesses the invalid item from its cache, the
response is equivalent to a cache miss, and the updated item is transferred from main memory. in
this way, inconsistent versions are prevented

The Cache Coherence Problem


in a multiprocessor system, data inconsistency may occur among adjacent levels or within the same
level of the memory hierarchy. for example, the cache and themain memory may have inconsistent

copies of the same object. as multiple processors operate in parallel, and independently multiple
caches may possess different copies of the same memory block, this creates cache coherence
problem. cache coherence schemes help to avoid this problem bymaintaining a uniform state for
each cached block of data let x be an element of shared data which has been referenced by two
processors,p1 and p2. in the beginning, three copies of x are consistent. if the processor p1 writes a
new data x1 into the cache, by using write-through policy, the same copywill be written immediately
into the shared memory. in this case, inconsistency occurs between cache memory and the main
memory. when a write-back
policy is used, the main memory will be updated when the modified data in thecache is replaced or
invalidated.

In General, There Are Three Sources Of Inconsistency Problem −


300
sharing of writable data process migration i/o activity

Snoopy Bus Protocols


snoopy protocols achieve data consistency between the cache memory and the shared memory
through a bus-based memory system. write-
invalidate and write-update policies are used for maintaining cache consistency.

in this case, we have three processors p1, p2, and p3 having a consistent copy ofdata element ‘x’ in
their local cache memory and in the shared memory (figure-a). processor p1 writes x1 in its cache
memory using write-invalidate protocol. so, all other copies are invalidated via the bus. it is denoted
by ‘I’ (figure-b). invalidated blocks are also known as dirty, i.e., they should not be used. the write-
update protocol updates all the cache copies via the bus. by using write back cache, the memory
copy is also updated (figure-c).

301
Cache Events And Actions
following events and actions occur on the execution of memory-access andinvalidation commands
−read-miss − when a processor wants to read a block and it is not in the cache, a read-miss occurs.
this initiates a bus-read operation. if no dirty copy exists, then the main memory that has a consistent
copy, supplies a copy to the requesting cache memory. if a dirty copy exists in a remote cache
memory, that cache will restrain the main memory and send a copyto the requesting cache memory.
in both the cases, the cache copy will enter the valid state after a read [Link]-hit − if the copy is
in dirty or reserved state, write is done locally andthe new state is dirty. if the new state is valid, write-
invalidate command is broadcasted to all the caches, invalidating their copies. when the shared
memory is written through, the resulting state is reserved after this first write.
write-miss − if a processor fails to write in the local cache memory, thecopy must come either from
the main memory or from a remote cachememory with a dirty block. this is done by sending a read-
invalidate command, which will invalidate all cache copies. then the localcopy is updated with dirty
[Link]-hit − read-hit is always performed in local cache memory withoutcausing a transition of
state or using the snoopy bus for invalidation.

Block Replacement − when a copy is dirty, it is to be written back to the main memory by block
replacement method. however, when the copy is either in valid or reserved or invalid state, no
replacement will take place.

Directory-Based Protocols
302
by using a multistage network for building a large multiprocessor with hundredsof processors, the
snoopy cache protocols need to be modified to suit the network capabilities. broadcasting being very
expensive to perform in a multistage network, the consistency commands is sent only to those
caches thatkeep a copy of the block. this is the reason for development of directory-based protocols
for network-connected multiprocessors.
in a directory-based protocols system, data to be shared are placed in a common directory that
maintains the coherence among the caches. here, the directory acts as a filter where the processors
ask permission to load an entry from the primary memory to its cache memory. if an entry is changed
the directory eitherupdates it or invalidates the other caches with that entry.

Hardware Synchronization Mechanisms


synchronization is a special form of communication where instead of data control, information is
exchanged between communicating processes residing in the sameor different processors.
multiprocessor systems use hardware mechanisms to implement low-level synchronization
operations. most multiprocessors have hardware mechanisms toimpose atomic operations such as
memory read, write or read-modify-write operations to implement some synchronization primitives.
other than atomic memory operations, some inter-processor interrupts are also used for
synchronization purposes.

Cache Coherency In Shared Memory Machines


maintaining cache coherency is a problem in multiprocessor system when theprocessors contain
local cache memory. data inconsistency between differentcaches easily occurs in this system.

The Major Concern Areas Are −Sharing Of Writable Data Process Migration I/O Activity
Sharing Of Writable Data
when two processors (p1 and p2) have same data element (x) in their local caches and one process
(p1) writes to the data element (x), as the caches are write-through local cache of p1, the main
memory is also updated. now when p2tries to read data element (x), it does not find x because the
data element in thecache of p2 has become outdated

Process Migration
303
in the first stage, cache of p1 has data element x, whereas p2 does not have anything. a process on
p2 first writes on x and then migrates to p1. now, the process starts reading data element x, but as
the processor p1 has outdated datathe process cannot read it. so, a process on p1 writes to the data
element x and then migrates to p2. after migration, a process on p2 starts reading the data element
x but it finds an outdated version of x in the main memory.

I/O Activity
as illustrated in the figure, an i/o device is added to the bus in a two-processor multiprocessor
architecture. in the beginning, both the caches contain the data element x. when the i/o device
receives a new element x, it stores the new element directly in the main memory. now, when either p1
or p2 (assume p1) tries to read element x it gets an outdated copy. so, p1 writes to element x. now,if
i/o device tries to transmit x it gets an outdated copy.

Uniform Memory Access (Uma)


uniform memory access (uma) architecture means the shared memory is the same for all processors

304
in the system. popular classes of uma machines, which are commonly used for (file-) servers, are the
so-called symmetric multiprocessors (smps). in an smp, all system resources like memory, disks,
otheri/o devices, etc. are accessible by the processors in a uniform manner.
Non-Uniform Memory Access (Numa)
in numa architecture, there are multiple smp clusters having an internal indirect/shared network,
which are connected in scalable message-passing network. so, numa architecture is logically shared
physically distributed [Link] a numa machine, the cache-controller of a processor
determines whether a memory reference is local to the smp’s memory, or it is remote. to reduce the
number of remote memory accesses, numa architectures usually apply caching processors that can
cache the remote data. but when caches are involved, cache coherency needs to be maintained. so
these systems are also known as cc-numa(cache coherent numa).

Cache Only Memory Architecture (Coma)


coma machines are similar to numa machines, with the only difference that themain memories of
coma machines act as direct-mapped or set-associative caches. the data blocks are hashed to a
location in the dram cache according totheir addresses. data that is fetched remotely is actually
stored in the local main memory. moreover, data blocks do not have a fixed home location, they can
freely move throughout the system.
coma architectures mostly have a hierarchical message-passing network. a switch in such a tree
contains a directory with data elements as its sub-tree. sincedata has no home location, it must be
explicitly searched for. this means that a remote access requires a traversal along the switches in the
tree to search their directories for the required data. so, if a switch in the network receives multiple
requests from its subtree for the same data, it combines them into a single request which is sent to
the parent of the switch. when the requested data returns, the switch sends multiple copies of it down
its subtree.

Coma Versus Cc-Numa


following are the differences between coma and [Link] tends to be more flexible than cc-
numa because coma transparently supports the migration and replication of data without theneed of
the [Link] machines are expensive and complex to build because they need non-standard memory
management hardware and the coherency protocolis harder to implement.
remote accesses in coma are often slower than those in cc-numa sincethe tree network needs to be
traversed to find the data.

Multicore Processor
A multicore processor is a single computing component comprised of two or more cpus that read
and execute the actual program instructions. the individualcores can execute multiple instructions in
parallel, increasing the performance ofsoftware which is written to take advantage of the unique
architecture. the first multicore processors were produced by intel and amd in the early 2000s. today,
processors are created with two cores ("dual core"), four cores ("quad core"), six cores ("hexa core"),
and eight cores ("octo core"). processorsare made with as many as 100 physical cores, as well as
1000 effective independent cores by using fpgas (field programmable gate arrays).
a multicore processor is a single integrated circuit (a.k.a., chip multiprocessor orcmp) that contains
multiple core processing units, more commonly known as cores. there are many different multicore
processor architectures, which varyin terms of number of cores. different multicore processors often
have different numbers of cores. for example, a quad-core processor has four cores. thenumber of
cores is usually a power of two.

305
Number Of Core Types.
homogeneous (symmetric) cores. all of the cores in a homogeneousmulticore processor are of the
same type; typically, the core processing units are general-purpose central processing units that run
a single multicore operating system. heterogeneous (asymmetric) cores. heterogeneous multicore
processors have a mix of core types that often-run different operating systems and include graphics
processing units. number and level of caches. multicore processors vary in terms of their instruction
and data caches, which are relatively small and fast pools of local memory. How cores are
interconnected. multicore processors also vary in terms oftheir bus architectures.
isolation. the amount, typically minimal, of in-chip support for the spatialand temporal isolation of
cores:

Physical Isolation ensures that different cores cannot access the same physical hardware (e.g.,
memory locations such as caches andram).temporal isolation ensures that the execution of software
on one core does not impact the temporal behavior of software runningon another core.

Homogeneous Multicore Processor


the following figure notionally shows the architecture of a system in which 14 software applications
are allocated by a single host operating system to the coresin a homogeneous quad-core processor.
in this architecture, there are three levels of cache, which are progressively larger but slower: l1
(consisting of an instruction cache and a data cache), l2, and l3. note that the l1 and l2 caches are
local to a single core, whereas l3 is shared among all four cores.

Heterogeneous Multicore Processor


306
the following figure notionally shows how these 14 applications could be allocated to four different
operating systems, which in turn are allocated to four different cores, in a heterogeneous, quad-core
processor. from left to right, the cores include a general-purpose central processing unit core running
windows; a graphical processing unit (gpu) core running graphics-intensive applications onlinux; a
digital signal processing (dsp) core running a real-time operating system (rtos); and a high-
performance core also running an rtos.

Current Trends In Multicore Processing


multicore processors are replacing traditional, single-core processors so that fewer single-core
processors are being produced and supported. consequently, single-core processors are becoming
technologically obsolete. heterogeneous multicore processors, such as computer-on-a-chip
processors, are becoming morecommon.
although multicore processors have largely saturated some application domains (e.g., cloud
computing, data warehousing, and on-line shopping), they are just starting to be used in real-time,
safety- and security-critical, cyber-physical systems. one area in which multicore processing is
becoming popular is in environments constrained by size, weight, and power, and cooling (swap-c),
in which significantly increased performance is required.

Pros Of Multicore Processing


multicore processing is typically commonplace because it offers advantages in thefollowing seven
areas:
energy efficiency. by using multicore processors, architects can decrease the number of embedded
computers. they overcome increased heat generation due to Moore’s law (i.e., smaller circuits
increase electrical resistance, which creates more heat), which in turn decreases the need forcooling.
307
the use of multicore processing reduces power consumption (lessenergy wasted as heat), which
increases battery life. True concurrency. by allocating applications to different cores, multicore
processing increases the intrinsic support for actual (as opposed to virtual)parallel processing within
individual software applications across multiple applications.
performance. multicore processing can increase performance by running multiple applications
concurrently. the decreased distance between coreson an integrated chip enables shorter resource
access latency and higher cache speeds when compared to using separate processors or computers.
however, the size of the performance increase depends on the number of cores, the level of real
concurrency in the actual software, and the use of shared resources.
isolation. multicore processors may improve (but do not guarantee) spatialand temporal isolation
(segregation) compared to single-core [Link] running on one core is less likely to
affect software on another core than if both are executing on the same single core. this decoupling
is due to both spatial isolation (of data in core-specific cashes) and temporal isolation, because
threads on one core are not delayed by threads on another core. multicore processing may also
improve robustness by localizing the impact of defects to single core. this increased isolation is
particularly important in the independent execution of mixed-criticality applications (mission-critical,
safety critical, and security-critical).

reliability and robustness. allocating software to multiple cores increasesreliability and robustness
(i.e., fault and failure tolerance) by limiting fault and/or failure propagation from software on one core
to software on another. the allocation of software to multiple cores also supports failure tolerance
by supporting failover from one core to another (and subsequentrecovery).
obsolescence avoidance. the use of multicore processors enables architects to avoid technological
obsolescence and improve maintainability. chip manufacturers are applying the latest technical
advances to their multicore chips. as the number of cores continues to increase, it becomes
increasingly hard to obtain single-core chips.
hardware costs. by using multicore processors, architects can produce systems with fewer
computers and processors.

Cons Of Multicore Processing


although there are many advantages to moving to multicore processors, architects must address
disadvantages and associated risks in the following sixareas:
shared resources. cores on the same processor share both processor- internal resources (l3 cache,
system bus, memory controller, i/o controllers, and interconnects) and processor-external resources
(main memory, I/o devices, and networks). these shared resources imply (1) theexistence of single
points of failure, (2) two applications running on
the same core can interfere with each other, and (3) software running onone core can impact software
running on another core (i.e., interference can violate spatial and temporal isolation because
multicore support for isolation is limited). the diagram below uses the color red to illustrate sixshared
resources.

interference. interference occurs when software executing on one core impacts the behavior of
software executing on other cores in the same processor. this interference includes failures of both
spatial isolation (due to shared memory access) and failure of temporal isolation (due to interference
delays and/or penalties). temporal isolation is a bigger problem than spatial isolation since multicore
processors may have special hardware that can be used to enforce spatial isolation (to prevent
software running on different cores from accessing the same processor-internal memory). the
number of interference paths increases rapidly with the number of cores and the exhaustive analysis
308
of all interference paths is often impossible. the impracticality of exhaustive analysis necessitates
the selection of representative interference paths when analyzing isolation. the following diagram
uses the color red to illustrate three possible interference paths between pairs of applications
involving six shared resources.

Concurrency defects. cores execute concurrently, creating the potential for concurrency defects
including deadlock, live lock, starvation, suspension, (data) race conditions, priority inversion, order
violations, and atomicity violations. note that these are essentially the same types of concurrency
defects that can occur when software is allocated to multiple threads on a single core.

Non-determinism. multicore processing increases non-determinism. for example, i/o interrupts have
top-level hardware priority (also a problem with single core processors). multicore processing is also
subject to lock trashing, which stems from excessive lock conflicts due to simultaneous access of
kernel services by different cores (resulting in decreased concurrency and performance). the
resulting non-deterministic behaviorcan be unpredictable, can cause related faults and failures, and
can maketesting more difficult (e.g., running the same test multiple times may notyield the same test
result).

Analysis difficulty. the real concurrency due to multicore processing requires different memory
consistency models than virtual interleaved concurrency. it also breaks traditional analysis
approaches for work on single core processors. the analysis of maximum time limits is harder and
may be overly conservative. although interference analysis becomes morecomplex as the number of
cores-per-processor increases, overly restricting the core number may not provide adequate
performance.

Accreditation and certification. interference between cores can cause missed deadlines and
excessive jitter, which in turn can cause faults (hazards) and failures (accidents). verifying a multicore

309
system requires proper real-time scheduling and timing analysis and/or specialized performance
testing. moving from a single core to a multicore architecture may require recertification.
unfortunately, current safety policy guidelines are based on single-core architectures and must be
updated based on the recommendations that will be listed in the final blog entry in this series.

the division algorithm for all positive integers a and b,where b ≠ 0,


𝑎 = 𝑞𝑏 + 𝑟
𝑎 𝑟
= 𝑞 +
𝑏 𝑏

a divided by 𝑏 gives a quotient and remainder.


The quotient 𝑞 and remainder 𝑟 are integers

example
𝑎 = 𝑞𝑏 + 𝑟
158 = 9 × 17 + 5
Convention uses a dot 𝒕 to show multiplication instead of a 𝑥
This is fine, since we are purely dealing with integers. No decimals are involved

158 = 9 ⋅ 17 + 5

so 𝑞 = 9 and 𝑟 = 5

use the division algorithm to find the quotient and remainder whena = 158 and b = 17

The Euclidean algorithm this uses the division algorithm to: -


find the greatest common divisor (gcd)[ aka highest common factor (hcf)]
The greatest common denominator (gcd) of two integers 𝑎 and 𝑏, at least one of which ≠ 0
is found when the remainder in the division algorithm is zero

𝑎 = 𝑞𝑏 + 𝑟

so 𝑎 = 𝑞𝑏 + 0

find the lowest common multiple (lcm) of two numbers


𝑎𝑏
Icm =
(𝑎, 𝑏)

reduce a fraction to its simplest form(just divide top and bottom by the gcd) find relatively prime
(coprime) integersthese occur when the gcd (a, b) = 1
solve equations of the formgcd (a, b) =ax +by
If 𝑎𝑥 + 𝑏𝑦 = 𝑑 where gcd (𝑎, 𝑏) = 𝑑 then

𝑏
𝑥𝑛 = 𝑥0 + ( ) 𝑚
𝑑
𝑎
𝑦𝑛 = 𝑦0 + ( ) 𝑚
𝑑
describes the general solution 𝑥𝑛 , 𝑦𝑛 when the particular solutions 𝑥0 , 𝑦0 are known

310
example
find the gcd of 135 and 1780

𝑎 = 𝑞𝑏 + 𝑟
1780 = 13 ⋅ 135 + 25
Now continue, replacing
𝑎 with 𝑏 and 𝑏 with 𝑟
135 = 5 ⋅ 25 + 10
25 = 2 ⋅ 10 + 5
10 = 2 ⋅ 5 + 0
gcd (135,1780) = 5

example
find the lcm of 135 and 1780
𝑎𝑏
1 cm =
(𝑎, 𝑏)
135 ⋅ 1780
=
5
240300
=
5
= 48060
Icm(135,1780) = 48060

example
reduce the fraction 1480/128600 to its simplest form
𝑎 = 𝑞𝑏 + 𝑟
128600 = 86 ⋅ 1480 + 1320
1480 = 1 ⋅ 1320 + 160
1320 = 8 ⋅ 160 + 40
160 = 4 ⋅ 40 + 0
gcd (128600,1480) = 40

Divide top and bottom by the gcd


1480 ÷ 40 37
=
128600 ÷ 40 3215
𝑎 = 𝑞𝑏 + 𝑟
111 = 3 ⋅ 34 + 9
34 = 3 ∙ 9 + 7
9= 1∙7+2
7= 3∙2+1
2= 2∙1+0
gcd (34,111) = 1
∴ 34 and 111 are coprime. show that 34 and 111 are co-prime
1. example
solve 34𝑥 + 111𝑦 = 1, where 𝑥 and 𝑦 are integers

311
𝑎 = 𝑞𝑏 + 𝑟
111 = 3 ∙ 34 +
34 = 3 ⋅ 9 + 7
9=1⋅7+2
7=3⋅2+1
2=2⋅1+0
change subject to 𝑟 and substitute
Start with the second last equation
and work backwards
=7−3∙2
= 7 − 3 ∙ (9 − 1 ∙ 7)
=7−3∙9+3∙7 =4⋅7−3∙9
= 4 ∙ (34 − 3 ⋅ 9) − 3 ⋅ 9 = 4 ∙ 34 − 15 ∙
= 4 ⋅ 34 − 15 ⋅ (111 − 3 ⋅ 34)
= 49 ⋅ 34 − 15 ⋅ 111
compare to original
34𝑥 + 111𝑦 = 1
⇒ 𝑥 = 49 𝑦 = −15
2. Diophantine equations
these are of the form
𝑎𝑥 𝑛 + 𝑏𝑦 𝑛 = 𝑐 𝑛
Where all numbers are integers 𝑎𝑥 + 𝑏𝑦 = 𝑐
has a solution only if the gcd is a factor of 𝑐

To solve
1 Find gcd (𝑎, 𝑏) = 𝑑then 𝑑 ∣ 𝑐 so 𝑐 = 𝑑𝑛 for some integer 𝑛.
Express 𝑐 in terms of 𝑑
2 Express 𝑑 in the form 𝑑 = 𝑎𝑠 + 𝑏𝑡 for some integers 𝑠 and 𝑡
3 Multiply by 𝑛 to get 𝑥 = 𝑠𝑛 𝑦 = 𝑡𝑛

example
solve the linear Diophantine equation69x +27𝑦 = 1332, if it exists
69𝑥 + 27𝑦 = 1332
Find the gcd of 69 and 27
69 = 2 ⋅ 27 + 15
27 = 1 ∙ 15 + 12
15 = 1 ⋅ 12 + 3
12 = 4 ⋅ 3 + 0
gcd (69,27) = 3
since 3 ∣ 1332, a solution exists
𝑐 = 𝑑𝑛 ⇒ 1332 = 3𝑛 ⇒ 𝑛 = 444

312
3 = 15 − 1 ⋅ 12
= 15 − 1 ⋅ (27 − 1 ⋅ 15) = 15 − 1 ⋅ 27 + 1 ⋅ 15 = 2 ⋅ 15 − 1 ⋅ 27
= 2 ⋅ (69 − 2 ⋅ 27) − 1 ⋅ 27
= 2 ⋅ 69 − 4 ⋅ 27 − 1 ⋅ 27
= 2 ⋅ 69 − 5 ⋅ 27
𝑑 = 69𝑠 + 27𝑡
⇒ 𝑠 = 2 𝑡 = −5
Multiply through by 𝒏
𝑥 = 2𝑛 𝑦 = −5𝑛
= 2 ⋅ 444 = −5 ⋅ 444
One solution is 𝑥 = 888, 𝑦 = −2220
𝑏 27
𝑥𝑛 = 𝑥0 + ( ) 𝑚 = 888 + ( ) 𝑚 = 888 + 9𝑚
𝑑 3
𝑎
𝑦𝑛 = 𝑦0 + ( ) 𝑚 = −2220 + 13𝑚
𝑑
for some multiple m

example
find the positive integer values of 𝑥 and 𝑦 that satisfy 69𝑥 + 27𝑦 = 1332 From above, a solution
exists
69𝑥 + 27𝑦 = 1332
gcd (69,27) = 3
23𝑥 + 9𝑦 = 444
solving for 𝒙
444 − 9𝑦
𝑥 =
23
7 9𝑦
= 19 −
23 23
9𝑦 7
= 19 − +
23 23
9𝑦 − 7
= 19 −
23
9𝑦 − 7
∴ ≤ 18
23
23 ∙ 18 + 7
⇒𝑦≤
9
421 7
⇒𝑦≤ ≤ 46
9 9
0 < 𝑦 ≤ 46, Δ𝑦 = 9
Lowest possible is
𝑦 = 11
444 − 99
thus 𝑥 = = 15
23
Alternatively, solving for 𝑦

313
444 − 23𝑥
𝑦 =
9
23𝑥 − 3
= 49 −
9
23𝑥 − 3
∴ ≤ 48
9
48 ∙ 9 + 3
⇒ 𝑥≤
23
435 21
⇒ 𝑥≤ ≤ 18
23 23
0 < 𝑥 ≤ 18, Δ𝑥 = 23
Lowest possible answers
𝑥 = 15
23 ⋅ 15 − 3
𝑦 = 49 −
9
= 49 − 38
𝑦 = 11
check
69𝑥 + 17𝑦 = 69 ⋅ 15 + 17 ⋅ 11 = 1035 + 187 = 1332
3. pythagorean triples 𝑎𝑥 2 + 𝑏𝑦 2 = 𝑐 2 to find these, pick an odd positive number
divide its square into two integers which areas close to being equal as is possible
e.g., 72 = 49 = 24 + 25
gives triples 7,24,25
72 + 242 = 252
alternatively, pick any even integer ntriples are 2𝑛, 𝑛2 − 1 and 𝑛2 + 1
e.g., picking 8 gives 16,63 and 65 indeed 162 + 632 = 652
Fermat’s lastliveorem
4. 𝑎𝑥 𝑛 + 𝑏𝑦 𝑛 = 𝑐 𝑛 , 𝑛 > 2 cannot be solved with all as integers 36 = 100100 in base 2
number bases
to convert a number into a different bases,usethe division algorithm n taking b as therequired base.

example
convert 36 into binary 36 = 1001002
𝑎 = 𝑞𝑏 + 𝑟
36 = 18 ⋅ 2 + 0
Now continue, replacing a with 𝑞
18 = 9 ⋅ 2 + 0
9= 4⋅2+1
4= 2⋅2+0
2= 1⋅2+0
1= 0⋅2+1
36 = 24 in base 16

example

314
𝑎 = 𝑞𝑏 + 𝑟
503793 = 31487 ⋅ 16 + 1
31487 = 1967 ⋅ 16 + 15
1967 = 122 ⋅ 16 + 15
122 = 7 ⋅ 16 + 10
convert 36 into hexadecimal
7 = 0 ⋅ 16 + 7
503793 = 7AFF1 in base 16
503793dec = 7𝐴𝐹𝐹1hex

example
convert 503703 into hexadecimal
(Remember that hexadecimal uses letters) computer system architecture)

1. Any signed negative binary numberis recognized by its _


a) MSB
b) LSB
c) Byte
d) Nibble

Answer: a
Explanation: Any negative number isrecognized by its MSB (Most Significant Bit).
If it’s 1, then it’s negative, else if it’s0, then positive.

2. The parameter through which 16


c) Adding
d) Subtracting

Answer: b
Explanation: On multiplying the decimal number continuously by 2, the binary equivalent is
obtained bythe collection of the integer part. However, if it’s an integer, then itsbinary equivalent is
determined bydividing the number by 2 and collecting the remainders.

3. The representation of octalnumber (532.2)8 in decimal is distinct values can be represented is


known as
a. Bit
b. Byte
c. Word
d. Nibble

Answer: c
Explanation: It can be represented upto 16 different values with the help ofa Word. Nibble is a
combination of four bits and Byte is a combination of8 bits. It is “word” which is said to be a
collection of 16-bits on most of the systems.

315
3. If the decimal number is a fractionthen its binary equivalent is obtainedby the number
continuously by 2.
a) Dividing
b) Multiplying
a) (346.25)10
b) (532.864)10
c) (340.67)10
d) (531.668)10

Answer: a
Explanation: Octal to Decimal conversion is obtained by multiplying8 to the power of base index
along with the value at that index position. (532.2)8 = 5 * 82 + 3 * 81 + 2 * 80 + 2 *
8-1 = (346.25)10

4. Which of the following is not a datatype?


a) Symbolic Data
b) Alphanumeric Data
c) Numeric Data
d) Alphabetic Data

Answer: a
Explanation: Data types are of three basic types: Numeric, Alphabetic andAlphanumeric. Numeric
Data consistsof only numbers.
Alphabetic Data consists of only letters and a blank character andalphanumeric data consists of
symbols.

5. is the raw material used as input and is the processed data obtained as output ofdata
processing.
a) Data, Instructions
b) Instructions, Program
c) Data, Program
d) Program, Code
has no I.Q. of its own. It does onlywhat it is programmed to do. It cannot take decisions of its own.
A computer is diligent because it canwork continuously for hours withoutgetting any errors or
without getting grumbled. The accuracy of a computer is consistently high, and its level of
accuracy depends on its design. A computer can perform any task if, itcan be broken down into a
series oflogical steps. Therefore, a computeris versatile.

8. Fill in the blank in the diagram.

Answer: a
Explanation: Data can be assumed as a raw material which, in turns after processing gives the
desired output inthe form of instructions. Further, a set of ordered and meaningful instructions is
known as a program.
316
7. Which of the following is not acharacteristic of a computer?
a) Diligence
b) I.Q.
c) Accuracy
d) Versatility
Answer: b
Explanation: The Computer system
a) Input Unit
b) Memory Unit
c) Control Unit
d) I/O Unit

Answer: c
Explanation: The control unit manages and coordinates the operations of a computer system. The
ALU is responsible for performingall the arithmetic and bitwise operations . Therefore, both these
units combine to form the brain ofthe computer ,which is the centralprocessing unit.

9. The part of a processor whichcontains hardware necessary to address for the read and write
operations.

11. If the control signals are generated by combinational logic, then they are generated by a type of
perform all the operations required controlled unit by a computer
a) Data path
b) Controller
c) Registers
d) Cache
Answer: a
Explanation: A processor is a part of the computer which does all the datamanipulation and
decision making. Aprocessor comprises of:
A data path which contains the hardware necessary to perform all the operations. A controller tells
thedata path what needs to be done.
The registers act as intermediatestorage for the data.

10. What does MAR stand for?


a) Main Address Register
b) Memory Access Register
c) Main Accessible Register
d) Memory Address Register

Answer: d
Explanation: MAR is a type of registerwhich is responsible for the fetch operation. MAR is
connected to the address bus, and it specifies the
a) Micro programmed
317
b) Software
c) Logic
d) Hardwired

Answer: d
Explanation: The main task of a control unit is to generate control signals. There are two main
types ofcontrol units:
A hardwired control unit generatescontrol signals by using combinational logic circuits and the
Micro programmed control unit generates control signals by using some software’s.

12. Which is the simplest method ofimplementing hardwired control unit?


a) State Table Method
b) Delay Element Method
c) Sequence Counter Method
d) Using Circuits

Answer: a
Explanation: There are 3 ways of implementing hardwired control unit:A state table is the simplest
method in which a number of circuits are designed based on the cells in thetable.
A delay element method consists of aflowchart drawn for the circuit. A D- flip flop is used as a
delay element. A sequence counter method used k- modulo counter as a replacement fork delay
elements.

13. A set of microinstructions for asingle machine instruction is called


a) Program
b) Command
c) Micro program
d) Micro command

Answer: c
Explanation: For every micro- operation, a set of microinstructions are written which indicate the
controlsignals to be activated. A set of microinstructions is a micro [Link] address of the
next microinstruction is given by a Micro- program counter.

14. Micro-program consists of a set ofmicroinstructions which are strings of0s and 1s.
a) True
b) False

Answer: a
Explanation: The computer
understands only binary language. So, the micro-program should have instructions which
are in the form of0s and 1s. Each output line of the micro-program corresponds to one control
signal.

318
15. A decoder is required in case of a _________
a) Vertical Microinstruction
b) Horizontal Microinstruction
c) Multilevel Microinstruction
d) All types of microinstructions

Answer: a
Explanation: There are two types ofmicroinstructions: Horizontal and Vertical.
In a horizontal microinstruction, eachbit represents a signal to be activatedwhereas, in case of
vertical microinstruction bits are decoded and, the decoder then produces signals.

16. In Boolean algebra, the OR operation is performed by whichproperties?


a) Associative properties
b) Commutative properties
c) Distributive properties
d) All of the Mentioned
Answer: d
Explanation: The expression for Associative property is given by

19. The involution of A is equal to__________ A+(B+C) = (A+B) +C & A*(B*C) =(A*B) *C.
The expression for Commutative property is given by A+B = B+A & A*B= B*A.
The expression for Distributive property is given by A+BC=(A+B) (A+C)& A(B+C) = AB+AC.

17. The expression for Absorption lawis given by


a) A + AB = A
b) A + AB = B
c) AB + AA’ = A
d) A + B = B + A
Answer: a
Explanation: The expression for Absorption Law is given by: A+AB = [Link]: A + AB = A(1+B) = A
(Since 1 + B = 1 as pier 1’s Property).

18. According to boolean law: A + 1 =?


a) 1
b) A
c) 0
d) A’
Answer: a
319
Explanation: A + 1 = 1, as per 1’sProperty.
a) A
b) A’
c) 1
d) 0
Answer: a
Explanation: The involution of A means double inversion of A (i.e., A”)and is equal to A.
Proof: ((A)’)’ = A

20. A (A + B) = ?
a) AB
b) 1
c) (1 + AB)
d) A
Answer: d
Explanation: A (A + B) = AA + AB (By Distributive Property) = A + AB (A.A =A By Commutative
Property) = A (1 + B) = A*1 (1 + B = 1 by 1’s Property) = A.

21. DE Morgan’s theorem states that


a) (AB)’ = A’ + B’
b) (A + B)’ = A’ * B
c) A’ + B’ = A’B’
d) (AB)’ = A’ + B

Answer: a
Explanation: The DE Morgan’s law states that (AB)’ = A’ + B’ & (A + B)’ =A’ * B’, as per the Dual
Property.

22. (A + B) (A’ * B’) =?


a) 1
b) 0
c) AB
d) AB’
Answer: b
Explanation: The DE Morgan’s law states that (AB)’ = A’ + B’ & (A + B)’ =A’ * B’, as per the Dual
Property.

23. Complement of the expressionA’B + CD’ is


a) (A’ + B)(C’ + D)

320
b) (A + B’)(C’ + D)
c) (A’ + B) (C’ + D)
d) (A + B’) (C + D’)

Answer: b
Explanation: (A’B + CD’)’ = (A’B)'(CD’)’
(By DeMorgan’s Theorem) = (A” + B’)(C’ + D”) (By DeMorgan’s Theorem) = (A + B’)(C’ + D).

24. Simplify Y = AB’ + (A’ + B) C.


a) AB’ + C
b) AB + AC
c) A’B + AC’
d) AB + A
Answer: a
Explanation: Y = AB’ + (A’ + B)C = AB’+ (AB’)’C = (AB’ + C)( AB’ + AB’) = (AB’ + C).1 = (AB’ + C).

25. The boolean function A + BC is areduced form of


a) AB + BC
b) (A + B)(A + C)
c) A’B + AB’C
d) (A + C)B
Answer: b
Explanation: (A + B)(A + C) = AA + AC+ AB + BC = A + AC + AB + BC (By Commutative Property) =
A(1 + C + B)+ BC = A + BC (1 + B + C =1 By 1’s Property).

26. What is an ambiguous conditionin a NAND based S’-R’ latch?


a) S’=0, R’=1
b) S’=1, R’=0
c) S’=1, R’=1
d) S’=0, R’=0

Answer: d
Explanation: In a NAND based S-R latch, If S’=0 & R’=0 then both the outputs (i.e. Q & Q’) goes HIGH
and this condition is called as ambiguous/forbidden state. This state is also known as an Invalid
state as the system goes into anunexpected situation.

27. In a NAND based S’-R’ latch, ifS’=1 & R’=1 then the state of the latch is
a) No change
b) Set
c) Reset
d) Forbidden
321
Answer: a
Explanation: In a NAND based S’-R, latch if S’=1 & R’=1 then there is no any change in the state. It
remains inits prior state. This state is used for the storage of data.

28. A NAND based S’-R’ latch can beconverted into S-R latch by placing
a) A D latch at each of its input
b) An inverter at each of its input
c) It can never be converted
d) Both a D latch and an inverter at itsinput
Answer: d
Explanation: A NAND based S’-R’ latch can be converted into S-R latchby placing either a D latch or
an inverter at its input as its operationswill be complementary.

29. One major difference between aNAND based S’-R’ latch & a NOR based S-R latch is
a) The inputs of NOR latch are 0 but 1for NAND latch
b) The inputs of NOR latch are 1 but 0for NAND latch
c) The output of NAND latch becomesset if S’=0 & R’=1 and vice versa for NOR latch
d) The output of NOR latch is 1 but 0for NAND latch
Answer: a
Explanation: Due to inverted input ofNAND based S’-R’ latch, the inputs of NOR latch are 0 but 1 for
NAND latch.

30. The characteristic equation of S-Rlatch is


a) Q(n+1) = (S + Q(n)) R’
b) Q(n+1) = SR + Q(n)R
c) Q(n+1) = S’R + Q(n)R
d) Q(n+1) = S’R + Q'(n)R

Answer: a
Explanation: A characteristic equationis needed when a specific gate requires a specific output in
order to satisfy the truth table. The characteristic equation of S-R latch is Q(n+1) = (S + Q(n))R’.

31. The difference between a flip-flop& latch is


a) Both are same
b) Flip-flops consist of an extra output
c) Latches has one input but flip-flophas two
d) Latch has two inputs but flip-flophas one
Answer: c
322
Explanation: Flip-flop is a modified version of latch. To determine the changes in states, an
additional control input is provided to the latch.

32. How many types of flip-flops are?


a) 2
b) 3
c) 4
d) 5
Answer: c
Explanation: There are 4 types of flip-flops, viz., S-R, J-K, D, and T. D flip- flop is an advanced
version of S-R flip-flop, while T flip-flop is an advanced version of J-K flip-flop.

33. The S-R flip flop consist of

a) 4 AND gates
b) Two additional AND gates
c) An additional clock input
d) 3 AND gates
Answer: b
Explanation: The S-R flip flop consistof two additional AND gates at the Sand R inputs of S-R latch.

34. What is one disadvantage of an S-R flip-flop?


a) It has no Enable input
b) It has a RACE condition
c) It has no clock input
d) Invalid State
Answer: d
Explanation: The main drawback of s-r flip flop is invalid output when boththe inputs are high, which
is referredto as Invalid State.

35. One example of the use of an S-Rflip-flop is as


a) Racer
b) Stable oscillator
c) Binary storage register
d) Transition pulse generator
Answer: c
Explanation: S-R refers to [Link], it is used to store two values 0 and 1. Hence, it is referred to
as binary storage element. It functionsas memory storage during the No Change State.

323
36. When is a flip-flop said to betransparent?
a) When the Q output is opposite theinput
b) When the Q output follows theinput
c) When you can see through the ICpackaging
d) When the Q output is complementary of the input
Answer: b
Explanation: Flip-flop have the property of responding immediatelyto the changes in its inputs. This
property is called transparency.

37. On a positive edge-triggered S-R flip-flop, the outputs reflect the inputcondition when
a) The clock pulse is LOW
b) The clock pulse is HIGH
c) The clock pulse transitions fromLOW to HIGH
d) The clock pulse transitions fromHIGH to LOW
Answer: c
Explanation: Edge triggered device will follow when there is transition. Itis a positive edge triggered
when transition takes place from low to high, while, it is negative edge triggered when the transition
takesplace from high to low.

38. A group of bits used to representa symbol is called a


a) byte
b) memory
c) nibble
d) code
Answer: a
Explanation: In binary coding, every symbol that appears in data is represented by a group of bits,
whichare called bytes. Computer codes usebinary coding schemes.

39. BCD uses 6 bits to represent asymbol.


a) True
b) False
Answer: a
Explanation: In a Binary Coded Decimal format, 64 characters i.e., 26different characters can be
represented. It is one of the early computer codes.

40. Which of the following is not atype of computer code?


a) EBCDIC
324
b) BCD
c) ASCII
d) EDIC
Answer: d
Explanation: There is no coding scheme like EDIC. EBCDIC stands forExtended Binary Coded
Decimal Interchange Code. BCD stands for Binary Coded Decimal. ASCII stands for American
Standard Code for information interchange.

41. The BCD representation of(34)10 is


a) 6
b) 7
c) 8
d) 5
Answer: b
Explanation: BCD numbers arerepresented as:

34 = (0011 0100) [Link] digit is individually taken and anequivalent standard 4 bit term is
written for the respective digit.

42. Perform BCD addition of (23)BCD +(20)BCD .


a) 00110100
b) 01000011
c) 10011
d) 11100
Answer: b
Explanation: To add any two BCDnumbers: Simply perform the addition:23+20=43. Then, write the
equivalent BCDnumber = (0100 0011) BCD.

43. The weights used in Binary codeddecimal code are:


a) 4,2,1
b) 8,4,2,1
c) 6,4,2,1
d) 2,1

Answer: b
Explanation: BCD is a weighted code and it uses the weights 8,4,2,1 respectively. It is often called
the 8421 code. Since, it uses 4 bits for therepresentation therefore the weightsare assigned as : 23
= 8, 22 = 4, 21 = 2,
20 = 1.

325
44. Write the decimal equivalent for(110001)BCD.
a) 31
b) 13
c) C1
d) 1C
Answer: a
Explanation: To obtain the decimalequivalent : We start from the rightmost bit andmake groups of
4, then write the decimal equivalent accordingly.
0011 0001 = (31)10.

45. The 9’s complement of 45 is


a) 45
b) 54
c) 64
d) 46
Answer: b
Explanation: The 9’s complement of anumber is obtained by subtracting each digit from 9. Here,
99-45=54. Therefore, the 9’s complement is 54.

46. The 10’s complement of 455 is


a) 543
b) 544
c) 545
d) 546

Answer: c
Explanation: To obtain the 10’s complement, we first obtain the 9’scomplement and then add 1 to
it. 999-455=544 (9’s) 544+1=545(10’s).

47. The Excess-3 representation of(0100) BCD is


a) 0110
b) 1110
c) 0111
d) 1100

Answer: c
Explanation: The excess-3 code isobtained by adding 3 to the BCD code.
Here, 0100+0011=0111. Also, 4+3=7.

48. What is the hold condition of aflip-flop?


a) Both S and R inputs activated
326
b) No active S or R input
c) Only S is active
d) Only R is active
Answer: b
Explanation: The hold condition in a flip-flop is obtained when both of theinputs are LOW. It is the
No Change State or Memory Storage state if a flip-flop.

49. If an active-HIGH S-R latch has a 0on the S input and a 1 on the R input and then the R input
goes to 0, the latch will be
a) SET
b) RESET
c) Clear
d) Invalid

Answer: b
Explanation: If S=0, R=1, the flip flopis at reset condition. Then at S=0, R=0, there is no change. So,
it remains in reset. If S=1, R=0, the flipflop is at the set condition.

50. The circuit that is primarily responsible for certain flip-flops to bedesignated as edge-triggered
is the
a) Edge-detection circuit
b) NOR latch
c) NAND latch
d) Pulse-steering circuit
Answer: a
Explanation: The circuit that is primarily responsible for certain flip-flops to be designated as edge-
triggered is the edge-detection circuit.

51. The output of a logic gate is 1 when all the input are at logic 0 asshown below:

0 0 1

0 1 0

1 0 0

327
1 1 0

INPUT OUTPUT

A B C

0 0 1

0 1 0

1 0 0

The 1 1 1
gate is
either
a) A NAND or an EX-OR
b) An OR an EX-NOR
c) An AND or an EX-OR
d) A NOR or an EX-NOR
Answer: d
Explanation: The output of a logic gate is 1 when all inputs are at logic
0. The gate is NOR. The output of a logic gate is 1 when all inputs are at logic 0 or all inputs are at
logic 1, thenit is EX-NOR. (The truth tables for NOR and EX-NOR Gates are shown in above table).

52. The code where all successive numbers differ from their precedingnumber by single bit is
a) Alphanumeric Code
b) BCD
c) Excess 3
d) Gray
Answer: d
Explanation: The code where all successive numbers differ from their preceding number by single
bit is graycode. It is an unweighted code. The most important characteristic of this code is that
only a single bit change occurs when going from one code number to next. BCD Code is one in
which decimal digits are represented by a group of 4-bits each, whereas, inExcess-3 Code, the
328
decimal numbers are incremented by 3 and then written in their BCD format.

53. The following switching functionsare to be implemented using a


decoder:
f1 = ∑m(1, 2, 4, 8, 10, 14) f2 = ∑m(2,
5, 9, 11) f3 = ∑m(2, 4, 5, 6, 7)
The minimum configuration ofdecoder will be
a) 2 to 4 lines
b) 3 to 8 lines
c) 4 to 16 lines
d) 5 to 32 lines
Answer: c
Explanation: 4-to-16-line decoder asthe midterms are ranging from 1 to14.

54. How many AND gates are required to realize Y = CD + EF + G?


a) 4
b) 5
c) 3
d) 2
Answer: d
Explanation: To realize Y = CD + EF +G, two AND gates are required and two OR gates are required.

55. The NOR gate output will be highif the two inputs are
a) 00
b) 01
c) 10
d) 11

Answer: a
Explanation: In 01, 10 or 11 output islow if any of the I/P is high. So, the correct option will be 00.

56. How many two-input AND ORgates are required to realize Y = CD+EF+G?
a) 2, 2
b) 2, 3
c) 3, 3
d) 3, 2

Answer: a
Explanation: Y = CD + EF + G
The number of two input AND gate =2
329
The number of two input OR gate = 2.

57. A universal logic gate is one whichcan be used to generate any logic function. Which of the
following is a universal logic gate?
a) OR
b) AND
c) XOR
d) NAND
Answer: d
Explanation: An Universal Logic Gateis one which can generate any logic function and also the
three basic gates: AND, OR and NOT. Thus, NORand NAND can generate any logic
function and are thus Universal LogicGates.

58. A full adder logic circuit will have

a) Two inputs and one output


b) Three inputs and three outputs
c) Two inputs and two outputs
d) Three inputs and two outputs
Answer: d
Explanation: A full adder circuit will add two bits and it will also account the carry input generated
in the previous stage. Thus, three inputs andtwo outputs (Sum and Carry) are there. In case of half
adder circuit, there are only two inputs bits and two outputs (SUM and CARRY).

59. How many two input AND gates and two input OR gates are requiredto realize Y = BD + CE +
AB?
a) 3, 2
b) 4, 2
c) 1, 1
d) 2, 3

Answer: a
Explanation: There are three product terms. So, three AND gates of two inputs are required. As only
two inputOR gates are available, so two OR gates are required to get the logicalsum of three
product terms.

60. Which of following are known asuniversal gates?


a) NAND & NOR
b) AND & OR
c) XOR & OR
330
d) EX-NOR & XOR
Answer: a
Explanation: The NAND & NOR gates are known as universal gates becauseany digital circuit can
be realized completely by using either of these two gates, and also, they can generatethe 3 basic
gates AND, OR and NOT.

61. The gates required to build a halfadder are


a) EX-OR gate and NOR gate
b) EX-OR gate and OR gate
c) EX-OR gate and AND gate
d) EX-NOR gate and AND gate
Answer: c
Explanation: The gates required to build a half adder are EX-OR gate andAND gate. EX-OR outputs
the SUM ofthe two input bits whereas AND outputs the CARRY of the two input bits.

62. The CISC stands for


a) Computer Instruction SetCompliment
b) Complete Instruction SetCompliment
c) Computer Indexed SetComponents
d) Complex Instruction set computer
Answer: d
Explanation: CISC is a computer architecture where in the processor performs more complex
operations inone step.

63. The computer architecture aimedat reducing the time of execution of instructions is
a) CISC
b) RISC
c) ISA
d) ANNA
Answer: b
Explanation: The RISC stands for Reduced Instruction Set Computer.

3. The Sun micro systems processorsusually follow architecture.


a) CISC
b) ISA
c) ULTRA SPARC
d) RISC
331
Answer: d
Explanation: The Risk machine aims at reducing the instruction set of thecomputer.

64. The RISC processor has a morecomplicated design than CISC.


a) True
b) False
Answer: b
Explanation: The RISC processor design is simpler than CISC andit consists of fewer transistors.

65. The iconic feature of the RISCmachine among the following is


a) Reduced number of addressingmodes
b) Increased memory size
c) Having a branch delay slot
d) All of the mentioned
Answer: c
Explanation: A branch delay slot is aninstruction space immediately following a jump or branch.

66. Both the CISC and RISC architectures have been developed toreduce the
a) Cost
b) Time delay
c) Semantic gap
d) All of the mentioned
Answer: c
Explanation: The semantic gap is thegap between the high-level languageand the low level language.

67. Out of the following which is nota CISC machine.


a) IBM 370/168
b) VAX 11/780
c) Intel 80486
d) Motorola A567
Answer: d Explanation: None.

68. Pipelining is a unique feature of


a) RISC
b) CISC
c) ISA
d) IANA

332
Answer: a
Explanation: The RISC machinearchitecture was the first to implement pipe-lining.

69. In CISC architecture most of thecomplex instructions are stored in


a) Register
b) Diodes
c) CMOS
d) Transistors
Answer: d
Explanation: In CISC architecture more emphasis is given on the instruction set and the
instructionstake over a cycle to complete.

70. Which of the architecture ispower efficient?


a) CISC
b) RISC
c) ISA
d) IANA
Answer: b
Explanation: Hence the RISC architecture is followed in the designof mobile devices.

71. A task carried out by the OS andhardware to accommodate multipleprocesses in main memory.
a) Memory control
b) Memory management
c) Memory sharing
d) Memory usage
Answer: b
Explanation: Memory management iscarried out by the OS and hardware to accommodate multiple
processes in main memory.
72. An HTML file is a text file containing small markup tags.
a) True
b) False
Answer: a
Explanation: The statement is true. HTML stands for Hyper Text MarkupLanguage. It is a text file
containing small markup tags.

73. Secondary memory is the long-term store for programs and data while main memory holds
program and data currently in use. What kindof an organization is this?
a) Physical
333
b) Logical
c) Structural
d) Simple
Answer: a
Explanation: The secondary memoryis the long term store for programs and data while main
memory holds program and data currently in use.
This is a physical organization.

74. Memory organization in which users write programs in modules withdifferent characteristics.
a) Physical
b) Logical
c) Structural
d) Simple
Answer: b
Explanation: The answer is Logical. Tohandle user programs properly, the operating system and
the hardware should support a basic form of module to provide protection and sharing.

75. An executing process must be loaded entirely in main memory. What kind of a memory
organizationis this?
a) Physical
b) Logical
c) Structural
d) Simple
Answer: d
Explanation: This is simple memoryorganization. An executing processmust be loaded entirely in
main memory (if overlays are not used).

76. FTP stands for.


a) File Text Protocol
b) File Transfer Protocol
c) Firm Transfer Protocol
d) File Transplant Protocol
Answer: b
Explanation: FTP stands for File
Transfer Protocol. It is a type ofinternet service use for the transmission of files.

77. A set of overlapping divisions in the main memory are called


a) Partitions
334
b) Divisions
c) Blocks
d) Modules
Answer: a
Explanation: Partition main memoryinto a set of non overlapping regionscalled partitions. Partitions
can be ofequal or unequal sizes.

78. Any program, no matter how small, occupies an entire partition.


This is called
a) fragmentation
b) prior fragmentation
c) internal fragmentation
d) external fragmentation
Answer: c
Explanation: It is called as internal fragmentation. Main memory use isinefficient. Any program, no
matterhow small, occupies an entire partition. This is called internal fragmentation.

79. _ is used to shift processes so they are contiguous, andall free memory is in one block.
a) Fragmentation
b) Compaction
c) External Fragmentation
d) Division
Answer: b
Explanation: Use compaction to shift processes so they are contiguous, andall free memory is in one
block.

80. searches for smallestblock. The fragment left behind issmall as possible.
a) best fit
b) first fit
c) next fit
d) last fit
Answer: a
Explanation: Best fit searches for thesmallest block. The fragment left behind is as small as
possible.

81. What is the static charge that canbe stored by your body as you walk across a carpet?
a) 300 volts

335
b) 3000 volts
c) 30000 volts
d) Over 30000 volts

Answer: d
Explanation: When a person walks across a carpeted or tile floor electriccharge builds up in the
body due to the friction between shoes and floor material. If the friction static is greater the
voltage potential developin the body will be greater. You start act as a capacitor. This is called
Electrostatic discharge. The potentialstatic charge that can develop from walking on tile floors is
greater than 15000 volts while carpeted floors cangenerate in excess of 30000 volts.

82. What must be done to interfaceTTL to CMOS?


a) A dropping resistor must be usedon the CMOS of 12 V supply to reduce it to 5 V for the TTL
b) As long as the CMOS supply voltage is 5 V they can be interfaced(however, the fan-out of the
TTL is limited to five CMOS gates)
c) A 5 V Zener diode must be placedacross the inputs of the TTL gates inorder to protect them
from the higher output voltages of the CMOSgates
d) A pull-up resistor must be used between the TTL output-CMOS inputnode and Vcc; the value of
RP will depend on the number of CMOS gates connected to the node

Answer: d
Explanation: To interface TTL to CMOS a pull-up resistor must be usedbetween the TTL output-
CMOS input node and Vcc. A pull-up resistor is used to avoid the floating state on the input node of
the CMOS, thus using a small amount of current. The value of RP will depend on the number of
CMOS gates connected to the node.

83. What causes low-power SchottkyTTL to use less power than the 74XX series TTL?
a) The Schottky-clamped transistor
b) A larger value resistor
c) The Schottky-clamped MOSFET
d) A small value resistor
Answer: b
Explanation: A larger value resistor causes low power low-power Schottky TTL to use less power
thanthe 74XX series TTL.

84. What are the major differences between the 5400 and 7400 series ofICs?
a) The 5400 series are military gradeand require tighter supply voltages
and temperatures
b) The 5400 series are military grade and allow for a wider range of supplyvoltages and temperatures
c) The 7400 series are an improvement over the original 5400s

336
d) The 7400 series was originally developed by Texas Instruments andthe 5400 series was brought
out by National Semiconductors after TI’s patents expired as a second supply source

Answer: b
Explanation: The 5400 series are military grade and allow for a wider range of supply voltages and
temperatures, these are the major differences between the 5400 and 7400 series of ICs. Also, the
working temperature range of 5400 series is -50 to 125C while that for 7400 is 0 to70C.

85. Which of the following statements apply to CMOS devices?


a) The devices should not be insertedinto circuits with the power on
b) All tools, test equipment and metalworkbenches should be tied to earth ground
c) The devices should be stored andshipped in antistatic tubes or
conductive foam
d) All of the Mentioned
Answer: d
Explanation: For CMOS devices, all the mentioned statements are applicable. The devices should
not beinserted into circuits with the power on. All tools, test equipment and metal workbenches
should be tied toearth ground. Also, the devices should be stored and shipped in antistatic tubes or
conductive foam.

86. Brain of computer is


a) Control unit
b) Arithmetic and Logic unit
c) Central Processing Unit
d) Memory
Answer: c
Explanation: The CPU is referred to asthe brain of a computer.
It consists of a control unit and thearithmetic and logic unit. It is responsible for performing all the
processes and operations.

87. Control Unit acts as the centralnervous system of the computer.


a) True
b) False
Answer: a
Explanation: The control unit is referred to as the central nervoussystem because it selects and
interprets the instructions and coordinates execution.

88. What does MBR stand for?


a) Main Buffer Register
b) Memory Buffer Routine
337
c) Main Buffer Routine
d) Memory Buffer Register
Answer: d
Explanation: The binary subtraction 0
– 1 gives the result 1.
A borrow of 1 is although generatedand is removed from the next highercolumn.

89. In the instruction ADD A, B, the answer gets stored in


a) B
b) A
c) Buffer
d) C
Answer: b
Explanation: In any instruction of theform ADD A, B; the answer gets stored in the A register. The
format is: ADD Destination, Source.

90. What is the high-speed memorybetween the main memory and theCPU called?
a) Register Memory
b) Cache Memory
c) Storage Memory
d) Virtual Memory
Answer: b
Explanation: It is called the Cache Memory. The cache memory is thehigh speed memory between
the main memory and the CPU.

91. Cache Memory is implementedusing the DRAM chips.


a) True
b) False
Answer: b
Explanation: The Cache memory is implemented using the SRAM chips and not the DRAM chips.
SRAM stands for Static RAM. It is faster andis expensive.

92. Whenever the data is found in thecache memory it is called as


a) HIT
b) MISS
c) FOUND
d) ERROR

338
Answer: a

Explanation: Whenever the data is found in the cache memory, it is called as Cache HIT. CPU first
checksin the cache memory since it is closest to the CPU.

93. LRU stands for


a) Low-Rate Usage
b) Least Rate Usage
c) Least Recently Used
d) Low Required Usage
Answer: c
Explanation: LRU stands for Least Recently Used. LRU is a type of replacement policy used by the
cachememory.

94. When the data at a location incache is different from the data located in the main memory, the
cache is called
a) Unique
b) Inconsistent
c) Variable
d) Fault
Answer: b
Explanation: The cache is said to beinconsistent. Inconsistency must beavoided as it leads to
serious data bugs.

95. Which of the following is not awrite policy to avoid Cache Coherence?
a) Write through
b) Write within
c) Write back
d) Buffered write
Answer: b
Explanation: There is no policy whichis called as the write within policy.

96. The portion of the processor which contains the hardware required to fetch the operations is
The other three options are the write
policies which are used to avoidcache coherence.
a) Datapath
b) Processor
c) Control
339
d) Output unit

Answer: a
Explanation: The Datapath contains the hardware required to fetch the operations. The control tells
the datapath what needs to be done.

97. What does PC stand for?


a) Program Changer
b) Program Counter
c) Performance Counter
d) Performance Changer
Answer: b
Explanation: The Program counter contains the address of the next instruction which is to be
fetched by

98. Causing the CPU to step through a series of micro-operations is called the control unit. All
other options are invalid.
a) Execution
b) Runtime
c) Sequencing
d) Pipelining
Answer: c

Explanation: Sequencing is the process of causing the CPU to step through a series of micro-
[Link] causes the performance ofeach micro-operation.

99. Which of the following holds thelast instruction fetched?


a) PC
b) MAR
c) MBR
d) IR
Answer: c
Explanation: The IR which stands forthe instruction register contains thelast instruction fetched. All
the other options are registerswhich are used for the fetch operation.

100. The functions of execution andsequencing are performed by using


a) Input Signals

340
b) Output Signals
c) Control Signals
d) CPU
Answer: c
Explanation: Sequencing followed by the process of execution is performedby the Control signals.
Sequencing is traversing each and every operation whereas execution causes the performance of
each operation.

101. What does D in the D-flip flopstand for?


a) Digital
b) Direct
c) Delay
d) Durable
Answer: c
Explanation: In the hardwired controlunit, the delay element method uses D-flip flop which causes a
delay. Since, in the delay element method,there must be a finite time gap between the 2 steps.

102. All input of NOR as low producesresults as


a) Low
b) Mid
c) High
d) Floating
Answer: c
Explanation: All input of NOR as low produces the result as high, whereas,rest all conditions
produce output as low.

103. What is a multiplexer?


a) It is a type of decoder which decodes several inputs and gives oneoutput
b) A multiplexer is a device whichconverts many signals into one
c) It takes one input and results intomany output
d) It is a type of encoder which decodes several inputs and gives oneoutput
Answer: b
Explanation: A multiplexer (or MUX) is a device that selects one of severalanalog or digital input
signals and forwards the selected input into a single line, depending on the active select lines.

104. Which combinational circuit is renowned for selecting a single inputfrom multiple inputs &
directing the binary information to output line?
341
a) Data Selector
b) Data distributor
c) Both data selector and datadistributor
d) Demultiplexer
Answer: a
Explanation: Data Selector is anothername of Multiplexer. A multiplexer (or MUX) is a device that
selects oneof several analog or digital input signals and forwards the selected input into a single
line, depending onthe active select lines.

105. It is possible for an enable or strobe input to undergo an expansionof two or more MUX ICs to
the digitalmultiplexer with the proficiency of large number of
a) Inputs
b) Outputs
c) Selection lines
d) Enable lines
Answer: a

Explanation: It is possible for an enable or strobe input to undergo anexpansion of two or more
MUX ICs to the digital multiplexer with the proficiency of large number of inputs.

106. Which is the major functioningresponsibility of the multiplexing combinational circuit?


a) Decoding the binary information
b) Generation of all minterms in anoutput function with OR-gate
c) Generation of selected path between multiple sources and asingle destination
d) Encoding of binary information
Answer: c
Explanation: The major functioning responsibility of the multiplexing combinational circuit is
generation ofselected path between multiple sources and a single destination because it makes
the circuit too flexible. A multiplexer (or MUX) is a device that selects one of several analog or
digital input signals and forwards the selected input into a single line, depending on the active
select lines.

107. What is the function of an enable input on a multiplexer chip?


a) To apply Vcc
b) To connect ground
c) To active the entire chip
d) To active one half of the chip

342
Answer: c
Explanation: Enable input is used to active the chip, when enable is high the chip works (ACTIVE),
when enableis low the chip does not work (MEMORY). However, Enable can be Active-High or
Active-Low, indicating it is active either when it is connectedto VCC or GND respectively.

108. The language made up of binarycoded instructions.


a) Machine
b) C
c) BASIC
d) High level
Answer: a
Explanation: The language made up of binary coded instructions built intothe hardware of a
particular computer and used directly by the computer is machine language.

109. Binary code comprises of digitsfrom 0 to 9.


a) True
b) False
Answer: b
Explanation: The statement is false.
Binary as the word suggests containsonly 2 digits : 0 and 1.
0 denotes false and 1 denotes a truthvalue.

110. The contains the address of the next instruction to beexecuted.


a) IR
b) PC
c) Accumulator
d) System counter
Answer: b
Explanation: PC stands for program counter (It contains the address of the next instruction to be
executed).

111. The memory unit is made up of


bytes.a) 256
b) 124
c) 4096
d) 3096

Answer: c
Explanation: The memory unit is made up of 4,096 bytes. Memory unitis responsible for the
storage of [Link] is an important entity in the computer system.
343
112. A document that specifies howmany times and with what data the
program must be run in order tothoroughly test it.
a) addressing plan
b) test plan
c) validation plan
d) verification plan
Answer: b
Explanation: Test plan is the A document that specifies how manytimes and with what data the
program must be run in order to thoroughly test it. It comes under testing.

113. An approach that designs test cases by looking at the allowable datavalues.
a) Maintenance
b) Evaluation
c) Data coverage
d) Validation
Answer: c
Explanation: Data coverage is theterm used. It is responsible for designing the test cases.

114. The formal grammar rules governing the construction of validinstruction.


a) test case
b) syntax
c) program
d) semantics
Answer: b
Explanation: Syntax determines thegrammatical rules in a code.
Semantics give meaning to theinstructions.

115. A program that reads each of the instructions in mnemonic form and translates it into the
machine-language equivalent.
a) Machine language
b) Assembler
c) Interpreter
d) C program
Answer: b
Explanation: Assembler does this job.A language that uses mnemonic codes for the representation
of machine-language instructions is called assembly language.

116. An approach that designs test cases by looking at the allowable datavalues.
344
a) Data coverage
b) Code Coverage
c) Debugging
d) Validation

Answer: a
Explanation: Data coverage is an approach that designs test cases by looking at the allowable data
[Link] coverage is an approach that designs test cases by looking at the code.

117. The rules that give meaning tothe instructions.


a) Semantics
b) Syntax
c) Code
d) Cases
Answer: a
Explanation: The answer is [Link] are the rules that give meaning to the instructions. The
syntax is the formal rules that ensure validation of code.

118. One multiplexer can take theplace of


a) Several SSI logic gates
b) Combinational logic circuits
c) Several Ex-NOR gates
d) Several SSI logic gates orcombinational logic circuits
Answer: d
Explanation: A multiplexer (or MUX) is a device that selects one of severalanalog or digital input
signals andforwards the selected input into a single line, depending on the active select lines.
Since many operational behaviour can be performed by usinga multiplexer. Whereas, a
combinational circuit is a combination of many logic gates which makes the circuit more complex.

119. A digital multiplexer is a combinational circuit that selects


a) One digital information from several sources and transmits theselected one
b) Many digital information andconvert them into one
c) Many decimal inputs and transmitsthe selected information
d) Many decimal outputs and acceptsthe selected information
Answer: a
Explanation: A digital multiplexer is acombinational circuit that selects onedigital information from
several sources and transmits the selected information on a single output line depending on the
status of the selectlines. That is why it is also known

345
adata selector.

120. In a multiplexer, the selection ofa particular input line is controlled by

a) Data controller
b) Selected lines
c) Logic gates
d) Both data controller and selectedlines
Answer: b
Explanation: The selection of a particular input line is controlled by aset of selected lines in a
multiplexer, which helps to select a particular input from several sources.

121. If the number of n selected inputlines is equal to 2^m, then it requires select lines.
a) 2
b) m
c) n
d) 2n
Answer: b
Explanation: If the number of n selected input lines is equal to 2^mthen it requires m select lines to
select one of m select lines.

122. How many select lines would berequired for an 8-line-to-1-line multiplexer?
a) 2
b) 4
c) 8
d) 3
Answer: d
Explanation: 2n input lines, n controllines and 1 output line available for MUX. Here, 8 input lines
mean 23 inputs. So, 3 control lines are possible. Depending on the status ofthe select lines, the
input is selectedand fed to the output.

123. A basic multiplexer principle canbe demonstrated through the use of a


a) Single-pole relay
b) DPDT switch
c) Rotary switch
d) Linear stepper
Answer: c

346
Explanation: A basic multiplexer principle can be demonstrated through the use of a rotary switch.
Since its behaviour is similar to the multiplexer. There are around 10 digits out of which one is
selected one at a time and fed to the output.

124. How many NOT gates are required for the construction of a 4-to-1 multiplexer?
a) 3
b) 4
c) 2
d) 5
Answer: c
Explanation: There are two NOT gatesrequired for the construction of 4-to- 1 multiplexer. x0, x1, x2
and x3 are the inputs and C1 and C0 are the select lines and M is the [Link] diagram of a 4-to-
1 multiplexer isshown
below:

125. In the given 4-to-1 multiplexer, ifc1 = 0 and c0 = 1 then the output M is
a) X0
b) X1
c) X2
d) X3
Answer: b
Explanation: The output will be X1, because c1 = 0 and c0 = 1 results into1 which further results as
X1. And rest of the AND gates give output as0.

126. The enable input is also knownas


a) Select input
b) Decoded input
c) Strobe
d) Sink
Answer: c
Explanation: The enable input is also known as strobe which is used to cascade two or more
multiplexer ICs to construct a multiplexer with a larger number of inputs. Enable inputactivates the
multiplexer to operate.

127. Execution of several activities atthe same time.


a) processing
b) parallel processing
c) serial processing
d) multitasking
347
Answer: b
Explanation: Execution of several activities at the same time is referredto as parallel processing.
Like, Two multiplications at the same time on 2different processes.

128. Parallel processing has singleexecution flow.


a) True
b) False
Answer: b
Explanation: The statement is false. Sequential programming specificallyhas single execution flow.

129. A term for simultaneous accessto a resource, physical or logical.


a) Multiprogramming
b) Multitasking
c) Threads
d) Concurrency
Answer: d
Explanation: Concurrency is the termused for the same. When several things are accessed
simultaneously, the job is said to be concurrent.

130. leads toconcurrency.


a) Serialization
b) Parallelism
c) Serial processing
d) Distribution
Answer: b
Explanation: Parallelism leads naturally to Concurrency. For example, Several processes trying to
print a file on a single printer.

131. A parallelism based on increasing processor word size.


a) Increasing
b) Count based
c) Bit based
d) Bit level
Answer: d
Explanation: Bit level parallelism is based on increasing processor wordsize. It focuses on
hardware capabilities for structuring.

132. A type of parallelism that usesmicro architectural techniques.

348
a) instructional
b) bit level
c) bit based
d) increasing
Answer: a
Explanation: Instructional level usesmicro architectural techniques. It focuses on program
instructions forstructuring.

133. MIPS stands for?


a) Mandatory Instructions/sec
b) Millions of Instructions/sec
c) Most of Instructions/sec
d) any Instructions / sec
Answer: b
Explanation: MIPS stands for Millionsof Instructions/sec. MIPS is a way to measure the cost of
computing.

134. The measure of the “effort” needed to maintain efficiency whileadding processors.
a) Maintainability
b) Efficiency
c) Scalability
d) Effectiveness
Answer: c
Explanation: The measure of the“effort” needed to maintain
efficiency while adding processors iscalled as scalabilty.

135. The rate at which the problem size need to be increased to maintainefficiency.
a) Iso efficiency
b) Efficiency
c) Scalability
d) Effectiveness
Answer: a
Explanation: Isoefficiency is the rate at which the problem size need to beincreased to maintain
efficiency.

136. Several instructions execution simultaneously in


a) processing
b) parallel processing
349
c) serial processing
d) multitasking
Answer: b
Explanation: In parallel processing, the several instructions are executedsimultaneously.

137. How many inputs will a decimal-to-BCD encoder have?


a) 4
b) 8
c) 10
d) 16
Answer: c
Explanation: An encoder is a combinational circuit encoding the information of 2n input lines to n
output lines, thus producing the binary equivalent of the input. Thus, a Decimal-to-bcd converter
has decimal values as inputs which range from 0-9. So, total 10 inputs are therein a decimal-to-
BCD encoder.

138. How many outputs will a decimal-to-BCD encoder have?


a) 4
b) 8
c) 12
d) 16
Answer: a
performs the opposite operation of adecoder which results in 2n outputs from n inputs. Thus, an
encoder different from a decoder because of the output of an encoder is a binary code for 1-of-N
input.

140. The full form of ROM is


Explanation: An encoder is a
combinational circuit encoding the information of 2n input lines to n output lines, thus producing
the binary equivalent of the input. Thus,a decimal to BCD encoder has 4 outputs.

139. How is an encoder differentfrom a decoder?


a) The output of an encoder is abinary code for 1-of-N input
b) The output of a decoder is a binarycode for 1-of-N input
c) The output of an encoder is abinary code for N-of-1 output
d) The output of a decoder is a binarycode for N-of-1 output
Answer: a
Explanation: An encoder is a combinational circuit encoding theinformation of 2n input lines to n
350
output lines, thus producing the binary equivalent of the input. It
a) Read Outside Memory
b) Read Out Memory
c) Read Only Memory
d) Read One Memory
Answer: c
Explanation: The full form of ROM isRead Only Memory.

141. ROM consist of


a) NOR and OR arrays
b) NAND and NOR arrays
c) NAND and OR arrays
d) NOR and AND arrays
Answer: c
Explanation: ROM consists of NAND and OR arrays which can be programmed by the user to
implement combinational & sequential functions. Combinational Operations like that of adders and
subtractors and Sequential Functionslike that of storing in the memory.

142. For reprogrammability, PLDs use


a) PROM
b) EPROM
c) CDROM
d) PLA
Answer: b
Explanation: For reprogram ability, PLDs use EPROM (i.e. Erasable PROM). It erases the previous
program and starts uploading a new one. However, data is erased by exposing it to UV-light, which
is a tedious and time-consuming process.

143. The full form of PROM is


a) Previous Read Only Memory
b) Programmable Read Out Memory
c) Programmable Read Only Memory
d) Previous Read Out Memory
Answer: c
Explanation: The full form of PROM isProgrammable Read Only Memory, where the ROM can be
programmed by the user.

144. The full form of EPROM is


351
a) Easy Programmable Read OnlyMemory
b) Erasable Programmable Read Only
Memory
c) Eradicate Programmable Read OnlyMemory
d) Easy Programmable Read OutMemory
Answer: b
Explanation: The full form of EPROMis Erasable Programmable Read OnlyMemory, where the ROM
can be erased and re-used by the user.

145. PLDs with programmable ANDand fixed OR arrays are called


a) PAL
b) PLA
c) APL
d) PPL
Answer: a Explanation: PLDs with
programmable AND and fixed ORarrays are called PAL (i.e.
Programmable Array Logic). However, PAL is less flexible but hashigher speed.

146. When both the AND and OR areprogrammable, such PLDs are knownas
a) PAL
b) PPL
c) PLA
d) APL
Answer: c
Explanation: When both the AND andOR are programmable, such PLDs areknown as PLA (i.e.
Programmable Logic Array). However, PLA is more flexible but has less speed.

147. ASIC stands for


a) Application Special IntegratedCircuits
b) Applied Special Integrated Circuits
c) Application Specific IntegratedCircuits
d) Applied Specific Integrated CircuitsAnswer: c
Explanation: In digital electronics, ASIC stands for Application Specific Integrated Circuits. It is a
customizedintegrated circuit which is produced for a specific use and not for a common purpose.

148. The programmability and high density of PLDs make them useful inthe design of
a) ISAC

352
b) ASIC
c) SACC
d) CISF
Answer: b
Explanation: The programmability and high density of PLDs make themuseful in the design of ASIC
(i.e. Application Specific Integrated Circuits) where design changes canbe more rapidly and
inexpensively.

149. FPGA stands for


a) Full Programmable Gate Array
b) Full Programmable Genuine Array
c) First Programmable Gate Array
d) Field Programmable Gate Array
Answer: d
Explanation: In digital electronics, FPGA stands for Field Programmable Gate Array. This type of
integrated circuit is for general-purpose which isconfigured by the user as per their requirement.

150. Which of the following is areprogrammable gate array?


a) EPROM
b) FPGA
c) Both EPROM and FPGA
d) ROM
Answer: c
Explanation: Both FPGA and EPROMare reprogrammable gate array.

151. The difference between FPGAand PLD is that


a) FPGA is slower than PLD
b) FPGA has high power dissipation
c) FPGA incorporates logic blocks
d) All of the Mentioned
Answer: c
Explanation: The differences betweenFPGA and PLD is that FPGA incorporates logic blocks
instead of fixed AND-OR gates and is faster withlow power dissipation. FPGAs are designed for
having higher gate countwhereas, PLDs are used for lesser gate counts.

152. If we record any music in anyrecorder, such types of process is called


a) Multiplexing
b) Encoding
353
c) Decoding
d) Demultiplexing
Answer: b
Explanation: If we record any music inany recorder, it means that we are giving data to a recorder.
So, such process is called encoding. Getting back the music from the recorded data, is known as
decoding.

153. Can an encoder be a transducer?


a) Yes
b) No
c) May or may not be
d) Both are not even related slightly
Answer: a
Explanation: Of course, a transducer is a device which has the capability toemit data as well as to
accept.
Transducer converts signal from oneform of energy to another.

154. How many OR gates are required for a Decimal-to-bcdencoder?


a) 2
b) 10
c) 3
d) 4
Answer: d
Explanation: An encoder is a combinational circuit encoding theinformation of 2^n input lines to n
output lines, thus producing the binary equivalent of the input.
This is clear from the diagram that itrequires 4 OR gates: Since, a part of the program needs tobe in
memory for the process of execution, the logical space can therefore be much larger than the
physical address space.

155. Separation of user logical memory and physical memory is


a) Memory control
b) Memory management
c) Memory sharing
d) Virtual memory
Answer: d
Explanation: The separation of user logical memory and physical memoryis called virtual memory.
Only part ofthe program needs to be in memory for execution.
354
156. Logical Address space can be larger than physical address space.
a) True
b) False
Answer: a
Explanation: The statement is true.

157. Virtual Memory can be implemented via


a) Demand Paging
b) Logical paging
c) Structural way
d) Simple division
Answer: a
Explanation: Demand paging can implement virtual memory. Anotherway is demand segmentation.

158. COW stands for?


a) Copy over write
b) Convert over write
c) Count over write
d) Copy over write
Answer: d
Explanation: COW stands for Copy over write. COW allows both parentand child processes to share
the same pages initially.

159. LRU stands for?


a) Least Recently used
b) Less Recently used
c) Least Recurrently used
d) Least Randomly used
Answer: a
Explanation: LRU stands for Least Recently used. LRU is least recentlyused. It replaces page with
the smallest count.

160. An allocation that uses a proportional allocation scheme usingpriorities rather than size.
a) Priority allocation
b) File allocation
c) Preference allocation
d) Simple allocation
355
Answer: a
Explanation: Priority allocation uses aproportional allocation scheme usingpriorities rather than size.

161. A process selects a replacementframe from the set of all frames.


a) Local replacement
b) Global replacement
c) Block replacement
d) Module replacement
Answer: b
Explanation: Global replacement process selects a replacement framefrom the set of all frames;
one process can take a frame fromanother.

162. How many OR gates are required for an octal-to-binaryencoder?


a) 3
b) 2
c) 8
d) 10
Answer: a
Explanation: An encoder is a combinational circuit encoding the information of 2n input lines to n
output lines, thus producing the binary equivalent of the input. Thus, in octal to binary encoder
there are 8(=23) inputs, thus 3 output lines.

163. For 8-bit input encoder howmany combinations are possible?


a) 8
b) 2^8
c) 4
d) 2^4

Answer: b
Explanation: An encoder is a combinational circuit encoding the information of 2n input lines to n
output lines, thus producing the binary equivalent of the input. Thereare 28 combinations are
possible for an 8-bit input encoder but out of which only 8 are used using 3 outputlines. It is a
disadvantage of encoder.

164. The discrepancy of 0 output dueto all inputs being 0 or D0, being 0 is resolved by using
additional input known as
a) Enable
b) Disable
c) Strobe

356
d) Clock
Answer: a
Explanation: Such problems are resolved by using enable input, whichbehaves as active if it gets 0
as input since it is an active-low pin.

165. Can an encoder be called asmultiplexer?


a) No
b) Yes
c) Sometimes
d) Never
Answer: b
Explanation: A multiplexer or MUX is a combination circuit that contains more than one input line,
one outputline and more than one selection [Link], an encoder is also considered a type of
multiplexer but
without a single output line andwithout any selection lines.

166. If two inputs are active on a priority encoder, which will be codedon the output?
a) The higher value
b) The lower value
c) Neither of the inputs
d) Both of the inputs
Answer: a
Explanation: An encoder is a combinational circuit encoding the information of 2n input lines to n
output lines, thus producing the binary equivalent of the input. If twoinputs are active on a priority
encoder, the input of higher value will be coded in the output.

167. How many outputs are presentin a BCD decoder?


a) 4
b) 5
c) 15
d) 10
Answer: d
Explanation: A binary decoder is a combinational logic circuit which decodes binary information
from n- inputs to a maximum of 2n outputs. ABCD to Decimal decoder has 10number of outputs
because the decimal digit’s range is from 0 to 9.

168. Which digital system translatescoded characters into a more usefulform?


a) Encoder
357
b) Display
c) Counter
d) Decoder
Answer: d
Explanation: A binary decoder is a combinational logic circuit which decodes binary information
from n-inputs to a maximum of 2n [Link] converts the coded characters into our
required data form.

169. What control signals may be necessary to operate a 1-line-to-16line decoder?


a) Flasher circuit control signal
b) A LOW on all gate enable inputs
c) Input from a hexadecimal counter
d) A HIGH on all gate enable circuits
Answer: b
Explanation: A LOW on all gate enable inputs is necessary to operatea 1-line-to-16 line decoder
because enable pins are usually, active-low pins.

170. How many inputs are requiredfor a 1-of-10 BCD decoder?


a) 4
b) 8
c) 10
d) 2
Answer: a
Explanation: A binary decoder is a combinational logic circuit which decodes binary information
from n-inputs to a maximum of 2n [Link], for a BCD to decimal decoder, No. of inputs =
4 such thatnumber of outputs is <= 2n.

171. A BCD decoder will have howmany rows in its truth table?
a) 10
b) 9
c) 8
d) 3
Answer: a
Explanation: A binary decoder is a combinational logic circuit which decodes binary information
from n- inputs to a maximum of 2n outputs. Thus, BCD decoder will have 10 rowsas it’s input
ranges from 0 to 9.

358
172. How many possible outputs would a decoder have with a 6-bitbinary input?
a) 32
b) 64
c) 128
d) 16

Answer: c
Explanation: The possible outputs would be: 2n = 64 (Since n = 6 here).

173. One way to convert BCD to binary using the hardware approachis:
a) By using MSI IC circuits
b) By using a keyboard encoder
c) By using an ALU
d) By using UART
Answer: a
Explanation: One way to convert BCDto binary using the hardware approach is MSI (medium scale
integration) IC circuits.

174. How many inputs are requiredfor a 1-of-16 decoder?


a) 2
b) 16
c) 8
d) 4
Answer: d
Explanation: A binary decoder is a combinational logic circuit which decodes binary information
from n-inputs to a maximum of 2n [Link], number of outputs = 16.
16 = 24 = 2n. Thus, number of inputs is4.

175. A truth table with output columns numbered 0–15 may be forwhich type of decoder IC?
a) Hexadecimal 1-of-16
b) Dual octal outputs
c) Binary-to-hexadecimal
d) Hexadecimal-to-binary
Answer: a
Explanation: A binary decoder is a combinational logic circuit which decodes binary information
from n- inputs to a maximum of 2n outputs. Atruth table with output columns numbered 0–15 may
be for Hexadecimal 1-of-16. Because hexadecimal occupies less space in a system.

176. How can the active condition (HIGH or LOW) or the decoder outputbe determined from the
359
logic symbol?
a) A bubble indicates active-HIGH
b) A bubble indicates active-LOW
c) A triangle indicates active-HIGH
d) A triangle indicates active-LOW

Answer: b
Explanation: A bubble indicates active-LOW in a decoder always. Enable pin of the decoder is
usually active-LOW and is triggered on inputbeing at 0.

177. A code converter is a logic circuitthat


a) Inverts the given input
b) Converts into decimal number
c) Converts data of one type intoanother type
d) Converts to octal
Answer: c
Explanation: A code converter is a logic circuit that changes data presented in one type of binary
codeto another type of binary code.

178. Use the weighting factors to convert the following BCD numbersto binary _

0101 0011 & 0010 0110 1000

a) 01010011 001001101000
b) 11010100 100001100000
c) 110101 100001100
d) 101011 001100001

Answer: c
Explanation: Firstly, convert every 4sets of binary to decimal from the given: 0101=5, 0011=3. Then
convert53 to binary, which will give [Link], do the same with the next 4 set of binary digits.

179. he primary use for gray code is


a) Coded representation of a shaft’smechanical position
b) Turning on/off software switches
c) To represent the correct ASCII codeto indicate the angular position of a shaft on rotating
machinery
d) To convert the angular position ofa shaft on rotating machinery into hexadecimal code
Answer: a
Explanation: Gray code is useful because only one bit changes at a time, which is implemented
easily inCoded representation of a shaft’s mechanical position. In Gray Code, every sequence of
360
successive bits differs by 1 bit only.

180. Code is a symbolic representation of


a) Discrete information
b) Continuous information
c) Decimal information into binary
d) Binary information into decimal

Answer: a
Explanation: Code is a symbolic representation of discrete information. Codes can be anything like
numbers, letter or words, writtenin terms of group of symbols.

181. One way to convert BCD to binary using the hardware approachis
a) With MSI IC circuits
b) With a keyboard encoder
c) With an ALU
d) UART
Answer: a
Explanation: One way to convert BCDto binary using the hardware approach is MSI IC (i.e. medium
scaleintegration) circuits.

182. Why is the Gray code morepractical to use when coding theposition of a rotating shaft?
a) All digits change between counts
b) Two digits change between counts
c) Only one-digit changes betweencounts
d) Alternate digit changes betweencounts
Answer: c
Explanation: The Gray code is morepractical to use when coding the
position of a rotating shaft becauseonly one digit changes between counts that is reflected to the
next count.

183. Reflected binary code is alsoknown as


a) BCD code
b) Binary code
c) ASCII code
d) Gray Code
Answer: d
Explanation: The reflected binary code is also known as gray code because one digit reflected to

361
the next bit. In Gray Code, every sequence of successive bits differs by1 bit only.

184. Why do we use gray codes?


a) To count the no of bits changes
b) To rotate a shaft
c) Error correction
d) Error Detetction
Answer: c
Explanation: Today, Gray codes are widely used to facilitate error correction in digital
communicationssuch as digital terrestrial television and some cable TV systems.

185. Earlier, reflected binary codeswere applied to


a) Binary addition
b) 2’s complement
c) Mathematical puzzles
d) Binary multiplication
Answer: c
Explanation: The reflected binary code is also known as gray code because one digit reflected to
the next bit. In Gray Code, every sequence of successive bits differs by 1 bit only. Reflected binary
codes were applied to mathematical puzzlesbefore they became known to engineers.

186. The binary representation of BCD number 00101001 (decimal 29)is


a) 0011101
b) 0110101
c) 1101001
d) 0101011

Answer: a
Explanation: The given BCD number00101001 has three 1s. So, it can berewritten as 0000001-1,
0001000-8,0010100-20 and after addition, we get 0011101 as output.

187. Convert binary number into graycode: 100101.


a) 101101
b) 001110
c) 110111
d) 111001

Answer: c
Explanation: : Conversion from BinaryTo Gray Code:

362
1 (XOR) 0 (XOR) 0 (XOR) 1 (XOR) 0
(XOR) 1

↓ ↓ ↓ ↓ ↓1 1 0 1 1 1

188. Each personal computer has a


that manages the computer’s arithmetical, logical andcontrol activities.
a) Microprocessor
b) Assembler
c) Microcontroller
d) Interpreter
Answer: a
Explanation: Microprocessor handles all these activities. Each family of processors has its own set
of instructions for handling various operations like getting input from keyboard, displaying
information on a screen and performing various otherjobs.

189. Assembly Language requires lessmemory and execution time.


a) True
b) False
Answer: a
Explanation: The statement is [Link] of using assembly language are:
• It requires less memory andexecution time.
• It allows hardware-specific complexjobs in an easier way.
• It is suitable for time-critical jobs.
190. The data size of a word is
a) 2-byte
b) 4-byte
c) 8-byte d)16-byte
Answer: a
Explanation: The processor supportsthe following data sizes:
• Word: a 2-byte data item
• Double word: a 4-byte (32 bit) dataitem, etc.

191. A direct reference of specificlocation.


a) Segment Address
b) Absolute Address
c) Offset
d) Memory Address
363
Answer: b
Explanation: There are two kinds ofmemory addresses:
• An absolute address – a directreference of specific location.
• The segment address (or offset) –starting address of a memory segment with the offset value.

192. A Borland Turbo Assembler.


a) nasm
b) tasm
c) gas
d) asm
Answer: b
Explanation: Tasm is the borland turbo assembler. Nasm is used withlinux generally. Gas is the
GNU assembler.

193. The instructions that tell theassembler what to do.


a) Executable instructions
b) Pseudo-ops
c) Logical instructions
d) Macros

Answer: a
Explanation: The executable instructions or simple instructions tellthe processor what to do. Each
instruction consists of an operation code (opcode). Each executable instruction generates one
machine language instruction.

194. The segment containing datavalues passed to functions and procedures within the program.
a) Code
b) Data
c) Stack
d) System
Answer: c
Explanation: The stack segment contains data values passed to functions and procedures within
theprogram. The code segment definesan area in memory that stores the instruction codes.

195. To speed up the processor operations, the processor includessome internal memory storage
locations, called
a) Drives
b) Memory
c) Units
364
d) Registers
Answer: d
Explanation: The processor has someinternal memory storage locations, known as registers. The
registers stores data elements for processing without having to access memory.

196. To locate the exact location of data in memory, we need the startingaddress of the segment,
which is found in the DS register and an offsetvalue. This offset value is also called?
a) Effective Address
b) Direct offset address
c) Memory address
d) General Address
Answer: a
Explanation: When operands are specified in memory addressing mode, direct access to main
memory,usually to the data segment, is required. This way of addressing results in slower
processing of data. To get the exact location of data in memory, we need segment start address,
which is found in the DS register and an offset value. This offset value is called an effective
address.

197. Each byte of character is storedas its ASCII value in


a) Hexadecimal
b) Binary
c) Octal
d) Decimal
Answer: a
Explanation: Assembly language dealswith hexadecimal values only. Each decimal value is
automatically converted to its 16-bit binary equivalent and stored as a hexadecimal number.

198. A latch is an example of a


a) Monostable multivibrator
b) Astable multivibrator
c) Bistable multivibrator
d) 555 timer
Answer: c
Explanation: A latch is an example ofa bistable multivibrator. A Bistable multivibrator is one in
which the circuit is stable in either of two states. It can be flipped from one state to the other state
and vice- versa.

199. Latch is a device with


c) Three stable states
365
d) Infinite stable states
Answer: b
Explanation: Since, a latch works onthe principal of bistable multivibrator. A Bistable multivibrator
is one in which the circuit is stable in either of two states. It can be flipped from one state to the
other state and vice- versa. So a latch has two stable states.

200. Why are latches called amemory devices?


a) It has capability to stare 8 bits ofdata
b) It has internal memory of 4 bit
c) It can store one bit of data
d) It can store infinite amount of data
Answer: c
Explanation: Latches can be memory devices and can store one bit of datafor as long as the device
is powered. Once device is turned off, the memory gets refreshed.

201. Two stable states of latches are

a) One stable state


b) Two stable state
a) Astable & Monostable
b) Low input & high output

c) High output & low output


d) Low output & high input
Answer: c set/reset. It is a type of latch havingtwo stable states.

204. The SR latch consists of


Explanation: A latch has two stables
states, following the principle of Bistable Multivibrator. There are twostable states of latches, and
these states are high-output and low- output.

202. How many types of latches are


a) 4
b) 3
c) 2
d) 5
Answer: a
Explanation: There are four types of latches: SR latch, D latch, JK latch andT latch. D latch is a
366
modified form of SR latch whereas, T latch is an advanced form of JK latch.

203. The full form of SR is


a) System rated
b) Set reset
c) Set ready
d) Set Rated
Answer: b
Explanation: The full form of SR is
a) 1 input
b) 2 inputs
c) 3 inputs
d) 4 inputs
Answer: b
Explanation: SR or Set-Reset latch isthe simplest type of bistable multivibrator having two stable
states. The diagram of SR latch is shownbelow:

204. The outputs of SR latch are


a) x and y
b) a and b
c) s and r
d) q and q’
Answer: d
Explanation: SR or Set-Reset latch is the simplest type of bistable multivibrator having two stable
states. The inputs of SR latch are s and r while outputs are q and q’. It isclear from the diagram:

367
.

205. The NAND latch works whenboth inputs are


a) 1
b) 0
c) Inverted
d) Don’t cares
Answer: a
Explanation: The NAND latch works when both inputs are 1. Since, both of the inputs are inverted in
a NANDlatch.

206. The first step of analysisprocedure of SR latch is to


a) label inputs
b) label outputs
c) label states
d) label tables
Answer: b
Explanation: All flip flops have at leastone output labeled Q (i.e. inverted).
This is so because the flip flops have inverting gates inside them, hence inorder to have both Q and
Q complement available, we have atleast one output labelled.

207. The inputs of SR latch are


a) x and y
b) a and b
c) s and r
d) j and k

Answer: c
Explanation: SR or Set-Reset latch is the simplest type of bistable multivibrator having two stable
states. The inputs of SR latch are s and r while outputs are q and q’. It isclear from the diagram:

208. When a high is applied to the Setline of an SR latch, then


a) Q output goes high
b) Q’ output goes high
c) Q output goes low
d) Both Q and Q’ go high
Answer: a
Explanation: S input of a SR latch isdirectly connected to the output [Link], when a high is applied Q
outputgoes high and Q’ low.

368
209. When both inputs of SR latchesare low, the latch
a) Q output goes high
b) Q’ output goes high
c) It remains in its previously set orreset state
d) it goes to its next set or reset state
Answer: c
Explanation: When both inputs of SRlatches are low, the latch remains in it’s present state. There is
no changein the output.

210. When both inputs of SR latches are high, the latch goes
a) Unstable
b) Stable
c) Metastable
d) Bistable
Answer: c
Explanation: When both gates are
identical and this is “metastable”, andthe device will be in an undefined state for an indefinite
period.

211. Latches constructed with NORand NAND gates tend to remain in the latched condition due to
whichconfiguration feature?
a) Low input voltages
b) Synchronous operation
c) Gate impedance
d) Cross coupling
Answer: d
Explanation: Latch is a type of bistable multivibrator having two stable states. Both inputs of a
latch are directly connected to the other’soutput. Such types of structure are called cross coupling
and due to which latches remain in the latched condition.

212. One example of the use of an S-


R flip-flop is as _
a) Transition pulse generator
b) Racer
c) Switch debouncer
d) Astable oscillator

369
Answer: c
Explanation: The SR flip-flop is veryeffective in removing the effects ofswitch bounce, which is the
unwanted noise caused during theswitching of electronic devices.

213. The truth table for an S-R flip-flop has how many VALID entries?
a) 1
b) 2
c) 3
d) 4
Answer: c
Explanation: The SR flip-flop actually has three inputs, Set, Reset and its current state. The Invalid
or Undefined State occurs at both S andR being at 1.

214. When both inputs of a J-K flip-flop cycle, the output will
a) e invalid
b) Change
c) Not change
d) Toggle
Answer: c
Explanation: After one cycle the valueof each input comes to the same value. Eg: Assume J=0 and
K=1. After 1 cycle, it becomes as J=0->1->0(1 cycle complete) and K=1->0->1(1 cycle complete).
The J & K flip-flop has 4 stable states: Latch, Reset, Set and Toggle.

215. Which of the following is correctfor a gated D-type flip-flop?


a) The Q output is either SET or RESETas soon as the D input goes HIGH or LOW
b) The output complement followsthe input when enabled
c) Only one of the inputs can be HIGHat a time
d) The output toggles if one of theinputs is held HIGH
Answer: a
Explanation: In D flip flop, when the clock is high then the output dependson the input otherwise
reminds previous output. In a state of clock high, when D is high the output Q also high, if D is ‘0’
then output is alsozero. Like SR flip-flop, the D-flip-flop also have an invalid state at both inputs
being 1.

216. A basic S-R flip-flop can be constructed by cross-coupling ofwhich basic logic gates?
a) AND or OR gates
b) XOR or XNOR gates
c) NOR or NAND gates
370
d) AND or NOR gates
Answer: c
Explanation: The basic S-R flip-flop can be constructed by cross couplingof NOR or NAND gates.
Cross coupling means the output of secondgate is fed to the input of first gate and vice-versa.

217. The logic circuits whose outputsat any instant of time depends only on the present input but
also on the past outputs are called
a) Combinational circuits
b) Sequential circuits
c) Latches
d) Flip-flops
Answer: b
Explanation: In sequential circuits, the output signals are fed back to theinput side. So, The circuits
whose outputs at any instant of time depends only on the present input but also on the past
outputs are called sequential circuits. Unlike sequential circuits, if output dependsonly on the
present state, then it’s known as combinational circuits.

218. Whose operations are morefaster among the following?


a) Combinational circuits
b) Sequential circuits
c) Latches
d) Flip-flops
Answer: a
Explanation: Combinational circuitsare often faster than sequential circuits. Since, the
combinational circuits do not require memory elements whereas the sequential circuits need
memory devices to perform their operations in sequence. Latches and Flip-flops come under
sequential circuits.

219. How many types of sequentialcircuits are?


a) 2
b) 3
c) 4
d) 5
Answer: a
Explanation: There are two types ofsequential circuits viz., (i) synchronous or clocked and (ii)
asynchronous or unclocked.
Synchronous Sequential Circuits aretriggered in the presence of a clock signal, whereas,
Asynchronous Sequential Circuits function in the absence of a clock signal.

371
220. The sequential circuit is alsocalled
a) Flip-flop
b) Latch
c) Strobe
d) Adder
Answer: b
Explanation: The sequential circuit is also called a latch because both are amemory
cell, which are capable of storing one bit of information.

221. The basic latch consists of


a) Two inverters
b) Two comparators
c) Two amplifiers
d) Two adders
Answer: a
Explanation: The basic latch consists of two inverters. It is in the sense thatif the output Q = 0 then
the second output Q’ = 1 and vice versa.

222. In S-R flip-flop, if Q = 0 the output is said to be


a) Set
b) Reset
c) Previous state
d) Current state
Answer: b
Explanation: In S-R flip-flop, if Q = 0 the output is said to be reset and setfor Q = 1.

223. What is a trigger pulse?


a) A pulse that starts a cycle ofoperation
b) A pulse that reverses the cycle ofoperation
c) A pulse that prevents a cycle ofoperation
d) A pulse that enhances a cycle ofoperation
Answer: a
Explanation: Trigger pulse is definedas a pulse that starts a cycle of operation.

224. The circuits of NOR based S-Rlatch classified as asynchronous sequential circuits, why?
a) Because of inverted outputs
b) Because of triggering functionality
372
c) Because of cross-coupledconnection
d) Because of inverted outputs &triggering functionality
Answer: c
Explanation: The cross-coupled connections from the output of one gate to the input of the other
gate constitute a feedback path. For this reason, the circuits of NOR based S-Rlatch classified as
asynchronous sequential circuits. Moreover, they
are referred to as asynchronous because they function in the absenceof a clock pulse.

225. In digital logic, a counter is adevice which


a) Counts the number of outputs
b) Stores the number of times aparticular event or process has occurred
c) Stores the number of times a clockpulse rises and falls
d) Counts the number of inputs
Answer: b
Explanation: In digital logic and computing, a counter is a device which stores (and sometimes
displays) the number of times a particular event or process has occurred, often in relationship to a
clock signal.

226. A counter circuit is usuallyconstructed of


a) A number of latches connected incascade form
b) A number of NAND gatesconnected in cascade form
c) A number of flip-flops connected incascade
d) A number of NOR gates connectedin cascade form
Answer: c
Explanation: A counter circuit is usually constructed of a number offlip-flops connected in cascade.
Preferably, JK Flip-flops are used toconstruct counters and registers.

227. What is the maximum possible range of bit-count specifically in n-bitbinary counter consisting
of ‘n’ number of flip-flops?
a) 0 to2n
b) 0 to 2n + 1
c) 0 to 2n – 1
d) 0 to 2n+1/2

Answer: c
Explanation: The maximum possible range of bit-count specifically in n-bitbinary counter
consisting of ‘n’ number of flip-flops is 0 to 2n-1. For say, there is a 2-bit counter, then it will count
till 22-1 = 3. Thus, it will count from 0 to 3.

228. How many types of the counterare there?


373
a) 2
b) 3
c) 4
d) 5
Answer: b
Explanation: Counters are of 3 types, namely, (i)asynchronous/synchronous, (ii)single and multi-
mode & (iii)modulus counter. These further can be subdivided into Ring Counter,Johnson Counter,
Cascade Counter, Up/Down Counter and such like.

229. A decimal counter has states.


a) 5
b) 10
c) 15
d) 20
Answer: b
Explanation: Decimal counter is also known as 10 stage counter. So, it has10 states. It is also
known as DecadeCounter counting from 0 to 9.

230. Ripple counters are also called


a) SSI counters
b) Asynchronous counters
c) Synchronous counters
d) VLSI counters
Answer: b
Explanation: Ripple counters are alsocalled asynchronous counter. In Asynchronous counters, only
the firstflip-flop is connected to an external clock while the rest of the flip-flops have their
preceding flip-flop outputas clock to them.

231. Synchronous counter is a type of___________


a) SSI counters
b) LSI counters
c) MSI counters
d) VLSI counters
Answer: c
Explanation: Synchronous Counter isa Medium Scale Integrated (MSI). In Synchronous Counters,
the clock pulse is supplied to all the flip-flops simultaneously.

232. Three-decade counter wouldhave

374
a) 2 BCD counters
b) 3 BCD counters
c) 4 BCD counters
d) 5 BCD counters
Answer: b
Explanation: Three-decade counter has 30 states and a BCD counter has10 states. So, it would
require 3 BCDcounters. Thus, a three decade counter will count from 0 to 29.

233. BCD counter is also known as_________


a) Parallel counter
b) Decade counter
c) Synchronous counter
d) VLSI counter
Answer: b
Explanation: BCD counter is also known as decade counter because both have the same number of
stagesand both count from 0 to 9.

234. The parallel outputs of a countercircuit represent the


a) Parallel data word
b) Clock frequency
c) Counter modulus
d) Clock count
Answer: d
Explanation: The parallel outputs of acounter circuit represent the clock count. A counter counts
the number of times an event takes place in accordance to the clock pulse.

235. A register is defined as


a) The group of latches for storingone bit of information
b) The group of latches for storing n-bit of information
c) The group of flip-flops suitable forstoring one bit of information
d) The group of flip-flops suitable forstoring binary information
Answer: d

Explanation: A register is defined as the group of flip-flops suitable for storing binary information.
Each flip-flop is a binary cell capable of storingone bit of information. The data in a register can be
transferred from oneflip-flop to another.

236. The register is a type of


a) Sequential circuit
375
b) Combinational circuit
c) CPU
d) Latches
Answer: a
Explanation: Register’s output depends on the past and present states of the inputs. The device
whichfollows these properties is termed as a sequential circuit. Whereas combinational circuits
only depend on the present values of inputs.

237. How many types of registersare?


a) 2
b) 3
c) 4
d) 5
Answer: c
Explanation: There are 4 types of shift registers, viz., Serial-In/Serial-Out, Serial-In/Parallel-Out,
Parallel- In/Serial-Out and Parallel-In/Parallel-Out.

238. The main difference between aregister and a counter is


a) A register has no specific sequenceof states
b) A counter has no specific sequenceof states
c) A register has capability to storeone bit of information, but counterhas n-bit
d) A register counts data
Answer: a
Explanation: The main difference between a register and a counter isthat a register has no specific
sequence of states except in certain specialized applications.

239. In D register, ‘D’ stands for


a) Delay
b) Decrement
c) Data
d) Decay
Answer: c
Explanation: D stands for “data” incase of flip-flops and not [Link] are made of a group of
flip-flops.

240. Registers capable of shifting inone direction is


a) Universal shift register
b) Unidirectional shift register

376
c) Unipolar shift register
d) Unique shift register
Answer: b
Explanation: The register capable of shifting in one direction is unidirectional shift register. The
register capable of shifting in both directions is known as a bidirectionalshift register.

241. A register that is used to storebinary information is called


a) Data register
b) Binary register
c) Shift register
d) D – Register
Answer: b
Explanation: A register that is used tostore binary information is called a binary register. A register
in which data can be shifted is called shift register.

242. A shift register is defined as__________


a) The register capable of shiftinginformation to another register
b) The register capable of shifting information either to the right or tothe left
c) The register capable of shiftinginformation to the right only
d) The register capable of shiftinginformation to the left only
Answer: b
Explanation: The register capable of shifting information either to the right or to the left is termed
as shift register. A register in which data canbe shifted only in one direction is called unidirectional
shift register, while if data can shifted in both directions, it is known as a bidirectional shift register.

243. How many methods of shiftingof data are available?


a) 2
b) 3
c) 4
d) 5
Answer: a
Explanation: There are two types ofshifting of data are available and
these are serial shifting & parallelshifting.

244. In serial shifting method, datashifting occurs


a) One bit at a time
b) simultaneously

377
c) Two bit at a time
d) Four bit at a time
Answer: a
Explanation: As the name suggests serial shifting, it means that data shifting will take place one bit
at a time for each clock pulse in a serial fashion. While in parallel shifting, shifting will take place
with all bits simultaneously for each clock pulse ina parallel fashion.

245. Memory is a/an


a) Device to collect data from othercomputer
b) Block of data to keep dataseparately
c) Indispensable part of computer
d) Device to connect through all overthe world
Answer: c
Explanation: Memory is an indispensable unit of a computer andmicroprocessor based systems
whichstores permanent or temporary data.

246. The instruction used in a program for executing them is storedin the
a) CPU
b) Control Unit
c) Memory
d) Microprocessor
Answer: c
Explanation: All of the program and the instructions are stored in the memory. The processor
fetches it asand when required.

247. A flip flop stores


a) 10 bit of information
b) 1 bit of information
c) 2 bit of information
d) 3-bit information
Answer: b
Explanation: A flip-flop has capability to store 1 bit of information. It can beused further after
erasing previous information.

248. A register is able to hold


a) Data
b) Word

378
c) Nibble
d) Both data and word
Answer: b
Explanation: Register is also a part ofmemory inside a computer. It standsthere to hold a word. A
word is a group of 16-bits or 2-bytes.

249. A register file holds


a) A large number of word ofinformation
b) A small number of word ofinformation
c) A large number of programs
d) A modest number of words ofinformation
Answer: d
Explanation: A register file is differentfrom a simple register because of capability to hold a modest
number of words of information. A word is a group of 16-bits or 2-bytes.

250. The very first computer memoryconsisted of


a) A small display
b) A large memory storageequipment
c) An automatic keyboard input
d) An automatic mouse input
Answer: b
Explanation: The very first computermemory consisted of a minute magnetic toroid, which
requiredlarge, bulky circuit boards stored inlarge cabinates.

251. A minute magnetic toroid is alsocalled as


a) Large memory
b) Small memory
c) Core memory
d) Both small and large memory
Answer: c
Explanation: A minute magnetic toroid is also called as core memory which is made up of a
semiconductor.A semiconductor is a device whose electrical conductivity lies between that of
conductor and insulator.

252. Which one of the following hascapability to store data in extremelyhigh densities?
a) Register
b) Capacitor
c) Semiconductor

379
d) Flip-Flop
Answer: c
Explanation: Semiconductor has capability to store data in extremelyhigh densities.

253. A large memory is compressed into a small one by using


a) LSI semiconductor
b) VLSI semiconductor
c) CDR semiconductor
d) SSI semiconductor
Answer: b
Explanation: VLSI (Very Large Scale Integration) semiconductor is used inmodern computers to
short the size of memory.

254. VLSI chip utilizes


a) NMOS
b) CMOS
c) BJT
d) All of the Mentioned
Answer: d
Explanation: VLSI (Very Large-Scale Integration) is a memory chip which is made up of NMOS,
CMOS, BJT, andBic MOS. It can include 10,000 to 100,000 gates per IC.

255. CD-ROM refers to


a) Floppy disk
b) Compact Disk-Read Only Memory
c) Compressed Disk-Read OnlyMemory
d) Compressed Disk- Random AccessMemory
Answer: b
Explanation: CD-ROM refers to Compact Disk-Read Only Memory.

256. Data stored in an electronicmemory cell can be accessed at random and on demand using

a) Memory addressing
b) Direct addressing
c) Indirect addressing
d) Control Unit
Answer: b
380
Explanation: Direct addressing eliminates the need to process alarge stream of irrelevant data in
order to the desired data word.

257. The full form of PLD is


a) Programmable Large Device
b) Programmable Long Device
c) Programmable Logic Device
d) Programmable Lengthy Device
Answer: c
Explanation: The full form of PLD isProgrammable Logic Device.

258. The evolution of PLD began with


Answer: a
Explanation: The evolution of PLD (Programmable Logic Device) began with Programmable Read
Only Memory (i.e. PROM). Here, the ROM can be externally programmed as perthe user.

259. A ROM is defined as


a) Read Out Memory
b) Read Once Memory
c) Read Only Memory
d) Read One MemoryView Answer
Answer: c
Explanation: A ROM is defined as Read Only Memory which can read the instruction stored in a
computer.

260. Which of the circuits in figure (ato d) is the sum-of-products implementation of figure (e)?
a. EROM
b. RAM
c. PROM
d. EEPROM

261. Which of the following logicexpressions represents the logic diagram shown?

381
a) X=AB’+A’B
b) X=(AB)’+AB
c) X=(AB)’+A’B’
d) X=A’B’+AB
a) a
b) b
c) c
d) d
Answer: d
Explanation: SOP means Sum of Products form which represents the sum of product terms having
variables in complemented as well asin uncomplemented form. Here, the diagram of d contains
the OR gate followed by the AND gates, so it is in SOP form.
Answer: d
Explanation: 1st output of AND gateis = A’B’ 2nd AND gate’s output is = AB and, OR gate’s output is
= (A’B’)+(AB) = AB+ A’B’.

262. The device shown here is mostlikely a


a) Comparator
b) Multiplexer
c) Inverter
d) Demultiplexer
Answer: d

382
Explanation: The given diagram is demultiplexer, because it takes singleinput & gives many
outputs. A demultiplexer is a combinational circuit that takes a single output and latches it to
multiple outputs depending on the select lines.

263. What type of logic circuit is represented by the figure shownbelow?

a) XOR
b) XNOR
c) AND
d) XAND
Answer: b
Explanation: After solving the circuit we get (A’B’)+AB as output, which is XNOR operation. Thus, it
will produce1 when inputs are even number of 1sor all 0s, and produce 0 when input isodd number
of 1s.

264. For a two-input XNOR gate, withthe input waveforms as shown


below, which output waveform iscorrect?
a) d
b) a
c) c
d) b
Answer: a
Explanation: When both inputs are same then the o/p is high for a XNORgate.
i.e., A B O/P0 0 1
010
100
1 1 1.
Thus, it will produce 1 when inputs are even number of 1s or all 0s, and produce 0 when input is
odd numberof 1s.

265. Which of the following combinations of logic gates can


decode binary 1101?
a. One 4-input AND gate
383
b. One 4-input AND gate, oneinverter
c. One 4-input AND gate, one OR gate
d. One 4-input NAND gate, oneinverter

Answer: b
Explanation: For decoding any number output must be high for thatcode and this is possible in One
4- input NAND gate, one inverter optiononly. A decoder is a
combinational circuit that converts binary data to n-coded data upto 2n outputs.

266. What is the indication of a shortto ground in the output of a driving gate?
a) Only the output of the defectivegate is affected
b) There is a signal loss to all loadgates
c) The node may be stuck in eitherthe HIGH or the LOW state
d) The affected node will be stuck inthe HIGH state
Answer: b
Explanation: Short to ground in the output of a driving gate indicates of asignal loss to all load
gates. This results in information being disruptedand loss of data.

267. For the device shown here, assume the D input is LOW, both S inputs are LOW and the input is
[Link] is the status of the Y’ outputs?
a) All are HIGH
b) All are LOW
c) All but Y0 are LOW
d) All but Y0 are HIGH
Answer: d
Explanation: In the given diagram, S0and S1 are selection bits. So,
I/P S0 S1 O/PD = 0 0 0 Y0
D = 0 0 1 Y1
D = 0 1 0 Y2
D = 0 1 1 Y3
Hence, inputs are S0 and S1 are Lowmeans 0, so output is Y0 and rest allare HIGH.

268. The carry propagation can beexpressed as


a) Cp = AB
b) Cp = A + B
c) All but Y0 are LOW
d) All but Y0 are HIGH
Answer: b
Explanation: This happens in parallel adders (where we try to add numbersin parallel via more than
384
one adders).A carry propagation occurs when carry from one adder needs to be forwarded to other
adder and that second adder is holding the computation (addition) because carryfrom first adder
has not come yet. So,there is a slight delay for second adder and this is known as carry
propagation.

269. 3 bits full adder contains


a) 3 combinational inputs
b) 4 combinational inputs
c) 6 combinational inputs
d) 8 combinational inputs
Answer: d
Explanation: Full Adder is a combinational circuit with 3 input bitsand 2 output bits CARRY and
SUM. Three bits full adder requires 23 = 8 combinational circuits.

270. The ‘heart’ of the processorwhich performs many different operations


a) Arithmetic and logic unit
b) Motherboard
c) Control Unit
d) Memory
Answer: a
Explanation: The Arithmetic and logicunit performs all the basic operationsof the computer
system. It performs all the arithmetic(+,-,*,/,etc) as well as the logical operations( AND, OR, NOT,
etc.).

271. ALU is the place where the actual executions of instructions takeplace during the processing
operation.
a) True
b) False
Answer: a
Explanation: ALU is a combinational electronic circuit which basically performs all the logical or the
bitwiseoperations and the arithmetic operations. Therefore, it is the place where the actual
executions of instructions take place.

272. Which of the following is not abitwise operator?


a) |
b) ^
c) .
d) <<

385
Answer: c
Explanation: All except the dot(.)operator are bitwise operators.
| : Bitwise OR
^ : Bitwise XOR
<< : Shift Left

273. The sign magnitude representation of -1 is a) 0001


b) 1110
c) 1000
d) 1001

Answer: d
Explanation: The first leftmost bit i.e. the most significant bit in the sign magnitude represents if
the number is positive or negative. If the MSB is 1,the number is negative else if it is 0, the number
is positive. Here,
+1=0001 and for -1=1001.

274. IEEE stands for


a) Instantaneous ElectricalEngineering
b) Institute of Emerging ElectricalEngineers
c) Institute of Emerging ElectronicEngineers
d) Institute of Electrical andelectronics engineers
Answer: d
Explanation: The IEEE is an organization of professionals in thefield of electronics and electrical
engineering. IEEE has given certainstandards of its own which are followed in the field of computer
science and electrical engineering.

275. The ALU gives the output of the operations and the output is stored inthe
a) Memory Devices
b) Registers
c) Flags
d) Output Unit
Answer: b
Explanation: Any output generated by the ALU gets stored in the registers. The registers are the
temporary memory locations withinthe processor that are connected bysignal paths to the CPU.

278. The process of division onmemory spaces is called


a) Paging
b) Segmentation
c) Bifurcation
386
d) Dynamic Division
Answer: b
Explanation: The memory space isdivided into segments of dynamic
the number of 1 bit in any [Link] resultant bit is called the parity bit. The main aim of the
parity bit is to check for errors.

281. The bitwise complement of 0 is


size. The programmer is aware of the segmentation and can reallocate the
segments accordingly.

279. Number of bits in ALU is


a) 4
b) 8
c) 16
d) 2
Answer: c
Explanation: Arithmetic and Logic Unit consists of 16bits. They performcertain Arithmetic and
bitwise operations (add, subtract, AND, OR, XOR, Increment, decrement, shift).

280. Which flag indicates the numberof 1 bit that results from an operation?
a) Zero
b) Parity
c) Auxiliary
d) Carry
Answer: b
Explanation: The parity flag indicates
a) 00000001
b) 10000000
c) 11111111
d) 11111110

Answer: c
Explanation: Bitwise complement isbasically used to convert all the 0 digits to 1 and the 1s to 0s.
So, for 0 = 00000000(in 8-bits) ::: 11111111(1s complement). The bitwise complement is often
referredto as the 1s complement.

282. Unicode provides a consistentway of encoding multilingual plain text.


a) True
b) False

387
Answer: a
Explanation: Unicode defines codesfor characters used in all major languages of the world. It is a
coding system which supportsalmost all the languages. It defines special codes for different
characters,symbols, diacritics, etc.

283. Which of the following is not atype of numeric value in zoned format?
a) Positive
b) Negative
c) Double
d) Unsigned
Answer: c
Explanation: The zoned format canrepresent numeric values of type Positive, negative and
unsigned numbers. A sign indicator is used inthe zone position of the rightmost digit.

284. The sign indicator of unsignednumbers is


a) C
b) D
c) F
d) X
Answer: c
Explanation: A sign indicator is used in the zone position of the rightmostdigit. A sign indicator C is
used for positive, D for negative and F is usedfor negative numbers.
285. The EBCDIC value of the number345 in zoned format is
a) F3F4F5
b) E3E4E5
c) F3F4C5
d) F3F4D5
Answer: a
Explanation: F is used for the representation of unsigned numberstherefore, F3F4F5 represents
345.
F3F4C5 represents +345. F3F4D5represents -345.

286. Which of the following logic families has the highest maximumclock frequency?
a) S-TTL
b) AS-TTL
c) HS-TTL
d) HCMOS

388
Answer: b
Explanation: AS-TTL (Advanced Schottky) has a maximum clock frequency of 105 MHz. S-TTL
(Schottky High Speed TTL) has 100 MHz. Found nothing as HS-TTL. Thereare H and S separate
TTL. HCMOS has50 MHz clock frequency.

287. Why is the fan-out of CMOSgates frequency dependent?


a) Each CMOS input gate has a specific propagation time and this limits the number of different
gates that can be connected to the output of a CMOS gate
b) When the frequency reaches thecritical value the gate will only be capable of delivering 70% of
the normal output voltage and consequently the output power willbe one-half of normal and this
defines the upper operating frequency
c) The higher number of gates attached to the output the more frequently they will have to be
serviced thus reducing the frequency at which each will be serviced with aninput signal
d) The input gates of the FETs are predominantly capacitive and as thesignal frequency increases
the capacitive loading also increases thereby limiting the number of loadsthat may be attached to
the output of the driving gate

Answer: d
Explanation: Fan out is the measure of maximum number of inputs that asingle logic gate output
can drive. Actually, power dissipation in CMOS circuits depends on clock [Link] the
frequency increases Pd alsoincreases so fan-out depends on frequency.

288. Logic circuits that are designatedas buffers, drivers or buffers/drivers are designed to have:
a) A greater current/voltage capability than an ordinary logiccircuit
b) Greater input current/voltagecapability than an ordinary logiccircuit
c) A smaller output current/voltagecapability than an ordinary logic
d) Greater the input and output current/voltage capability than anordinary logic circuit
Answer: a
Explanation: Buffer circuits are usually incorporated to isolate the input from the output. Logic
circuits that are designated as buffers, driversor buffer/drivers are designed to have a greater
current/voltage capability than an ordinary logic circuit.

289. Which of the following will notnormally be found on a data sheet?


a) Minimum HIGH level outputvoltage
b) Maximum LOW level outputvoltage
c) Minimum LOW level outputvoltage
d) Maximum HIGH level input current
Answer: c
Explanation: Minimum LOW level output voltage will not normally befound on a data sheet.

389
290. Which of the following logic families has the shortest propagationdelay?
a) S-TTL
b) AS-TTL
c) HS-TTL
d) HCMOS
Answer: b
Explanation: AS-TTL (Advanced Schottky) has a maximum clock frequency that is 105 MHz. So,
the propagation delay will be given by 1/105 sec which is the lowest one. Itis followed by S-TTL
and HCMOS in terms of increasing propagation delay.

291. ARM stands for


a) Advanced Rate Machines
b) Advanced RISC Machines
c) Artificial Running Machines
d) Aviary Running Machines
Answer: b
Explanation: ARM is a type of systemarchitecture.

292. The main importance of ARMmicro-processors is providing operation with


a) Low cost and low powerconsumption
b) Higher degree of multi-tasking
c) Lower error or glitches
d) Efficient memory management
Answer: a
Explanation: The Stand alone featureof the ARM processors is that they’reeconomically viable.

293. ARM processors where basicallydesigned for


a) Main frame systems
b) Distributed systems
c) Mobile systems
d) Super computers
Answer: c
Explanation: These ARM processorsare designed for handheld devices.

294. The ARM processors don’tsupport Byte addressability.


a) True
b) False

390
Answer: b
Explanation: The ability to store datain the form of consecutive bytes.

295. The address space in ARM is


a) 224
b) 264
c) 216
d) 232

Answer: d Explanation: None.

296. have been developedspecifically for pipelined systems.


a) Utility software
b) Speed up utilities
c) Optimizing compilers
d) None of the mentioned
Answer: c
Explanation: The compilers which aredesigned to remove redundant partsof the code are called as
optimizing compilers.

297. The pipelining process is alsocalled as


a) Superscalar operation
b) Assembly line operation
c) Von Neumann cycle
d) None of the mentioned
Answer: b
Explanation: It is called so because itperforms its operation at the assembly level.

298. The fetch and execution cyclesare interleaved with the help of
a) Modification in processorarchitecture
b) Clock
c) Special unit
d) Control unit
Answer: b
Explanation: The time cycle of theclock is adjusted to perform the interleaving.

299. Each stage in pipelining shouldbe completed within cycle.


a) 1
b) 2
c) 3
391
d) 4
Answer: a
Explanation: The stages in the pipelining should get completedwithin one cycle to increase the
speed of performance.

300. In pipelining the task which requires the least time is performedfirst.
a) True
b) False
Answer: b
Explanation: This is done to avoidstarvation of the longer task.

301. If a unit completes its task before the allotted time period, then
a) It’ll perform some other task in theremaining time
b) Its time gets reallocated to adifferent task
c) It’ll remain idle for the remainingtime
d) None of the mentioned
Answer: c Explanation: None.

302. To increase the speed of memory access in pipelining, wemake use of


a) Special memory locations
b) Special purpose registers
c) Cache
d) Buffers
Answer: c
Explanation: By using the cache we can reduce the speed of memoryaccess by a factor of 10.

303. The periods of time when theunit is idle is called as


a) Stalls
b) Bubbles
c) Hazards
d) Both Stalls and Bubbles
Answer: d
Explanation: The stalls are a type ofhazards that affect a pipelined system.

304. The contention for the usage ofa hardware device is called
a) Structural hazard
b) Stalk
392
c) Deadlock
d) None of the mentioned
Answer: a Explanation: None.

305. The situation wherein the data of operands are not available is called
a) Data hazard
b) Stock
c) Deadlock
d) Structural hazard
Answer: a
Explanation: Data hazards are generally caused when the data is notready on the destination side.

306. The decimal numbers represented in the computer are called as floating point numbers, as
the decimal point floats through thenumber.
a) True
b) False
Answer: a
Explanation: By doing this the computer is capable of accommodating the large floatnumbers also.

307. The numbers written to the power of 10 in the representation of decimal numbers are called
as
a) Height factors
b) Size factors
c) Scale factors
d) None of the mentioned
Answer: c
Explanation: These are called as scalefactors cause they’re responsible in determining the degree
of specification of a number.

308. If the decimal point is placed tothe right of the first significant digit,then the number is called

a) Orthogonal
b) Normalized
c) Determinate
d) None of the mentioned
Answer: b Explanation: None.

309. constitute therepresentation of the floatingnumber.


393
a) Sign
b) Significant digits
c) Scale factor
d) All of the mentioned
Answer: d
Explanation: The following factors areresponsible for the representation of the number.

310. The sign followed by the stringof digits is called as


a) Significant
b) Determinant
c) Mantissa
d) Exponent
Answer: c
Explanation: The mantissa alsoconsists of the decimal point.

311. In IEEE 32-bit representations, the mantissa of the fraction is said tooccupy bits.
a) 24
b) 23
c) 20
d) 16
Answer: b
Explanation: The mantissa is made tooccupy 23 bits, with 8 bit exponent.

312. The normalized representationof 0.0010110 * 2 9 is


a) 0 10001000 0010110
b) 0 10000101 0110
c) 0 10101010 1110
d) 0 11110100 11100

Answer: b
Explanation: Normalized representation is done by shifting thedecimal point.

313. The 32-bit representation of thedecimal number is called as


a) Double-precision
b) Single-precision
c) Extended format
d) None of the mentioned
Answer: b Explanation: None.

394
314. In 32 bit representation the scale factor as a range of
a) -128 to 127
b) -256 to 255
c) 0 to 255
d) None of the mentioned
Answer: a
Explanation: Since the exponent fieldhas only 8 bits to store the value.

315. In double precision format, thesize of the mantissa is


a) 32 bit
b) 52 bit
c) 64 bit
d) 72 bit
Answer: b
Explanation: The double precisionformat is also called as 64 bit representation.

316. The DMA differs from the interrupt mode by


a) The involvement of the processorfor the operation
b) The method of accessing the I/Odevices
c) The amount of data transferpossible
d) None of the mentioned
Answer: d
Explanation: DMA is an approach ofperforming data transfers in bulk between memory and the
external device without the intervention ofthe processor.

317. The DMA transfers are performed by a control circuit calledas


a) Device interface
b) DMA controller
c) Data controller
d) Overlooker
Answer: b
Explanation: The Controller performs the functions that would normally be carried out by the
processor.

318. In DMA transfers, the requiredsignals and addresses are given by the
a) Processor
b) Device drivers
395
c) DMA controllers
d) The program itself
Answer: c
Explanation: The DMA controller acts as a processor for DMA transfers and overlooks the entire
process.

319. After the completion of the DMAtransfer, the processor is notified by

a) Acknowledge signal
b) Interrupt signal
c) WMFC signal
d) None of the mentioned
Answer: b
Explanation: The controller raises aninterrupt signal to notify the processor that the transfer was
complete.

320. The DMA controller has registers.


a) 4
b) 2
c) 3
d) 1
Answer: c
Explanation: The Controller uses the registers to store the starting address, word count and the
status ofthe operation.

330. When the R/W bit of the statusregister of the DMA controller is setto 1.
a) Read operation is performed
b) Write operation is performed
c) Read & Write operation isperformed
d) None of the mentioned
Answer: a Explanation: None.
331. The controller is connected tothe
a) Processor BUS
b) System BUS
c) External BUS
d) None of the mentioned
Answer: b
396
Explanation: The controller is directlyconnected to the system BUS to provide faster transfer of
data.

332. Can a single DMA controller perform operations on two differentdisks simultaneously?
a) True
b) False
Answer: a
Explanation: The DMA controller canperform operations on two differentdisks if the appropriate
details are known.

333. The technique whereby the DMA controller steals the access cycles of the processor to
operate iscalled
a) Fast conning
b) Memory Con
c) Cycle stealing
d) Memory stealing
Answer: c
Explanation: The controller takes over the processor’s access cycles and performs memory
operations.

334. The technique where the controller is given complete access tomain memory is
a) Cycle stealing
b) Memory stealing
c) Memory Con
d) Burst mode
Answer: d
Explanation: The controller is givenfull control of the memory access cycles and can transfer
blocks at a faster rate.

335. The side of the interface circuits,that has the data path and the control signals to transfer
data between interface and device is
a) BUS side
b) Port side
c) Hardwell side
d) Software side
Answer: b
Explanation: This side connects thedevice to the motherboard.

336. What is the interface circuit?


397
a) Helps in installing of the softwaredriver for the device
b) Houses the buffer that helps indata transfer
c) Helps in the decoding of theaddress on the address BUs
d) None of the mentioned
Answer: c
Explanation: Once the address is puton the BUS the interface circuit decodes the address and uses
the buffer space to transfer data.

337. The conversion from parallel to serial data transmission and vice versa takes place inside the
interfacecircuits.
a) True
b) False
Answer: a
Explanation: The Interrupt-request line is a control line along which thedevice is allowed to send the
interrupt signal.

338. The return address from the interrupt-service routine is stored onthe
a) System heap
b) Processor register
c) Processor stack
d) Memory
Answer: c
Explanation: The Processor after servicing the interrupts as to load theaddress of the previous
process and this address is stored in the stack.

339. The signal sent to the devicefrom the processor to the device after receiving an interrupt is
a) Interrupt-acknowledge
b) Return signal
c) Service signal
d) Permission signal
Answer: a
Explanation: The Processor upon receiving the interrupt should let the device know that its request
is received.

340. The interrupt-request line is apart of the


a) Data line

398
b) Control line
c) Address line
d) None of the mentioned

Answer: b
Explanation: By doing this the interface circuits provide a betterinterconnection between devices.

341. When the process is returnedafter an interrupt service should be loaded again.
i) Register contents
ii) Condition codes
iii)Stack contents
iv)Return addresses
a) i, iv
b) ii, iii and iv
c) iii, iv
d) i, ii
Answer: d
Explanation: The delay in servicing of an interrupt happens due to the time is taken for contact
switch to take place.

342. The time between the receiverof an interrupt and its service is
a) Interrupt delay
b) Interrupt latency
c) Cycle time
d) Switching time
Answer: b
Explanation: The delay in servicing ofan interrupt happens due to the timeis taken for contact
switch to take place.

343. Interrupts form an importantpart of systems.


a) Batch processing
b) Multitasking
c) Real-time processing
d) Multi-user
Answer: c
Explanation: This forms an importantpart of the Real time system since if aprocess arrives with
greater priority then it raises an interrupt and the other process is stopped and the interrupt will be
serviced.
399
344. A single Interrupt line can be used to service n different devices.
a) True
b) False
Answer: a Explanation: None.

345. *@Ac# is a type of


data.
a) Symbolic
b) Alphanumeric
c) Alphabetic
d) Numeric

Answer: b
Explanation: Alphanumeric data consists of symbols. Alphanumericdata may be a letter, either in
uppercase or lowercase or some special symbols like #,^,*,(, etc.)

346. Which of the following is not avalid representation in bits?


a) 8-bit
b) 24-bit
c) 32-bit
d) 64-bit

Answer: b
Explanation: There are no criteria likethe 24-bit representation of numbers. Numbers can be written
in 8-bit, 16-bit, 32-bit and 64-bit as per the IEEE format.

347. What are the entities whosevalues can be changed called?


a) Constants
b) Variables
c) Modules
d) Tokens

Answer: b
Explanation: Variables are the data entities whose values can be changed. Constants have a fixed
value. Tokens are the words which are easily identified by the compiler.

348. Which of the following is not abasic data type in C language?


a) float
b) int
c) real
d) char

400
Answer: c
Explanation: There are 5 basic datatypes in C language: int, char, float,double, void.
Int is for the representation of integers, char is for strings and characters, float and double are for
floating point numbers whereas voidis a valueless special data type.

349. BOOLEAN is a type of data typewhich basically gives a tautology or fallacy.


a) True
b) False

Answer: a
Explanation: A Boolean representation is for giving logical values. It returns either true or [Link] a
result gives a truth value, it is called tautology whereas if it returnsa false term, it is referred to as
fallacy.

350. What does FORTRAN stands for?


a) Formula Transfer
b) Formula Transformation
c) Formula Translation
d) Format Transformation

Answer: c
Explanation: FORTRAN is a type of computer language. It was developedfor solving mathematical
and scientific problems. It is very commonly used among the scientific community.

351. The program written by the programmer in high level language iscalled
a) Object Program
b) Source Program
c) Assembled Program
d) Compiled Program

Answer: b
Explanation: The program written bythe programmer is called a source
d) Data Objects

Answer: b
Explanation: Attributes can determine how any location can be used. Attributes can be type, name,
component, etc. Data objects are thevariables and constants in a program.

352. A standardized language usedfor commercial applications.


a) C
b) Java
c) COBOL
d) FORTRAN
401
Answer: c
Explanation: COBOL is a language used in business and commercial applications. It stands for
CommonBusiness Oriented Language. It is imperative, procedural as well as object oriented
language.

353. define how thelocations can be used.


a) Data types
b) Attributes
c) Links
a) (11.375)10
b) (10.123)10
c) (11.175)10
d) (9.23)10

Answer: a
Explanation: Binary to Decimal conversion is obtained by multiplying2 to the power of base index
along with the value at that index position.1 * 23 + 0 * 22 + 1 * 21 +1*20 + 0 * 2-1 +1 * 2-2 + 1 * 2-3 =
(11.375)10 Hence, (1011.011)2 = (11.375)10

354. An important drawback ofbinary system is


a) It requires very large string of 1’sand 0’s to represent a decimal number
b) It requires sparingly small string of1’s and 0’s to represent a decimal number
c) It requires large string of 1’s andsmall string of 0’s to represent a decimal number
d) It requires small string of 1’s andlarge string of 0’s to represent a decimal number

Answer: a
Explanation: The most vital drawbackof binary system is that it requires
very large string of 1’s and 0’s to represent a decimal number. Hence,Hexadecimal systems are
used by processors for calculation purposes as it compresses the long binary strings into small
parts.

355. The decimal equivalent of theoctal number (645)8 is


a) (450)10
b) (451)10
c) (421)10
d) (501)10

Answer: c
Explanation: Octal to Decimal conversion is obtained by multiplying8 to the power of base index
along with the value at that index [Link] decimal equivalent of the octal number (645)8 is 6 *
82 + 4 * 81 + 5 * 80 = 6 * 64 + 4 * 8 + 5 = 384 + 32 + 5 =
(421)10.

356. The largest two-digit hexadecimal number is


402
a) (FE)16
b) (FD)16
c) (FF)16
d) (EF)16

Answer: c
Explanation: (FE)16 is 254 in decimalsystem, while (FD)16 is 253. (EF)16 is239 in decimal system.
And, (FF)16 is 255. Thus, The largest two-digithexadecimal number is (FF)16.

357. Representation of hexadecimalnumber (6DE)H in decimal:


a) 6 * 162 + 13 * 161 + 14 * 160
b) 6 * 162 + 12 * 161 + 13 * 160
c) 6 * 162 + 11 * 161 + 14 * 160
d) 6 * 162 + 14 * 161 + 15 * 160

Answer: a
Explanation: Hexadecimal to Decimalconversion is obtained by multiplying16 to the power of base
index along with the value at that index [Link] hexadecimal number D & E represents 13 & 14
respectively.
So, 6DE = 6 * 162 + 13 * 161 + 14 *
160.

358. The quantity of double word is

a) 16 bits
b) 32 bits
c) 4 bits
d) 8 bits

Answer: b
Explanation: One word means 16 bits,Thus, the quantity of double word is 32 bits.

359. What is the addition of the binary numbers 11011011010 and010100101?


a) 0111001000
b) 1100110110
c) 11101111111
d) 10011010011

Answer: c
Explanation: The rules for BinaryAddition are :
0+0=0
0+1=1
1+0=1

403
1 + 1 = 0 ( Carry 1)
1
1+0=1
1 + 1 = 0 ( Carry 1)
111111
101101
+011011
1001000
Therefore, the addition of 101101 +011011 = 1001000.

360. Perform binary subtraction:101111 – 010101 = ?


a) 100100
b) 010101
c) 011010
d) 011001
11011011010
+00010100101
11101111111

361. Perform binary addition: 101101


+ 011011 = ?a) 011010
b) 1010100
c) 101110
d) 1001000

Answer: d
Explanation: The rules for BinaryAddition are :
0+0=0
0+1=1
Answer: c
Explanation: The rules for BinarySubtraction are :
0–0=0
0 – 1 = 1 (Borrow
1–0=1
1–1=0
101111
- 0 1 0 1 0 10 1 1 0 1 0

Therefore, The subtraction of 101111


– 010101 = 011010. 01001
361. Binary subtraction of 100101 –011110 is 010010
0000000
404
01001000
000000000
a) 000111
b) 111000
c) 010101
d) 101010

Answer: a
Explanation: The rules for BinarySubtraction are :
0–0=0
0 – 1 = 1 ( Borrow 1)
1–0=1
1–1=0
100101
- 0 1 1 1 1 00 0 0 1 1 1 Therefore, The subtraction of 100101
– 011110 = 000111.

362. Perform multiplication of the binary numbers: 01001 × 01011 = ?a) 001100011
b) 110011100
c) 010100110
d) 101010111

Therefore, 01001 × 01011 =


001100011.

365. 100101 × 0110 = ?


a) 1011001111
b) 0100110011
c) 101111110
d) 0110100101

Answer: c
Explanation: The rules for binarymultiplication are:
0*0=0
0*1=0
1*0=0
1*1=1

Answer: a
Explanation: The rules for binarymultiplication are:
0*0=0 100101
0*1=0 x 0110
1*0=0
1*1=1 000000
1001010
405 10010100
000000000
Therefore, 100101 x 0110 =
01001
x01011
_
011011110

366. n multiplication of (10.10) and(01.01), we get


a) 101.0010
b) 0010.101
c) 011.0010
d) 110.0011

Answer: c
Explanation: The rules for binarymultiplication are:
0*0=0
0*1=0
1*0=0
1*1=1
1 0.1 0
x 0 1.0 1
1010
00000
101000
0000000

0 1 1.0 0 1 0
Therefore, 10.10 x 01.01 = 011.0010.

367. Divide the binary numbers:111101 ÷ 1001 and find the remainder
a) 0010
b) 1010
c) 1100
d) 0011

Answer: d
Explanation: Binary Division is
accomplished using long divisionmethod.

406
1001)111101(11
1001

01100
1001

0111
Therefore, the remainder of 111101 ÷
1001 = 0111.
368. CPU has built-in ability to execute a particular set of machineinstructions, called as _
a) Instruction Set
b) Registers
c) Sequence Set
d) User instructions
Answer: a
Explanation: An instruction is any taskwhich is to be performed by the processor. Instructions are
stored in the register. Instruction set is the set of machine instructions.

369. Opcode indicates the operationsto be performed.


a) True
b) False
Answer: a
Explanation: Every instruction has an opcode. Additionally, it may have one or more operands and
the op codeindicates the operation to be performed.

370. The length of a register is called


a) word limit
b) word size
c) register limit
d) register size
Answer: b
Explanation: The length of a register is called word size. It tells the numberof bits a register can
store.
Registers are a part of the CPU.

371. The holds the contents of the accessed memoryword.


a) MAR
b) MBR
407
c) PC
d) IR
Answer: b
Explanation: The MBR holds thecontents of the accessed (read/written) memory word. MBR
stands for Memory BufferRegister.

372. Which of the following is not avisible register?


a) General Purpose Registers
b) Address Register
c) Status Register
d) MAR
Answer: d
Explanation: MAR or the memory address register is not a visible register. This register is user
inaccessible. It contains the addressof the memory block to be read or written to.

373. Which of the following is a datatransfer instruction?


a) STA 16-bit address
b) ADD A, B
c) MUL C, D
d) RET
Answer: a
Explanation: The instruction STA 16-bit address is a data transfer instruction.
STA means Store in Accumulator.

374. What is correct instruction if youwant the control to go to the location2000h?


a) MOV 2000h
b) MOV A, 2000h
c) JMP 2000h
d) RET 2000h

Answer: c
Explanation: The JMP instruction is used to move to a particular location.
377. New CPU whose instruction setincludes the instruction set of its predecessor CPU is said to
be In 8085 microprocessors, JMP with its predecessor.
statement tells the processor to go tolocation 2000h (here).

375. What kind of a flag is the signflag?


a) General Purpose
408
b) Status
c) Address
d) Instruction
Answer: b
Explanation: Sign flag is a type of status register or the flag register. It is used to indicate the sign
of certainbits.

376. The number of sign bits in a 32-bit IEEE format


a) 1
b) 11
c) 9
d) 23
Answer: a
Explanation: There is only 1 sign bit inall the standards. In a 32-bit format, there is 1 sign bit, 8 bits
for the exponent and 23 bits for the mantissa.
a) fully compatible
b) forward compatible
c) compatible
d) backward compatible
Answer: d
Explanation: The CPU is called backward compatible since it contains the instruction set of its
predecessor. Manufacturers tend to group their CPUs into families havingsimilar instruction set.

378. What does ASCII stand for?


a) American Standard Code forInformation Interchange
b) American Scientific Code forInformation Interchange
c) American Scientific Code forInterchanging Information
d) American Standard Code forInterchanging Information
Answer: a
Explanation: The ASCII codes are usedto represent the bits into symbols and vice versa. ASCII is
the American Standard Code which is used to exchange information.

379. The decimal representation forthe character ‘!’ in ASCII is

a) 31
b) 32
c) 33
409
d) 34
Answer: c
Explanation: The decimal representation of a few basiccharacters are:
33 : !
34 : ”
35: #
36 :$.

380. The two types of ASCII are


and
a) ASCII-4 and ASCII-8
b) ASCII-8 and ASCII-16
c) ASCII-7 and ASCII-8
d) ASCII-4 and ASCII-16
Answer: c
Explanation: The two types of ASCII are ASCII-7 and ASCII-8. ASCII-7 uses7 bits for the
representation of numbers and ASCII-8 uses 8-bits.

381. Any set of digits or alphabets aregenerally referred as

a) Characters
b) Symbols
c) Bits
d) Bytes
Answer: a
Explanation: We refer to the digits and alphabets generally as characters. A character is generally a
unit of information in computers.

382. The first 128 characters are thesame in both the types of ASCII i.e. ASCII-7 and ASCII-8.
a) True
b) False
Answer: a
Explanation: There are two types ofASCII codes: ASCII-7 and ASCII-8.
ASCII-7 uses 7 bits to represent a number whereas ASCII-8 uses 8-bitsto represent a number.

383. The number of characters thatcan be represented in ASCII-8 are


a) 128
b) 256

410
c) 32
d) 64
Answer: b
Explanation: ASCII-8 can represent 256 different characters. ASCII-8 uses
8-bits for the representation of
384. The zone of alphabetic characters from A to O in ASCII is
a) 1000
b) 0100
c) 0010
d) 0001

Answer: b
Explanation: The zone used by ASCII for alphabets is 0100. For e.g. A is represented as
0100(zone)0001(digit). The hex equivalent is 41 for A. The zone usedby numbers is 0011.

385. The representation of the number 8 in binary in ASCII-8 format


a) 00111000
b) 01001000
c) 1000
d) 00011000

Answer: a
Explanation: The ASCII-8 format will have 8 bits. The zone for the character 8 is 0011 and the digit
is 1000. Therefore, its representation is00111000.
a) 01011000
b) 00111000
c) 10001000
d) 00010100

Answer: a
Explanation: The binary coding for the letter X is 01011000. Here, 0101 is the zone whereas 1000 is
the [Link] alphabets from P to Z have the zone 0101.

387. Express the ASCII equivalent ofthe signed binary number (00110010)2.
a) 2
b) 1
c) A
d) ,

Answer: a
Explanation: The ASCII characters forthe remaining options are:
1 : 00110001
411
A : 01000001
, : 00101100.

388. Computer has a built-in systemclock that emits millions of regularlyspaced electric pulses per
called clock cycles.
a) second
b) millisecond
c) microsecond
d) minute
Answer: a
Explanation: The regularly spaced electric pulses per second are referred to as the clock cycles. All
thejobs performed by the processor are on the basis of clock cycles.

389. It takes one clock cycle toperform a basic operation.


a) True
b) False
Answer: a
Explanation: It takes exactly one clockcycle to perform a basic operation, such as moving a byte of
memory from a location to another location inthe computer.

390. The operation that does not involves clock cycles is


a) Installation of a device
b) Execute
c) Fetch
d) Decode
Answer: a
Explanation: Normally, several clockcycles are required to fetch, executeand decode a particular
program.
Installation of a device is done by thesystem on its own.

391. The number of clock cycles persecond is referred as


a) Clock speed
b) Clock frequency
c) Clock rate
d) Clock timing
Answer: a
Explanation: The number of clock cycles per second is the clock [Link] is generally measured in
gigahertz (109 cycles/sec) or megahertz (106 cycles/sec).

412
392. CISC stands for
a) Complex Information Sensed CPU
b) Complex Instruction Set Computer
c) Complex Intelligence Sensed CPU
d) Complex Instruction Set CPU
Answer: b
Explanation: CISC is a large instruction set computer. It has variable length instructions. It alsohas
variety of addressing modes.

393. Which of the following processorhas a fixed length of instructions?


a) CISC
b) RISC
c) EPIC
d) Multi-core
Answer: b
Explanation: The RISC which stands for Reduced Instruction set computerhas a fixed length of
instructions. It has a small instruction set. Also has reduced references to memory to retrieve
operands.

394. Processor which is complex andexpensive to produce is


a) RISC
b) EPIC
c) CISC
d) Multi-core
Answer: c
Explanation: CISC stands for complexinstruction set computer. It is mostlyused in personal
computers. It has a large instruction set and a variable length of instructions.

395. The architecture that uses atighter coupling between the compiler and the processor is
a) EPIC
b) Multi-core
c) RISC
d) CISC
Answer: a
Explanation: EPIC stands for Explicitlyparallel instruction computing. It hasa tighter coupling
between the compiler and the processor. It enables the compiler to extract maximum parallelism
in the original code.

396. MAR stands for


413
a) Memory address register
b) Main address register
c) Main accessible register
d) Memory accessible register
Answer: a
Explanation: The MAR stands for memory address register. It holds theaddress of the active
memory location.

397. A circuitry that processes that responds to and processes the basic instructions that are
required to drivea computer system is
a) Memory
b) ALU
c) CU
d) Processor
Answer: d
Explanation: The processor is responsible for processing the basicinstructions in order to drive a
computer. The primary functions of a
400. The 2’s complement of 15 is processor are fetched, decode and
execute.

398. The value of base in a decimalnumber system is


a) 8
b) 2
c) 10
d) 16
Answer: c
Explanation: A decimal number system consists of 10 digits from 0 to9.
The definition of base describes it as
a) 0000
b) 0001
c) 0010
d) 0100

Answer: b
Explanation: 2’s complement isobtained by adding 1 to the 1’scomplement of the number.
Here, Binary of 15 = 1111
1’s complement of 15= 0000
2’s complement of 15= 0000+1=0001.

414
399. Another name for base is a quantity to represent the number
of digits present in that particularnumber system.
Therefore, here, the base is 10.

400. Convert: (110)2 = ( )10.


a) 4
b) 5
c) 6
d) 9
Answer: c
Explanation: The base 2 represents that the number is binary ,whereas, the base 10 represents that
it is to beconverted to the decimal format.

[Link]: 22 * 1 + 21 * 1 + 20 *0 = 6.
a) root
b) radix
c) entity
d) median
Answer: b
Explanation: Another name for base is radix. Base refers to the number ofdigits that a particular
number system consists of.
The base of decimal number systemis 10, binary is 2 and so on.

402. The decimal equivalent of(0.101)2 will be _

a) 0.5
b) 0.625
c) 0.25
d) 0.875

Answer: b
Explanation: Since the base is 2 , it could be easily guessed that the number is binary. Conversion:
2-1 * 1
+ 2-2 * 0 + 2-3 * 1 = 0.625.

403. Which of the following is not apositional number system?


a) Roman Number System
b) Octal Number System
c) Binary Number System
d) Hexadecimal Number System
415
Answer: a
Explanation: The Roman numbersystem isn’t a positional numbersystem since it uses symbols to
represent numbers.
The octal number system uses digitsfrom 0-7, the binary number systemuses digits from 0-1
whereas, the hexadecimal number system uses digits from 0-15.

404. The value of radix in binary number system is


a) 2
b) 8
c) 10
d) 1
Answer: a
Explanation: In a binary number system, the value of base or radix is
2. The binary system uses only twodigits for the representation of numbers; therefore, its base id
has chosen to be 2.

405. The binary equivalent of the decimal number 10 is a) 0010


b) 10
c) 1010
d) 010

Answer: c
Explanation: To get the binary equivalent of any number, we need to divide the number by 2 and
obtainthe remainders as : We then write the remainders in thereverse order as 1010 .

406. A computer language that is written in binary codes only is


a) machine language
b) C
c) C#
d) pascal

Answer: a
Explanation: Machine Language is written in binary codes only. It can beeasily understood by the
computer and is very difficult for us to understand. A machine language, unlike other languages,
requires no translators or interpreters.

407. The octal equivalent of1100101.001010 is


a) 624.12
b) 145.12
c) 154.12
d) 145.21
416
Answer: b
Explanation: The octal equivalent isobtained by grouping the numbersinto three, from right to left
beforedecimal and from right to left afterthe decimal place.
Here,i.e., 145.12 is the octal equivalent ofthe number.

408. The input hexadecimalrepresentation of 1110 is


a) 0111
b) E
c) 15
d) 14
Answer: b
Explanation: In hexadecimal numbersystem, 1110 = 15, which is represented by the alphabet E.
Some representations are:
A 10
B 11
C 12
D 13
E 14
F 15.

409. What could be the maximumvalue of a single digit in an octal number system?
a) 8
b) 7
c) 6
d) 5
Answer: b
Explanation: The maximum value inany number system is one less than the value of the base. The
base in an octal number system is 8, therefore, the maximum value of the single digitis 7. It takes
digits from 0 to 7.

410. In a number system, eachposition of a digit represents aspecific power of the base.
a) True
b) False
Answer: a
Explanation: In a number system, every digit is denoted by a specific power of base. Like in an
octal system, consider the number 113, itwill be represented as :82 * 1 + 81 * 1 + 80 *3.

411. The maximum number of bitssufficient to represent an octal number in binary is _


a) 4
417
b) 3
c) 7
d) 8
Answer: b
Explanation: The octal number system comprises of only 8 [Link], three bits (23 = 8) are
sufficient to represent any octal number in the binary format.

412. The binary number 111 in octalformat is


a) 6
b) 7
c) 8
d) 5
Answer: b
Explanation: Certain binary to octalrepresentations are:
000=0
001=1
010=2
011=3
100=4
101=5
110=6
111=7

413. Convert (22)8 into its corresponding decimal number.


a) 28
b) 18
c) 81
d) 82
Answer: b
Explanation: To convert an octalnumber to decimal number:
81 * 2 + 80 * 2 = 16 + 2 = [Link], the decimal equivalent is 18.

414. What does the symbol D represent in a hexadecimal number system?


a) 8
b) 16
c) 13
d) 14

418
Answer: c
Explanation: The symbols A, B, C, D, Eand F represent 10, 11, 12, 13, 14 and15 respectively in a
hexadecimal system. This system comprises of 15 numbers in total: digits from 0-9 and symbols
from A to F.
c) 7
d) 8
Answer: a
Explanation: The hexadecimal number system comprises of only 15symbols: 10 digits and 5
symbols. Hence, three bits (24 = 16) are sufficient to represent any hexadecimal number in the
binaryformat.

417. The binary number 1110 inhexadecimal format is


415. ABC is a valid hexadecimal
number.
a) True
b) False
Answer: a
Explanation: In a hexadecimal number system, alphabets are used for the representation of
numbers from 10 to 15. Here, A represents 10,B represents 11 and C represents [Link], it is
a valid hexadecimal number.

416. The maximum number of bits sufficient to represent a hexadecimalnumber in binary:


a) 4
b) 3
a) 6
b) E
c) 14
d) 15
Answer: b
Explanation: Certain binary to hexadecimal representations are :1010=A
1011=B
1100=C
1101=D
1110=E
1111=F.

419
Language Design
Language design techniques are the most important topic to design the Programming Language
and to solve various types of problems in the discipline of Comp. Science and IT. The following are
the major topics covered in Language Design.
1. Programming Language Concepts
2. PL-Paradigms and Models
3. Programming Environments
4. Translation process

Programming Language Concepts


Computer programming language, any of various languages for expressing a setof detailed
instructions for a digital computer. Such instructions can be executed directly when they are in the
computer manufacturer-specific numerical form known as machine language, after a simple
substitution process when expressed in a corresponding assembly language, or after translation
from some “higher- level” language. Although there are many computer languages, relatively few
are widely used.

Machine and assembly languages are “low-level,” requiring a programmer tomanage explicitly all
of a computer’s idiosyncratic features of data storage and operation. In contrast, high-level
languages shield a programmer from worrying about such considerations and provide a notation
that is more easily written and read by programmers.

Language Types
Machine and assembly languages
A machine language consists of the numeric codes for the operations that a particular computer
can execute directly. The codes are strings of 0s and 1s, or binary digits (“bits”), which are
frequently converted both from and to hexadecimal (base 16) for human viewing and modification.
Machine language instructions typically use some bits to represent operations, such as addition,
and some to represent operands, or perhaps the location of the next instruction. Machine language
is difficult to read and write, since it does not resemble conventional mathematical notation or
human language, and its codes vary from computer to computer.

Assembly language is one level above machine language. It uses short mnemonic codes for
instructions and allows the programmer to introduce names for blocks of memory that hold data.
One might thus write “add pay, total”instead of “0110101100101000” for an instruction that adds
two numbers.

Assembly language is designed to be easily translated into machine language. Although blocks of
data may be referred to by name instead of by their machine addresses, assembly language does
not provide more sophisticated means of organizing complex information. Like machine language,
assembly language requires detailed knowledge of internal computer architecture. It is useful when
such details are important, as in programming a computer to interact with input/output devices
(printers, scanners, storage devices, and so forth).

The built-in competence and defects of the various programming languages like FORTRAN, ALGOL,
COBOL, C, C++, and JAVA. List of Differences between higher and lower/machine level languages.
Basic theories like abstract syntax, interpretation, stack, heap organization, compilation
techniques, different types of 'type checking' and 'error checking' various for each Programming
420
language

Algorithmic languages
Algorithmic languages are designed to express mathematical or symbolic computations. They can
express algebraic operations in notation similar to mathematics and allow the use of subprograms
that package commonly usedoperations for reuse. They were the first high-level languages.

FORTRAN
The first important algorithmic language was FORTRAN (formula translation), designed in 1957 by
an IBM team led by John Backus. It was intended for scientificcomputations with real numbers and
collections of them organized as one- or multidimensional arrays. Its control structures included
conditional IF statements,repetitive loops (so-called DO loops), and a GOTO statement that allowed
nonsequential execution of program code. FORTRAN made it convenient to have subprograms for
common mathematical operations, and built libraries of them.

FORTRAN was also designed to translate into efficient machine language. It was immediately
successful and continues to evolve.

ALGOL
ALGOL (algorithmic language) was designed by a committee of American and European computer
scientists during 1958–60 for publishing algorithms, as well asfor doing computations. Like LISP
(described in the next section), ALGOL had recursive subprograms—procedures that could invoke
themselves to solve a problem by reducing it to a smaller problem of the same kind. ALGOL
introduced block structure, in which a program is composed of blocks that mightcontain both data
and instructions and have the same structure as an entire program. Block structure became a
powerful tool for building large programs outof small components.

ALGOL contributed a notation for describing the structure of a programming language, Backus–
Naur Form, which in some variation became the standard toolfor stating the syntax (grammar) of
programming languages. ALGOL was widely used in Europe, and for many years it remained the
language in which computeralgorithms were published. Many important languages, such as Pascal
and Ada (both described later), are its descendants.

421
LISP
LISP (list processing) was developed about 1960 by John McCarthy at
the Massachusetts Institute of Technology (MIT) and was founded on the mathematical theory of
recursive functions (in which a function appears in its owndefinition). A LISP program is a function
applied to data, rather than being a sequence of procedural steps as in FORTRAN and ALGOL. LISP
uses a very simple notation in which operations and their operands are given in a parenthesized
list. For example, (+ a (* b c)) stands for a + b*c. Although this appears awkward, the notation works
well for computers. LISP also uses the list structure to represent data, and, because programs and
data use the same structure, it is easy for a LISP program to operate on other programs as data.

LISP became a common language for artificial intelligence (AI) programming, partly owing to the
confluence of LISP and AI work at MIT and partly because AIprograms capable of “learning” could
be written in LISP as self-modifying programs. LISP has evolved through numerous dialects, such
as Scheme and Common LISP.
The C programming language was developed in 1972 by Dennis Ritchie and Brian Kernighan at the
AT&T Corporation for programming computer operating systems. Its capacity to structure data and
programs through the composition of smaller units is comparable to that of ALGOL. It uses a
compact notation and provides the programmer with the ability to operate with the addresses of
data aswell as with their values. This ability is important in systems programming, and C shares
with assembly language the power to exploit all the features of a
computer’s internal architecture. C, along with its descendant C++, remains one of the most
common languages.

Business-oriented languages
COBOL
COBOL (common business-oriented language) has been heavily used by businesses since its
inception in 1959. A committee of computer manufacturers and users and U.S. government
organizations established CODASYL (Committee on Data Systems and Languages) to develop and
oversee the language standard inorder to ensure its portability across diverse systems.

COBOL uses an English-like notation—novel when introduced. Business computations organize and
manipulate large quantities of data, and COBOLintroduced the record data structure for such tasks.
A record
clusters heterogeneous data such as a name, ID number, age, and address into a single unit. This
contrasts with scientific languages, in which homogeneous arrays of numbers are common.
Records are an important example of “chunking” data into a single object, and they appear in nearly
all modern languages.

SQL
SQL (structured query language) is a language for specifying the organization of databases
(collections of records). Databases organized with SQL are called relational because SQL provides
the ability to query a database for information
that falls in a given relation. For example, a query might be “find all records withboth last_name
Smith and city New York.” Commercial database programs commonly use a SQL-like language for
their queries.

Education-oriented languages

422
BASIC
BASIC (beginner’s all-purpose symbolic instruction code) was designed
at Dartmouth College in the mid-1960s by John Kemeny and Thomas Kurtz. It wasintended to be
easy to learn by novices, particularly non-computer science majors, and to run well on a time-
sharing computer with many users. It had simple data structures and notation and it was
interpreted: a BASIC program wastranslated line-by-line and executed as it was translated, which
made it easy to locate programming errors.

Its small size and simplicity also made BASIC a popular language for early personalcomputers. Its
recent forms have adopted many of the data and control structures of other contemporary
languages, which makes it more powerful but less convenient for beginners.

Pascal
About 1970 Niklaus Wirth of Switzerland designed Pascal to teach structured programming, which
emphasized the orderly use of conditional and loop controlstructures without GOTO statements.
Although Pascal resembled ALGOL in notation, it provided the ability to define data types with
which to organize complex information, a feature beyond the capabilities of ALGOL as well
as FORTRAN and COBOL. User-defined data types allowed the programmer tointroduce names for
complex data, which the language translator could then check for correct usage before running a
program.

During the late 1970s and ’80s, Pascal was one of the most widely used languagesfor programming
instruction. It was available on nearly all computers, and, because of its familiarity, clarity, and
security, it was used for
production software as well as for education.

Logo
Logo originated in the late 1960s as a
simplified LISP dialect for education; Seymour Papert and others used it at MIT to teach
mathematical thinking to schoolchildren. It had a more
conventional syntax than LISP and featured “turtle graphics,” a simple method for generating
computer graphics. (The name came from an early project to programa turtlelike robot.) Turtle
graphics used body-centred instructions, in which an object was moved around a screen by
commands, such as “left 90” and “forward,” that specified actions relative to the current position
and orientation of the object rather than in terms of a fixed framework. Together with recursive
routines, this technique made it easy to program intricate and attractive patterns.

Hyper talk
Hyper talk was designed as “programming for the rest of us” by Bill Atkinson for Apple’s Macintosh.
Using a simple English-like syntax, Hypertalk enabledanyone to combine text, graphics, and audio
quickly into “linked stacks” that
could be navigated by clicking with a mouse on standard buttons supplied by the program.
Hypertalk was particularly popular among educators in the 1980s and early ’90s for classroom
multimedia presentations. Although Hypertalk had many features of object-oriented languages
(described in the next section), Apple did
not develop it for other computer platforms and let it languish; as Apple’s marketshare declined in
the 1990s, a new cross-platform way of displaying multimedia left Hypertalk all but obsolete (see
the section World Wide Web display languages).
423
Object-oriented languages
Object-oriented languages help to manage complexity in large programs. Objectspackage data and
the operations on them so that only the operations are publiclyaccessible and internal details of the
data structures are hidden. This information hiding made large-scale programming easier by
allowing a programmer to think about each part of the program in isolation. In addition, objects
may be derived from more general ones, “inheriting” their capabilities. Such an
object hierarchy made it possible to define specialized objects without repeatingall that is in the
more general ones.

Object-oriented programming began with the Simula language (1967), which added information
hiding to ALGOL. Another influential object-oriented language was Smalltalk (1980), in which a
program was a set of objects that interacted by sending messages to one another.

C++
The C++ language, developed by Bjarne Stroustrup at AT&T in the mid-1980s, extended C by adding
objects to it while preserving the efficiency of C [Link] has been one of the most important
languages for both education and industrial programming. Large parts of many operating systems,
such as
the Microsoft Corporation’s Windows 98, were written in C++.

Ada
Ada was named for Augusta Ada King, countess of Lovelace, who was an assistantto the 19th-
century English inventor Charles Babbage, and is sometimes called the first computer programmer.
Ada, the language, was developed in the early 1980s for the U.S. Department of Defense for large-
scale programming. It combined Pascal-like notation with the ability to package operations and
data into independent modules. Its first form, Ada 83, was not fully object-oriented, but the
subsequent Ada 95 provided objects and the ability to
construct hierarchies of them. While no longer mandated for use in work for theDepartment of
Defense, Ada remains an effective language for engineering largeprograms.

Java
In the early 1990s, Java was designed by Sun Microsystems, Inc., as a programming language for
the World Wide Web (WWW). Although it resembled C++ in appearance, it was fully object-oriented.
In particular, Java dispensed with lower-level features, including the ability to manipulate data
addresses, a capability that is neither desirable nor useful in programs for distributed [Link]
order to be portable, Java programs are translated by a Java Virtual Machine specific to each
computer platform, which then executes the Java program. In addition to adding interactive
capabilities to the Internet through Web “applets,”Java has been widely used for programming
small and portable devices, such as mobile telephones.

PL-Paradigms and Models


A programming paradigm is a various system design of ideas that have been used to
guide/implement the programming.
Paradigm can also be termed as method to solve some problem or do some task. Programming
paradigm is an approach to solve problem using some programminglanguage or also we can say
it is a method to solve a problem using tools and techniques that are available to us following some
approach. There are lots for programming language that are known but all of them need to follow
some strategy when they are implemented and this methodology/strategy is paradigms. Apart
424
from varieties of programming language there are lots of paradigms to fulfil each and every
demand.

Following list of paradigms


Imperative: Explicit sequence [such as assignment statements] of statements thatchange the state
of the computer.

It is one of the oldest programming paradigm. It features close relation relation to machine
architecture. It is based on Von Neumann architecture. It works by changing the program state
through assignment statements. It performs step by step task by changing state. The main focus
is on how to achieve the goal. The paradigm consist of several statements and after execution of
all the result is stored.

Advantage:

1. Very simple to implement


2. It contains loops, variables etc.

Disadvantage
1. Complex problem cannot be solved
2. Less efficient and less productive
3. Parallel programming is not possible

vdc
This paradigm emphasizes on procedure in terms of under lying machine model.
There is no difference in between procedural and imperative approach. It has the ability to reuse
the code and it was boon at that time when it was in use because of its reusability.
Object-Oriented: By defining the objects that transfers messages to each objects or program.
Objects have their own internal state with public interface calls[encapsulation].

The program is written as a collection of classes and object which are meant for communication.
The smallest and basic entity is object and all kind of computation is performed on the objects
only. More emphasis is on data rather procedure. It can handle almost all kind of real life problems
which are today in scenario.

Advantages:
1. Data security
2. Inheritance
3. Code reusability
4. Flexible and abstraction is also present

Parallel processing: It is a type of processing that works like a divide and conquer technique by
dividing the task into multiple small processes and processing them parallel to run a program in
the least time.

Parallel processing is the processing of program instructions by dividing them among multiple
425
processors. A parallel processing system posses many numbers ofprocessor with the objective of
running a program in less time by dividing them. This approach seems to be like divide and conquer.
Examples are NESL (one of the oldest one) and C/C++ also supports because of some library
function.

Declarative
Programming by mentioning/specifying the value/result that what we need andmentioning how to
get the result.

It is divided as Logic, Functional, Database. In computer science the declarative programming is a


style of building programs that expresses logic of computation without talking about its control
flow. It often considers programs as theories of some [Link] may simplify writing parallel
programs. The focus is on what needs to be done rather how it should be done basically
emphasize on what code codeis actually doing. It just declare the result we want rather how it has
be produced. This is the only difference between imperative (how to do) and declarative (what to
do) programming paradigms. Getting into deeper we would see logic, functional and database.

Logic (as per defined rules): Specifying a set of rules/business logic in theprogramming. It is
used to solve logic problems.
It can be termed as abstract model of computation. It would solve logical problems like puzzles,
series etc. In logic programming we have a knowledge basewhich we know before and along with
the question and knowledge base, which is given to machine, it produces result. In normal
programming languages, such concept of knowledge base is not available but while using the
concept of artificial intelligence, machine learning we have some models like Perception model
which is using the same mechanism.
In logical programming the main emphasize is on knowledge base and theproblem.

sum of two number in prolog:


predicates
sumoftwonumber(integer, integer)
clauses
sum (0, 0).
sum(n, r):-/

n1=n-1,
sum (n1,
r1),r=r1+n

Functional (Application-oriented): Expressing the calculations as evaluation ofmath-function,


Function call programming with to avoid any global state change.

426
The functional programming paradigms has its roots in mathematics, and it is language
independent. The key principle of this paradigms is the execution of series of mathematical
functions. The central model for the abstraction is the function which are meant for some specific
computation and not the data structure. Data are loosely coupled to functions. The function hide
their implementation. Function can be replaced with their values without changing the meaning of
the program. Some of the languages like Perl, JavaScript mostly uses this paradigm.

Examples of Functional programming paradigm:

JavaScript: developed by Brendan Eich


Haskwell : developed by Lennart Augustsson, Dave Barton
Scala: developed by Martin Odersky
Erlang: developed by Joe Armstrong, Robert Virding
Lisp : developed by John Mccarthy
ML : developed by Robin Milner
Clojure : developed by Rich Hickey

Structured: Clean programming like goto-free, with proper nested control structures.
This programming methodology is based on data and its movement. Program statements are
defined by data rather than hard-coding a series of steps. A database program is the heart of a
business information system and provides file creation, data entry, update, query and reporting
functions. There are several programming languages that are developed mostly for database
application. For example, SQL. It is applied to streams of structured data, for filtering, transforming,
aggregating (such as computing statistics), or calling other programs. So it has its own wide
application.

To execute a program written in any kind of language, it has to be translated to machine level
language first. The source code will be translated to Machine level language / Object code by a
translator.
There are three types of translators available

Assembles: Assemblers convert the assembly language mnemonics codes to themachine code.
427
Compilers: Compiler converts the full source code program to machine level [Link] it will run
in the machine without any further translation process. But, the error correction process is tough in
the compilers.

Interpreters: Interpreters converts each instruction line by line into the objectcode [like Java].

Virtual Machine
A virtual machine (or "VM") is an emulated computer system created
using software. It uses physical system resources, such as the CPU, RAM, and diskstorage, but is
isolated from other software on the computer. It can easily be created, modified, or destroyed
without affecting the host computer.

Virtual machines provide similar functionality to physical machines, but they do not run directly on
the hardware. Instead, a software layer exists between the hardware and the virtual machine. The
software that manages one or more VMs is called a "hypervisor" and the VMs are called "guests"
or virtualized instances. Each guest can interact with the hardware, but the hypervisor controls
them. Thehypervisor can start up and shut down virtual machines and also allocate a specific
amount of system resources to each one.
virtual machine can be created using virtualization software. Examples includeMicrosoft Hyper-V
Manager, VMware Workstation Pro, and Parallels Desktop. These applications allow us to run
multiple VMs on a single computer. For example, Parallels Desktop for Mac allows us to run
Windows, Linux, and macOS virtual machines on our Mac.
VMs are ideal for testing software since developers can install one or more applications and revert
to a saved state (or "snapshot") whenever needed. Testingsoftware on a regular operating system
can cause unexpected crashes and may leave some files lingering behind after the software is
uninstalled. It is safer to test software on a virtual machine that is isolated from the operating
system and can be fully reset as needed.

Binding Time
As we have just seen, operating systems use various kinds of names to refer to objects. Sometimes
the mapping between a name and an object is fixed, but sometimes it is not. In the latter case, it
may matter when the name is bound tothe object. In general, early binding is simple, but is not
flexible, whereas late binding is more complicated but often more flexible.
To clarify the concept of binding time, look at some real-world examples. An example of early
binding is the practice of some colleges to allow parents to enrolla baby at birth and prepay the
current tuition. When the student shows up 18years later, the tuition is fully paid up, no matter how
high it may be at thatmoment.

In manufacturing, ordering parts in advance and maintaining an inventory of themis early binding.
In contrast, just-in-time manufacturing requires suppliers to be able to provide parts on the spot,
with no advance notice required. This is late binding.
Programming languages often support multiple binding times for variables. Globalvariables are
bound to a particular virtual address by the compiler. This exemplifies early binding. Variables local
428
to a procedure are assigned a virtual address (on the stack) at the time the procedure is invoked.
This is intermediate binding. Varables stored on the heap (those allocated by malloc in C or new in
Java) are assigned virtual addresses only at the time they are actually used. Here we have late
binding.

Operating systems often use early binding for most data structures, but occasionally use late
binding for flexibility. Memory allocation is a case in point. Early multiprogramming systems on
machines lacking address relocation hardware had to load a program at some memory address
and relocate it to runthere. If it was ever swapped out, it had to be brought back at the same memory
address or it would fail. In contrast, paged virtual memory is a form of late binding. The actual
physical address corresponding to a given virtual address is not known until the page is touched
and actually brought into memory.

Another example of late binding is window placement in a GUI. In contrast to theearly graphical
systems, in which the programmer had to specify the absolute screen coordinates for all images
on the screen, in modern GUIs, the software uses coordinates relative to the window's origin, but
that is not determined untilthe window is put on the screen, and it may even be changed later.
Binding refers to the process of converting identifiers (such as variable andperformance names)
into addresses. Binding is done for each variable andfunctions. For functions, it means that
matching the call with the right functiondefinition by the compiler. It takes place either at compile
time or at runtime.

Early Binding (compile-time time polymorphism) As the name indicates, compiler(or linker) directly
associate an address to the function call. It replaces the call with a machine language instruction
that tells the mainframe to leap to the address of the function.
By default early binding happens in C++. Late binding is achieved with the helpof virtual keyword)

429
// CPP Program to illustrate early binding.

// Any normal function call (without virtual)

// is binded early. Here we have taken base

// and derived class example so that readers

// can easily compare and see difference in

// outputs. #include<iostream>

using namespace std;

class Base

public:

void show() { cout<<" In Base \n"; }

};

class Derived: public Base

public:

void show() { cout<<"In Derived \n"; }

};

int main(void)

Output:

430
In Base
Late Binding : (Run time polymorphism) In this, the compiler adds code thatidentifies the kid of
object at runtime then matches the call with the right function definition. This can be achieved by
declaring a virtual function.

// CPP Program to illustrate late binding#include<iostream>using namespace std;class Base

public:

virtual void show() { cout<<" In Base \n"; }

};

class Derived: public Base{public:void show() { cout<<"In Derived \n"; }};int main(void){Base
*bp = new Derived;bp->show(); // RUN-TIME POLYMORPHISM return 0;

Output:

In Derived

Syntax in Programming
Syntax is the set of rules that define what the various combinations of symbols mean. This tells
the computer how to read the code. Syntax refers to a concept inwriting code dealing with a very
specific set of words and a very specific order to those words when we give the computer
instructions. This order and this strict structure is what enables us to communicate effectively with
a computer. Syntax is to code, like grammar is to English or any other language. A big difference
though is that computers are really exacting in how we structure that grammar orour syntax.
This syntax is why we call programming coding. Even amongst all the different languages that are
out there. Each programming language uses different words ina different structure in how we give
it information to get the computer to follow our instructions.
Web developers primarily focus on HTML, CSS, and JavaScript. That is what we’regoing to focus
on in this course as well. By focusing on these languages and mastering them, We’ll be able to write
websites that can be opened by any browser in the world.
Syntax in computer programming means the rules that control the structure of the symbols,
punctuation, and words of a programming language.
Without syntax, the meaning or semantics of a language is nearly impossible tounderstand.

For example, a series of English words, such as — subject a need and doessentence a verb — has
little meaning without syntax.
Applying basic syntax results in the sentence — Does a sentence need a subjectand verb?

431
Programming languages function on the same principles.
If the syntax of a language is not followed, the code will not be understood by a compiler or
interpreter.
Compilers convert programming languages like Java or C++ into binary code thatcomputers can
understand. If the syntax is incorrect, the code will not compile.
Interpreters execute programming languages such as JavaScript or Python at runtime. The
incorrect syntax will cause the code to fail.
That’s why it is crucial that a programmer pays close attention to a language’s syntax. No
programmer likes to get a syntax error.

Basic Syntax
Basic syntax represents the fundamental rules of a programming [Link] these rules, it
is impossible to write functioning code.
Every language has its own set of rules that make up its basic syntax. Naming conventions are a
primary component of basic syntax conventions and vary bylanguage.
1. Case Sensitive. Java, C++, and Python are examples of languages that are case-
sensitive. Identifiers such as world and World have different meanings in these languages.
Languages such as Basic and SQL are insensitive, meaning world and World have the same
meaning.
2. Class Names. Java requires the first letter of each word in class names beupper
case. For example, class FirstJavaClass. Languages such as C or C++use an underscore to
separate words. In C, the class name would befirst_java_class.
3. Program Filenames. The name of a Java program file must match the classname
with the extension ‘*.java” added to the name. For
4. example, [Link] would be the name of the program file for the class
FirstJavaClass. C and C++ files require a “*.c” or “*.cpp” extension buthave no other stipulations.
5. Different languages may have rules for adding comments, using white space, ordeclaring
variables.
6. Object-oriented languages such as Java and C use methods that have different syntax
requirements.
The first step in learning any programming language is to understand the basicssuch as phrase
structure, proper syntax and correctly structured code.

Understanding Syntax
Human languages have syntax. These rules stipulate word order, punctuation and sentence
structure.
Without these rules, it would be impossible to communicate in a given [Link] learning a
foreign language, one of the first steps is learning its syntax.
Writing code requires the same focus on syntax. Once the code is written, it isread multiple times
by different people.
Sometimes the code may be read years after it is written, making coding standards necessary.
Coding standards can make the code easy to understand.

432
C Syntax
look at a C program that prints the sentence — My first line of code. All Cinstructions are written in
lower case.

#include
int main() {
printf( “My first line of code” );}
For this example, ignore the include statement at the start of the program. All Cprograms must
begin with main () followed by a left curly bracket ( { ).
This convention indicates the start of the program. A right curly bracket ( } )indicates the end.
The print function (printf) is called, followed by what is to print. The text to printmust be surrounded
by quotation marks and enclosed in parentheses.
All statements must end with a semicolon ( ; ). For example, to print a secondsentence add the
following statement before the right curly bracket:
printf( “just printed!” );}
The executed program would display: My first line of code just printed!

Why Is Syntax Important in Programming?


Syntax improves code readability. It ensures that the four C’s of coding aremaintained:
1. Communication
2. Code integration
3. Consistency
4. Clarity

The concept behind conventions is to make the code explain itself. If the code is self-explanatory,
the focus can be on design and program improvements and noton what does this mean?
Using consistent standards means that code is predictable and discoverable whenread by other
programmers.
When code does not follow conventions, it becomes disorganized and difficult toread. It becomes
what is known as spaghetti code.
The term has a negative connotation indicating that the programmer did not have the skills or
experience needed to write readable code.

The Translation Process.


A computer system can only understand machine code. A program written for example in a high
level language such as Java cannot be run directly. To execute acomputer program written in any
programming language, it must first be translated.

The source code which is written by the programmer needs to be translated. When translated, the
source code becomes object code which is understandableby the computer system. This process
can be seen in the following diagram;

433
There are three main types of translators; Assemblers, Compilers and Interpreters.A description of
each of these types of translators is given in the following table.
The three main types of translators

Type Description

Assembler Assemblers convert assembly language mnemonics

into machine code.


Interpreters convert each instruction of the source code into
Interpreters the object code as the program is being run. This gives a
better interactive environment butis slower.
A compiler converts the entire source code into machine code
Compilers so that it can be run on the machinewithout further translation.
However, error correction is tedious.

Stages in Translating a Program Lexical analysis (Scanner): Breaking a program into primitive
components, calledtokens (identifiers, numbers, keywords, …)
Syntactic analysis (Parsing): Creating a syntax tree of the program.
Symbol table: Storing information about declared objects (identifiers, procedurenames, …)
Semantic analysis: Understanding the relationship among the tokens in theprogram.
Optimization: Rewriting the syntax tree to create a more efficient program.

Code generation: Converting the parsed program into an executable form.

Elementary Data Types

Variables and Constants


Variables: A variable is it Quadruple which is composed of a name, a set ofattributes, a reference
and a value.
A simple variable is an elementary data object with a name and binding of dataobject to value may
change during its lifetime. This data objects are basically defined and named by programmer
explicitly.

Attribute of a variable:
example of variable in "ALGOL Language"y:=9;

434
We can say that it has four attributes

1) the name of the box:y

2) The name of description of a current content.i.e. 9 we can also say that square of 3.

3) the box or storage location(s) which holds(s) the value.

4) the content of the box or 9.

The name of the box and its storage location are fixed, but the contents and itname may vary
over time.

Another example in C language:


• int N;- It declares a simple data object N of type integer.
• N=27; beta value 27 is assigned to variable N.
o declare the variable name N of type integer.
o lifetime of N is execution end.
o data object bound to N during end of execution time.
o value 27 is assigned and may be changed during life of N.
o hidden from the programmer are other binding made by virtual computer
like creating Activation Record, Storage for this activationrecord in Run-TimeStack etc.
Data Object:
Definition: A Data object represents a container for data values, a place wheredata values may be
stored and later retrieved.
Definition: A runtime grouping of one or more pieces of data in a virtualcomputer.
Definition: A Location in memory with an assignment name in the actualcomputer.

Data objects can be:

1) at program execution- Programmer-defined -(example variables, constant,arrays, files etc)


2) not directly accessible to programmer- system defined- run time storage,stacks, file buffers, free
space lists.

435
Data values can be:
• Single number
• Pointer to other objects and characters.

Data object is usually represented as storage in Computer memory and a datavalue is represented
by a pattern of bits. So we can represent the relation between Data Object and Data value.

436
A Data Object is elementary if it contains a data value that is always manipulatedas a unit.
A Data Object is an Data Structure if it is an aggregate of the data object
Binding and Attributes of Data Object:

Binding is an association of data values and entity.


Type: This associates the data object with the set of data values that the objectmay take.
1. location: This associate the binding of a storage location in memory where thedata object is
represented. Only storage management routines can only change add data object in the virtual
computer.
2. Value: This binding is usually the result of an assignment operation.
3. Name: The binding to one or more names by which the object maybe referenced
during program execution is usually set up by declaration andmodified by subprogram calls the
returns.

437
Component: The binding of a data object to one or more data object of which it is a component is
often represented by a pointer value. And may be modified bya change in pointer.

In ALGOL68 we can define constant by

real root2=1.4142135;
That was much acceptable that time.

In Ada, provides a uniform notation for setting constants to initial values and for initializing
variables.

X: Constant INTEGER:=17;
In C language: const is used to initialise the constant value

Const int MAX=80;


The constant MAX is a programmer defined constant because the programmerexplicitly defines
the name for the value 30.
In C, there is micro definition which is used for control the execution of programand can be used
for declaring constant.
Example #define MAX30
It is a compile-time operation that causes all references to MAX in program to bechanged to the
constant 30.
In this 30 has two names, the programmer defined MAX and literal name 30. Bothof which may be
used to refer to a data object containing the value 30.
# Define MAX 30 is a command, which the translator used to equate "MAX" withthe value "30",
whereas the const attribute in C is a translator directive startingthat MAX will always contain the
value 30.

Specification of Elementary Data Types


An elementary data object contains a single data values and class of such data objects over which
various operations are defined is termed as elementary datatype.
Some elementary data types: Integer, real, character, Boolean, enumeration and pointer and
specification may differ significantly between two languages.

Attributes: Basic attributes of any data object, such as data type and name areusually invariant
during its lifetime.

Some attributes may be stored in a descriptor as a part of the data object dailyprogram execution.
Others may be used only to determine the storage representation of the data object.
The value of an attribute of a data object is different from the value that the dataobject contains.
Values: The type of a data object determines the set of possible values that it maycontain.

For Example: C defines the following four classes of integer typesint, short, long and char

438
because most hardware implements multiple Precision integer arithmetic(example 16 bit and 32
bit integers or 32 bit and 64 integers) We can use' short'for shortest value of the integer word length.
long uses the longest value implemented by the hardware.
int uses the most efficient value that the hardware implements.
In C, Characters are stored as 8 bit integers in the type char, which is subtype ofinteger.
Operations:- The set of operations Defined by language is basically refers thathow data object of
that data type may be manipulated.
If the operations are primitive operation, means specified as part of language.

Programmer defined operations, in the form of subprograms or methoddeclarations as part of


class definitions.

Example
Integer* integer-> integer
a) integer addition is an operation that take to integer data objects as anarguments and produces
an integer data object as a result.

b) SQRT: real-> real


A Square-root operation, SQRT,on real number data object is specified.
(Port of operation)
An algorithm that specifies how to compute the results for any given set ofarguments is a common
method for specifying the action of an operation.
In C, we have concept a function prototype which signature of an operation, the number, order and
data types of the arguments in the domain of an operation aregiven as well as the order and the
data type of the resulting range.

Binary operation: Two arguments with single result Monolic operation: Single argument with single
result. Implementation of Elementary Data Types:" Implementation of Elementary data type
consists of
1. Storage representation for data objects
2. Values of that type
3. Set of algorithms or procedures that define the operations of thetype in
terms of manipulations of the storage representation.

Storage representation of Elementary data type:


1) Hardware Influence: Computer hardware influence the storage of elementarydata type.
In this case computer hardware executes the program. If the hardware storage representation are
used, then the basic operations on data of that data type notimplemented using hardware provided
operations.
2) Software influenced: If we do not use hardware storage representation, thenthe operation must
be software simulated and some operation will execute muchless efficient.

Two methods to treat Attributes:


It has to be determined by the compiler and not stored in discriptors during execution or not stored
439
in runtime storage representation. It is usually a methodin C language.
It is stored in a descriptor as part of the data object at runtime in LISP, Prologlanguage .
The storage representation is usually described in terms of

1. Size of the block of memory required (the number of memory wordsbytes, ot


bits needed)
2. Layout of attributes and data values within the block.

Implementation of operations:
Each operation defined for data objects of a given type may be implemented inone of three main
ways: -
1) Directly as a hardware operation: If simple data types are stored using the hardware
representation, when the primitive operations are implemented usingthe arithmetic operations built
in to hardware.
2) As a Subprogram or procedure: A square root for an example, this operation isnot provided
directly as a hardware operation. So it is software simulated implemented as a procedure or
function.
3) as an inline code sequence: It is software implementation of the code and itsoperation. Instead
of using a subprogram, operation in the subprogram are copied into the program at the point where
the subprogram would otherwise have been invoked.

For Example:
The absolute value of function on numbers abs(x)= if x<0 then -x else x
is usually implemented as an inline code sequence.

1. fetch value of x from memory


2. if x >0, skip the next instruction
3. set x=-x
4. store new value of x in memory
Here each line is implemented by a single hardware operation.

Scalar Data Types


Scalar data types represent a single object, i.e. only one value can be derived. In general, scalar
objects follow the hardware architecture of a [Link] Data Types
Integers Sub -ranges

Floating-point real numbers Fixed-point real numbers Other Data Types - Complex numbers
Rational numbers Enumerations Booleans Characters
Integers Specification Maximal and minimal valuesOperations:

Arithmetic Relational Assignment Bit operations


Implementation - hardware defined

Sub-ranges Specification:
subtype of integer
a sequence of integer values within some restricted range Example:
440
Pascal declaration A: 1..10 means that the variable A may be assigned integer values from 1
through 10.
Implementation
smaller storage requirements, better type checking

Floating-point real numbers Specification:


Minimum and maximal value
Round-off issues - the check for equality may fail due to round -off

Implementation
Mantissa - exponent model. Example: 10.5 = 0.105 x 102,Mantissa: 105, Exponent: 2

Fixed-point real numbers Specification:


real numbers with predefined decimal places

Implementation:
Directly supported by hardware or simulated by software

Other scalar data types


Complex numbers: software simulated with two storage locations one the realportion and one for
the imaginary portion.

Rational numbers: the quotient of two integers. Enumerations: Ordered list of different values
Booleans
Characters

Scalar Data Type Enumeration


An Enumerated data type is a data type whose domain values are given in a list orordered list and
who's only operations are equality and assignment. or
An Enumeration is an ordered list of distinct [Link]
An Enumeration is a complete ordered listing of all items in a collection.
Pascal was first language which introduced enumeration. To make enumeration facility useful, a
programming language must provide a mechanism for declaring and defining the new data type
and for declaring variables whose value will comefrom the element of type.

It is assumed that this literals are distinct and does equality can be directlydefined.
"Before an era of enumeration what we had ?"
For example: A variable student class might have only 4 possible values representing fresher,
sophomore, junior and senior. Similarly, a variableStudents might have only two values representing
Male and Female. Before the contact of enumeration, the language like

Fortran or Cobol such variables is declared as integer type and distinct values areassigned. like
fresher=1 , sophomore=2, and so onand male=0, female =1

441
Then translator manipulate values as integers.
That creates big problem likeSophomore =1 and female=1
As both have some values can we apply integer-based operation on it. As a point of view of
programmer, it should not be but according to translator it can apply asthey are of integer types.
Then languages such as C, article Pascal and Ada includes an Enumeration datatype that allows
the programmer to define and manipulate such variables directly.

Specification of Enumeration
The programmers defined both the literal name to be used for the values andtheir ordering using a
declaration such as in pascal.

Type months=(jan,feb, mar, apr, june, jul, aug, sep, oct,nov,dec); In C


Enum student class{ fresh, soph, junior, senior};enum studentsex {male, female};
In Pascal, C example can be written as type class =(fresh, soph, junior, senior}; Followed by
declaration for variables such asStudent class: Class;
Studentsex class: Class.
Here type definition introduces the type name class, which may be used whereverthe primitive type
name such as integer might be used time.
It also introduces the literals of fresh, soph, junior, senior which may be used

wherever a language- defined literal such as "27" might be used. Thus we canwrite.
if studentclass= junior then.....
Instead of the less understandable
if studentclass= 3 then ...........
Which would be required if integer variables were used. Static compiler can finderror such as if
student class= Male then

As Male is part of student class. Operations which we can perform-


• Relational operations (equal, less-than, greater-than,etc)
• Assignment
• Successor and Predecessor

Implementation of Enumeration
• Each value in the enumeration sequence is represented at run-time by one ofthe integers 0,1,2,
as only a small set of values is involved and the values are
• never negative.
• In this integer representation is often shortened to omit the sign bit and use only enough bits for
the range of values required, as with the sub-range values.
• Only and maximum 2 bits are required to represent the senior=3 in memory because
3=11(binary)/ 2 bits only
• In C, the programmer main override default and set any values desired for enumeration
values for example.
• Enum class{ fresh=74, soph=89, junio=7, senior=28}

442
• With this storage representation for enumeration types. Relational operationssuch as =,>,
and < may be implemented.

Scalar Data Types: Booleans

The Boolean data type is a data type, having two values(usually denoted true orfalse), intended to
represent the truth values of logic and Boolean algebra.

Specification: In Pascal and Ada, the Boolean data type is considered simply alanguage - defined
enumeration, viz;
type Boolean=(false, true);

Which both defines the names true and false for the values of the types and define ordering
false<true
Common Operations in boolean are
and: Boolean*Boolean->Boolean(conjunction)
or: Boolean*Boolean->Boolean(inclusive disjunction ) not : Boolean ->Boolean(negative or
complement)

Implementation of boolean data type:


Single bit of storage is provided, no descriptor designated the data type is needed. Because single
bit may not be separately addressable in memory whichoften takes a byte or word to represent it if
extended. Then the value true and false might be represented in two ways within the storage unit:
• a particular bit is used for the value(often the sign bit of the number
representation), with '0= false', '1=true', and the rest of the byte or wordignored, or
• A zero value in the entire storage unit represent False, and any other nonzero value
represents true

Scalar Data Types: CharactersSpecification of Characters


443
A character data type provides data objects that have a single character as their value. Set of values
in character data type depends upon "Hardware and Operating System" like ASCII character set.
and ordering of the characters in thischaracter set is called Collecting Sequence And ordering given
by the 'RelationalOperations'.

Character set includes


• Spaces
• Digits
• Special character @,#,$,& etc.

Operations on character data include only

• Relational operations
• Assignment and
• To test character for- Letter, Digit, Special Character

Implementation of Character Data Type


Character data values are almost directly supported by the underlying hardware and operating
system because their use in input-output.

In C Character is declared

ASCII value of character data type in C are


0 to 9 is 48 to 57/ ASCII value
A to z is 65 to 90
a to z is 97 to 122
And all remaining for special [Link] a ; //declaration
a='A'; // initializing character data object with AWhere= A=65=1000001

444
Composite Data Types
Unbounded length: storage allocation at run time. String can be any length

Character Strings - operations


Concatenation – appending two strings
➢ Relational operations – equal, less than, greater than
• Substring selection using positioning subscripts
• Substring selection using pattern matching
• Input / output formatting
• Dynamic strings - the string is evaluated at run time.

implementation
445
• Fixed declared length: A packed vector of characters
• Variable length to a declared bound: a descriptor that contains the maximum length and
the current
Length
• Unbounded length: Either a linked storage of fixed-length data objects or acontiguous
array of characters with dynamic run-time storage allocation

Pointers and Programmer- Constructed Objects

Objects
Specification:
Reference data objects only of a single type – C, Pascal, [Link] data objects of any type –
Smalltalk C, C++: pointers are data objects and can be manipulated by the program Java: pointers
are hidden data structures, managed by the languageimplementation

Pointers - implementation
Absolute addresses stored in the pointer. Allows for storing the new objectanywhere in the memory
Relative addresses: offset with respect to some base address.
Advantages: the entire block can be moved to another location without invalidating the addresses
in the pointers, since they are relative, not absolute.

Pointers – implementation problems

• Management of a general heap storage area: to create objects of differentsize


• Garbage - the contents of pointer is destroyed, and the object still exists
• Dangling references: the object is destroyed however the pointer still contains the
address of the used location, and can be wrongly used by theprogram.

Characteristics:
• Usually resideon secondary storage devicesas disks, tapes.
• Lifetime is greater than the lifetime of the program that hascreated the files.

Implementation – as part of the operating system

Types of Files
Sequential file: a data structure composed of a linear sequence ofcomponents of the same type.
Interactive Input-Output: sequential files used in interactive mode.

Direct Access Files: Any single component can be accessed at random just as in anarray.
Key: the subscript to access a component.

Implementation: a key table is kept in main memory


Indexed Sequential Files: Similar to direct access files using a key combined withbeing able to
sequentially process the file. The file must be ordered by the key

446
C programming
C programming is a general-purpose, procedural, imperative computer programming language
developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX
operating system. C is the most widely used computer language. It keeps fluctuating at number
one scale of popularity along with Java programming language, which is also equally popularand
most widely used among modern software programmers.
Why to Learn C Programming?

C programming language is a MUST for students and working professionals to become a great
Software Engineer specially when they are working in SoftwareDevelopment Domain. I will list down
some of the key advantages of learning CProgramming:
• Easy to learn
• Structured language
• It produces efficient programs
• It can handle low-level activities
• It can be compiled on a variety of computer platforms
• Facts about C

• C was invented to write an operating system called UNIX.


• C is a successor of B language which was introduced around the early1970s.
• The language was formalized in 1988 by the American NationalStandard Institute (ANSI).
• The UNIX OS was totally written in C.
• Today C is the most widely used and popular System ProgrammingLanguage.
• Most of the state-of-the-art software have been implemented usingC.

1. Today's most popular Linux OS and RDBMS MySQL have been writtenin C.
2. Hello World using C Programming.

#include <stdio.h

int main() {

/* my first program in C */

printf("Hello, World! \n");

return 0;

Applications of C Programming
C was initially used for system development work, particularly the programs that make-up the
447
operating system. C was adopted as a system development languagebecause it produces code
that runs nearly as fast as the code written in assembly language. Some examples of the use of C
are -
1. Operating Systems
2. Language Compilers
3. Assemblers
4. Text Editors
5. Print Spoolers
6. Network Drivers
7. Modern Programs
8. Databases
9. Language Interpreters
10. Utilities

Token
Tokens are the smallest elements of a program, which are meaningful to thecompiler.
The following are the types of tokens: Keywords, Identifiers, Constant, Strings,Operators, etc.

auto double int struct

break else long switch

case enum register typedef

char extern return union

continue for signed void

do if static while

default goto sizeof volatile

const float short unsigned

Identifiers
Each program element in C programming is known as an identifier. They are usedfor naming of
variables, functions, array etc. These are user-defined names whichconsist of alphabets, number,
underscore ‘_’. Identifier’s name should not be same or same as keywords. Keywords are not used
as identifiers.
448
Rules for naming C identifiers −
• It must begin with alphabets or underscore.
• Only alphabets, numbers, underscore can be used, no other special
characters, punctuations are allowed.
• It must not contain white space.
• It should not be a keyword.
• It should be up to 31 characters long.
Rules for constructing C identifiers
• The first character of an identifier should be either an alphabet or an underscore,
and then it can be followed by any of the character, digit, orunderscore.
• It should not begin with any numerical digit.
• In identifiers, both uppercase and lowercase letters are distinct. Therefore,we can
say that identifiers are case sensitive.
• Commas or blank spaces cannot be specified within an identifier.
• Keywords cannot be represented as an identifier.
• The length of the identifiers should not be more than 31 characters.
• Identifiers should be written in such a way that it is meaningful, short, andeasy to
read.

Example of valid identifiers


total, sum, average, _m _, sum_1, etc.

Example of invalid identifiers


2sum (starts with a numerical digit)
• int (reserved word)
• char (reserved word)
• m+n (special character, i.e., '+')

• Types of identifiers
• Internal identifier
• External identifier

Internal Identifier
If the identifier is not used in the external linkage, then it is known as an internalidentifier. The
internal identifiers can be local variables.

External Identifier
If the identifier is used in the external linkage, then it is known as an externalidentifier. The external
identifiers can be function names, global variables.

Differences between Keyword and Identifier

449
Keyword Identifier

Keyword is a pre-defined word. The identifier is a user-defined word

It can be written in both lowercase anduppercase


It must be written in a lowercaseletter.
letters.

Its meaning is pre-defined in the ccompiler. Its meaning is not defined in the c compiler.

It is a combination of alphabetical
It is a combination of alphanumericcharacters.
characters.
It does not contain the underscore
It can contain the underscore character.
character.

int main()

int a=10;

int A=20;

printf("Value of a is : %d",a);

printf("\nValue of A is :%d",A);return

0;

}
The above output shows that the values of both the variables, 'a' and 'A' aredifferent. Therefore, we
conclude that the identifiers are case sensitive.

Strings
A string is an array of characters ended with a null character (\0). This null character indicates that
string has ended. Strings are always enclosed with doublequotes (“ “).
how to declare String in C language –
Example:

450
1) char string[20] = {‘s’,’t’,’u’,’d’,’y’, ‘\0’};

2) char string[20] = “demo”;

char string [] = “demo”;Here is an example of tokens in C language,


#include >stdio.h>int main() {

// using keyword charchar a1 = 'H';

int b = 8; float d 5.6.

// declaration of string

char string[200] = "demodotcom";if(b<10)

printf("Character Value : %c\n",a1);else

printf("Float value : %f\n",d);

printf("String Value : %s\n", string);

return 0;

Output
Character Value: H
String Value: demo dot com

Data Types in C
A data type specifies the type of data that a variable can store such as integer,floating,
character, etc.

451
There are the following data types in C language

Types Data Types

Basic Data Type int, char, float, double

Derived Data Type array, pointer, structure, union

Enumeration Data Type enum

Void Data Type void

Data Types Memory Size Range

char 1 byte −128 to 127

signed char 1 byte −128 to 127

unsigned char 1 byte 0 to 255

short 2 byte −32,768 to 32,767

452
signed short 2 byte −32,768 to 32,767

unsigned short 2 byte 0 to 65,535

int 2 byte −32,768 to 32,767

signed int 2 byte −32,768 to 32,767

unsigned int 2 byte 0 to 65,535

short int 2 byte −32,768 to 32,767

signed short int 2 byte −32,768 to 32,767

unsigned short int 2 byte 0 to 65,535

long int 4 byte -2,147,483,648 to 2,147,483,647

signed long int 4 byte -2,147,483,648 to 2,147,483,647

unsigned long int 4 byte 0 to 4,294,967,295

float 4 byte

double 8 byte

long double 10 byte

453
Subprogram
A Subprogram is a program inside any larger program that can be reused anynumber of times.
ontrol at the subprogram level is concerned with subprogram invocation and the relationship
between the calling module and the called module. What follows is alist of possible ways the caller
and the callee are related.

Characteristics of a Subprogram:

(1) A Subprogram is implemented using the Call & Return instructions inAssembly Language.
(2) The Call Instruction is present in the Main Program and the Return(Ret)Instruction is present in
the subprogram itself.
(3) It is important to note that the Main Program is suspended during the execution of any
subprogram. Moreover, after the completion of the subprogramthe main program executes from
the next sequential address present in the Program Counter .
(4) For the implementation of any subprogram, a “Stack” is used to store
the “Return Address” to the Main Program . Here, Return Address means the immediately next
instruction address after the Call Instruction in the Main program. This Return Address is present
inside the Program Counter . Thus duringthe execution of the Call Instruction, the Program Counter
value is first pushed tothe Stack as the Return Address and then the Program Counter value is
updated to the given address in the Call Instruction. Similarly, during the execution of Return(Ret)
Instruction, the value present in the stack is popped and the ProgramCounter value is restored for
further execution of the Main Program .
(5) The Main advantage of Subprogram is that it avoids repetition of Code andallows us to reuse
the same code again and again.

454
ARRAY

Introduction
• Arrays are also known as subscript variable.
• Array is a collection of similar elements
• Whatever may the size of array, it always consumed memory in a contiguousmanner

• Need of array
• Till now we have been designing solution to small problems that require less number of
variables to handle program data. Think about a scenario where Weneed to handle hundreds of
variables or even more than that.
• In such scenario, We might be thinking about what variable names should beused, how to
reduce redundant code, etc.
• Assume We have to store marks of 100 students and then think about thefollowing:
455
• What could be our variable naming convention?
• How We efficiently write input instruction to store 100data.
• How could We easily manipulate data like adding all ofthem
in a less complex style?
• The answer to all these questions is subscript notation also known as arrays.

Array Declaration

• When We want to create large number of variables We need not to think about 100s of
names. Assume that We want to create 100 variables to store marks of 100 students.
• Here is the way:

int marks [100];


• Notice square brackets after array name marks. This pair of square bracketsis
used to depict array [Link] mention in the square bracket is size of array. In our example
we wrote 100, so size of the array is 100. Thus we have declared 100 variablesin one go.
• These 100 variables are all of type int. Since array is a collection of similar
elements, data type for all 100 variables is int.
• Name of the first variable is marks[0], second variable is marks[1], and so on.
Therefore the last variable is marks[99]. Here it is important to note that in C language array
indexing starts with 0 and not from 1.
• Example: Program to calculate average of 10 marks#include<stdio.h>

• #include<conio.h>main()

• {
• int i, marks[10], sum=0;float avg;

clrscr(); print(“Enter 10 numbers”);for(i=0;i<=9;i++)


scanf(“%d”,&marks[i]); for(i=0;i<=9;i++)

sum=sum+marks[i]; avg=sum/10.0;

printf(“Average is %f”,avg);
getch();

}Explanation:

• Total numbers of variables in this program are 13. Their namesare i,


sum, avg, marks[0], marks[1],…marks[9].
• Notice the input statement, scanf() is repeated 10 times, this is possible
as we can access array index with the help of variable. Observe &marks[i] in scanf(), here i is used
for indexing. As the loop proceed value of i changes from 0 to 9. In this way wee neednot to write
scanf() 10 times.
• Data manipulation becomes also easy, we added all 10 values stored in
an array putting statement sum=sum+marks[i] in theloop.
456
• Since we have an array of size 10 and each of these blocks are oftype
int, to tal memory consumed for this array is 20 bytes (2 bytes for each).

One dimension array


To use an array variable in a program, it must be declared. When defining anarray in a program,
three things need to be specified.
• What kind of data it can hold, i.e., int, char, double, string, etc.
• How many values it can hold, i.e., the maximum number it can hold
• A name
In the previous example the array declared known as one dimensional array.
Note: According to our previous example marks is not a variable name but marks[0] is a variable.
Thus we can not assign anything to marks like marks=5;

Two-dimension array
C language supports multidimensional arrays also. The simplest form of a multidimensional array
is the two-dimensional array. Both the row's and column'sindex begin from 0.
Two dimensional arrays is actually array of arrays. So here we are creating an array of several
identical arrays.
Consider the following declaration style

int a [2][3];

• this declaration means, we have an array of 2 arrays containing 3 int blocks each.
o Total numbers of blocks are 6, they are all of type int. Memory
allocation done is always sequential, but we canassume it as two arrays each of size 3.
o Logically we can see it as a row column structure. Firstrow is
our 0th array and second row is 1st array.
o Two dimensional arrays are used to handle data which is
logically two dimensional like matrix.
• Example: Program to add two matrix of order 3 x 3.#include<conio.h>

#include<stdio.h> main(){int a[3][3],b[3][3],c[3][3];int i,j; clrscr();printf("Enter 9 numbers for first

matrix\n");for(i=0;i<3;i++)for(j=0;j<3;j++) scanf("%d",&a[i][j]); printf("Enter 9 numbers for second

matrix\n");

for(i=0;i<3;i++)
for(j=0;j<3;j++)

scanf("%d",&b[i][j]);

for(i=0;i<3;i++)
for(j=0;j<3;j++)

c[i][j]=a[i][j]+b[i][j];printf("\nSum of matrix is: \n");


457
for(i=0;i<3;i++)
{

for(j=0;j<3;j++)
printf("%d ",c[i][j]);printf("\n");

}
getch();

}
Explanation:

1. Notice the declaration of arrays. We have declared three two dimensionalarrays.


2. Observe the style of input. scanf() is repeated with nested loop.

3. Lastly sum of corresponding elements of two matrices are added and storedin third
array.
4. Finally sum is displayed on the screen Initialization of array at the time of

declarationInitializing one dimension array

int a[5]={ 23,45,11,67,55};


int a[ ]= { 23,45,11,67,55};int a[5]= {22,45};

int a[5]= {12,23,76,85,43,33};

In the first style we declared an array with size 5 and assign 5 values to them, Firstvalue is stored
in a[0] and last in a[4].
Second style is also valid. When We initialize array at the time of declaration it isnot necessary to
mention size of array, otherwise it is compulsory. Compiler assumes the size of array by counting
number of values assigned to it.
Third notation style is also valid as two variables a[0] and a[1] initializes with 22and 45, remaining
variables are initialized to 0.
Fourth style leads to compilation error. an array can not be intialized with datamore than the size of
array.
Initialization of two dimension array
int b[2] [3] = {12,65,78,45,33,21};
int b[ ] [3] = {12,65,78,45,33,21};
int b[2] [ ] = {12,65,78,45,33,21};
int b[ ] [ ] = {12,65,78,45,33,21};

Last two styles are invalid and lead to compile time error.

C Structures
Structure is a user-defined datatype in C language which allows us to combine data of different
types together. Structure helps to construct a complex data typewhich is more meaningful. It is

458
somewhat similar to an Array, but an array holds data of similar type only. But structure on the other
hand, can store data of any type, which is practical more useful.
For example: If I have to write a program to store Student information, which willhave Student's
name, age, branch, permanent address, father's name etc, which included string values, integer
values etc, how can I use arrays for this problem, I will require something which can hold data of
different types together.
In structure, data is stored in form of records.

Defining a structure

struct keyword is used to define a structure. struct defines a new data type whichis a collection of
primary and derived datatypes.

Syntax:

struct [structure_tag]

//member variable 1

//member variable 2

//member variable 3

...

}[structure_variables];

As We can see in the syntax above, we start with the struct keyword, then it's optional to provide
our structure a name, we suggest giving it a name, then inside the curly braces, we have to mention
all the member variables, which are nothing but normal C language variables of different types like
int, float, array etc.
After the closing curly brace, we can specify one or more structure variables,again this is optional.
Note: The closing curly brace in the structure type declaration must be followedby a semicolon (;).

Example of Structure

459
struct Student

char name[25];

int age;

char branch[10];

// F for female and M for male

char gender;

};

Here struct Student declares a structure to hold the details of a student which consists of 4 data
fields, namely name, age, branch and gender. These fields are called structure elements or
members.
Each member can have different datatype, like in this case, name is an array
of char type and age is of int type etc. Student is the name of the structure and iscalled as the
structure tag.

Declaring Structure Variables


It is possible to declare variables of a structure, either along with structure definition or after the
structure is defined. Structure variable declaration is similar to the declaration of any normal
variable of any other datatype. Structure variables can be declared in following two ways:

1) Declaring Structure variables separately

460
struct Student

char name[25];

int age;

char branch[10];

//F for female and M for male

char gender;

};

struct Student S1, S2; //declaring variables of struct Student

2) Declaring Structure variables with structure definition

struct Student

char name[25];

int age;

char branch[10];

//F for female and M for male

char gender;

}S1, S2;

Here S1 and S2 are variables of structure Student. However, this approach is not much
recommended.

Accessing Structure Members


Structure members can be accessed and assigned values in a number of ways. Structure members

461
have no meaning individually without the structure. In order to assign a value to any structure
member, the member name must be linked withthe structure variable using a dot . operator also
called period or member
access operator.
For example:

#include<stdio.h>

#include<string.h>

struct Student

char name[25];

int age;

char branch[10];

//F for female and M for male

char gender;

};

int main()

struct Student s1;

/*

s1 is a variable of Student type andage is a member of Student

*/

[Link] = 18;

/*

using string function to add name

*/
462
strcpy([Link], "Viraaj");

/*

displaying the stored values

*/

printf("Name of Student 1: %s\n", [Link]);printf("Age of Student 1: %d\n", [Link]);

return 0;

}
Name of Student 1: ViraajAge of Student 1: 18
We can also use scanf() to give values to structure members through terminal.

scanf(" %s ", [Link]);


scanf(" %d ", &[Link]);

Structure Initialization
Like a variable of any other datatype, structure variable can also be initialized atcompile time.

or,

struct Patient p1;

[Link] = 180.75; //initialization of each member separately

[Link] = 73;

[Link] = 23;

C Array of Structures
Why use an array of structures?
Consider a case, where we need to store the data of 5 students. We can store it by using the
structure as given below.
#include<stdio.h>
struct student

char name[20];
463
int id;

float marks;

};

void main()

struct student s1,s2,s3;

int dummy;

printf("Enter the name, id, and marks of student 1 ");

scanf("%s %d %f",[Link],&[Link],&[Link]);

scanf("%c",&dummy);

printf("Enter the name, id, and marks of student 2 ");

scanf("%s %d %f",[Link],&[Link],&[Link]);

scanf("%c",&dummy);

printf("Enter the name, id, and marks of student 3 ");

scanf("%s %d %f",[Link],&[Link],&[Link]);

scanf("%c",&dummy);

printf("Printing the details \n");

printf("%s %d %f\n",[Link],[Link],[Link]);

printf("%s %d %f\n",[Link],[Link],[Link]);

printf("%s %d %f\n",[Link],[Link],[Link]);

Output

464
Enter the name, id, and marks of student 1 James 90 90

Enter the name, id, and marks of student 2 Adoms 90 90

Enter the name, id, and marks of student 3 Nick 90 90

Printing the details....

James 90 90.000000

Adoms 90 90.000000

Nick 90 90.000000

In the above program, we have stored data of 3 students in the structure. However, the complexity
of the program will be increased if there are 20 students. In that case, we will have to declare 20
different structure variables andstore them one by one. This will always be tough since we will have
to declare a variable every time we add a student. Remembering the name of all the variablesis
also a very tricky task. However, c enables us to declare an array of structures by using which, we
can avoid declaring the different structure variables; instead we can make a collection containing
all the structures that store the information of different entities.

Array of Structures in C
An array of structres in C can be defined as the collection of multiple structures variables where
each variable contains information about different entities. The array of structures in C are used to
store information about multiple entities ofdifferent data types. The array of structures is also
known as the collection of structures.

465
#include<stdio.h> #include <string.h>struct student{

int rollno;

char name[10];

};

int main(){

int i;

struct student st[5];

printf("Enter Records of 5 students");

for(i=0;i<5;i++){ printf("\nEnter Rollno:");scanf("%d",&st[i].rollno);printf("\nEnter Name:");

scanf("%s",&st[i].name);

printf("\nStudent Information List:");

for(i=0;i<5;i++){

printf("\nRollno:%d, Name:%s",st[i].rollno,st[i].name);

return 0;

}
Output:

Enter Records of 5 students

Enter Rollno:1

Enter Name:Sonoo Enter Rollno:2 Enter Name:Ratan Enter Rollno:3 Enter Name:Vimal

Enter Rollno:4 Enter Name:James Enter Rollno:5 Enter Name:Sarfraz

466
Student Information List:Rollno:1, Name:Sonoo Rollno:2, Name:Ratan Rollno:3,

Name:Vimal Rollno:4, Name:James

Rollno:5, Name:Sarfraz that one structure has another stucture as member variable.
C provides us the feature of nesting one structure within another structure by using which, complex
data types are created. For example, we may need to storethe address of an entity employee in a
structure. The attribute address may also have the subparts as street number, city, state, and pin
code. Hence, to store theaddress of the employee, we need to store the address of the employee
into a separate structure and nest the structure address into the structure employee.
Consider the following program.

#include<stdio.h>

struct address

char city[20];

int pin;

char phone[14];

};

struct employee

char name[20];

struct address add; 467

};
printf("Printing the employee information.........\n");

printf("name: %s\nCity: %s\nPincode: %d\nPhone: %s",[Link],[Link].


city,[Link],[Link]);

o By Embedded structure

1) Separate structure
Here, we create two structures, but the dependent structure should be used inside the main
structure as a member. Consider the following example.

468
struct Date

int dd;

int mm;

int yyyy;

};

struct Employee

int id;

char name[20];

struct Date doj;

}emp1;

As We can see, doj (date of joining) is the variable of type Date. Here doj is usedas a member in
Employee structure. In this way, we can use Date structure in many structures.
2) Embedded structure

The embedded structure enables us to declare the structure inside the [Link], it requires
less line of codes but it can not be used in multiple data structures. Consider the following example.
o struct Employee
o {
o int id;
o char name[20];
o struct Date
o {
o int dd;
o int mm;
o int yyyy;
o }doj;
o } emp1;

Accessing Nested Structure

469
We can access the member of the nested structure by Outer_Structure.Nested_Structure.member
as given below:

[Link]

[Link]

[Link]

C Nested Structure example

a simple example of the nested structure in C language.

#include <stdio.h>

#include <string.h>

struct Employee

int id;

char name[20];

struct Date

int dd;

int mm;

int yyyy;

}doj;

}e1;

int main( )

//storing employee information

470
[Link]=101;

strcpy([Link], "Sonoo Jaiswal");//copying string into char array

[Link]=10;

[Link]=11;

[Link]=2014;

//printing first employee information

printf( "employee id : %d\n", [Link]);

printf( "employee name : %s\n", [Link]);

printf( "employee date of joining (dd/mm/yyyy) : %d/%d/%d\n", [Link],e


[Link],[Link]);

return 0;
char name[20];

struct address add;

};

void display(struct employee);

void main ()

struct employee emp;

printf("Enter employee information?\n");

scanf("%s %s %d %s",[Link],[Link], &[Link], [Link]);

display(emp);

void display(struct employee emp)

471
printf("Printing the details ...... \n");

printf("%s %s %d %s",[Link],[Link],[Link],[Link]);

We can pass a structure as a function argument just like we pass any othervariable or an array as
a function argument.
Example:
int roll;};

void show(struct Student st);void main()

struct Student std;

printf("\nEnter Student record:\n");printf("\nStudent name:\t"); scanf("%s", [Link]);

printf("\nEnter Student rollno.:\t"); scanf("%d", &[Link]);

show(std);

void show(struct Student st)

#include<stdio.h>

struct Student

char name[10];

printf("\nstudent name is %s", [Link]);

printf("\nroll is %d", [Link]);

C Unions

472

int roll;};
Unions are conceptually similar to structures. The syntax to declare/define a union is also similar
to that of a structure. The only differences is in terms of storage. In structure each member has its
own storage location, whereas all members of union uses a single shared memory location which
is equal to the sizeof its largest data member.

union item

int m;

float x;

char c;

}It1;
This implies that although a union may contain many members of different types, it cannot handle
all the members at the same time. A union is declaredusing the union keyword.

This declares a variable It1 of type union item. This union contains three memberseach with a
different data type. However only one of them can be used at a time. This is due to the fact that
only one location is allocated for allthe union variables, irrespective of their size. The compiler
allocates the storagethat is large enough to hold the largest variable type in the union.
In the union declared above the member x requires 4 bytes which is largest amongst the members
for a 16-bit machine. Other members of union will sharethe same memory address.

Accessing a Union Member in C


Syntax for accessing any union member is similar to accessing structure members,

473
union test

int a;

float b;

char c;

}t;

t.a; //to access members of union t

t.b;

t.c;

Time for an Example

#include <stdio.h>

union item

int a;

float b;

char ch;

};

int main( )

union item it;it.a = 12;

it.b = 20.2;[Link] = 'z'

printf("%d\n", it.a);

474
printf("%f\n", it.b);

printf("%c\n", [Link]);return 0;

the expected result. This is because in union, the memory is shared among
different data types. Hence, the only member whose value is currently stored willhave the memory.
In the above example, value of the variable c was stored at last, hence the valueof other variables
is lost.

Advantage of union over structure


It occupies less memory because it occupies the size of the largest member only.

Disadvantage of union over structure


Only the last entered data can be stored in the union. It overwrites the datapreviously stored in the
union.

String
String is nothing but a collection of characters in a linear sequence. 'C' alwaystreats a string a
single data even though it contains whitespaces. A single character is defined using single quote
representation. A string is representedusing double quote marks.
Example, "Welcome to the world of programming!"

'C' provides standard library <string.h> that contains many functions which can beused to perform
complicated string operations easily.
Declare and initialize a String

A string is a simple array with char as a data type. 'C' language does not directlysupport string as a
data type. Hence, to display a string in 'C', We need to makeuse of a character array.
The general syntax for declaring a variable as a string is as follows,

char string_variable_name [array_size];

The classic string declaration can be done as follow:


char string name[string_length] = "string";

The size of an array must be defined while declaring a string variable because itused to calculate
how many characters are going to be stored inside the string variable. Some valid examples of
string declaration are as follows,

475
char first_name[15]; //declaration of a string variable

char last_name[15];

The above example represents string variables with an array size of 15. This means that the given
character array is capable of holding 15 characters at [Link] indexing of array begins from 0
hence it will store characters from a 0-14 position. The C compiler automatically adds a NULL
character '\0' to the character array created.
The initialization of a string variable. Following example demonstrates theinitialization of a string
variable,

char first_name[15] = "ANTHONY";

char first_name[15] = {'A','N','T','H','O','N','Y','\0'}; // NULL character '\0' is


required at end in this declaration

char string1 [6] = "hello";/* string size = 'h'+'e'+'l'+'l'+'o'+"NULL" = 6 */

char string2 [ ] = "world"; /* string size = 'w'+'o'+'r'+'l'+'d'+"NULL" = 6 */

char string3[6] = {'h', 'e', 'l', 'l', 'o', '\0'} ; /*Declaration as set of characters ,Size
6*/

In string3, the NULL character must be added explicitly, and the characters areenclosed in single
quotation marks.
'C' also allows us to initialize a string variable without defining the size of thecharacter array. It can
be done in the following way,

char first_name[ ] = "NATHAN";

The name of a string acts as a pointer because it is basically an array.


String Input: Read a String
When writing interactive programs which ask the user for input, C provides thescanf(), gets(), and
fgets() functions to find a line of text entered from the user.
When we use scanf() to read, we use the "%s" format specifier without using the"&" to access the
variable address because an array name acts as a pointer. For example:

476
#include <stdio.h>

int main() {

char name[10];

int age;

printf("Enter your first name and age: \n");

scanf("%s %d", name, &age);

printf("You entered: %s %d",name,age);

Output:

Enter your first name and age:

John_Smith 48

The problem with the scanf function is that it never reads an entire string. It will halt the reading
process as soon as whitespace, form feed, vertical tab, newline ora carriage return occurs. Suppose
we give input as "Guru99 Tutorials" then the scanf function will never read an entire string as a
whitespace character occurs between the two names. The scanf function will only read Guru99.
In order to read a string contains spaces, we use the gets() function. Gets ignoresthe whitespaces.

477
#include <stdio.h>

int main() {

char full_name[25];

printf("Enter your full name: ");

gets(full_name);

printf("My full name is %s ",full_name);

return 0;

Output:

Enter your full name: Dennis Ritchie

My full name is Dennis Ritchie

Another safer alternative to gets() is fgets() function which reads a specified


number of characters. For example:

#include <stdio.h>

int main() {

char name[10];

printf("Enter your name plz: ");

fgets(name, 10, stdin);

printf("My name is %s ",name);


It stops reading when a newline is reached (the Enter key is pressed).For example:

return 0;}

Output:

478
Enter your name plz: Carlos

My name is Carlos

The fgets() arguments are :

• the string name,

• the number of characters to read,

• stdin means to read from the standard input which is the keyboard.


String Output: Print/Display a String
The standard printf function is used for printing or displaying a string on an outputdevice. The
format specifier used is %s

Example,

printf("%s", name);

String output is done with the fputs() and printf() functions.


fputs() function

The fputs() needs the name of the string and a pointer to where We want to display the text. We
use
printf("Enter your town: ");gets(town);

fputs(town, stdout);
return 0;}
#include <stdio.h>int main()

{char town[40];

stdout which refers to the standard output in order toprint to the screen. For example:

479
The standard 'C' library provides various functions to manipulate the strings within a program.
These functions are also called as string handlers. All thesehandlers are present inside <string.h>
header file.

Output:

Enter your town: New York

New York

puts function

The puts function prints the string on an output device and moves the cursor back
to the first position. A puts function can be used in the following way,

#include <stdio.h>
int main() {

char name[15];

gets(name); //reads a string

puts(name); //displays a string

return 0;}

The syntax of this function is comparatively simple than other functions.

The string library

Function Purpose

This function is used for finding a length of a string. It returns


strlen() how manycharacters are present in a string excluding the
NULL character.

480
This function is used for combining twostrings together to
strcat(str1, str2) form a single [Link] Appends or concatenates str2 to the
end of str1 and returns a pointer to str1.

This function is used to compare two strings with each other.


strcmp(str1, str2) It returns 0 if str1 is equal to str2, less than 0 if str1 <str2, and
greater than 0 if str1 > str2.

int val;

//string comparison

val= strcmp(string1,string2); if(val==0){

printf("Strings are equal\n");

else{

printf("Strings are not equal\n");

//string concatenation

printf("Concatenated string:%s",strcat(string1,string2)); //string1 contains helloworld!

//string length

printf("\nLength of first string:%d",strlen(string1)); printf("\nLength of second

string:%d",strlen(string2));

//string copy

printf("\nCopied string is:%s\n",strcpy(string3,string1)); //string1 is copied intostring3

return 0;}

481
Strings are not equal
Output:

Concatenated string:Hello World!

Length of first string:12

Length of second string:7

Copied string is:Hello World!

Other important library functions are:


• strncmp(str1, str2, n) :it returns 0 if the first n characters of str1 is equal tothe first
n characters of str2, less than 0 if str1 < str2, and greater than 0 if str1 > str2.
• strncpy(str1, str2, n) This function is used to copy a string from anotherstring.
Copies the first n characters of str2 to str1
• strchr(str1, c): it returns a pointer to the first occurrence of char c in str1, orNULL
if character not found.
• strrchr(str1, c): it searches str1 in reverse and returns a pointer to theposition of
char c in str1, or NULL if character not found.
• strstr(str1, str2): it returns a pointer to the first occurrence of str2 in str1, orNULL
if str2 not found.
• strncat(str1, str2, n) Appends (concatenates) first n characters of str2 to theend
of str1 and returns a pointer to str1.
• strlwr() :to convert string to lower case
• strupr() :to convert string to upper case
• strrev() : to reverse string

Converting a String to a Number


In C programming, we can convert a string of numeric characters to a numericvalue to prevent a
run-time error. The stdio.h library contains the following functions for converting a string to a
number:
int atoi(str) Stands for ASCII to integer; it converts str to the equivalent int value. 0 is returned if the
first character is not a number or no numbers areencountered.
double atof(str) Stands for ASCII to float, it converts str to the equivalent double value. 0.0 is
returned if the first character is not a number or numbers are encountered.
long int atol(str) Stands for ASCII to long int, Converts str to the equivalentlong integer value.
0 is returned if the first character is not a number or nonumbers are encountered.

The following program demonstrates atom() function:


482
#include <stdio.h>int main()

{char *string_id[10];int ID;

printf("Enter a number: ");gets(string_id);

ID = atoi(string_id); print("you enter %d ",ID);

return 0;}

Output:

Enter a number: 221348

you enter 221348

➢ A string pointer declaration such as char *string = "language" is a constantand


cannot be modified.

Summary
• A string is a sequence of characters stored in a character array.
• A string is a text enclosed in double quotation marks.
• A character such as 'd' is not a string and it is indicated by single quotation marks.
• 'C' provides standard library functions to manipulate strings in a program. String
manipulators are stored in <string.h> header file.
• A string must be declared or initialized before using into a program.
• There are different input and output string functions, each one among them has itsfeatures.
• Don't forget to include the string library to work with its functions
• We can convert string to number through the atoi(), atof() and atol() which are veryuseful
for coding and decoding processes.
• We can manipulate different strings by defining a string array.

Pointer?

POINTER is a variable that stores address of another variable. A pointer can alsobe used to refer
to another pointer function. A pointer can be incremented/decremented, i.e., to point to the next/
previous memory [Link] purpose of pointer is to save memory space and achieve faster
execution time.

How does Pointer Work?


If we declare a variable v of type int, v will actually store a value.
v is equal to zero now.

483
However, each variable, apart from value, also has its address (or, simply put, where it is located in
the memory). The address can be retrieved by putting anampersand (&) before the variable name.

If We print the address of a variable on the screen, it will look like a totally
random number (moreover, it can be different from run to run).

The output of this program is -480613588.

Now, what is a pointer? Instead of storing a value, a pointer will y store the
address of a variable.

Int *y = &v;

VARIABLE POINTER

A variable that points to thestorage/memory


A value stored in
address
a named storage/memory address
of another variable

Declaring a pointer
Like variables, pointers have to be declared before they can be used in our program. Pointers can
be named anything We want as long as they obey C'snaming rules. A pointer declaration has the
following form.

484
data_type * pointer_variable_name;

Here,
• data_type is the pointer's base type of C's variable types and indicates thetype of
the variable that the pointer points to.
• The asterisk (*: the same asterisk used for multiplication) which is indirection
operator, declares a pointer.
• Some valid pointer declarations
• int *ptr_thing; /* pointer to an integer */
• int *ptr1,thing;/* ptr1 is a pointer to type integer and thing is an integer variable
• */
• double *ptr2; /* pointer to a double */float *ptr3; /* pointer to a float */

• char *ch1 ; /* pointer to a character */


• float *ptr, variable;/*ptr is a pointer to type float and variable is an ordinary floatvariable */

Initialize a pointer
After declaring a pointer, we initialize it like standard variables with a variable address. If pointers
are not uninitialized and used in the program, the results are unpredictable and potentially
disastrous.
To get the address of a variable, we use the ampersand (&)operator, placed before the name of a
variable whose address we need. Pointer initialization isdone with the following [Link] =
&variable.

A simple program for pointer illustration is given below:


Address stored in a variable p is:60ff08

Value stored in a variable p is10


#include <stdio.h>

int main()

{
int a=10; //variable declaration

int *p; //pointer variable declaration

p=&a; //store address of variable a in pointer p printf("Address stored in a variable p


is:%x\n",p); //accessing the address

printf("Value stored in a variable p is:%d\n",*p); //accessing the valuereturn 0;


Output:
485
Operator Meaning

Serves 2 purpose

* • Declaration of a pointer
• Returns the value of thereferenced
variable

Serves only 1 purpose


&
➢ Returns the address of avariable

Types of a pointer

Null pointer
We can create a null pointer by assigning null value during the pointer declaration. This
method is useful when We do not have any address assigned tothe pointer. A null pointer
always contains value 0.
Following program illustrates the use of a null pointer:
#include <stdio.h>
int main()
{
int *p = NULL; //null pointer
printf (“The value inside variable p is:\n%x”,p);

return 0;
Output:
The value inside variable p is:
0

Void Pointer
In C programming, a void pointer is also called as a generic pointer. It does not have any standard
data type. A void pointer is created by using the keyword [Link] can be used to store an address of
any variable.

Following program illustrates the use of a void pointer: #include <stdio.h>int main()
486
{

void *p = NULL; //void pointer

printf("The size of pointer is:%d\n",sizeof(p));return 0;

}
Output: The size of pointer is:4

Wild pointer
A pointer is said to be a wild pointer if it is not being initialized to anything. Thesetypes of
pointers are not efficient because they may point to some unknown memory location
which may cause problems in our program and it may lead to crashing of the program. One
should always be careful while working with wild pointers.
Following program illustrates the use of wild pointer: #include <stdio.h>int main()
{ int *p; //wild pointer printf("\n%d",*p);

return 0;

}
Output:
timeout: the monitored command dumped core sh: line 1: 95298 Segmentation fault
timeout 10s main

Other types of pointers in 'c' are as follows:


• Dangling pointer
• Complex pointer
• Near pointer
• Far pointer
• Huge pointer

Direct and Indirect Access Pointers


In C, there are two equivalent ways to access and manipulate a variable content
• Direct access: we use directly the variable name
• Indirect access: we use a pointer to the variableunderstand this with the help

of program below

• #include <stdio.h>

• /* Declare and initialize an int variable */int var = 1;


/* Declare a pointer to int */int *ptr;int main( void )

Indirect access, var = 1

487
The address of var = 4202496

The address of var = 4202496

Indirect access, var = 48

Pointers Arithmetic
The pointer operations are summarized in the following figure

Pointer Operations
Priority operation (precedence)

When working with pointers, we must observe the following priority rules:

o The operators * and & have the same priority as the unary operators (the
negation!, the incrementation++, decrement--).
o In the same expression, the unary operators *, &,!, ++, - are evaluatedfrom right
to left.
488
• If a P pointer points to an X variable, then * P can be used wherever X can bewritten.
• The following expressions are equivalent:

int X =10 int *P = &Y;

For the above code, below expressions are true

Expression Equivalent Expression

Y=*P+1
Y=X+1 X=X+10X+=2
*P=*P+10
++X
*P+=2
X++
++*P (*P)++

In the latter case, parentheses are needed: as the unary operators * and ++ areevaluated from right
to left, without the parentheses the pointer P would be incremented, not the object on which P
points.

Below table shows the arithmetic and basic operation that can be used whendealing with pointers

Operation Explanation

int *P1,*P2 P1=P2; P1 and P2 point tothe same


Assignment
integer variable

Incrementation and decrementation Int *P1; P1++;P1-- ;

489
This allows the pointer to move N elements in a
table. The pointer will beincreased or decreased
Adding an offset (Constant) by N times the number of byte (s) of the type of
the
variable. P1+5;

Pointers and Arrays


Traditionally, we access the array elements using its index, but this method can beeliminated by
using pointers. Pointers make it easy to access each array element.

#include <stdio.h>

int main()

int a[5]={1,2,3,4,5}; //array initialization

int *p; //pointer declaration

/*the ptr points to the first element of the array*/

p=a; /*We can also type simply ptr==&a[0] */


printf("Printing the array elements using pointer\n"); for(int i=0;i<5;i++)//loop for

traversing array elements

{
printf("\n%x",*p); //printing array elements

p++; //incrementing to the next element, you can also write p=p+1

return 0;

then it will execute in this manner:

490
Pointer Addition/Increment

Since p currently points to the location 0 after adding 1, the value will become 1,and hence
the pointer will point to the memory location 1.

Pointers and Strings


A string is an array of char objects, ending with a null character '\ 0'. We can manipulate
strings using pointers. Here is an example that explains this section #include <stdio.h>
#include <string.h>int main()
{

char str[]="Hello Manish99";char *p;

p=str;

printf("First character is:%c\n",*p);p =p+1;

printf("Next character is:%c\n",*p); printf("Printing all the characters in a string\n");p=str;

//reset the pointer

for(int i=0;i<strlen(str);i++)

Outpu
t

Adding a particular number to a pointer will move the pointer location to the
value obtained by an addition operation. Suppose p is a pointer that currently
points to the memory location 0 if we perform following addition operation, p+1

491
p++;

return 0;

Output

First character is:H

Next character is:e

Printing all the characters in a string

e
l
l
o

a
n
i
s
h
9

Another way to deal strings is with an array of pointers like in the following
program:

#include <stdio.h>

492
int main(){

char *materials[ ] = { "iron", "copper", "gold"};

printf("Please remember these materials :\n");

int i ;

for (i = 0; i < 3; i++) {

printf("%s\n", materials[ i ]);}

return 0;}

Output:

Please remember these materials:

iron

copper

gold

Advantages of Pointers

Pointers are useful for accessing memory locations.


Pointers provide an efficient way for accessing the elements of an array
structure.
Pointers are used for dynamic memory allocation as well as
deallocation.
Pointers are used to form complex data structures such as linked list,
graph, tree, etc.

Disadvantages of Pointers
1. Pointers are a little complex to understand.
2. Pointers can lead to various errors such as segmentation faults or canaccess a
memory location which is not required at all.

3. If an incorrect value is provided to a pointer, it may cause memorycorruption.

493
4. Pointers are also responsible for memory leakage.
5. Pointers are comparatively slower than that of the variables.
6. Programmers find it very difficult to work with the pointers; therefore it is
programmer's responsibility to manipulate a pointer carefully.
Summary
o A pointer is nothing but a memory location where data is stored.
o A pointer is used to access the memory location.
o There are various types of pointers such as a null pointer, wild pointer, voidpointer
and other types of pointers.
o Pointers can be used with array and string to access elements moreefficiently.
o We can create function pointers to invoke a function dynamically.
o Arithmetic operations can be done on a pointer which is known as pointer
arithmetic.
o Pointers can also point to function which make it easy to call differentfunctions in
the case of defining an array of pointers.
o When We want to deal different variable data type, We can use a typecastvoid
pointer.
Functions in C

A function is a block of code that performs a particular task.

There are many situations where we might need to write same line of code for more than once in a
program. This may lead to unnecessary repetition of code, bugs and even becomes boring for the
programmer. So, C language provides anapproach in which We can declare and define a group of
statements once in theform of a function and it can be called and used whenever required.
These functions defined by the user are also know as User-defined Functions

C functions can be classified into two categories,


➢ Library functions
➢ User-defined functions

494
Library functions are those functions which are already defined in C library,
example printf(), scanf(), strcat() etc. We just need to include appropriate header
files to use these functions. These are already declared and defined in C libraries.

A User-defined functions on the other hand, are those functions which are
defined by the user at the time of writing program. These functions are made for
code reusability and for saving time and space.

Benefits of Using Functions

1. It provides modularity to Wer program's structure.

2. It makes our code reusable. We just have to call the function by its name to
use it, wherever required.

3. In case of large programs with thousands of code lines, debugging andediting


becomes easier if We use functions.

4. It makes the program more readable and easy to understand.


Function Declaration

General syntax for function declaration is,

returntype functionName(type1 parameter1, type2 parameter2,...);

495
Like any variable or an array, a function must also be declared before its used. Function declaration
informs the compiler about the function name, parametersis accept, and its return type. The actual
body of the function can be defined separately. It's also called as Function Prototyping. Function
declaration consistsof 4 parts.
1. returntype
2. function name
3. parameter list
4. terminating semicolon

returntype
When a function is declared to perform some sort of calculation or any operationand is expected
to provide with some result at the end, in such cases,
a return statement is added at the end of function body. Return type specifies thetype of value(int,
float, char, double) that function is expected to return to the program which called the function.
Note: In case our function doesn't return any value, the return type wouldbe void.
functionName
Function name is an identifier and it specifies the name of the function. Thefunction name is any
valid C identifier and therefore must follow the same naming rules like other variables in C
language.
parameter list

The parameter list declares the type and number of arguments that the functionexpects when it is
called. Also, the parameters in the parameter list receives theargument values when the function
is called. They are often referred as formal parameters.
An Example
a simple program with a main() function, and a user defined function to multiplytwo numbers, which
will be called from the main() function.

#include<stdio.h>

int multiply(int a, int b); // function declaration

int main()
}

intdefinition
Function i, j, result;Syntax
Just like in the example above, the general syntax of function definition is,
printf("Please enter 2 numbers you want to multiply...");
496
scanf("%d%d", &i, &j);
returntype functionName(type1 parameter1, type2 parameter2,...)

// function body goes here

The first line returntype functionName(type1 parameter1, type2 parameter2,...) is known as


function header and the statement(s) within curlybraces is called function body.
Note: While defining a function, there is no semicolon(;) after the parenthesis inthe function header,
unlike while declaring the function or calling the function.

functionbody
The function body contains the declarations and the statements(algorithm) necessary for
performing the required task. The body is enclosed within curlybraces { ... } and consists of three
parts.
a) local variable declaration(if required).
b) function statements to perform the task inside the function.
c) a return statement to return the result evaluated by the function(if returntype is
void, then no return statement is required).

Calling a function
When a function is called, control of the program gets transferred to the function.

functionName(argument1, argument2,...);

In the example above, the statement multiply(i, j); inside the main() function isfunction call.

Passing Arguments to a function


Arguments are the values specified during the function call, for which the formal

parameters are declared while defining the function: It is possible to have a function with
parameters but no return type. It is not necessary, that if a function accepts parameter(s),
it must return a result too.

497
While declaring the function, we have declared two parameters a and b of
type int. Therefore, while calling that function, we need to pass two arguments, else we will get
compilation error. And the two arguments passed should be received in the function definition,
which means that the function header in the function definition should have the two parameters to
hold the argument values. These received arguments are also known as formal parameters. The
name of thevariables while declaring, calling and defining a function can be different.

Returning a value from function


A function may or may not return a result. But if it does, we must use
the return statement to output the result. return statement also ends the function execution, hence
it must be the last statement of any function. If Wewrite any statement after the return statement,

498
it won't be executed.

The datatype of the value returned using the return statement should be same asthe
return type mentioned at function declaration and definition. If any of it mismatches, We
will get compilation [Link] the next tutorial, we will learn about the different types of
user defined functions in C language and the concept of Nesting of functions which is used
inrecursion.

Type of User-defined Functions in C


There can be 4 different types of user-defined functions, they are:

• Function with no arguments and no return value


• Function with no arguments and a return value
• Function with arguments and no return valueFunction with arguments and a return value
• Below, about all these types, along with program examples.

Function with no arguments and no return value


Such functions can either be used to display information or they are completelydependent on user
inputs.
Below is an example of a function, which takes 2 numbers as input from user, anddisplay which is
the greater number. #include<stdio.h>

void greatNum(); // function declarationint main()

greatNum();{

// function call
499
return 0;

void greatNum()

// function definition
int i, j;

printf("Enter 2 numbers that you want to compare...");scanf("%d%d", &i, &j);

if(i > j) {

printf("The greater number is: %d", i);

}
else {

printf("The greater number is: %d", j);

}}

Function with no arguments and a return value


We have modified the above example to make the function greatNum() returnthe number which is
greater amongst the 2 input numbers.

if(i > j) {

greaterNum = i;

else {

greaterNum = j;

// returning the result

return greaterNum;

Function with arguments and no return value

500
We are using the same function as example again and again, to demonstrate thatto solve a problem
there can be many different ways.
This time, we have modified the above example to make the
function greatNum() take two int values as arguments, but it will not be returninganything.

greatNum(i, j); // function call

return 0;

void greatNum(int x, int y) // function definition

if(x > y) {

printf("The greater number is: %d", x);

else {

printf("The greater number is: %d", y);

#include<stdio.h>

int greatNum(int a, int b); // function declaration

int main()

int i, j, result;

printf("Enter 2 numbers that you want to compare...");

501
Function with arguments and a return value
This is the best type, as this makes the function completely independent of inputsand outputs, and
only the logic is defined inside the function body.

scanf("%d%d", &i, &j);


result = greatNum(i, j); // function call

printf("The greater number is: %d", result);

return 0;

int greatNum(int x, int y) // function definition

if(x > y) {

return x;

else {

return y;

Nesting of Functions
C language also allows nesting of functions i.e to use/call one function insideanother function's
body. We must be careful while using nested functions, because it may lead to infinite nesting.

502
function1()

// function1 body here

function2();

// function1 body here

If function2() also has a call for function1() inside it, then in that case, it will lead to an infinite
nesting. They will keep calling each other and the program will neverterminate.
consider that inside the main() function, function1() is called and its execution starts, then inside
function1(), we have a call for function2(), so the control of program will go to the function2(). But
as function2() also has a call to function1()in its body, it will call function1(), which will again call
function2(), and this will goon for infinite times, until We forcefully exit from program execution.

Recursion
Recursion is a special way of nesting functions, where a function calls itself insideit. We must have
certain conditions in the function to break out of the recursion,otherwise recursion will occur infinite
times.

function1()

// function1 body

function1();

// function1 body

Example: Factorial of a number using Recursion

503
#include<stdio.h>

int factorial (int //declaring the function


x);

void main()

int a, b;

printf("Enter a number...");

scanf("%d", &a);

b = factorial(a); //calling the function named factorial

printf("%d", b);

int factorial(int x) //defining the function

int r = 1;

if(x == 1)

return 1;

else

r = x*factorial(x-1); //recursion, since the function calls itself

return r;

Similarly, there are many more applications of recursion in C language. Go to theprograms section,
to find out more programs using recursion.

504
File Handling in C
In programming, we may require some specific input data to be generated severalnumbers of times.
Sometimes, it is not enough to only display the data on the console. The data to be displayed may
be very large, and only a limited amount ofdata can be displayed on the console, and since the
memory is volatile, it is impossible to recover the programmatically generated data again and
again.
However, if we need to do so, we may store it onto the local file system which isvolatile and can be
accessed every time. Here, comes the need of file handling inC.
File handling in C enables us to create, update, read, and delete the files stored onthe local file
system through our C program. The following operations can be performed on a file.
• Creation of the new file
• Opening an existing file
• Reading from the file
• Writing to the file
• Deleting the file

Functions for file handling


There are many functions in the C library to open, read, write, search and closethe file. A list of file
functions are given below:

No. Function Description

1 fopen() opens new or existing file

2 fprintf() write data into the file

3 fscanf() reads data from the file

4 fputc() writes a character into the file

5 fgetc() reads a character from file

6 fclose() closes the file

7 fseek() sets the file pointer to given position

505
8 fputw() writes an integer to file

9 fgetw() reads an integer from file

10 ftell() returns current position

11 rewind() sets the file pointer to the beginning of the file

name can be like "c://some_folder/some_file.ext".

• The mode in which the file is to be opened. It is a [Link] can use one of the

following modes in the fopen() function.

Mode Description

r opens a text file in read mode

w opens a text file in write mode

a opens a text file in append mode

r+ opens a text file in read and write mode

w+ opens a text file in read and write mode

a+ opens a text file in read and write mode

rb opens a binary file in read mode

wb opens a binary file in write mode

ab opens a binary file in append mode

506
rb+ opens a binary file in read and write mode

wb+ opens a binary file in read and write mode

ab+ opens a binary file in read and write mode

The fopen function works in the following way.


• Firstly, It searches the file to be opened.
• Then, it loads the file from the disk and place it into the buffer. The buffer isused
to provide efficiency for the read operations.
• It sets up a character pointer which points to the first character of the file.

Consider the following example which opens a file in write mode.

Output

The content of the file will be printed.

#include<stdio.h>

void main( )

FILE *fp ;

char ch ;

fp = fopen("file_handle.c","r") ;

while ( 1 )

ch = fgetc ( fp ) ;

if ( ch == EOF )

break ;

printf("%c",ch) ;

fclose (fp ) ; 507

}
#include; void main( )

FILE *fp; // file pointerchar ch;

fp = fopen("file_handle.c","r");while ( 1 )

ch = fgetc ( fp ); //Each character of the file is read and stored in the character [Link] ( ch ==

EOF )

break; printf("%c",ch);

fclose (fp );

Closing File: fclose()

C fprintf() and fscanf()

C fprintf() and fscanf() example


1. int fclose(FILE *fp );

C fputc() and fgetc()

C fputc() and fgetc() example

508
C fputs() and fgets()

C fputs() and fgets() example

C fseek()

C fseek() example

C fprintf() and fscanf()


Writing File : fprintf() function
The fprintf() function is used to write set of characters into file. It sends formattedoutput to a
stream.
Syntax:

int fprintf(FILE *stream, const char *format [, argument, ...])

Example:

#include <stdio.h>

main(){

FILE *fp;

fp = fopen("[Link]", "w");//opening file

fprintf(fp, "Hello file by fprintf...\n");//writing data into file

fclose(fp);//closing file

Reading File: fscanf() function#include <stdio.h>\


void main()

FILE *fptr;
509
int id;

char name[30];
float salary;

fptr = fopen("[Link]", "w+");/* open for writing */

if (fptr == NULL)

{
printf("File does not exists \n");

return;

}
printf("Enter the id\n"); scanf("%d", &id); fprintf(fptr, "Id= %d\n", id); printf("Enter the

name \n");scanf("%s", name);

fprintf(fptr, "Name= %s\n", name);

The fscanf() function is used to read set of characters from file. It reads a word
from the file and returns EOF at the end of file.

Syntax: int fscanf(FILE *stream, const char *format [, argument, ...])


Example: #include <stdio.h>main (){

FILE *fp;

char buff[255];//creating char array to store data of filefp = fopen("[Link]", "r");

while(fscanf(fp, "%s", buff)!=EOF){printf("%s ", buff );

fclose(fp);

}
Output:

Hello file by fprintf...

C File Example: Storing employee information

510
A file handling example to store employee information as entered by user fromconsole. We are
going to store id, name and salary of the employee.
printf("Enter the salary\n");

scanf("%f", &salary);

fprintf(fptr, "Salary= %.2f\n", salary);

fclose(fptr);

Output:

Enter the id

Enter the name

sonoo

Enter the salary

120000

Now open file from current directory. For windows operating system, go to TC\bindirectory, We will
see [Link] file. It will have following information.
[Link]
Id= 1
Name= sonoo Salary= 120000

Command Line Arguments in C


The arguments passed from command line are called command line [Link] arguments
are handled by main() function.
To support command line argument, We need to change the structure of main()function as given
below.

int main(int argc, char *argv[] )

Here, argc counts the number of arguments. It counts the file name as the first
argument.
The argv[] contains the total number of arguments. The first argument is the filename
always.

511
#include <stdio.h>

void main(int argc, char *argv[] ) {

printf("Program name is: %s\n", argv[0]);


if(argc < 2){
printf("No argument passed through command line.\n");

}
else{

printf("First argument is: %s\n", argv[1]);

}
Example
the example of command line arguments where we are passing one argumentwith file
name.

Run this program as follows in Linux:

./program hello

Run this program as follows in Windows from command line:

[Link] hello

Output:

Program name is: program

First argument is: hello

If we pass many arguments, it will print only one.

./program hello c how r u

Output:

512
Program name is: program

First argument is: hello

./program "hello c how r u"


But if we pass many arguments within double quote, all arguments will be treated as a single
argument only.

Output:

Program name is: program

First argument is: hello c how r u

We can write our program to print all the arguments. In this program, we areprinting only argv[1],
that is why it is printing only one argument.

C - Preprocessors
The C Preprocessor is not a part of the compiler but is a separate step in the compilation process.
In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do
required pre-processing before the actual compilation. We'll refer to the C Preprocessor as CPP.
All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character,
and for readability, a preprocessor directive should begin in the first column. The following section
lists down all the important preprocessor directives −

[Link]. Directive & Description

#define
1
Substitutes a preprocessor macro.

#include
2
Inserts a particular header from another file.

#undef
3
Undefines a preprocessor macro.

513
#ifdef
4
Returns true if this macro is defined.

#ifndef
5
Returns true if this macro is not defined.

#if
6
Tests if a compile time condition is true.

#else
7
The alternative for #if.

#elif
8
#else and #if in one statement.

#endif
9
Ends preprocessor conditional.

#error
10
Prints error message on stderr.

#pragma
11
Issues special commands to the compiler, using a standardized method.

Preprocessors Examples
Analyze the following examples to understand various directives.#define MAX_ARRAY_LENGTH 20
This directive tells the CPP to replace instances of MAX_ARRAY_LENGTH with 20.
#include <stdio.h>
#include "myheader.h"
Use #define for constants to increase readability.

514
These directives tell the CPP to get stdio.h from System Libraries and add the text to the current
source file. The next line tells CPP to get myheader.h from thelocal directory and add the content
to the current source file.

#undef FILE_SIZE
#define FILE_SIZE 42

It tells the CPP to undefine existing FILE_SIZE and define it as 42.

#ifndef MESSAGE
#define MESSAGE "You wish!"
#endif

It tells the CPP to define MESSAGE only if MESSAGE isn't already defined.

#ifdef DEBUG
/* Your debugging statements here */
#endif

It tells the CPP to process the statements enclosed if DEBUG is defined. This is useful if We pass
the -DDEBUG flag to the gcc compiler at the time of compilation. This will define DEBUG, so We can
turn debugging on and off on thefly during compilation.
Predefined Macros
ANSI C defines a number of macros. Although each one is available for use in programming, the
predefined macros should not be directly modified.

[Link]. Macro & Description

DATE
1
The current date as a character literal in "MMM DD YYYY" format.

TIME
2
The current time as a character literal in "HH:MM:SS" format.

FILE
3
This contains the current filename as a string literal.

515
LINE
4
This contains the current line number as a decimal constant.

#define message_for(a, b) \
printf(#a " and " #b ": We love you!\n")

5 STDC
Defined as 1 when the compiler complies with the ANSI standard.

try the following example −

#include <stdio.h>

int main() {

printf("File :%s\n", FILE );


printf("Date :%s\n", DATE );
printf("Time :%s\n", TIME );
printf("Line :%d\n", LINE );
printf("ANSI :%d\n", STDC );

When the above code in a file test.c is compiled and executed, it produces thefollowing result −
File :test.c
Date :Jun 2 2012
Time :03:36:24
Line :8
ANSI :1

Preprocessor Operators
The C preprocessor offers the following operators to help create macros −The Macro Continuation

(\) Operator

A macro is normally confined to a single line. The macro continuation operator(\) is used to
continue a macro that is too long for a single line. For example −
516
The Stringize (#) Operator

The stringize or number-sign operator ( '#' ), when used within a macro definition, converts a macro
parameter into a string constant. This operator may be used only in a macro having a specified
argument or parameter list. For example −

#include <stdio.h>

#define message_for(a, b) \
printf(#a " and " #b ": We love you!\n")

int main(void) {
message_for(Carole, Debra);
return 0;
}
When the above code is compiled and executed, it produces the following result
−Carole and Debra: We love you! The Token Pasting (##) Operator
The token-pasting operator (##) within a macro definition combines two arguments. It permits two
separate tokens in the macro definition to be joined into a single token. For example −

#include <stdio.h>

#define tokenpaster(n) printf ("token" #n " = %d", token##n)

int main(void) {
int token34 = 40;
tokenpaster(34);
return 0;
}

When the above code is compiled and executed, it produces the following result
−token34 = 40
It happened so because this example results in the following actual output fromthe preprocessor

printf ("token34 = %d", token34);

This example shows the concatenation of token##n into token34 and here we have used both
stringize and token-pasting.
The Defined() Operator
The preprocessor defined operator is used in constant expressions to determine if an identifier is
defined using #define. If the specified identifier is defined, the value is true (non-zero). If the symbol
517
is not defined, the value is false (zero). The defined operator is specified as follows −

#include <stdio.h>

#if !defined (MESSAGE)


#define MESSAGE "You wish!"
#endif

int main(void) {
printf("Here is the message: %s\n", MESSAGE);
return 0;
}

When the above code is compiled and executed, it produces the following result
−Here is the message: You wish!Parameterized Macros
One of the powerful functions of the CPP is the ability to simulate functions using
parameterized macros. For example, we might have some code to square anumber as follows −

int square(int x) {
return x * x;
}

We can rewrite above the code using a macro as follows −

#Define square(x) ((x) * (x))

Macros with arguments must be defined using the #define directive before they can be used. The
argument list is enclosed in parentheses and must immediately follow the macro name. Spaces
are not allowed between the macro name and open parenthesis. For example −

#include <stdio.h>

#define MAX(x,y) ((x) > (y) ? (x) : (y))

int main(void) {
printf("Max between 20 and 10 is %d\n", MAX(10, 20));
return 0;
}

When the above code is compiled and executed, it produces the following result
−Max between 20 and 10 is 20

Object-oriented programming (OOP)


518
Object-oriented programming (OOP) is a computer programming model thatorganizes software
design around data, or objects, rather than functions andlogic. An object can be defined as a data
field that has unique attributes and behavior.
OOP focuses on the objects that developers want to manipulate rather than thelogic required to
manipulate them. This approach to programming is well-suitedfor programs that are large, complex
and actively updated or maintained.

The organization of an object-oriented program also makes the method beneficialto collaborative
development, where projects are divided into groups.
Additional benefits of OOP include code reusability, scalability and efficiency. Even when using
microservices, developers should continue to apply the principles of OOP.
The first step in OOP is to collect all of the objects a programmer wants to manipulate and identify
how they relate to each other -- an exercise often knownas data modeling.
Examples of an object can range from physical entities, such as a human being who is described
by properties like name and address, down to small computerprograms, such as widgets.
Once an object is known, it is labeled with a class of objects that defines the kindof data it contains
and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method.
Objects can communicate with well- defined interfaces called messages.

Principles of OOP
Object-oriented programming is based on the following principles:

Encapsulation. The implementation and state of each object are privately held inside a defined
boundary, or class. Other objects do not have access to this class or the authority to make changes
but are only able to call a list of public functions, or methods. This characteristic of data hiding
provides greater program security and avoids unintended data corruption.
Hiding the implementation details of the class from the user through an object’s methods is known
as data encapsulation. In object oriented programming, it binds the code and the data together and
keeps them safefrom outside [Link]. Objects only reveal internal mechanisms
that are relevant for theuse of other objects, hiding any unnecessary implementation code. This
concept helps developers more easily make changes and additions over time.

Inheritance. Relationships and subclasses between objects can be assigned, allowing developers
to reuse a common logic while still maintaining a unique hierarchy. This property of OOP forces a
more thorough data analysis, reducesdevelopment time and ensures a higher level of accuracy.
Inheritance as in general terms is the process of acquiring properties. In OOPone object inherit the
properties of another object.

Polymorphism. Objects can take on more than one form depending on the context. The program
will determine which meaning or usage is necessary foreach execution of that object, cutting down
the need to duplicate code.
Polymorphism is the process of using same method name by multiple classes and redefines

519
methods for the derived classes.

Object-oriented programming languages


While Simula is credited as the first object-oriented programming language, themost popular OOP
languages are:
• Java
• JavaScript
• Python
• C++
• Visual Basic .NET
• Ruby
• Scala
• PHP
• OOPSLA is the annual conference for Object-Oriented Programming Systems, Languages
and Applications.

Criticism of OOP
The object-oriented programming model has been criticized by developers for multiple reasons.
The largest concern is that OOP overemphasizes the data component of software development
and does not focus enough on computationor algorithms. Additionally, OOP code may be more
complicated to write and takelonger to compile.

Alternative methods to OOP include:


• functional programming
• structured programming
• imperative programming
Most advanced programming languages give developers the option to combinethese models.
Object Oriented Programming Paradigm (OOPP)
The Object Oriented programming paradigm plays an important role in human computer interface.
It has different components that takes real world objects andperforms actions on them, making live
interactions between man and the machine. Following are the components of OOPP −
• This paradigm describes a real-life system where interactions are among real
objects.
• It models applications as a group of related objects that interact with eachother.
• The programming entity is modeled as a class that signifies the collection of
related real world objects.
• Programming starts with the concept of real world objects and classes.
• Application is divided into numerous packages.
• A package is a collection of classes.A class is an encapsulated group of similar
real world objects.

Objects
520
Real-world objects share two characteristics − They all have state and [Link] the following
pictorial example to understand Objects.

In the above diagram, the object ‘Dog’ has both state and behavior.
An object stores its information in attributes and discloses its behavior through methods. now
discuss in brief the different components of object oriented programming.

Public Interface
The point where the software entities interact with each other either in a singlecomputer or in a
network is known as pubic interface. This help in data [Link] objects can change the state
of an object in an interaction by using only those methods that are exposed to the outer world
through a public interface.

Class
A class is a group of objects that has mutual methods. It can be considered as theblueprint using
which objects are created.
Classes being passive do not communicate with each other but are used toinstantiate objects that
interact with each other.

Example
Object Oriented Modeling of User Interface Design
Object oriented interface unites users with the real-world manipulating softwareobjects for
designing purpose. see the diagram.

521
Interface design strive to make successful accomplishment of user’s goals with the help of
interaction tasks and manipulation.
While creating the OOM for interface design, first of all analysis of user requirements is done. The
design specifies the structure and components required for each dialogue. After that, interfaces are
developed and testedagainst the Use Case. Example − Personal banking application.
The sequence of processes documented for every Use Case are then analyzed forkey objects. This
results into an object model. Key objects are called analysis objects and any diagram showing
relationships between these objects is called object diagram.

C++ Identifiers
C++ identifiers in a program are used to refer to the name of the variables, functions, arrays, or
other user-defined data types created by the programmer. They are the basic requirement of any
language. Every language has its own rulesfor naming the identifiers.
In short, we can say that the C++ identifiers represent the essential elements in aprogram which are
given below:
• Constants
522
• Variables
• Functions
• Labels
• Defined data types
• Some naming rules are common in both C and C++. They are as follows:
• Only alphabetic characters, digits, and underscores are allowed.
• The identifier name cannot start with a digit, i.e., the first letter should be
alphabetical. After the first letter, we can use letters, digits, or underscores.
• In C++, uppercase and lowercase letters are distinct. Therefore, we cansay that
C++ identifiers are case-sensitive.
• A declared keyword cannot be used as a variable name.

For example, suppose we have two identifiers, named as 'FirstName', and 'Firstname'. Both the
identifiers will be different as the letter 'N' in the first case in
uppercase while lowercase in second. Therefore, it proves that identifiers arecase-sensitive.

Valid Identifiers
The following are the examples of valid identifiers are:

Result

Test2

_sum

power

Invalid Identifiers
The following are the examples of invalid identifiers:

Sum-1 // containing special character '-'.

2data // the first letter is a digit.

break // use of a keyword.

Note: Identifiers cannot be used as the keywords. It may not conflict with the keywords, but it is
highly recommended that the keywords should not be used as the identifier name. We should
always use a consistent way to name the identifiers so that our code will be more readable and
maintainable.
The major difference between C and C++ is the limit on the length of the name ofthe variable. ANSI
C considers only the first 32 characters in a name while ANSI C++ imposes no limit on the length
of the name.
523
Constants are the identifiers that refer to the fixed value, which do not change during the execution
of a program. Both C and C++ support various kinds of literalconstants, and they do have any
memory location. For example, 123, 12.34, 037, 0X2, etc. are the literal constants.

A simple example to understand the concept of identifiers.


#include <iostream> using namespace std;int main ()

int a;

int A;

cout<<"Enter the values of 'a' and 'A'";cin>>a;

cin>>A;

cout<<"\nThe values that you have entered are : "<<a<<" , "<<A;

return 0;
}

What are the keywords?


Keywords are the reserved words that have a special meaning to the compiler. They are reserved
for a special purpose, which cannot be used as the [Link] example, 'for', 'break', 'while', 'if',
'else', etc. are the predefined words wherepredefined words are those words whose meaning is
already known by the compiler. Whereas, the identifiers are the names which are defined by the
programmer to the program elements such as variables, functions, arrays,objects, classes

Differences between Identifiers and Keywords

The following is the list of differences between identifiers and keywords:

Identifiers Keywords

Identifiers are the names defined by theprogrammer Keywords are the reserved wordswhose
to the basic elements of a program. meaning is known by the compiler.

524
It is used to identify the name of thevariable. It is used to specify the type ofentity.

It can consist of letters, digits, andunderscore. It contains only letters.

It can use both lowercase and uppercaseletters. It uses only lowercase letters.

No special character can be used exceptthe


It cannot contain any specialcharacter.
underscore.

The starting letter of identifiers can belowercase, It can be started only with thelowercase
uppercase or underscore. letter.

It can be classified as internal and external


It cannot be further classified.
identifiers.

Examples are test, result, sum, power, etc. Examples are 'for', 'if', 'else', 'break',etc.

C++ Variable

A variable is a name of memory location. It is used to store data. Its value can bchanged
and it can be reused many [Link] is a way to represent memory location through symbol
so that it can be easilyidentified.
type variable_list;
The example of declaring variable is given below:
The syntax to declare a variable:

int x;
float y;
char z;
525
Here, x, y, z are variables and int, float, char are data types.

We can also provide values while declaring the variables as given below:
int x=5,b=10; //declaring 2 variable of integer type
float f=30.8;
char c='A';

Rules for defining variables


A variable can have alphabets, digits and underscore.

A variable name can start with alphabet and underscore only. It can't start withdigit.
No white space is allowed within variable name.

A variable name must not be any reserved word or keyword e.g. char, float etc.
Valid variable names:int a;

int _ab;
int a30;

Invalid variable names:int 4;

int x y;
int double; C++ Data Types

A data type specifies the type of data that a variable can store such as integer,floating, character
etc.

There are 4 types of data types in C++ language.


526
Types Data Types

Basic Data Type int, char, float, double, etc

Derived Data Type array, pointer, etc

Enumeration Data Type enum

User Defined Data Type structure

The memory size of basic data types may change according to 32 or 64 bitoperating system.
the basic data types. It size is given according to 32 bit OS.

Data Types Memory Size Range

char 1 byte -128 to 127

signed char 1 byte -128 to 127

unsigned char 1 byte 0 to 127

short 2 byte -32,768 to 32,767

signed short 2 byte -32,768 to 32,767

unsigned short 2 byte 0 to 32,767

int 2 byte -32,768 to 32,767

signed int 2 byte -32,768 to 32,767

unsigned int 2 byte 0 to 32,767

527
short int 2 byte -32,768 to 32,767

signed short int 2 byte -32,768 to 32,767

unsigned short int 2 byte 0 to 32,767

long int 4 byte

signed long int 4 byte

unsigned long int 4 byte

float 4 byte

double 8 byte

long double 10 byte

C++ Operators
An operator is simply a symbol that is used to perform operations. There can bemany types of
operations like arithmetic, logical, bitwise etc.
There are following types of operators to perform different types of operations inC language.
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operator
• Unary operator
• Ternary or Conditional Operator
• Misc Operator

528
Precedence of Operators in C++
The precedence of operator species that which operator will be evaluated firstand next.
The associativity specifies the operators direction to be evaluated, itmay be left to right or
right to left. the precedence by the example given below:

1. int data=5+10*10;
The "data" variable will contain 105 because * (multiplicative operator) isevaluated before
+ (additive operator).

The precedence and associativity of C++ operators is given below:

Category Operator Associativity

Postfix () [] -> . ++ - - Left to right

Unary + - ! ~ ++ - - (type)* & sizeof Right to left

Multiplicative */% Left to right

Additive +- Right to left

529
Shift << >> Left to right

Relational < <= > >= Left to right

Equality == !=/td> Right to left

Bitwise AND & Left to right

Bitwise XOR ^ Left to right

Bitwise OR | Right to left

Logical AND && Left to right

Logical OR || Left to right

Conditional ?: Right to left

Assignment = += -= *= /= %=>>= <<= &= ^= |= Right to left

Comma , Left to right

Decision making in C++ - if, else and else if


Decision making is about deciding the order of execution of statements based oncertain conditions
or repeat a group of statements until certain specified conditions are met. C++ handles decision-
making by supporting the following statements,
• if statement
• switch statement
• conditional operator statement
• goto statement

Decision making with if statement


The if statement may be implemented in different forms depending on thecomplexity of conditions
to be tested. The different forms are,
1. Simple if statement
2. if else statement
3. Nested if else statement
530
4. else if statement

Simple if statement
The general form of a simple if statement is,

if(expression)

statement-inside;

statement-outside;

If the expression is true, then 'statement-inside' will be executed, otherwise'statement-inside' is


skipped and only 'statement-outside' will be executed.

Example: #include< iostream.h>int main( )

int x,y;x=15; y=13;

if (x > y )

cout << "x is greater than y";

} statement-block1;

else

statement-block2;

}
531
else

statement-block3.

Output: x is greater than y y is greater than x Nested if else statement The general form
of a nested if else statement is if(expression)

{if(expression1)
{
if 'expression' is false or returns false, then the 'statement-block3' will beexecuted,
otherwise execution will enter the if condition and check for 'expression 1'. Then if the
'expression 1' is true or returns true, then the 'statement-block1' will be executed
otherwise 'statement-block2' will be executed.
Example: void main()

int a,b,c;
cout << "enter 3 number";cin >> a >> b >> c; if(a > b)

if( a > c) {

cout << "a is greatest";

else

cout << "c is greatest";

else

{
532
if( b> c)

cout << "b is greatest";

else
{

cout << "c is greatest";

}}

The above code will print different statements based on the valuesof a, b and c variables
if(expression 1)

{
statement-block1;

}
else if(expression 2)

{
statement-block2;

}
else if(expression 3 )
{

statement-block3;
}

else
default-statement;
The expression is tested from the top(of the ladder) downwards. As soon as thetrue condition is
found, the statement associated with it is executed.

Example:

void main( )
int a;
533
cout << "enter a number";cin >> a;

if( a%5==0 && a%8==0)

cout << "divisible by both 5 and 8";

else if( a%8==0 )

cout << "divisible by 8";

else if(a%5==0)

cout << "divisible by 5";

{
else

cout << "divisible by none";

If We enter value 40 for the variable a, then the output will be:

534
Output

divisible by both 5 and 8

Points to Remember

In if statement, a single statement can be included without enclosing it into


curly braces { }.

int a = 5;

if(a > 4)

cout << "success";

Output
success

No curly braces are required in the above case, but if we have more than one
statement inside if condition, then we must enclose them inside curly braces
otherwise only the first statement after the if condition will be considered.

int a = 2;

if(a > 4)

cout << "success";

// below statement is outside the if condition

cout << "Not inside the if condition"

Output

Not inside the if condition

535
Output

hello

C++ Functions
The function in C++ language is also known as procedure or subroutine in other programming
languages.
To perform any task, we can create function. A function can be called many times. It provides
modularity and code reusability.

Advantage of functions in C
There are many advantages of functions.

1) Code Reusability
By creating functions in C++, we can call it many times. So we don't need to writethe same code
again and again.

2) Code optimization
It makes the code optimized, we don't need to write much code.
Suppose, we have to check 3 numbers (531, 883 and 781) whether it is prime number or not.
Without using function, we need to write the prime number logic3 times. So, there is repetition of
code.
But if we use functions, we need to write the logic only once and we can reuse itseveral times.

Types of Functions
There are two types of functions in C programming:

1. Library Functions: are the functions which are declared in the C++ header filessuch as ceil(x),
cos(x), exp(x), etc.
2. User-defined functions: are the functions which are created by the C++ programmer, so that
he/she can use it many times. It reduces complexity of a bigprogram and optimizes the code.

536
Declaration of a function
The syntax of creating function in C++ language is given below:

return_type function_name(data_type parameter...)

//code to be executed

C++ Function Example


the simple example of C++ function.

Output: #include <iostream> using namespace std;void func() {

static int i=0; //static variable

int j=0; //local variablei++;

j++;

cout<<"i=" << i<<" and j=" <<j<<endl;

int main()

func();

func();

func();

i= 1 and j= 1

i= 2 and j= 1

537
i= 3 and j= 1

Call by value and call by reference in C++


There are two ways to pass value or data to function in C language: call by value and call by
reference. Original value is not modified in call by value but it is modified in call by reference.

Understand call by value and call by reference in C++ language one by one.

Call by value in C++


In call by value, original value is not modified.
In call by value, value being passed to the function is locally stored by the functionparameter in
stack memory location. If We change the value of function parameter, it is changed for the current
function only. It will not change the valueof variable inside the caller method such as main().

The concept of call by value in C++ language by the example given below:
#include <iostream> using namespace std;void change(int data);int main()

int data = 3; change(data);

cout << "Value of the data is: " << data<< endl;

return 0;

538
void change(int data)

Output:

Value of the data is: 3

Call by reference in C++

In call by reference, original value is modified because we pass reference

data = 5;

(address).

Here, address of the value is passed in the function, so actual and formal arguments share the
same address space. Hence, value changed inside thefunction, is reflected inside as well as outside
the function.
Note: To understand the call by reference, We must have the basic knowledge ofpointers.
the concept of call by reference in C++ language by the example given below:
539
#include<iostream> using namespace std; void swap(int *x, int *y)

int swap;swap=*x;

*x=*y;

*y=swap;

int main()

int x=500, y=100;

swap(&x, &y); // passing value to functioncout<<"Value of x is: "<<x<<endl; cout<<"Value

of y is: "<<y<<endl;

return 0;

Output:

Value of x is: 100

Value of y is: 500

Difference between call by value and call by reference in C++

No. Call by value Call by reference

An address of value is passed tothe


1 A copy of value is passed to thefunction
function

540
Changes made inside the function isnot Changes made inside the functionis
2
reflected on other functions reflected outside the function also

Actual and formal arguments will becreated Actual and formal arguments willbe created
3
in different memory location in same memory location

C++ virtual function


• A C++ virtual function is a member function in the base class that Weredefine
in a derived class. It is declared using the virtual keyword.
• It is used to tell the compiler to perform dynamic linkage or late bindingon the
function.
• There is a necessity to use the single pointer to refer to all the objects ofthe
different classes. So, we create the pointer to the base class that refers to all the derived objects.
But, when base class pointer contains the address of the derived class object, always executes the
base class function. This issue can only be resolved by using the 'virtual' function.
• A 'virtual' is a keyword preceding the normal declaration of a function.
• When the function is made virtual, C++ determines which function is to be
invoked at the runtime based on the type of the object pointed by the base class pointer.

Late binding or Dynamic linkage


In late binding function call is resolved during runtime. Therefore compilerdetermines the type of
object at runtime, and then binds the function call.

Rules of Virtual Function


• Virtual functions must be members of some class.
• Virtual functions cannot be static members.
• They are accessed through object pointers.
• They can be a friend of another class.
• A virtual function must be defined in the base class, even though it is notused.
• The prototypes of a virtual function of the base class and all the derivedclasses
must be identical. If the two functions with the same name but different prototypes, C++ will
consider them as the overloaded functions.
• We cannot have a virtual constructor, but we can have a virtualdestructor
• Consider the situation when we don't use the virtual keyword.
#include <iostream> using namespace std;class A

541
{

int x=5;
public:
void display()

std::cout << "Value of x is : " << x<<std::endl;

};

class B: public A

int y = 10;

public:

void display()

std::cout << "Value of y is : " <<y<< std::endl;

};

int main()

A *a;

B b;

a = &b;

a- >display();

return 0;

542
Output:
Value of x is: 5

Derived Class is invoked

Output: void display()

cout << "Derived Class is invoked"<<endl;

};

int main()

A* a; //pointer of base class B b; //object of derived classa = &b;

a->display(); //Late Binding occurs

}
Pure Virtual Function

• A virtual function is not used for performing any task. It only serves as a
placeholder.
• When the function has no definition, such function is known as "do-nothing"
function.
• The "do-nothing" function is known as a pure virtual function. A purevirtual
function is a function declared in the base class that has no definition relative to the base class.
• A class containing the pure virtual function cannot be used to declare the
objects of its own, such classes are known as abstract base classes.

• The main objective of the base class is to provide the traits to the derived
classes and to create the base pointer used for achieving theruntime polymorphism.

Pure virtual function can be defined as:

1. virtual void display() = 0;

543
A simple example:

Output:
{

Base *bptr;

//Base b;

Derived d;

bptr = &d;

bptr->show();

eturn 0;

}
Derived class is derived from the base class.
In the above example, the base class contains the pure virtual function. Therefore,the base class is
an abstract base class. We cannot create the object of the base class.

C++ Inheritance
In C++, inheritance is a process in which one object acquires all the properties andbehaviors of its
parent object automatically. In such way, we can reuse, extend or modify the attributes and
behaviors which are defined in other class.
In C++, the class which inherits the members of another class is called derived class and the class
whose members are inherited is called base class. The derivedclass is the specialized class for the
base class.
Advantage of C++ Inheritance

Code reusability: Now we can reuse the members of our parent class. So, there isno need to define
the member again. So less code is required in the class.

Types Of Inheritance
C++ supports five types of inheritance:

➢ Single inheritance
➢ Multiple inheritance
➢ Hierarchical inheritance
➢ Multilevel inheritance
➢ Hybrid inheritance

544
Derived Classes
A Derived class is defined as the class derived from the base class.

The Syntax of Derived class:

class derived_class_name :: visibility-mode base_class_name


{

// body of the derived class.


}

Where,

derived_class_name: It is the name of the derived class.

visibility mode: The visibility mode specifies whether the features of the baseclass are publicly
inherited or privately inherited. It can be public or private.
base_class_name: It is the name of the base class.

o When the base class is privately inherited by the derived class, public members of
the base class becomes the private members of the derived class. Therefore, the public members
of the base class are not accessible by the objects of the derived class only by the member
functions of the derived class.

o When the base class is publicly inherited by the derived class, public members of
the base class also become the public members of the derived class. Therefore, the public
members of the base class are accessible by theobjects of the derived class as well as by the
member functions of the baseclass.
Note:
545
o In C++, the default mode of visibility is private.
o The private members of the base class are never inherited.

C++ Single Inheritance


Single inheritance is defined as the inheritance in which a derived class isinherited from the only
one base class.

Where 'A' is the base class, and 'B' is the derived class.

C++ Single Level Inheritance Example: Inheriting Fields


When one class inherits another class, it is known as single level inheritance. theexample of single
level inheritance which inherits the fields only.
#include <iostream> using namespace std;class Account {

public:

float salary = 60000;

};

class Programmer: public Account {

public:

float bonus = 5000;

};

int main(void) { Programmer p1;

cout<<"Salary: "<<[Link]<<endl;cout<<"Bonus: "<<[Link]<<endl;return 0;

Output:
Salary: 60000

Bonus: 5000

In the above example, Employee is the base class and Programmer isthe derived class.
#include <iostream> using namespace std;class Animal {

public:

546
void eat() { cout<<"Eating..."<<endl;

};

class Dog: public Animal

public:

void bark(){ cout<<"Barking...";

}; C++ Single Level Inheritance Example: Inheriting Methods :another example of


inheritance in C methods only.
int main(void) {Dog d1; [Link]();

[Link]();

return 0;

}
Output: Eating...

Barking...

• Public: When the member is declared as public, it is accessible to all the


functions of the program.
• Private: When the member is declared as private, it is accessible withinthe class only.
• Protected: When the member is declared as protected, it is accessiblewithin
its own class as well as the class immediately derived from it.

Visibility of Inherited Members:

How to make a Private Member Inheritable


The private member is not inheritable. If we modify the visibility mode by makingit public,
but this takes away the advantage of data hiding.
547
C++ introduces a third visibility modifier, i.e., protected. The member which is declared as
protected will be accessible to all the member functions within theclass as well as the class
immediately derived from it.
Visibility modes can be classified into three categories:

Base class visibility Derived class visibility

Public Private Protected

Private Not Inherited Not Inherited Not Inherited

Protected Protected Private Protected

Public Public Private Protected

C++ Multilevel Inheritance


Multilevel inheritance is a process of deriving a class from another derived class.

public:

void bark(){

548
cout<<"Barking..."<<endl;

#include <iostream>

using namespace std;

class Animal {

public:

void eat() {

cout<<"Eating..."<<endl;

};

class Dog: public Animal

C++ Multi Level Inheritance Example


When one class inherits another class which is further inherited by another class,it is
known as multi level inheritance in C++. Inheritance is transitive so the last derived class
acquires all the members of all its base classes.
the example of multi level inheritance in C++.

};

class BabyDog: public Dog


{

public:
void weep() {
cout<<"Weeping...";
}

549
};

int main(void) {
BabyDog d1;
[Link]();
[Link]();
[Link]();
return 0;
}
Output:

Eating...

Barking...

Weeping...

C++ Multiple Inheritance

Multiple inheritance is the process of deriving a new class that inherits theattributes from two or
more classes.

Syntax of the Derived class:


class D : visibility B-1, visibility B-2, ?

{
// Body of the class;

Ambiguity Resolution in Inheritance


Ambiguity can be occurred in using the multiple inheritance when a function withthe same name
occurs in more than one base class.
The above issue can be resolved by using the class resolution operatorwith the function. In the
above example, the derived class code can berewritten as:

class C : public A, public B

550
void view()
An ambiguity can also occur in single inheritance.

Consider the following situation:


class A

public:

void display()

cout<<?Class A?;

};

class B

{
public: void display()

{
cout<<?Class B?;
}

};

551
{

// body of class B.

class C : public A

// body of class C.

class D : public A

// body of class D.

C++ Hierarchical Inheritance

Hierarchical inheritance is defined as the process of deriving more than one classfrom a
base class.

552
In the above case, the function of the derived class overrides the method of the
base class. Therefore, call to the display() function will simply call the function
defined in the derived class. If we want to invoke the base class function, we canuse the
class resolution operator.
int main()

{
B b; [Link]();// Calling the display() function of B class. b.B :: display();// Calling the
display() function defined in B class.
// Calling the display() function defined in B class.

Object is a runtime entity; it is created at runtime.


Object is an instance of a class. All the members of the class can be accessedthrough object.

An example to create object of student class using s1 as the reference variable.

Student s1; //creating an object of Student

In this example, Student is the type and s1 is the reference variable that refers tothe instance of
Student class.

C++ Class

In C++, object is a group of similar objects. It is a template from which objects arecreated. It
can have fields, methods, constructors [Link] example of C++ class that has three fields
only.

There can be two types of constructors in C++.


• Default constructor
• Parameterized constructor

C++ Default Constructor


A constructor which has no argument is known as default constructor. It isinvoked at the time of
creating object.
553
the simple example of C++ default Constructor.
#include <iostream> using namespace std;class Employee

public:

Employee()

cout<<"Default Constructor Invoked"<<endl;

};

int main(void)

Employee e1; //creating an object of EmployeeEmployee e2;

return 0;

Output:

Default Constructor Invoked

Default Constructor Invoked

C++ Parameterized Constructor


A constructor which has parameters is called parameterized constructor. It is used to provide
different values to distinct objects.

C++ Destructor
A destructor works opposite to constructor; it destructs the objects of classes. It can be
defined only once in a class. Like constructors, it is invoked automatically.A destructor is
defined like constructor. It must have same name as class. But it iprefixed with a tilde sign
(~).
Note: C++ destructor cannot have parameters. Moreover, modifiers can't beapplied on

554
destructors.

C++ Constructor and Destructor Example


An example of constructor and destructor in C++ which is called automatically#include

<iostream> using namespace std;class Employee

{
public:

Employee()

cout<<"Constructor Invoked"<<endl;

555
~Employee()

cout<<"Destructor Invoked"<<endl;

};

int main(void)

Employee e1; //creating an object of Employee

Employee e2; //creating an object of Employee

return 0;

Output:

Constructor Invoked

Constructor Invoked

Destructor Invoked

Destructor Invoked

C++ Overloading (Operator and Function)

C++ allows us to specify more than one definition for a function name or
an operator in the same scope, which is called function overloading and operator overloading
respectively.
An overloaded declaration is a declaration that is declared with the same name asa previously
declared declaration in the same scope, except that both declarations have different arguments
and obviously different definition(implementation).
When we call an overloaded function or operator, the compiler determines the most appropriate
definition to use, by comparing the argument types We have used to call the function or operator
with the parameter types specified in the definitions. The process of selecting the most appropriate
overloaded function oroperator is called overload resolution.
Function Overloading in C++

556
we can have multiple definitions for the same function name in the same scope. The definition of
the function must differ from each other by the types and/or the number of arguments in the
argument list. We cannot overload function declarations that differ only by return type.
Following is the example where same function print() is being used to printdifferent data types −

#include <iostream>

using namespace std;

class printData {

public:

void print(int i) {

cout << "Printing int: " << i << endl;

void print(double f) {

cout << "Printing float: " << f << endl;

void print(char* c) {

cout << "Printing character: " << c << endl;

};

int main(void) {printData pd;

// Call print to print [Link](5);

// Call print to print [Link](500.263);

// Call print to print [Link]("Hello C++");

return 0;

}
557
When the above code is compiled and executed, it produces the following result −Printing int: 5
Printing float: 500.263 Printing character: Hello C++ Operators Overloading in C++ We can redefine
or overload most of the built-in operators available in C++. Thus,a programmer can use operators
with user-defined types as well.
Overloaded operators are functions with special names: the keyword "operator" followed by the
symbol for the operator being defined. Like any other function, an overloaded operator has a return
type and a parameter list.

Box operator+(const Box&);


declares the addition operator that can be used to add two Box objects and returns final Box object.
Most overloaded operators may be defined as ordinarynon-member functions or as class member
functions. In case we define above function as non-member function of a class then we would have
to pass two arguments for each operand as follows −
Box operator+(const Box&, const Box&);

Following is the list of operators which can be overloaded −

+ - * / % ^

& | ~ ! , =

< > <= >= ++ --

<< >> == != && ||

+= -= /= %= ^= &=

|= *= <<= >>= [] ()

-> ->* new new [] delete delete []

Following is the list of operators, which can not be overloaded −

:: .* . ?:

Operator Overloading Examples


Here are various operator overloading examples to help us in understanding theconcept.

558
[Link] Operators & Example

1 Unary Operators Overloading

2 Binary Operators Overloading

3 Relational Operators Overloading

4 Input/Output Operators Overloading

5 ++ and -- Operators Overloading

6 Assignment Operators Overloading

7 Function call () Operator Overloading

8 Subscripting [] Operator Overloading

9 Class Member Access Operator -> Overloading

Templates in C++
A template is a simple and yet very powerful tool in C++. The simple idea is to pass data type as a
parameter so that we don’t need to write the same code fordifferent data types. For example, a
software company may need sort () for different data types. Rather than writing and maintaining
the multiple codes, wecan write one sort () and pass data type as a parameter.
C++ adds two new keywords to support templates: ‘template’ and ‘typename’.The second keyword
can always be replaced by keyword ‘class’.

How templates work?


Templates are expanded at compiler time. This is like macros. The difference is, compiler does
type checking before template expansion. The idea is simple, source code contains only
function/class, but compiled code may contain multiplecopies of same function/class.

559
Function Templates We write a generic function that can be used for different data types. Examples
of function templates are sort(), max(), min(), printArray().
#include <iostream> using namespace std;

// One function works for all data types. This would work

// even for user defined types if operator '>' is overloadedtemplate <typename T>

T myMax(T x, T y)

return (x > y)? x: y;

int main()

{
cout << myMax<int>(3, 7) << endl; // Call myMax for int

cout << myMax<double>(3.0, 7.0) << endl; // call myMax for doublecout <<

myMax<char>('g', 'e') << endl; // call myMax for char return 0;

}
Class Templates Like function templates, class templates are useful when a class defines
something that is independent of the data type. Can be useful for classes like LinkedList,
BinaryTree, Stack, Queue, Array, etc.

560
C++ Exception Handling
An exception is a problem that arises during the execution of a program. A C++ exception is a
response to an exceptional circumstance that arises while a program is running, such as an attempt
to divide by zero.
Exceptions provide a way to transfer control from one part of a program toanother. C++ exception
handling is built upon three keywords: try,
catch, and throw.
➢ throw − A program throws an exception when a problem shows up. Thisis done using a throw
keyword.
➢ catch − A program catches an exception with an exception handler atthe place in a program
where We want to handle the problem.
The catch keyword indicates the catching of an exception.
➢ try − A try block identifies a block of code for which particular exceptions will be activated. It's
followed by one or more catch blocks.
Assuming a block will raise an exception, a method catches an exception using a combination of
the try and catch keywords. A try/catch block is placed around thecode that might generate an
exception. Code within a try/catch block is referred to as protected code, and the syntax for using
try/catch as follows −
try {

// protected code

} catch( ExceptionName e1 ) {

// catch block

} catch( ExceptionName e2 ) {

// catch block

} catch( ExceptionName eN ) {

// catch block

We can list down multiple catch statements to catch different type of exceptionsin case our try
block raises more than one exception in different situations.

Throwing Exceptions
Exceptions can be thrown anywhere within a code block using throw statement. The operand of
the throw statement determines a type for the exception and canbe any expression and the type of
the result of the expression determines the type of exception thrown.
561
Following is an example of throwing an exception when dividing by zero conditionoccurs −
double division(int a, int b) {if( b == 0 ) {

throw "Division by zero condition!";

return (a/b);
}

Catching Exceptions
The catch block following the try block catches any exception. We can specify what type of
exception We want to catch and this is determined by the exceptiondeclaration that appears in
parentheses following the keyword catch.

try {

// protected code

} catch( ExceptionName e ) {

// code to handle ExceptionName exception

Above code will catch an exception of Exception Name type. If We want to specifythat a catch block
should handle any type of exception that is thrown in a try block, We must put an ellipsis, ..., between
the parentheses enclosing the
exception declaration as follows –
try {

// protected code

} catch(...) {

// code to handle any exception

C++ Standard Exceptions


C++ provides a list of standard exceptions defined in <exception> which we canuse in our
programs. These are arranged in a parent-child class hierarchy shownbelow –

562
Here is the small description of each exception mentioned in the above hierarchy

[Link] Exception & Description

563
std::exception
1
An exception and parent class of all the standard C++ exceptions.

std::bad_alloc
2
This can be thrown by new.

std::bad_cast
3
This can be thrown by dynamic_cast.

std::bad_exception
4
This is useful device to handle unexpected exceptions in a C++ program.

std::bad_typeid
5
This can be thrown by typeid.

std::logic_error
6
An exception that theoretically can be detected by reading the code.

std::domain_error
7
This is an exception thrown when a mathematically invalid domain is used.

std::invalid_argument
8
This is thrown due to invalid arguments.

std::length_error
9
This is thrown when a too big std::string is created.

std::out_of_range
10 This can be thrown by the 'at' method, for example a std::vector and
std::bitset<>::operator[]().

564
std::runtime_error
11
An exception that theoretically cannot be detected by reading the code.

std::overflow_error
12
This is thrown if a mathematical overflow occurs.

std::range_error
13
This is occurred when We try to store a value which is out of range.

std::underflow_error
14
This is thrown if a mathematical underflow occurs.

C++ Files and Streams


another standard C++ library called fstream, which defines three new data types –

[Link] Data Type & Description

ofstream
1 This data type represents the output file stream and is used to create filesand to write
information to files.

ifstream
2
This data type represents the input file stream and is used to readinformation from files.

565
fstream

3 This data type represents the file stream generally, and has the capabilitiesof both
ofstream and ifstream which means it can create files, write information to files, and
read information from files.

To perform file processing in C++, header files <iostream> and <fstream> must beincluded in our
C++ source file.

Opening a File
A file must be opened before We can read from it or write to it.
Either ofstream or fstream object may be used to open a file for writing. Andifstream object is used
to open a file for reading purpose only.
Following is the standard syntax for open() function, which is a member offstream, ifstream, and
ofstream [Link] open(const char *filename, ios::openmode mode);
Here, the first argument specifies the name and location of the file to be openedand the second
argument of the open() member function defines the mode in which the file should be opened.

[Link] Mode Flag & Description

ios::app
1
Append mode. All output to that file to be appended to the end.

ios::ate
2
Open a file for output and move the read/write control to the end of thefile.

ios::in
3
Open a file for reading.

ios::out
4
Open a file for writing.

566
ios::trunc
5
If the file already exists, its contents will be truncated before opening thefile.

we can combine two or more of these values by ORing them together. For example if We want to
open a file in write mode and want to truncate it in casethat already exists, following will be the
syntax −
ofstream outfile;
[Link]("[Link]", ios::out | ios::trunc ); Similar way, We can open a file for reading and writing
purpose as follows −fstream afile;
[Link]("[Link]", ios::out | ios::in );

Closing a File
When a C++ program terminates it automatically flushes all the streams, releaseall the allocated
memory and close all the opened files. But it is always a good practice that a programmer should
close all the opened files before program termination.
Following is the standard syntax for close() function, which is a member offstream, ifstream, and
ofstream objects.
void close();

Writing to a File
While doing C++ programming, We write information to a file from our programusing the stream
insertion operator (<<) just as We use that operator to output information to the screen. The only
difference is that We usean ofstream or fstream object instead of the cout object.

Reading from a File


We read information from a file into our program using the stream extractionoperator (>>) just as
We use that operator to input information from the keyboard. The only difference is that We use an
ifstream or fstream object instead of the cin object.

File Position Pointers


Both istream and ostream provide member functions for repositioning the file-position pointer.
These member functions are seekg ("seek get") for istream and seekp ("seek put") for ostream.
The argument to seekg and seekp normally is a long integer. A second argumentcan be specified
to indicate the seek direction. The seek direction can
be ios::beg (the default) for positioning relative to the beginning of a stream, ios::cur for positioning
relative to the current position in a streamor ios::end for positioning relative to the end of a stream.
The file-position pointer is an integer value that specifies the location in the file asa number of bytes
from the file's starting location. Some examples of positioning the "get" file-position pointer are −
// position to the nth byte of fileObject (assumes ios::beg)[Link]( n );

567
// position n bytes forward in fileObject

[Link]( n, ios::cur );

// position n bytes back from end of [Link]( n, ios::end );

// position at end of [Link]( 0, ios::end ); C++ Exceptions

C++ Exceptions
When executing C++ code, different errors can occur: coding errors made by theprogrammer, errors
due to wrong input, or other unforeseeable things.
When an error occurs, C++ will normally stop and generate an error message. Thetechnical term for
this is: C++ will throw an exception (throw an error).

C++ try and catch


Exception handling in C++ consist of three keywords: try, throw and catch:
The try statement allows We to define a block of code to be tested for errors while it is being
executed.
The throw keyword throws an exception when a problem is detected, which letsus create a custom
error.
The catch statement allows We to define a block of code to be executed, if anerror occurs in the try
block.
The try and catch keywords come in pairs:

Example
try {
// Block of code to try
throw exception; // Throw an exception when a problem arise
}
catch () {
// Block of code to handle errors
}

Web Programming
Web programming refers to the writing, markup and coding involved in Web development, which
includes Web content, Web client and server scripting and network security. The most common
languages used for Web programming are XML, HTML, JavaScript, Perl 5 and PHP. Web
programming is different from just programming, which requires interdisciplinary knowledge on the
application area,client and server scripting, and database technology.
Web programming can be briefly categorized into client and server coding. The client side needs
programming related to accessing data from users and providing information. It also needs to
ensure there are enough plug ins to enrich user experience in a graphic user interface, including
security measures.

568
1. To improve user experience and related functionalities on the client side, JavaScript is
usually used. It is an excellent client-side platform for designing and implementing Web
applications.
2. HTML5 and CSS3 supports most of the client-side functionality provided byother application
frameworks.
3. The server side needs programming mostly related to data retrieval, security and
performance. Some of the tools used here include ASP, Lotus Notes, PHP, Java and MySQL.
There are certain tools/platforms that aid in both client- and server-side programming. Some
examples of these are Opa and Tersus.

Hypertext Markup Language (HTML)


Hypertext markup language (HTML) is the major markup language used to displayWeb pages on
the Internet. In other words, Web pages are composed of HTML, which is used to display text,
images or other resources through a Web browser.
All HTML is plain text, meaning it is not compiled and may be read by [Link] file extension for
an HTML file is .htm or .html.
New Web developers may mistake HTML for a programming language when it is actually a markup
language. HTML is used with other technologies because all HTML really does is organize
documents. On the client side, JavaScript (JS) is usedto provide interactivity. On the server side, a
Web development platform like Ruby, PHP or [Link] is used.
When a Web developer builds an application, the work is performed on the server, and raw HTML
is sent out to the user. The line between server-side development and client side development is
blurry with technologies like AJAX.
HTML was never designed for the Web that exists today, as it is just a markuplanguage with severe
limitations, in terms of control and design. Numerous technologies have been used to work around
this issue - the most significant being cascading style sheet (CSS).
The long term solution is (or hopefully will be) HTML5, which is the next generation of HTML and
allows for more control and interactivity. As with any development on the Web, the move to
standards is a slow and arduous process, and Web developers and designers have to make due
with current and supportedtechnologies, which means that basic HTML will continue to be used for
some time.

Applications of HTML
As mentioned before, HTML is one of the most widely used language over theweb. I'm going to list
few of them here:

1. Web pages development - HTML is used to create pages which are rendered over the web.
Almost every page of web is having html tags in itto render its details in browser.
2. Internet Navigation - HTML provides tags which are used to navigate from one page to
another and is heavily used in internet navigation.
3. Responsive UI - HTML pages now-a-days works well on all platform, mobile,tabs, desktop or
laptops owing to responsive design strategy.
4. Offline support HTML pages once loaded can be made available offline on the machine
569
without any need of internet.
5. Game development- HTML5 has native support for rich experience and is now useful in
gaming developent arena as well.

• Basic HTML Document


In its simplest form, following is an example of an HTML document −

<!DOCTYPE html>

<html>

<head>

<title>This is document title</title>

</head>

<body>

<h1>This is a heading</h1>

<p>Document content goes here. ... </p>

</body>

</html>

HTML Tags
As told earlier, HTML is a markup language and makes use of various tags to format the content.
These tags are enclosed within angle braces <Tag Name>.Except few tags, most of the tags have
their corresponding closing tags. For example, <html> has its closing tag </html> and <body> tag
has its closing tag </body> tag etc.
Above example of HTML document uses the following tags − 1

[Link] Tag & Description

<!DOCTYPE...>
1
This tag defines the document type and HTML version.

570
<html>

2 This tag encloses the complete HTML document and mainly comprises ofdocument
header which is represented by <head>...</head> and document body which is
represented by <body>...</body> tags.

<head>
3 This tag represents the document's header which can keep other HTMLtags like <title>,
<link> etc.

<title>
4
The <title> tag is used inside the <head> tag to mention the documenttitle.

<body>
5
This tag represents the document's body which keeps other HTML tags

like <h1>, <div>, <p> etc.

<h1>
6
This tag represents the heading.

<p>
7
This tag represents a paragraph.

To learn HTML, we will need to study various tags and understand how they behave, while
formatting a textual document. Learning HTML is simple as users have to learn the usage of
different tags in order to format the text or images tomake a beautiful webpage.
World Wide Web Consortium (W3C) recommends using lowercase tags startingfrom HTML 4.

HTML Document Structure


A typical HTML document will have the following structure −

571
<html>

<head>

Document header related tags

</head>

<body>

Document body related tags

</body>

</html>

The <!DOCTYPE> Declaration


The <!DOCTYPE> declaration tag is used by the web browser to understand theversion of the HTML
used in the document. Current version of HTML is 5 and itmakes use of the following declaration

<!DOCTYPE html>
There are many other declaration types which can be used in HTML documentdepending on what
version of HTML is being used.
Extensible Markup Language (XML)
Extensible Markup Language (XML) is a universal format, maintained by the W3C, used for
representation and transfer of structured data on the web or between different applications.
The language uses a structured representation by allowing users to create customdefined tags
according to XML Document Type Definition (DTD) standards. The structure of an XML document
can be represented in the form of a tree known asa Document Object Model (DOM).
XML is designed to describe data but is not concerned with the data’s visualization. The tags
created in XML are self explanatory and the user is free to define their own tags — hence the
“extensible.”
XML support is provided by many programming language platforms to create andprocess XML
data. Simplicity, portability, platform independence, and usability are some of the key features that
have resulted in the increasing popularity of theuse of XML-based standards.
XML has been the main source of motivation for development of service orientedarchitecture (SOA)
platforms such as web services that are not tied to any particular language and collaborate
effectively in heterogeneous environments. RSS, Atom, SOAP and XHTML are some of the
standards influenced by XML.

572
JavaScript (JS)

Javascript (JS) is a scripting languages, primarily used on the Web. It is used to enhance HTML
pages and is commonly found embedded in HTML code. JavaScriptis an interpreted language.
Thus, it doesn't need to be compiled. JavaScript renders web pages in an interactive and dynamic
fashion. This allowing the pages to react to events, exhibit special effects, accept variable text,
validate data,
create cookies, detect a user’s browser, etc.

HTML pages are fine for displaying static content, e.g. a simple image or [Link], most pages
nowadays are rarely static. Many of today’s pages havemenus, forms, slideshows and even images
that provide user interaction.
Javascript is the language employed by web developers to provide such interaction. Since
JavaScript works with HTML pages, a developer needs to know HTML to harness this scripting
language’s full potential. While there are other languages that can be used for scripting on the Web,
in practice it is essentially allJavascript.
There are two ways to use JavaScript in an HTML file. The first one involves embedding all the
JavaScript code in the HTML code, while the second method makes use of a separate JavaScript
file that’s called from within a Script element, i.e., enclosed by Script tags. JavaScript files are
identified by the .js extension.
Although JavaScript is mostly used to interact with HTML objects, it can also be made to interact
with other non-HTML objects such as browser plugins, CSS (Cascading Style Sheets) properties,
the current date, or the browser itself. To write JavaScript code, all We need is a basic text editor
like Notepad in Windows, Gimp in Linux, or BBEdit. Some text editors, like BBEdit feature syntax
highlightingfor JavaScript. This will allow We easily identify elements of JavaScript code. The latest
versions of Internet Explorer, Firefox, and Opera all support JavaScript.
Java
Java is a programming language that produces software for multiple platforms. When a
programmer writes a Java application, the compiled code (known as

bytecode) runs on most operating systems (OS), including Windows, Linux and Mac OS. Java
derives much of its syntax from the C and C++ programming languages.

Java was developed in the mid-1990s by James A. Gosling, a former computerscientist with Sun
Microsystems.
Java produces applets (browser-run programs), which facilitate graphical user interface (GUI) and
object interaction by Internet users. Prior to Java applets, Webpages were typically static and non-
interactive. Java applets have diminished in popularity with the release of competing products,
such as Adobe Flash and Microsoft Silverlight.

Java applets run in a Web browser with Java Virtual Machine (JVM), which translates Java

573
bytecode into native processor instructions and allows indirect OS or platform program execution.
JVM provides the majority of components neededto run bytecode, which is usually smaller than
executable programs written through other programming languages. Bytecode cannot run if a
system lacks required JVM.

Java program development requires a Java software development kit (SDK) thattypically includes
a compiler, interpreter, documentation generator and other tools used to produce a complete
application.

Development time may be accelerated through the use of integrated development environments
(IDE) - such as JBuilder, Netbeans, Eclipse or [Link] facilitate the development of GUIs,
which include buttons, text boxes, panels, frames, scrollbars and other objects via drag-and-drop
and point-and-clickactions.

Java programs are found in desktops, servers, mobile devices, smart cards andBlu-ray Discs (BD).

Java is −
➢ Object Oriented − In Java, everything is an Object. Java can be easilyextended since it is
based on the Object model.
➢ Platform Independent − Unlike many other programming languages including C and C++,
when Java is compiled, it is not compiled into platform specific machine, rather into platform
independent byte code. This byte code is distributed over the web and interpreted by the
VirtualMachine (JVM) on whichever platform it is being run on.
➢ Simple − Java is designed to be easy to learn. If We understand the basicconcept of OOP
Java, it would be easy to master.
➢ Secure − With Java's secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-keyencryption.
➢ Architecture-neutral − Java compiler generates an architecture-neutralobject file format,
which makes the compiled code executable on manyprocessors, with the presence of Java
runtime system.
➢ Portable − Being architecture-neutral and having no implementation dependent aspects of
the specification makes Java portable. Compiler inJava is written in ANSI C with a clean
portability boundary, which is a POSIX subset.
➢ Robust − Java makes an effort to eliminate error prone situations byemphasizing mainly on
compile time error checking and runtime checking.
➢ Multithreaded − With Java's multithreaded feature it is possible to writeprograms that can
perform many tasks simultaneously. This design feature allows the developers to construct
interactive applications that can run smoothly.
➢ Interpreted − Java byte code is translated on the fly to native machineinstructions and is not
stored anywhere. The development process is more rapid and analytical since the linking is
an incremental and light-weight process.

574
➢ High Performance − With the use of Just-In-Time compilers, Javaenables high performance.
➢ Distributed − Java is designed for the distributed environment of theinternet.
➢ Dynamic − Java is considered to be more dynamic than C or C++ since itis designed to adapt
to an evolving environment. Java programs can carry extensive amount of run-time
information that can be used to verify and resolve accesses to objects on run-time.
Dynamic HyperText Markup Language (DHTML)
Dynamic HyerText Markup Language (DHTML) is a combination of Web development technologies
used to create dynamically changing websites. Web pages may include animation, dynamic menus
and text effects. The technologiesused include a combination of HTML, JavaScript or VB Script,
CSS and the document object model (DOM).

Designed to enhance a Web user’s experience, DHTML includes the followingfeatures:


➢ Dynamic content, which allows the user to dynamically change Webpage content
➢ Dynamic positioning of Web page elements
➢ Dynamic style, which allows the user to change the Web page’s color,font, size or content
While DHTML enhances the website user’s experience, the technology may alsobe frustrating for
users when it is used incorrectly. For example, a website menuwith flashy DHTML animations can
easily confuse user navigation. Another DHTML issue occurs when Web developers attempt to
create cross-browser DHTML, which is very difficult.

For Web developers, DHTML poses the following problems:

➢ It can be difficult to develop and debug because of lack of Web browserand technological
support.
➢ DHTML scripts may not work correctly in various Web browsers.
➢ The Web page layout may not display correctly when it is developed to display in different
screen size combinations and in different browsers.
As a result of these problems, Web developers must determine whether DHTML enhances the user
experience in any given context. Most Web developers abandon complex DHTML and use simple
cross-browser routines to improve userexperience, as opposed to integrating excessive DHTML
visual effects.
Components of Dynamic HTML
DHTML consists of the following four components or languages:
➢ HTML 4.0
➢ CSS
➢ JavaScript
➢ DOM.

HTML 4.0
HTML is a client-side markup language, which is a core component of the [Link] defines the
structure of a web page with various defined basic elements or tags.

575
CSS
CSS stands for Cascading Style Sheet, which allows the web users or developersfor controlling the
style and layout of the HTML elements on the web pages.
JavaScript
JavaScript is a scripting language which is done on a client-side. The various browser supports
JavaScript technology. DHTML uses the JavaScript technology for accessing, controlling, and
manipulating the HTML elements. The statementsin JavaScript are the commands which tell the
browser for performing an action.

DOM
DOM is the document object model. It is a w3c standard, which is a standard interface of
programming for HTML. It is mainly used for defining the objects andproperties of all elements in
HTML.
Uses of DHTML
Following are the uses of DHTML (Dynamic HTML):

o It is used for designing the animated and interactive web pages that aredeveloped in real-time.
o DHTML helps users by animating the text and images in their documents.
o It allows the authors for adding the effects on their pages.
o It also allows the page authors for including the drop-down menus orrollover buttons.
o This term is also used to create various browser-based action games.
o It is also used to add the ticker on various websites, which needs to refresh their content
automatically.
Features of DHTML
Following are the various characteristics or features of DHTML (Dynamic HTML):

o Its simplest and main feature is that we can create the web pagedynamically.
o Dynamic Style is a feature, that allows the users to alter the font, size,color, and content of a
web page.
o It provides the facility for using the events, methods, and properties. And,also provides the
feature of code reusability.
o It also provides the feature in browsers for data binding.
o Using DHTML, users can easily create dynamic fonts for their web sites orweb pages.
o With the help of DHTML, users can easily change the tags and theirproperties.
o The web page functionality is enhanced because the DHTML uses low-bandwidth effect.
Difference between HTML and DHTML

o Following table describes the differences between HTML and DHTML:

576
HTML (Hypertext Markup language) DHTML (Dynamic Hypertext Markuplanguage)

1. HTML is simply a markup language. 1. DHTML is not a language, but it is a set of


technologies of web development.

2. It is used for developing and creating web 2. It is used for creating and designing theanimated
pages. and interactive web sites or pages.

3. This markup language creates static web 3. This concept creates dynamic webpages.
pages.

4. It does not contain any server-sidescripting 4. It may contain the code of server-sidescripting.
code.

5. The files of HTML are stored withthe .html or 5. The files of DHTML are stored with the
.htm extension in a .dhtm extension in a system.

system.

6. A simple page which is created by a user 6. A page which is created by a user usingthe HTML,
without using the scripts or styles called as an CSS, DOM, and JavaScript technologies called a
HTML page. DHTML page.

7. This markup language does not need 7. This concept needs database connectivity
database connectivity. because it interacts withusers.

DHTML JavaScript

577
JavaScript can be included in HTML pages, which creates the content of the pageas dynamic. We
can easily type the JavaScript code within the <head> or <body>tag of a HTML page. If we want to
add the external source file of JavaScript, we can easily add using the <src> attribute.
Following are the various examples, which describes how to use the JavaScripttechnology with the
DHTML:
Scripting Language
A scripting language is a language that uses a sophisticated method to bring codesto a runtime
environment. In key ways, scripting languages are made for specific runtime environments, and
they automate some of the code implementation.
In that sense, they are modernizations of a system that previously used compilers to interpret
inputs.
Examples of scripting language implementation involve their use in operatingsystem shells and
web browser technologies, and elsewhere, where the interpreter can enhance how the language is
used.

Example: Python
A basic comparison of scripting languages in programming evolution involves Python, one of the
most popular languages used for many new kinds of projectsinvolving machine learning.
Python is known as a scripting language in its modular and automated build, compared to legacy
programming languages like COBOL and BASIC, which areknown as compiled languages.
Interpreted Languages
In many cases, a scripting language uses an interpreter instead of a compiler, andthat's how We
can tell whether a language is a scripting language or not.
Compiled languages use a compiler to make code into assembly language ormachine language. By
contrast, scripting languages and other interpreted languages use an interpreter.
The interpreter is responsible to interpret the source code for program [Link] could say that
in a scripting language with an interpreter, the code is the language itself, and it gets interpreted
relatively on-the-fly. Other kinds of systems like just-in-time compiling can also apply.
Hybrids
An example of the complexity of compiler languages and interpreted languages such as scripting
languages is evident in the evolution of Sun Microsystems and itsJava computer programming
language set, which has been so much a fundamental part of computer science for so many years.
Classic Java is commonly known as a compiler language. It uses the traditionalcompiler system to
convert code into machine language, as do C++ and other object oriented programming methods
of its time.
However, languages like JavaScript are known as interpreter languages, where instead of using a
compiler, an interpreter tool is used to change the way that the

code syntax is used and implemented. If We, for example, have a virtual machinefriendly language
like ByteCode interpreting Java script for a compiler, that wouldbe an interpreted language.

578
Benefits and Disadvantages of Scripting and Interpreted Languages

There are various benefits and disadvantages associated with the use of interpreted languages
over compiler languages. The uniqueness of domain- specific scripting languages and their use in
various runtime environments has been discussed. There's also the idea that interpreted language
systems can helpwhen distributed systems have different machine languages in play that make it
difficult for compiled languages to bridge these cross-platform gaps.
On the other hand, some experts talk about latency with interpreted programs,just because the code
has to run through an interpreter instead of being traditionally compiled. Experts have to assess
these sorts of trade-offs as they consider whether using a scripting language makes sense in a
given project environment.
Generally, though, the ability to abstract programming in this way is an attractivepart of modernizing
our codebase tools.
Java Servlet
Java Servlets are server-side Java program modules that process and answer clientrequests and
implement the servlet interface. It helps in enhancing Web server functionality with minimal
overhead, maintenance and support.
A servlet acts as an intermediary between the client and the server. As servlet modules run on the
server, they can receive and respond to requests made by theclient. Request and response objects
of the servlet offer a convenient way to handle HTTP requests and send text data back to the client.
Since a servlet is integrated with the Java language, it also possesses all the Javafeatures such as
high portability, platform independence, security and Java database connectivity.

There are two Java Servlet types: Basic and [Link] servlets are used as follows:
• When an HTML form is submitted, the servlet processes and stores the data.
• When a client supplies a database query, the results are provided to theclient by the servlet.
• In most cases, the server uses the common gateway interface (CGI).However, Java Servlets
have many advantages over CGI, including:
• A servlet runs in the same process, eliminating the need to create a new process for every
request.
• The CGI program must be reloaded for each CGI request. A servlet, however,does not require
reloading and remains in the memory between requests.
• A servlet answers multiple requests simultaneously by using one instance,saving memory and
easily managing persistent data.
• The servlet engine runs in a sandbox or restricted environment, protecting the server from
potentially harmful servlets.
Servlet Life Cycle
The servlet life cycle is the Java servlet processing event sequence that occurs from servlet
instance creation to destruction. The servlet life cycle is controlled bythe container that deploys the
servlet.
The servlet life cycle is made up of four stages:
579
• Instantiation
• Initialization
• Client request handling
• Destruction

When a servlet request is mapped, the servlet container checks for the existenceof a servlet class
instance. If an instance does not exist, the Web container loads the servlet class, creates an
instance of this class and initializes this instance by calling the init() method.

The initialization process is completed prior to client request handling. The container does not call
the init() method again, unless a servlet is reloaded. Afterthe instantiation and initialization are
completed, the servlet container calls the service() method to respond to the request. When the
servlet is no longer needed, the container destroys the servlet with the destroy() method. This
method is also executed only one time.
Applications of Servlet
➢ Read the explicit data sent by the clients (browsers). This includes anHTML form on a Web
page or it could also come from an applet or a custom HTTP client program.
➢ Read the implicit HTTP request data sent by the clients (browsers). This includes cookies,
media types and compression schemes the browser understands, and so forth.
➢ Process the data and generate the results. This process may require talking to a database,
executing an RMI or CORBA call, invoking a Webservice, or computing the response directly.
➢ Send the explicit data (i.e., the document) to the clients (browsers). Thisdocument can be sent
in a variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc.
➢ Send the implicit HTTP response to the clients (browsers). This includestelling the browsers
or other clients what type of document is being returned (e.g., HTML), setting cookies and
caching parameters, and other such tasks.
Java Applet
A Java applet is a small dynamic Java program that can be transferred via the Internet and run by
a Java-compatible Web browser. The main difference between Java-based applications and
applets is that applets are typically executedin an AppletViewer or Java-compatible Web browser.
All applets import
the [Link] package.

The following are two issues with Java applets:


➢ Security: Java resolves the security issue by restricting applets to Java’s execution
environment and preventing access to system resources.
➢ Portability: Portability is defined as the applet’s ability to run on different computers and
operating systems.
Any browser with Java Virtual Machine (JVM) can execute bytecode, which is theoutput of a Java
compiler and can be run only in a JVM. Bytecode is Java’s solution for security and portability.

580
Application Conversion to Applets
It is easy to convert a graphical Java application (that is, an application that usesthe AWT and that
We can start with the Java program launcher) into an applet that We can embed in a web page.
Following are the specific steps for converting an application to an applet.
➢ Make an HTML page with the appropriate tag to load the applet code.
➢ Supply a subclass of the JApplet class. Make this class public. Otherwise,the applet cannot
be loaded.
➢ Eliminate the main method in the application. Do not construct a frame window for the
application. Our application will be displayed inside thebrowser.
➢ Move any initialization code from the frame window constructor to the init method of the
applet. We don't need to explicitly construct the applet object. The browser instantiates it for
We and calls the init method.
➢ Remove the call to setSize; for applets, sizing is done with the width andheight parameters in
the HTML file.
➢ Remove the call to setDefaultCloseOperation. An applet cannot beclosed; it terminates when
the browser exits.
➢ If the application calls setTitle, eliminate the call to the method. Appletscannot have title bars.
(You can, of course, title the web page itself, using the HTML title tag.)
➢ Don't call setVisible(true). The applet is displayed automatically.

Computer Graphics
Computer Graphics involves technology to access. The Process transforms and presents
information in a visual form. The role of computer graphics insensible. In today life, computer
graphics has now become a common element in user interfaces, T.V. commercial motion pictures.
Computer Graphics is the creation of pictures with the help of a computer. Theend product of the
computer graphics is a picture it may be a business graph, drawing, and engineering.
In computer graphics, two or three-dimensional pictures can be created that are used for research.
Many hardware devices algorithm has been developing for improving the speed of picture
generation with the passes of time. It includes thecreation storage of models and image of objects.
These models for various fields like engineering, mathematical and so on.
Today computer graphics is entirely different from the earlier one. It is not possible. It is an
interactive user can control the structure of an object of variousinput devices.

Definition of Computer Graphics:


It is the use of computers to create and manipulate pictures on a display device. Itcomprises of
software techniques to create, store, modify, represents pictures.

Why computer graphics used?


Suppose a shoe manufacturing company want to show the sale of shoes for five years. For this
vast amount of information is to store. So a lot of time and memorywill be needed. This method will
be tough to understand by a common man. In this situation graphics is a better alternative. Graphics
581
tools are charts and [Link] graphs, data can be represented in pictorial form. A picture can
be understood easily just with a single look.
Interactive computer graphics work using the concept of two-way communication between
computer users. The computer will receive signals from the input device,and the picture is modified
accordingly. Picture will be changed quickly when we apply command.

Display Devices in Computer Graphics


The display device is an output device used to represent the information in theform of images
(visual form). Display systems are mostly called a video monitor or Video display unit (VDU).
Display devices are designed to model, display, view, or display information. Thepurpose of display
technology is to simplify information sharing.
Today, the demand for high-quality displays is [Link] are some display devices given

below:

1. Cathode-Ray Tube(CRT)
2. Color CRT Monitor
3. Liquid crystal display(LCD)
4. Light Emitting Diode(LED)
5. Direct View Storage Tubes(DVST)
6. Plasma Display
7. 3D Display

1. Cathode-ray Tube (CRT): Here, CRT stands for Cathode ray tube. It is a technology which is used
in traditional computer monitor and television.
Cathode ray tube is a particular type of vacuum tube that displays images whenan electron beam
collides on the radiant surface.

582
Component of CRT:
• Electron Gun: The electron gun is made up of several elements, mainly a heating filament
(heater) and a cathode.
The electron gun is a source of electrons focused on a narrow beam facing theCRT.
• Focusing & Accelerating Anodes: These anodes are used to produce anarrow and sharply
focused beam of electrons.
• Horizontal & Vertical Deflection Plates: These plates are used to guide thepath of the electron
the beam. The plates produce an electromagnetic fieldthat bends the electron beam through
the area as it travels.
• Phosphorus-coated Screen: The phosphorus coated screen is used toproduce bright spots
when the high-velocity electron beam hits it.

There are two ways to represent an object on the screen:


1. Raster Scan: It is a scanning technique in which the electron beam moves along the screen. It
moves from top to bottom, covering one line at a time.
A raster scan is based on pixel intensity control display as a rectangular box on thescreen called a
raster.
Picture description is stored in the memory area called as Refresh buffer, orFrame Buffer.
Frame buffer is also known as Raster or Bitmap. Raster scan provides the refreshrate of 60 to 80
frames per second.

For Example: Television


The beam refreshing has two types:
1. Horizontal Retracing
2. Vertical Retracing
When the beam starts from the top left corner and reaches bottom right, andagain return to the top
left, it is called the vertical retrace.
It will call back from top to bottom more horizontally as a horizontal reversal.

583
Advantages:
1. Real image
2. Many colors to be produced
3. Dark scenes can be pictured

Disadvantages:
1. Less resolution
2. Display picture line by line
3. More costly

2. Random Scan (Vector scan): It is also known as stroke-writing display or calligraphic display.
In this, the electron beam points only to the area in which thepicture is to be drawn.
It uses an electron beam like a pencil to make a line image on the screen. The image is constructed
from a sequence of straight-line segments. On the screen, each line segment is drawn by the beam
to pass from one point on the screen tothe other, where its x & y coordinates define each point.

584
After compilation of picture drawing, the system cycle back to the first line andcreate all the lines
of picture 30 to 60 times per second.

Fig: A Random Scan display draws the lines of an object in a specific orderAdvantages:

1. High Resolution
2. Draw smooth line Drawing
Disadvantages:
1. It does only the wireframe.
2. It creates complex scenes due to flicker.

2. Color CRT Monitor: It is similar to a CRT monitor.


The basic idea behind the color CRT monitor is to combine three basic colors- Red,
Green, and Blue. By using these three colors, we can producemillions of different colors.

The two basic color display producing techniques are:


1. Beam–Penetration Method: It is used with a random scan monitor for displaying pictures.
There are two phosphorus layers- Red and Green are coated inside the screen. The color shown
depends on how far the electronbeam penetrates the phosphorus surface.
A powerful electron beam penetrates the CRT, it passes through the red layer andexcites the green
layer within.
A beam with slow electrons excites only the red layer.

A beam with the medium speed of electrons, a mixture of red and green light isemitted to display
two more colors- orange and yellow.

585
Advantages:
1. Better Resolutio
2. Half cost
3. Inexpensive

Disadvantages:

1. Only four possible colors


2. Time Consuming

2. Shadow–Mask Method: It is used with a raster scan monitor for displaying pictures. It has
more range of color than the beam penetration method. It is usedin television sets and monitors.
Structure:

1. It has three phosphorus color dots at each position of the [Link] Dot: Red color Second Dot:
Green colorThird Dot: Blue color

1. It has three different guns. Each for one color.


2. It has a metal screen or plate just before the phosphorus screen,named “Shadow-Mask.”
3. It also has a shadow grid just behind the phosphorus coated screen withtiny holes in a triangular
shape.
Working: A Shadow Mask is a metal plate with tiny holes present inside a colormonitor.
A Shadow Mask directs the beam by consuming the electrons so that the beamhits only the desired
point and displays a resulting picture.
It has three different guns. These guns direct their beams to shadow mask, whichallows them to
pass. It is a task of a shadow mask to direct the beam on its particular dot on the screen and
produce a picture on the screen.
A Shadow Mask can display a wider range of pictures than beam penetration.

586
Advantages:
1. Display a wider range picture.
2. Display realistic images.
3. In-line arrangement of RGB color.

Disadvantages:
Difficult to cover all three beams on the same [Link] Resolution.

3. Liquid crystal display (LCD): The LCD depends upon the light modulatingproperties of liquid
crystals.
LCD is used in watches and portable computers. LCD requires an AC power supplyinstead of DC,
so it is difficult to use it in circuits.
It generally works on flat panel display technology. LCD consumes less power thanLED. The LCD
screen uses the liquid crystal to turn pixels on or off.
Liquid Crystals are a mixture of solid and liquid. When the current flows inside it,its position changes
into the desired color.

For Example: TFT(Thin Film Transistor)


Advantages:
1. Produce a bright image
2. Energy efficient
3. Completely flat screen

Disadvantages:
Fixed aspect ratio & ResolutionLower Contrast

More Expensive
4. Light Emitting Diode (LED): LED is a device which emits when current passesthrough it. It is a
semiconductor device.
The size of the LED is small, so we can easily make any display unit by arranging alarge number of
587
LEDs.
LED consumes more power compared to LCD. LED is used on TV, smartphones,motor vehicles,
traffic light, etc.
LEDs are powerful in structure, so they are capable of withstanding mechanicalpressure. LED also
works at high temperatures.
Advantages:

1. The Intensity of light can be controlled.


2. Low operational Voltage.
3. Capable of handling the high temperature.

Disadvantages:
More Power Consuming than LCD.

5. Direct View Storage Tube (DVST): It is used to store the picture information as a charge
distribution behind the phosphor-coated screen.
There are two guns used in DVST:

[Link] / Secondary Gun: It is used to display a picture on the screen.

Advantages:
Less Time Consuming

No Refreshing Required

High-Resolution

Less Cost
[Link] Gun: It
588
is used to store the picture information.

Disadvantages:
The specific part of the image cannot be [Link] do not display color.

[Link] Display: It is a type of flat panel display which uses tiny plasma cells. It isalso known as
the Gas-Discharge display.
Components of plasma display:
1. Anode: It is used to deliver a positive voltage. It also has the line wires.
2. Cathode: It is used to provide negative voltage to gas cells. It also has fine wires.
3. Gas Plates: These plates work as capacitors. When we pass the voltage, the celllights regularly.
4. Fluorescent cells: It contains small pockets of gas liquids when the voltage ispassed to this
neon gas. It emits light.

Advantages:
1. Wall Mounted
2. Slim
3. Wider angle

Disadvantages:
Phosphorus loses luminosity over [Link] consumes more electricity than LCD. Large Size

D Display: It is also called stereoscope display technology. This technology iscapable of bringing
589
depth perception to the viewer.
It is used for 3D gaming and 3D TVs.

For Example: Fog Display, Holographic Display, Retina Display Etc.


Advantages:
• Impressive Picture Quality
• High Definition
• Motion Communicates

Disadvantage:
• Expensive
• Binocular Fusion
Raster Scan

In a raster scan system, the electron beam is swept across the screen, one row ata time from top
to bottom. As the electron beam moves across each row, the beam intensity is turned on and off
to create a pattern of illuminated spots.
A Raster Scan Display is based on intensity control of pixels in the form of a rectangular box called
Raster on the screen. Information of on and off pixels is stored in refresh buffer or Frame buffer.
Televisions in our house are based on Raster Scan Method. The raster scan system can store
information of each pixel position, so it is suitable for realistic display of objects. Raster Scan
provides arefresh rate of 60 to 80 frames per second.
Frame Buffer is also known as Raster or bit map. In Frame Buffer the positions arecalled picture
elements or pixels. Beam refreshing is of two types. First is horizontal retracing and second is
vertical retracing. When the beam starts from the top left corner and reaches the bottom right scale,
it will again return to the top left side called at vertical retrace. Then it will again more horizontally
from top to bottom call as horizontal retracing shown in fig:

Types of Scanning or travelling of beam in Raster Scan


1. Interlaced Scanning
2. Non-Interlaced Scanning

In Interlaced scanning, each horizontal line of the screen is traced from top to bottom. Due to which
fading of display of object may occur. This problem can besolved by Non-Interlaced scanning. In
this first of all odd numbered lines are traced or visited by an electron beam, then in the next circle,
even number of lines are located.
For non-interlaced display refresh rate of 30 frames per second used. But it gives flickers. For
interlaced display refresh rate of 60 frames per second is used.
Picture definition is stored in memory area called the Refresh Buffer or FrameBuffer. This memory
area holds the set of intensity values for all the screen points. Stored intensity values are then
retrieved from the refresh buffer and “painted” on the screen one row scanlinescanline at a time as
shown in the following illustration.

590
Each screen point is referred
to as a pixel pictureelementpictureelement or [Link] the end of each scan line, the electron beam
returns to the left side of the screen to begin displaying the next scan line.

Advantages:
1. Realistic image
2. Million Different colors to be generated
3. Shadow Scenes are possible.

Disadvantages:
1. Low Resolution
2. Expensive

Random Scan VectorScanVectorScan


In this technique, the electron beam is directed only to the part of the screen where the picture is
to be drawn rather than scanning from left to right and top tobottom as in raster scan. It is also
called vector display, stroke-writing display, or calligraphic display.

Random Scan System uses an electron beam which operates like a pencil to create a line image
on the CRT screen. The picture is constructed out of a sequence of straight-line segments. Each
line segment is drawn on the screen by directing the beam to move from one point on the screen
to the next, where its x& y coordinates define each point. After drawing the picture. The system
cycles back to the first line and design all the lines of the image 30 to 60 time eachsecond. The
process is shown in fig:
Random-scan monitors are also known as vector displays or stroke-writingdisplays or calligraphic
displays.
Picture definition is stored as a set of line-drawing commands in an area of memory referred to as
the refresh display file. To display a specified picture, the system cycles through the set of
commands in the display file, drawing each component line in turn. After all the line-drawing
commands are processed, the system cycles back to the first line command in the list.
Random-scan displays are designed to draw all the component lines of a picture30 to 60 times each
second.
591
Advantages:
1. A CRT has the electron beam directed only to the parts of the screen wherean image is to be
drawn.
2. Produce smooth line drawings.
3. High Resolution
Disadvantages:
1. Random-Scan monitors cannot display realistic shades scenes.
Differentiate between Random and Raster Scan Display:

Random Scan Raster Scan


1. It has high Resolution 1. Its resolution is low.
2. It is more expensive 2. It is less expensive
3. Any modification if needed iseasy [Link] is tough
4. Solid pattern is tough to fill [Link] pattern is easy to fill
5. Refresh rate depends orresolution 5. Refresh rate does not depend onthe picture.
6. Only screen with view on an areais displayed. 6. Whole screen is scanned.
7. Beam Penetration technologycome under it. 7. Shadow mark technology cameunder this.
8. It does not use interlacingmethod. 8. It uses interlacing
9. It is restricted to line drawing 9. It is suitable for realistic display.

applications

Input Devices
The Input Devices are the hardware that is used to transfer transfers input to the

592
These Devices include:

1. Keyboard

computer. The data can be in the form of text, graphics, sound, and text. Output
device display data from the memory of the computer. Output can be text,
numeric data, line, polygon, and other objects.

2. Mouse
3. Trackball
4. Spaceball
5. Joystick
6. Light Pen
7. Digitizer
8. Touch Panels
9. Voice [Link] Scanner

Keyboard:
The most commonly used input device is a keyboard. The data is entered by pressing the set of
keys. All keys are labeled. A keyboard with 101 keys is called aQWERTY keyboard.

593
The keyboard has alphabetic as well as numeric keys. Some special keys are alsoavailable.

1. Numeric Keys: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
2. Alphabetic keys: a to z (lower case), A to Z (upper case)
3. Special Control keys: Ctrl, Shift, Alt
4. Special Symbol Keys: ; , " ? @ ~ ? :
5. Cursor Control Keys: ↑ → ← ↓
6. Function Keys: F1 F2 F3 F9.
7. Numeric Keyboard: It is on the right-hand side of the keyboard and used for fast entry of
numeric data.

Function of Keyboard:
1. Alphanumeric Keyboards are used in CAD. (Computer Aided Drafting)
2. Keyboards are available with special features line screen co-ordinatesentry, Menu selection or
graphics functions, etc.
3. Special purpose keyboards are available having buttons, dials, and [Link] are used to
enter scalar values. Dials also enter real numbers. Buttons and switches are used to enter
predefined function values.
Advantage:
1. Suitable for entering numeric data.
2. Function keys are a fast and effective method of using commands, withfewer errors.

Disadvantage:
594
1. Keyboard is not suitable for graphics input.

Mouse:
A Mouse is a pointing device and used to position the pointer on the screen. It is asmall palm size
box. There are two or three depression switches on the top. The movement of the mouse along the
x-axis helps in the horizontal movement of thecursor and the movement along the y-axis helps in
the vertical movement of the cursor on the screen. The mouse cannot be used to enter text.
Therefore, they are used in conjunction with a keyboard.

Advantage:
1. Easy to use
2. Not very expensive

Filled Area Primitives:


Region filling is the process of filling image or region. Filling can be of boundary orinterior region as
shown in fig. Boundary Fill algorithms are used to fill the boundary and flood-fill algorithm are used
to fill the interior.

Scan Line Polygon Fill Algorithm:


This algorithm lines interior points of a polygon on the scan line and these pointsare done on or off
according to requirement. The polygon is filled with various colors by coloring various pixels.
In above figure polygon and a line cutting polygon in shown. First of all, scanning is done. Scanning
is done using raster scanning concept on display device. The beam starts scanning from the top
left corner of the screen and goes toward the bottom right corner as the endpoint. The algorithms
find points of intersection ofthe line with polygon while moving from left to right and top to bottom.
The various points of intersection are stored in the frame buffer. The intensities of such points is
keep high. Concept of coherence property is used. According to thisproperty if a pixel is inside the
polygon, then its next pixel will be inside the polygon.

Side effects of Scan Conversion:


1. Staircase or Jagged: Staircase like appearance is seen while the scan wasconverting line or
circle.
2. Unequal Intensity: It deals with unequal appearance of the brightness of different lines. An
inclined line appears less bright as compared to the horizontaland vertical line.

595
Flood Fill Algorithm:
In this method, a point or seed which is inside region is selected. This point iscalled a seed point.
Then four connected approaches or eight connected approaches is used to fill with specified color.
The flood fill algorithm has many characters similar to boundary fill. But this method is more
suitable for filling multiple colors boundary. When boundary is ofmany colors and interior is to be
filled with one color we use this algorithm.

In fill algorithm, we start from a specified interior point (x, y) and reassign all pixel values are
currently set to a given interior color with the desired color. Using

either a 4-connected or 8-connected approaches, we then step through pixel positions until all
interior points have been repainted.

Disadvantage:

596
1. Very slow algorithm

#include<dos.h>

May be fail for large polygons

Initial pixel required more knowledge about surrounding pixels.


Algorithm:

Procedure floodfill (x, y,fill_ color, old_color: integer)

If (getpixel (x, y)=old_color)

setpixel (x, y, fill_color);

fill (x+1, y, fill_color, old_color);

fill (x-1, y, fill_color, old_color);

fill (x, y+1, fill_color, old_color);

fill (x, y-1, fill_color, old_color);

Program1: To implement 4-connected flood fill algorithm:


#include<stdio.h>

#include<conio.h>

#include<graphics.h>
void flood(int,int,int,int);
void main()
{
intgd=DETECT,gm;

initgraph(&gd,&gm,"C:/TURBOC3/bgi");

rectangle(50,50,250,250);

597
flood(55,55,10,0);

getch();
}
void flood(intx,inty,intfillColor, intdefaultColor)
{
if(getpixel(x,y)==defaultColor)
{
delay(1);

putpixel(x,y,fillColor);

flood(x+1,y,fillColor,defaultColor);

flood(x-1,y,fillColor,defaultColor);

flood(x,y+1,fillColor,defaultColor);

flood(x,y-1,fillColor,defaultColor);

}
}

Output:

598
Boundary Filled Algorithm:
This algorithm uses the recursive method. First of all, a starting pixel called as the seed is
considered. The algorithm checks boundary pixel or adjacent pixels are colored or not. If the
adjacent pixel is already filled or colored then leave it, otherwise fill it. The filling is done using four
connected or eight connected approaches.

Four connected approaches is more suitable than the eight connectedapproaches.


1. Four connected approaches: In this approach, left, right, above, below pixelsare tested.
2. Eight connected approaches: In this approach, left, right, above, below andfour diagonals are
selected.

Boundary can be checked by seeing pixels from left and right first. Then pixels arechecked by seeing
pixels from top to bottom. The algorithm takes time and memory because some recursive calls are
needed.

Problem with recursive boundary fill algorithm:

It may not fill regions sometimes correctly when some interior pixel is already filled with color. The
algorithm will check this boundary pixel for filling and will found already filled so recursive process
will terminate. This may vary because ofanother interior pixel unfilled.
So check all pixels color before applying the algorithm.

Algorithm:
fill (x, y+1, color, color 1);

fill (x, y-1, color, color 1);

599
Procedure fill (x, y, color, color1: integer)

int c;

c=getpixel (x, y);

if (c!=color) (c!=color1)

setpixel (x, y, color)

fill (x+1, y, color, color 1);

fill (x-1, y, color, color 1);

MidPoint Circle Algorithm


It is based on the following function for testing the spatial relationship between the arbitrary
point (x, y) and a circle of radius r centered at the origin:

600
Now, consider the coordinates of the point halfway between pixel T and pixel S This is called

midpoint (xi+1,yi- ) and we use it to define a decision parameter:

Pi=f (xi+1,yi- ) = (xi+1)2+(yi- )2-r2 equation 2

If Pi is -ve ⟹midpoint is inside the circle and we choose pixel T


If Pi is+ve ⟹midpoint is outside the circle (or on the circle)and we choose pixel [Link] decision

parameter for the next step is:

Pi+1=(xi+1+1)2+(yi+1- )2- r2 ........... equation 3

Since xi+1=xi+1, we have

If pixel T is choosen ⟹Pi<0

We have yi+1=yi
If pixel S is choosen ⟹Pi≥0

We have yi+1=yi-1

We can continue to simplify this in n terms of (xi,yi) and get

Now, initial value of Pi (0,r)from equation 2

We can put ≅1
601
∴r is an integerSo, P1=1-r
Algorithm:

Step1: Put x =0, y =r in equation

Step2: Repeat steps while x ≤ y


2We have p=1-r Plot (x,
y)
If (p<0)
Then set p = p + 2x + 3Else
p = p + 2(x-y)+5
y =y - 1 (end if)
x =x+1 (end loop)

Step3: End

Program to draw a circle using Midpoint Algorithm:

#include <graphics.h>

#include <stdlib.h>

#include <math.h>

#include <stdio.h>

#include <conio.h>

#include <iostream.h>

class bresen
{
float x, y,a, b, r, p;

public:

void get ();

void cal ();

};
602
void main ()

bresen b;

[Link] ();

[Link] ();

getch ();

Void bresen :: get ()

cout<<"ENTER CENTER AND RADIUS";

cout<< "ENTER (a, b)";

cin>>a>>b;

cout<<"ENTER r";

cin>>r;

void bresen ::cal ()

/* request auto detection */

int gdriver = DETECT,gmode, errorcode;

int midx, midy, i;

/* initialize graphics and local variables */

initgraph (&gdriver, &gmode, " ");

/* read result of initialization */

errorcode = graphresult ();


603
if (errorcode ! = grOK) /*an error occurred */

printf("Graphics error: %s \n", grapherrormsg (errorcode);

printf ("Press any key to halt:");

getch ();

exit (1); /* terminate with an error code */

x=0;

y=r;

putpixel (a, b+r, RED);

putpixel (a, b-r, RED);

putpixel (a-r, b, RED);

putpixel (a+r, b, RED);

p=5/4)-r;

while (x<=y)

If (p<0)

p+= (4*x)+6;

else

p+=(2*(x-y))+5;

y--;

604
x++;

putpixel (a+x, b+y, RED);

putpixel (a-x, b+y, RED);

putpixel (a+x, b-y, RED);

putpixel (a+x, b-y, RED);

putpixel (a+x, b+y, RED);

putpixel (a+x, b-y, RED);

putpixel (a-x, b+y, RED);

putpixel (a-x, b-y, RED);

}
}

Output:

Bresenham's Line Algorithm

This algorithm is used for scan converting a line. It was developed by Bresenham. It is an
efficient method because it involves only integer addition, subtractions, and multiplication
operations. These operations can be performed very rapidly solines can be generated
quickly.

In this method, next pixel selected is that one who has the least distance fromtrue line.
605
The method works as follows:

Assume a pixel P1'(x1',y1'),then select subsequent pixels as we work our may tothe night,
one pixel position at a time in the horizontal direction toward P2'(x2',y2').
Once a pixel in choose at any stepThe next pixel is

1. Either the one to its right (lower-bound for the line)


2. One top its right and up (upper-bound for the line)
The line is best approximated by those pixels that fall the least distance from thepath between
P1',P2'.

To chooses the next one between the bottom pixel S and top pixel T.
If S is chosen

We have xi+1=xi+1 and yi+1=yi


If T is chosen
The actual y coordinates of the line at x = xi+1is
We have xi+1=xi+1 and yi+1=yi+1
y=mxi+1+b

The distance from S to the actual line in y directions = y-yi


The distance from T to the actual line in y directiont = (yi+1)-y

Now consider the difference between these 2 distance valuess - t


When (s-t) <0 ⟹ s < tThe closest pixel is S
When (s-t) ≥0 ⟹ s < t
606
The closest pixel is T
Since x_(i+1)=xi+1,we have
di+1+di=2𝗈y.(xi+1-xi)- 2𝗈x(yi+1-yi)Special Cases

If chosen pixel is at the top pixel T (i.e., di≥0)⟹ yi+1=yi+1di+1=di+2𝗈y-2𝗈x


If chosen pixel is at the bottom pixel T (i.e., di<0)⟹ yi+1=yidi+1=di+2𝗈y
Finally, we calculate d1
d1=𝗈x[2m(x1+1)+2b-2y1-1]d1=𝗈x[2(mx1+b-y1)+2m-1]

Since mx1+b-yi=0 and m = , we haved1=2𝗈y-𝗈x


Advantage:
1. It involves only integer arithmetic, so it is simple.
2. It avoids the generation of duplicate points.
3. It can be implemented using hardware because it does not use multiplicationand division.
4. It is faster as compared to DDA (Digital Differential Analyzer) because it does not involve
floating point calculations like DDA Algorithm.
Disadvantage:
1. This algorithm is meant for basic line drawing only Initializing is not a part of Bresenham's line
algorithm. So to draw smooth lines, We should want to look intoa different algorithm.
Bresenham's Line Algorithm:

Step1: Start Algorithm

Step2: Declare variable x1,x2,y1,y2,d,i1,i2,dx,dy

Step3: Enter value of x1,y1,x2,y2


Where x1,y1are coordinates of starting pointAnd x2,y2 are coordinates of Ending point
Step4: Calculate dx = x2-x1
Calculate dy = y2-y1 Calculate i1=2*dy Calculate i2=2*(dy-dx)Calculate d=i1-dx
Step5: Consider (x, y) as starting point and xendas maximum possible value of x.
If dx < 0
Then x = x2y = y2 xend=x1
If dx > 0 Then x = x1
y = y1
xend=x2

Step6: Generate point at (x,y)coordinates.


Step7: Check if whole line is generated.
If x > = xendStop.
Step8: Calculate co-ordinates of the next pixelIf d < 0
Then d = d + i1If d ≥ 0
Then d = d + i2 Increment y = y + 1
Step9: Increment x = x + 1
Step10: Draw a point of latest (x, y) coordinates
607
Step11: Go to step 7

Step12: End of Algorithm


Example: Starting and Ending position of the line are (1, 1) and (8, 5). Findintermediate points.
Solution: x1=1
y1=1x2=8y2=5
dx= x2-x1=8-1=7dy=y2-y1=5-1=4
I1=2* ∆y=2*4=8 I2=2*(∆y-∆x)=2*(4-7)=-6d = I1-∆x=8-7=1

x y d=d+I1 or I2

1 1 d+I2=1+(-6)=-5

2 2 d+I1=-5+8=3

3 2 d+I2=3+(-6)=-3

4 3 d+I1=-3+8=5

5 3 d+I2=5+(-6)=-1

6 4 d+I1=-1+8=7

7 4 d+I2=7+(-6)=1

8 5

608
Program to implement Bresenham's Line Drawing Algorithm:
{

#include<stdio.h>

#include<graphics.h>

void drawline(int x0, int y0, int x1, int y1)

int dx, dy, p, x, y;

dx=x1-x0;

dy=y1-y0;

x=x0;

y=y0;

p=2*dy-dx;

while(x<x1)

if(p>=0)

putpixel(x,y,7);

y=y+1;

p=p+2*dy-2*dx;

else

putpixel(x,y,7);

p=p+2*dy;}

x=x+1;

609
}

}
int main()
{
int gdriver=DETECT, gmode, error, x0, y0, x1, y1;

initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");

printf("Enter co-ordinates of first point: ");

scanf("%d%d", &x0, &y0);

printf("Enter co-ordinates of second point: ");


scanf("%d%d", &x1, &y1);

drawline(x0, y0, x1, y1); return 0;

Output:

Midpoint Ellipse Algorithm:


This is an incremental method for scan converting an ellipse that is centered at the origin in
standard position i.e., with the major and minor axis parallel to coordinate system axis. It is very
similar to the midpoint circle algorithm. Becauseof the four-way symmetry property we need to
consider the entire elliptical curvein the first quadrant.
first rewrite the ellipse equation and define the function f that can be used todecide if the midpoint
between two candidate pixels is inside or outside the ellipse:

610
Now divide the elliptical curve from (0, b) to (a, 0) into two parts at point Q wherethe slope of the
curve is -1.

Slope of the curve is defined by the f(x, y) = 0 is where fx & fy are partialderivatives of f(x, y) with
respect to x & y.

We have fx = 2b2 x, fy=2a2 y & Hence we can monitor the slope valueduring the scan conversion
process to detect Q. Our starting point is (0, b)
Suppose that the coordinates of the last scan converted pixel upon entering step iare (xi,yi). We are
to select either T (xi+1),yi) or S (xi+1,yi-1) to be the next pixel. The midpoint of T & S is used to define
the following decision parameter.

pi = f(xi+1),yi- )

pi=b2 (xi+1)2+a2 (yi- )2-a2 b2


If pi<0, the midpoint is inside the curve and we choose pixel T.

If pi>0, the midpoint is outside or on the curve and we choose pixel [Link] parameter for the

next step is:


611
pi+1=f(xi+1+1,yi+1- )

= b2 (xi+1+1)2+a2 (yi+1- )2-a2 b2


Since xi+1=xi+1,we have

pi+1-pi=b2[((xi+1+1)2+a2 (yi+1- )2-(yi - )2] pi+1= pi+2b2 xi+1+b2+a2 [(yi+1- )2-(yi - )2]

If T is chosen pixel (pi<0), we have yi+1=yi.

If S is chosen pixel (pi>0) we have yi+1=yi-1. Thus we can express


pi+1in terms of pi and (xi+1,yi+1): pi+1= pi+2b2 xi+1+b2 if pi<0 =pi+2b2 xi+1+b2-2a2 yi+1 if pi>0
The initial value for the recursive expression can be obtained by the evaluatingthe original definition
of pi with (0, b):

p1 = (b2+a2 (b- )2-a2 b2


= b2-a2 b+a2/4
Suppose the pixel (xj yj) has just been scan converted upon entering step j. The next pixel is either
U (xj ,yj-1) or V (xj+1,yj-1). The midpoint of the horizontal lineconnecting U & V is used to define the
decision parameter:

qj=f(xj+ ,yj-1)

qj=b2 (xj+ )2+a2 (yj -1)2-a2 b2


If qj<0, the midpoint is inside the curve and we choose pixel V.

If qj≥0, the midpoint is outside the curve and we choose pixel [Link] for the next step
is:

qj+1=f(xj+1+ ,yj+1-1)

= b2 (xj+1+ )2+ a2 (yj+1-1)2- a2 b2


Since yj+1=yj-1,we have

qj+1-qj=b2 [(xj+1+ )2-(xj + )2 ]+a2 (yj+1-1)2-( yj+1)2 ]


qj+1=qj+b2 [(xj+1+ )2-(xj + )2]-2a2 yj+1+a2
If V is chosen pixel (qj<0), we have xj+1=xj.

If U is chosen pixel (pi>0) we have xj+1=xj. Thus we can expressqj+1in terms of qj and (xj+1,yj+1 ):
qj+1=qj+2b2 xj+1-2a2 yj+1+a2 if qj < 0
=qj-2a2 yj+1+a2 if qj>0
The initial value for the recursive expression is computed using the original definition of qj. And the
coordinates of (xk yk) of the last pixel choosen for the part1 of the curve:

q1 = f(xk+ ,yk-1)=b2 (xk+ )2-a2 (yk-1)2- a2 b2


Algorithm:

612
int x=0, y=b; [starting point]
int fx=0, fy=2a2 b [initial partial derivatives]int p = b2-a2 b+a2/4

while (fx<="" 1="" {="" set="" pixel="" (x,="" y)="" x++;="" fx="fx" +="" 2b2;if (p<0)

p = p + fx +b2;else
{
y--;

fy=fy-2a2
p = p + fx +b2-fy;
}
}
Setpixel (x, y);

p=b2(x+0.5)2+ a2 (y-1)2- a2 b2
while (y>0)
{
y--;

fy=fy-2a2;if (p>=0) p=p-fy+a2else

{
x++;
fx=fx+2b2 p=p+fx-fy+a2;

}
Setpixel (x,y);
}
Transformations
Computer Graphics provide the facility of viewing object from different [Link] architect can
study building from different angles i.e.
1. Front Evaluation
2. Side elevation
3. Top plan

A Cartographer can change the size of charts and topographical maps. So if graphics images are
coded as numbers, the numbers can be stored in memory. These numbers are modified by
mathematical operations called as Transformation.
The purpose of using computers for drawing is to provide facility to user to viewthe object from
different angles, enlarging or reducing the scale or shape of object called as Transformation.

Two essential aspects of transformation are given below:


1. Each transformation is a single entity. It can be denoted by a unique nameor symbol.
2. It is possible to combine two transformations, after connecting a single transformation is
obtained, e.g., A is a transformation for translation. The Btransformation performs scaling. The
613
combination of two is C=AB. So C is obtained by concatenation property.
There are two complementary points of view for describing objecttransformation.

1. Geometric Transformation: The object itself is transformed relative to the coordinate system
or background. The mathematical statement of this viewpoint is defined by geometric
transformations applied to each point ofthe object.
2. Coordinate Transformation: The object is held stationary while the coordinate system is
transformed relative to the object. This effect isattained through the application of coordinate
transformations.

An example that helps to distinguish these two viewpoints:


The movement of an automobile against a scenic background we can simulatethis by
o Moving the automobile while keeping the background fixed-(GeometricTransformation)
o We can keep the car fixed while moving the background scenery-(Coordinate Transformation)

Types of Transformations:
1. Translation
2. Scaling
3. Rotating
4. Reflection
5. Shearing

Note: Translation, Scaling, and Rotation are also called as Basic Transformations.

Translation
It is the straight line movement of an object from one position to another is calledTranslation. Here
the object is positioned from one coordinate location to another.

Translation of point:
To translate a point from coordinate position (x, y) to another (x1 y1), we add algebraically the
translation distances Tx and Ty to original coordinate.
x1=x+Txy1=y+Ty

The translation pair (Tx,Ty) is called as shift vector.

Translation is a movement of objects without deformation. Every position or point is translated by


the same amount. When the straight line is translated, thenit will be drawn using endpoints.
For translating polygon, each vertex of the polygon is converted to a new position. Similarly, curved
objects are translated. To change the position of the circle or ellipse its center coordinates are
transformed, then the object is drawnusing new coordinates.
Let P is a point with coordinates (x, y). It will be translated as (x1 y1).

614
Matrix for Translation:

Scaling:
It is used to alter or change the size of objects. The change is done using scalingfactors. There are
two scaling factors, i.e. Sx in x direction Sy in y-direction. If the

original position is x and y. Scaling factors are Sx and Sy then the value ofcoordinates after scaling
will be x1 and y1.
If the picture to be enlarged to twice its original size then Sx = Sy =2. If Sxand Sy arenot equal then
615
scaling will occur but it will elongate or distort the picture.

If scaling factors are less than one, then the size of the object will be reduced. If
scaling factors are higher than one, then the size of the object will be enlarged.

If Sxand Syare equal it is also called as Uniform Scaling. If not equal then called as
Differential Scaling. If scaling factors with values less than one will move the
object closer to coordinate origin, while a value higher than one will move
coordinate position farther from origin.

Enlargement: If T1= ,If (x1 y1)is original position and T1is translation vector
then (x2 y2) are coordinated after scaling

The image will be enlarged two times

Reduction: If T1= . If (x1 y1) is original position and T1 is translation vector, then (x2 y2) are
coordinates after scaling

616
617
Matrix for Scaling:

Example: Prove that 2D Scaling transformations are commutative i.e, S1 S2=S2 S1.

Solution: S1 and S2 are scaling matrices

618
Rotation:
It is a process of changing the angle of the object. Rotation can be clockwise or anticlockwise. For
rotation, we have to specify the angle of rotation and rotationpoint. Rotation point is also called a
pivot point. It is print about which object is rotated.

Types of Rotation:
1. Anticlockwise
2. Counterclockwise
The positive value of the pivot point (rotation angle) rotates an object in acounter-clockwise
(anti-clockwise) direction.

The negative value of the pivot point (rotation angle) rotates an object in aclockwise direction.

When the object is rotated, then every point of the object is rotated by the same
angle.

Straight Line: Straight Line is rotated by the endpoints with the same angle andredrawing
the line between new endpoints.

Polygon: Polygon is rotated by shifting every vertex using the same rotationalangle.

Curved Lines: Curved Lines are rotated by repositioning of all points and drawingof the
curve at new positions.

Circle: It can be obtained by center position by the specified angle.

Ellipse: Its rotation can be obtained by rotating major and minor axis of an ellipseby the
desired angle.

619
Matrix for rotation is a clockwise direction.

620
Matrix for rotation is an anticlockwise direction.

Matrix for homogeneous co-ordinate rotation (clockwise)

Matrix for homogeneous co-ordinate rotation (anticlockwise)

Rotation about an arbitrary point: If we want to rotate an object or point about


an arbitrary point, first of all, we translate the point about which we want to
rotate to the origin. Then rotate point or object about the origin, and at the end,
we again translate it to the original place. We get rotation about an arbitrary
point.

Example: The point (x, y) is to be rotated

The (xc yc) is a point about which counterclockwise rotation is done

Step1: Translate point (xc yc) to origin

621
Step2: Rotation of (x, y) about the origin

Step3: Translation of center of rotation back to its original position

622
Example1: Prove that 2D rotations about the origin are commutative i.e.R1 R2=R2 R1.

Solution: R1 and R2are rotation matrices

Example2: Rotate a line CD whose endpoints are (3, 4) and (12, 15) about originthrough a 45°
anticlockwise direction.

Solution: The point C (3, 4)

623
624
Example3: Rotate line AB whose endpoints are A (2, 5) and B (6, 12) about originthrough a 30°
clockwise direction.

Solution: For rotation in the clockwise direction. The matrix is

Step1: Rotation of point A (2, 5). Take angle 30°

Step2: Rotation of point B (6, 12)

Reflection:
625
It is a transformation which produces a mirror image of an object. The mirrorimage can be either
about x-axis or y-axis. The object is rotated by180°.
Types of Reflection:

1. Reflection about the x-axis

626
Reflection about the y-axis

Reflection about an axis perpendicular to xy plane and passing through the


origin

Reflection about line y=x

1. Reflection about x-axis: The object can be reflected about x-axis with the help
of the following matrix

In this transformation value of x will remain same whereas the value of y will
become negative. Following figures shows the reflection of the object axis. The
object will lie another side of the x-axis.

627
2. Reflection about y-axis: The object can be reflected about y-axis with the help of
following transformation matrix

Here the values of x will be reversed, whereas the value of y will remain the [Link] object will lie
another side of the y-axis.
The following figure shows the reflection about the y-axis

628
3. Reflection about an axis perpendicular to xy plane and passing through origin:
In the matrix of this transformation is given below

In this value of x and y both will be reversed. This is also called as half revolutionabout the origin.

4. Reflection about line y=x: The object may be reflected about line y = x with the help of
629
following transformation matrix

First of all, the object is rotated at 45°. The direction of rotation is clockwise. Afterit reflection is
done concerning x-axis. The last step is the rotation of y=x back to its original position that is
counterclockwise at 45°.
Example: A triangle ABC is given. The coordinates of A, B, C are given as

A (3 4)
B (6 4)
C (4 8)
Find reflected position of triangle i.e., to the x-axis.

Solution:

630
The a point coordinates after reflection

The b point coordinates after reflection

The coordinate of point c after reflection

a (3, 4) becomes a1 (3, -4)


b (6, 4) becomes b1 (6, -4)
c (4, 8) becomes c1 (4, -8)

Program to perform Mirror Reflection about a line:

631
#include <iostream.h>

#include <conio.h>

#include <graphics.h>

#include <math.h>

#include <stdlib.h>

#define pi 3.14

class arc

float x[10],y[10],theta,ref[10][10],ang;

float p[10][10],p1[10][10],x1[10],y1[10],xm,ym;

int i,k,j,n;

public:

void get();

void cal ();

void map ();

void graph ();

void plot ();

void plot1();

};

void arc::get ()

cout<<"\n ENTER ANGLE OF LINE INCLINATION AND Y INTERCEPT";

cin>> ang >> b;

cout <<"\n ENTER NO OF VERTICES";


632
cin >> n;

cout <<"\n ENTER";

for (i=0; i<n; i++)

cout<<"\n x["<<i<<"] and y["<<i<<"]";

theta =(ang * pi)/ 180;

ref [0] [0] = cos (2 * theta);

ref [0] [1] = sin (2 * theta);

ref [0] [2] = -b *sin (2 * theta);

ref [1] [0] = sin (2 * theta);

ref [1] [1] = -cos (2 * theta);

ref [1] [2] = b * (cos (2 * theta)+1);

ref [2] [0]=0;

ref [2] [1]=0;

ref [2] [2] = 1;

void arc :: cal ()

for (i=0; i < n; i++)

p[0] [i] = x [i];

p [1] [i] = y [i];

p [2] [i] = 1;
633
}

for (i=0; i<3;i++)

for (j=0; j<n; j++)

p1 [i] [j]=0;

for (k=0;k<3; k++)

p1 [i] [j] + = ref [i] [k] * p [k] [j];

for (i=0; i<n; i++)

x1 [i]=p1[0] [i];

y1 [i] = p1 [1] [i];

void arc :: map ()

int gd = DETECT,gm;

initgraph (&gd, &gm, " ");

int errorcode = graphresult ();

/* an error occurred */

if (errorcode ! = grOK)

{
634
printf ("Graphics error: %s \n", grapherrormsg (errorcode));

printf ("Press any key to halt:");

getch ();

exit (1); /* terminate with an error code */

void arc :: graph ()

xm=getmaxx ()/2;

ym=getmaxy ()/2;

line (xm, 0, xmm 2*ym);

void arc :: plot 1 ()

for (i=0; i <n-1; i++)

circle (x1[i]+xm, (-y1[i]+ym), 2);

line (x1[i]+xm, (-y1[i]+ym), x1[i+1]+xm, (-y1[i+1]+ym));

line (x1[n-1)+xm, (-y1[n-1]+ym), x1[0]+xm, (-y1[0]+ym));

getch();

void arc :: plot ()

635
line (x1[i]+xm, (-y1[i]+ym), x[i+1]+xm, (-y1[i+1]+ym));

line (x[n-1]+xm, (-y1[n-1]+ym), x[0]+xm, (-y[0]+ym));

getch();

void main ()

class arc a;

clrscr();

[Link]();

[Link]();

[Link]();

[Link]();

[Link]();

a.plot1();

getch();

Output:
{

for (i=0; i <n-1; i++)

circle (x1[i]+xm, (-y1[i]+ym, 2);

636
Shearing:

It is transformation which changes the shape of object. The sliding of layers ofobject occur. The
shear can be in one direction or in two directions.
Shearing in the X-direction: In this horizontal shearing sliding of layers occur. Thehomogeneous
matrix for shearing in the x-direction is shown below:

Shearing in the Y-direction: Here shearing is done by sliding along vertical or y-axis.

Shearing in X-Y directions: Here layers will be slided in both x as well as y


direction. The sliding will be in horizontal as well as vertical direction. The shape
of the object will be distorted. The matrix of shear in both directions is given by:

Matrix Representation of 2D Transformation

637
Homogeneous Coordinates

The rotation of a point, straight line or an entire image on the screen, about a
point other than origin, is achieved by first moving the image until the point of
rotation occupies the origin, then performing rotation, then finally moving the
image to its original position.

The moving of an image from one place to another in a straight line is called a translation. A
translation may be done by adding or subtracting to each point, theamount, by which picture is
required to be shifted.

Translation of point by the change of coordinate cannot be combined with other transformation by

638
using simple matrix application. Such a combination is essentialif we wish to rotate an image about
a point other than origin by translation, rotation again translation.
To combine these three transformations into a single transformation, homogeneous coordinates
are used. In homogeneous coordinate system, two- dimensional coordinate positions (x, y) are
represented by triple-coordinates.
Homogeneous coordinates are generally used in design and construction applications. Here we
perform translations, rotations, scaling to fit the pictureinto proper position.
Example of representing coordinates into a homogeneous coordinate system: For two-
dimensional geometric transformation, we can choose
homogeneous parameter h to any non-zero value. For our convenience take it asone. Each two-
dimensional position is then represented with homogeneous coordinates (x, y, 1).

Following are matrix for two-dimensional transformation in homogeneouscoordinate:

Composite Transformation:
A number of transformations or sequence of transformations can be combined into single one
called as composition. The resulting matrix is called as composite matrix. The process of
combining is called as concatenation.

Suppose we want to perform rotation about an arbitrary point, then we can perform it by the
sequence of three transformations
639
1. Translation
2. Rotation
3. Reverse Translation

The ordering sequence of these numbers of transformations must not be changed. If a matrix is
represented in column form, then the composite transformation is performed by multiplying matrix
in order from right to left [Link] output obtained from the previous matrix is multiplied with the
new coming matrix.

Example showing composite transformations:


The enlargement is with respect to center. For this following sequence of transformations will be
performed and all will be combined to a single one
Step1: The object is kept at its position as in fig (a)
Step2: The object is translated so that its center coincides with the origin as in fig(b)
Step3: Scaling of an object by keeping the object at origin is done in fig (c)
Step4: Again translation is done. This second translation is called a reverse translation. It will
position the object at the origin location.
Above transformation can be represented as [Link]-1

640
Note: Two types of rotations are used for representing matrices one is column

method. Another is the row method.

641
Advantage of composition or concatenation of matrix:
1. It transformations become compact.
2. The number of operations will be reduced.
3. Rules used for defining transformation in form of equations are complex as compared to
matrix.
Composition of two translations:
Let t1 t2 t3 t4are translation vectors. They are two translations P1 and P2. The matrix of P1 and P2
given below. The P1 and P2are represented using Homogeneous matrices and P will be the final
transformation matrix obtainedafter multiplication.
Above resultant matrix show that two successive translations are additive.

Composition of two Rotations: Two Rotations are also additive


Composition of two Scaling: The composition of two scaling is multiplicative. LetS11 and S12are
matrix to be multiplied.

642
Computer Graphics Window to Viewport Co-ordinate Transformation

Once object description has been transmitted to the viewing reference frame, we choose the
window extends in viewing coordinates and selects the viewport limitsin normalized coordinates.
Object descriptions are then transferred to normalized device coordinates:
We do this thing using a transformation that maintains the same relative placement of an object in
normalized space as they had in viewing coordinates.
If a coordinate position is at the center of the viewing window:
It will display at the center of the viewport.

Fig shows the window to viewport mapping. A point at position (xw, yw) inwindow mapped into
position (xv, yv) in the associated viewport.

643
In order to maintain the same relative placement of the point in the viewport asin the window, we
require:

Solving these impressions for the viewport position (xv, yv), we havexv=xvmin+(xw-xwmin)sx
yv=yvmin+(yw-ywmin)sy equation 2
Where scaling factors are

Equation (1) and Equation (2) can also be derived with a set of transformation that converts the
window or world coordinate area into the viewport or screencoordinate area. This conversation is
performed with the following sequence oftransformations:
644
1. Perform a scaling transformation using a fixed point position (xwmin,ywmin) that scales the
window area to the size of the viewport.
2. Translate the scaled window area to the position of the viewport. Relativeproportions of objects
are maintained if the scaling factors are the same (sx=sy).
From normalized coordinates, object descriptions are mapped to the variousdisplay devices.
Any number of output devices can we open in a particular app, and three windows to viewport
transformation can be performed for each open outputdevice.
This mapping called workstation transformation (It is accomplished by selecting awindow area in
normalized space and a viewport area in the coordinates of the display device).
As in fig, workstation transformation to partition a view so that different parts ofnormalized space
can be displayed on various output devices).

Matrix Representation of the above three steps of Transformation:

645
Step1:Translate window to origin 1Tx=-Xwmin Ty=-Ywmin

Step2:Scaling of the window to match its size to the viewportSx=(Xymax-Xvmin)/(Xwmax-Xwmin)


Sy=(Yvmax-Yvmin)/(Ywmax-Ywmin)

Step3:Again translate viewport to its correct position on screen.


Tx=XvminTy=Yvmin
Above three steps can be represented in matrix form:VT=T * S * T1
T = Translate window to the origin S=Scaling of the window to viewport sizeT1=Translating viewport

on screen.

Viewing Transformation= T * S * T1

Advantage of Viewing Transformation:


We can display picture at device or display system according to our need andchoice.

Note:
➢ World coordinate system is selected suits according to the applicationprogram.
➢ Screen coordinate system is chosen according to the need of design.
➢ Viewing transformation is selected as a bridge between the world andscreen coordinate.

Line Clipping:
It is performed by using the line clipping algorithm. The line clipping algorithmsare:
1. Cohen Sutherland Line Clipping Algorithm
2. Midpoint Subdivision Line Clipping Algorithm
3. Liang-Barsky Line Clipping Algorithm

Cohen Sutherland Line Clipping Algorithm:


In the algorithm, first of all, it is detected whether line lies inside the screen or it isoutside the screen.
All lines come under any one of the following categories:
1. Visible
2. Not Visible
646
3. Clipping Case

1. Visible: If a line lies within the window, i.e., both endpoints of the line lieswithin the window. A
line is visible and will be displayed as it is.
2. Not Visible: If a line lies outside the window it will be invisible and rejected. Such lines will not
display. If any one of the following inequalities is satisfied, thenthe line is considered invisible. Let
A (x1,y2) and B (x2,y2) are endpoints of line.
xmin,xmax are coordinates of the window.
ymin,ymax are also coordinates of the window.x1>xmax
x2>xmax y1>ymax
y2>ymax x1<xmin x2<xmin y1<ymin y2<ymin

3. Clipping Case: If the line is neither visible case nor invisible case. It is
considered to be clipped case. First of all, the category of a line is found based on
nine regions given below. All nine regions are assigned codes. Each code is of 4
bits. If both endpoints of the line have end bits zero, then the line is considered to
be visible.

The center area is having the code, 0000, i.e., region 5 is considered a rectangle
window.

Following figure show lines of various types

647
Line AB is the visible case Line OP is an invisible case Line PQ is an invisible line Line IJ are clipping
candidates
Line MN are clipping candidateLine CD are clipping candidate

Advantage of Cohen Sutherland Line Clipping:


1. It calculates end-points very quickly and rejects and accepts lines quickly.
2. It can clip pictures much large than screen size.
Algorithm of Cohen Sutherland Line Clipping: Step1:Calculate positions of both endpoints of the

line Step2:Perform OR operation on both of these end-points

Step3:If the OR operation gives 0000Then


line is considered to be visible
else
Perform AND operation on both endpointsIf And ≠ 0000

then the line is invisibleelse


And=0000
Line is considered the clipped case.

Step4:If a line is clipped case, find an intersection with boundaries of the windowm=(y2-y1 )(x2-x1)
(a) If bit 1 is "1" line intersects with left boundary of rectangle windowy3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window

(b) If bit 2 is "1" line intersect with right boundaryy3=y1+m(X-X1)


where X = Xwmax
where X more is maximum value of X co-ordinate of the window

648
(c) If bit 3 is "1" line intersects with bottom boundaryX3=X1+(y-y1)/m
where y = ywmin
ywmin is the minimum value of Y co-ordinate of the window

(d) If bit 4 is "1" line intersects with the top boundaryX3=X1+(y-y1)/m


where y = ywmax
ywmax is the maximum value of Y co-ordinate of the window

Example of Cohen-Sutherland Line Clipping Algorithm:


Let R be the rectangular window whose lower left-hand corner is at L (-3, 1) andupper right-hand
corner is at R (2, 6). Find the region codes for the endpoints infig:

The region code for point (x, y) is set according to the scheme Bit 1 = sign (y-ymax)=sign (y-6) Bit 3
= sign (x-xmax)= sign (x-2)Bit 2 = sign (ymin-y)=sign(1-y) Bit 4 = sign (xmin-x)=sign(-3-x)
Here

649
So

A (-4, 2)→ 0001 F (1, 2)→ 0000


B (-1, 7) → 1000 G (1, -2) →0100
C (-1, 5)→ 0000 H (3, 3) → 0100
D (3, 8) → 1010 I (-4, 7) → 1001
E (-2, 3) → 0000 J (-2, 10) → 1000
We place the line segments in their appropriate categories by testing the regioncodes found in the
problem.

Category1 (visible): EF since the region code for both endpoints is 0000.
Category2 (not visible): IJ since (1001) AND (1000) =1000 (which is not 0000).

Category 3 (candidate for clipping): AB since (0001) AND (1000) = 0000, CD since(0000) AND
(1010) =0000, and GH. since (0100) AND (0010) =0000.
The candidates for clipping are AB, CD, and GH.

In clipping AB, the code for A is 0001. To push the 1 to 0, we clip against the
boundary line xmin=-3. The resulting intersection point is I1 (-3,3 ). We clip (do not display) AI1 and I1
B. The code for I1is 1001. The clipping category for I1 B is 3since (0000) AND (1000) is (0000). Now
B is outside the window (i.e., its code is 1000), so we push the 1 to a 0 by clipping against the line
ymax=6. The resulting
intersection is l2 (-1 ,6). Thus I2 B is clipped. The code for I2 is 0000. The remaining segment I1 I2 is
displayed since both endpoints lie in the window (i.e.,their codes are 0000).
For clipping CD, we start with D since it is outside the window. Its code is [Link] push the first 1
to a 0 by clipping against the line ymax=6. The resulting
intersection I3 is ( ,6),and its code is 0000. Thus I3 D is clipped and the remainingsegment CI3 has
both endpoints coded 0000 and so it is displayed.
For clipping GH, we can start with either G or H since both are outside the window. The code for G
is 0100, and we push the 1 to a 0 by clipping against the
line ymin=[Link] resulting intersection point is I4 (2 ,1) and its code is 0010. We clip GI4 and work on
I4 H. Segment I4 H is not displaying since (0010) AND (0010)
=0010.

Polygon:
Polygon is a representation of the surface. It is primitive which is closed in [Link] is formed using
a collection of lines. It is also called as many-sided figure. The lines combined to form polygon are
called sides or edges. The lines are obtained by combining two vertices.

Example of Polygon:
1. Triangle
2. Rectangle
650
3. Hexagon
4. Pentagon

Following figures shows some polygons.

Types of Polygons
1. Concave
2. Convex
A polygon is called convex of line joining any two interior points of the polygon lies inside the
polygon. A non-convex polygon is said to be concave. A concavepolygon has one interior angle
greater than 180°. So that it can be clipped intosimilar polygons.

651
A polygon can be positive or negative oriented. If we visit vertices and vertices
visit produces counterclockwise circuit, then orientation is said to be positive.

652
Polygon Clipping SutherlandHodgmanAlgorithmSutherlandHodgmanAlgorithm
A polygon can also be clipped by specifying the clipping window. Sutherland Hodgeman polygon
clipping algorithm is used for polygon clipping. In this algorithm, all the vertices of the polygon are
clipped against each edge of theclipping window.
First the polygon is clipped against the left edge of the polygon window to get new vertices of the
polygon. These new vertices are used to clip the polygon against right edge, top edge, bottom edge,
of the clipping window as shown in thefollowing figure.

653
While processing an edge of a polygon with clipping window, an intersection
point is found if edge is not completely inside clipping window and the a partial
edge from the intersection point to the outside edge is clipped. The following
figures show left, right, top and bottom edge clippings −

654
Object Representation, Geometric Transformations and Viewing

9. 3D Object Representations

Methods:
➢ Polygon and Quadric surfaces: For simple Euclidean objects
➢ Spline surfaces and construction: For curved surfaces
➢ Procedural methods: Eg. Fractals, Particle systems
➢ Physically based modeling methods
➢ Octree Encoding
➢ Isosurface displays, Volume rendering, etc.

Classification:
Boundary Representations (B-reps) eg. Polygon facets and spline patches Space- partitioning
representations eg. Octree Representation
Objects may also associate with other properties such as mass, volume, so as todetermine their
response to stress and temperature etc.

Polygon Surfaces
Objects are represented as a collection of surfaces. 3D object representation isdivided into two
categories.
• Boundary Representations B−repsB−reps − It describes a 3D object as a setof surfaces that

655
separates the object interior from the environment.
• Space–partitioning representations − It is used to describe interior properties, by partitioning
the spatial region containing an object into a setof small, non-overlapping, contiguous solids
usuallycubesusuallycubes.
The most commonly used boundary representation for a 3D graphics object is a set of surface
polygons that enclose the object interior. Many graphics system usethis method. Set of polygons
are stored for object description. This simplifies and speeds up the surface rendering and display
of object since all surfaces can be described with linear equations.
The polygon surfaces are common in design and solid-modeling applications, since their wireframe
display can be done quickly to give general indication ofsurface structure. Then realistic scenes are
produced by interpolating shadingpatterns across polygon surface to illuminate.

Curved Surfaces
1. Regular curved surfaces can be generated as
- Quadric Surfaces, eg. Sphere, Ellipsoid, or
- Superquadrics, eg. Superellipsoids

656
2. Irregular surfaces can also be generated using some special formulating approach, to forma
kind of blobby objects -- Theshapes showing a certain degree of fluidity.

3. Spline Representations
Spline means a flexible strip used to produce a smooth curve through a designated set of points.
Several small weights are distributed along thelength of the strip to hold it in position on the drafting
table as the curve is drawn.
We can mathematically describe such a curve with a piecewise cubic polynomial function => spline
curves. Then a spline surface can be described with 2 sets of orthogonal spline curves.

Quadric Surfaces
Quadric surfaces are defined by quadratic equations in two dimensional space. Spheres and cones
are examples of quadrics. The quadric surfaces of RenderMan are surfaces of revolution in which
a finite curve in two dimensions is swept in three dimensional space about one axis to create a
surface. A circle centered at the origin forms a sphere. If the circle is not centered at the origin, the
circle sweeps out a torus. A line segment with one end lying on the axis of rotation forms a cone.
A line segment parallel to the axis of rotation forms a cylinder. The generalization of a line segment
creates a hyperboloid by rotating an arbitrary linesegment in three dimensional space about the Z
axis. The axis of rotation is always the z axis. Each quadric routine has a sweep parameter,
specifying the

angular extent to which the quadric is swept about z axis. Sweeping a quadric byless than 360
degrees leaves an open surface.
Quadrics

Many common shapes can be modeled with quadrics. Although it is possible to convert quadrics
to patches, they are defined as primitives because special- purpose rendering programs render
them directly and because their surface parameters are not necessarily preserved if they are
converted to patches.
Quadric primitives are particularly useful in solid and molecular modelingapplications.
All the following quadrics are rotationally symmetric about the z axis. In all thequadrics u and v are
assumed to run from 0 to 1. These primitives all define
a bounded region on a quadric surface. It is not possible to define
infinite quadrics. Note that each quadric is defined relative to the origin of the object coordinate
657
system. To position them at another point or with their symmetry axis in another direction requires
the use a modeling transformation.
The geometric normal to the surface points ``outward'' from the z-axis, if
the current orientation matches the orientation of the current transformation and"inward" if they
don't match. The sense of a quadric can be reversed by giving negative parameters. For example,
giving a negative thetamax parameter in any of the following definitions will turn the quadric inside-
out.
Each quadric has a parameterlist. This is a list of token-array pairs where each token is one of the
standard geometric primitive variables or a variable which has been defined with RiDeclare.
Position variables should not be given with [Link] angular arguments to these functions are
given in degrees. The trigonometric functions used in their definitions are assumed to also accept
angles in degrees.
RiSphere( radius, zmin, zmax, thetamax, parameterlist )

RtFloat radius;
RtFloat zmin, zmax;

RtFloat thetamax;
Requests a sphere defined by the following equations:

658
Note that if zmin > -radius or zmax < radius, the bottom or top of the sphere is
open, and that if thetamax is not equal to 360 degrees, the sides are also open.

RIB BINDING

Sphere radius zmin zmax thetamax parameterlist

Sphere [radius zmin zmax thetamax] parameterlist

EXAMPLE

RiSphere(0.5, 0.0, 0.5, 360.0, RI_NULL);

RiCone( height, radius, thetamax, parameterlist )


RtFloat height;
RtFloat radius;

RtFloat thetamax;

Requests a cone defined by the following equations:

Note that the bottom of the cone is open, and if thetamax is not equal to 360degrees, the sides are
open.
RIB BINDING

Cone height radius thetamax parameterlist


Cone [height radius thetamax] parameterlistEXAMPLE

RtColor four_colors[4];

RiCone(0.5, 0.5, 270.0, "Cs", (RtPointer)four_colors, RI_NULL);

RiCylinder( radius, zmin, zmax, thetamax, parameterlist )


RtFloat radius;

RtFloat zmin, zmax;


RtFloat thetamax;

Requests a cylinder defined by the following equations:

Note that the cylinder is open at the top and bottom, and if thetamax is not equalto 360 degrees,
the sides also are open.

RIB BINDING
Cylinder radius zmin zmax thetamax parameterlist

Cylinder [radius zmin zmax thetamax] parameterlist


Bezier Curves
659
Bezier curve is discovered by the French engineer Pierre Bézier. These curves canbe generated
under the control of other points. Approximate tangents by using control points are used to
generate curve. The Bezier curve can be represented mathematically as −

Where pipi is the set of points and Bni(t)Bin(t) represents the Bernsteinpolynomials which are given
by −

Where n is the polynomial degree, i is the index, and t is the variable.


The simplest Bézier curve is the straight line from the point P0P0 to P1P1. A quadratic Bezier curve
is determined by three control points. A cubic Bezier curveis determined by four control points.

Properties of Bezier Curves


Bezier curves have the following properties −

• They generally follow the shape of the control polygon, which consists ofthe segments joining
the control points.
• They always pass through the first and last control points.
• They are contained in the convex hull of their defining control points.
• The degree of the polynomial defining the curve segment is one less that the number of
defining polygon point. Therefore, for 4 control points, thedegree of the polynomial is 3, i.e.
cubic polynomial.
• A Bezier curve generally follows the shape of the defining polygon.
• The direction of the tangent vector at the end points is same as that of thevector determined
by first and last segments.
• The convex hull property for a Bezier curve ensures that the polynomialsmoothly follows the
control points.

660
• No straight line intersects a Bezier curve more times than it intersects itscontrol polygon.
• They are invariant under an affine transformation.

• Bezier curves exhibit global control means moving a control point alters theshape of the whole
curve.
• A given Bezier curve can be subdivided at a point t=t0 into two Bezier segments which join
together at the point corresponding to the parametervalue t=t0.

B-Spline Curves
The Bezier-curve produced by the Bernstein basis function has limited flexibility.

• First, the number of specified polygon vertices fixes the order of theresulting polynomial which
defines the curve.
• The second limiting characteristic is that the value of the blending functionis nonzero for all
parameter values over the entire curve.
The B-spline basis contains the Bernstein basis as the special case. The B-splinebasis is non-
global.
A B-spline curve is defined as a linear combination of control points Pi and B-spline basis
function Ni,Ni, k tt given by

Where,

661
Properties of B-spline Curve
B-spline curves have the following properties −

• The sum of the B-spline basis functions for any parameter value is 1.
• Each basis function is positive or zero for all parameter values.
• Each basis function has precisely one maximum value, except for k=1.
• The maximum order of the curve is equal to the number of vertices ofdefining polygon.
• The degree of B-spline polynomial is independent on the number ofvertices of defining polygon.
• B-spline allows the local control over the curve surface because each vertexaffects the shape
of a curve only over a range of parameter values where itsassociated basis function is nonzero.
• The curve exhibits the variation diminishing property.
• The curve generally follows the shape of defining polygon.
• Any affine transformation can be applied to the curve by applying it to thevertices of defining
polygon.
• The curve line within the convex hull of its defining polygon.

Bezier and B-spline SurfacesBezier Surfaces.

Like the Bezier curves, the Bezier surfaces use the Bernstein polynomials as blending functions.
We now have the control points being points on a design net,which is again a rectangular mesh
spread over area of interest. The x and y coordinates of the control points are fixed and the shape
of the surface varies as the control points are moved up or down. The figure below shows a Bezier
surface with an associated control net of 3 points by 4 points. The values of the points are stored
in an array B(4,3) and the blending functions are obtained fromthe equations of the Bezier curves.

662
Bezier Surface and Control Net
Thus, the three point Bezier curve is given by :

B(v) = (1-v)2B(I,1) + 2v(1-v)B(I,2) + v2B(I,3)

or
B(v) = b(20)(v) B(I,1) + b(21)(v) B(I,2) + b(22)(v) B(I,3)

and the 4-point Bezier curve needed in the u-direction has the form: B(u) = (1-u)3B(1,J) + 3u(1-

u)2B(2,J) + 3u2(1-u)B(3,J) + u3B(4,J)

or B(u) = b{30}(u)B(1,J) + b{31}(u) B(2,J) + b{32}(u) B(3,J) + b{33}(u) B(4,J)


These must be combined together in the matrix equation to calculate any pointon the surface. The
equation of a point on the Bezier surface is given by:
r(u,v) = [b{30}(u) b{31}(u) b{32}(u) b{33}(u)] B(1,1)B(1,2) B(1,3) b{20}(v)
B(2,1) B(2,2) B(2,3) b{21}(v)

B(3,1) B(3,2) B(3,3) b{22}(v)B(4,1) B(4,2) B(4,3)

To obtain the equation of one of the edge-curves, e.g. when u=0, we mustsubstitute in the matrix
equation:

r(0,v) = B(1,1) B(1,2) B(1,3) (1-v)(1-v)


2v(1-v)

v*v
which becomes r(0,v) = (1-v)(1-v)B(1,1) + 2v(1-v)B(1,2) + v*vB(1,3) and similarly for the other edge
curves. This form of the Bezier curve assumes a rectangular mesh with m+1 points in the one
direction and n+1 points in the other. It requiresthe edge curves defining the patches to be coplanar
and does not provide local control within a patch. A surface may be made up of several Bezier
patches and, as for the curves, if we require the tangents to be continuous across the joins, then
the sets of control points across the curves must be not only coplanar but also collinear.
The Proceedings of the Royal Society, Series A, for February 1971 contained the papers from a
meeting on `Computer Aids in Mechanical Engineering Design'. Thisincluded a paper by Bezier on
his `Unisurf' package used by the Renault car company to design their car bodies. Although it is not
obvious from the paper, this was the earliest use of Bezier surfaces, which were invented for this
package. Another paper described the `Multiobject' package by Armit, which used the same
equations. The paper by Sabin, discribing the `Numerical Master Geometry' in use at the British
Aircraft Corporation, shows the extensive use of Bicubic Surface tiles in their work because they
are particularly concerned to get the extrasmoothness of functions which can only be guaranteed
by bicubic or higher-orderpatches.
This volume of the proceedings gives an interesting insight into the way that these packages were
viewed at the time. In some respects, things have changed little since then. They describe a
situation where many users had their own two orthree C.A.D. programs to use, and there was very
663
little guidance on the best choice for a newcomer to the field. Nowadays, there is a bewildering
variety of large and comprehensive packages for C.A.D. but the newcomer still has little

guidance amongst an even larger choice of software. Unfortunately the cost of amistake is very
much larger, since these packages are now big business.
B-Spline Surfaces.

The use of B-Spline surfaces is necessary in some CAD applications to give localcontrol of the
shape. The equation of this surface is given by
Q(u,v) = sum{i=0 to m} sum{j=0 to n} B(i+1,j+1) N{i,k}(u) M{j,l}(v) In the x-direction, x(i) are the

elements of the k-knot vector and

N{i,1}(u) = 1 if x(i) <= u <= x(i+1)


= 0 otherwise

and
N{i.k}(u) = (u-x(i)) * N{i,k-1}(u) + (x(i+k)-u) * N{i+1,k-1}(u)

(x(i+k-1)-x(i)) (x(i+k)-x(i+1))

In the y-direction, the y(j) are elements of the l-knot vector and we have similarexpressions for
M{j,1}(v) and M{j,l}(v).
This simple version of the B-Spline expects a rectangular net and requires all polygons in the one-
direction to have the same degree of multiplicity (i.e. to use one knot-vector for all lines across the
net). We can obtain greater flexibility by relaxing these conditions, but at the expense of greater
complexity. These curvesare widely used in many CAD packages.

Illumination model
Illumination model, also known as Shading model or Lightning model, is used to calculate the
intensity of light that is reflected at a given point on surface. Thereare three factors on which
lightning effect depends on:
1. Light Source :
Light source is the light emitting source. There are three types of lightsources:
1. Point Sources – The source that emit rays in all directions (A bulb in aroom).
2. Parallel Sources – Can be considered as a point source which is farfrom the surface (The sun).
3. Distributed Sources – Rays originate from a finite area (A tubelight).

Their position, electromagnetic spectrum and shape determine the lightningeffect.


2. Surface :
When light falls on a surface part of it is reflected and part of it is [Link] the surface
structure decides the amount of reflection and absorptionof light. The position of the surface
and positions of all the nearby surfaces also determine the lightning effect.
3. Observer :
The observer’s position and sensor spectrum sensitivities also affect thelightning effect.
664
1. Ambient Illumination :
Assume We are standing on a road, facing a building with glass exterior and sun rays are falling
on that building reflecting back fromit and the falling on the object under observation. This
would
be Ambient Illumination. In simple words, Ambient Illumination isthe one where source of light
is indirect.

The reflected intensity Iamb of any point on the surface is:

2. Diffuse Reflection :
Diffuse reflection occurs on the surfaces which are rough or grainy. In this reflection the
brightness of a point depends upon the angle made by the lightsource and the surface.

The reflected intensity Idiff of a point on the surface is:

665
3. Specular Reflection :
When light falls on any shiny or glossy surface most of it is reflected back, suchreflection is
known as Specular Reflection.
Phong Model is an empirical model for Specular Reflection which provides us withthe formula
for calculation the reflected intensity Ispec:

Polygen Rending Methods

666
Image of Flow Chart of polygen rending methods

Gouraud shading
This Intensity-Interpolation scheme, developed by Gouraud and usually referred to as Gouraud
Shading, renders a polygon surface by linear interpolating intensity value across the surface.
Intensity values for each polygon are coordinate with the value of adjacent polygons along the
common edges, thus eliminating the intensity discontinuities that can occur in flat shading.
Each polygon surface is rendered with Gouraud Shading by performing thefollowing calculations:
1. Determining the average unit normal vector at each polygon vertex.
2. Apply an illumination model to each vertex to determine the vertexintensity.
3. Linear interpolate the vertex intensities over the surface of the polygon.

At each polygon vertex, we obtain a normal vector by averaging the surfacenormals of all polygons
staring that vertex as shown in fig:

Thus, for any vertex position V, we acquire the unit vertex normal
with the
calculation

Once we have the vertex normals, we can determine the intensity at the
vertices
from a lighting model.

Following figures demonstrate the next step: Interpolating intensities


667
along the polygon edges. For each scan line, the intensities at the
intersection of the scan line with a polygon edge are linearly
obtaining the intensities at point 4 is to interpolate between intensities I1 and I2 using only the
vertical displacement of the scan line.

Similarly, the intensity at the right intersection of this scan line (point 5) is interpolated from the
intensity values at vertices 2 and 3. Once these bounding intensities are established for a scan line,
an interior point (such as point P in theprevious fig) is interpolated from the bounding intensities at
point 4 and 5 as

668
Incremental calculations are used to obtain successive edge intensity values between scan lines
and to obtain successive intensities along a scan line as shownin fig:

If the intensity at edge position (x, y) is interpolated as

Then we can obtain the intensity along this edge for the next scan line, Y-1 as

Similar calculations are used to obtain intensities at successive horizontal pixel


positions along each scan line.

When surfaces are to be rendered in color, the intensities of each color

component is calculated at the vertices. Gouraud Shading can be connected witha hidden-surface
algorithm to fill in the visible polygons along each scan-line. An example of an object-shaded with
the Gouraud method appears in the followingfigure:

669
Gouraud Shading discards the intensity discontinuities associated with the constant-shading
model, but it has some other deficiencies. Highlights on the surface are sometimes displayed with
anomalous shapes, and the linear intensity interpolation can cause bright or dark intensity streaks,
called Match bands, to appear on the surface. These effects can be decreased by dividing the
surface intoa higher number of polygon faces or by using other methods, such as Phong shading,
that requires more calculations.

Viewing-Pipeline
The viewing-pipeline in 3 dimensions is almost the same as the 2D-viewing- pipeline. Only after the
definition of the viewing direction and orientation (i.e., ofthe camera) an additional projection step
is done, which is the reduction of 3D- data onto a projection plane:

670
This projection step can be arbitrarily complex, depending on which 3D-viewingconcepts should be
used.

Viewing-Coordinates
Similar to photography there are certain degrees of freedom when specifying thecamera:
1. Camera position in space
2. Viewing direction from this position
3. Orientation of the camera (view-up vector)
4. Size of the display window (corresponds to the focal length of a photo-camera)
With these parameters the camera-coordinate system is defined (viewingcoordinates). Usually the
xy-plane of
this viewing-coordinate system is orthogonal to the main viewing direction andthe viewing direction
is in the direction of the negative z-axis.
Based on the camera position the usual way to define the viewing-coordinatesystem is:

In animations the camera-definition is often automatically calculated according to certain


conditions, e.g. when the camera moves around an object or in flight- simulations, such that desired
effects can be achieved in an uncomplicated way.
To convert world-coordinates to viewing-coordinates a series of simple transformations is needed:
mainly a translation of the coordinate origins onto each other and afterwards 3 rotations, such that
the coordinate-axes also coincide (two rotations for the first axis, one for the second axis, and the
third axisis already correct then). Of course, all these
transformations can be merged by multiplication into one matrix, which looksabout like this:

MWC,VC = Rz· Ry· Rx· T


Projection
It is the process of converting a 3D object into a 2D object. It is also defined as mapping or
transformation of the object in projection plane or view plane. Theview plane is displayed surface.

671
1. Choose a camera position (also called eye-point, or view-point).

2. Choose a viewing direction = Choose the z– direction of the viewing-


coordinates.

3. Choose a direction „upwards“. From this, the x-axis and y-axis can be
calculated: the image-plane is orthogonal to the viewing direction. The parallel
projection of the „view-up vector“ onto this image plane defines the y-axis of
the viewing coordinates.

4. Calculate the x-axis as vector-product of the z- and y-axis.

5. The distance of the image-plane from the eye-point defines the viewing angle,
which is the size of the scene to be displayed.

672
Perspective Projection
In perspective projection farther away object from the viewer, small it appears. This property of
projection gives an idea about depth. The artist use perspective projection from drawing three-
dimensional scenes.

Two main characteristics of perspective are vanishing points and perspective foreshortening. Due
to foreshortening object and lengths appear smaller from thecenter of projection. More we increase

673
the distance from the center of projection,smaller will be the object appear.

Vanishing Point
It is the point where all lines will appear to meet. There can be one point, twopoint, and three point
perspectives.
One Point: There is only one vanishing point as shown in fig (a)
Two Points: There are two vanishing points. One is the x-direction and other inthe y -direction as
shown in fig (b)

Three Points: There are three vanishing points. One is x second in y and third intwo directions.
In Perspective projection lines of projection do not remain parallel. The lines converge at a single
point called a center of projection. The projected image on the screen is obtained by points of
intersection of converging lines with the planeof the screen. The image on the screen is seen as of
viewer's eye were located at the centre of projection, lines of projection would correspond to path
travel by light beam originating from object.

Important terms related to perspective


1. View plane: It is an area of world coordinate system which is projected intoviewing plane.
2. Center of Projection: It is the location of the eye on which projected lightrays converge.
3. Projectors: It is also called a projection vector. These are rays start from theobject scene and
are used to create an image of the object on viewing or view plane.

Anomalies in Perspective Projection


It introduces several anomalies due to these object shape and appearance getsaffected.
1. Perspective foreshortening: The size of the object will be small of itsdistance from the center

674
of projection increases.
2. Vanishing Point: All lines appear to meet at some point in the view plane.
3. Distortion of Lines: A range lies in front of the viewer to back of viewer isappearing to six
rollers.

Foreshortening of the z-axis in fig (a) produces one vanishing point, P1. Foreshortening the x and z-
axis results in two vanishing points in fig (b). Adding ay-axis foreshortening in fig (c) adds vanishing
point along the negative y-axis.

Parallel Projection
Parallel Projection use to display picture in its true shape and size. When projectors are
perpendicular to view plane then is called orthographic projection.

The parallel projection is formed by extending parallel lines from each vertex on the object until
they intersect the plane of the screen. The point of intersection isthe projection of vertex.
Parallel projections are used by architects and engineers for creating working drawing of the object,
675
for complete representations require two or more views ofan object using different planes.

1. Isometric Projection: All projectors make equal angles generally angle is of30°.
2. Dimetric: In these two projectors have equal angles. With respect to twoprinciple axis.
3. Trimetric: The direction of projection makes unequal angle with theirprinciple axis.
4. Cavalier: All lines perpendicular to the projection plane are projected withno change in length.

676
5. Cabinet: All lines perpendicular to the projection plane are projected toone
half of their length. These give a realistic appearance of object.

677
678
679
Frames of Reference
Computers will do exactly what We tell them to do. The question is about understanding what do
we actually want to do and explaining that to a computerwith enough rigor. For example we might
want the computer to render a square,but this sentence is way too abstract for the computer to
understand. More rigorous way to think about this is that we want lines between pairs of
vertices (1,1), (−1,1), (−1,−1) and (1,−1), that are represented in the world space,to be drawn in a
400×300 area of the screen so that there is a linear mapping:

680
[−4,4]×[−3,3]→[0,400]×[0,300].
This will already specify which pixels to color for our vertices. For example the vertex (1,1)(1,1)
would be drawn on the pixel located at coordinates (250,200).Here We might notice a couple of
problematic things:
➢ Our geometry will be mirrored in the y direction, because in our worldspace y will point up, but
in the screen space, y will point down.
➢ We are mapping from 2D to 2D. How to do it from 3D to 2D? What if weare not looking from
the positive z direction?
On the other hand we might notice that with this kind of mapping our scene would always show the
same amount of the scene if the resolutionschanges. Although we might want to change that also.
There are actually many frames of references and transformations between ourvertices and what
we see on the screen. look at them one at a time.

World Space

First, our vertices are usually defined in the object space. We will try to center ourobject around
some object origin (Object) that will serve as the scaling and rotation fixed point. Our object is
located somewhere in the world space though, so we will use modelling transformations to
represent the vertices with world space coordinates. Imagine if there are multiple triangles, they
can not all be located in the world space origin, they are probably scattered all around the world
space, and thus each have distinct world space coordinates. Although they might have the same
object space (local) coordinates.

Camera Space

681
Secondly, there is a camera somewhere in the world space. This camera has its own coordinates
in the world space and is transformed just like any other object /vertex. Our goal here is to position
everything into camera space so that camera and world frames match. In other words, transform
everything so that camera willbe located at the world origin and the axes will be aligned.
Usually there is a function called lookAt(), where We can say where in the world is our camera
located, which is the up direction and to what point is it pointed (is looking) at. This is a convenience
function that underneath will construct the corresponding matrix that will do the camera
transformation in this step. see, how this can be done.
We know:

➢ Camera's position in world space. Call it pp.


➢ Camera's up-vector. Call it uu.
➢ Camera's looking direction. Call it ll.

Well, the first step would be to align the origins. So we want to move all ourobjects so that the
camera would be in the world origin. We had a
translation pp that moved camera away from the origin, so the reverse would bejust −p.

So the first transformations would be:

Next we need to align the axes. Now, the vector ll shows the direction we are facing, but because
the z-axis should be in the negative direction, we will reverse it: w=−l. We assume that vectors uu
and ww are orthogonal to each other and of unit length. We still need one orthogonal vector, the
right vector, in order to have

the camera basis. We could use the Gram-Schmidt process here, but a more simpler way to find an
orthogonal unit vector, given already two, would be to usethe cross product of vectors. So v=w×u.
Notice that the cross product is not commutative and will follow the right-hand rule. The vector vv
will emerge
from the plane defined by ww and uu in the direction where the angle
from w to u will be counter-clockwise. If We exchange ww and uu in the crossproduct, then the
result will point to the opposite direction.
Now we have the vectors u, v and w that are the basis of the camera's frame ofreference. The
transformation that would transform the camera basis from the world basis (ignoring the
translation for now) would be:

682
Remember that we can look at the columns of the matrix to determine how the basis would
transform. But that would be the transformation which would transform the camera space
(coordinates) to the world space. We need to find a transformation to get from world space to
camera space. Or in other words, transform the camera basis to be the current world space basis.
We might remember from algebra that the inverse of an orthogonal matrix is the transposeof it. All
rotation matrices are orthogonal matrices and a multiplication of two rotation matrices is a rotation
matrix. Our camera basis will differ from the worldbasis only by a number of rotations. So in order
to find out how to transform the world so that the camera basis would be aligned with the world
basis, we only need to take the inverse of those rotation. That is the inverse of the matrix we just
found. The inverse is currently just the transpose of it.

The total view transformation would be then:

In some sources the view transformation is called the inverse of the camera transformation. There
the camera transformation is the transformation that transforms the actual camera as an object.
In other sources the camera transformation is the transformation that transforms all the vertices
into the camera space. One should explain what is actually meant when using those [Link] term
view transformation (the view matrix) is generally more common.

Clip Space
Third step is to construct the clip space. This is the space that should be seen fromthe camera. In
our illustration here there is a 2D projection of it. In 3D We will also have a top and a bottom plane.
683
Based on the transformation We might have to specify those plains directly or, as is the case with
perspective projection, We can specify a field of view parameter that will calculate those itself.
Everything outside this clip space is clipped, i.e. ignored in rendering. It might depend on what kind
of clipping techniques are in use. For example if a line crosses the clip space, then it might be
segmented: another vertex is created at the border of the clip space. Objects that are wholly outside
of the clip space, areignored. This is one place where we want to be able to determine the rough
locations of our objects quickly. Later we will see different methods (e.g. binary space partitioning,
bounding volume hierarchy) that help to determine that.
Mathematically We can think that the equations of the planes are constructed and intersections
with other planes (ones defined by all of the triangles in the scene) are checked for. Of course, if
we are only interested about vertices, thenwe can put every vertex in the plane equation and see
which side of the plane avertex lies.
We will look this and the next step in more detail when talking about differentprojections.

Canonical View Volume

Fourth step is to transform everything so that the clip space will form a canonicalview volume. This
canonical view volume is a cube in the
coordinates [−1,1]×[−1,1]×[−1,1]. As we can see from the previous illustration wehad kind of a weird
shape for the clip space. This shape is a frustum of a pyramid in the case of perspective projection.
In computer graphics we call it the view frustum. Transforming that into a cube will transform the
whole space in a very affecting way. This is the part where we leave the world of affine
transformationsand perform a perspective projection transformation. It is actually quite simple, we
will just put a non-zero value in the third column of the last row of our transformation matrix. As we
remember, affine transformations needed the last row to be (0,0,0,1), but for perspective
transformation we will have (0,0,p,0).
Depending on how an API is implemented, we might have p=1 or p=−1 or evensomething else. After
this transformation, there is a need for the perspective division, because the value of w will usually

684
no longer be 1. Remember that in homogeneous coordinates (x,y,z,w)=(x/w,y/w,z/w).
As We can see, coordinates will be divided based on the value of w, which will depend on the value
of z. This actually causes the objects further away to be projected smaller then objects that are
closer to the camera - the same way wesee the world.

Screen Space

Final step is to project the canonical view volume into screen space. Our screen has usually
mapped the coordinates of pixels so that (0,0)(0,0) is in the top-left corner and positive directions
are to the right and down. Depending on the actually screen resolution (or window / viewport size
if we are not rendering full-screen), we will have to map the canonical view volume coordinates to
different ranges. In either way, this will just be a linear mapping from the
ranges [−1,1]×[−1,1]→[0,width]×[0,height] like we saw in the beginning.
This mapping is called the viewport transformation and the matrix that does it is quite simple. This
step is usually done automatically. For the proportional linear mapping from one range into another
we just need to scale the initial range to beof the same length as the final range, and then translate
it so that they cover eachother.
685
Notice that the z value is brought along here. This is useful in order to later determine which objects
are in front of other objects. Also the y values still seemto be reversed. This will be handled later by
OpenGL, currently we just assume that the (0,0) in the screen space is at the bottom-left corner and
the positive directions are up and right. Also the z value will later be normalized to a
range [0,1].

1) What is the 16-bit compiler allowable range for integer constants?


a) -3.4e38 to 3.4e38
b) -32767 to 32768
c) -32668 to 32667
d) -32768 to 32767
Answer: (d) -32768 to 32767
Explanation: In a 16-bit C compiler, we have 2 bytes to store the value.
• The range for signed integers is -32768 to 32767.
• The range for unsigned integers is 0to 65535.
• The range for unsigned character is 0 to 255.

2) Study the following program:


1. main()
2. {printf("javatpoint");
3. main();}
What will be the output of this program?
a. Wrong statement
b. It will keep on printing javatpoint
c. It will Print javatpoint once
d. None of the these
Answer: (b) It will keep on printing javatpoint
Explanation: In this program, the main function will call itself again and again. Therefore, it will
continue to print javatpoint.

3) What is required in each C program?


a. The program must have at least one function.
b. The program does not require any function.
c. Input data
d. Output data
Answer: (a) The program must have at least one function.
Explanation: Any C program has at least one function, and even the most trivial programs can
specify additional functions. A function is a piece of code. In other words, it works like a sub-
program.

4) What will this program print?


1. main() 2. {
3. int i = 2;

686
4. {
5. int i = 4, j = 5;
6. printf("%d %d", i, j); 7. }
8. printf("%d %d", i, j); 9. }
a. 4525
b. 2525
c. 4545
d. None of the these
Answer: (a) 4525
Explanation: In this program, it will first print the inner value of the function and then print the outer
value of the function.
5) Which of the following comment is correct when a macro definition includes arguments?
a. The opening parenthesis should immediately follow the macro name.
b. There should be at least one blank between the macro name and the opening parenthesis.
c. There should be only one blank between the macro name and the opening parenthesis.
d. All the above comments are correct.
Answer: (a) The opening parenthesis should immediately follow the macro name.
Explanation: None

6) What is a lint?
a. C compiler
b. Interactive debugger
c. Analyzing tool
d. C interpreter
Answer: (c) Analyzing tool
Explanation: Lint is an analyzing tool that analyzes the source code by suspicious
constructions, stylistic errors, bugs, and flag programming errors. Lint is a compiler-like tool in
which it parses the source files of C programming. It checks the syntactic accuracy of these files.

7) What is the output of this statement "printf("%d", (a++))"?


a. The value of (a + 1)
b. The current value of a
c. Error message
d. Garbage
Answer: (b) The current value of "a".
Explanation: None

8) Study the following program:


1. main() 2. {
3. char x [10], *ptr = x;
4. scanf ("%s", x);
5. change(&x[4]); 6. }
7. change(char a[]) 8. {
9. puts(a);
10. }
If abcdefg is the input, the output will be
a. abcd
b. abc
687
c. efg
d. Garbage Answer: (c) efg
Explanation: None

9) Study the following program:


1. main() 2. {
3. int a = 1, b = 2, c = 3:
4. printf("%d", a + = (a + = 3, 5, a)) 5. }
What will be the output of this program?
a. 6
b. 9
c. 12
d. 8
Answer: (d) 8
Explanation: It is an effect of the comma operator.
a + = (a + = 3, 5, a)
It first evaluates to "a + = 3" i.e. a = a + 3 then evaluate 5 and then evaluate "a".
Therefore, we will get the output is 4. Then,
a+=4
It gives 8 as the output.

10) What does this declaration mean?


1. int x : 4;
a. X is a four-digit integer.
b. X cannot be greater than a four-digit integer.
c. X is a four-bit integer.
d. None of the these Hide Answer Workspace
Answer: (c) X is a four-bit integer.
Explanation: This means, "X" is a four bit integer.

11) Why is a macro used in place of a function?


a. It reduces execution time.
b. It reduces code size.
c. It increases execution time.
d. It increases code size.
Answer: (d) It reduces code size.
Explanation: Macro is used in place of a function because it reduces code size, and very efficient.

12) In the C language, the constant is defined .


a. Before main
b. After main
c. Anywhere, but starting on a new line.
d. None of the these.
Answer: (c) Anywhere but starting on a new line.
Explanation: In the C language, the constant is defined anywhere, but starting on a new line.

13) How many times will the following loop execute?


1. for(j = 1; j <= 10; j = j-1)
688
a. Forever
b. Never
c. 0
d. 1
Answer: (a) Forever
Explanation: None

14) A pointer is a memory address. Suppose the pointer variable has p address 1000, and that p is
declared to have type int*, and an int is 4 bytes long. What address is represented by expression p
+ 2?
a. 1002
b. 1004
c. 1006
d. 1008
Answer: (d) 1008
Explanation: None

15) What is the result after execution of thefollowing code if a is 10, b is 5, and c is 10?
1. If ((a > b) && (a <= c))
2. a = a + 1;
3. else
4. c = c+1; a. a = 10, c = 10
b. a = 11, c = 10
c. a = 10, c = 11
d. a = 11, c = 11
Answer: (b) a = 11, c = 10
Explanation: None

16) Which one of the following is a loop construct that will always be executed once?
a. for
b. while
c. switch
d. do while
Answer: (d) do while
Explanation: The body of a loop is often executed at least once during the do-whileloop. Once the
body is performed, the condition is tested. If the condition is valid, it will execute the body of a loop;
otherwise, control is transferred out of the loop.

17) Which of the following best describes the ordering of destructor calls for stack- resident objects
in a routine?
a. The first object created is the first object destroyed; last created is last destroyed.
b. The first object destroyed is the last object destroyed; last created is first destroyed.
c. Objects are destroyed in the order they appear in memory, the object with the lowest memory
address is destroyed first.
d. The order is undefined and may vary from compiler to compiler.
Answer: (b) The first object destroyed is the last object destroyed; last created is first destroyed.
Explanation: None

689
18) How many characters can a string hold when declared as follows?
1. char name[20]:
a. 18
b. 19
c. 20
d. None of the these Answer: (b) 20
Explanation: None

19) Directives are translated by the


a. Pre-processor
b. Compiler
c. Linker
d. Editor
Answer: (a) Pre-processor
Explanation: In C language, the pre- processor is a macro processor that is dynamically used by the
C programmer to modify the program before it is properly compiled (Before construction, pro-
processor directives are implemented).

20) How many bytes does "int = D" use?


a. 0
b. 1
c. 2 or 4
d. 10
Answer: (c) 2 or 4
Explanation: The int type takes 2 or 4 bytes.

21) What feature makes C++ so powerful?


a. Easy implementation
b. Reusing the old code
c. Easy memory management
d. All of the above Answer: (d) All of the above Explanation: None

22) Which of the following will copy the null-terminated string that is in array src into array dest?
a. dest = src;
b. dest == src;
c. strcpy(dest, src);
d. strcpy(src, dest);
Answer: (c) strcpy(dest, src)
Explanation: strcpy is a string function that is used to copy the string between the two files.
strcpy(destination, source)

23) In the statement "COUT << "javatpoint"<< end1;", end1 is a .


a. Extractor
b. Inserter
c. Manipulator
d. Terminator
Answer: (c) Manipulator
Explanation: End1 is an I/O manipulator that takes effect in printing a new line '\ n' character and
690
then flushing the output stream.

24) Each instance of a class has a different set of


a. Class interfaces
b. Methods
c. Return types
d. Attribute values
Answer: (d) Attribute values
Explanation: Each instance of the class has a different set of attribute values

25) How many instances of a class can bedeclared?


a. 1
b. 10
c. As per required
d. None of the these
Answer: (c) As per required
Explanation: You can always declare multiple instances of a class, as per required. Each object will
hold its own individual inner variables (unless they are static, in which case they are shared).

26) What will the result of num variable after execution of the following statements?
1. int num = 58;2. num % = 11;
a. 3
b. 5
c. 8
d. 11
Answer: (a) 3
Explanation: num = 58
num % = 11 num = num % 11 num = 58 % 11
num = 3

27) What is the maximum number of characters that can be held in the string variable char address
line [40]?
a. 38
b. 39
c. 40
d. 41
Answer: (b) 39
Explanation: None

28) What will the result of num1 variable after execution of the following statements?
1. int j = 1, num1 = 4; 2. while (++j <= 10) 3. {
4. num1++;
5. }
a. 11

b. 12

691
c. 13

d. 14
Answer: (c) 13
Explanation: None

29) What will the result of len variable after execution of the following statements?
1. int len;
2. char str1[] = {"39 march road"};
3. len = strlen(str1);
a. 11
b. 12
c. 13
d. 14
Answer: (c) 13
Explanation: strlen is a string function that counts the word and also count the space in the string.
(39 march road) = 13

30) Study the following statement


1. #include <stdio.h>
2. int main()
3. {
4. int *ptr, a = 10;
5. ptr = &a;
6. *ptr += 1;
7. printf("%d,%d/n", *ptr, a); 8. }
What will be the output?
a. 10, 10
b. 10, 11
c. 11, 10
d. 11, 11
Answer: (d) 11, 11
Explanation: None

31) Given the following statement, what will be displayed on the screen?
1. int * aPtr;
2. *aPtr = 100;
3. cout << *aPtr + 2;a. 100
b. 102
c. 104
d. 108
Answer: (b) 102
Explanation: aPtr is an integer pointer which value is 100.
= *aPtr + 2
= 100 + 2
= 102

692
32) Give the following declarations and an assignment statement. Which one is equivalent to the
expression str [4]?
1. char str[80];
2. char * p;
3. p = str;
a. p + 4
b. *p + 4
c. *(p + 4)
d. p [3] Answer: (c) *(p + 4)
Explanation: None

33) Which one is the correct description for the variable balance declared below?
1. int ** balance;
a. Balance is a point to an integer
b. Balance is a pointer to a pointer to an integer
c. Balance is a pointer to a pointer to a pointer to an integer
d. Balance is an array of integer
Answer: (b) Balance is a pointer to a pointer to an integer
Explanation: This code description states that the remainder is a pointer to a pointer to an integer.

34) A class D is derived from a class B, b is an object of class B, d is an object of class D, and pb is
a pointer to class B object. Which of the following assignment statement is not valid?
a. d = d;
b. b = d;
c. d = b;
d. *pb = d:
Answer: (c) d = b;
Explanation: A class D is derived from a class B, so "d" is not equal to b.

35) Which of the following statement is not true?


a. A pointer to an int and a pointer to a double are of the same size.
b. A pointer must point to a data item on the heap (free store).
c. A pointer can be reassigned to point to another data item.
d. A pointer can point to an array.
Answer: (b) A pointer must point to a data item on the heap (free store).
Explanation: None

36) Which of the following SLT template class is a container adaptor class?
a. Stack
b. List
c. Deque
d. Vector
Answer: (a) Stack
Explanation: Container Adaptors is the subset of Containers that provides many types interface for
sequential containers, such as stack and queue.

37) What kinds of iterators can be used with vectors?


a. Forward iterator
693
b. Bi-directional iterator
c. Random access iterator
d. All of the above
Answer: (d) All of the above
Explanation: An iteration is like a pointer, indicating an element inside the container. All these types
of iterations can be used with vectors.

38) Let p1 be an integer pointer with a current value of 2000. What is the content of p1 after the
expression p1++ has been evaluated?
a. 2001
b. 2002
c. 2004
d. 2008
Answer: (c) 2004
Explanation: The size of one pointer integer is 4 bytes. The current value of p1 is 2000.
p1++ = p1 + 1 p1++ = 2004

39) Let p1 and p2 be integer pointers. Which one is a syntactically wrong statement?
a. p1 = p1 + p2;
b. p1 = p1 - 9;
c. p2 = p2 + 9;
d. cout << p1 - p2; Answer: (a) p1 = p1 + p2;
Explanation: None

40) Suppose that cPtr is a character pointer, and its current content is 300. What will be the new
value in cPtr after the following assignment?
1. cPtr = cPtr + 5; a. 305
b. 310
c. 320
d. 340
Hide Answer Workspace Answer: (a) 305 Explanation: cPtr = cPtr + 5 cPtr = 300 + 5cPtr = 305

41) Which is valid expression in c language?


a. int my_num = 100,000;
b. int my_num = 100000;
c. int my num = 1000;
d. int my num == 10000;
Answer: (b) int my_num = 100000;
Explanation: Special symbol, Space, and comma cannot be used in a variable name in c language.

42) If addition had higher precedence than multiplication, then the value of the expression (1 + 2 * 3
+ 4 * 5) would be which of the following?
a. 27
b. 47
c. 69
d. 105
Hide Answer Workspace
Answer: (d) 105
694
Explanation: (1 + 2 * 3 + 4 * 5)
= (1 + 2) * (3 + 4) * 5
=3*7*5
= 105

43) What will be the output of this program?


1. int main() 2. {
3. int a=10, b=20;
4. printf("a=%d b=%d",a,b);
5. a=a+b;
6. b=a-b;
7. a=a-b;
8. printf("a=%d b=%d",a,b);
9. return 0;
10. }
a. a = 20, b = 20
b. a = 10, b = 20
c. a = 20, b = 10
d. a = 10, b = 10
Answer: (c) a = 20, b = 10
Explanation: This program is a swapping program.
a = a + b → a = 10 + 20 → a = 30b = a - b → b = 30 - 20 → B = 10a = a - b → a = 30 - 10 → a = 20

44) The following statements are about EOF. Which of them is true?
a. Its value is defined within stdio.h
b. Its value is implementation dependent
c. Its value can be negative
d. Its value should not equal the integer equivalent of any character
e. All of the these
Answer: (e) All of the these
Explanation: All statements are true

45) What does this statement mean? 1. x - = y + 1;


a. x = x - y + 1
b. x = -x - y - 1
c. x = x + y - 1
d. x = x - y - 1
Answer: (d) x = x - y - 1
Explanation: x - = y + 1x = x - (y + 1)
So, x = x - y – 1

46) Study the following statement


1. for (i = 3; i < 15; i + = 3)
2. {printf ("%d", i); 3. ++i;
4. }
What will be the output? a. 3 6 9 12
b. 3 6 9 12 15
c. 3 7 11
695
d. 3 7 11 15
Answer: (c) 3 7 15
Explanation: None

47) Study the following statement


1. main()
2. {
3. char *s = "Hello,"
4. "World!";
5. printf("%s", s); 6. }
What will be the output?
a. Hello, World!
b. Hello, World!
c. Hello
d. Compile error
Answer: (b) Hello, World!
Explanation: The output of this program is "Hello, World!". This program's output will not appear in
the new line because the \ nescape sequence has not been used in this program.

48) Study the following array definition


1. int num[10] = {3, 3, 3};
Which of the following statement is correct?
a. num[9] is the last element of the array num
b. The value of num[8] is 3
c. The value of num[3] is 3
d. None of the above
Answer: (a) num[9] is the last element of the array num
Explanation: The num[9] is the last element of the array number because the total element in this
array is 10, and the array starts with 0, so the last element of the array is the num[9].

49) What will the output after execution of the following statements?
1. main() 2. {
3. printf ("\\n ab");
4. printf ("\\b si");
5. printf ("\\r ha"); 6. }
a. absiha
b. asiha
c. haasi
d. hai
Answer: (d) hai
Explanation:
• \\n - newline - printf("\\nab"); - Prints 'ab'
• \\b - backspace - printf("\\bsi"); - firstly '\\b' removes 'b' from 'ab ' and then prints 'si'. So, after
execution of printf("\\bsi"); it is 'asi'
• \\r - linefeed - printf("\\rha"); - Now here '\\r' moves the cursor to the start of the current line
and then override 'asi' to 'hai'

50) What will the output after execution of the following statements?
696
1. void main() 2. {
3. int i = 065, j = 65;
4. printf ("%d %d", i, j); 5. }
a. 065 65
b. 53 65
c. 65 65
d. Syntax error
Answer: (b) 53 65
Explanation: This value (065) is an octal value, and it equals to the decimal value 53.

51. Prolog comes under


a) Logic Programming
b) Procedural Programming
c) OOP
d) Functional
Answer: a
Explanation: Prolog stands for Programming in Logic. The options mentioned are the four
categories of programming. Prolog is a type of logic programming.

52. Java is procedural programming.


a) True
b) False
Answer: b
Explanation: The statement is false. Java is a type of object oriented programming language. It
involves solving real-life problems as well.

53. A program that can execute high-level language programs.


a) Compiler
b) Interpreter
c) Sensor
d) Circuitry
Answer: b
Explanation: Interpreter is a program that can execute high-level language programs “directly,”
without first being translated into machine language.

54. Executables might be called


a) native code
b) executable code
c) complex code
d) machine code
Answer: a
Explanation: The executables are sometimes called native code. HLL are translated to Machine
language called the native code.

55. Source program is compiled to an intermediate form called


a) Byte Code
b) Smart code
c) Executable code
697
d) Machine code
Answer: a
Explanation: The Source program is compiled to an intermediate form called byte code. For each
supported platform, write a “virtual machine” emulator that reads byte code and emulates its
execution.

56. is the assembly language for an imaginary architecture.


a) Byte code
b) Machine code
c) Native code
d) Executable code
Answer: a
Explanation: Source program is compiled to an intermediate form – byte code. Byte code is the
assembly language for an imaginary architecture.

57. JIT stands for?


a) Just in time
b) Jump in time
c) Jump in text
d) Jump in terms
Answer: a
Explanation: JIT stands for Just in time. JVMs actually compile each bytecode instruction to native
code the first time it is used.

58. JVM stands for?


a) Java virtual machine
b) Java visual machine
c) JRE virtual machine
d) JRE visual machine
Answer: a
Explanation: JVM stands for Java Virtual Machine. Other related terms are JRE which is java
runtime environment and JDK which is java development kit.

59. A language supported by MS. Net platform.


a) C
b) C++
c) java
d) C#
Answer: d
Explanation: C# is supported by MS. Net platform. JAVA was originally designed for web purposes.

60. Which of the following isn’t a characteristic of High level languages?


a) machine code
b) platform independent
c) interactive execution
d) user-friendly
Answer: a
Explanation: HLL isn’t in machine language. It is converted to machine language for further
698
processing.

61. Which of the following approach help us understand better about Real time examples, say
Vehicle or Employee of an Organisation?
a) Procedural approach
b) Object Oriented approach
c) Both a and b
d) None of the mentioned
Answer: b
Explanation: Object Oriented Programming
supports the concept of class and object which help us understand the real time examples better.
Vehicle is defined to be a class. Car, truck, bike are defined to be objects of the class, Vehicle.

62. Which of the following Paradigm is followed by Object Oriented Language Design?
a) Process-Oriented Model
b) Data Controlling access to code.
c) Both a and b
d) None of the mentioned
Answer: b
Explanation: Object-oriented programming organises a program around its data(that is, objects)
and a set of well-defined interfaces to that data.

63. Which of the following approach is followed by Object Oriented Language during the execution
of a program?
a) Bottom up approach
b) Top down approach
c) Both a and b
d) None of the mentioned
Answer: a
Explanation: Bottom up approach begins with details and moves to higher conceptual level there by
reducing complexity and making the concept easier to understand.

64. Which of the following is/are advantage of using object oriented programming?
a) Code Reusability
b) Can create more than one instance of a class without interference
c) Platform independent
d) All of the mentioned
Answer: d
Explanation: None.

65. Java Compiler translates the source code into?


a) Machine code
b) Assembly code
c) Byte code
d) JVM code
Answer: c
Explanation: Java program is converted into ‘byte code’ which makes it easier to run on wide variety
of environments. Only the run- time package JVM has to be implemented for each platform.
699
66. What is the output of this program?
1. class PrintTest {
2. public static void main(Stringargs[])
3. {
4. int num = 10;
5. if (NUM < 100) {
6. [Link]("Thevalue of num is"+ num);
7. }
8. }
9. }
a) Compilation error
b) Run time error
c) The value of num is 10
d) None of the mentioned
Answer: a
Explanation: Java is case-sensitive. The variable ‘num’ used in print statement is not same as the
variable ‘NUM’ used in the if conditional statement.

67. Which of the following is called as ‘Comiplation unit’?


a) Object file
b) Byte code
c) Source file
d) All of the mentioned
Answer: c
Explanation: None.

68. What is the output of this program?


1. class TypeChecking {
2. public static void main(Stringargs[])
3. {
4. int num = 10.5;
5. [Link]("Output
:The value of num is" +num);6. }
7. }
a) Output: The value of num is 10.5
b) Run-time error
c) Compilation error
d) None of the mentioned
Answer: c
Explanation: Java is storngly typed language. The variable num is declared as ‘int’ but the value
assigned to it is ‘float’, as a result the code does not get compiled.

69. Which is a named memory location assigned a value by the program?


a) variable
b) literal
c) identifier
d) None of the mentioned
700
Answer: a
Explanation: None.

70. What is Address Binding?


a) going to an address in memory
b) locating an address with the help of another address
c) binding two addresses together to form a new address in a different memory space
d) a mapping from one address space to another
Answer: d
Explanation: None.

71. Binding of instructions and data tomemory addresses can be done at


a) Compile time
b) Load time
c) Execution time
d) All of the mentioned
Answer: d Explanation: None.

72. If the process can be moved during its execution from one memory segment to another, then
binding must be
a) delayed until run time
b) preponed to compile time
c) preponed to load time
d) none of the mentioned
Answer: a
Explanation: None.

73. What is Dynamic loading?


a) loading multiple routines dynamically
b) loading a routine only when it is called
c) loading multiple routines randomly
d) none of the mentioned
Answer: b Explanation: None.
74. What is the advantage of dynamic loading?
a) A used routine is used multiple times
b) An unused routine is never loaded
c) CPU utilization increases
d) All of the mentioned
Answer: b
Explanation: None.

75. The idea of overlays is to


a) data that are needed at any given time
b) enable a process to be larger than the amount of memory allocated to it
c) keep in memory only those instructions
d) all of the mentioned
Answer: d
Explanation: None.
701
76. The must design andprogram the overlay structure.
a) programmer
b) system architect
c) system designer
d) none of the mentioned
Answer: a
Explanation: None.

77. The swaps processes in and out of the memory.


a) Memory manager
b) CPU
c) CPU manager
d) User
Answer: a
Explanation: None.

78. If a higher priority process arrives and wants service, the memory manager can swap out the
lower priority process to
the higher priority process finishes, the lower priority process is swapped back in and continues
execution. This variant of swapping is sometimes called?
a) priority swapping
b) pull out, push in
c) roll out, roll in
d) none of the mentioned
Answer: c
Explanation: None.

79. If binding is done at assembly or load time, then the process be moved to different
locations after being swapped out and in again.
a) can
b) must
c) can never
d) may
Answer: c
Explanation: None.

80. Which of the following is not the primary objectives in the analysis model?
a) describing the customer complaints
b) establishing a basis for the creation of a software design
c) defining a set of requirements that can be validated once the software is built
d) none of the mentioned
Answer: d
Explanation: All the options are covered inanalysis model.

81. A description of each function presented in the DFD is contained in a execute the higher priority
process. When
a) ta flow
702
b) process specification
c) control specification
d) data store
Answer: b
Explanation: None.

82. Which diagram indicates the behaviour of the system as a consequence of externalevents?
a) data flow diagram
b) state transition diagram
c) control specification diagram
d) workflow diagram
Answer: b
Explanation: The state transition diagram represents the various modes of behavior (called states)
of the system and the manner in which transitions are made from state to state.
83. A data model contains
a) data object
b) attributes
c) relationships
d) all of the mentioned
Answer: d
Explanation: The data model consists of three interrelated pieces of information: the data object,
the attributes that describe the data object, and the relationships that connect data objects to one
another.

84. defines the properties of a data object and take on one of the three different
characteristics.
a) data object
b) attributes
c) relationships
d) data object and attributes
Answer: b
Explanation: They can be used to name an instance of the data object, describe the instance, or
make reference to another instance in another table.

85. Which of the following is not a data type?


a) Symbolic Data
b) Alphanumeric Data
c) Numeric Data
d) Alphabetic Data
Answer: a
Explanation: Data types are of three basic types: Numeric, Alphabetic and Alphanumeric. Numeric
Data consists of only numbers.
Alphabetic Data consists of only letters and a blank character and alphanumeric data consists of
symbols.

86. *@Ac# is a type of data.


a) Symbolic
b) Alphanumeric
703
c) Alphabetic
d) Numeric
Answer: b
Explanation: Alphanumeric data consists of symbols. Alphanumeric data may be a letter, either in
uppercase or lowercase or some special symbols like #,^,*,(, etc.

87. Which of the following is not a valid representation in bits?


a) 8-bit
b) 24-bit
c) 32-bit
d) 64-bit
Answer: b
Explanation: There are no criteria like the 24-bit representation of numbers. Numbers can be written
in 8-bit, 16-bit, 32-bit and 64-bit as per the IEEE format.

88. What are the entities whose values can be changed called?
a) Constants
b) Variables
c) Modules
d) Tokens
Answer: b
Explanation: Variables are the data entities whose values can be changed. Constants have a fixed
value. Tokens are the words which are easily identified by the compiler.

89. Which of the following is not a basic data type in C language?


a) float
b) int
c) real
d) char
Answer: c
Explanation: There are 5 basic data types inC language: int, char, float, double, void.
Int is for the representation of integers, char is for strings and characters, float anddouble are for
floating point numbers whereas void is a valueless special data type.

90. BOOLEAN is a type of data type which basically gives a tautology or fallacy.
a) True
b) False
Answer: a
Explanation: A Boolean representation is for giving logical values. It returns either true or false. If a
result gives a truth value, it is called tautology whereas if it returns a false term, it is referred to as
fallacy.

91. What does FORTRAN stands for?


a) Formula Transfer
b) Formula Transformation
c) Formula Translation
d) Format Transformation
Answer: c
704
Explanation: FORTRAN is a type of computer language. It was developed for solving mathematical
and scientific problems. It is very commonly used among the scientific community.

92. The program written by the programmer in high level language is called
a) Object Program
b) Source Program
c) Assembled Program
d) Compiled Program
Answer: b
Explanation: The program written by the programmer is called a source program. The program
generated by the compiler after compilation is called an object program. The object program is in
machine language.

93. A standardized language used for commercial applications.


a) C
b) Java
c) COBOL
d) FORTRAN
Answer: c
Explanation: COBOL is a language used in business and commercial applications. It stands for
Common Business Oriented Language. It is imperative, procedural as well as object oriented
language.

94. define how the locations can be used.


a) Data types
b) Attributes
c) Links
d) Data Objects
Answer: b
Explanation: Attributes can determine how any location can be used. Attributes can be type, name,
component, etc. Data objects are the variables and constants in a program.

95. Which was the first purely object oriented programming language developed?
a) Java
b) C++
c) SmallTalk
d) Kotlin
Answer: c
Explanation: SmallTalk was the first programming language developed which was purely object
oriented. It was developed by Alan Kay. OOP concept came into the picture in 1970’s.

96. Which of the following best defines a class?


a) Parent of an object
b) Instance of an object
c) Blueprint of an object
d) Scope of an object
Answer: b
Explanation: A class is Blueprint of an object which describes/ shows all the functions and data that
705
are provided by an object of a specific class. It can’t be called as parent or instance of an object.
Class in general describes all the properties of an object.

97. Who invented OOP?


a) Alan Kay
b) Andrea Ferro
c) Dennis Ritchie
d) Adele Goldberg
Answer: a
Explanation: Alan Kay invented OOP, Andrea Ferro was a part of SmallTalk Development. Dennis
invented C++ and Adele Goldberg was in team to develop SmallTalk but Alan actually had got
rewarded for OOP.

98. What is the additional feature in classes that was not in structures?
a) Data members
b) Member functions
c) Static data allowed
d) Public access specifier
Answer: b
Explanation: Member functions are allowed inside a class but were not present in structure
concept. Data members, static data and public access specifiers were present in structures too.

99. Which is not feature of OOP in general definitions?


a) Code reusability
b) Modularity
c) Duplicate/Redundant data
d) Efficient Code
Answer: c
Explanation: Duplicate/Redundant data is dependent on programmer and hence can’t be
guaranteed by OOP. Code reusability is done using inheritance. Modularity is supported by using
different code files and classes. Codes are more efficient because of features of OOP.

100. Pure OOP can be implemented without using class in a program. (True or False)
a) True
b) False
Answer: b
Explanation: It’s false because for a program to be pure OO, everything must be written inside
classes. If this rule is violated, the program can’t be labelled as purely OO.

101. Which Feature of OOP illustrated the code reusability?


a) Polymorphism
b) Abstraction
c) Encapsulation
d) Inheritance
Answer: d
Explanation: Using inheritance we can reuse the code already written and also can avoid creation
of many new functions or variables, as that can be done one time and be reused, using classes.

706
102. Which language does not support all 4 types of inheritance?
a) C++
b) Java
c) Kotlin
d) Small Talk
Answer: b
Explanation: Java doesn’t support all 4 types of inheritance. It doesn’t support multiple inheritance.
But the multiple inheritance can be implemented using interfaces in Java.

103. How many classes can be defined in a single program?


a) Only 1
b) Only 100
c) Only 999
d) As many as you want
Answer: d
Explanation: Any number of classes can be defined inside a program, provided that their names are
different. In java, if public class is present then it must have the same name as that of file.

104. When OOP concept did first came into picture?


a) 1970’s
b) 1980’s
c) 1993
d) 1995
Answer: a
Explanation: OOP first came into picture in1970’s by Alan and his team. Later it was used by some
programming languages and got implemented successfully, SmallTalk was first language to use
pure OOP and followed all rules strictly.

105. Why Java is Partially OOP language?


a) It supports usual declaration of primitive data types
b) It doesn’t support all types of inheritance
c) It allows code to be written outside classes
d) It does not support pointers
Answer: a
Explanation: As Java supports usual declaration of data variables, it is partial implementation of
OOP. Because accordingto rules of OOP, object constructors must be used, even for declaration of
variables.

106. Which concept of OOP is false for C++?


a) Code can be written without using classes
b) Code must contain at least one class
c) A class must have member functions
d) At least one object should be declared in code
Answer: b
Explanation: In C++, it’s not necessary to
use classes, and hence codes can be written without using OOP concept. Classes may or may not
contain member functions, so it’s not a necessary condition in C++. And, an object can only be
declared in a code if its class is defined/included via header file.
707
107. Which header file is required in C++ to use OOP?
a) iostream.h
b) stdio.h
c) stdlib.h
d) OOP can be used without using any header file
Answer: d
Explanation: We need not include any specific header file to use OOP concept in C++, only specific
functions used in code need their respective header files to be included or classes should be
defined if needed.

108. Which of the two features match each other?


a) Inheritance and Encapsulation
b) Encapsulation and Polymorphism
c) Encapsulation and Abstraction
d) Abstraction and Polymorphism
Answer: c
Explanation: Encapsulation and Abstraction are similar features. Encapsulation is actually binding
all the properties in a single class or we can say hiding all the features of object inside a class. And
Abstraction is hiding unwanted data (for user) and showing only the data required by the user of
program.

109. Which feature allows open recursion, among the following?


a) Use of this pointer
b) Use of pointers
c) Use of pass by value
d) Use of parameterized constructor
Answer: a
Explanation: Use of this pointer allows an object to call data and methods of itself whenever
needed. This helps us call the members of an object recursively, and differentiate the variables of
different scopes.

110. Which of the following is not type of class?


a) Abstract Class
b) Final Class
c) Start Class
d) String Class
Answer: c
Explanation: Only 9 types of classes are provided in general, namely, abstract, final, mutable,
wrapper, anonymous, input- output, string, system, network. We may further divide the classes into
parent class and subclass if inheritance is used.

111. Class is pass by


a) Value
b) Reference
c) Value or Reference, depending on program
d) Copy
Answer: b
708
Explanation: Classes are pass by reference, and the structures are pass by copy. It
doesn’t depend on the program.

112. What is default access specifier for data members or member functions declared within a
class without any specifier, in C++?
a) Private
b) Protected
c) Public
d) Depends on compiler
Answer: a
Explanation: The data members and member functions are Private by default in C++ classes, if
none of the access specifier is used. It is actually made to increase the privacy of data.

113. Which is most appropriate comment on following class definition?


class Student
{
int a;
public : float a;
};
a) Error : same variable name can’t be used twice
b) Error : Public must come first
c) Error : data types are different for same variable
d) It is correct
Answer: a
Explanation: Same variable can’t be defined twice in same scope. Even if the data types are
different, variable name must be different. There is no rule like Public member should come first or
last.

114. Which is known as a generic class?


a) Abstract class
b) Final class
c) Template class
d) Efficient Code
Answer: c
Explanation: Template classes are known to be generic classes because those can be used for any
data type value and the same class can be used for all the variables of different data types.

115. Size of a class is


a) Sum of the size of all the variables declared inside the class
b) Sum of the size of all the variables alongwith inherited variables in the class
c) Size of the largest size of variable
d) Classes doesn’t have any size
Answer: d
Explanation: Classes doesn’t have any size, actually the size of object of the class can be defined.
That is done only when an object is created and its constructor is called.

116. Which class can have member functions without their implementation?
a) Default class
709
b) String class
c) Template class
d) Abstract class
Answer: d
Explanation: Abstract classes can have member functions with no implementation, where the
inheriting subclasses must implement those functions.

117. Which of the following describes a friend class?


a) Friend class can access all the private members of the class, of which it is a friend
b) Friend class can only access protected members of the class, of which it is a friend
c) Friend class don’t have any implementation
d) Friend class can’t access any data
member of another class but can use it’s methods
Answer: a
Explanation: A friend class can access all the private members of another class, of which it is a
friend. It is a special class provided to use when you need to reuse the data of a class but don’t
want that class to have those special functions.

118. What is the scope of a class nested inside another class?


a) Protected scope
b) Private scope
c) Global scope
d) Depends on access specifier and inheritance used
Answer: d
Explanation: It depends on the access specifier and the type of inheritance used with the class,
because if the class is inherited then the nested class can be usedby subclass too, provided it’s not
of private type.

119. Class with main() function can be inherited.


a) True
b) False
Answer: a
Explanation: The class containing main function can be inherited and hence the program can be
executed using the derived class names also in java.

120. Which definition best describes anobject?


a) Instance of a class
b) Instance of itself
c) Child of a class
d) Overview of a class
Answer: a
Explanation: An object is instance of its class. It can be declared in the same way that a variable is
declared, only thing is youhave to use class name as the data type.

121. How many objects can be declared of a specific class in a single program?
a) 32768
b) 127
c) 1
710
d) As many as you want
Answer: d
Explanation: You can create as many objects of a specific class as you want, provided enough
memory is available.

122. Which among the following is false?


a) Object must be created before using members of a class
b) Memory for an object is allocated only after its constructor is called
c) Objects can’t be passed by reference
d) Objects size depends on its class data members
Answer: c
Explanation: Objects can be passed by reference. Objects can be passed by valuealso. If the object
of a class is not created, we can’t use members of that class.

123. Which of the following is incorrect?


a) class student{ }s;
b) class student{ }; student s;
c) class student{ }s[];
d) class student{ }; student s[5];
Answer: c
Explanation: The array must be specified with a size. You can’t declare object array, or any other
linear array without specifying its size. It’s a mandatory field.

124. The object can’t be


a) Passed by reference
b) Passed by value
c) Passed by copy
d) Passed as function
Answer: d
Explanation: Object can’t be passed as function as it is an instance of some class, it’s not a
function. Object can be passed by reference, value or copy. There is no term defined as pass as
function for objects.

125. What is size of the object of following class (64 bit system)?
class student { int rollno; char name[20];
static int studentno; };
a) 20
b) 22
c) 24
d) 28
Answer: c
Explanation: The size of any object of student class will be of size 4+20=24, because static
members are not really considered as property of a single object. So static variables size will not be
added.

126. Functions can’t return objects.


a) True
b) False
711
Answer: b
Explanation: Functions can always return an object if the return type is same as that of object being
returned. Care has to be taken while writing the prototype of the function.

127. How members of an object are accessed?


a) Using dot operator/period symbol
b) Using scope resolution operator
c) Using member names directly
d) Using pointer only
Answer: a
Explanation: Using dot operator after the name of object we can access its members. It is not
necessary to use the pointers. We can’t use the names directly because it maybe used outside the
class.

128. If a local class is defined in a function, which of the following is true for an object of that class?
a) Object is accessible outside the function
b) Object can be declared inside any other function
c) Object can be used to call other class members
d) Object can be used/accessed/declared locally in that function
Answer: d
Explanation: For an object which belongs to a local class, it is mandatory to declare and use the
object within the function because the class is accessible locally within the class only.

129. Which among the following is wrong?


a) class student{ }; student s;
b) abstract class student{ }; student s;
c) abstract class student{ }s[50000000];
d) abstract class student{ }; class toppers: public student{ }; topper t;
Answer: b
Explanation: We can never create instance of an abstract class. Abstract classes doesn’t have
constructors and hence when an instance is created there is no facility to initialize its members.
Option d is correct because topper class is inheriting the base abstract class student, and hence
topper class object can be created easily.

130. Which feature of OOP indicates codereusability?


a) Encapsulation
b) Inheritance
c) Abstraction
d) Polymorphism
Answer: b
Explanation: Inheritance indicates the code reusability. Encapsulation and abstraction are meant
to hide/group data into one element. Polymorphism is to indicate different tasks performed by a
single entity.

131. If a function can perform more than 1 type of tasks, where the function name remains same,
which feature of OOP is used here?
a) Encapsulation
b) Inheritance
712
c) Polymorphism
d) Abstraction
Answer: c
Explanation: For the feature given above, the OOP feature used is Polymorphism. Example of
polymorphism in real life is a kid, who can be a student, a son, a brother depending on where he is.

132. If different properties and functions of a real world entity is grouped or embedded into a single
element, what is it called in OOP language?
a) Inheritance
b) Polymorphism
c) Abstraction
d) Encapsulation

Answer: d
Explanation: It is Encapsulation, which groups different properties and functions of a real world
entity into single element.
Abstraction, on other hand, is hiding of functional or exact working of codes and showing only the
things which are required by the user.

133. Which of the following is not a feature of pure OOP?


a) Classes must be used
b) Inheritance
c) Data may/may not be declared using object
d) Functions Overloading
Answer: c
Explanation: Data must be declared using objects. Object usage is mandatory because it in turn
calls its constructors, which in turn must have a class defined. If object is not used, it is a violation
of pure OOP concept.

134. Which among the following doesn’t come under OOP concept?
a) Platform independent
b) Data binding
c) Message passing
d) Data hiding
Answer: a
Explanation: Platform independence is notfeature of OOP. C++ supports OOP but it’s not a platform
independent language.
Platform independence depends on programming language.

135. Which feature of OOP is indicated bythe following code?


class student{ int marks; };
class topper:public student{ int age; topper(int age){ [Link]=age; } };
a) Inheritance
b) Polymorphism
c) Inheritance and polymorphism
d) Encapsulation and Inheritance
Answer: d
Explanation: Encapsulation is indicated by use of classes. Inheritance is shown by inheriting the
713
student class into topper class. Polymorphism is not shown here because we have defined the
constructor in the topper class but that doesn’t mean that default constructor is overloaded.

136. Which feature may be violated if we don’t use classes in a program?


a) Inheritance can’t be implemented
b) Object must be used is violated
c) Encapsulation only is violated
d) Basically all the features of OOP gets violated
Answer: d
Explanation: All the features are violated because Inheritance and Encapsulation won’t be
implemented. Polymorphism and Abstraction are still possible in some cases, but the main features
like data binding, object use and etc won’t be used hence the use of class is must for OOP concept.

137. How many basic features of OOP are required for a programming language to be purely OOP?
a) 7
b) 6
c) 5
d) 4
Answer: a
Explanation: There are 7 basic features that define whether a programing language is pure OOP or
not. The 4 basic features are inheritance, polymorphism, encapsulation and abstraction. Further,
one is, object use is must, secondly, message passing and lastly, Dynamic binding.

138. The feature by which one object can interact with another object is
a) Data transfer
b) Data Binding
c) Message Passing
d) Message reading
Answer: c
Explanation: The interaction between two object is called the message passing feature. Data
transfer is not a feature of OOP. Also, message reading is not a feature of OOP.

139. underlines the feature of Polymorphism in a class.


a) Nested class
b) Enclosing class
c) Inline function
d) Virtual Function
Answer: d
Explanation: Virtual Functions can be defined in any class using the keyword virtual. All the classes
which inherit the class containing the virtual function, define the virtual function as required.
Redefining the function on all the derived classes according to class and use represents
polymorphism.

140. Which feature in OOP is used to allocate additional function to a predefined operator in any
language?
a) Operator Overloading
b) Function Overloading
714
c) Operator Overriding
d) Function Overriding
Answer: a
Explanation: The feature is operator overloading. There is not a feature named operator overriding
specifically. Function overloading and overriding doesn’t give addition function to any operator.

141. Which among doesn’t illustrates polymorphism?


a) Function overloading
b) Function overriding
c) Operator overloading
d) Virtual function
Answer: b
Explanation: Function overriding doesn’t illustrate polymorphism because the functions are
actually different and theirs scopes are different. Function and operator overloading illustrate
proper polymorphism. Virtual functions show polymorphism because all the classes which inherit
virtual function, define the same function in different ways.

142. Exception handling is a feature of OOP.


a) True
b) False
Answer: a
Explanation: Exception handling is a feature of OOP as it includes classes concept in most of the
cases. Also it may come handy while using inheritance.

143. Which among the following, for a pure OOP language, is true?
a) The language should follow 3 or more features of OOP
b) The language should follow at least 1 feature of OOP
c) The language must follow only 3 features of OOP
d) The language must follow all the rules of OOP
Answer: d
Explanation: The language must follow all the rules of OOP to be called a purely OOP language.
Even if a single OOP feature is not followed, then it’s known to be a partially OOP language.

144. Does OOP provide better security than POP?


a) Always true for any programming language
b) May not be true with respect to all programming languages
c) It depends on type of program
d) It’s vice-versa is true
Answer: a
Explanation: It is always true as we have the facility of private and protected access
specifiers. Also, only the public and global data are available globally or else the program should
have proper permission to access the private data.

145. Which among the following best describes polymorphism?


a) It is the ability for a message/data to be processed in more than one form
b) It is the ability for a message/data to be processed in only 1 form
c) It is the ability for many messages/data to be processed in one way
d) It is the ability for undefined message/data to be processed in at least one way
715
Answer: a
Explanation: It is actually the ability for a message / data to be processed in more than one form.
The word polymorphism indicates many-forms. So if a single entitytakes more than one form, it is
known as polymorphism.

146. What do you call the languages that support classes but not polymorphism?
a) Class based language
b) Procedure Oriented language
c) Object-based language
d) If classes are supported, polymorphism will always be supported
Answer: c
Explanation: The languages which support classes but doesn’t support polymorphism, are known
as object-based languages.
Polymorphism is such an important feature, that is a language doesn’t support this feature, it can’t
be called as a OOP language.
147. Which among the following is the language which supports classes but not polymorphism?
a) SmallTalk
b) Java
c) C++
d) Ada
Answer: d
Explanation: Ada is the language which supports the concept of classes but doesn’t support the
polymorphism feature. It is an object-based programming language. Note that it’s not an OOP
language.

148. If same message is passed to objects of several different classes and all of those can respond
in a different way, what is this feature called?
a) Inheritance
b) Overloading
c) Polymorphism
d) Overriding
Answer: c
Explanation: The feature defined in question defines polymorphism features. Here the different
objects are capable of responding to the same message in different ways, hence polymorphism.

149. Which type of function among thefollowing shows polymorphism?


a) Inline function
b) Virtual function
c) Undefined functions
d) Class member functions
Answer: b
Explanation: Only virtual functions among these can show polymorphism. Class member functions
can show polymorphism too but we should be sure that the same function is being overloaded or
is a function of abstract class or something like this, since we are not sure about all these, we can’t
say whether it can show polymorphism or not.

150. In case of using abstract class or function overloading, which function is supposed to be called
first?
716
a) Local function
b) Function with highest priority in compiler
c) Global function
d) Function with lowest priority because it might have been halted since long time, because of low
priority
Answer: b
Explanation: Function with highest priority is called. Here, it’s not about the thread scheduling in
CPU, but it focuses on whether the function in local scope is present or not, or if scope resolution
is used in some way, or if the function matches the argument signature. So all these things define
which function has the highest priority to be called in runtime. Local function could be one of the
answer but we can’t say if someone have used pointer to another function or same function name.

151. Which among the following can’t beused for polymorphism?


a) Static member functions
b) Member functions overloading
c) Predefined operator overloading
d) Constructor overloading
Answer: a
Explanation: Static member functions are not property of any object. Hence it can’t be considered
for overloading/overriding. For polymorphism, function must be property of object, not only of class.

152. Which among the following can showpolymorphism?


a) Overloading ||
b) Overloading +=
c) Overloading <<
d) Overloading &&
Answer: c
Explanation: Only insertion operator can be overloaded among all the given options.
And the polymorphism can be illustratedhere only if any of these is applicable of being overloaded.
Overloading is type of polymorphism.

153. Polymorphism is possible in C language.


a) True
b) False
Answer: a
Explanation: It is possible to implement polymorphism in C language, even though itdoesn’t support
class. We can use structures and then declare pointers which in turn points to some function. In
this way we simulate the functions like member functions but not exactly member function. Now
we can overload these functions, hence implementing polymorphism in C language.

154. Which problem may arise if we use abstract class functions for polymorphism?
a) All classes are converted as abstract class
b) Derived class must be of abstract type
c) All the derived classes must implement the undefined functions
d) Derived classes can’t redefine the function
Answer: c
Explanation: The undefined functions must be defined is a problem, because one may need to
implement few undefined functions from abstract class, but he will have to define each of the
717
functions declared in abstract class. Being useless task, it is a problem sometimes.

155. Which among the following is not true for polymorphism?


a) It is feature of OOP
b) Ease in readability of program
c) Helps in redefining the same functionality
d) Increases overhead of function definition always
Answer: d
Explanation: It never increases function definition overhead, one way or another if you don’t use
polymorphism, you will use the definition in some other way, so it actually helps to write efficient
codes.

156. If 2 classes derive one base class and redefine a function of base class, also overload some
operators inside class body. Among these two things of function and

operator overloading, where is polymorphism used?


a) Function overloading only
b) Operator overloading only
c) Both of these are using polymorphism
d) Either function overloading or operator overloading because polymorphism can be applied only
once in a program
Answer: d
Explanation: Both of them are using polymorphism. It is not necessary that polymorphism can be
used only once in a program, it can be used anywhere, any number of times in a single program.

157. Which among the following best describes encapsulation?


a) It is a way of combining various data members into a single unit
b) It is a way of combining various member functions into a single unit
c) It is a way of combining various data members and member functions into a single unit which
can operate on any data
d) It is a way of combining various data members and member functions that operate on those
data members into a single unit
Answer: d
Explanation: It is a way of combining both data members and member functions, which operate on
those data members, into a single unit. We call it a class in OOP generally. This feature have helped
us modify the structures used in C language to be upgraded into class in C++ and other languages.

158. If data members are private, what can we do to access them from the class object?
a) Create public member functions to access those data members
b) Create private member functions to access those data members
c) Create protected member functions to access those data members
d) Private data members can never be accessed from outside the class
Answer: a
Explanation: We can define public member functions to access those private data members and
get their value for use or alteration. They can’t be accessed directly but is possible to be access
using member functions. This is done to ensure that the private data doesn’t get modified
accidentally.

718
159. While using encapsulation, which among the following is possible?
a) Code modification can be additional overhead
b) Data member’s data type can be changed without changing any other code
c) Data member’s type can’t be changed, or whole code have to be changed
d) Member functions can be used to change the data type of data members
Answer: b
Explanation: Data member’s data type can be changed without changing any further code. All the
members using that data can continue in the same way without any modification. Member
functions can never change the data type of same class data members.

160. Find which of the following uses encapsulation?


a) void main(){ int a; void fun( int a=10; cout<<a); fun(); }
b) class student{ int a; public: int b;};
c) class student{int a; public: void disp(){ cout<<a;} };
d) struct topper{ char name[10]; public : int marks; }
Answer: c
Explanation: It is the class which uses both the data members and member functions being
declared inside a single unit. Only data members can be there in structures also. And the
encapsulation can only be illustrated if some data/operations are associated within class.

161. Encapsulation helps in writing


classes in java.
a) Mutable
b) Abstract
c) Wrapper
d) Immutable
Answer: d
Explanation: Immutable classes are used for caching purpose generally. And it can be created by
making the class as final and making all its members private.

162. Which among the following should be encapsulated?


a) The data which is prone to change is near future
b) The data prone to change in long terms
c) The data which is intended to be changed
d) The data which belongs to some other class
Answer: a
Explanation: The data prone to change in near future is usually encapsulated so that it doesn’t get
changed accidentally. We encapsulate the data to hide the critical working of program from outside
world.

163. How can Encapsulation be achieved?


a) Using Access Specifiers
b) Using only private members
c) Using inheritance
d) Using Abstraction
Answer: a
Explanation: Using access specifiers we can achieve encapsulation. Using this we can in turn
implement data abstraction. It’s not necessary that we only use private access.
719
164. Which among the following violates the principle of encapsulation almost always?
a) Local variables
b) Global variables
c) Public variables
d) Array variables
Answer: b
Explanation: Global variables almost always violates the principles of encapsulation.
Encapsulation says the data should be accessed only by required set of elements. But global
variable is accessible everywhere, also it is most prone to changes. It doesn’t hide the internal
working of program.

165. Which among the following would destroy the encapsulation mechanism if it was allowed in
programming?
a) Using access declaration for private members of base class
b) Using access declaration for publicmembers of base class
c) Using access declaration for local variable of main() function
d) Using access declaration for global variables
Answer: a
Explanation: If using access declaration for private members of base class was allowed in
programming, it would have destroyed whole concept of encapsulation. As if it was possible, any
class which gets inherited privately, would have been able to inherit the private members of base
class, and hence could access each and every member of base class.

166. Which among the following can be a concept against encapsulation rules?
a) Using function pointers
b) Using char* string pointer to be passed to non-member function
c) Using object array
d) Using any kind of pointer/array address in passing to another function
Answer: d
Explanation: If we use any kind of array or pointer as data member which should not be changed,
but in some case its address is passed to some other function or similar variable. There are chances
to modify its whole data easily. Hence Against encapsulation.

167. Consider the following code and select the correct option.
a) This code is good to go
b) This code may result in undesirable conditions
c) This code will generate error
d) This code violates encapsulation
Answer: d
Explanation: This code violates the encapsulation. By this code we can get the address of the
private member of the class, hence we can change the value of private member, which is against
the rules.

168. Encapsulation is the way to add functions in a user defined structure.


a) True
b) False
Answer: b
720
Explanation: False, because we can’t call these structures if member functions are involved, it must
be called class. Also, it is not just about adding functions, it’s about binding data and functions
together.

169. Using encapsulation data security is


class student
{
int marks;
public : int* fun()
{
return &marks;
}
};
main()
{
student s;
int *ptr=[Link]();return 0;
}
a) Not ensured
b) Ensured to some extent
c) Purely ensured
d) Very low
Answer: b
Explanation: The encapsulation can only ensure data security to some extent. If pointer and
addresses are misused, it may violate encapsulation. Use of global variables also makes the
program vulnerable, hence we can’t say that encapsulation gives pure security.

170. Which among the following best defines abstraction?


a) Hiding the implementation
b) Showing the important data
c) Hiding the important data
d) Hiding the implementation and showing only the features
Answer: d
Explanation: It includes hiding the implementation part and showing only the required data and
features to the user. It is done to hide the implementation complexity and details from the user. And
to provide a good interface in programming.

[Link] is abstraction.
a) Object
b) Logical
c) Real
d) Hypothetical
Answer: c
Explanation: Object is real abstraction because it actually contains those features of class. It is the
implementation of overview given by class. Hence the class is logical abstraction and its object is
real.

721
172. Hiding the implementation complexity can
a) Make the programming easy
b) Make the programming complex
c) Provide more number of features
d) Provide better features
Answer: a
Explanation: It can make programming easy. The programming need not know how the inbuilt
functions are working but can use those complex functions directly in the program. It doesn’t
provide more number of features or better features.

173. Abstraction gives higher degree of


a) Class usage
b) Program complexity
c) Idealized interface
d) Unstable interface
Answer: c
Explanation: It is to idealize the interface. In this way the programmer can use the programming
features more efficiently and can code better. It can’t increase the program complexity, as the
feature itself is made to hide it.

174. Class is abstraction.


a) Object
b) Logical
c) Real
d) Hypothetical
Answer: b
Explanation: Class is logical abstraction because it provides a logical structure for all of its objects.
It gives an overview of the features of an object.

175. Abstraction can apply to


a) Control and data
b) Only data
c) Only control
d) Classes
Answer: a
Explanation: Abstraction applies to both. Control abstraction involves use of subroutines and
control flow abstraction. Data abstraction involves handling pieces of data in meaningful ways.

[Link] among the following can be viewed as combination of abstraction of data and code.
a) Class
b) Object
c) Inheritance
d) Interfaces
Answer: b
Explanation: Object can be viewed as abstraction of data and code. It uses data members and their
functioning as data abstraction. Code abstraction as use of object of inbuilt class.

177. Abstraction principle includes


722
a) Use abstraction at its minimum
b) Use abstraction to avoid longer codes
c) Use abstraction whenever possible to avoid duplication
d) Use abstraction whenever possible to achieve OOP
Answer: c
Explanation: Abstraction principle includesuse of abstraction to avoid duplication (usually of code).
It this way the program doesn’t contain any redundant functions and make the program efficient.

178. Higher the level of abstraction, higherare the details.


a) True
b) False
Answer: b
Explanation: Higher the level of abstraction, lower are the details. The best way to understand this
is to consider a whole system that is highest level of abstraction as it hides everything inside. And
next lower level would contain few of the computer components and so on.

179. Encapsulation and abstraction differ as


a) Binding and Hiding respectively
b) Hiding and Binding respectively
c) Can be used any way
d) Hiding and hiding respectively
Answer: a
Explanation: Abstraction is hiding the complex code. For example, we directly use cout object in
C++ but we don’t know how is it actually implemented. Encapsulation is data binding, as in, we try
to combine a similar type of data and functions together.

180. If two classes combine some private data members and provides public member functions to
access and manipulate those data members. Where is abstraction used?
a) Using private access specifier for datamembers
b) Using class concept with both data members and member functions
c) Using public member functions to access and manipulate the data members
d) Data is not sufficient to decide what is being used
Answer: c
Explanation: It is the concept of hiding program complexity and actual working in background.
Hence use of public member functions illustrates abstraction here.

181. A phone is made up of many components like motherboard, camera, sensors and etc. If the
processor represents all the functioning of phone, display shows the display only, and the phone is
represented as a whole. Which among the following have highest level of abstraction?
a) Motherboard
b) Display
c) Camera
d) Phone
Answer: d
Explanation: Phone as a whole have the highest level of abstraction. This is because the phone
being a single unit represents the whole system. Whereas motherboard, display and camera are its
components.

723
182. Which among the following is not a level of abstraction?
a) Logical level
b) Physical level
c) View level
d) External level
Answer: d
Explanation: Abstraction is generally divided into 3 different levels, namely, logical, physical and
view level. External level is not defined in terms of abstraction.

183. Using higher degree of abstraction


a) May get unsafe
b) May reduce readability
c) Can be safer
d) Can increase vulnerability
Answer: c
Explanation: It will make the code safer. One may think it reduces the readability, but the fact is, it
actually helps us understand the code better. We don’t have to read the complex code which is of
no use in understanding the program.

184. Which among the following best describes the Inheritance?


a) Copying the code already written
b) Using the code already written once
c) Using already defined functions in programming language
d) Using the data and functions into derivedsegment
Answer: d
Explanation: It can only be indicated by using the data and functions that we use in derived class,
being provided by parent class. Copying code is nowhere similar to this concept, also using the
code already written is same as copying. Using already defined functions is not inheritance as we
are not adding any of our own features.

185. How many basic types of inheritance are provided as OOP feature?
a) 4
b) 3
c) 2
d) 1
Answer: a
Explanation: There are basically 4 types of inheritance provided in OOP, namely, single level,
multilevel, multiple and hierarchical inheritance. We can add one more type as Hybrid inheritance
but that is actually the combination any types of inheritance from the 4 basic ones.

186. Which among the following best defines single level inheritance?
a) A class inheriting a derived class
b) A class inheriting a base class
c) A class inheriting a nested class
d) A class which gets inherited by 2 classes
Answer: b
Explanation: A class inheriting a base class defines single level inheritance. Inheriting an already
derived class makes it multilevel inheritance. And if base class is inherited by 2 other classes, it is
724
multiple inheritance.

187. Which among the following is correct for multiple inheritance?


a) class student{public: int marks;}s; class stream{int total;}; class topper:public student, public
stream{ };
b) class student{int marks;}; class stream{ }; class topper: public student{ };
c) class student{int marks;}; class stream:public student{ };
d) class student{ }; class stream{ }; class topper{ };
Answer: a
Explanation: Class topper is getting derived from 2 other classes and hence it is multiple
inheritance. Topper inherits class stream and class student publicly and hence can use its features.
If only few classes are defined, there we are not even using
inheritance (as in option class student{ };class stream{ }; class topper{ };).

188. Which programming language doesn’t support multiple inheritance?


a) C++ and Java
b) C and C++
c) Java and SmallTalk
d) Java
Answer: d
Explanation: Java doesn’t support multiple inheritance. But that feature can be implemented by
using the interfaces concept. Multiple inheritance is not supported because of diamond problem
and similar issues.

189. Which among the following is correct for a hierarchical inheritance?


a) Two base classes can be used to bederived into one single class
b) Two or more classes can be derived into one class
c) One base class can be derived into other two derived classes or more
d) One base class can be derived into only 2 classes
Answer: c
Explanation: One base class can be derived into the other two derived classes or more. If only one
class gets derived by only 2 other classes, it is also hierarchical inheritance, but it is not a
mandatory condition, because any number of derived classes can be there.

190. Which is the correct syntax of inheritance?


a. class derived_classname : base_classname{ /*define class body*/ };
b. class base_classname : derived_classname{ /*define class body*/ };
c. class derived_classname : access base_classname{ /*define class body*/ };
d. class base_classname :access derived_classname{ /*define class body*/ };
Answer: c
Explanation: Firstly, keyword class should come, followed by the derived class name. Colon is must
followed by access in which base class has to be derived, followed by the base class name. And
finally the body of class. Semicolon after the body is also must.

191. Which type of inheritance leads to diamond problem?


a) Single level
b) Multi-level
c) Multiple
725
d) Hierarchical
Answer: c
Explanation: When 2 or more classes inherit the same class using multiple inheritance and then one
more class inherits those two base classes, we get a diamond like structure. Here, ambiguity arises
when same function gets derived into 2 base classes and finally to 3rd level class because same
name functions are being inherited.

192. Which access type data gets derived as private member in derived class?
a) Private
b) Public
c) Protected
d) Protected and Private
Answer: a
Explanation: It is a rule, that when a derived class inherits the base class in private access mode, all
the members of base class gets derived as private members of the derived class.

193. If a base class is inherited in protected access mode then which among the following is true?
a) Public and Protected members of base class becomes protected members of derived class
b) Only protected members become protected members of derived class
c) Private, Protected and Public all members of base, become private of derived class
d) Only private members of base, become private of derived class
Answer: a
Explanation: As the programming language rules apply, all the public and protected members of
base class becomes protected members of derived class in protected access mode. It can’t be
changed because it would hinder the security of data and may add vulnerability in the program.

194. How many types of inheritance are possible in C++?


a) 2
b) 3
c) 4
d) 5
Answer: d
Explanation: There are five types of inheritance that are possible in C++. Single level, Multilevel,
multiple, hierarchical and hybrid. Here we count hybrid also because it sometimes can bring up a
new form of inheritance, Like inheritance using multiple and hierarchical, which sometimes results
in diamond problem.

195. Which among the following is true?


a) Java supports all types of inheritance
b) Java supports multiple inheritance
c) Java doesn’t support multiple inheritance
d) Java doesn’t support inheritance
Answer: c
Explanation: Java doesn’t support multiple inheritance. This is done to avoid the diamond problem
that sometimes arises with inherited functions. Though, multiple inheritance can be implemented
in java using interfaces.

196. Which type of inheritance is illustrated by the following code?


726
a) Single level
b) Multilevel and single level
c) Hierarchical
d) Hierarchical and single level
Answer: c
Explanation: It is hierarchical inheritance and single level inheritance. Since class topper is
inheriting class student, it is single level inheritance. And then average is inherited by section and
overall, so it is hierarchical inheritance. But both of them are separate. Hence it is not hybrid
inheritance.

197. Which among the following best describes multiple inheritance?


a) Two classes being parent of any other classes
b) Three classes being parent of other classes
c) More than one class being parent of other child classes
d) More than one class being parent of single child
Answer: d
Explanation: If a class inherits more thanone class, it is known as multiple inheritance. This should
not be referred with only two or three classes being inherited. But there must be one class which
inherits more than one class to becalled as multiple inheritance.

198. How many types of inheritance can be used at a time in a single program?
a) Any two types
b) Any three types
c) Any 4 types
d) Any type, any number of times
Answer: d
Explanation: Any type of inheritance can be used in any program. There is no rule to use only few
types of inheritance. Only thing that matters is how the classes are inherited and used.

199. Which among the following defines single level inheritance?


a) One base class derives another class
b) One derived class inherits from one base class
c) One base class inherits from one derived class
d) One derived class derives from another derived class
Answer: b
Explanation: If only one base class is used to derive only one subclass, it is known as single level
inheritance. The reason of this name is that we inherit the base class to one more level and stop
the inheritance any further.

200. If class A and class B are derived from class C and class D, then
a) Those are 2 pairs of single inheritance
b) That is multilevel inheritance
c) Those is enclosing class
d) Those are all independent classes
Answer: a
Explanation: Since class A is derived from class C and then class B is derived from class D, there
are two pairs of classes which shows single inheritance. Those two pairs are independent of each
other though.
727
201. If single inheritance is used, program will contain
a) At least 2 classes
b) At most 2 classes
c) Exactly 2 classes
d) At most 4 classes
Answer: a
Explanation: The program will contain at least 2 classes in the sense of base and derived classes.
At least one base class andone derived class must be there. Types of inheritance remains the same
though.

202. Single level inheritance supports inheritance.


a) Runtime
b) Compile time
c) Multiple inheritance
d) Language independency
Answer: a
Explanation: The runtime inheritance is done when object of a class is created to call a method. At
runtime the function is searched if it is in class of object. If not, it will search in its parent classes
and hierarchy for that method.

203. Which method in the code below is single level inherited?


class A
{
protected int a, b; public: void show()
{
cout&lt;&lt;a&lt;&lt;b;
}
};
class B: public A
{
public: void disp()
{
cout&lt;&lt;a++&lt;&lt;b++;
}
};
class C: private A, public B
{
void avg()
{
cout&lt;&lt;(a+b)/2;
}
};
a) Class A
b) Class B
c) Class C
d) None
Answer: b
728
Explanation: Class B is using single level inheritance. Class C is using multiple inheritance. And
class A is parent of other two classes.

204. If single level inheritance is used and an abstract class is created with some undefined
functions, can its derived class also skip some definitions?
a) Yes, always possible
b) Yes, possible if only one undefined function
c) No, at least 2 undefined functions must be there
d) No, the derived class must implement those methods
Answer: d
Explanation: The derived class must implement those methods. This is because the parent class is
abstract and hence will have some undefined functions which has to be defined in derived classes.
Since we

208. Which concept will result in derived class with more features (consider maximum 3 classes)?
a) Single inheritance
b) Multiple inheritance
c) Multilevel inheritance
d) Hierarchical inheritance
Answer: b
Explanation: If single inheritance is used then only feature of a single class are inherited, and if
multilevel inheritance is used, the 2nd class might have use private inheritance. Hence only multiple
inheritance can result in derived class with more features. This is not mandatory but in a case if we
consider same number of features in each class, it will result the same.

209. Single level inheritance is safer than are using single level inheritance, if derived
class doesn’t implement those functions then one more class has to be there which will become
multi-level inheritance.

207. Which among the following is false for single level inheritance?
a) There can be more than 2 classes in program to implement single inheritance
b) There can be exactly 2 classes to implement single inheritance in a program
c) There can be more than 2 independent classes involved in single inheritance
d) The derived class must implement all the abstract method if single inheritance is used
Answer: c
Explanation: If more than 2 independent classes are involved to implement the single level
inheritance, it won’t be possible as there must be only one child and one parent class and none
other related class.
a) Multiple inheritance
b) Interfaces
c) Implementations
d) Extensions
Answer: a
Explanation: Interfaces also represent a way of inheritance but is a wide word to decide which
inheritance we are talking about in it, hence can’t be considered. Implementation and extensions
also doesn’t match that level of specific idea. And multiple inheritance not so safe as it might result
in some ambiguity.

729
210. Which language doesn’t support single level inheritance?
a) Java
b) C++
c) Kotlin
d) All languages support it
Answer: d
Explanation: All the languages support single level inheritance. Since any class can inherit other
classes as required, if single level inheritance was not allowed it would result in failing a lot of
features of OOP.

211. Which among the following best defines multilevel inheritance?


a) A class derived from another derived class
b) Classes being derived from other derived classes
c) Continuing single level inheritance
d) Class which have more than one parent
Answer: b
Explanation: Only if the class is being derived from other derived class, it can be called as multilevel
inheritance. If a class isderived from another class, it is single levelinheritance. There must be more
than one level of inheritance.

212. If there are 5 classes, E is derived from D, D from C, C from B and B from A. Which class
constructor will be called first if the object of E or D is created?
a) A
b) B
c) C
d) A and B
Answer: a
Explanation: A is parent of all other classes indirectly. Since A is parent of B and B is parent of C
and so on till E. Class A constructor will be called first always.

213. If there are 3 classes. Class C is derived from class B and B is derived from A, Which
class destructor will be called at last if object of C is destroyed.
a) A
b) B
c) C
d) All together
Answer: a
Explanation: The destructors are called in the reverse order of the constructors being called. Hence
in multilevel inheritance, the constructors are created from parent to child, which leads to
destruction from child to parent. Hence class A destructor will be called at last.

214. Which Class is having highest degree of abstraction in multilevel inheritance of 5 levels?
a) Class at 1st level
b) Class 2nd last level
c) Class at 5th level
d) All with same abstraction
Answer: a
Explanation: The class with highest degree of abstraction will be the class at the 1st level. You can
730
look at a simple example like, a CAR is more abstract than SPORTS CAR class. The level of
abstraction decrease with each level as more details comes out.

215. If all the classes use private inheritance in multilevel inheritance then
a) It will not be called multilevel inheritance
b) Each class can access only non-private members of its parent
c) Each subsequent class can access all members of previous level parent classes
d) None of the members will be available to any other class
Answer: b
Explanation: The classes will be able to access only the non-private members of its parent class.
The classes are using private inheritance, hence all the members of the parent class become
private in the derived class. In turn those won’t be allowed for further inheritance or direct access
outside the class.

216. Multilevel inheritance allows in the program.


a) Only 7 levels of inheritance
b) At least 7 levels of inheritance
c) At most 16 levels of inheritance
d) As many levels of inheritance as required
Answer: d
Explanation: The multilevel inheritance allows any number of levels of inheritance. This is the
maximum flexibility feature to make the members available to all the new classes and to add their
own functionalities. The code reusability is used too.

217. Multiple inheritance is


a) When a class is derived from another class
b) When a class is derived from two or more classes
c) When a class is derived from other two derived classes
d) When a class is derived from exactly one class
Answer: b
Explanation: The multiple inheritance is used when a class is being derived using two base classes
or more. This way a single class can have features of more than one classes inherited into a single
unit. This lets us combine two class members into a single class.

218. Which problem arises due to multiple inheritance, if hierarchical inheritance is used previously
for its base classes?
a) Diamond
b) Circle
c) Triangle
d) Loop
Answer: a
Explanation: The diamond problem arises when multiple inheritance is used. This problem arises
because the same name member functions get derived into a single class. Which in turn creates
ambiguity in calling those methods.

219. Which among the following is best to define hierarchical inheritance?


a) More than one classes being derived from one class
b) More than 2 classes being derived from single base class
731
c) At most 2 classes being derived from single base class
d) At most 1 class derived from another class
Answer: a
Explanation: When two or more classes get derived from a single base class, it is known as
hierarchical inheritance. This gives us
freedom to use same code with different scopes and flexibility into different classes.

220. Do members of base class gets divided among all of its child classes?
a) Yes, equally
b) Yes, depending on type of inheritance
c) No, it’s doesn’t get divided
d) No, it may or may not get divided
Answer: c
Explanation: The class members doesn’t get divided among the child classes. All the members get
derived to each of the subclasses as whole. The only restriction is from the access specifiers used.

221. Which among the following best defines the hybrid inheritance?
a) Combination of two or more inheritance types
b) Combination of same type of inheritance
c) Inheritance of more than 7 classes
d) Inheritance involving all the types of inheritance
Answer: a
Explanation: When more than one type of inheritance are used together, it results in new type of
inheritance which is in general known as hybrid inheritance. This may of may not have better
capabilities.

222. How many types of inheritance should be used for hybrid?


a) Only 1
b) At least 2
c) At most two
d) Always more than 2
Answer: b
Explanation: There must be combination of at least 2 types of inheritance. The inheritance should
be of different type.

223. Which of the following is the correct syntax of including a user defined header files in C++?
a) #include <userdefined.h>
b) #include <userdefined>
c) #include “userdefined”
d) #include [userdefined]
Answer: c
Explanation: C++ uses double quotes to include a user-defined header file. The correct syntax of
including user-defined is #include “userdefinedname”.

224. Which of the following is a correct identifier in C++?


a) 7var_name
b) 7VARNAME
c) VAR_1234
732
d) $var_name
Answer: c
Explanation: The rules for writing anidentifier is as follows:
i) may contain lowercase/uppercase letters, digits or underscore(_) only
ii) should start with a non-digit character
iii) should not contain any special characters like @, $, etc.

225. Which of the following is called address operator?


a) *
b) &
c) _
d) %
Answer: b
Explanation: & operator is called address
operator and is used to access the address of a variable.

226. Which of the following is used for comments in C++?


a) // comment
b) /* comment */
c) both // comment or /* comment */
d) // comment */
Answer: c
Explanation: Both the ways are used for commenting in C++ programming. // is usedfor single line
comments and /* … */ is used for multiple line comments.

227. What are the actual parameters in C++?


a) Parameters with which functions are called
b) Parameters which are used in thedefinition of a function
c) Variables other than passed parameters in a function
d) Variables that are never used in the function
Answer: a
Explanation: Actual parameters are those using which a function call is made i.e. which are actually
passed in a function when that function is called.

228. What are the formal parameters in C++?


a) Parameters with which functions are called
b) Parameters which are used in thedefinition of the function
c) Variables other than passed parameters in a function
d) Variables that are never used in the function
Answer: b
Explanation: Formal parameters are those which are used in the definition of a function. They
are the parameters that represent the actual parameters passed and they are the one which is used
inside the function.

229. Which function is used to read a single character from the console in C++?
a) [Link](ch)
b) getline(ch)
c) read(ch)
733
d) scanf(ch)
Answer: a
Explanation: C++ provides [Link]() functionto read a single character from console whereas others
are used to read either a single or multiple characters.

230. Which function is used to write a single character to console in C++?


a) [Link](ch)
b) [Link](ch)
c) write(ch)
d) printf(ch)
Answer: a
Explanation: C++ provides [Link]() function to write a single character to console whereas others
are used to write either a single or multiple characters.
231. What are the escape sequences?
a) Set of characters that convey special meaning in a program
b) Set of characters that whose use are avoided in C++ programs
c) Set of characters that are used in the name of the main function of the program
d) Set of characters that are avoided in cout statements
Answer: a
Explanation: Escape sequence is a set of characters that convey a special meaning to the program.
They are used to convey a meaning which cannot be conveyed directly.

232. Which of the following escape sequence represents carriage return?


a) \r
b) \n
c) \n\r
d) \c
Answer: a
Explanation: \r is used to represent carriage return which means move the cursor to the beginning
of the next line.

233. Which of the following escape sequence represents tab?


a) \t
b) \t\r
c) \b
d) \a
Answer: a
Explanation: \t is used to represent tab which means a set of blank spaces in a line.

234. Who created C++?


a) Bjarne Stroustrup
b) Dennis Ritchie
c) Ken Thompson
d) Brian Kernighan
Answer: a
Explanation: Bjarne Stroustrup is the original creator of C++ during 1979 at AT&T Bell Labs.

235. Which of the following is called insertion/put to operator?


734
a) <<
b) >>
c) >
d) <
Answer: a
Explanation: << operator is called insertion or put to operator i.e. insert/put things to console/files.

236. Which of the following is called extraction/get from operator?


a) <<
b) >>
c) >
d) <
Answer: b
Explanation: >> operator is called extraction or get from operator i.e. extract/get things from
console/files.
237. A language which has the capability to generate new data types are called
a) Extensible
b) Overloaded
c) Encapsulated
d) Reprehensible
Answer: a
Explanation: Languages that can produce/generate new data types are called extensible languages
as they have the ability to handle new data types.

238. What is the size of wchar_t in C++?


a) 2
b) 4
c) 2 or 4
d) Based on the number of bits in thesystem
Answer: d
Explanation: Compiler wants to make CPU as more efficient in accessing the next value.

239. Pick the odd one out.


a) array type
b) character type
c) boolean type
d) integer type
Answer: a
Explanation: Array type is not the basic type and it is constructed using the basic type.

240. Which data type is used to represent the absence of parameters?


a) int
b) short
c) void
d) float
Answer: c
Explanation: Because void specifies anempty set of values/parameters.

735
241. What does ‘\a’ escape code represent?
a) alert
b) backslash
c) tab
d) form feed
Answer: a
Explanation: Because \a is used to produce a beep sound.

242. Which type is best suited to represent the logical values?


a) integer
b) boolean
c) character
d) float
Answer: b
Explanation: Logical values can be either true or false, so the boolean type is suited for it.
243. Identify the user-defined types from the following?
a) enumeration
b) classes
c) both enumeration and classes
d) int
Answer: c
Explanation: They must be defined by theusers before use, unlike the other types which are readily
available.

244. Which operator is used to insert thedata into file?


a) >>
b) <<
c) <
d) >
Answer: b
Explanation: You can write information to a file from your program using the stream insertion
operator <<.

245. Which function is used to position back from the end of file object?
a) seekg
b) seekp
c) both seekg & seekp
d) seekf
Answer: a
Explanation: The member function seekg is used to position back from the end of file object.

246. How many objects are used for input and output to a string?
a) 1
b) 2
c) 3
d) 4
Answer: c
Explanation: The stringstream, ostringstream, and istringstream objects are used for input and
736
output to a string.

247. What will be the output of the following C++ code?

a) first
b) second
c) returns first 2 letter or number from the entered word
d) third
Answer: c
Explanation: In this program, We are using the sync function to return the first two letters of the
entered word.
Output:
a) This is sample
b) sample
c) Error
d) Runtime error
Answer: d
Explanation: In this program, if the file exist,it will read the file. Otherwise it will throw an exception.
A runtime error will occur because the value of the length variable will be “-1” if file doesn’t exist and
in line 13 we are trying to allocate an array of size “-1”.

248. What will be the output of the following C++ code?


1. #include <iostream>
2. using namespace std;
3. int main ()
4. {
5. char first, second;
6. cout << "Enter a word: ";
7. first = [Link]();
8. [Link]();
9. second = [Link]();
10. cout << first << endl;
11. cout << second << endl;
12. return 0;
13. }
a) first
b) second
c) returns first 2 letter or number from the entered word
d) third
Answer: c
Explanation: In this program, We are using the sync function to return the first two letters of the
entered word.

$ g++ [Link]
$ [Link]
Enter a word: steve
s
t
737
249. Which header file is required to use file I/O operations?
a) <ifstream>
b) <ostream>
c) <fstream>
d) <iostream>
Answer: c
Explanation: <fstream> header file is needed to use file I/O operations in C++. This header file
contains all the file I/O operations definition.

250. Which of the following is used to create an output stream?


a) ofstream
b) ifstream
c) iostream
d) fsstream
Answer: a
Explanation: ofstream is used to create anoutput stream in C++ file handling operations. Ofstream
objects are used to read files.

251. Which of the following is used to create a stream that performs both input and output
operations?
a) ofstream
b) ifstream
c) iostream
d) fstream
Answer: d
Explanation: fstream is used to create a stream that performs both input and output operations in
C++ file handling.

252. Which of the following is not used as a file opening mode?


a) ios::trunc
b) ios::binary
c) ios::in
d) ios::ate
Answer: a
Explanation: ios::trunc is used to truncate a file if it exists. It is not a file opening mode.

253. Which of the following statements are correct?


1) It is not possible to combine two or more file opening mode in open() method.
2) It is possible to combine two or more file opening mode in open() method.
3) ios::in and ios::out are input and output file opening mode respectively.
a) 1, 3
b) 2, 3
c) 3 only
d) 1, 2
Answer: a
Explanation: C++ allows to use one or more file opening mode in a single open() method. ios::in and
738
ios::out are input and output file opening mode respectively.

254. By default, all the files in C++ are opened in mode.


a) Text
b) Binary
c) ISCII
d) VTC
Answer: a
Explanation: By default, all the files in C++ are opened in text mode. They read the file as normal
text.

255. What is the use of ios::trunc mode?


a) To open a file in input mode
b) To open a file in output mode
c) To truncate an existing file to half
d) To truncate an existing file to zero
Answer: d
Explanation: In C++ file handling, ios::trunc mode is used to truncate an existing file to zero length.

256. How many groups of output of operation are there in c++?


a) 1
b) 2
c) 3
d) 4
Answer: b
Explanation: There are two groups of output operation in c++. They are formatted output and
unformatted output.

257. Pick out the correct objects about the instantiation of output stream.
a) cout
b) cerr
c) clog
d) all of the mentioned
Answer: d
Explanation: cout, cerr and clog are the standard objects for the instantiation of output stream
class.

258. What is meant by ofstream in c++?


a) Writes to a file
b) Reads from a file
c) Writes to a file & Reads from a file
d) delete a file
Answer: a
Explanation: ofstream is a stream class to write on files.

259. Which operator is used for input stream?


a) >
b) >>
739
c) <
d) <<
Answer: b
Explanation: The operator of extraction is >> and it is used on the standard input stream.

260. Where does a cin stops it extraction of data?


a) By seeing a blank space
b) By seeing (
c) By seeing a blank space & (d) By seeing <
Answer: a
Explanation: cin will stop its extraction when it encounters a blank space.

261. Which of the following is used for generic programming?


a) Virtual functions
b) Modules
c) Templates
d) Abstract Classes
Answer: c
Explanation: Templates are used for generic programming. They help in making generic functions
and classes hence achieving the generic codes.

262. Which of the following is correct about templates?


a) It is a type of compile time polymorphism
b) It allows the programmer to write one code for all data types
c) Helps in generic programming
d) All of the mentioned
Answer: d
Explanation: Templates are used for genericprogramming hence allowing to write a single function
for all data types. It is a type of compile time polymorphism.

263. What will be the output of the following C++ code?


#include <iostream>
using namespace std;
template <class T>
T max (T &a, T &b)
{
cout << "Template Called ";
return (a > b)? a : b;
}

template <>
int max <int> (int &a, int &b)
{
cout << "Called ";
return (a > b)? a : b;
}

int main ()
{ 740
int a = 10, b = 20;
cout << max <int> (a, b);
a) Template Called 20
b) Called 20
c) Error
d) Segmentation fault
Answer: b
Explanation: For T = int we have created a separate definition for the above template function.
Hence the call using int takes the newly defined function.

264. What will be the output of the following C++ code?


#include <iostream>
using namespace std;
template<int n>
struct funStruct
{
static const int val = 2*funStruct<n-
1>::val;
};

template<>
struct funStruct<0>
{
static const int val = 1 ;
};

int main()
{
cout << funStruct<10>::val << endl;
return 0;
}

a) 1
b) 1024
c) Error
d) Segmentation fault
Answer: b
Explanation: The above call for struct will call the first struct for n > 0 and second one when n = 0.
Therefore when value of n = 10 the until n becomes 0 first struct is called so we will call 2*2*2…10
times*1 which will give the result 210 = 1024.

265. What is an exception in C++ program?


a) A problem that arises during the execution of a program
741
b) A problem that arises during compilation
c) Also known as the syntax error
d) Also known as semantic error
Answer: a
Explanation: An exception is defined as theproblem in C++ program that arises during the execution
of the program for example divide by zero error.

266. By default, what a program does when it detects an exception?


a) Continue running
b) Results in the termination of the program
c) Calls other functions of the program
d) Removes the exception and tells the programmer about an exception
Answer: b
Explanation: By default, whenever a program detects an exception the program crashes as it does
not know how to handle it hence results in the termination of the program.

267. Why do we need to handle exceptions?


a) To avoid unexpected behaviour of a program during run-time
b) To let compiler remove all exceptions by itself
c) To successfully compile the program
d) To get correct output
Answer: a
Explanation: We need to handle exceptions in a program to avoid any unexpected behaviour during
run-time because that behaviour may affect other parts of the program. Also, an exception is
detected during run-time, therefore, a program may compile successfully even with some
exceptions cases in your program.

268. How Exception handling is implemented in the C++ program?


a) Using Exception keyword
b) Using try-catch block
c) Using Exception block
d) Using Error handling schedules
Answer: b
Explanation: C++ provides a try-catch block to handle exceptions in your program.

269. Which part of the try-catch block is always fully executed?


a) try part
b) catch part
c) finally part
d) throw part
Answer: c
Explanation: finally part of the try-catch block is always executed whether exceptions are caught or
not.

270. Which of the following is an exception in C++?


a) Divide by zero
b) Semicolon not written
c) Variable not declared
742
d) An expression is wrongly written
Answer: a
Explanation: Exceptions are those which are encountered during run-time of the program.
semicolon, variable not declared and the wrong expression are compile-time errors, therefore, they
are not exceptions. Divide by zero is the problem that is encountered during run-time, therefore, it
is an exception.

271. Where should we place catch block of the derived class in a try-catch block?
a) Before the catch block of Base class
b) After the catch block of Base class
c) Anywhere in the sequence of catch blocks
d) After all the catch blocks

Answer: a
Explanation: C++ asks the programmer to place the catch block of derived class before a catch
block of the base class, otherwise derived catch block will never be executed.

272. What id the syntax for catching any type of exceptions?


a) catch(Exception e)
b) catch(…)
c) catch(Exception ALL)
d) catch(ALL)
Answer: b
Explanation: catch(…) is used in C++ to catch all types of exceptions in a single catch block.

273. The C++ code which causes abnormal termination/behaviour of a program should be written
under block.
a) try
b) catch
c) finally
d) throw
Answer: a
Explanation: Code that leads to the abnormal termination of the program should be written under
the try block.
274. Exception handlers are declared with
keyword.
a) try
b) catch
c) throw
d) finally
Answer: b
Explanation: C++ uses catch block to handle
any exceptions that occur during run-time of the program.

275. Which of the following statements are correct about Catch handler?
i. It must be placed immediately after the try block
ii. It can have more than one parameters
iii. There must be one and only one catch handler for every try block
743
iv. There can be multiple catch handler for a try block
v. General catch handler can be kept anywhere after try block.
a) i, iv, v
b) i, ii, iii
c) i, iv
d) i, ii
Answer: c
Explanation: A catch block should always be placed after the try block and there can be multiple
catch block following a try block.

276. What is the role of a constructor in classes?


a) To modify the data whenever required
b) To destroy an object
c) To initialize the data members of an object when it is created
d) To call private functions from the outer world
Answer: c
Explanation: A constructor is used in classes to initialize data members of class in order to avoid
errors/segmentation faults.

277. Why constructors are efficient instead of a function init() defined by the user to initialize the
data members of an object?
a) Because user may forget to call init() using that object leading segmentation fault
b) Because user may call init() more than once which leads to overwriting values
c) Because user may forget to define init() function
d) All of the mentioned
Answer: d
Explanation: We cannot use init() because as mentioned in options that user may forget to initialize
the members which will lead to a segmentation fault. Also if the user calls the init() function more
than onceit may overwrite the values and may result into disastrous results. Also if any user forgets
to define init() function then no object will be initialized whereas if any constructor is not defined
in any class the class provides a default constructor for initialization.

278. What is a copy constructor?


a) A constructor that allows a user to move data from one object to another
b) A constructor to initialize an object with the values of another object
c) A constructor to check the whether to objects are equal or not
d) A constructor to kill other copies of a given object.
Answer: b
Explanation: Copy constructor allows the user to initialize an object with the values of another
object instead of supplying the same set of values again to initialize the object.

279. What will be the output of the following C++ code?


#include <iostream>
#include <string>
using namespace std;
class A{
int a;
public:
A(int i){ 744
a = i;
}
a) 5
b) 55
c) Error
d) Segmentation Fault
Answer: c
Explanation: As we have defined a constructor which takes an int parameter, so when we are trying
to declare an object obj of class A without supplying any parameter then as a constructor is
overwritten it will give an error saying that no matching function found. So whenever one writes a
constructor then the default constructor is overwritten hence if you want to declare an object
without parameter then you also have to define that constructor.

280. In the following C++ code how many times the string “A’s constructor called” will be printed?
#include <iostream>
#include <string>
using namespace std;
class A{
int a;
public:
A(){
cout<<"A's constructor
called";
}
};
class B{
static A a;
public:
B(){
cout<<"B's constructor
called";
}
static A get(){
return a;
}
};
A B::a; 745
int main(int argc, char const *argv[])
{
a) 3
b) 4
c) 2
d) 1
Answer: d
Explanation: As the object is defined ony once in the program at line A B::a, so the constructor of A
is called only once. For objects a1, a2 and a3 copy constructor is called so the string will not be
printed for them.

281. What happens if a user forgets to define a constructor inside a class?


a) Error occurs
b) Segmentation fault
c) Objects are not created properly
d) Compiler provides a default constructor to avoid faults/errors
Answer: d
Explanation: The C++ compiler always provides a default constructor if one forgets to define a
constructor inside a class.

282. How many parameters does a default constructor require?


a) 1
b) 2
c) 0
d) 3
Answer: c
Explanation: A default constructor does not require any parameters for object creation that’s why
sometimes we declare an object without any parameters.

283. How constructors are different from other member functions of the class?
a) Constructor has the same name as the class itself
b) Constructors do not return anything
c) Constructors are automatically called when an object is created
d) All of the mentioned
Answer: d
Explanation: All the above mention are the reasons where constructor differs from other normal
member functions of a class.

284. How many types of constructors are there in C++?


746
a) 1
b) 2
c) 3
d) 4
Answer: c
Explanation: There are three types of constructors in C++ namely default, parameterized and copy
constructor.

283. What is the difference between constructors and destructors?


a) They have a different function name
b) Constructors does not have return type whereas destructors do have
c) Constructors allow function parameters whereas destructors do not
d) Constructors does not function parameters
Answer: d
Explanation: All the above mention are the reasons where constructor differs from other normal
member functions of a class

284. How many Destructors are allowed in a Class?


a) 1
b) 2
c) 3
d) Any number
Answer: a
Explanation: A class in C++ allows only onedestructor, which is called whenever the lifetime of an
object ends.

285. Which of the following constructors are provided by the C++ compiler if not defined in a class?
a) Default constructor
b) Assignment constructor
c) Copy constructor
d) All of the mentioned
Answer: d
Explanation: If a programmer does not define the above constructors in a class the C++ compiler
by default provides these constructors to avoid error on basic operations.

286. When a copy constructor is called?


a) When an object of the class is returnedby value
b) When an object of the class is passed by value to a function
c) When an object is constructed based on another object of the same class
d) All of the mentioned
Answer: d
Explanation: Copy constructor is called in allthe above-mentioned criteria because in all the above
cases we are somehow trying to copy one object into another.

287. Pick the other name of operator function.


a) function overloading
b) operator overloading
c) member overloading
747
d) object overloading
Answer: b
Explanation: Operator function means operation defined for that operator so if user defines a
function for an operator then that is called operator overloading i.e. overloading already present
operator function.

288. Which of the following operators can’t be overloaded?


a) ::
b) +
c) –
d) []
Answer: a
Explanation: :: operator cannot be overloaded because this operator operates on names rather than
values and C++ has no syntax for writing codes that works on names than values so using syntax
these operators cannot be overloaded.

289. How to declare operator function?


a) operator sign
b) operator
c) name of the operator
d) name of the class
Answer: a
Explanation: We have to declare the operator function by using the operator, operator sign. Example
“operator +” wherethe operator is a keyword and + is the symbol need to be overloaded.

290. Which of the following statements is NOT valid about operator overloading?
a) Only existing operators can beoverloaded
b) The overloaded operator must have at least one operand of its class type
c) The overloaded operators follow the syntax rules of the original operator
d) None of the mentioned
Answer: b
Explanation: The overloaded operator must not have at least one operand of its class type.

291. Operator overloading is


a) making c++ operator works with objects
b) giving new meaning to existing operator
c) making the new operator
d) adding operation to the existing operators
Answer: d
Explanation: Operator overloading is the way adding operation to the existing operators.

292. Which operator is having the right to left associativity in the following?
a) Array subscripting
b) Function call
c) Addition and subtraction
d) Type cast
Answer: d
Explanation: There are many rights to left associativity operators in C++, which means they are
748
evaluation is done from right to left. Type Cast is one of them. Here is a link of the associativity of
operators: [Link] docs/blob/master/docs/cpp/cpp-built-in-
[Link]

293. Which operator is having the highest precedence?


a) postfix
b) unary
c) shift
d) equality
Answer: a
Explanation: The operator which is having the highest precedence is postfix and lowest is equality.

294. What is this operator called ?:?


a) conditional

b) relational
c) casting operator
d) unrelational
Answer: a
Explanation: In this operator, if the condition is true means, it will return the first operator, otherwise
second operator.

295. What will be the output of the following C++ code?

1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int a;
6. a = 5 + 3 * 5;
7. cout << a;
8. return 0;9.
}
a) 35
b) 20
c) 25
d) 30
Answer: b
Explanation: Because the * operator is having highest precedence, So it is executed first and then
the + operator will be executed.
Output:
$ g++ [Link]
$ [Link]
20

Explanation: Because the dynamic_cast operator is used to convert from base class to derived
749
class.

296. What is the use of dynamic_cast


operator?
a) it converts virtual base class to derived class
b) it converts the virtual base object to derived objects
c) it will convert the operator based on precedence
d) it converts the virtual base object to derived class
Answer: a
Explanation: Because the dynamic_cast operator is used to convert from base class to
derived class.

750
297. What will be the output of the following C++ code?
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int a = 5, b = 6, c, d;
6. c = a, b;
7. d = (a, b);
8. cout << c << ' ' << d;
9. return 0;
10. }
a) 5
b) 6
c) 6
d) 6
Answer: a
Explanation: It is a separator here. In C, thevalue a is stored in c and in d the value b is stored in d
because of the bracket.
Output:
$ g++ [Link]
$ a.out5 6

298. What will be the output of the following C++ code?

1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int i, j;
6. j = 10;
7. i = (j++, j + 100, 999 + j);
8. cout << i;
9. return 0;
10. }

a) 1000
b) 11
c) 1010
d) 1001
Answer : c
Explanation: j starts with the value 10. j is then incremented to 11. Next, j is added to
100. Finally, j (still containing 11) is added to 999 which yields the result 1010.
Output:

751
$ g++ [Link]
$ [Link]
1010

299. What will be the output of the following C++ code?


1. #include <iostream>
2. using namespace std;
3. int main ()
4. {
5. int x, y;
6. x = 5;
7. y = ++x * ++x;
8. cout << x << y;
9. x = 5;
10. y = x++ * ++x;
11. cout << x << y;
12. return 0;
13. }
a) 749735
b) 736749
c) 367497
d) 367597
Answer:a
Explanation: Because of the precedence the pre-increment and post increment operator, we got
the output as 749735.
Output:
$ g++ [Link]
$ [Link]
749735

300. What will be the output of the following C++ code?


1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int a = 5, b = 6, c;
6. c = (a > b) ? a : b;
7. cout << c;
8. return 0;9.
}
a) 6
b) 5
c) 4
d) 7
Answer: a
752
Explanation: Here the condition is false on conditional operator, so the b value is assigned to c.
Output:

$ g++ [Link]
$ [Link]
6

301. What will be the output of the following C++ code?

1. #include <iostream>
2. using namespace std;
3. main()
4. {
5. double a = 21.09399;
6. float b = 10.20;
7. int c ,d;
8. c = (int) a;
9. d = (int) b;
10. cout << c <<' '<< d;
11. return 0;
12. }

a) 20
b) 10
c) 21
d) 10
Answer: c
Explanation: In this program, we are casting the operator to integer, So it is printing as 21 and 10.
Output:
$ g++ [Link]
$ [Link]
21 10

302. How are many sequences of statements present in c++?


a) 4
b) 3
c) 5
d) 6
Answer: c
Explanation: There are five sequences ofstatements. They are Preprocessor directives, Comments,
Declarations, Function Declarations, Executable statements.

303. The if..else statement can be replaced by which operator?


a) Bitwise operator
b) Conditional operator

753
c) Multiplicative operator
d) Addition operator
Answer: b
Explanation: In the conditional operator, it will predicate the output using the givencondition.

304. The switch statement is also called as?


a) choosing structure
b) selective structure
c) certain structure
d) bitwise structure
Answer: b
Explanation: The switch statement is used to choose the certain code to execute, So it is also called
as selective structure.

305. What will be the output of the following C++ code?

1. #include <iostream>
2. using namespace std;
3. int main ()
4. {
5. int n;
6. for (n = 5; n > 0; n--)
7. {
8. cout << n;
9. if (n == 3)
10. break;
11. }
12. return 0;
13. }

a) 543
b) 54
c) 5432
d) 53
Answer: a
Explanation: In this program, We are printing the numbers in reverse order but by using break
statement we stopped printing on 3.
Output:
$ g++ [Link]
$ [Link]
543

306. What will be the output of thefollowing C++ code?

754
1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int a = 10;
6. if (a < 15)
7. {
8. time:
9. cout << a;
10. goto time;
11. }
12. break;
13. return 0;
14. }
a) 1010
b) 10
c) infinitely print 10
d) compile time error
Answer: d
Explanation: Because the break statement need to be presented inside a loop or a switch
statement.

307. What will be the output of thefollowing C++ code?

1. #include <iostream>
2. using namespace std;
3. int main()
4. {
5. int n = 15;
6. for ( ; ;)
7. cout << n;
8. return 0;9.
}
a) error
b) 15
c) infinite times of printing n
d) none of the mentioned
Answer: c
Explanation: There is not a condition in the for loop, So it will loop continuously.

308. What will be the output of thefollowing C++ code?

1. #include <iostream>
2. using namespace std;
3. int main()
755
4. {
5. int i;
6. for (i = 0; i < 10; i++);
7. {
8. cout << i;9. }
10. return 0;
11. }
a) 0123456789
b) 10
c) 012345678910
d) compile time error
Answer: b
Explanation: for loop with a semicolon is called as body less for loop. It is used only for
incrementing the variable values. So in this program the value is incremented and printed as 10.
Output:
$ g++ [Link]
$ [Link]
10

309. How many types of loops are there in C++?


a) 4
b) 2
c) 3
d) 1
Answer: a
Explanation: There are four types of loop. They are the while, do while, nested, for the loop.

310. Which looping process is best used when the number of iterations is known?
a) for
b) while
c) do-while
d) all looping processes require that the iterations be known
Answer: a
Explanation: Because in for loop we are allowed to provide starting and ending conditions of loops,
hence fixing the number of iterations of loops, whereas nosuch things are provided by other loops.

311. Which of the following is the default return value of functions in C++?
a) int
b) char
c) float
d) void
Answer: a
Explanation: C++ uses int as the default return values for functions. It also restricts that the return
type of the main function must be int.

312. What happens to a function defined inside a class without any complex operations (like
looping, a large number of lines, etc)?
756
a) It becomes a virtual function of the class
b) It becomes a default calling function of
the class
c) It becomes an inline function of the class
d) The program gives an error
Answer: c
Explanation: Any function which is defined inside a class and has no complex operations like loops,
a large number of lines then it is made inline.

313. What is an inline function?


a) A function that is expanded at each call during execution
b) A function that is called during compile time
c) A function that is not checked for syntax errors
d) A function that is not checked for semantic analysis
Answer: a
Explanation: Inline function is those which are expanded at each call during the execution of the
program to reduce the cost of jumping during execution.

314. An inline function is expanded during


a) compile-time
b) run-time
c) never expanded
d) end of the program
Answer: a
Explanation: An inline function is expanded during the compile-time of a program.

315. How many ways of passing a parameter are there in c++?


a) 1
b) 2
c) 3
d) 4
Answer: c
Explanation: There are three ways of passing a parameter. They are pass byvalue,pass by reference
and pass by pointer.

316. Which is used to keep the call by reference value as intact?


a) static
b) const
c) absolute
d) virtual
Answer: b
Explanation: Because const will not change the value of the variables during the execution.

317. By default how the value are passed inc++?


a) call by value
b) call by reference
c) call by pointer
d) call by object
757
Answer: a
Explanation: None.

318. What will be the output of the following C++ code?

1. #include <iostream>
2. using namespace std;
3. void copy (int& a, int& b, int&c)

4. {
5. a *= 2;
6. b *= 2;
7. c *= 2;
8. }
9. int main ()
10. {
11.
int x = 1, y = 3, z = 7;
12. copy (x, y, z);
13. cout << "x =" << x << ", y ="
<< y << ", z =" << z;
return 0;
}
14.
15.

a) 2 5 10
b) 2 4 5
c) 2 6 14
d) 2 4 9
Answer: c
Explanation: Because we multiplied the values by 2 in the copy function.
Output:
$ g++ [Link]
$ [Link]
x = 2,y = 6,z = 14

319. What will happen when we use void in argument passing?


a) It will not return value to its caller
b) It will return value to its caller
c) Maybe or may not be return any value to its caller
d) It will return value with help of object
Answer: a
Explanation: As void is not having any return value, it will not return the value to the caller.

320. What will be the output of the following C++ code?

758
1. #include <iostream>
2. using namespace std;
3. void Sum(int a, int b, int & c)
4. {
5. a = b + c;
6. b = a + c;
7. c = a + b;
8. }
9. int main()
10. {
11. int x = 2, y =3;
12. Sum(x, y, y);
13. cout << x << " " << y;
14. return 0;
15. }

a) 2 3
b) 6 9
c) 2 15
d) compile time error
Answer: c
Explanation: We have passed three values and it will manipulate according to the given condition
and yield the result as 2 15
Output:

$ g++ [Link]
$ [Link]
2 15

321. What is Inheritance in C++?


a) Wrapping of data into a single class
b) Deriving new classes from existing classes
c) Overloading of classes
d) Classes with same names
Answer: b
Explanation: Inheritance is the concept of OOPs in which new classes are derived from existing
classes in order to reuse the properties of classes defined earlier.

322. How many specifiers are used to derive a class?


a) 1
b) 2
c) 3
d) 4
Answer: c
Explanation: There are 3 specifiers used to derive a class. They are private, protected and public.

323. Which specifier makes all the datamembers and functions of base class inaccessible by the
derived class?
759
a) private
b) protected
c) public
d) both private and protected
Answer: a
Explanation: Private access specifier is used to make all the data members and functions of the
base class inaccessible.

324. If a class is derived privately from a base class then_______________________.


a) no members of the base class is inherited
b) all members are accessible by the derived class
c) all the members are inherited by the class but are hidden and cannot be accessible
d) no derivation of the class gives an error
Answer: c
Explanation: Whenever a class is derived, all the members of the base class is inherited by the
derived class but are not accessible by the derived class.

325. What is a virtual function in C++?


a) Any member function of a class
b) All functions that are derived from the base class
c) All the members that are accessing base class data members
d) All the functions which are declared in the base class and is re-defined/overridden by the derived
class
Answer: d
Explanation: Virtual function is a function that is declared inside the base class and is re-defined
inside the derived class.

326. Which is the correct syntax of declaring a virtual function?


a) virtual int func();
b) virtual int func(){};
c) inline virtual func();
d) inline virtual func(){};
Answer: a
Explanation: To make a function virtualfunction we just need to add virtual keyword at the starting
of the function declaration.

327. What will be the output of the following C++ code?

760
#include <iostream>
#include <string>
using namespace std;
class A{
float d;
public:
virtual void func(){
cout<<"Hello this is class
A\n";
}
};

class B: public A{
int a = 15;
public:
void func(){
cout<<"Hello this is class
B\n";
}
};

int main(int argc, char const *argv[])


{
B b;
[Link]();
return 0;
}

a) Hello this is class B


b) Hello this is class A
c) Error
d) Segmentation fault
Answer: a
Explanation: Normal execution of the program and object calls func() from class B.

328. What will be the output of the following C++ code?

761
#include <iostream>
#include <string>
using namespace std;
class A
{
float d;
public:
virtual void func(){
cout<<"Hello this is class
A\n";
}
};

class B: public A
{
int a = 15;
public:
void func(){
cout<<"Hello this is class
B\n";
}
};

int main(int argc, char const *argv[])


{
A *a;
a->func();
return 0;
}

a) Hello this is class A


b) Hello this is class B
c) Error
d) Segmentation Fault
Answer: d
Explanation: As object ‘a’ is a pointer object and we know every pointer needs to be initialised
memory before use. Hence segmentation fault. Use A *a = new A(); to initialise memory to the
object.

329. Which statement is incorrect about virtual function.


a) They are used to achieve runtime polymorphism
b) They are used to hide objects
c) Each virtual function declaration starts with the virtual keyword
d) All of the mentioned
Answer: b
Explanation: Virtual function are used to achieve runtime polymorphism by callingthe right function
762
during runtime. Their declaration starts with a virtual keyword.

330. The concept of deciding which function to invoke during runtime is called ______________
a) late binding
b) dynamic linkage
c) static binding
d) both late binding and dynamic linkage
Answer: d
Explanation: The concept of deciding which function to invoke during runtime is called late binding
or dynamic linkage. Late binding because function binding to the object is done during runtime.
Dynamic linkage because this binding is done during runtime.

331. What is a pure virtual function?


a) A virtual function defined inside the base class
b) A virtual function that has no definition relative to the base class
c) A virtual function that is defined insidethe derived class
d) Any function that is made virtual
Answer: b
Explanation: A virtual function that has no definition relative to the base class is calleda pure virtual
function.

332. Which attribute specifies a unique alphanumeric identifier to be associated with an element?
a) class
b) id
c) article
d) html
Answer: b
Explanation: HTML is Hyper Text Markup Language which is used to create web pages and
applications. The id attribute is most used to point to a style in a style sheet, and by JavaScript (via
the HTML DOM) to manipulate the element with the specific id. Class is a name given to HTML
elements which can be used by CSS and JavaScript for styling the web pages. A self-contained
content is called attribute.

333. The attribute specifies an inline style associated with an element,


which determines the rendering of the affected element.
a) dir
b) style
c) class
d) article
Answer: b
Explanation: Style attribute specifies an inline style for an element. The style attribute will override
any style set globally,
e) g. styles specified in the style tag or in an external style sheet. A self-contained content is called
attribute. Class is a name given to HTML elements which can be used by CSS and JavaScript for
styling the web pages. List of directory files is given by dir tag which is not supported in HTML5.

334. Which attribute is used to provide an advisory text about an element or its contents?
a) tooltip
763
b) dir
c) title
d) head
Answer: c
Explanation: The extra information about an element is specified by title tag. The information is
most often shown as a tooltip text when the mouse moves over the element. List of directory files
is given by dir tag which is not supported in HTML5. Tooltip or else infotip is a graphical user
interface of an element. Container of metadata is called head.

335. The attribute sets the text direction as related to the lang attribute.
a) lang
b) sub
c) dir
d) ds
Answer: c
Explanation: The dir attribute specifies the text direction of the element’s content. List of directory
files is given by dir tag which is not supported in HTML5. The language of an element’s content is
given by lang attribute. The subscript text is defined by sub attribute.

336. Which of the following is the attribute that specifies the column name from the data source
object that supplies the bound data?
a) dataFormatAs
b) datafld
c) disabled
d) datasrc
Answer: b
Explanation: DataFormatAs specifies how data is rendered. The identifier for data source is set by
dataSrc. Datafld attribute specifies the column name from the data source object that supplies the
bound data. This attribute is specific to Microsoft’s data binding. A Disabled is a boolean attribute
which specifies that <input> element should be disabled.

337. Which of the following is the attribute that indicates the name of the data source object that
supplies the data that is bound to this element?
a) dataFormatAs
b) datafld
c) disabled
d) datasrc
Answer: d
Explanation: The identifier for data source is set by dataSrc. When the dataSrc property is applied
to a tabular data consumer, the entire data set is repeated by the consuming elements.
DataFormatAs specifies how data is rendered. A Disabled isa boolean attribute which specifies that
<input> element should be disabled.

338. Which of the following is the attribute that specifies additional horizontal space, in pixels, to
be reserved on either side of an embedded item like an iframe, applet, image, and so on?
a) height
b) hspace
c) hidefocus
764
d) datasrc
Answer: b
Explanation: Height of element is pixels is specified by height attribute. The hspace attribute
specifies the whitespace on left and right side of an object. The hidefocus specifies whether a
focused rectangle is drawn around an object. The identifier for data source is set by dataSrc.

339. The accesskey attribute specifies a keyboard navigation accelerator for the element.
a) True
b) False
Answer: a
Explanation: The accesskey attribute specifies a shortcut key to activate/focus an element. It
specifies a keyboard navigation accelerator for the element. We can use accesskey attribute in
forms or links.

340. Which feature was already introduced before HTML5?


a) Canvas/SVG
b) Video
c) Geolocation
d) Frames
Answer: d
Explanation: Until recently you could not draw on the web and graphics were not very interactive
but canvas/SVG which were introduced by HTML5 solved all the problems. Video, Geolocation were
also new features introduced by HTML5. Frames were already there before the launch of HTML5.

341. Which tag is used with JavaScript?


a) <canvas>
b) <table>
c) <article>
d) <footer>
Answer: a
Explanation: <canvas> tag is basically used for graphics via scripting i.e. usually with Java Script
(scripting language, basically used to create animations). Other tags like <table>, <article>, <footer>
can be used simply with HTML.

342. What application can one create even before the introduction of HTML5?
a) Web applications
b) Mobile applications
c) Forms
d) Browser based games
Answer: c
Explanation: With the help of HTML5 and JavaScript it became possible to create excellent mobile
applications, browser based games, web applications and many more other applications. Forms
were already introduced before HTML5.

343. JavaScript Code can be called by using ______________


a) RMI
b) Triggering Event
c) Preprocessor
765
d) Function/Method
Answer: d
Explanation: JavaScript code can be called by making a function call to the element on which
JavaScript has to be run. There are many other methods like onclick, onload, and onsubmit etc.

344. The type of a variable that is volatile is ___________________


a) Volatile variable
b) Mutable variable
c) Immutable variable
d) Dynamic variable
Answer: b
Explanation: The variables whose values can be changed are called mutable variable types. In
JavaScript, only objects and arrays are mutable, not primitive values.

345. A hexadecimal literal begins with________________


a) 00
b) 0x
c) 0X
d) Both 0x and 0X
Answer: d
Explanation: Generally, X or x denotes hexadecimal values. So, any integer literal that begins with
0X or 0x denotes a hexadecimal number.

346. The generalised syntax for a real number representation is


a) [digits][.digits][(E|e)[(+|-)]digits]
b) [digits][+digits][(E|e)[(+|-)]digits]
c) [digits][(E|e)[(+|-)]digits]
d) [.digits][digits][(E|e)[(+|-)]digits]
Answer: a
Explanation: Floating-point literals may also be represented using exponential notation: a real
number followed by the letter e (or E), followed by an optional plus or minus sign, followed by an
integer exponent. This notation represents the real number multiplied by 10 to the power of the
exponent.

347. JavaScript when there is an indefinite or an infinite value during an arithmetic


computation.
a) Prints an exception error
b) Prints an overflow error
c) Displays “Infinity”
d) Prints the value as such
Answer: c
Explanation: When the result of a numericoperation is larger than the largest representable number
(overflow), JavaScript prints the value as Infinity. Similarly, when a negative value becomes larger
than the largest representable negative number, the result is negative infinity. The infinite values
behave as you would expect: adding, subtracting, multiplying, or dividing them by anything results
in an infinite value (possibly with the sign reversed).
348. Which of the following is not considered as an error in JavaScript?
a) Syntax error
766
b) Missing of semicolons
c) Division by zero
d) Missing of Bracket
Answer: c
Explanation: Division by zero is not an error in JavaScript: it simply returns infinity or negative
infinity. There is one exception, however: zero divided by zero does not have a well defined value,
and the result of this operation is the special not-a-number value, printed as NaN.

349. The escape sequence ‘\f’ stands for


a) Floating numbers
b) Representation of functions that returns a value
c) \f is not present in JavaScript
d) Form feed
Answer: d
Explanation: \f is the JavaScript escape sequence that stands for Form feed (\u000C). It skips to
the start of the next page. (Applies mostly to terminals where the output device is a printer rather
than a VDU).

350. The snippet that has to be used to check if “a” is not equal to “null” is
a) if(a!=null)
b) if (!a)
c) if(a!null)
d) if(a!==null)
Answer: d
Explanation: A strict comparison (e.g., ===) is only true if the operands are of the same type and the
contents match. The more commonly-used abstract comparison (e.g. ==) converts the operands
to the same type before making the comparison. The not- equal operator !== compares 0 to null and
evaluates to either true or false.

351. The statement a===b refers to _____________


a) Both a and b are equal in value, type and reference address
b) Both a and b are equal in value
c) Both a and b are equal in value and type
d) There is no such statement
Answer: c
Explanation: ”===” operator is known as the strict comparison operator. A strict comparison (===)
is only true if the operands are of the same type and the contents match.

352. Assume that we have to convert “false” that is a non-string to string. The command that we
use is (without invokingthe “new” operator).
a) [Link]()
b) String(false)
c) String newvariable=”false”
d) Both [Link]() and String(false)
Answer: d
Explanation: The three approaches for converting to string are: [Link](),””
+ value and String(value). A non-string can be converted in two ways without using a new operator
[Link] () and String(false).
767
353. XML is a markup language.
a) meta
b) beta
c) octa
d) peta
Answer: a
Explanation: Generally speaking, a meta language is a language used to describe a language. XML
is a metalanguage that is used to describe a markup language.

354. XML uses principle to formally describe the data.


a) DDL
b) DTD
c) DML
d) None of the mentioned
Answer: b
Explanation: A document type definition (DTD) is a set of markup declarations that define a
document type for an SGML-family markup language (SGML, XML, HTML). A Document Type
Definition (DTD) defines the legal building blocks of an XML document. It defines the document
structure with a list of legal elements and attributes.

355. Which among the following are true for an Extensible markup language?
a) Human Readable/ Machine Readable
b) Extended from SGML
c) Developed by www consortium
d) All of the mentioned
Answer: d
Explanation: XML is an open format markup language with a filename extension of .xml.

356. Which of them have XML as their default format?


a) IWork
b) LibreOffice
c) OpenOffice
d) All of the mentioned
Answer: d
Explanation: More that hundred of document formats using XML syntax have been developed,
including RSS, Atom, SOAP and XHTML.

357. A DTD is associated with a XML file by means of


a) Function
b) <!DOCTYPE>
c) Macros
d) None of the mentioned
Answer: b
Explanation: A document type definition defines the legal building blocks of an XML document .

358. Which of the following is not an example of electronic mark up?

768
a) HTML
b) LaTeX
c) PostScript
d) None of the mentioned
Answer: d
Explanation: There are three categories of electronic markup: presentational, procedural, and
descriptive markup. Examples are XML, HTML, LaTeX, etc.

359. troff and nroff are in Unix.


a) functions
b) typesetting tools
c) System sofwares
d) None of the mentioned
Answer: b
Explanation: Early examples of computer markup languages can be found in typesetting tools like
troff and nroff in Unix.

360. Which of the following is not OOPS concept in Java?


a) Inheritance
b) Encapsulation
c) Polymorphism
d) Compilation
Answer: d
Explanation: There are 4 OOPS concepts in Java. Inheritance, Encapsulation, Polymorphism and
Abstraction.

361. Which of the following is a type of polymorphism in Java?


a) Compile time polymorphism
b) Execution time polymorphism
c) Multiple polymorphism
d) Multilevel polymorphism
Answer: a
Explanation: There are two types of polymorphism in Java. Compile time polymorphism
(overloading) and runtime polymorphism (overriding).

362. When does method overloading is determined?


a) At run time
b) At compile time
c) At coding time
d) At execution time
Answer: b
Explanation: Overloading is determined at compile time. Hence, it is also known as compile time
polymorphism.

363. What is the range of short data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
769
d) None of the mentioned
Answer: b
Explanation: Short occupies 16 bits in memory. Its range is from -32768 to 32767.

364. What is the range of byte data type in Java?


a) -128 to 127
b) -32768 to 32767
c) -2147483648 to 2147483647
d) None of the mentioned
Answer: a
Explanation: Byte occupies 8 bits in memory. Its range is from -128 to 127.

365. How constructor can be used for a servlet?


a) Initialization
b) Constructor function
c) Initialization and Constructor function
d) Setup() method
Answer: c
Explanation: We cannot declare constructors for interface in Java. This means we cannot enforce
this requirement to any class which implements Servlet interface. Also, Servlet requires
ServletConfig object for initialization which is created by container.

366. Can servlet class declare constructor with ServletConfig object as an argument?
a) True
b) False
Answer: b
Explanation: ServletConfig object is createdafter the constructor is called and before init() is called.
So, servlet init parameters cannot be accessed in the constructor.

367. What is the difference between servlets and applets?


i. Servlets execute on Server; Applets execute on browser
ii. Servlets have no GUI; Applet has GUI
iii. Servlets creates static web pages;
Applets creates dynamic web pages
iv. Servlets can handle only a single request;
Applet can handle multiple requests
a) i, ii, iii are correct
b) i, ii are correct
c) i, iii are correct
d) i, ii, iii, iv are correct
Answer: b
Explanation: Servlets execute on Server and doesn’t have GUI. Applets execute on browser and has
GUI.

368. Which of the following code is used to get an attribute in a HTTP Session object in servlets?
a) [Link](String name)
b) [Link](String name)
c) [Link](String name)
770
d) [Link](String name)
Answer: a
Explanation: session has various methods for use.

369. Which of these functions is called to display the output of an applet?


a) display()
b) paint()
c) displayApplet()
d) PrintApplet()
Answer: b
Explanation: Whenever the applet requires to redraw its output, it is done by using method paint().

370. Which of these methods can be used to output a string in an applet?


a) display()
b) print()
c) drawString()
d) transient()
Answer: c
Explanation: drawString() method is defined in Graphics class, it is used to output a string in an
applet.

371. Which of these methods is a part of Abstract Window Toolkit (AWT) ?


a) display()
b) paint()
c) drawString()
d) transient()
Answer: b
Explanation: paint() is an abstract method defined in AWT.

372. Which of these modifiers can be used for a variable so that it can be accessed from any thread
or parts of a program?
a) transient
b) volatile
c) global
d) No modifier is needed
Answer: b
Explanation: The volatile modifier tells the compiler that the variable modified by volatile can be
changed unexpectedly by other part of the program. Specially used in situations involving
multithreading.

373. The most commonly used input device is


a) Mouse
b) Keyboard
c) Scanner
d) Printer
Answer: b
Explanation: Keyboard is the most commonly used input device.
374. Which keys allows user to enter frequently used operations in a single key stroke?
771
a) Function keys
b) Cursor control keys
c) Trackball
d) Control keys
Answer: a
Explanation: Function keys are used to access frequently used areas.

375. are used to measure dial rotations.


a) Potentiometers
b) Volta meter
c) Parameter
d) Only a
Answer: d
Explanation: Potentiometer measures thedial rotations.

376. The device which is used to position the screen cursor is


a) Mouse
b) Joystick
c) Data glove
d) Both a and c
Answer: a
Explanation: A mouse is small hand-held box used to position the screen cursor.

377. is used for detecting mouse motion.


a) Optical sensor
b) Rollers on the bottom of mouse
c) Both a and b
d) Sensor
Answer: c
Explanation: Rollers and optical sensors are used to record the amount and direction of movement.

378. The Cartesian slope-intercept equationfor a straight line is


a) y = m.x + b
b) y = b.x + m
c) y = x.x + m
d) y = b + m.m
Answer: a
Explanation: Equation for a straight line is y = m.x + b.

379. For lines with slope magnitude |m|<1, ?x can be


a) A set corresponding vertical deflection
b) A set proportional to a small horizontal deflection voltage
c) Only a
d) All of the mentioned
Answer: b
Explanation:?x can be a set proportional to a small horizontal deflection voltage only if slope
magnitude |m| < 1.
380. On raster system, lines are plotted with
772
a) Lines
b) Dots
c) Pixels
d) None of the mentioned
Answer: c
Explanation: Using pixels lines can be plotted.

381. Expansion of line DDA algorithm is


a) Digital difference analyzer
b) Direct differential analyzer
c) Digital differential analyzer
d) Data differential analyzer
Answer: c
Explanation: DDA stands for digital differential analyzer.

382. Which algorithm is a faster method forcalculating pixel positions?


a) Bresenham’s line algorithm
b) Parallel line algorithm
c) Mid-point algorithm
d) DDA line algorithm
Answer: d
Explanation: The DDA is a faster method for calculating pixel positions.

383. The function which references a single attribute that specifies how a primitive is to be
displayed with that attribute setting is called
a) Individual attribute
b) Unbundled attribute
c) Bundled attribute
d) A or B
Answer: d
Explanation: Individual attribute are also known as unbundled attribute.

384. A particular set of attribute values for aprimitive on each output device is chosen by specifying
appropriate table index is known as?
a) Individual attribute
b) Unbundled attribute
c) Bundled attribute
d) A or B
Answer: c
Explanation: Bundle attributes specifies group of attribute values. And these values can be bundled
into the workstation table.

385. A table for which, a primitive defines groups of attribute values to be used whendisplaying that
primitive on a particular output device is called
a) Bundle table
b) Index table
c) Both a and b
d) None of these
773
Answer: a
Explanation: None.

386. The choice between a bundled attribute or an unbundled attribute is made by


a) Setting switch
b) Setting bundle table
c) Index table
d) Only a
Answer: d
Explanation: By setting switch the user can change their choice between bundled attribute or an
unbundled attribute.

387. A translation is applied to an object by


a) Repositioning it along with straight line path
b) Repositioning it along with circular path
c) Only b
d) All of the mentioned
Answer: a
Explanation: A translation is applied to an object by repositioning it along with straight line path
from one location to another.

388. We translate a two-dimensional point by adding


a) Translation distances
b) Translation difference
c) X and Y
d) Only a
Answer: d
Explanation: We can translate 2D point byadding translation distances dx and dy.

389. The translation distances (dx, dy) is called as


a) Translation vector
b) Shift vector
c) Both a and b
d) Neither a nor b
Answer: c
Explanation: The translation distances (dx, dy) from its original position is called as translation
vector or shift vector.

390. In 2D-translation, a point (x, y) can move to the new position (x’, y’) by usingthe equation
a) x’=x+dx and y’=y+dx
b) x’=x+dx and y’=y+dy
c) X’=x+dy and Y’=y+dx
d) X’=x-dx and y’=y-dy
Answer: b
Explanation: By adding translation distance dx and dy to its originsl position (x, y) we can obtain a
new position (x’, y’).

391. The two-dimensional translation equation in the matrix form is


774
a) P’=P+T
b) P’=P-T
c) P’=P*T
d) P’=p
Answer: a
Explanation: The 2D translation equation is P’=P+T.

392. A two dimensional rotation is applied to an object by


a) Repositioning it along with straight line path
b) Repositioning it along with circular path
c) Only b
d) Any of the mentioned
Answer: c
Explanation: A two dimensional rotation isapplied to an object by repositioning it along with circular
path.

393. To generate a rotation , we must specify


a) Rotation angle ϴ
b) Distances dx and dy
c) Rotation distance
d) All of the mentioned
Answer: a
Explanation: Generate a rotation, we must specify rotation angle ϴ of the rotation point or pivot
point which the object is to be rotated.

394. Positive values for the rotation angle ϴ defines


a) Counterclockwise rotations about the end points
b) Counterclockwise translation about the pivot point
c) Counterclockwise rotations about the pivot point
d) Negative direction
Answer: c
Explanation: A positive value for the rotation angle ϴ defines counterclockwise rotations about the
pivot point.

395. The rotation axis that is perpendicular to the xy plane and passes through the pivot point is
known as
a) Rotation
b) Translation
c) Scaling
d) Shearing
Answer: a
Explanation: The rotation transformation is also described as a rotation about a rotation axis that
is perpendicular to the xy plane and passes through the pivot point.

396. The original coordinates of the point in polor coordinates are


a) X’=r cos (Ф +ϴ) and Y’=r cos (Ф +ϴ)
b) X’=r cos (Ф +ϴ) and Y’=r sin (Ф +ϴ)
c) X’=r cos (Ф -ϴ) and Y’=r cos (Ф -ϴ)
775
d) X’=r cos (Ф +ϴ) and Y’=r sin (Ф -ϴ)
Answer: b
Explanation: The original coordinates of the point in polor coordinates are X’=r cos (Ф
+ϴ) and Y’=r sin (Ф +ϴ).

397. The two-dimensional rotation equation in the matrix form is


a) P’=P+T
b) P’=R*P
c) P’=P*P
d) P’=R+P
Answer: b
Explanation: The 2D translation equation is P’=R*P.

398. The transformation that is used to alter the size of an object is


a) Scaling
b) Rotation
c) Translation
d) Reflection
Answer: a
Explanation: Scaling is used to alter the size of an object.

399. The two-dimensional scaling equation in the matrix form is


a) P’=P+T
b) P’=S*P
c) P’=P*R
d) P’=R+S
Answer: b
Explanation: The 2d scaling equation is P’=S*P.

400. Scaling of a polygon is done by computing


a) The product of (x, y) of each vertex
b) (x, y) of end points
c) Center coordinates
d) Only a
Answer: d
Explanation: Scaling of a polygon is done by computing the product of (x, y) of each vertex with
scaling factor sx and sy to produce the transformation coordinates ( Xnew, Ynew).
401. If the scaling factors values sx and sy < 1 then
a) It reduces the size of object
b) It increases the size of object
c) It stunts the shape of an object
d) None
Answer: a
Explanation: If the scaling factors values sx and sy < 1 then it reduces the size of object.

402. If the scaling factors values sx and sy are assigned to the same value then
a) Uniform rotation is produced
b) Uniform scaling is produced
776
c) Scaling cannot be done
d) Scaling can be done or cannot be done
Answer: b
Explanation: When sx and sy are assigned the same value then uniform scaling is produced that
maintains relative object proportions.

403. The matrix representation for translation in homogeneous coordinates is


a) P’=T+P
b) P’=S*P
c) P’=R*P
d) P’=T*P
Answer: d
Explanation: The matrix representation for translation is P’=T*P.

104. The matrix representation for scaling in homogeneous coordinates is


a) P’=S*P
b) P’=R*P
c) P’=dx+dy
d) P’=S*S
Answer: a
Explanation: The matrix representation for scaling is P’=S*P.

405. The matrix representation for rotation in homogeneous coordinates is


a) P’=T+P
b) P’=S*P
c) P’=R*P
d) P’=dx+dy
Answer: c
Explanation: The matrix representation for rotation is P’=R*P.

406. What is the use of homogeneous coordinates and matrix representation?


a) To treat all 3 transformations in a consistent way
b) To scale
c) To rotate
d) To shear the object
Answer: a
Explanation: To treat all 3 transformations in a consistent way, we use homogeneous coordinates
and matrix representation.

407. Two successive translations are


a) Multiplicative
b) Inverse
c) Subtractive
d) Additive
Answer: d
Explanation: Successive translations are additive.
P’= T(tx1, ty1) .[T(tx2, ty2)] P
= {T(tx1, ty1). T(tx2, ty2)}.P
777
Or T(tx1, ty1). T(tx2, ty2) = T(tx1+tx2 , ty1 + ty2).

408. Two successive translations are not commutative.


a) True
b) False
Answer: b
Explanation: According to commutative property, the order does not matter. Same as in the case of
successive translations. Hence we can say that two successive translations are commutative.

409. General pivot point rotation can beexpressed as


a) T(zr,yr).R(θ).T(-zr,-yr) = R(xr,yr,θ)
b) T(xr,yr).R(θ).T(-xr,-yr) = R(xr,yr,θ)
c) T(xr,yr).R(θ).T(-xr,-yr) = R(zr,yr,θ)
d) T(xr,yr).R(θ).T(-xr,-yr) = R(xr,yr,Q)
Answer: b
Explanation: Since the first two parameters are in 2D, hence only ‘x’ and ‘y’ can be variable along
with ‘θ’. In other options, there is one more parameter ‘z’.

410. Which of the following is NOT correct?(A, B and C are matrices)


a) A.B = B.A
b) A.B.C = (A.B).C = A.(B.C)
c) C(A+B) = C.A + C.B
d) 1 A = A 1
Answer: a
Explanation: Matrix multiplication does not commute. We cannot switch the order of the factors
and expect to end up with the same result. Hence, A.B ≠ B.A.

411. Reflection about the line y=0, the axis, is accomplished with the transformation matrix with
how many elements as ‘0’?
a) 8
b) 9
c) 4
d) 6
Answer: d
Explanation: The matrix used for reflection about y=0 is an identity matrix with 6 ‘0’s and two ‘1’s
and one element as ‘-1’.

412. In a rotation, by how much angle is the object rotated?


a) 45 degree
b) 90 degree
c) 180 degree
d) 360 degree
Answer: c
Explanation: Reflection is the mirror image of the original object. It rotates the object 1890 degrees.
The left side image is formed

413. Reflection is a special case of rotation.


778
a) True
b) False
Answer: b
Explanation: Reflection is a special case of rotation of 180° about a line in xy plane passing through
the origin.

414. If two pure reflections about a line passing through the origin are applied successively the
result is _____________________.
a) Pure rotation
b) Quarter rotation
c) Half rotation
d) True reflection
Answer: a
Explanation: When we apply reflection onetime, it rotates the image by 180 degrees. So, if we repeat
it 2 times the total reflection will be of 360 degrees.

415. What is the determinant of the pure reflection matrix?


a) 1
b) 0
c) -1
d) 2
Answer: c
Explanation: The pure reflection matrix is:
[T] = | 1 0 |
| 0 -1|
So, the determinant will be = (1) (-1) – (0) (0) = 0.

416. Shearing is also termed as______________


a) Selecting
b Sorting
c) Scaling
d) Skewing
Answer: d
Explanation: In the case of shear only one coordinate changes its coordinates and other preserves
its values, that’s why it is also called skewing.

417. Shearing and reflection are types of translation.


a) True
b) False
Answer: b
Explanation: Shearing and reflection are not types of translation. They are types of transformation.
Even translation is also a type of transformation.

418. Which of this is compulsory for 2D reflection.


a) Reflection plane.
b) Origin
c) Reflection axis
d) Co-ordinate axis.
779
Answer: c
Explanation: Reflection axis is the axis with respect to which reflection is done. In 3D, it is reflection
plane rather than reflection axis.

419. A view is selected by specifying a sub- area of the picture area.


a) half
b) total
c) full
d) quarter
Answer: b
Explanation: We consider a formal mechanism of view, that is, which part of the picture is to be
displayed. That’s why we select a view by specifying a sub-area of the total picture area.

420. Co-ordinates are ranging according to the screen resolution.


a) True
b) False
Answer: a
Explanation: When we display a scene, only those objects which have a particular window are
displayed. So for that mechanism to work, co-ordinates are made to range themselves according to
the screen resolution.

422. Any convenient co-ordinate system or Cartesian co-ordinates which can be used to define the
picture is called
a) spherical co-ordinates
b) vector co-ordinates
c) viewport co-ordinates
d) world co-ordinates
Answer: d
Explanation: World Coordinate Systems (WCS) are the type of coordinate systems which describe
the physical coordinates associated with a data array, such as sky coordinates. It is also used to
denote wavelengths of a spectrum and to draw astronomical images.

423. The object space or the space in which the application model is defined is called__________
a) World co-ordinate system
b) Screen co-ordinate system
c) World window
d) Interface window
Answer: a
Explanation: World Coordinate System also called as WCS is any coordinate systems that describe
the physical coordinates associated with a data array. They also used for an astronomical image,
or for determining the wavelength scale for a spectrum.

424. What is the name of the space in which the image is displayed?
a) World co-ordinate system
b) Screen co-ordinate system
c) World window
d) Interface window
Answer: b
780
Explanation: The coordinate system of the screen is a Cartesian coordinate system.
The origin (0,0) is at the top left of the screen. Point is denoted by (x,y), where x is x co-ordinate and
y is y co-ordinate.

425. What is the rectangle in the world defining the region that is to be displayed?
a) World co-ordinate system
b) Screen co-ordinate system
c) World window
d) Interface window
Answer: c
Explanation: The world window specifies which part of the window needs to be drawn. It also
defines which part of the window should be drawn and which part outside the window should not
be drawn and should be clipped away.

426. What is the primary use of clipping in computer graphics?


a) adding graphics
b) removing objects and lines
c) zooming
d) copying
Answer: b
Explanation: The primary use of clipping in computer graphics is to remove objects, lines, or line
segments that are outside theviewing pane.

427. A polygon can be clipped using clipping operations.


a) True
b) False
Answer: a
Explanation: A polygon can also be clipped by specifying the clipping window. Sutherland
Hodgeman polygon clipping algorithm is used for polygon clipping.

428. Which vertex of the polygon is clipped first in polygon clipping?


a) top right
b) bottom right
c) bottom left
d) top left
Answer: d
Explanation: In polygon clipping, first the polygon is clipped against the left edge of the polygon
window to get new vertices of the polygon. So, it is the top left which is clipped first.

429. How many methods of text clipping are there?


a) 5
b) 4
c) 3
d) 2
Answer: c
Explanation: There are three methods for text clipping which are −
1) All or none string clipping 2) All or none character clipping 3) Text clipping.
430. A bitmap is collection of that describes an image.
781
a) bits
b) colors
c) algorithms
d) pixels
Answer: d
Explanation: A bitmap is a collection of pixels that describe an image. It is a type of computer
graphics that the computer uses to store and display pictures.

431. We can change the size or resize the bitmap image.


a) True
b) False
Answer: b
Explanation: We can’t resize the bitmap image. When the bitmap image is resized, the image pixels
get distorted. It is one of the main disadvantages of the bitmap.

432. In line clipping, the portion of line which is of window is cut and the portion that is
thewindow is kept.
a) outside, inside
b) inside, outside
c) exact copy, different
d) different, an exact copy
Answer: a
Explanation: Line clipping follows the same algorithm that is in the case of point clipping. So, in line
clipping also, we will cut the portion of the line which is outside of the window and keep only the
portion that is inside the window.

433. Cohen-Sutherland clipping is an example of


a) polygon clipping
b) text clipping
c) line clipping
d) curve clipping
Answer: c
Explanation: It is a type of algorithm which is used for line clipping or in other words it is line clipping
algorithm. Other examples of line clipping algorithms are a Liang-Barsky algorithm and Cyrus-Beck
algorithm.

434. The Cohen-Sutherland algorithm divides the region into number of spaces.
a) 8
b) 6
c) 7
d) 9
Answer: d
Explanation: The Cohen-Sutherland algorithm divides a two-dimensional space into 9 regions and
then efficiently determines the lines and portions of lines that are visible. The portions are visible
in the central region of interest.

435. What is the name of the small integer which holds a bit for the result of every

782
plane test?
a) setcode
b) outcode
c) incode
d) bitcode
Answer: b
Explanation: A small integer holding a bit for the result of every plane test failed in clipping is
termed as outcode. Primitives may be trivially rejected if the bitwise of all its vertices outcodes is
non zero.

436. An outcode can have bits for two- dimensional clipping and bits for
three-dimensional clipping. a) 4,6
b) 6,8
c) 2,4
d) 1,3
Answer: a
Explanation: The outcode will have 4 bits for two-dimensional clipping, or 6 bits in the three-
dimensional case. The first bit is set to 1 if the point is above the viewport. The bits in the 2D
outcode represent: top, bottom, right, left.

783
Database Management System
Database Management System or DBMS in short refers to the technology of storing and retrieving
usersí data with utmost efficiency along with appropriatesecurity measures.

Database is a collection of related data and data is a collection of facts and figures that can be
processed to produce information.
Mostly data represents recordable facts. Data aids in producing information, which is based on
facts. For example, if we have data about marks obtained by all students, we can then conclude
about toppers and average marks.

A database management system stores data in such a way that it becomes easier to retrieve,
manipulate, and produce information.
Database Management System or DBMS in short refers to the technology of storing and retrieving
usersí data with utmost efficiency along with appropriatesecurity measures.

Characteristics
Traditionally, data was organized in file formats. DBMS was a new concept then, and all the
research was done to make it overcome the deficiencies in traditional style of data management.
A modern DBMS has the following characteristics −
• Real-world entity − A modern DBMS is more realistic and uses real-world entities to design its
architecture. It uses the behavior and attributes too. For example, a school database may use
students as an entity and their ageas an attribute.
• Relation-based tables − DBMS allows entities and relations among them to form tables. A user
can understand the architecture of a database just by looking at the table names.
• Isolation of data and application − A database system is entirely different than its data. A
database is an active entity, whereas data is said to be passive, on which the database works and
organizes. DBMS also stores metadata, which is data about data, to ease its own process.
• Less redundancy − DBMS follows the rules of normalization, which splits a relation when any of
its attributes is having redundancy in values. Normalization is a mathematically rich and scientific
process that reduces data redundancy.
• Consistency − Consistency is a state where every relation in a database remains consistent.
There exist methods and techniques, which can detectattempt of leaving database in inconsistent
state. A DBMS can provide greater consistency as compared to earlier forms of data storing
applications like file-processing systems.
• Query Language − DBMS is equipped with query language, which makes it more efficient to
retrieve and manipulate data. A user can apply as many, and as different filtering options as
required to retrieve a set of data. Traditionally it was not possible where file-processing system
was used.
• ACID Properties − DBMS follows the concepts
of Atomicity, Consistency, Isolation, and Durability (normally shortened as ACID). These concepts
are applied on transactions, which manipulate data in a database. ACID properties help the
database stay healthy in multi- transactional environments and in case of failure.

784
• Multiuser and Concurrent Access − DBMS supports multi-user environment and allows them to
access and manipulate data in parallel. Though there are restrictions on transactions when users
attempt to handle the same data item, but users are always unaware of them.
• Multiple views − DBMS offers multiple views for different users. A user who is in the Sales
department will have a different view of database than a
person working in the Production department. This feature enables theusers to have a concentrate
view of the database according to their requirements.
• Security − Features like multiple views offer security to some extent where users are unable to
access data of other users and departments. DBMS offers methods to impose constraints while
entering data into the database and retrieving the same at a later stage. DBMS offers many
different levels of security features, which enables multiple users to have different views with
different features. For example, a user in the Sales department cannotsee the data that belongs to
the Purchase department. Additionally, it can also be managed how much data of the Sales
department should be displayed to the user. Since a DBMS is not saved on the disk as traditional
file systems, it is very hard for miscreants to break the code.

Users
A typical DBMS has users with different rights and permissions who use it for different purposes.
Some users retrieve data and some back it up. The users of aDBMS can be broadly categorized as
follows −
• Administrators − Administrators maintain the DBMS and are responsible for administrating the
database. They are responsible to look after its usageand by whom it should be used. They create
access profiles for users and apply limitations to maintain isolation and force security.
Administrators
also look after DBMS resources like system license, required tools, and other software and
hardware related maintenance.
• Designers − Designers are the group of people who actually work on the designing part of the
database. They keep a close watch on what data should be kept and in what format. They identify
and design the whole setof entities, relations, constraints, and views.
• End Users − End users are those who actually reap the benefits of having aDBMS. End users can
range from simple viewers who pay attention to the logs or market rates to sophisticated users
such as business analysts.

Applications of DBMS
Database is a collection of related data and data is a collection of facts and figures that can be
processed to produce information.
Mostly data represents recordable facts. Data aids in producing information, which is based on
facts. For example, if we have data about marks obtained by all students, we can then conclude
about toppers and average marks.
A database management system stores data in such a way that it becomes easier to retrieve,
manipulate, and produce information. Following are the important characteristics and
applications of DBMS.

785
• ACID Properties − DBMS follows the concepts
of Atomicity, Consistency, Isolation, and Durability (normally shortened as ACID). These concepts
are applied on transactions, which manipulate data in a database. ACID properties help the
database stay healthy in multi- transactional environments and in case of failure.
• Multiuser and Concurrent Access − DBMS supports multi-user environment and allows them to
access and manipulate data in parallel. Though there are restrictions on transactions when users
attempt to handle the same data item, but users are always unaware of them.
Multiple views − DBMS offers multiple views for different users. A user who is in the Sales
department will have a different view of database than a person working in the Production
department. This feature enables the users to have a concentrate view of the database according
to their requirements.
• Security − Features like multiple views offer security to some extent where users are unable to
access data of other users and departments. DBMS offers methods to impose constraints while
entering data into the database and retrieving the same at a later stage. DBMS offers many
different levels of security features, which enables multiple users to have different views with
different features. For example, a user in the Sales department cannotsee the data that belongs to
the Purchase department. Additionally, it can also be managed how much data of the Sales
department should be displayed to the user. Since a DBMS is not saved on the disk as traditional
file systems, it is very hard for miscreants to break the code.
DBMS - Architecture
The design of a DBMS depends on its architecture. It can be centralized or decentralized or
hierarchical. The architecture of a DBMS can be seen as either single tier or multi-tier. An n-tier
architecture divides the whole system into related but independent n modules, which can be
independently modified, altered, changed, or replaced.
In 1-tier architecture, the DBMS is the only entity where the user directly sits onthe DBMS and uses
it. Any changes done here will directly be done on the DBMS itself. It does not provide handy tools
for end-users. Database designers and programmers normally prefer to use single-tier
architecture.
If the architecture of DBMS is 2-tier, then it must have an application through which the DBMS can
be accessed. Programmers use 2-tier architecture where they access the DBMS by means of an
application. Here the application tier isntirely independent of the database in terms of operation,
design, andprogramming.
3- tier Architecture
A 3-tier architecture separates its tiers from each other based on the complexity of the users and
how they use the data present in the database. It is the most widely used architecture to design a
DBMS.

786
• Database (Data) Tier − At this tier, the database resides along with its query processing
languages. We also have the relations that define the dataand their constraints at this level.
• Application (Middle) Tier − At this tier reside the application server and the programs that
access the database. For a user, this application tier presents an abstracted view of the database.
End-users are unaware of any existence of the database beyond the application. At the other end,
the database tier is not aware of any other user beyond the application tier. Hence, the application
layer sits in the middle and acts as a mediator between the end-user and the database.
• User (Presentation) Tier − End-users operate on this tier and they know nothing about any
existence of the database beyond this layer. At this
ayer, multiple views of the database can be provided by the application. All views are generated by
applications that reside in the application tier.
Multiple-tier database architecture is highly modifiable, as almost all its components are
independent and can be changed independently.
Data Models
Data models define how the logical structure of a database is modeled. Data Models are
fundamental entities to introduce abstraction in a DBMS. Data models define how data is
connected to each other and how they are processed and stored inside the system.
The very first data model could be flat data-models, where all the data used are to be kept in the
same plane. Earlier data models were not so scientific; hence they were prone to introduce lots of
duplication and update anomalies.
Entity-Relationship Model
Entity-Relationship (ER) Model is based on the notion of real-world entities and relationships
among them. While formulating real-world scenario into the database model, the ER Model
creates entity set, relationship set, general attributes and constraints.
ER Model is best used for the conceptual design of a database.

ER Model is based on −
o Entities and their attributes.
o Relationships among entities. These concepts are explained below.
o Entity − An entity in an ER Model is a real-world entity having properties called
attributes. Every n
o attribute is defined by its set of values
called domain. For example, in a school database, a student is considered as an
entity. Student has various attributes like name, age, class, etc.
o Relationship − The logical association among entities is called relationship.
Relationships are mapped with entities in various ways. Mapping cardinalities define
the number of association between two entities.
Mapping cardinalities −

787
▪ one to one
▪ one to many

▪ many to one
▪ many to many

Relational Model

The most popular data model in DBMS is the Relational Model. It is more scientific a model than
others. This model is based on first-order predicate logic and defines a table as an n-ary relation.

The main highlights of this model are −

• Data is stored in tables called relations.


• Relations can be normalized.
• In normalized relations, values saved are atomic values.
• Each row in a relation contains a unique value.
• Each column in a relation contains values from a same domain.

Data Schemas
A database schema is the skeleton structure that represents the logical view of the entire
database. It defines how the data is organized and how the relations among them are associated.
It formulates all the constraints that are to be applied on the data.
A database schema defines its entities and the relationship among them. It contains a descriptive
detail of the database, which can be depicted by means of schema diagrams. It’s the database
designers who design the schema to help programmers understand the database and make it
useful.

A database schema can be divided broadly into two categories −


788
• Physical Database Schema − This schema pertains to the actual storage of data and its form of
storage like files, indices, etc. It defines how the data will be stored in a secondary storage.
• Logical Database Schema − This schema defines all the logical constraints that need to be
applied on the data stored. It defines tables, views, and integrity constraints.

Database Instance

It is important that we distinguish these two terms individually. Database schemais the skeleton of
database. It is designed when the database doesn't exist at all. Once the database is operational,
it is very difficult to make any changes to it. A database schema does not contain any data or
information.
A database instance is a state of operational database with data at any given time. It contains a
snapshot of the database. Database instances tend to change with time. A DBMS ensures that its
every instance (state) is in a valid state, by diligently
following all the validations, constraints, and conditions that the databasedesigners have imposed.

Three schema Architecture


• The three-schema architecture is also called ANSI/SPARC architecture or three-level
architecture.
• This framework is used to describe the structure of a specific databasesystem.
• The three-schema architecture is also used to separate the user applications and physical
database.
• The three-schema architecture contains three-levels. It breaks the database down into three
different categories.
The three-schema architecture is as follows:
In the above diagram:
• It shows the DBMS architecture.

• Mapping is used to transform the request and response between various database levels of
architecture.
• Mapping is not good for small DBMS because it takes more time.

• In External / Conceptual mapping, it is necessary to transform the request from external


level to conceptual schema.
• In Conceptual / Internal mapping, DBMS transform the request from the conceptual to
internal level.
1. Internal Level

o The internal level has an internal schema which describes the physical storage structure of
the database.
o The internal schema is also known as a physical schema.

o It uses the physical data model. It is used to define that how the data will be stored in a
789
block.
o The physical level is used to describe complex low-level data structures indetail.

2. Conceptual Level
o he conceptual schema describes the design of a database at the conceptual level.
Conceptual level is also known as logical level.
o The conceptual schema describes the structure of the whole database.
o The conceptual level describes what data are to be stored in the database and also
describes what relationship exists among those data.
o In the conceptual level, internal details such as an implementation of the data structure are
hidden.
o Programmers and database administrators work at this level.

3. External Level
o At the external level, a database contains several schemas that sometimes called as
subschema. The subschema is used to describe the different viewof the database.
o An external schema is also known as view schema.
o Each view schema describes the database part that a particular user groupis interested and
hides the remaining database from that user group.
o The view schema describes the end user interaction with database systems.

Data Independence
If a database system is not multi-layered, then it becomes difficult to make any changes in the
database system. Database systems are designed in multi-layers aswe learnt earlier.
Data Independence
A database system normally contains a lot of data in addition to users’ data. Forexample, it stores
data about data, known as metadata, to locate and retrieve data easily. It is rather difficult to
modify or update a set of metadata once it is stored in the database. But as a DBMS expands, it
needs to change over time tosatisfy the requirements of the users. If the entire data is dependent,
it would become a tedious and highly complex job.
Metadata itself follows a layered architecture, so that when we change data at one layer, it does
not affect the data at another level. This data is independentbut mapped to each other.
790
Logical Data Independence
Logical data is data about database, that is, it stores information about how data is managed
inside. For example, a table (relation) stored in the database and all its constraints, applied on that
relation.
Logical data independence is a kind of mechanism, which liberalizes itself from actual data stored
on the disk. If we do some changes on table format, it should not change the data residing on the
disk.

Physical Data Independence


All the schemas are logical, and the actual data is stored in bit format on the disk. Physical data
independence is the power to change the physical data without impacting the schema or logical
data.
For example, in case we want to change or upgrade the storage system itself − suppose we want
to replace hard-disks with SSD − it should not have any impacton the logical data or schemas.

Database Language
• A DBMS has appropriate languages and interfaces to express databasequeries and updates.
• Database languages can be used to read, store and update the data inthe database.

Types of Database Language


1. Data Definition Language
• DDL stands for Data Definition Language. It is used to define databasestructure or pattern.
• It is used to create schema, tables, indexes, constraints, etc. in thedatabase.
• Using the DDL statements, you can create the skeleton of the database.
• Data definition language is used to store the information of metadata like the number of tables
and schemas, their names, indexes, columns ineach table, constraints, etc.

Some tasks that come under DDL:


• Create: It is used to create objects in the database.
• Alter: It is used to alter the structure of the database.
• Drop: It is used to delete objects from the database.
• Truncate: It is used to remove all records from a table.
• Rename: It is used to rename an object.
• Comment: It is used to comment on the data dictionary.
These commands are used to update the database schema that's why they come under Data
definition language.
2. Data Manipulation Language
DML stands for Data Manipulation Language. It is used for accessing and manipulating data in a
database. It handles user requests.

Some tasks that come under DML:


• Select: It is used to retrieve data from a database.
791
• Insert: It is used to insert data into a table.
• Update: It is used to update existing data within a table.
• Delete: It is used to delete all records from a table.
• Merge: It performs UPSERT operation, i.e., insert or update operations.
all: It is used to call a structured query language or a Java subprogram.
• Explain Plan: It has the parameter of explaining data.
• Lock Table: It controls concurrency.

3. Data Control Language


• DCL stands for Data Control Language. It is used to retrieve the stored orsaved data.
• The DCL execution is transactional. It also has rollback parameters.
(But in Oracle database, the execution of data control language does not have thefeature of rolling
back.)

Some tasks that come under DCL:


• Grant: It is used to give user access privileges to a database.
• Revoke: It is used to take back permissions from the user.
There are the following operations which have the authorization of Revoke: CONNECT, INSERT,

USAGE, EXECUTE, DELETE, UPDATE and SELECT.

4. Transaction Control Language


TCL is used to run the changes made by the DML statement. TCL can be grouped into a logical
transaction.

Some tasks that come under TCL:


• Commit: It is used to save the transaction on the database.
• Rollback: It is used to restore the database to original since the lastCommit.

DBMS Interface
A database management system (DBMS) interface is a user interface which allows for the ability
to input queries to a database without using the query language
itself. A DBMS interface could be a web client, a local client that runs on a desktop computer, or
even a mobile app.
A database management system stores data and responds to queries using a query language,
such as SQL. A DBMS interface provides a way to query data without having to use the query
language, which can be complicated.
The typical way to do this is to create some kind of form that shows what kinds of queries users
can make. Web-based forms are increasingly common with the popularity of MySQL, but the
traditional way to do it has been local desktop apps. It is also possible to create mobile
applications. These interfaces provide a friendlier way of accessing data rather than just using the
command line.
User-friendly interfaces provide by DBMS may include the following:

792
1. Menu-Based Interfaces for Web Clients or Browsing –

These interfaces present the user with lists of options (called menus) that lead the user through
the formation of a request. Basic advantage of using menus is that they remove the tension of
remembering specific commands and syntax of any query language, rather than query is basically
composed step by step by collecting or picking options from a menu that isbasically shown by the
system. Pull-down menus are a very popular technique in Web based interfaces. They are also
often used in browsing interface which allow a user to look through the contents of a database in
an exploratory and unstructured manner.
2. Forms-Based Interfaces –
A forms-based interface displays a form to each user. Users can fill out all of the form entries to
insert a new data, or they can fill out only certain entries, in which case the DBMS will redeem
same type of data for other remaining entries. This type of forms are usually designed or created
and programmed for the users that have no expertise in operating system.
Many DBMSs have forms specification languages which are special languages that help specify
such forms.

Example: SQL* Forms is a form-based language that specifies queries using a form designed in
conjunction with the relational database schema.b>
3. Graphical User Interface –
A GUI typically displays a schema to the user in diagrammatic form. The user then can specify a
query by manipulating the diagram. In many cases, GUIs utilize both menus and forms. Most GUIs
use a pointing device such as mouse, to pick certain part of the displayed schema diagram.
4. Natural language Interfaces –
These interfaces accept request written in English or some other language and attempt to
understand them. A Natural language interface has its own schema, which is similar to the
database conceptual schema as well as a dictionary of important words.
793
The natural language interface refers to the words in its schema as well as to the set of standard
words in a dictionary to interpret the request. If the interpretation is successful, the interface
generates a high-level query corresponding to the natural language and submits it to the DBMS for
processing, otherwise a dialogue is started with the user to clarify any provided condition or
request. The main disadvantage with this is that the capabilities of this type of interfaces are not
that much advance.
5. Speech Input and Output –
There is a limited use of speech say it for a query or an answer to a question or being a result of a
request, it is becoming commonplace Applications with limited vocabularies such as inquiries for
telephone directory, flight arrival/departure, and bank account information are allowed speech for
input and output to enable ordinary folks to access thisinformation.
The Speech input is detected using a predefined words and used to set upthe parameters that are
supplied to the queries. For output, a similar conversion from text or numbers into speech take
place.

6. Interfaces for DBA –


Most database system contains privileged commands that can be used only by the DBA’s staff.
These include commands for creating accounts, setting system parameters, granting account
authorization, changing a schema, reorganizing the storage structures of a databases.

Centralized and Client-Server DBMS Architectures:


Centralized DBMS:
a) Merge everything into single system including- Hardware, DBMS software, application
programs, and user interface processing software.
b) User can still connect by a remote terminal – but all processing is done atcentralized site.

Physical Centralized Architecture:


Architectures for DBMS have pursued trends similar to those generating computer system
architectures. Earlier architectures utilized mainframes computers to provide the main processing
for all system functions including user application programs as well as user interface programs
as well all DBMS functionality. The reason was that the majority of users accessed such systems
via computer terminals that did not have processing power and only provided display capabilities.
Thus, all processing was performed remotely on the computer system and only display
information and controls were sent from the computer to the display terminals which were
connected to central computer via a variety of typesof communication networks.
As prices of hardware refused most users replaced their terminals with PCs and workstations. At
first database systems utilized these computers similarly to how they have used is play terminals
so that DBMS itself was still a Centralized DBMS in which all the DBMS functionality application
program execution and user interface processing were carried out on one Machine.

Basic 2-tier Client-Server Architectures:


➢ Specialized Servers with Specialized functions

794
➢ Print server
➢ File server
➢ DBMS server
➢ Web server
➢ Email server
➢ Clients are able to access the specialized servers as needed

Logical two-tier client server architecture:


Clients:
➢ Offer appropriate interfaces through a client software module to access as well as utilize
the various server resources.
➢ Clients perhaps diskless machines or PCs or Workstations with disks with only the client
software installed.
➢ Connected to the servers by means of some form of a network. (LAN- local area network,
wireless network and so on.)
DBMS Server:

Provides database query as well as transaction services to the clients


➢ Relational DBMS servers are habitually called query servers, SQL servers, or transaction
servers
➢ Applications running on clients use an Application Program Interface (API)to access server
databases via standard interface such as:
➢ ODBC- Open Database Connectivity standardJDBC- for Java programming access
➢ Client and server should install appropriate client module and server module software for
ODBC or JDBC

Two Tier Client-Server Architecture:

➢ A client program may perhaps connect to several DBMSs sometimes called the data
sources.
➢ In general data sources are able to be files or other non-DBMS software thatmanages data.
Other variations of clients are likely- example in some object DBMSs more functionality is
transferred to clients including data dictionary functions, optimization as well as recovery
across multiple servers etc.

Three Tier Client-Server Architecture:

a) Common for Web applications.


b) Intermediate Layer entitled Application Server or Web Server.
c) Stores the web connectivity software as well as the business logic part of the application
used to access the corresponding data from the database server.
d) Acts like a conduit for sending moderately processed data between the database server and
the client.

795
e) Three-tier Architecture is able to Enhance Security:
i. Database server merely accessible via middle tier.
ii. clients can’t directly access database server.
Classification of DBMS's:
• Based on the data model used
• Traditional- Network, Relational, Hierarchical.
• Emerging- Object-oriented and Object-relational.
• Other classifications
• Single-user (typically utilized with personal computers) v/s multi-user (mostDBMSs).
• Centralized (utilizes a single computer with one database) v/s distributed (uses multiple
computers and multiple databases)

Variations of Distributed DBMSs (DDBMSs):


➢ Homogeneous DDBMS
➢ Heterogeneous DDBMS
➢ Federated or Multi-database Systems
➢ Distributed Database Systems have at the present come to be known as client-server-
based database systems because
➢ They don’t support a totally distributed environment however rather a set of database
servers supporting a set of clients.

Cost considerations for DBMSs:


➢ Cost Range- from free open-source systems to configurationscosting millions of dollars
➢ Instances of free relational DBMSs- MySQL, PostgreSQL andothers.

Data Modelling
Data modeling (data modelling) is the process of creating a data model for the data to be stored
in a Database. This data model is a conceptual representation of Data objects, the associations
between different data objects and the rules. Data modeling helps in the visual representation of
data and enforces business rules, regulatory compliances, and government policies on the data.
Data Models ensure consistency in naming conventions, default values, semantics, security while
ensuring quality of the data.

Data Model
Data model is defined as an abstract model that organizes data description, data semantics and
consistency constraints of data. Data model emphasizes on what data is needed and how it
should be organized instead of what operations will be performed on data. Data Model is like
architect's building plan which helps building conceptual models and set relationship between
data items.
The two types of Data Models techniques are
1. Entity Relationship (E-R) Model
2. UML (Unified Modelling Language)
796
Why use Data Model?
The primary goal of using data model is:

• Ensures that all data objects required by the database are accurately represented.
Omission of data will lead to creation of faulty reports andproduce incorrect results.
• A data model helps design the database at the conceptual, physical andlogical levels.
• Data Model structure helps to define the relational tables, primary and foreign keys and
stored procedures.
• It provides a clear picture of the base data and can be used by database developers to
create a physical database.
• It is also helpful to identify missing and redundant data.
• Though the initial creation of data model is labor and time consuming, in the long run, it
makes your IT infrastructure upgrade and maintenance cheaper and faster.

Types of Data Models


Types of Data Models: There are mainly three different types of data models: conceptual data
models, logical data models and physical data models and each one has a specific purpose. The
data models are used to represent the data and how it is stored in the database and to set the
relationship between data items.
1. Conceptual Data Model: This Data Model defines WHAT the system contains. This model
is typically created by Business stakeholders and Data Architects. The purpose is to
organize, scope and define business conceptsand rules.
2. Logical Data Model: Defines HOW the system should be implemented regardless of the
DBMS. This model is typically created by Data Architects and Business Analysts. The
purpose is to be developed technical map of rulesand data structures.
3. Physical Data Model: This Data Model describes HOW the system will be implemented
using a specific DBMS system. This model is typically created by DBA and developers. The
purpose is actual implementation of the database.

Types of Data Model

Conceptual Data Model


A Conceptual Data Model is an organized view of database concepts and their relationships. The
purpose of creating conceptual data model is to establish entities, their attributes and
relationships. In this data modeling level, there is hardly any detail available of the actual database
structure. Business stakeholdersand data architects typically create a conceptual data model.
The 3 basic tenants of Conceptual Data Model are

• Entity: A real-world thing


• Attribute: Characteristics or properties of an entity
• Relationship: Dependency or association between two entities

797
Data model example:

1. Customer and Product are two entities. Customer number and name are attributes of the
Customer entity
2. Product name and price are attributes of product entity
3. Sale is the relationship between the customer and product
4. Conceptual Data Model

Characteristics of a conceptual data model


• Offers Organization-wide coverage of the business concepts.
• This type of Data Models is designed and developed for a businessaudience.
• The conceptual model is developed independently of hardware specifications like data storage
capacity, location or software specifications like DBMS vendor and technology. The focus is to
represent data as a user will see it in the "real world."
Conceptual data models known as Domain models create a common vocabulary for all
stakeholders by establishing basic concepts and scope.

Logical Data Model


The Logical Data Model is used to define the structure of data elements and to set relationships
between them. Logical data model adds further information to the conceptual data model
elements. The advantage of using Logical data model is to provide a foundation to form the base
for the Physical model. However, themodeling structure remains generic.

Logical Data Model


At this Data Modeling level, no primary or secondary key is defined. At this Data modeling level,
you need to verify and adjust the connector details that were setearlier for relationships.

Characteristics of a Logical data model


1. Describes data needs for a single project but could integrate with other logical data models
based on the scope of the project.
2. Designed and developed independently from the DBMS.
3. Data attributes will have datatypes with exact precisions and length.

4. Normalization processes to the model is applied typically till 3NF.

Physical Data Model


A Physical Data Model describes database specific implementation of the data model. It offers
database abstraction and helps generate schema. This is because of the richness of meta-data
offered by a Physical Data Model. Physical data model also helps in visualizing database structure
by replicating database columnkeys, constraints, indexes, triggers and other RDBMS features.

Physical Data Model


Characteristics of a physical data model:

798
• The physical data model describes data need for a single project or application though it
maybe integrated with other physical data modelsbased on project scope.
• Data Model contains relationships between tables that which addresses cardinality and
nullability of the relationships.
• Developed for a specific version of a DBMS, location, data storage or technology to be used
in the project.
• Columns should have exact datatypes, lengths assigned and default values.
• Primary and Foreign keys, views, indexes, access profiles, and authorizations, etc. are
defined.
Advantages and Disadvantages of Data Model:
Advantages of Data model:

1. The main goal of a designing data model is to make certain that dataobjects offered by the
functional team are represented accurately.
2. The data model should be detailed enough to be used for building thephysical database.
3. The information in the data model can be used for defining the relationship between tables,
primary and foreign keys, and stored procedures.
4. Data Model helps business to communicate the within and acrossorganizations.
5. Data model helps to documents data mappings in ETL process
6. Help to recognize correct sources of data to populate the model

Disadvantages of Data model:

1. To develop Data model one should know physical data storedcharacteristics.


2. This is a navigational system produces complex application development, management.
Thus, it requires a knowledge of the biographical truth.
3. Even smaller change made in structure require modification in the entireapplication.
4. There is no set data manipulation language in DBMS.

Entity Relationship (E-R) Model


The ER model defines the conceptual view of a database. It works around real- world entities and
the associations among them. At view level, the ER model is considered a good option for
designing databases.

Component of ER Diagram

ER Diagram
ER Model is represented by means of an ER diagram. Any object, for example, entities, attributes
of an entity, relationship sets, and attributes of relationship sets, can be represented with the help
of an ER diagram.

Entity
An entity can be a real-world object, either animate or inanimate, that can be easily identifiable.
799
For example, in a school database, students, teachers, classes, and courses offered can be
considered as entities. All these entities have some attributes or properties that give them their
identity.

An entity set is a collection of similar types of entities. An entity set may contain entities with
attribute sharing similar values. For example, a Students set may contain all the students of a
school; likewise a Teachers set may contain all the teachers of a school from all faculties. Entity
sets need not be disjoint.
An entity may be any object, class, person or place. In the ER diagram, an entitycan be represented
as rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be
taken as an entity.

a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any
key attribute of its own. The weak entity is represented by adouble rectangle.

Attributes
Entities are represented by means of their properties, called attributes. All attributes have values.
For example, a student entity may have name, class, andage as attributes.
There exists a domain or range of values that can be assigned to attributes. For example, a
student's name cannot be a numeric value. It has to be alphabetic. A student's age cannot be
negative, etc.
Attributes are the properties of entities. Attributes are represented by means of ellipses. Every
ellipse represents one attribute and is directly connected to its entity (rectangle).
If the attributes are composite, they are further divided in a tree like structure. Every node is then
connected to its attribute. That is, composite attributes are represented by ellipses that are
connected with an ellipse.

Multivalued attributes are depicted by double ellipse.


Derived attributes are depicted by dashed ellipse.

Types of Attributes
1. Simple attribute − Simple attributes are atomic values, which cannot be divided further. For
example, a student's phone number is an atomic valueof 10 digits.
2. Composite attribute − Composite attributes are made of more than one simple attribute.
For example, a student's complete name may have first name and last-named.
3. Derived attribute − Derived attributes are the attributes that do not exist in the physical
database, but their values are derived from other attributes present in the database. For
example, average salary in a department

4. should not be saved directly in the database, instead it can be derived. Foranother example,
age can be derived from data_of_birth.
800
5. Single-value attribute − Single-value attributes contain single value. For example −
Social_Security_Number.
6. Multi-value attribute − multi-value attributes may contain more than one values. For
example, a person can have more than one phone number, email address, etc.
These attribute types can come together in a way like −

➢ simple single-valued attributes


➢ simple multi-valued attributes
➢ composite single-valued attributes
➢ composite multi-valued attributes

Entity-Set and Keys


Key is an attribute or collection of attributes that uniquely identifies an entityamong entity set.
For example, the roll number of a student makes him/her identifiable amongstudents.
• Super Key − A set of attributes (one or more) that collectively identifies anentity in an entity
set.
• Candidate Key − A minimal super key is called a candidate key. An entity setmay have more
than one candidate key.
• Primary Key − A primary key is one of the candidate keys chosen by the database designer
to uniquely identify the entity set.

Relational Database Design (RDD) mean


Relational database design (RDD) models information and data into a set of tables with rows and
columns. Each row of a relation/table represents a record, and each column represents an
attribute of data. The Structured Query Language (SQL) is used to manipulate relational
databases. The design of a relational database is composed of four stages, where the data are
modeled into a set of related tables. The stages are:
➢ Define relations/attributes
➢ Define primary keys
➢ Define relationships
➢ Normalization

Relational Database Design (RDD)


Relational databases differ from other databases in their approach to organizing data and
performing transactions. In an RDD, the data are organized into tables and all types of data
access are carried out via controlled transactions. Relational database design satisfies the ACID
(atomicity, consistency, integrity and durability) properties required from a database design.
Relational database design mandates the use of a database server in applications for dealing with
datamanagement problems.

The four stages of an RDD are as follows:


• Relations and attributes: The various tables and attributes related to each table are
identified. The tables represent entities, and the attributes represent the properties of the
801
respective entities.
• Primary keys: The attribute or set of attributes that help in uniquely identifying a record is
identified and assigned as the primary key
• Relationships: The relationships between the various tables are established with the help of
foreign keys. Foreign keys are attributes occurring in a table that are primary keys of
another table. The types of relationships thatcan exist between the relations (tables) are:

o One to one
o One to many
o Many to many

An entity-relationship diagram can be used to depict the entities, their attributes and the
relationship between the entities in a diagrammatic way.
• Normalization: This is the process of optimizing the database structure. Normalization
simplifies the database design to avoid redundancy and confusion. The different normal forms
are as follows:
• First normal form
• Second normal form
• Third normal form
• Boyce-Codd normal form
• Fifth normal form
By applying a set of rules, a table is normalized into the above normal forms in a linearly
progressive fashion. The efficiency of the design gets better with each higher degree of
normalization.

Relationship
The association among entities is called a relationship. For example, an employee works at a
department, a student enrolls in a course. Here, Works atand enrolls are called relationships.
A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.

Types of relationship are as follows:


a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known as one-to-
one relationship.
For example, A female can marry to one male, and a male can marry to onefemale
One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an entity on the
right associates with the relationship then this is known as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is done by the only specific
scientist.
b. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity on the
right associates with the relationship then it is known as a many-to-one relationship.
802
For example, Student enrolls for only one course, but a course can have manystudents.
c. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on
the right associates with the relationship then it is knownas a many-to-many relationship.
For example, Employee can assign by many projects and projects can have manyemployees.
Participation Constraints

• Total Participation − Each entity is involved in the relationship. Total participation is


represented by double lines.
• Partial participation − Not all entities are involved in the relationship. Partial participation is
represented by single lines.

Relationship Set
A set of relationships of similar type is called a relationship set. Like entities, arelationship too can
have attributes. These attributes are called descriptive attributes.

Degree of Relationship
The number of participating entities in a relationship defines the degree of therelationship.
• Binary = degree 2
• Ternary = degree 3
• n-ary = degree

Mapping Cardinalities
Cardinality defines the number of entities in one entity set, which can be associated with the
number of entities of other set via relationship set.
• One-to-one − One entity from entity set A can be associated with at most one entity of
entity set B and vice versa.
• One-to-many − One entity from entity set A can be associated with more than one entity of
entity set B however an entity from entity set B, can beassociated with at most one entity.
• Many-to-one − More than one entity from entity set A can be associated with at most one
entity of entity set B, however an entity from entity set B can be associated with more than
one entity from entity set A.
• Many-to-many − One entity from A can be associated with more than oneentity from B and
vice versa.
Notation of ER diagram
Database can be represented using the notations. In ER diagram, many notations are used to
express the cardinality. These notations are as follows:

Fig: Notations of ER diagram


Relational Model concept
Relational model can represent as a table with columns and rows. Each row is known as a tuple.
Each table of the column has a name or attribute.
Domain: It contains a set of atomic values that an attribute can take.
Attribute: It contains the name of a column in a particular table. Each attribute Ai must have a
803
domain, dom (Ai)

Relational instance: In the relational database system, the relational instance is represented by a
finite set of tuples. Relation instances do not have duplicate tuples.
Relational schema: A relational schema contains the name of the relation andname of all columns
or attributes.
Relational key: In the relational key, each row has one or more attributes. It can identify the row in
the relation uniquely.

Example: STUDENT Relation

NAME ROLL_NO PHONE_NO ADDRESS AGE

Ram 14795 7305758992 Noida 24

Shyam 12839 9026288936 Delhi 35

Laxman 33289 8583287182 Gurugram 20

Mahesh 27857 7086819134 Ghaziabad 27

Ganesh 17282 9028 9i3988 Delhi 40

➢ In the given table, NAME, ROLL_NO, PHONE_NO, ADDRESS, and AGE arethe attributes.
➢ The instance of schema STUDENT has 5 tuples.
➢ t3 = <Laxman, 33289, 8583287182, Gurugram, 20>

Properties of Relations

➢ Name of the relation is distinct from all other relations.


➢ Each relation cell contains exactly one atomic (single) value
➢ Each attribute contains a distinct name
➢ Attribute domain has no significance
➢ tuple has no duplicate value
➢ Order of tuple can have a different sequence

804
Constraints on Relational database model
On modeling the design of the relational database, we can put some restrictions like what values
are allowed to be inserted in the relation, what kind of modifications and deletions are allowed in
the relation. These are the restrictionswe impose on the relational database.
In models like ER models, we did not have such features.
Constraints in the databases can be categorized into 3 main categories:

1. Constraints that are applied in the data model is called Implicit constraints.
2. Constraints that are directly applied in the schemas of the data model, byspecifying them in
the DDL (Data Definition Language). These are called as schema-based constraints or
Explicit constraints.
3. Constraints that cannot be directly applied in the schemas of the data model. We call these
Application based or semantic constraints.
4. So here we will deal with Implicit constraints.

Mainly Constraints on the relational database are of 4 types:


1. Domain constraints
2. Key constraints
3. Entity Integrity constraints
4. Referential integrity constraints
1. Domain constraints:
• Every domain must contain atomic values (smallest indivisible units) it means composite
and multi-valued attributes are not allowed.
• We perform datatype check here, which means when we assign a data typeto a column we
limit the values that it can contain. E.g., If we assign the datatype of attribute age as int,
we can’t give it values other than int datatype.
Explanation:
In the above relation, Name is a composite attribute and Phone is a multi-values attribute, so it is
violating domain constraint.
2. Key Constraints or Uniqueness Constraints:
3. These are called uniqueness constraints since it ensures that every tuple in the relation should
be unique.
4. A relation can have multiple keys or candidate keys (minimal super key), outof which we choose
one of the keys as primary key, we don’t have any restriction on choosing the primary key out of
candidate keys, but it is suggested to go with the candidate key with a smaller number of
attributes.
5. Null values are not allowed in the primary key, hence Not Null constraint is also a part of key
constraint.

Explanation:
In the above table, EID is the primary key, and first and the last tuple has the same value in EID i.e.,
01, so it is violating the key constraint.

805
6. Entity Integrity Constraints:
1. Entity Integrity constraints says that no primary key can take NULL value, since using primary
key we identify each tuple uniquely in a relation.

Explanation:
In the above relation, EID is made primary key, and the primary key can’t take NULL values but in
the third tuple, the primary key is null, so it is a violating EntityIntegrity constraint.
7. Referential Integrity Constraints:

1. The Referential integrity constraints is specified between two relations or tables and used
to maintain the consistency among the tuples in two relations.
2. This constraint is enforced through foreign key, when an attribute in the foreign key of
relation R1 have the same domain(s) as the primary key of relation R2, then the foreign
key of R1 is said to reference or refer to theprimary key of relation R2.
3. The values of the foreign key in a tuple of relation R1 can either take the values of the
primary key for some tuple in relation R2, or can take NULLvalues, but can’t be empty.

Explanation:
In the above, DNO of the first relation is the foreign key, and DNO in the second relation is the
primary key. DNO = 22 in the foreign key of the first table is not allowed since DNO = 22
is not defined in the primary key of the second relation. Therefore, Referential integrity constraints
is violated here

Relational Language
Relational language is a type of programming language in which the programming logic is
composed of relations and the output is computed based on the query applied. Relational
language works on relations among data and entities to compute a result. Relational language
includes features from and is similar to functional programming language.
Relational language is primarily based on the relational data model, which governs relational
database software and systems. In the relational model’s programming context, the procedures
are replaced by the relations among values. These relations are applied over the processed
arguments or values to
construct an output. The resulting output is mainly in the form of an argument or property. The
side effects emerging from this programming logic are also handled by the procedures or
relations.
Relational language is primarily based on the relational data model, which governs relational
database software and systems. In the relational model’s programming context, the procedures
are replaced by the relations among values. These relations are applied over the processed
arguments or values to
construct an output. The resulting output is mainly in the form of an argument or property. The
side effects emerging from this programming logic are also handled by the procedures or
806
relations.

Relational Databases and Schemas


A relational database schema is an arrangement of relation states in such a manner that every
relational database state fulfills the integrity constraints set ona relational database schema.
A relational schema outlines the database relationships and structure in a relational database
program. It can be displayed graphically or written in the Structured Query Language (SQL) used
to build tables in a relational database.
A relational schema contains the name of the relation and name of all columns orattributes.
A relation schema represents name of the relation with its attributes. e.g., STUDENT (ROLL_NO,
NAME, ADDRESS, PHONE and AGE) is relation schema for STUDENT. If a schema has more than 1
relation, it is called Relational Schema.
a relational database schema is an arrangement of integrity constraints. Thus, in the context of
relational database schema following points deserve a particular consideration:

1. A specific characteristic, that bears the same real-world concept, may appear in more than
one relationship with the same or a different name. For example, in Employees relation,
Employee Id (EmpId) is represented inVouchers as AuthBy and PrepBy.
2. The specific real-world concept that appears more than once in a relationship should be
represented by different names. For example, an employee is represented as subordinate
or junior by using EmpId and as a superior or senior by using SuperId, in the employee’s
relation.
3. The integrity constraints that are specified on database schema shall apply to every
database state of that schema.

Understanding a Relational Schema


A relational schema for a database is an outline of how data is organized. It can be a graphic
illustration, or another kind of chart used by programmers to understandhow each table is laid out,
including the columns and the types of data they hold and how tables connect. It can also be
written in SQL code.
A database schema usually specifies which columns are primary keys in tables and which other
columns have special constraints such as being required to have unique values in each record. It
also usually specifies which columns in which tables contain references to data in other tables,
often by including primary keys from other table records so that rows can be easily joined. These
are called foreign key columns. For example, a customer order table may contain acustomer
number column that is a foreign key referencing the primary key of thecustomer table.

Relational Model Diagram


The figure below indicates a relation in a relational model.
It is a student relation and it is having entries of 5 students (tuples) in it. The figure below will help
you identify the relation, attributes, tuples and field in arelational model.

Update Operations, and Dealing with Constraint Violations


807
The operations of the relational model can be categorized
into retrievals and updates. The relational algebra operations, which can be used to specify
retrievals, are discussed in detail in Chapter 6. A relational algebra expression forms a new
relation after applying a number of algebraic operators to an existing set of relations; its main use
is for querying a database to retrieve information. The user formulates a query that specifies the
data of interest, and anew relation is formed by applying relational operators to retrieve this data.
That result relation becomes the answer to (or result of) the user’s query. Chapter 6 also
introduces the language called relational calculus, which is used to define the new relation
declaratively without giving a specific order of operations.
In this section, we concentrate on the
database modification or update operations. There are three basic operations that can change the
states of relations in the database: Insert, Delete, and Update (or modify). They insert new data,
delete old data, or modify existing data records. Insert is used to insert one or more new tuples in
a relation, Delete is used to delete tuples, and Update (or modify) is used to change the values of
some attributes in existing tuples. Whenever these operations are applied, the integrity
constraints specified on the relational database schema should not be violated. In this section we
discuss the types of constraints that may be violated by each of these operations and the types of
actions that may be taken if an operation causes a violation. We use the database shown in
Figure 3.6 for examples and discuss only key constraints, entity integrity constraints, and the
referential integrity constraints shown.

1. The Insert Operation


The Insert operation provides a list of attribute values for a new tuple t that is to be inserted into a
relation R. Insert can violate any of the four types of constraintsdis-cussed in the previous section.
Domain constraints can be violated if an attribute value is given that does not appear in the
corresponding domain or is not of the appropriate data type. Key constraints can be violated if a
key value in the new tuple t already exists in another tuple in the relation r(R). Entity integrity can
be violated if any part of the primary key of the new tuple t is NULL. Referential integrity can be
violated if the value of any foreign key in t refers to a tuple that does not exist in the referenced
relation. Here are some examples to illustrate this discussion.
Operation:
Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, NULL, ‘1960-04-05’, ‘6357 Windy Lane, Katy, TX’, F, 28000, NULL, 4>
into EMPLOYEE.
Result: This insertion violates the entity integrity constraint (NULL for the primary key Ssn), so it is
rejected.
Operation:
Insert <‘Alicia’, ‘J’, ‘Zelaya’, ‘999887777’, ‘1960-04-05’, ‘6357 Windy Lane, Katy, TX’, F, 28000,
‘987654321’, 4> into EMPLOYEE.
Result: This insertion violates the key constraint because another tuple with the same Ssn value
already exists in the EMPLOYEE relation, and so it is rejected.
Operation:
Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, ‘677678989’, ‘1960-04-05’, ‘6357 Windswept,
Katy, TX’, F, 28000, ‘987654321’, 7> into EMPLOYEE.
808
Result: This insertion violates the referential integrity constraint specified on Dno in EMPLOYEE
because no corresponding referenced tuple exists in
DEPARTMENT with Dnumber = 7.
Operation:
Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, ‘677678989’, ‘1960-04-05’, ‘6357 Windy Lane, Katy, TX’, F, 28000,
NULL, 4> into EMPLOYEE.
Result: This insertion satisfies all constraints, so it is acceptable.
If an insertion violates one or more constraints, the default option is to reject the insertion. In this
case, it would be useful if the DBMS could provide a reasonto the user as to why the insertion was
rejected. Another option is to attempt to correct the reason for rejecting the insertion, but this is
typically not used for violations caused by Insert; rather, it is used more often in correcting
violationsfor Delete and Update. In the first operation, the DBMS could ask the user to
provide a value for Ssn and could then accept the insertion if a valid Ssn value is provided. In
opera-tion 3, the DBMS could either ask the user to change the valueof Dno to some valid value (or
set it to NULL), or it could ask the user to insert
a DEPARTMENT tuple with Dnumber = 7 and could accept the original insertion only after such an
operation was accepted. Notice that in the latter case the insertion violation can cascade back to
the EMPLOYEE relation if the user attempts to insert a tuple for department 7 with a value for
Mgrs. that doesnot exist in the EMPLOYEE relation.

2. The Delete Operation


The Delete operation can violate only referential integrity. This occurs if the tuple being deleted is
referenced by foreign keys from other tuples in the database. To specify deletion, a condition on
the attributes of the relation selects the tuple (ortuples) to be deleted. Here are some examples.
Operation:
Delete the WORKS_ON tuple with Essn = ‘999887777’ and Pno = 10. Result: This deletion is
acceptable and deletes exactly one tuple.
Operation:
Delete the EMPLOYEE tuple with Ssn = ‘999887777’.
Result: This deletion is not acceptable, because there are tuples in WORKS_ON that refer to this
tuple. Hence, if the tuple in EMPLOYEE isdeleted, referential integrity violations will result.
Operation:
Delete the EMPLOYEE tuple with Ssn = ‘333445555’.
Result: This deletion will result in even worse referential integrity violations, because the tuple
involved is referenced by tuples fromthe EMPLOYEE,
DEPARTMENT, WORKS_ON, and DEPENDENT relations.
Several options are available if a deletion operation causes a violation. The first option, called
restrict, is to reject the deletion. The second option,
called cascade, is to attempt to cascade (or propagate) the deletion by deleting tuples that
reference the tuple that is being deleted. For example, in operation 2,
the DBMS could automatically delete the offending tuples
from WORKS_ON with Essn = ‘999887777’. A third option, called set null or set default, is to
modify the referencing attribute values that cause the violation; each such value is either set to

809
NULL or changed to reference another default valid tuple. Notice that if a referencing attribute
that causes a viola-tion is part of the primary key, it cannot be set to NULL; otherwise, it would
violate entity integrity.
Combinations of these three options are also possible. For example, to avoid having operation 3
cause a violation, the DBMS may automatically delete alltuples from WORKS_ON and DEPENDENT
with Essn = ‘333445555’. Tuples
in EMPLOYEE with Super_ssn = ‘333445555’ and the tuple in DEPARTMENT with Mgr_ssn =
‘333445555’ can have
their Super_ssn and Mgr_ssn values changed to other valid values or to NULL.
Although it may make sense to delete automatically
the WORKS_ON and DEPENDENT tuples that refer to an EMPLOYEE tuple, it may not make sense
to delete other EMPLOYEE tuples or a DEPARTMENT tuple.
In general, when a referential integrity constraint is specified in the DDL, the DBMS will allow the
database designer to specify which of the options applies in case of a violation of the constraint.
We discuss how to specify these options in the SQL DDL in Chapter 4.

3. The Update Operation


The Update (or modify) operation is used to change the values of one or more attributes in a tuple
(or tuples) of some relation R. It is necessary to specify a condition on the attributes of the
relation to select the tuple (or tuples) to be modified. Here are some examples.
Operation:
Update the salary of the EMPLOYEE tuple with Ssn = ‘999887777’ to28000. Result: Acceptable.
Operation:
Update the Dno of the EMPLOYEE tuple with Ssn = ‘999887777’ to 1. Result:Acceptable.
Operation:
Update the Dno of the EMPLOYEE tuple with Ssn = ‘999887777’ to 7. Result: Unacceptable,
because it violates referential integrity.
Operation:
Update the Ssn of the EMPLOYEE tuple with Ssn = ‘999887777’ to ‘987654321’.
Result: Unacceptable, because it violates primary key constraint by repeating a value that already
exists as a primary key in another tuple; it violates refer-ential integrity constraints because there
are other relations that refer to the existing value of Ssn.
Updating an attribute that is neither part of a primary key nor of a foreign
key usually causes no problems; the DBMS need only check to confirm that the new value is of the
correct data type and domain. Modifying a primary key value is similar to delet-ing one tuple and
inserting another in its place because we use the primary key to identify tuples. Hence, the issues
discussed earlier in both Sections 3.3.1 (Insert) and 3.3.2 (Delete) come into play. If a foreign key
attribute is modified, the DBMS must make sure that the new value refers to an existing tuple in
the referenced relation (or is set to NULL). Similar options exist to deal with referential integrity
violations caused by Update as those options discussed for the Delete operation. In fact, when a
referential integrity constraint is specified in the DDL, the DBMS will allow the user to choose
separate options to deal with a violation caused by Delete and a vio-lation caused by Update.

810
4. The Transaction Concept
A database application program running against a relational database typically executes one or
more transactions. A transaction is an executing program that includes some database
operations, such as reading from the database, or applying insertions, deletions, or updates to the
database. At the end of the transaction, it must leave the database in a valid or consistent state
that satisfies all the constraints spec-ified on the database schema. A single transaction may
involve any number of retrieval operations (to be discussed as part of relational algebra and
calculus in Chapter 6, and as a part of the language SQL in Chapters 4 and 5), and any number of
update operations. These retrievals and updates will together form an atomic unit of work against
the database. For example, a transaction to apply a bank with-drawal will typically read the user
account record, check if there is a sufficient bal-ance, and then update the record by the
withdrawal amount.
A large number of commercial applications running against relational databases in online
transaction processing (OLTP) systems are executing transactions at rates that reach several
hundred per second.

Relational Algebra
Relational algebra is a procedural query language. It gives a step-by-step process to obtain the
result of the query. It uses operators to perform queries.

Types of Relational operation

1. Select Operation:

o The select operation selects tuples that satisfy a given predicate.


o It is denoted by sigma (σ).

1. Notation: σ p(r)
Where:
σ is used for selection prediction
r is used for relation
p is used as a propositional logic formula which may use connectors like: AND ORand NOT. These
relational can use as relational operators like =, ≠, ≥, <, >, ≤.
For example: LOAN Relation

BRANCH_NAME LOAN_NO AMOUNT

Downtown L-17 1000

Redwood L-23 2000

811
Perryride L-15 1500

Downtown L-14 1500

Mianus L-13 500

Roundhill L-11 900

Perryride L-16 1300

Input:
1. σ BRANCH_NAME="perryride" (LOAN)

Output:

BRANCH_NAME LOAN_NO AMOUNT

Perryride L-15 1500

Perryride L-16 1300

2. Project Operation:
o This operation shows the list of those attributes that we wish to appear inthe result. Rest of the
attributes are eliminated from the table.
o It is denoted by ∏.
1. Notation: ∏ A1, A2, An (r)

Were
A1, A2, A3 is used as an attribute name of relation [Link]: CUSTOMER RELATION

NAME STREET CITY

Jones Main Harrison

Smith North Rye

812
Hays Main Harrison

Curry North Rye

Johnson Alma Brooklyn

Brooks Senator Brooklyn

Input:

1. ∏ NAME, CITY (CUSTOMER)


Output:

NAME CITY

Jones Harrison

Smith Rye

Hays Harrison

Curry Rye

Johnson Brooklyn

Brooks Brooklyn

3. Union Operation:
• Suppose there are two tuples R and S. The union operation contains all the
tuples that are either in R or S or both in R & S.
• It eliminates the duplicate tuples. It is denoted by 𝖴.
1. Notation: R 𝖴 S

A union operation must hold the following condition:

• R and S must have the attribute of the same number.


• Duplicate tuples are eliminated [Link]:
813
DEPOSITOR RELATION

CUSTOMER_NAME ACCOUNT_NO

Johnson A-101

Smith A-121

Mayes A-321

Turner A-176

Johnson A-273

Jones A-472

Lindsay A-284

BORROW RELATION

CUSTOMER_NAME LOAN_NO

Jones L-17

Smith L-23

Hayes L-15

Jackson L-14

Curry L-93

Smith L-11

814
Williams L-17

Input:

1. ∏ CUSTOMER_NAME (BORROW) 𝖴 ∏ CUSTOMER_NAME (DEPOSITOR)


Output:

CUSTOMER_NAME

Johnson

Smith

Hayes

Turner

Jones

Lindsay

Jackson

Curry

Williams

Mayes

4. Set Intersection:
• Suppose there are two tuples R and S. The set intersection operation
contains all tuples that are in both R & S.
• It is denoted by intersection ∩.
1. Notation: R ∩ S

Example: Using the above DEPOSITOR table and BORROW table


815
Input:
1. ∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR)

Output:

CUSTOMER_NAME

Smith

Jones

5. Set Difference:
• Suppose there are two tuples R and S. The set intersection operationcontains
all tuples that are in R but not in S.
• It is denoted by intersection minus (-).

1. Notation: R - S
Example: Using the above DEPOSITOR table and BORROW table

Input:

1. ∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR)


Output:

CUSTOMER_NAME

Jackson

Hayes

Willians

Curry

6. Cartesian product
• The Cartesian product is used to combine each row in one table with each row in the other
table. It is also known as a cross product.
• It is denoted by X.

816
1. Notation: E X DExample:
EMPLOYEE

1 Smith A

2 Harry C

3 John B

DEPARTMENT

DEPT_NO DEPT_NAME

A Marketing

B Sales

C Legal

Input:
1. EMPLOYEE X DEPARTMENT

Output:

EMP_ID EMP_NAME EMP_DEPT DEPT_NO DEPT_NAME

1 Smith A A Marketing

1 Smith A B Sales

1 Smith A C Legal

2 Harry C A Marketing

817
2 Harry C B Sales

2 Harry C C Legal

3 John B A Marketing

3 John B B Sales

3 John B C Legal

7. Rename Operation:

The rename operation is used to rename the output relation. It is denotedby rho (ρ).
Example: We can use the rename operator to rename STUDENT relation toSTUDENT1.
1. ρ (STUDENT1, STUDENT)
Note: Apart from these common operations Relational algebra can be used in Joinoperations.
Relational Calculus
• Relational calculus is a non-procedural query language. In the non- procedural query
language, the user is concerned with the details of how toobtain the end results.
• The relational calculus tells what to do but never explains how to do.
Types of Relational calculus:

1. Tuple Relational Calculus (TRC)


• The tuple relational calculus is specified to select the tuples in a relation. In TRC, filtering
variable uses the tuples of a relation.
• The result of the relation can have one or more tuples.
Notation:
1. {T | P (T)} or {T | Condition (T)}Where T is the resulting tuples P(T) is the condition used to fetch.

For example:
1. {[Link] | Author(T) AND Article = 'database' }
OUTPUT: This query selects the tuples from the AUTHOR relation. It returns a tuple with 'name'
from Author who has written an article on 'database'.
TRC (tuple relation calculus) can be quantified. In TRC, we can use Existential (∃) and Universal
Quantifiers (∀).

For example:

1. {R| ∃T ∈ Authors([Link]='database' AND [Link]=[Link])}


818
Output: This query will yield the same result as the previous one.

2. Domain Relational Calculus (DRC)

1. The second form of relation is known as Domain relational calculus. In domain relational
calculus, filtering variable uses the domain of attributes.
2. Domain relational calculus uses the same operators as tuple calculus. Ituses logical connectives
𝖠 (and), ∨ (or) and ┓(not).
3. It uses Existential (∃) and Universal Quantifiers (∀) to bind the variable.
Notation:
1. { a1, a2, a3, ..., an | P (a1, a2, a3, ... ,an)}
Were a1, a2 are attributes
P stands for formula built by inner attributes
For example:

1. {< article, page, subject > | ∈ javatpoint 𝖠 subject = 'database'}


Output: This query will yield the article, page, and subject from the relational javatpoint, where the
subject is a database.
Codd Rules
Dr Edgar F. Codd, after his extensive research on the Relational Model of database systems, came
up with twelve rules of his own, which according to him, a database must obey in order to be
regarded as a true relational database.
These rules can be applied on any database system that manages stored data using only its
relational capabilities. This is a foundation rule, which acts as a basefor all the other rules.

Rule 1: Information Rule


The data stored in a database, may it be user data or metadata, must be a valueof some table cell.
Everything in a database must be stored in a table format.

Rule 2: Guaranteed Access Rule


Every single data element (value) is guaranteed to be accessible logically with a combination of
table-name, primary-key (row value), and attribute-name (column value). No other means, such as
pointers, can be used to access data.

Rule 3: Systematic Treatment of NULL Values


The NULL values in a database must be given a systematic and uniform treatment. This is a very
important rule because a NULL can be interpreted as one the following − data is missing, data is
not known, or data is not applicable.

Rule 4: Active Online Catalog


The structure description of the entire database must be stored in an online catalog, known as
data dictionary, which can be accessed by authorized users. Users can use the same query
language to access the catalog which they use toaccess the database itself.

819
Rule 5: Comprehensive Data Sub-Language Rule
A database can only be accessed using a language having linear syntax that supports data
definition, data manipulation, and transaction management operations. This language can be
used directly or by means of some application. If the database allows access to data without any
help of this language, then it is considered as a violation.

Rule 6: View Updating Rule


All the views of a database, which can theoretically be updated, must also be updatable by the
system.

Rule 7: High-Level Insert, Update, and Delete Rule


A database must support high-level insertion, updation, and deletion. This must not be limited to a
single row, that is, it must also support union, intersection and minus operations to yield sets of
data records.

Rule 8: Physical Data Independence


The data stored in a database must be independent of the applications that access the database.
Any change in the physical structure of a database must not have any impact on how the data is
being accessed by external applications.

Rule 9: Logical Data Independence


The logical data in a database must be independent of its user’s view (application). Any change in
logical data must not affect the applications using [Link] example, if two tables are merged or one
is split into two different tables, there should be no impact or change on the user application. This
is one of the most difficult rule to apply.
Rule 10: Integrity Independence

A database must be independent of the application that uses it. All its integrity constraints can be
independently modified without the need of any change in the application. This rule makes a
database independent of the front-end applicationand its interface.

Rule 11: Distribution Independence


The end-user must not be able to see that the data is distributed over various locations. Users
should always get the impression that the data is located at one site only. This rule has been
regarded as the foundation of distributed database systems.

Rule 12: Non-Subversion Rule


If a system has an interface that provides access to low-level records, then the interface must not
be able to subvert the system and bypass security and integrityconstraints.

SQL
SQL is a programming language for Relational Databases. It is designed over relational algebra
and tuple relational calculus. SQL comes as a package with allmajor distributions of RDBMS.

820
SQL comprises both data definition and data manipulation languages. Using the data definition
properties of SQL, one can design and modify database schema, whereas data manipulation
properties allow SQL to store and retrieve data fromdatabase.

➢ SQL stands for Structured Query Language. It is used for storing and managing data in
relational database management system (RDMS).
➢ It is a standard language for Relational Database System. It enables a user to create, read,
update and delete relational databases and tables.
➢ All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server use SQL as their
standard database language.
➢ SQL allows users to query the database in a number of ways, usingEnglish-like statements.
Rules:
SQL follows the following rules:
➢ Structure query language is not case sensitive. Generally, keywords of SQL are written in
uppercase.
➢ Statements of SQL are dependent on text lines. We can use a single SQL statement on one
or multiple text line.
➢ Using the SQL statements, you can perform most of the actions in adatabase.
➢ SQL depends on tuple relational calculus and relational algebra.

SQL process:
➢ When an SQL command is executing for any RDBMS, then the system figure out the best
way to carry out the request and the SQL engine determines that how to interpret the task.
➢ In the process, various components are included. These components can be optimization
Engine, Query engine, Query dispatcher, classic, etc.
➢ All the non-SQL queries are handled by the classic query engine, but SQLquery engine won't
handle logical files.

Characteristics of SQL
➢ SQL is easy to learn.
➢ SQL is used to access data from relational database managementsystems.
➢ SQL can execute queries against the database.
➢ SQL is used to describe the data.
➢ SQL is used to define the data in the database and manipulate it whenneeded.
➢ SQL is used to create and drop the database and table.
➢ SQL is used to create a view, stored procedure, function in a database.
➢ SQL allows users to set permissions on tables, procedures, and views.

SQL Datatype
➢ SQL Datatype is used to define the values that a column can contain.
➢ Every column is required to have a name and data type in the databasetable.

Datatype of SQL:
821
1. Binary Datatypes
There are Three types of binary Datatypes which are given below:

DataType Description

binary It has a maximum length of 8000 bytes. It contains fixed-lengthbinary data.

Var binary It has a maximum length of 8000 bytes. It contains variable-lengthbinary data.

image It has a maximum length of 2,147,483,647 bytes. It contains variable-length binary


data.

2. Approximate Numeric Datatype:


The subtypes are given below:

Datatype From To Description

float -1.79E +308 1.79E + It is used to specify a floating-point value


308 e.g. 6.2, 2.9 etc.

real -3.40e +38 3.40E + It specifies a single precision floating pointnumber


38

3. Exact Numeric Datatype


The subtypes are given below:

Datatype
822
int It is used to specify an integer value.

smallint It is used to specify small integer value.

bit It has the number of bits to store.

decimal It specifies a numeric value that can have a decimal number.

numeric It is used to specify a numeric value.

4. Character String Datatype


The subtypes are given below:

Datatype Description

char It has a maximum length of 8000 characters. It contains Fixed-length non-unicode


characters.

varchar It has a maximum length of 8000 characters. It contains variable- length non-unicode
characters.

text It has a maximum length of 2,147,483,647 characters. It contains variable-length non-


unicode characters.

5. Date and time Datatypes


The subtypes are given below:

823
Datatype Description

date It is used to store the year, month, and days value.

time It is used to store the hour, minute, and second values.

timestamp It stores the year, month, day, hour, minute, and the secondvalue.

SQL INSERT Statement


The SQL INSERT statement is used to insert a single or multiple data in a table. In SQL, You can
insert the data in two ways:
➢ Without specifying column name
➢ By specifying column nameSample Table
EMPLOYEE

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

3 Christian Denver 100000 42

4 Kristen Washington 500000 29

5 Russell Los angels 200000 36

824
1. Without specifying column name
If you want to specify all column values, you can specify or ignore the columnvalues.
Syntax
1. INSERT INTO TABLE_NAME
2. VALUES (value1, value2, value 3, Value N);

Query
1. INSERT INTO EMPLOYEE VALUES (6, 'Marry', 'Canada', 600000, 48);
Output: After executing this query, the EMPLOYEE table will look like:

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

3 Christian Denver 100000 42

4 Kristen Washington 500000 29

5 Russell Los angels 200000 36

6 Marry Canada 600000 48

2. By specifying column name


To insert partial column values, you must have to specify the column names.

Syntax
1. INSERT INTO TABLE_NAME2. [(col1, col2, col3, col N)]
3. VALUES (value1, value2, value 3, Value N);

Query
1. INSERT INTO EMPLOYEE (EMP_ID, EMP_NAME, AGE) VALUES (7, 'Jack', 40);
Output: After executing this query, the table will look like:

825
EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

3 Christian Denver 100000 42

4 Kristen Washington 500000 29

5 Russell Los angels 200000 36

6 Marry Canada 600000 48

7 Jack null null 40

Note: In SQL INSERT query, if you add values for all columns then there is no need to specify the
column name. But you must be sure that you are entering the values in the same order as the
column exists.

SQL Update Statement


The SQL UPDATE statement is used to modify the data that is already in the database. The
condition in the WHERE clause decides that which row is to beupdated.
Syntax
1. UPDATE table name
2. SET column1 = value1, column2 = value2, ...
3. WHERE condition;Sample Table EMPLOYEE

EMP_ID EMP_NAME CITY SALARY AGE

826
1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

3 Christian Denver 100000 42

4 Kristen Washington 500000 29

5 Russell Los angels 200000 36

6 Marry Canada 600000 48

Updating single record


Update the column EMP_NAME and set the value to 'Emma' in the row whereSALARY is 500000.
Syntax
1. UPDATE table name
2. SET column name = value
3. WHERE condition.

Query
1. UPDATE EMPLOYEE
2. SET EMP_NAME = 'Emma'
3. WHERE SALARY = 500000.

Output: After executing this query, the EMPLOYEE table will look like:

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

827
3 Christian Denver 100000 42

4 Emma Washington 500000 29

5 Russell Los angels 200000 36

6 Marry Canada 600000 48

Updating multiple records


If you want to update multiple columns, you should separate each field assignedwith a comma. In
the EMPLOYEE table, update the column EMP_NAME to 'Kevin'and CITY to 'Boston' where EMP_ID
is 5.
Syntax
1. UPDATE table name
2. SET column name = value1, column_name2 = value2
3. WHERE condition.

Query
1. UPDATE EMPLOYEE
2. SET EMP_NAME = 'Kevin', City = 'Boston'
3. WHERE EMP_ID = 5.
Output

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

3 Christian Denver 100000 42

4 Kristen Washington 500000 29

828
5 Kevin Boston 200000 36

6 Marry Canada 600000 48

Without use of WHERE clause


If you want to update all row from a table, then you don't need to use the WHERE clause. In the
EMPLOYEE table, update the column EMP_NAME as 'Harry'.

Syntax
1. UPDATE table_name
2. SET column_name = value1.

Query
1. UPDATE EMPLOYEE
2. SET EMP_NAME = 'Harry';
Output

EMP_ID EMP_NAME CITY SALARY AGE

1 Harry Chicago 200000 30

2 Harry Austin 300000 26

3 Harry Denver 100000 42

4 Harry Washington 500000 29

5 Harry Los angels 200000 36

6 Harry Canada 600000 48

SQL DELETE Statement


The SQL DELETE statement is used to delete rows from a table. Generally, DELETE statement
removes one or more records form a table.

829
Syntax
1. DELETE FROM table_name WHERE some_condition;Sample Table

EMPLOYEE

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

3 Christian Denver 100000 42

4 Kristen Washington 500000 29

5 Russell Los angels 200000 36

6 Marry Canada 600000 48

Deleting Single Record


Delete the row from the table EMPLOYEE where EMP_NAME = 'Kristen'. This will delete only the
fourth row.
Query

1. DELETE FROM EMPLOYEE


2. WHERE EMP_NAME = 'Kristen';
Output: After executing this query, the EMPLOYEE table will look like:

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

830
3 Christian Denver 100000 42

5 Russell Los angels 200000 36

6 Marry Canada 600000 48

Deleting Multiple Record


Delete the row from the EMPLOYEE table where AGE is 30. This will delete two rows(first and third
row).
Query
1. DELETE FROM EMPLOYEE WHERE AGE= 30;

Output: After executing this query, the EMPLOYEE table will look like:

EMP_ID EMP_NAME CITY SALARY AGE

2 Robert Austin 300000 26

3 Christian Denver 100000 42

5 Russell Los angels 200000 36

6 Marry Canada 600000 48

Delete all of the records


Delete all the row from the EMPLOYEE table. After this, no records left to display. The EMPLOYEE
table will become empty.
Syntax
DELETE * FROM table name;or

DELETE FROM table name.


Query

831
1. DELETE FROM EMPLOYEE.
Output: After executing this query, the EMPLOYEE table will look like:

EMP_ID EMP_NAME CITY SALARY AGE

Note: Using the condition in the WHERE clause, we can delete single as well as multiple records. If
you want to delete all the records from the table, then youdon't need to use the WHERE clause.

Views in SQL
o Views in SQL are considered as a virtual table. A view also contains rows and
columns.
o To create the view, we can select the fields from one or more tables present in
the database.
o A view can either have specific rows based on certain condition or all therows of
a table.
Sample table:
Student Detail

STU_ID NAME ADDRESS

1 Stephan Delhi

2 Kathrin Noida

3 David Ghaziabad

4 Alina Gurugram

Student_Marks

STU_ID NAME MARKS AGE

1 Stephan 97 19

832
2 Kathrin 86 21

3 David 74 18

4 Alina 90 20

5 John 96 18

1. Creating view
A view can be created using the CREATE VIEW statement. We can create a view from a single
table or multiple tables.
Syntax:
1. CREATE VIEW view_name AS
2. SELECT column1, column2....
3. FROM table name
4. WHERE condition.

2. Creating View from a single table


In this example, we create a View named DetailsView from the tableStudent_Detail.
Query:

1. CREATE VIEW DetailsView AS


2. SELECT NAME, ADDRESS
3. FROM Student_Details
4. WHERE STU_ID < 4;
Just like table query, we can query the view to view the data.

1. SELECT * FROM DetailsView;

Output:

NAME ADDRESS

Stephan Delhi

833
Kathrin Noida

David Ghaziabad

3. Creating View from multiple tables


View from multiple tables can be created by simply include multiple tables in the SELECT
statement.
In the given example, a view is created named MarksView from two tables Student_Detail and
Student_Marks.
Query:

1. CREATE VIEW MarksView AS


2. SELECT Student_Detail.NAME, Student_Detail.ADDRESS, Student_Marks.MARKS
3. FROM Student_Detail, Student_Mark
4. WHERE Student_Detail.NAME = Student_Marks.NAME.
To display data of View MarksView:
1. SELECT * FROM MarksView;

NAME ADDRESS MARKS

Stephan Delhi 97

Kathrin Noida 86

David Ghaziabad 74

Alina Gurugram 90

4. Deleting View

A view can be deleted using the Drop View statement.

Syntax
1. DROP VIEW name.

834
Example:
If we want to delete the View Marks View, we can do this as:

1. DROP VIEW Marks View.


Triggers are stored programs, which are automatically executed or fired when some events occur.
Triggers are, in fact, written to be executed in response to anyof the following events −
• A database manipulation (DML) statement (DELETE, INSERT, or UPDATE)
• A database definition (DDL) statement (CREATE, ALTER, or DROP).
• A database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, orSHUTDOWN).
Triggers can be defined on the table, view, schema, or database with which theevent is associated.
Benefits of Triggers

Triggers can be written for the following purposes −


▪ Generating some derived column values automatically
▪ Enforcing referential integrity
▪ Event logging and storing information on table access
▪ Auditing
▪ Synchronous replication of tables
▪ Imposing security authorizations
▪ Preventing invalid transactions
Creating Triggers
The syntax for creating a trigger is −
CREATE [OR REPLACE] TRIGGER name {BEFORE | AFTER | INSTEAD OF} {INSERT [OR] | UPDATE
[OR] | DELETE} [OF colonnade] [FOR EACH ROW] WHEN (condition) DECLARE Declaration-
statements
Were,
• CREATE [OR REPLACE] TRIGGER trigger name − Creates or replaces an existing trigger with the
trigger name.
• {BEFORE | AFTER | INSTEAD OF} − This specifies when the trigger will beexecuted. The INSTEAD
OF clause is used for creating trigger on a view.
• {INSERT [OR] | UPDATE [OR] | DELETE} − This specifies the DML operation.

• [OF col_name] − This specifies the column name that will be updated.
• [ON table name] − This specifies the name of the table associated with thetrigger.
• [REFERENCING OLD AS o NEW AS n] − This allows you to refer new and old values for various
DML statements, such as INSERT, UPDATE, and DELETE.
• [FOR EACH ROW] − This specifies a row-level trigger, i.e., the trigger will be executed for each
row being affected. Otherwise, the trigger will execute just once when the SQL statement is
executed, which is called a table leveltrigger.
• WHEN (condition) − This provides a condition for rows for which the trigger would fire. This
clause is valid only for row-level triggers.

835
Example

To start with, we will be using the CUSTOMERS table we had created and used in the previous
chapters −
Select * from customers.

The following program creates a row-level trigger for the customers table that would fire for
INSERT or UPDATE or DELETE operations performed on the CUSTOMERS table. This trigger will
display the salary difference between the oldvalues and new values −
CREATE OR REPLACE TRIGGER display_salary_changes

BEFORE DELETE OR INSERT OR UPDATE ON customers


FOR EACH ROW WHEN ([Link] > 0) DECLARE sal_diff number. BEGIN sal_diff := :NEW. Salary -:
OLD. Salary.
When the above code is executed at the SQL prompt, it produces the followingresult −
Trigger created.

The following points need to be considered here −


• OLD and NEW references are not available for table-level triggers, rather you can use them for
record-level triggers.
• If you want to query the table in the same trigger, then you should use the AFTER keyword,
because triggers can query the table or change it again only after the initial changes are applied
and the table is back in a consistent state.
• The above trigger has been written in such a way that it will fire before any DELETE or INSERT or
UPDATE operation on the table, but you can write your trigger on a single or multiple operations,
for example BEFORE DELETE, which will fire whenever a record will be deleted using the DELETE
operation on the table.

Triggering a Trigger
Let us perform some DML operations on the CUSTOMERS table. Here is one INSERT statement,
which will create a new record in the table −
INSERT INTO CUSTOMERS (ID, NAME, AGE,ADDRESS,SALARY) VALUES (7, 'Kriti', 22, 'HP', 7500.00

);

When a record is created in the CUSTOMERS table, the above create


836
trigger, display_salary_changes will be fired, and it will display the following result

Old salary:

New salary: 7500


Salary difference:
Because this is a new record, old salary is not available, and the above result comes as null. Let us
now perform one more DML operation on the CUSTOMERS table. The UPDATE statement will
update an existing record in the table −
When a record is updated in the CUSTOMERS table, the above create
trigger, display_salary_changes will be fired, and it will display the following result

SQL injection (SQLi)
SQL injection is a web security vulnerability that allows an attacker to interfere with the queries
that an application makes to its database. It generally allows an attacker to view data that they
are not normally able to retrieve. This might include data belonging to other users, or any other
data that the application itself is able to access. In many cases, an attacker can modify or delete
this data, causing persistent changes to the application's content or behavior.
In some situations, an attacker can escalate an SQL injection attack to compromise the
underlying server or other back end infrastructure, or perform adenial-of-service attack.

Impact of a successful SQL injection attack


A successful SQL injection attack can result in unauthorized access to sensitive data, such as
passwords, credit card details, or personal user information. Many high-profile data breaches in
recent years have been the result of SQL injection attacks, leading to reputational damage and
regulatory fines. In some cases, an attacker can obtain a persistent backdoor into an
organization's systems, leading to a long-term compromise that can go unnoticed for an extended
period.

SQL injection examples


There are a wide variety of SQL injection vulnerabilities, attacks, and techniques, which arise in
different situations. Some common SQL injection examples include:
1. Retrieving hidden data, where you can modify an SQL query to returnadditional results.
2. Subverting application logic, where you can change a query to interfere with the
application's logic.
3. UNION attacks, where you can retrieve data from different databasetables.
4. Examining the database, where you can extract information about the version and
structure of the database.
5. Blind SQL injection, where the results of a query you control are not returned in the
application's responses.

How to detect SQL injection vulnerabilities


The majority of SQL injection vulnerabilities can be found quickly and reliably using Burp Suite's
837
web vulnerability scanner.
SQL injection can be detected manually by using a systematic set of tests againstevery entry point
in the application. This typically involves:
➢ Submitting the single quote character ' and looking for errors or otheranomalies.
➢ Submitting some SQL-specific syntax that evaluates to the base (original) value of the entry
point, and to a different value, and looking for systematic differences in the resulting
application responses.
➢ Submitting Boolean conditions such as OR 1=1 and OR 1=2 and looking for differences in
the application's responses.
➢ Submitting payloads designed to trigger time delays when executed within an SQL query
and looking for differences in the time taken to respond.
➢ Submitting OAST payloads designed to trigger an out-of-band network interaction when
executed within an SQL query, and monitoring for anyresulting interactions.

SQL injection in different parts of the query


Most SQL injection vulnerabilities arise within the WHERE clause of
a SELECT query. This type of SQL injection is generally well-understood byexperienced testers.
But SQL injection vulnerabilities can in principle occur at any location within the query, and within
different query types. The most common other locations whereSQL injection arises are:
➢ In UPDATE statements, within the updated values or the WHERE clause.
➢ In INSERT statements, within the inserted values.
➢ In SELECT statements, within the table or column name.
➢ In SELECT statements, within the ORDER BY clause.

Second-order SQL injection


First-order SQL injection arises where the application takes user input from an HTTP request and,
in the course of processing that request, incorporates the input into an SQL query in an unsafe
way.
In second-order SQL injection (also known as stored SQL injection), the application takes user
input from an HTTP request and stores it for future use. This is usually done by placing the input
into a database, but no vulnerability arises at the point where the data is stored. Later, when
handling a different HTTPrequest, the application retrieves the stored data and incorporates it into
an SQL query in an unsafe way.
Second-order SQL injection often arises in situations where developers are aware of SQL injection
vulnerabilities, and so safely handle the initial placement of the input into the database. When the
data is later processed, it is deemed to be safe, since it was previously placed into the database
safely. At this point, the data is handled in an unsafe way, because the developer wrongly deems it
to be trusted.

Database-specific factors
Some core features of the SQL language are implemented in the same way across popular
database platforms, and so many ways of detecting and exploiting SQL injection vulnerabilities
work identically on different types of databases.

838
However, there are also many differences between common databases. These mean that some
techniques for detecting and exploiting SQL injection work differently on different platforms. For
example:
➢ Syntax for string concatenation.
➢ Comments.
➢ Batched (or stacked) queries.
➢ Platform-specific APIs.
➢ Error messages.

How to prevent SQL injection


Most instances of SQL injection can be prevented by using parameterized queries (also known as
prepared statements) instead of string concatenation within the query.
The following code is vulnerable to SQL injection because the user input is concatenated directly
into the query:
String query = "SELECT * FROM products WHERE category = '"+ input + "'";

Statement statement = [Link] Statement


();ResultSet resultSet =[Link](query);
This code can be easily rewritten in a way that prevents the user input from Parameterized queries
can be used for any situation where untrusted input appears as data within the query, including the
WHERE clause and values in an INSERT or UPDATE statement. They can't be used to handle
untrusted input inother parts of the query, such as table or column names, or the ORDER BY clause.
Application functionality that places untrusted data into those parts of the query will need to take a
different approach, such as white listing permitted input values, or using different logic to deliver
the required behavior.
For a parameterized query to be effective in preventing SQL injection, the string that is used in the
query must always be a hard-coded constant and must never contain any variable data from any
origin. Do not be tempted to decide case-by- case whether an item of data is trusted and continue
using string concatenation within the query for cases that are considered safe. It is all too easy to
make mistakes about the possible origin of data, or for changes in other code to violate
assumptions about what data is tainted.

Functional Dependency
The functional dependency is a relationship that exists between two attributes. It typically exists
between the primary key and non-key attribute within a table.
X → Y The left side of FD is known as a determinant; the right side of the production isknown as
a dependent.

For example:
Assume we have an employee table with attributes: Emp_Id, Emp_Name,Emp_Address.
Here Emp_Id attribute can uniquely identify the Emp_Name attribute of employee table because if
we know the Emp_Id, we can tell that employee nameassociated with it.
Functional dependency can be written as:
Emp_Id → Emp_NameWe can say that Emp_Name is functionally dependent on Emp_Id.

839
Types of Functional dependency
1. Trivial functional dependency

➢ A → B has trivial functional dependency if B is a subset of A.


➢ The following dependencies are also trivial like: A → A, B → B
Example:

➢ Consider a table with two columns Employee_Id and Employee_Name.


➢ {Employee_id, Employee_Name} → Employee_Id is a trivial functional de
pendency as
➢ Employee_Id is a subset of {Employee_Id, Employee_Name}.
➢ Also, Employee_Id → Employee_Id and Employee_Name → Employee_N ame
are trivial dependencies too.
2. Non-trivial functional dependency
➢ A → B has a non-trivial functional dependency if B is not a subset of A.
➢ When A intersection B is NULL, then A → B is called as complete non-trivial.

Example:
1. ID → Name,
2. Name → DOB

Normalization
➢ Normalization is the process of organizing the data in the database.
➢ Normalization is used to minimize the redundancy from a relation or set of relations. It is
also used to eliminate the undesirable characteristics like Insertion, Update and Deletion
Anomalies.
➢ Normalization divides the larger table into the smaller table and links them using
relationship.
➢ The normal form is used to reduce redundancy from the database table.

Types of Normal Forms


There are the four types of normal forms:

840
NormalForm
1NF A relation is in 1NF if it contains an atomic value.

2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully functional
dependent on the primary key.

3NF A relation will be in 3NF if it is in 2NF and no transitiondependency exists.

4NF A relation will be in 4NF if it is in Boyce Codd normal form and hasno multi-valued
dependency.

5NF A relation is in 5NF if it is in 4NF and not contains any joindependency and joining
should be lossless.

Transaction

• The transaction is a set of logically related operation. It contains a group oftasks.


• A transaction is an action or series of actions. It is performed by a single user to perform
operations for accessing the contents of the database.
Example: Suppose an employee of bank transfers Rs 800 from X's account to Y's account. This
small transaction contains several low-level tasks:

X's Account
1. Open Account(X)
2. Old_Balance = [Link]
3. New_Balance = Old_Balance - 800
4. [Link] = New_Balance
5. Close Account(X)

Y's Account
1. Open Account(Y)
2. Old Balance = Y. Balance
3. New Balance = Old Balance + 800
4. Y. Balance = New Balance
5. Close Account(Y)

841
Operations of Transaction:
Following are the main operations of transaction:
Read(X): Read operation is used to read the value of X from the database and stores it in a buffer
in main memory.

Write(X): Write operation is used to write the value back to the database fromthe buffer.
An example to debit transaction from an account which consists of followingoperations:
1. 1. R(X);
2. 2. X = X - 500.
3. 3. W(X);
Assume the value of X before starting of the transaction is 4000.
➢ The first operation reads X's value from database and stores it in abuffer.
➢ The second operation will decrease the value of X by 500. So, buffer willcontain 3500.
➢ The third operation will write the buffer's value to the database. So, X'sfinal value will be 3500.
But it may be possible that because of the failure of hardware, software or power, etc. that
transaction may fail before finished all the operations in the set.
For example: If in the above transaction, the debit transaction fails after executing operation 2
then X's value will remain 4000 in the database which is notacceptable by the bank.
To solve this problem, we have two important operations:
Commit: It is used to save the work done permanently.

Rollback: It is used to undo the work done.

Transaction property
The transaction has the four properties. These are used to maintain consistency in a database,
before and after the transaction.

Property of Transaction
1. Atomicity
2. Consistency
3. Isolation
4. Durability

Atomicity

• It states that all operations of the transaction take place at once if not, the transaction is
aborted.
• There is no midway, i.e., the transaction cannot occur partially. Each transaction is treated
as one unit and either run to completion or is notexecuted at all.

Atomicity involves the following two operations:


Abort: If a transaction aborts, then all the changes made are not visible. Commit: If a transaction
commits, then all the changes made are [Link]

842
• The integrity constraints are maintained so that the database is consistentbefore and after
the transaction.
• The execution of a transaction will leave a database in either its prior stable state or a new
stable state.
• The consistent property of database states that every transaction sees a consistent
database instance.
• The transaction is used to transform the database from one consistent state to another
consistent state.

Isolation
• It shows that the data which is used at the time of execution of a transaction cannot be
used by the second transaction until the first oneis completed.
• In isolation, if the transaction T1 is being executed and using the data item X, then that data
item can't be accessed by any other transactionT2 until the transaction T1 ends.
• The concurrency control subsystem of the DBMS enforced the isolationproperty.
Durability

• The durability property is used to indicate the performance of the database's consistent
state. It states that the transaction made thepermanent changes.
• They cannot be lost by the erroneous operation of a faulty transaction or by the system
failure. When a transaction is completed, then the database reaches a state known as the
consistent state. That consistent state cannot be lost, even in the event of a system's
failure.
• The recovery subsystem of the DBMS has the responsibility of Durabilityproperty.

States of Transaction
In a database, the transaction can be in one of the following states -

Active state

• The active state is the first state of every transaction. In this state, the
transaction is being executed.
• For example: Insertion or deletion or updating a record is done here. But allthe
records are still not saved to the database.
Partially committed

• In the partially committed state, a transaction executes its final operation, but the data is
still not saved to the database.
• In the total mark calculation example, a final display of the total marks step is executed in
this state.

Committed
A transaction is said to be in a committed state if it executes all its operationssuccessfully. In this
843
state, all the effects are now permanently saved on the database system.
Failed state

➢ If any of the checks made by the database recovery system fails, then the transaction is
said to be in the failed state.
➢ In the example of total mark calculation, if the database is not able to fire a query to fetch
the marks, then the transaction will fail to execute.
Aborted

➢ If any of the checks fail and the transaction has reached a failed state then the database
recovery system will make sure that the database is in its previous consistent state. If not
then it will abort or roll back the transaction to bring the database into a consistent state.
➢ If the transaction fails in the middle of the transaction then before executing the
transaction, all the executed transactions are rolled backto its consistent state.
➢ After aborting the transaction, the database recovery module will select one of the two
operations:
1. Re-start the transaction

2. Kill the transaction


Desirable Properties of Transactions
Any transaction must maintain the ACID properties, viz. Atomicity, Consistency, Isolation, and
Durability.
➢ Atomicity − This property states that a transaction is an atomic unit of processing, that is,
either it is performed in its entirety or not performed atall. No partial update should exist.
➢ Consistency − A transaction should take the database from one consistent state to another
consistent state. It should not adversely affect any data item in the database.
➢ Isolation − A transaction should be executed as if it is the only one in the system. There
should not be any interference from the other concurrent transactions that are
simultaneously running.
➢ Durability − If a committed transaction brings about a change, that change should be
durable in the database and not lost in case of any failure.
➢ Schedules and Conflicts
➢ In a system with a number of simultaneous transactions, a schedule is the total order of
execution of operations. Given a schedule S comprising of n transactions,say T1, T2, T3 Tn;
for any transaction Ti, the operations in Ti must execute as
➢ laid down in the schedule S.

Types of Schedules
There are two types of schedules −

➢ Serial Schedules − In a serial schedule, at any point of time, only one transaction is active,
i.e., there is no overlapping of transactions. This isdepicted in the following graph −

844
➢ Parallel Schedules − In parallel schedules, more than one transaction is active
simultaneously, i.e. the transactions contain operations that overlap at time. This is
depicted in the following graph −

Conflicts in Schedules
In a schedule comprising of multiple transactions, a conflict occurs when two active transactions
perform non-compatible operations. Two operations are said to be in conflict, when all of the
following three conditions exists simultaneously −
• The two operations are parts of different transactions.
• Both the operations access the same data item.
• At least one of the operations is a write item () operation, i.e. it tries tomodify the data item.

Serializability
A serializable schedule of ‘n’ transactions is a parallel schedule which is equivalent to a serial
schedule comprising of the same ‘n’ transactions. Aserializable schedule contains the correctness
of serial schedule while ascertaining better CPU utilization of parallel schedule.

Equivalence of Schedules
Equivalence of two schedules can be of the following types −

➢ Result equivalence − Two schedules producing identical results are said to be


result equivalent.
➢ View equivalence − Two schedules that perform similar action in a similar
manner are said to be view equivalent.
➢ Conflict equivalence − Two schedules are said to be conflict equivalent if both
contain the same set of transactions and has the same order of conflicting pairs
of operations.
Concurrency Control

➢ In the concurrency control, the multiple transactions can be executedsimultaneously.


➢ It may affect the transaction result. It is highly important to maintain the order of execution
of those transactions.

Problems of concurrency control


Several problems can occur when concurrent transactions are executed in an uncontrolled
manner. Following are the three problems in concurrency control.
1. Lost updates
2. Dirty read
3. Unrepeatable read

1. Lost update problem


➢ When two transactions that access the same database items contain their operations in a
way that makes the value of some database item incorrect, then the lost update problem
845
occurs.
➢ If two transactions T1 and T2 read a record and then update it, then theeffect of updating of
the first record will be overwritten by the second update.

Example:
Here,
➢ At time t2, transaction-X reads A's value.
➢ At time t3, Transaction-Y reads A's value.
➢ At time t4, Transactions-X writes A's value on the basis of the value seenat time t2.
➢ At time t5, Transactions-Y writes A's value on the basis of the value seenat time t3.
➢ So, at time T5, the update of Transaction-X is lost because Transaction y overwrites it without
looking at its current value.
➢ Such type of problem is known as Lost Update Problem as update made by one transaction is
lost here.

2. Dirty Read

➢ The dirty read occurs in the case when one transaction updates an item ofthe database, and
then the transaction fails for some reason. The updated database item is accessed by
another transaction before it is changed backto the original value.
➢ A transaction T1 updates a record which is read by T2. If T1 aborts, then T2now has values
which have never formed part of the stable database.

Example:
➢ At time t2, transaction-Y writes A's value.
➢ At time t3, Transaction-X reads A's value.
➢ At time t4, Transactions-Y rollbacks. So, it changes A's value back to thatof prior to t1.
➢ So, Transaction-X now contains a value which has never become part of the stable
database.
➢ Such type of problem is known as Dirty Read Problem, as one transaction reads a dirty
value which has not been committed.
3. Inconsistent Retrievals Problem

➢ Inconsistent Retrievals Problem is also known as unrepeatable read. When a transaction


calculates some summary function over a set of data while the other transactions are
updating the data, then the Inconsistent Retrievals Problem occurs.
➢ A transaction T1 reads a record and then does some other processing during which the
transaction T2 updates the record. Now when the transaction T1 reads the record, then the
new value will be inconsistentwith the previous value.
Example:
Suppose two transactions operate on three accounts.
1. Transaction-X is doing the sum of all balance while transaction-Y is transferring an amount
50 from Account-1 to Account-3.
846
2. Here, transaction-X produces the result of 550 which is incorrect. If we write this produced
result in the database, the database will become an inconsistent state because the actual
sum is 600.
3. Here, transaction-X has seen an inconsistent state of the database.

Concurrency Control Protocol


Concurrency control protocols ensure atomicity, isolation, and serializability of concurrent
transactions. The concurrency control protocol can be divided intothree categories:
➢ Lock based protocol
➢ Time-stamp protocol
➢ Validation based protocol

Query Processing in DBMS


Query Processing is the activity performed in extracting data from the database. In query
processing, it takes various steps for fetching the data from the database. The steps involved are:
1. Parsing and translation
2. Optimization
3. Evaluation
The query processing works in the following way:

Parsing and Translation


As query processing includes certain activities for data retrieval. Initially, the givenuser queries get
translated in high-level database languages such as SQL. It gets translated into expressions that
can be further used at the physical level of the file system. After this, the actual evaluation of the
queries and a variety of query - optimizing transformations and takes place. Thus before
processing a query, a computer system needs to translate the query into a human-readable and
understandable language. Consequently, SQL or Structured Query Language is the best suitable
choice for humans. But it is not perfectly suitable for the internal representation of the query to
the system. Relational algebra is well suited for the internal representation of a query. The
translation process in query processing is similar to the parser of a query. When a user executes
any query, for generating the internal form of the query, the parser in the system checks the syntax
of the query, verifies the name of the relation in the database, the tuple, and finally the required
attribute value. The parser creates a tree of the query, known as 'parse- tree.' Further, translate it
into the form of relational algebra. With this, it evenly replaces all the use of the views when used
in the query.
Thus, we can understand the working of a query processing in the below-described diagram:
Suppose a user executes a query. As we have learned that there are various methods of
extracting the data from the database. In SQL, a user wants to fetch the records of the employees
whose salary is greater than or equal to 10000. Fordoing this, the following query is undertaken:

select emp_name from Employee where salary>10000.


Thus, to make the system understand the user query, it needs to be translated in the form of
relational algebra. We can bring this query in the relational algebra form as:

847
1. σsalary>10000 (πsalary (Employee))
2. πsalary (σsalary>10000 (Employee))
After translating the given query, we can execute each relational algebra operation by using
different algorithms. So, in this way, a query processing beginsits working.

Evaluation
For this, with addition to the relational algebra translation, it is required to annotate the translated
relational algebra expression with the instructions used for specifying and evaluating each
operation. Thus, after translating the user query, the system executes a query evaluation plan.

Query Evaluation Plan


➢ In order to fully evaluate a query, the system needs to construct a queryevaluation plan.
➢ The annotations in the evaluation plan may refer to the algorithms to be used for the
particular index or the specific operations.
➢ Such relational algebra with annotations is referred to as Evaluation Primitives. The
evaluation primitives carry the instructions needed forthe evaluation of the operation.
➢ Thus, a query evaluation plan defines a sequence of primitive operationsused for evaluating
a query. The query evaluation plan is also referred toas the query execution plan.
➢ A query execution engine is responsible for generating the output of the given query. It
takes the query execution plan, executes it, and finally makes the output for the user query.

Optimization
➢ The cost of the query evaluation can vary for different types of queries. Although the
system is responsible for constructing the evaluation plan, the user does need not to write
their query efficiently.
➢ Usually, a database system generates an efficient query evaluation plan, which minimizes
its cost. This type of task performed by the database system and is known as Query
Optimization.
➢ For optimizing a query, the query optimizer should have an estimated cost analysis of each
operation. It is because the overall operation cost depends on the memory allocations to
several operations, execution costs, and so on.
➢ Finally, after selecting an evaluation plan, the system evaluates the query and produces the
output of the query.

Steps for Query Optimization


Query optimization involves three steps, namely query tree generation, plan generation, and query
plan code generation.

Step 1 − Query Tree Generation


A query tree is a tree data structure representing a relational algebra expression. The tables of the
query are represented as leaf nodes. The relational algebra operations are represented as the
internal nodes. The root represents the queryas a whole.
During execution, an internal node is executed whenever its operand tables are available. The
848
node is then replaced by the result table. This process continues forall internal nodes until the root
node is executed and replaced by the result table.
For example, let us consider the following schemas −EMPLOYEE

EmpID EName Salary DeptNo

DEPARTMENT

DNo DName L

Example 1
Let us consider the query as the following.
$$\pi_{EmpID} (\sigma_ {EName = \small "Arun Kumar"} {(EMPLOYEE)})$$ The corresponding

query tree will be −

Example 2
consider another query involving a join.
$\pi_{EName, Salary} (\sigma_{DName = \small "Marketing"} {(DEPARTMENT)})
\bowtie_{DNo=DeptNo}{(EMPLOYEE)}$ Following is the query tree for the above query.

Step 2 − Query Plan Generation


After the query tree is generated, a query plan is made. A query plan is an extended query tree that
includes access paths for all operations in the query tree. Access paths specify how the relational
operations in the tree should be performed. For example, a selection operation can have an
access path that givesdetails about the use of B+ tree index for selection.
Besides, a query plan also states how the intermediate tables should be passedfrom one operator
to the next, how temporary tables should be used and how operations should be
pipelined/combined.

Step 3− Code Generation


Code generation is the final step in query optimization. It is the executable form of the query,
849
whose form depends upon the type of the underlying operating system. Once the query code is
generated, the Execution Manager runs it and produces the results.

Approaches to Query Optimization


Among the approaches for query optimization, exhaustive search and heuristics-based algorithms
are mostly used.

Exhaustive Search Optimization


In these techniques, for a query, all possible query plans are initially generated and then the best
plan is selected. Though these techniques provide the best solution, it has an exponential time
and space complexity owing to the large solution space. For example, dynamic programming
technique.

Heuristic Based Optimization


Heuristic based optimization uses rule-based optimization approaches for query optimization.
These algorithms have polynomial time and space complexity, which is lower than the exponential
complexity of exhaustive search-based algorithms. However, these algorithms do not necessarily
produce the best queryplan.
Some of the common heuristic rules are −

• Perform select and project operations before join operations. This is done by
moving the select and project operations down the query tree. This reduces the
number of tuples available for join.
• Perform the most restrictive select/project operations at first before the other
operations.
• Avoid cross-product operation since they result in very large-sized intermediate
tables.

Database Recovery TechniquesCrash Recovery

DBMS is a highly complex system with hundreds of transactions being executed every second.
The durability and robustness of a DBMS depends on its complex architecture and its underlying
hardware and system software. If it fails or crashes amid transactions, it is expected that the
system would follow some sort of algorithm or techniques to recover lost data.

Failure Classification
To see where the problem has occurred, we generalize a failure into various categories, as follows

Transaction failure
A transaction has to abort when it fails to execute or when it reaches a point fromwhere it can’t go
any further. This is called transaction failure where only a few transactions or processes are hurt.

Reasons for a transaction failure could be −


• Logical errors − Where a transaction cannot complete because it has some code error or any
850
internal error condition.
• System errors − Where the database system itself terminates an active transaction because the
DBMS is not able to execute it, or it has to stopbecause of some system condition. For example, in
case of deadlock orresource unavailability, the system aborts an active transaction.

System Crash
There are problems − external to the system − that may cause the system to stop abruptly and
cause the system to crash. For example, interruptions in power supply may cause the failure of
underlying hardware or software failure.
Examples may include operating system errors.

Disk Failure
In early days of technology evolution, it was a common problem where hard-disk drives or storage
drives used to fail frequently.
Disk failures include formation of bad sectors, unreachability to the disk, disk head crash or any
other failure, which destroys all or a part of disk storage.
Storage Structure
We have already described the storage system. In brief, the storage structure can be divided into
two categories −
• Volatile storage − As the name suggests, a volatile storage cannot survive system crashes.
Volatile storage devices are placed very close to the CPU; normally they are embedded onto the
chipset itself. For example, main memory and cache memory are examples of volatile storage.
They are fastbut can store only a small amount of information.
• Non-volatile storage − These memories are made to survive system crashes. They are huge in
data storage capacity, but slower in accessibility. Examples may include hard-disks, magnetic
tapes, flash memory, and non-volatile (battery backed up) RAM.

Recovery and Atomicity


When a system crashes, it may have several transactions being executed and various files opened
for them to modify the data items. Transactions are made of various operations, which are atomic
in nature. But according to ACID propertiesof DBMS, atomicity of transactions as a whole must be
maintained, that is, eitherall the operations are executed or none.

When a DBMS recovers from a crash, it should maintain the following −

• It should check the states of all the transactions, which were beingexecuted.
• A transaction may be in the middle of some operation; the DBMS mustensure the atomicity
of the transaction in this case.
• It should check whether the transaction can be completed now, or it needsto be rolled back.
• No transactions would be allowed to leave the DBMS in an inconsistentstate.
• There are two types of techniques, which can help a DBMS in recovering as well as
maintaining the atomicity of a transaction −
• Maintaining the logs of each transaction and writing them onto some stable storage before
851
actually modifying the database.
• Maintaining shadow paging, where the changes are done on a volatile memory, and later,
the actual database is updated.

Log-based Recovery
Log is a sequence of records, which maintains the records of actions performed by a transaction.
It is important that the logs are written prior to the actual modification and stored on a stable
storage media, which is failsafe.

Log-based recovery works as follows −

• The log file is kept on a stable storage media.


• When a transaction enters the system and starts execution, it writes a logabout it.
• <Tn, Start>
• When the transaction modifies an item X, it writes logs as follows −

• <Tn, X, V1, V2>


• It reads Tn has changed the value of X, from V1 to V2.
• When the transaction finishes, it logs −
• <Tn, commit>

The database can be modified using two approaches −

• Deferred database modification − All logs are written on to the stable storage and the database
is updated when a transaction commits.
• Immediate database modification − Each log follows an actual database modification. That is,
the database is modified immediately after every operation.

Recovery with Concurrent Transactions

When more than one transaction is being executed in parallel, the logs are interleaved. At the time
of recovery, it would become hard for the recovery system to backtrack all logs, and then start
recovering. To ease this situation,most modern DBMS use the concept of 'checkpoints'.

Checkpoint
Keeping and maintaining logs in real time and in real environment may fill out all the memory
space available in the system. As time passes, the log file may grow too big to be handled at all.
Checkpoint is a mechanism where all the previous logs are removed from the system and stored
permanently in a storage disk.
Checkpoint declares a point before which the DBMS was in consistent state, and all the
transactions were committed.

Recovery
When a system with concurrent transactions crashes and recovers, it behaves in the following
852
manner −
• The recovery system reads the logs backwards from the end to the lastcheckpoint.
• It maintains two lists, an undo-list and a redo-list.
• If the recovery system sees a log with <Tn, Start> and <Tn, Commit> or just
<Tn, Commit>, it puts the transaction in the redo-list.
• If the recovery system sees a log with <Tn, start> but no commit or abort log found, it puts the
transaction in undo-list.
All the transactions in the undo-list are then undone and their logs are removed. All the
transactions in the redo-list and their previous logs are removed and then redone before saving
their logs.

Object and Object-Relational Databases


Object-Relational Database (ORD)
An object-relational database (ORD) is a database management system (DBMS) that's composed
of both a relational database (RDBMS) and an object-oriented database (OODBMS). ORD supports
the basic components of any object-oriented database model in its schemas and the query
language used, such as objects, classes and inheritance.
An object-relational database may also be known as an object relational database management
system (ORDBMS).
ORD is said to be the middleman between relational and object-oriented databases because it
contains aspects and characteristics from both models. In ORD, the basic approach is based on
RDB, since the data is stored in a traditional database and manipulated and accessed using
queries written in a query language like SQL. However, ORD also showcases an object-oriented
characteristic in that the database is considered an object store, usually for software that is
written in an object-oriented programming language. Here, APIs are used to store and access the
data as objects.
One of ORD’s aims is to bridge the gap between conceptual data modeling techniques for
relational and object-oriented databases like the entity- relationship diagram (ERD) and object-
relational mapping (ORM). It also aims to connect the divide between relational databases and
the object-oriented modeling techniques that are usually used in programming languages like
Java, C#and C++.

Traditional RDBMS products concentrate on the efficient organization of data that is derived from
a limited set of datatypes. On the other hand, an ORDBMS has a feature that allows developers to
build and innovate their own data types and methods, which can be applied to the DBMS. With
this, ORDBMS intends to allow developers to increase the abstraction with which they view the
problem area.

Database Security
DB2 database and functions can be managed by two different modes of securitycontrols:
1. Authentication
2. Authorization

853
Authentication
Authentication is the process of confirming that a user logs in only in accordancewith the rights to
perform the activities he is authorized to perform. User authentication can be performed at
operating system level or database level itself. By using authentication tools for biometrics such
as retina and figure printsare in use to keep the database from hackers or malicious users.
The database security can be managed from outside the db2 database system. Here are some
types of security authentication process:
➢ Based on Operating System authentications.
➢ Lightweight Directory Access Protocol (LDAP)

For DB2, the security service is a part of operating system as a separate product. For
Authentication, it requires two different credentials, those are use rid or username, and password.

Authorization
You can access the DB2 Database and its functionality within the DB2 database system, which is
managed by the DB2 Database manager. Authorization is a process managed by the DB2
Database manager. The manager obtains information about the current authenticated user, that
indicates which databaseoperation the user can perform or access.
Here are different ways of permissions available for authorization:

Primary permission: Grants the authorization ID directly.

Secondary permission: Grants to the groups and roles if the user is a member
Public permission: Grants to all users publicly.

Context-sensitive permission: Grants to the trusted context role. Authorization can be given to

users based on the categories below:

➢ System-level authorization
➢ System administrator [SYSADM]
➢ System Control [SYSCTRL]
➢ System maintenance [SYSMAINT]
➢ System monitor [SYSMON]

Authorities provide of control over instance-level functionality. Authority provide to group


privileges, to control maintenance and authority operations. For instance, database and database
objects.
➢ Database-level authorization
➢ Security Administrator [SECADM]
➢ Database Administrator [DBADM]
➢ Access Control [ACCESSCTRL]
➢ Data access [DATAACCESS]
➢ SQL administrator. [SQLADM]
➢ Workload management administrator [WLMADM]
➢ Explain [EXPLAIN]

854
Authorities provide controls within the database. Other authorities for database include with LDAD
and CONNECT.
➢ Object-Level Authorization: Object-Level authorization involves verifying privileges when an
operation is performed on an object.
➢ Content-based Authorization: User can have read and write access to individual rows and
columns on a particular table using Label-based accessControl [LBAC].
DB2 tables and configuration files are used to record the permissions associated with
authorization names. When a user tries to access the data, the recorded permissions verify the
following permissions:
➢ Authorization name of the user
➢ Which group belongs to the user
➢ Which roles are granted directly to the user or indirectly to a group
➢ Permissions acquired through a trusted context.
While working with the SQL statements, the DB2 authorization model considersthe combination of
the following permissions:
➢ Permissions granted to the primary authorization ID associated with theSQL statements.
➢ Secondary authorization IDs associated with the SQL statements.
➢ Granted to PUBLIC
➢ Granted to the trusted context role.

Instance level authorities


Some instance related authorities.

System administration authority (SYSADM)


It is highest level administrative authority at the instance-level. Users with SYSADM authority can
execute some databases and database manager commands within the instance. Users with
SYSADM authority can perform thefollowing operations:
➢ Upgrade a Database
➢ Restore a Database
➢ Update Database manager configuration file.

System control authority (SYSCTRL)


It is the highest level in System control authority. It provides to perform maintenance and utility
operations against the database manager instance and itsdatabases. These operations can affect
system resources, but they do not allow direct access to data in the database.
Users with SYSCTRL authority can perform the following actions:
➢ Updating the database, Node, or Distributed Connect Service (DCS)directory
➢ Forcing users off the system-level
➢ Creating or dropping a database-level
➢ Creating, altering, or dropping a table space
➢ Using any table space
➢ Restoring Database

System maintenance authority (SYSMAINT)


855
It is a second level of system control authority. It provides to perform maintenance and utility
operations against the database manager instance and its
databases. These operations affect the system resources without allowing directaccess to data in
the database. This authority is designed for users to maintain databases within a database
manager instance that contains sensitive data.
Only Users with SYSMAINT or higher-level system authorities can perform thefollowing tasks:
➢ Taking backup
➢ Restoring the backup
➢ Roll forward recovery
➢ Starting or stopping instance
➢ Restoring tablespaces
➢ Executing db2trc command
➢ Taking system monitor snapshots in case of an Instance level user or adatabase level user.
A user with SYSMAINT can perform the following tasks:

➢ Query the state of a tablespace


➢ Updating log history files
➢ Reorganizing of tables
➢ Using RUNSTATS (Collection catalog statistics)

System monitors authority (SYSMON)


With this authority, the user can monitor or take snapshots of database manager instance or its
database. SYSMON authority enables the user to run the followingtasks:
• GET DATABASE MANAGER MONITOR SWITCHES
• GET MONITOR SWITCHES
• GET SNAPSHOT
• LIST
• LIST ACTIVE DATABASES
• LIST APPLICATIONS
• LIST DATABASE PARTITION GROUPS
• LIST DCS APPLICATIONS
• LIST PACKAGES
• LIST TABLES
• LIST TABLESPACE CONTAINERS
• LIST TABLESPACES
• LIST UTITLITIES
• RESET MONITOR
• UPDATE MONITOR SWITCHES

Database authorities
Each database authority holds the authorization ID to perform some action on thedatabase. These
database authorities are different from privileges. Here is the listof some database authorities:
ACCESSCTRL: allows to grant and revoke all object privileges and databaseauthorities.
BINDADD: Allows to create a new package in the database.
CONNECT: Allows to connect to the database.

856
CREATETAB: Allows to create new tables in the database.

CREATE_EXTERNAL_ROUTINE: Allows to create a procedure to be used by applications and the


users of the databases.
DATAACCESS: Allows to access data stored in the database tables.

DBADM: Act as a database administrator. It gives all other database authorities except
ACCESSCTRL, DATAACCESS, and SECADM.

EXPLAIN: Allows to explain query plans without requiring them to hold the privileges to access the
data in the tables.

IMPLICIT_SCHEMA: Allows a user to create a schema implicitly by creating an object using a


CREATE statement.
LOAD: Allows to load data into table.

QUIESCE_CONNECT: Allows to access the database while it is quiesce (temporarilydisabled).


SECADM: Allows to act as a security administrator for the database.

SQLADM: Allows to monitor and tune SQL statements. WLMADM: Allows to act as a workload

administrator Privileges

SETSESSIONUSER
Authorization ID privileges involve actions on authorization IDs. There is only one privilege, called
the SETSESSIONUSER privilege. It can be granted to user, or a group and it allows to session user
to switch identities to any of the authorization IDs on which the privileges are granted. This
privilege is granted by user SECADMauthority.

Schema privileges
These privileges involve actions on schema in the database. The owner of the schema has all the
permissions to manipulate the schema objects like tables, views, indexes, packages, data types,
functions, triggers, procedures and aliases. A user, a group, a role, or PUBLIC can be granted any
user of the following privileges:
➢ CREATEIN: allows to create objects within the schema
➢ ALTERIN: allows to modify objects within the schema.

DROPIN
This allows to delete the objects within the schema.

Table space privileges


These privileges involve actions on the tablespaces in the database. User can be granted the USE
privilege for the tablespaces. The privileges then allow them to create tables within tablespaces.
The privilege owner can grant the USE privilege with the command WITH GRANT OPTION on the
tablespace when tablespace is created. And SECADM or ACCESSCTRL authorities have the
857
permissions to USE privileges on the tablespace.

Table and view privileges


The user must have CONNECT authority on the database to be able to use table and view
privileges. The privileges for tables and views are as given below:

CONTROL
It provides all the privileges for a table or a view including drop and grant, revoke individual table
privileges to the user.

ALTER
It allows user to modify a table.

DELETE
It allows the user to delete rows from the table or view.

INDEX
It allows the user to insert a row into table or view. It can also run import utility.

REFERENCES
It allows the users to create and drop a foreign key.

SELECT
It allows the user to retrieve rows from a table or view.

UPDATE
It allows the user to change entries in a table, view.

Package privileges
User must have CONNECT authority to the database. Package is a database object that contains
the information of database manager to access data in the most efficient way for a particular
application.

CONTROL
It provides the user with privileges of rebinding, dropping or executing packages.A user with these
privileges is granted to BIND and EXECUTE privileges.

BIND
It allows the user to bind or rebind that package.

EXECUTE
Allows to execute a [Link] privileges

This privilege automatically receives CONTROL privilege on the index.


Sequence privileges

858
Sequence automatically receives the USAGE and ALTER privileges on thesequence.
Routine privileges

It involves the action of routines such as functions, procedures, and methodswithin a database.
The enhanced data model offers rich features but breaks backward compatibility.

The classic model is simple, well-understood, and had been around for a long time. The enhanced
data model offers many new features for structuring data. Data producers must choose which
data model to use.
Reasons to use the classic model:

➢ Data using the classic model can be read by all existing netCDF software.
➢ Writing programs for classic model data is easier.
➢ Most or all existing netCDF conventions are targeted at the classic model.
➢ Many great features, like compression, parallel I/O, large data sizes, etc.,are available within the
classic model.

Reasons to use the enhanced model:


➢ Complex data structures can be represented very easily in the data, leading to easier
programming.
➢ If existing HDF5 applications produce or use these data, and depend on user-defined types,
unsigned types, strings, or groups, then the enhancedmodel is required.
➢ In performance-critical applications, the enhanced model may providesignificant benefits.

Temporal Databases
Temporal data strored in a temporal database is different from the data stored in non-temporal
database in that a time period attached to the data expresses when it was valid or stored in the
database. As mentioned above, conventional databases consider the data stored in it to be valid
at time instant now, they do not keep track of past or future database states. By attaching a time
period to thedata, it becomes possible to store different database states.
A first step towards a temporal database thus is to timestamp the data. This allows the
distinction of different database states. One approach is that a temporal database may
timestamp entities with time periods. Another approachis the timestamping of the property values
of the entities. In the relational data model, tuples are timestamped, where as in object-oriented
data models, objectsand/or attribute values may be timestamped.

What time period do we store in these timestamps? As we mentioned already, there are mainly
two different notions of time which are relevant for temporal databases. One is called the valid
time, the other one is the transaction time. Valid time denotes the time period during which a fact
is true with respect to the real world. Transaction time is the time period during which a fact is
stored in the database. Note that these two time periods do not have to be the same for a single
fact. Imagine that we come up with a temporal database storing data about the 18th century. The
valid time of these facts is somewhere between 1700 and 1799, whereas the transaction time

859
starts when we insert the facts into the database, for example, January 21, 1998.

Assume we would like to store data about our employees with respect to the real world. Then, the
following table could result:

EmpID Name Department Salary Valid Time Start Valid Time End

10 John Research 11000 1985 1990

10 John Sales 11000 1990 1993

10 John Sales 12000 1993 INF

11 Paul Research 10000 1988 1995

12 George Research 10500 1991 INF

13 Ringo Sales 15500 1988 INF

The above valid-time table stores the history of the employees with respect to the real world. The
attributes Valid Time Start and Valid Time End actually represent a time interval which is closed
at its lower and open at its upper bound. Thus, we see that during the time period [1985 - 1990),
employee John was working in the

research department, having a salary of 11000. Then he changed to the sales department, still
earning 11000. In 1993, he got a salary raise to 12000. The upperbound INF denotes that the tuple
is valid until further notice. Note that it is now possible to store information about past states. We
see that Paul was employed from 1988 until 1995. In the corresponding non-temporal table, this
information was (physically) deleted when Paul left the company.

Different Forms of Temporal Databases


The two different notions of time - valid time and transaction time - allow the distinction of
different forms of temporal databases. A historical database stores data with respect to valid
time, a rollback database stores data with respect to transaction time. A bitemporal database
stores data with respect to both valid time and transaction time.
As mentioned above, commercial DBMS are said to store only a single state of the real world,
usually the most recent state. Such databases usually are
called snapshot databases. A snapshot database in the context of valid time and transaction time
is depicted in the following picture:
On the other hand, a bitemporal DBMS such as Time DB stores the history of data with respect to
both valid time and transaction time. Note that the history of when data was stored in the
database (transaction time) is limited to past and present database states, since it is managed by
the system directly which doesnot know anything about future states.
860
A table in the bitemporal relational DBMS Time DB may either be a snapshot table (storing only
current data), a valid-time table (storing when the data is valid wrt. the real world), a transaction-
time table (storing when the data was recorded in the database) or a bitemporal table (storing
both valid time and transaction time). An extended version of SQL allows to specify which kind of
table is needed when the table is created. Existing tables may also be altered (schema
versioning).
Additionally, it supports temporal queries, temporal modification statements and temporal
constraints.
The states stored in a bitemporal database are sketched in the picture below. Of course, a
temporal DBMS such as Time DB does not store each database state separately as depicted in
the picture below. It stores valid time and/or transactiontime for each tuple, as described above.

Multimedia Databases
The multimedia databases are used to store multimedia data such as images, animation, audio,
video along with text. This data is stored in the form of multiple file types like .txt(text),
.jpg(images), .swf(videos), .mp3(audio) etc.

Contents of the Multimedia Database


The multimedia database stored the multimedia data and information related to it. This is given in
detail as follows –

Media data
This is the multimedia data that is stored in the database such as images, videos, audios,
animation etc.

Media format data


The Media format data contains the formatting information related to the media data such as
sampling rate, frame rate, encoding scheme etc.

Media keyword data


This contains the keyword data related to the media in the database. For an image the keyword
data can be date and time of the image, description of theimage etc.

Media feature data


Th Media feature data describes the features of the media data. For an image, feature data can be
colours of the image, textures in the image etc.

Challenges of Multimedia Database


There are many challenges to implement a multimedia database. Some of theseare:
• Multimedia databases contains data in a large type of formats such as
• .txt(text), .jpg(images), .swf(videos), .mp3(audio) etc. It is difficult to convert one type of
data format to another.
• The multimedia database requires a large size as the multimedia data is quite large and
861
needs to be stored successfully in the database.
• It takes a lot of time to process multimedia data so multimedia database isslow.

Mobile Databases
Mobile databases are separate from the main database and can easily be transported to various
places. Even though they are not connected to the maindatabase, they can still communicate with
the database to share and exchangedata.
The mobile database includes the following components −
• The main system database that stores all the data and is linked to themobile database.
• The mobile database that allows users to view information even while on the move. It
shares information with the main database.
• The device that uses the mobile database to access data. This device can be a mobile
phone, laptop etc.
• A communication link that allows the transfer of data between the mobile database and the
main database.

Advantages of Mobile Databases


Some advantages of mobile databases are −

• The data in a database can be accessed from anywhere using a mobile database. It
provides wireless database access.
• The database systems are synchronized using mobile databases and multiple users can
access the data with seamless delivery process.
• Mobile databases require very little support and maintenance.
• The mobile database can be synchronized with multiple devices such as mobiles, computer
devices, laptops etc.

Disadvantages of Mobile Databases


Some disadvantages of mobile databases are −

• The mobile data is less secure than data that is stored in a conventional stationary
database. This presents a security hazard.
• The mobile unit that houses a mobile database may frequently lose power because of
limited battery. This should not lead to loss of data in database.

Deductive Database
A deductive database is a database system that makes conclusions about
its data based on a set of well-defined rules and facts. This type of database was developed to
combine logic programming with relational database management systems. Usually, the language
used to define the rules and facts is the logical programming language Data log.

A Deductive Database is a type of database that can make conclusions, or we cansay deductions
using a set of well-defined rules and fact that are stored in the database. In today’s world as we
862
deal with a large amount of data, this deductive database provides a lot of advantages. It helps to
combine the RDBMS with logic programming. To design a deductive database a purely declarative
programminglanguage called Data log is used.
The implementations of deductive databases can be seen in LDL (Logic Data Language), NAIL
(Not Another Implementation of Logic), CORAL, and VALIDITY. The use of LDL and VALIDITY in a
variety of business/industrial applications are asfollows.
1. LDL Applications:
This system has been applied to the following application domains:
• Enterprise modeling:
Data related to an enterprise may result in an extended ER model containing hundreds of entities
and relationship and thousands of attributes. This domain involves modeling the structure,
processes, andconstraints within an enterprise.
• Hypothesis testing or data dredging:
This domain involves formulating a hypothesis, translating in into an LDL rule set and a query, and
then executing the query against given data to test the hypothesis. This has been applied to
genome data analysis in the field of microbiology, where data dredging consists of identifying the
DNA sequences from low-level digitized auto radio graphs from experiments performed on [Link]
Bacteria.

•Software reuse:
A small fraction of the software for an application is rule-based and encoded in LDL (bulk is
developed in standard procedural code). The rules give rise to a knowledge base that contains, A
definition of each C module used in system and A set of rules that defines ways in which modules
can export/import functions, constraints and so on. The “Knowledge base” can be used to make
decisions that pertain to the reuse of software subsets.
This is being experimented within banking software.

2. VALIDITY Applications:
Validity combines deductive capabilities with the ability to manipulate complex objects (OIDs,
inheritance, methods, etc). It provides a DOOD data model and language called DEL (Datalog
Extended Language), an engine working along a client-server model and a set of tools for schema
and rule editing, validation, andquerying.

The following are some application areas of the VALIDITY system:


• Electronic commerce:
In electronic commerce, complex customers profiles have to be matched against target
descriptions. The matching process is also described by rules, and computed predicates deal with
numeric computations. The declarative nature of DEl makes the formulation of the matching
algorithm easy.
• Rules-governed processes:
In a rules-governed process, well defined rules define the actions to be performed. In those
process some classes are modeled as DEL classes. The main advantage of VALIDITY is the ease
with which new regulations are taken into account.
863
• Knowledge discovery:
The goal of knowledge discovery is to find new data relationships by analyzing existing data. An
application prototype developed by University of Illinois utilizes already existing minority student
data that has been enhanced with rules in DEL.
• Concurrent Engineering:
A concurrent engineering application deals with large amounts of centralized data, shared by
several participants. An application prototype has been developed in the area of civil engineering.
The design data is modeled using the object-oriented power of the DEL language. DEL is able to
handle transformation of rules into constraints, and it can also handle any closed formula as an
integrity constraint.

XML - Databases
XML Database is used to store huge amount of information in the XML format. As the use of
XML is increasing in every field, it is required to have a secured place to store the XML
documents. The data stored in the database can be queried using XQuery, serialized, and
exported into a desired format.

XML Database Types


There are two major types of XML databases −

• XML- enabled
• Native XML (NXD)

XML - Enabled Database


XML enabled database is nothing, but the extension provided for the conversion of XML
document. This is a relational database, where data is stored in tables consisting of rows and
columns. The tables contain set of records, which in turn consist of fields.

Native XML Database


Native XML database is based on the container rather than table format. It can store large amount
of XML document and data. Native XML database is queried by the XPath-expressions.
Native XML database has an advantage over the XML-enabled database. It is highly capable to
store, query and maintain the XML document than XML- enabled database.

Example
Following example demonstrates XML database −
<?xml version = "1.0"?>
<contact-info>
<contact1>
<name>Tanmay Patil</name>
<company>Tutorials Point</company>
<phone>(011) 123-4567</phone>
</contact1>
<contact2>
<name>Manisha Patil</name>

864
<company>Tutorials Point</company>
<phone> (011) 789-4567</phone>
</contact2>
</contact-info>
Here, a table of contacts is created that holds the records of contacts (contact1 and contact2),
which in turn consists of three entities − name, company and phone.

Internet Database Applications


Internet Database Applications are programs that are built to run on Internet browsers and
communicate with database servers. Internet Database Applications are usually developed using
very few graphics and are built usingXHTML forms and Style Sheets.
Most companies are starting to migrate from the old-fashioned desktop database applications to
web based Internet Database Applications in XHTML format.

Below are some of the benefits of Internet Database Applications:

➢ Powerful and Scalable - Internet Database Applications are more robust, agile and able to
expand and scale up more easily.
Database servers that are built to serve Internet applications are designed to handle millions of
concurrent connections and complex SQL queries.
A good example is Facebook, which uses database servers that are able to handle millions of
inquiries and complex SQL queries.
Internet database applications use the same type of database server that is designed to run
Facebook. The database servers that are built to serve desktop applications usually can handle
only a limited number of connections and are not able to deal with complex SQL queries.
• Web Based - Internet Database Applications are web-based applications, therefore the data
can be accessed using a browser at any location.
• Security - Database servers have been fortified with preventive features and security
protocols have been implemented to combat today's cyber security threats and
vulnerabilities.
• Open Source, Better Licensing Terms and Cost Savings - There are many powerful
database servers that are open source. This means that there is no licensing cost. Many
large enterprise sites are using Open-Source Database Servers, such as Facebook, Yahoo,
YouTube, Flickr, Wikipedia, etc.
Open Source also creates less dependence on vendors, which is a big advantage because that
provides more product quality control and lower cost. Open source also offers easier
customization and is experiencing a fast-growing adoption rate, especially by the large and influential
enterprises.
➢ Abundant Features - There are many open-source programming languages(such as PHP, Python,
Ruby) and hundreds of powerful open-source libraries, tools and plug-ins specifically built to
interact with today's database servers.

Geographical information system (GIS)


865
Geographical information system (GIS) is basically defined as a systematic integration of
hardware and software for capturing, storing, displaying, updating manipulating and analyzing
spatial data. GIS can also be viewed as an interdisciplinary area that incorporates many distinct
fields of study such as:
1. Geodesy that is basically projection,surveying, cartography and so on.

2. Remote Sensing
3. Photogrammetry
4. Environmental Science
5. City Planning
6. Cognitive Science
As a result, GIS relies on progress made in fields such as computer science, databases, statistics,
and artificial intelligence. All the different problems and question that arises from the integration
of multiple disciplines make a more thana simple tool.

Requirements for GIS –


Geographic Information requires a means of integration between different sources of data at
different level of accuracy. System basically deals with the aspects of daily life, so it must be
updated daily to keep it current and [Link] of the Information Stored in GIS are for practical
use requires a special means of retrieval and manipulation.
GIS system and application basically deals with information that can be viewed as data with
specific meaning and context rather than simple data.

Components of GIS system –


GIS system can be viewed as an integration of three components are hardwareand software, data,
people. Let’s discuss them one by one:
1. Hardware and software –
Hardware relates to device used by end users such as graphic devices or plotters and scanners.
Data storage and manipulation is done using a range of processor. With the development of the
Internet and Web based application, Web servers have become part of many system’s
architecture,hence most GIS’s follows 3-Tier architecture.
Software parts relates to the processes used to define, store and manipulate thedata and hence it
is akin to DBMS. Different models are used to provide efficient means of storage retrieval and
manipulation of data.
2. Data –
Geographic data are basically divided into two main groups are vector andraster.
Vector data/layers in GIS refers to discrete objects represented by points, lines and polygons.
Lines are formed by connecting two or more points and polygons are closed set of Lines. Layers
represent geometries that share a common set of attributes. Objects within a layer have mutual
topology. Vector sources include digitized maps, features extracted from image surveys and
many more.
Raster data is a continuous grid of cells in two dimension or the equivalent of cubic cells in three
dimensions. Raster data are divided conceptually into categorical and continuous. In a categorical
866
raster every cell value is linked to a category in a separate table. Examples Soil type, vegetation
types. Land suitability, and so on. Continuous raster images usually describe continuous
phenomena inspace such as Digital Elevation Model where each pixel is an elevation value.
Unlike categorical raster, a continuous raster doesn’t have an attribute/category table attached.
Typical Raster sources are aerial images, satellite images and scanned map images.
3. People –
People are involved in all phases of development of a GIS system and in collecting data. They
include cartographers and surveyors who create the maps and survey the land and the
geographical features. They also include system users who collect the data, upload the data to
system, manipulate the system and analyze the results.

Genome Data Management


GENOME is a prototype database management system (DBMS)/user interface system designed
to manage complex biological data, allowing users to more fully analyze and understand
relationships in human genome data. The system is designed to allow the establishment of a net-
work of searchable data sources.

Characteristics of Biological Data (Genome Data Management)


There are many characteristics of biological data. All these characteristics make the management
of biological information a particularly challenging problem.
Here mainly we will focus on characteristics of biological information and multidisciplinary field
called bioinformatics. Bioinformatics, now a days has emerged with graduate degree programs in
several universities.

Characteristics of Biological Information:


• There is a high amount and range of variability in data.
• There should be a flexibility in biological systems so that it can handle data types and
values. Placing constraints on data types must be limited with such a wide range of
possible data values. There can be a loss of information when there is exclusion of such
values.
• There will be a difference in representation of the same data by differentbiologists.
• This can be done even using the same system. There is multiple ways to model any given
entity with the results often reflecting the particular focusof the scientist.
• There should be a linking of data elements in a network of schemas.
• Defining the complex queries and also important to the biologists. Complex queries must
be supported by biological systems. Knowledge of the data structure is needed for the
average users because with the help of this knowledge average user can construct a
complex query across data sets on their own. For these systems must provide some tools
for building these queries.
• When compared with most other domains or applications, biological data becomes highly
complex.
• Such data must ensure that no information is lost during biological data modelling and

867
such data must be able to represent a complex substructure of data as well as
relationships. An additional context is provided by the structure of the biological data for
interpretation of the information.
• There is a rapid change in schemas of biological databases.
• There should be a support of schema evolution and data object migration so that there can
be an improved information flow between generations orreleases of databases.
• The relational database systems support the ability to extend the schema and a frequent
occurrence in the biological setting.
• Most biologists are not likely to have knowledge of internal structure of the database or
about schema design.
• Users need an information which can be displayed in a manner such that it can be
applicable to the problem which they are trying to address. Also the data structure should
be reflected in an easy and understandable manner. An information regarding the meaning
of the schema is not provided to the user because of the failure by the relational schemas.
A present search interfaces is provided by the web interfaces, which may limit access into
the database.
• There is no need of the write access to the database by the users ofbiological data, instead
they only require read access.
• There is limitation of write access to the privileged users called curators. There are only
small numbers of users which require write access but a wide variety of read access
patterns are generated by the users into thedatabases.
• Access to “old” values of the data are required by the users of biological data most often
while verifying the previously reported results.
• Hence system of archives must support the changes to the values of the
• data in the database. Access to both the most recent version of data value and its previous
version are important in the biological domain.
• Added meaning is given by the context of data for its use in biologicalapplications.
Whenever appropriate, context must be maintained and conveyed to the user. For the
maximization of the interpretation of a biological data value, it should be possible to integrate as
many contexts as possible.

Distributed databases
Distributed databases can be classified into homogeneous and heterogeneous databases having
further divisions.

Types of Distributed Databases


Distributed databases can be broadly classified into homogeneous and heterogeneous distributed
database environments, each with further sub-divisions, as shown in the following illustration.

Homogeneous Distributed Databases


In a homogeneous distributed database, all the sites use identical DBMS and operating systems.
Its properties are −

868
• The sites use very similar software.
• The sites use identical DBMS or DBMS from the same vendor.

• Each site is aware of all other sites and cooperates with other sites to process user
requests.
• The database is accessed through a single interface as if it is a singledatabase.

Types of Homogeneous Distributed Database


There are two types of homogeneous distributed database −

• Autonomous − Each database is independent that functions on its own. They are
integrated by a controlling application and use message passing toshare data updates.
• Non-autonomous − Data is distributed across the homogeneous nodes and a central or
master DBMS co-ordinates data updates across the sites.
• Heterogeneous Distributed Databases
• In a heterogeneous distributed database, different sites have different operating systems,
DBMS products and data models. Its properties are −
• Different sites use dissimilar schemas and software.
• The system may be composed of a variety of DBMSs like relational, network, hierarchical or
object oriented.
• Query processing is complex due to dissimilar schemas.
• Transaction processing is complex due to dissimilar software.
• A site may not be aware of other sites and so there is limited co-operation in processing
user requests.

Types of Heterogeneous Distributed Databases

• Federated − The heterogeneous database systems are independent in nature and


integrated together so that they function as a single databasesystem.
• Un-federated − The database systems employ a central coordinatingmodule through which
the databases are accessed.
• Distributed DBMS Architectures
• DDBMS architectures are generally developed depending on three parameters −
• Distribution − It states the physical distribution of data across the differentsites.
• Autonomy − It indicates the distribution of control of the database systemand the degree to
which each constituent DBMS can operate independently.
• Heterogeneity − It refers to the uniformity or dissimilarity of the data models, system
components and databases.

Architectural Models
Some of the common architectural models are −
• Client - Server Architecture for DDBMS

869
• Peer - to - Peer Architecture for DDBMS
• Multi - DBMS Architecture

Client - Server Architecture for DDBMS


This is a two-level architecture where the functionality is divided into servers and clients. The
server functions primarily encompass data management, query processing, optimization and
transaction management. Client functions include mainly user interface. However, they have
some functions like consistency checking and transaction management.

The two different client - server architecture is −


• Single Server Multiple Client
• Multiple Server Multiple Client (shown in the following diagram)

Peer- to-Peer Architecture for DDBMS


In these systems, each peer acts both as a client and a server for imparting database services.
The peers share their resource with other peers and co-ordinate their activities.
This architecture generally has four levels of schemas −

• Global Conceptual Schema − Depicts the global logical view of data.


• Local Conceptual Schema − Depicts logical data organization at each site.
• Local Internal Schema − Depicts physical data organization at each site.
• External Schema − Depicts user view of data.

Multi - DBMS Architectures


This is an integrated database system formed by a collection of two or more autonomous
database systems.

Multi-DBMS can be expressed through six levels of schemas −


• Multi-database View Level − Depicts multiple user views comprising of subsets of the
integrated distributed database.
• Multi-database Conceptual Level − Depicts integrated multi-database that comprises of
global logical multi-database structure definitions.
• Multi-database Internal Level − Depicts the data distribution across different sites and
multi-database to local data mapping.
• Local database View Level − Depicts public view of local data.
• Local database Conceptual Level − Depicts local data organization at eachsite.
• Local database Internal Level − Depicts physical data organization at eachsite.
• There are two design alternatives for multi-DBMS −
• Model with multi-database conceptual level.
• Model without multi-database conceptual level.

Design Alternatives
The distribution design alternatives for the tables in a DDBMS are as follows −
• Non-replicated and non-fragmented
• Fully replicated
870
• Partially replicated
• Fragmented
• Mixed

Non-replicated & non-fragmented


In this design alternative, different tables are placed at different sites. Data is placed so that it is
at a close proximity to the site where it is used most. It is most suitable for database systems
where the percentage of queries needed to join information in tables placed at different sites is
low. If an appropriate distribution strategy is adopted, then this design alternative helps to reduce
the communication cost during data processing.

Fully Replicated
In this design alternative, at each site, one copy of all the database tables is stored. Since, each
site has its own copy of the entire database, queries are very fast requiring negligible
communication cost. On the contrary, the massive redundancy in data requires huge cost during
update operations. Hence, this is suitable for systems where a large number of queries is required
to be handled whereas the number of database updates is low.

Partially Replicated
Copies of tables or portions of tables are stored at different sites. The distribution of the tables is
done in accordance to the frequency of access. This takes into consideration the fact that the
frequency of accessing the tables vary considerably from site to site. The number of copies of the
tables (or portions) depends on how frequently the access queries execute and the site which
generate the access queries.

Fragmented
In this design, a table is divided into two or more pieces referred to as fragments or partitions, and
each fragment can be stored at different sites. This considers the fact that it seldom happens that
all data stored in a table is required at a given site. Moreover, fragmentation increases parallelism
and provides better disaster recovery. Here, there is only one copy of each fragment in the
system, i.e., no redundant data.
The three fragmentation techniques are −
• Vertical fragmentation
• Horizontal fragmentation
• Hybrid fragmentation

Mixed Distribution
This is a combination of fragmentation and partial replications. Here, the tables are initially
fragmented in any form (horizontal or vertical), and then these fragments are partially replicated
across the different sites according to the frequency of accessing the fragments.

DBMS Architecture
In client server computing, the clients requests a resource and the server provides that resource. A

871
server may serve multiple clients at the same time while a client is in contact with only one server.
• The DBMS design depends upon its architecture. The basic client/server architecture is
used to deal with a large number of PCs, web servers, database servers and other
components that are connected with networks.
• The client/server architecture consists of many PCs and a workstationwhich are connected
via the network.
• DBMS architecture depends upon how users are connected to the database to get their
request done.

Types of DBMS Architecture


Database architecture can be seen as a single tier or multi-tier. But logically,database architecture
is of two types like: 2-tier architecture and 3-tier architecture.
The different structures for two tier and three tier are given as follows −

Two - Tier Client/Server Architecture


The two-tier architecture primarily has two parts, a client tier and a server tier. The client tier sends
a request to the server tier and the server tier responds with the desired information.
An example of a two-tier client/server structure is a web server. It returns the required web pages
to the clients that requested them.
An illustration of the two-tier client/server structure is as follows −

Advantages of Two - Tier Client/Server Architecture


Some of the advantages of the two-tier client/server structure are −
• This structure is quite easy to maintain and modify.
• The communication between the client and server in the form of request response
messages is quite fast.

Disadvantages of Two - Tier Client/Server Architecture


A major disadvantage of the two-tier client/server structure is −
If the client nodes are increased beyond capacity in the structure, then the server is not able to
handle the request overflow and performance of the system degrades.

Three - Tier Client/Server Architecture


The three-tier architecture has three layers namely client, application and data layer. The client
layer is the one that requests the information. In this case it could be the GUI, web interface etc.
The application layer acts as an interface between the client and data layer. It helps in
communication and also provides security.
The data layer is the one that actually contains the required data. An illustration of the three-tier
client/server structure is as follows −

Advantages of Three - Tier Client/Server Architecture


Some of the advantages of the three-tier client/server structure are −
872
• The three-tier structure provides much better service and fast performance.
• The structure can be scaled according to requirements without anyproblem.
• Data security is much improved in the three-tier structure.

Disadvantages of Three - Tier Client/Server Architecture


A major disadvantage of the three-tier client/server structure is −
• Three - tier client/server structure is quite complex due to advancedfeatures.

Data Mining Vs Data Warehousing


Data warehouse refers to the process of compiling and organizing data into one common
database, whereas data mining refers to the process of extracting usefuldata from the databases.
The data mining process depends on the data compiled in the data warehousing phase to
recognize meaningful patterns. A data warehousing is created to support management systems.

Data Warehouse:
A Data Warehouse refers to a place where data can be stored for useful mining. It is like a quick
computer system with exceptionally huge data storage capacity.
Data from the various organization's systems are copied to the Warehouse, whereit can be fetched
and conformed to delete errors. Here, advanced requests can be made against the warehouse
storage of data.

Data warehouse combines data from numerous sources which ensure the data quality, accuracy,
and consistency. Data warehouse boosts system execution by separating analytics processing
from transnational databases. Data flows into a data warehouse from different databases. A data
warehouse works by sorting out data into a pattern that depicts the format and types of data.
Query tools examine the data tables using patterns.
Data warehouses and databases both are relative data systems, but both are made to serve
different purposes. A data warehouse is built to store a huge amount of historical data and
empowers fast requests over all the data, typically using Online Analytical Processing (OLAP). A
database is made to store current transactions and allow quick access to specific transactions
for ongoing businessprocesses, commonly known as Online Transaction Processing (OLTP).
Important Features of Data Warehouse

The Important features of Data Warehouse are given below:


1. Subject Oriented

A data warehouse is subject-oriented. It provides useful data about a subject instead of the
company's ongoing operations, and these subjects can be customers, suppliers, marketing,
product, promotion, etc. A data warehouses
usually focuses on modeling and analysis of data that helps the business organization to make
data-driven decisions.
873
2. Time-Variant:
The different data present in the data warehouse provides information for aspecific period.
3. Integrated
A data warehouse is built by joining data from heterogeneous sources, such as social databases,
level documents, etc.
4. Non- Volatile
It means, once data entered the warehouse cannot be change.

Advantages of Data Warehouse:


➢ More accurate data access
➢ Improved productivity and performance
➢ Cost-efficient
➢ Consistent and quality data

Data Mining:
Data mining refers to the analysis of data. It is the computer-supported process of analyzing huge
sets of data that have either been compiled by computer systems or have been downloaded into
the computer. In the data mining process, the computer analyzes the data and extract useful
information from it. It looks for hidden patterns within the data set and try to predict future
behavior. Data mining is primarily used to discover and indicate relationships among the data
sets.
Data mining aims to enable business organizations to view business behaviors, trends
relationships that allow the business to make data-driven decisions. It is also known as
knowledge Discover in Database (KDD). Data mining tools utilize AI, statistics, databases, and
machine learning systems to discover the relationship between the data. Data mining tools can
support business-related questions that traditionally time-consuming to resolve any issue.

Important features of Data Mining:


The important features of Data Mining are given below:
➢ It utilizes the Automated discovery of patterns.
➢ It predicts the expected results.
➢ It focuses on large data sets and databases
➢ It creates actionable [Link] of Data Mining:

i. Market Analysis:
Data Mining can predict the market that helps the business to make the decision. For example, it
predicts who is keen to purchase what type of products.

ii. Fraud detection:


Data Mining methods can help to find which cellular phone calls, insurance claims, credit, or debit
card purchases are going to be fraudulent.

iii. Financial Market Analysis:


874
Data Mining techniques are widely used to help Model Financial Market

iv. Trend Analysis:


Analyzing the current existing trend in the marketplace is a strategic benefit because it helps in
cost reduction and manufacturing process as per marketdemand.

Differences between Data Mining and Data Warehousing:

Data Mining Data Warehousing

Data mining is the process ofdetermining A data warehouse is a database systemdesigned for
data patterns. analytics.

Data mining is generally considered as


Data warehousing is the process ofcombining all the
the process ofextracting useful data from
relevant data.
alarge set of data.

Business entrepreneurs carrydata mining Data warehousing is entirely carried out bythe
with the help of engineers. engineers.

In data mining, data is analyzed In data warehousing, data is stored

repeatedly. periodically.

Data mining uses patternrecognition Data warehousing is the process of extracting and
techniques toidentify patterns. storing data that alloweasier reporting.

875
One of the most amazing data mining One of the advantages of the data warehouse is its
techniques is the detectionand ability to update frequently. That is the reason why it is
identification of the unwanted errors that idealfor business entrepreneurs who want up todate
occur in the system. with the latest stuff.

The data mining techniques arecost-


The responsibility of the data warehouse isto simplify
efficient as compared to other statistical
every type of business data.
data applications.

In the data warehouse, there is a highpossibility that


The data mining techniques are not 100
the data required for analysis by the company may not
percent accurate. It may lead to serious
be integrated into the warehouse. It cansimply lead to
consequences in acertain condition.
loss of data.

Companies can benefit from thisanalytical Data warehouse stores a huge amount of historical
tool by equipping suitable and accessible data that helps users to analyze different periods and
knowledge-based data. trends to make futurepredictions.

Data Warehouse Modeling


Data warehouse modeling is the process of designing the schemas of the detailed and
summarized information of the data warehouse. The goal of data warehouse modeling is to
develop a schema describing the reality, or at least a part of the fact, which the data warehouse is
needed to support.
Data warehouse modeling is an essential stage of building a data warehouse for two main
reasons. Firstly, through the schema, data warehouse clients can visualize the relationships
among the warehouse data, to use them with greater ease. Secondly, a well-designed schema
allows an effective data warehouse structure to emerge, to help decrease the cost of
implementing the warehouse and improve the efficiency of using it.
Data modeling in data warehouses is different from data modeling in operational database
systems. The primary function of data warehouses is to support DSS processes. Thus, the
objective of data warehouse modeling is to make the data warehouse efficiently support complex

876
queries on long term information.
In contrast, data modeling in operational database systems targets efficiently supporting simple
transactions in the database such as retrieving, inserting, deleting, and changing data. Moreover,
data warehouses are designed for the customer with general information knowledge about the
enterprise, whereas operational database systems are more oriented toward use by software
specialists for creating distinct applications.

Data Warehouse model is illustrated in the given diagram.


The data within the specific warehouse itself has a particular architecture with the emphasis on
various levels of summarization, as shown in figure:
The current detail record is central in importance as it:
o Reflects the most current happenings, which are commonly the moststimulating.
o It is numerous as it is saved at the lowest method of the Granularity.
o It is always (almost) saved on disk storage, which is fast to access but expensive and difficult to
manage.

Older detail data is stored in some form of mass storage, and it is infrequently accessed and kept
at a level detail consistent with current detailed data.

Lightly summarized data is data extract from the low level of detail found at the current, detailed
level and usually is stored on disk storage. When building the data warehouse have to remember
what unit of time summarization is done over and also the components or what attributes the
summarized data will contain.
Highly summarized data is compact and directly available and can even be found outside the
warehouse.

Metadata is the final element of the data warehouses and is really of various dimensions in which
it is not the same as file drawn from the operational data,but it is used as: -
• A directory to help the DSS investigator locate the items of the datawarehouse.
• A guide to the mapping of record as the data is changed from the operational data to the
data warehouse environment.
• A guide to the method used for summarization between the current, accurate data and the
lightly summarized information and the highlysummarized data, etc.

Data Modeling Life Cycle


In this section, we define a data modeling life cycle. It is a straightforward process of transforming
the business requirements to fulfill the goals for storing, maintaining, and accessing the data
within IT systems. The result is a logical and physical data model for an enterprise data
warehouse.
The objective of the data modeling life cycle is primarily the creation of a storage area for
business information. That area comes from the logical and physical data modeling stages, as
shown in Figure:

877
Conceptual Data Model
A conceptual data model recognizes the highest-level relationships between thedifferent entities.
Characteristics of the conceptual data model
• It contains the essential entities and the relationships among them.
• No attribute is specified.
• No primary key is specified.

We can see that the only data shown via the conceptual data model is the entities that define the
data and the relationships between those entities. No other data, as shown through the
conceptual data model.

Logical Data Model


A logical data model defines the information in as much structure as possible, without observing
how they will be physically achieved in the database. The primary objective of logical data
modeling is to document the business data structures, processes, rules, and relationships by a
single view - the logical datamodel.

Features of a logical data model


• It involves all entities and relationships among them.
• All attributes for each entity are specified.
• The primary key for each entity is stated.
• Referential Integrity is specified (FK Relation).

The phase for designing the logical data model which are as follows:
• Specify primary keys for all entities.
• List the relationships between different entities.
• List all attributes for each entity.
• Normalization.
• No data types are listed

Physical Data Model


Physical data model describes how the model will be presented in the database. A physical
database model demonstrates all table structures, column names, data types, constraints,
primary key, foreign key, and relationships between tables.
The purpose of physical data modeling is the mapping of the logical data model to the physical
structures of the RDBMS system hosting the data warehouse. This contains defining physical
RDBMS structures, such as tables and data types to use when storing the information. It may also
include the definition of new data structures for enhancing query performance.

Characteristics of a physical data model

• Specification all tables and columns.

Foreign keys are used to recognize relationships between tables. The steps for physical data
model design which are as follows:
878
• Convert entities to tables.
• Convert relationships to foreign keys.
• Convert attributes to columns.

Types of Data Warehouse Models

Enterprise Warehouse
An Enterprise warehouse collects all the records about subjects spanning the entire organization.
It supports corporate-wide data integration, usually from one or more operational systems or
external data providers, and it's cross-functional in scope. It generally contains detailed
information as well as summarized information and can range in estimate from a few gigabytes
to hundreds of gigabytes, terabytes, or beyond.
An enterprise data warehouse may be accomplished on traditional mainframes, UNIX super
servers, or parallel architecture platforms. It required extensive business modeling and may take
years to develop and build.

Data Mart
A data mart includes a subset of corporate-wide data that is of value to a specific collection of
users. The scope is confined to particular selected subjects. For example, a marketing data mart
may restrict its subjects to the customer, items, and sales. The data contained in the data marts
tend to be summarized.

Data Marts is divided into two parts:

Independent Data Mart: Independent data mart is sourced from data captured from one or more
operational systems or external data providers, or data generally locally within a different
department or geographic area.

Dependent Data Mart: Dependent data marts are sourced exactly from enterprise data-
warehouses.

Virtual Warehouses
Virtual Data Warehouses is a set of perception over the operational database. For effective query
processing, only some of the possible summary vision may be materialized. A virtual warehouse
is simple to build but required excess capacity on operational database servers.

Concept Hierarchy
A concept hierarchy defines a sequence of mappings from a set of low-level concepts to higher-
level, more general concepts. Consider a concept hierarchy for the dimension location. City values
for location include Vancouver, Toronto, New York, and Chicago. Each city, however, can be
mapped to the province or state to which it belongs. For example, Vancouver can be mapped to
British Columbia, and Chicago to Illinois. The provinces and states can in turn be mapped to the
country (e.g., Canada or the United States) to which they belong. These mappings form a concept

879
hierarchy for the dimension location, mapping a set of low-level concepts (i.e., cities) to higher-
level, more general concepts (i.e., countries). This concept hierarchy is illustrated in Figure 4.9.

Figure 4.9. A concept hierarchy for location. Due to space limitations, not all ofthe hierarchy nodes
are shown, indicated by ellipses between nodes.
Many concept hierarchies are implicit within the database schema. For example, suppose that the
dimension location is described by the attributes number, street, city, province_or_state, zip code,
and country. These attributes are related by a total order, forming a concept hierarchy such as
“street < city < province_or_state< country.” This hierarchy is shown in Figure 4.10(a). Alternatively,
the attributesof a dimension may be organized in a partial order, forming a lattice. An exampleof a
partial order for the time dimension based on the attributes day, week, month, quarter, and year is
“day < {month < quarter; week} < year.”1 This lattice structure is shown in Figure 4.10(b). A
concept hierarchy that is a total or partial order among attributes in a database schema is called a
schema hierarchy.
Concept hierarchies that are common to many applications (e.g., for time) may be predefined in
the data mining system. Data mining systems should provide users with the flexibility to tailor
predefined hierarchies according to their particular needs. For example, users may want to define
a fiscal year starting on April 1 or an academic year starting on September 1.

Figure 4.10. Hierarchical and lattice structures of attributes in warehouse dimensions: (a) a
hierarchy for location and (b) a lattice for [Link] hierarchies may also be defined by
discretizing or grouping values for a given dimension or attribute, resulting in a set-grouping
hierarchy. A total or partial order can be defined among groups of values. An example of a set-
grouping hierarchy is shown in Figure 4.11 for the dimension price, where an interval ($X…$Y]
denotes the range from $X (exclusive) to $Y (inclusive).
Figure 4.11. A concept hierarchy for price.
There may be more than one concept hierarchy for a given attribute or dimension, based on
different user viewpoints. For instance, a user may prefer to organize price by defining ranges for
inexpensive, moderately priced, and expensive.

Concept hierarchies may be provided manually by system users, domain experts, or knowledge
engineers, or may be automatically generated based on statistical analysis of the data
distribution. The automatic generation of concept hierarchies is discussed in Chapter 3 as a
preprocessing step in preparation for data mining.
OLTP and OLAP: The two terms look similar but refer to different kinds of systems. Online
transaction processing (OLTP) captures, stores, and processes data from transactions in real
time. Online analytical processing (OLAP) uses complex queries to analyze aggregated historical
data from OLTP systems.

OLTP
An OLTP system captures and maintains transaction data in a database. Each transaction
involves individual database records made up of multiple fields or columns. Examples include
banking and credit card activity or retail checkoutscanning.
880
In OLTP, the emphasis is on fast processing, because OLTP databases are read, written, and
updated frequently. If a transaction fails, built-in system logic ensures data integrity.

OLAP
OLAP applies complex queries to large amounts of historical data, aggregated from OLTP
databases and other sources, for data mining, analytics, and business intelligence projects. In
OLAP, the emphasis is on response time to these complex queries. Each query involves one or
more columns of data aggregated from many rows. Examples include year-over-year financial
performance or marketing lead generation trends. OLAP databases and data warehouses give
analysts and decision-makers the ability to use custom reporting tools to turn data into
information. Query failure in OLAP does not interrupt or delay transaction processing for
customers, but it can delay or impact the accuracy of businessintelligence insights.

OLTP vs. OLAP: side-by-side comparison


OLTP is operational, while OLAP is informational. A glance at the key features of both kinds of
processing illustrates their fundamental differences, and how theywork together.

OLTP OLAP

Handles large volumes of data


Handles a large number of small
with complex queries
Characteristics transactions

Simple standardizedqueries
Query types Complex queries

Based on INSERT,UPDATE, DELETE Based on SELECT commands to


Operations commands aggregate data forreporting

Seconds, minutes,or hours


Response time Milliseconds depending on the

881
amount of data to
process

Industry-specific, such as retail, Subject-specific, such as sales,


Design manufacturing, orbanking inventory, or marketing

Aggregated data from


Source Transactions transactions

Plan, solve problems, support


Control and run essential business
decisions, discoverhidden
Purpose operations in realtime
insights

Data periodically refreshed


with scheduled, long- running
Data updates Short, fast updatesinitiated by user
batch jobs

Generally small ifhistorical data is Generally large due to


Space requirements archived aggregatinglarge datasets

Regular backups required to ensure Lost data can be reloaded


Backup andrecovery
business continuity from OLTP database as

882
and meet legal and needed in lieu of
governance requirements regular backups

Increases productivity of
business managers, data
Increases productivity of endusers analysts, and executives
Productivity

Lists day-to-daybusiness Multi-dimensional view of


Data view transactions enterprisedata

Knowledge workers such as


Customer-facing personnel, clerks, data analysts, business
online shoppers analysts,and executives
User examples

Denormalized databases for


Databasedesign Normalized databases forefficiency
analysis

OLTP provides an immediate record of current business activity, while OLAP generates and
validates insights from that data as it’s compiled over time. That historical perspective empowers
accurate forecasting, but as with all business intelligence, the insights generated with OLAP are
only as good as the datapipeline from which they emanate.

Association rules
Association rules are if-then statements that help to show the probability of relationships between
data items within large data sets in various types of databases. Association rule mining has a
number of applications and is widely used to help discover sales correlations in transactional data
or in medical datasets.
Association rule mining finds interesting associations and relationships among large sets of data
883
items. This rule shows how frequently a itemset occurs in a transaction. A typical example is
Market Based Analysis.
Market Based Analysis is one of the key techniques used by large relations to show associations
between items. It allows retailers to identify relationships between the items that people buy
together frequently.
Given a set of transactions, we can find rules that will predict the occurrence of an item based on
the occurrences of other items in the transaction.

TID ITEMS

1 Bread, Milk

2 Bread, Diaper, Beer, Eggs

3 Milk, Diaper, Beer, Coke

4 Bread, Milk, Diaper, Beer

TID ITEMS

5 Bread, Milk, Diaper, Coke

Before starting first see the basic definitions.

Support Count() – Frequency of occurrence of a [Link] ({Milk, Bread, Diaper})=2

Frequent Itemset – An itemset whose support is greater than or equal to minsupthreshold.

Association Rule – An implication expression of the form X -> Y, where X and Y areany 2 itemsets.
Example: {Milk, Diaper}->{Beer}
Rule Evaluation Metrics –

• Support(s) –
The number of transactions that include items in the {X} and {Y} parts of the rule as a percentage
of the total number of transactions. It is a measure of how frequently the collection of items occur
together as a percentage of alltransactions.
• Support = (X+Y) total –
It is interpreted as fraction of transactions that contain both X and Y.
• Confidence(c) –

884
It is the ratio of the no of transactions that includes all items in {B} as well as the no of
transactions that includes all items in {A} to the no of transactions that includes all items in {A}.
• Conf(X=>Y) = Supp (X Y) Supp(X) –
It measures how often each item in Y appears in transactions that containsitems in X also.
• Lift(l) –
The lift of the rule X=>Y is the confidence of the rule divided by the expected confidence,
assuming that the itemset X and Y are independent of each [Link] expected confidence is the
confidence divided by the frequency of {Y}.
• Lift(X=>Y) = Conf(X=>Y) Supp(Y) –
Lift value near 1 indicates X and Y almost often appear together as expected, greater than 1
means they appear together more than expected and less than 1 means they appear less than
expected. Greater lift values indicate stronger association.
Example – From the above table, {Milk, Diaper} =>{Beer}

s= ({Milk, Diaper, Beer}) |T|


= 2/5
= 0.4

The Association rule is very useful in analyzing datasets. The data is collected using bar-code
scanners in supermarkets. Such databases consist of a large number of transaction records
which list all items bought by a customer on a single purchase. So the manager could know if
certain groups of items are consistently purchased together and use this data for adjusting store
layouts,cross-selling, promotions based on statistics.

Classification
Classification is a data mining function that assigns items in a collection to target categories or
classes. The goal of classification is to accurately predict the target class for each case in the
data. For example, a classification model could be used to identify loan applicants as low,
medium, or high credit risks.
A classification task begins with a data set in which the class assignments are known. For
example, a classification model that predicts credit risk could be developed based on observed
data for many loan applicants over a period of time. In addition to the historical credit rating, the
data might track employment history, home ownership or rental, years of residence, number and
type of investments, and so on. Credit rating would be the target, the other attributes would be the
predictors, and the data for each customer would constitute a case.
Classifications are discrete and do not imply order. Continuous, floating-point values would
indicate a numerical, rather than a categorical, target. A predictive model with a numerical target
uses a regression algorithm, not a classification algorithm.
The simplest type of classification problem is binary classification. In binary classification, the
target attribute has only two possible values: for example, high credit rating or low credit rating.
Multiclass targets have more than two values: for example, low, medium, high, or unknown credit
rating.
In the model build (training) process, a classification algorithm finds relationships between the

885
values of the predictors and the values of the target. Different classification algorithms use
different techniques for finding relationships. These relationships are summarized in a model,
which can then be applied to a differentdata set in which the class assignments are unknown.
Classification models are tested by comparing the predicted values to known target values in a
set of test data. The historical data for a classification project is typically divided into two data
sets: one for building the model; the other for testing the model. See "Testing a Classification
Model".
Scoring a classification model results in class assignments and probabilities for each case. For
example, a model that classifies customers as low, medium, or high value would also predict the
probability of each classification for each customer.
Classification has many applications in customer segmentation, business modeling, marketing,
credit analysis, and biomedical and drug response modeling.

A Sample Classification Problem


Suppose we want to predict which of our customers are likely to increase spending if given an
affinity card. You could build a model using demographic dataabout customers who have used an
affinity card in the past. Since we want to predict either a positive or a negative response (will or
will not increase spending), we will build a binary classification model.
This example uses classification model, dt_sh_clas_sample, which is created by one of the Oracle
Data Mining sample programs (described in Oracle Data Mining Administrator's Guide). Figure 5-1
shows six columns and ten rows from the case table used to build the model. A target value of 1
has been assigned to customers who increased spending with an affinity card; a value of 0 has
been assigned to customers who did not increase spending.

Figure 5-1 Sample Build Data for Classification


After undergoing testing (see "Testing a Classification Model"), the model can be applied to the
data set that you wish to mine.
Figure 5-2 shows some of the predictions generated when the model is applied to the customer
data set provided with the Oracle Data Mining sample programs. It displays several of the
predictors along with the prediction (1=will increase spending; 0=will not increase spending) and
the probability of the prediction for each customer.

Figure 5-2 Classification Results in Oracle Data Miner

Description of "Figure 5-2 Classification Results in Oracle Data Miner"

Note:
Oracle Data Miner displays the generalized case ID in the DMR$CASE_ID column of the apply
output table. A "1" is appended to the column name of each predictor that you choose to include
in the output. The predictions (affinity card usage in Figure 5-2) are displayed in the PREDICTION
column. The probability of each prediction is displayed in the PROBABILITY column. For decision
trees, the node is displayed in the NODE column.
Since this classification model uses the Decision Tree algorithm, rules are generated with the
886
predictions and probabilities. With the Oracle Data Miner Rule Viewer, you can see the rule that
produced a prediction for a given node in the tree. Figure 5-3 shows the rule for node 5. The rule
states that married customerswho have a college degree (Associates, Bachelor, Masters, Ph.D., or
professional) are likely to increase spending with an affinity card.

Figure 5-3 Decision Tree Rules for Classification

Description of "Figure 5-3 Decision Tree Rules for Classification"


Testing a Classification Model
A classification model is tested by applying it to test data with known targetvalues and comparing
the predicted values with the known values.
The test data must be compatible with the data used to build the model and must be prepared in
the same way that the build data was prepared. Typically, the build data and test data come from
the same historical data set. A percentage of the records is used to build the model; the remaining
records are used to test the model.
Test metrics are used to assess how accurately the model predicts the known values. If the
model performs well and meets the business requirements, it can then be applied to new data to
predict the future.

Accuracy
Accuracy refers to the percentage of correct predictions made by the model when compared with
the actual classifications in the test data. Figure 5-4 shows the accuracy of a binary classification
model in Oracle Data Miner.

Figure 5-4 Accuracy of a Binary Classification Model

Description of "Figure 5-4 Accuracy of a Binary Classification Model"


Confusion Matrix
A confusion matrix displays the number of correct and incorrect predictions made by the model
compared with the actual classifications in the test data. The matrix is n-by-n, where n is the
number of classes.
Figure 5-5 shows a confusion matrix for a binary classification model. The rows present the
number of actual classifications in the test data. The columns present the number of predicted
classifications made by the model.

Figure 5-5 Confusion Matrix for a Binary Classification Model

Description of "Figure 5-5 Confusion Matrix for a Binary Classification Model"


In this example, the model correctly predicted the positive class
for affinity card 516 times and incorrectly predicted it 25 times. The model correctly predicted the
negative class for affinity card 725 times and incorrectly predicted it 10 times. The following can
be computed from this confusion matrix:
• The model made 1241 correct predictions (516 + 725).
• The model made 35 incorrect predictions (25 + 10).
887
• There are 1276 total scored cases (516 + 25 + 10 + 725).
• The error rate is 35/1276 = 0.0274.
• The overall accuracy rate is 1241/1276 = 0.9725.

Clustering
Clustering analysis finds clusters of data objects that are similar in some sense to one another.
The members of a cluster are more like each other than they are like members of other clusters.
The goal of clustering analysis is to find high-quality clusters such that the inter-cluster similarity
is low, and the intra-cluster similarity is high.
Clustering, like classification, is used to segment the data. Unlike classification, clustering models
segment data into groups that were not previously defined. Classification models segment data
by assigning it to previously defined classes, which are specified in a target. Clustering models do
not use a target.
Clustering is useful for exploring data. If there are many cases and no obvious groupings,
clustering algorithms can be used to find natural groupings. Clustering can also serve as a useful
data-preprocessing step to identify homogeneous groups on which to build supervised models.
Clustering can also be used for anomaly detection. Once the data has been segmented into
clusters, you might find that some cases do not fit well into any clusters. These cases are
anomalies or outliers.

Interpreting Clusters
Since known classes are not used in clustering, the interpretation of clusters can present
difficulties. How do you know if the clusters can reliably be used for business decision making?
You can analyze clusters by examining information generated by the clustering algorithm. Oracle
Data Mining generates the following information about eachcluster:
• Position in the cluster hierarchy, described in "Cluster Rules"
• Rule for the position in the hierarchy, described in "Cluster Rules"
• Attribute histograms, described in "Attribute Histograms"
• Cluster centroid, described in "Centroid of a Cluster"
As with other forms of data mining, the process of clustering may be iterative and may require the
creation of several models. The removal of irrelevant attributes or the introduction of new
attributes may improve the quality of the segments produced by a clustering model.
How are Clusters Computed?
There are several different approaches to the computation of clusters. Clustering algorithms may
be characterized as:

• Hierarchical — Groups data objects into a hierarchy of clusters. The hierarchy can be
formed top-down or bottom-up. Hierarchical methods rely on a distance function to
measure the similarity between clusters.
Note:
The clustering algorithms supported by Oracle Data Mining perform hierarchicalclustering.
• Partitioning — Partitions data objects into a given number of clusters. The clusters are
formed in order to optimize an objective criterion such as distance.
888
• Locality-based — Groups neighboring data objects into clusters based onlocal conditions.
• Grid-based — Divides the input space into hyper-rectangular cells, discards the low-density
cells, and then combines adjacent high-density cells to formclusters.

Cluster Rules
Oracle Data Mining performs hierarchical clustering. The leaf clusters are the final clusters
generated by the algorithm. Clusters higher up in the hierarchy are intermediate clusters.
Rules describe the data in each cluster. A rule is a conditional statement that captures the logic
used to split a parent cluster into child clusters. A rule describes the conditions for a case to be
assigned with some probability to a cluster. For example, the following rule applies to cases that
are assigned to cluster 19:

IF OCCUPATION in Cleric. AND OCCUPATION in Crafts AND OCCUPATION in [Link]


OCCUPATION in Prof.
CUST_GENDER in M

COUNTRY_NAME in United States of America


CUST_MARITAL_STATUS in Married

Support and Confidence


Support and confidence are metrics that describe the relationships between clustering rules and
cases.
Support is the percentage of cases for which the rule holds.
Confidence is the probability that a case described by this rule will actually be assigned to the
cluster.

Number of Clusters
The CLUS_NUM_CLUSTERS build setting specifies the maximum number of clusters that can be
generated by a clustering algorithm.
Attribute Histograms
In Oracle Data Miner, a histogram represents the distribution of the values of an attribute in a
cluster. Figure 7-1 shows a histogram for the distribution of occupations in a cluster of customer
data.
In this cluster, about 13% of the customers are craftsmen; about 13% are executives, 2% are
farmers, and so on. None of the customers in this cluster are in the armed forces or work in
housing sales.

Figure 7-1 Histogram in Oracle Data Miner

Description of "Figure 7-1 Histogram in Oracle Data Miner"

Centroid of a Cluster
The centroid represents the most typical case in a cluster. For example, in a data set of customer
ages and incomes, the centroid of each cluster would be a customer of average age and average
889
income in that cluster. If the data set included gender, the centroid would have the gender most
frequently represented in the cluster. Figure 7-1 shows the centroid values for a cluster.
The centroid is a prototype. It does not necessarily describe any given case assigned to the
cluster. The attribute values for the centroid are the mean of thenumerical attributes and the mode
of the categorical attributes.
Scoring New Data Oracle Data Mining supports the scoring operation for clustering. In addition to
generating clusters from the build data, clustering models create a Bayesian probability model
that can be used to score new data.
Sample Clustering Problems
These examples use the clustering model km_sh_clus_sample, created by one of the Oracle Data
Mining sample programs, to show how clustering might be used to find natural groupings in the
build data or to score new data.
Figure 7-2 shows six columns and ten rows from the case table used to build the model. Note that
no column is designated as a target.

Figure 7-2 Build Data for Clustering


Regression
Regression is a data mining function that predicts a number. Profit, sales, mortgage rates, house
values, square footage, temperature, or distance could all be predicted using regression
techniques. For example, a regression model could be used to predict the value of a house based
on location, number of rooms, lot size, and other factors.
A regression task begins with a data set in which the target values are known. For example, a
regression model that predicts house values could be developed basedon observed data for many
houses over a period of time. In addition to the value, the data might track the age of the house,
square footage, number of rooms, taxes, school district, proximity to shopping centers, and so on.
House value would be the target, the other attributes would be the predictors, and the data for
each house would constitute a case.
In the model build (training) process, a regression algorithm estimates the value of the target as a
function of the predictors for each case in the build data. These relationships between predictors
and target are summarized in a model, which can then be applied to a different data set in which
the target values are unknown.

Regression models are tested by computing various statistics that measure the difference
between the predicted values and the expected values. The historical data for a regression project
is typically divided into two data sets: one for building the model, the other for testing the model.
Regression modeling has many applications in trend analysis, business planning, marketing,
financial forecasting, time series prediction, biomedical and drug response modeling, and
environmental modeling.

How Does Regression Work?


You do not need to understand the mathematics used in regression analysis to develop and use
quality regression models for data mining. However, it is helpful to understand a few basic
concepts.
890
Regression analysis seeks to determine the values of parameters for a function that cause the
function to best fit a set of data observations that you provide. The following equation expresses
these relationships in symbols. It shows that regression is the process of estimating the value of
a continuous target (y) as a function (F) of one or more predictors (x1, x2, ..., xn), a set of
parameters (θ1, θ2 ,, θn), and a measure of error (e).
y = F(x,θ) + e
The predictors can be understood as independent variables and the target as a dependent
variable. The error, also called the residual, is the difference between the expected and predicted
value of the dependent variable. The regression parameters are also known as regression
coefficients.
The process of training a regression model involves finding the parameter values that minimize a
measure of the error, for example, the sum of squared errors.
There are different families of regression functions and different ways ofmeasuring the error.

Linear Regression

A linear regression technique can be used if the relationship between the predictors and the target
can be approximated with a straight line.
Regression with a single predictor is the easiest to visualize. Simple linear regression with a single
predictor is shown in Figure 4-1.

Figure 4-1 Linear Regression with a Single Predictor

Description of "Figure 4-1 Linear Regression with a Single Predictor"


Linear regression with a single predictor can be expressed with the followingequation.
y = θ2x + θ1 + e
The regression parameters in simple linear regression are:
• The slope of the line (θ2) — the angle between a data point and theregression line
• The y intercept (θ1) — the point where x crosses the y axis (x = 0)

Multivariate Linear Regression


The term multivariate linear regression refers to linear regression with two or more predictors (x1,
x2, …, xn). When multiple predictors are used, the regression line cannot be visualized in two-
dimensional space. However, the line can be computed simply by expanding the equation for
single-predictor linear regressionto include the parameters for each of the predictors.
y = θ1 + θ2x1 + θ3x2 + ...... θn xn-1 + e

Regression Coefficients
In multivariate linear regression, the regression parameters are often referred to as coefficients.
When you build a multivariate linear regression model, the algorithm computes a coefficient for
each of the predictors used by the model.
The coefficient is a measure of the impact of the predictor x on the target y. Numerous statistics
are available for analyzing the regression coefficients to evaluate how well the regression line fits
the data. ("Regression Statistics".)
891
Nonlinear Regression
Often the relationship between x and y cannot be approximated with a straight line. In this case, a
nonlinear regression technique may be used. Alternatively, the data could be preprocessed to
make the relationship linear.
Nonlinear regression models define y as a function of x using an equation that is more
complicated than the linear regression equation. In Figure 4-2, x and y have a nonlinear
relationship.

Figure 4-2 Nonlinear Regression with a Single Predictor


Description of "Figure 4-2 Nonlinear Regression with a Single Predictor"
Multivariate Nonlinear Regression
The term multivariate nonlinear regression refers to nonlinear regression with two or more
predictors (x1, x2, …, xn). When multiple predictors are used, the nonlinear relationship cannot be
visualized in two-dimensional space.

Confidence Bounds
A regression model predicts a numeric target value for each case in the scoring data. In addition
to the predictions, some regression algorithms can identify confidence bounds, which are the
upper and lower boundaries of an interval inwhich the predicted value is likely to lie.
When a model is built to make predictions with a given confidence, the confidence interval will be
produced along with the predictions. For example, a model might predict the value of a house to
be $500,000 with a 95% confidencethat the value will be between $475,000 and $525,000.

A Sample Regression Problem


Suppose you want to learn more about the purchasing behavior of customers of different ages.
You could build a model to predict the ages of customers as a function of various demographic
characteristics and shopping patterns. Since the model will predict a number (age), we will use a
regression algorithm.
This example uses the regression model, svmr_sh_regr_sample, which is created by one of the
Oracle Data Mining sample programs. Figure 4-3 shows six columns and ten rows from the case
table used to build the model.
The affinity card column can contain either a 1, indicating frequent use of apreferred-buyer card, or
a 0, which indicates no use or infrequent use.

Figure 4-3 Sample Build Data for Regression

Description of "Figure 4-3 Sample Build Data for Regression"


After undergoing testing (see "Testing a Regression Model"), the model can be applied to the data
set that you wish to mine.
Figure 4-4 shows some of the predictions generated when the model is applied to the customer
data set provided with the Oracle Data Mining sample programs.
Several of the predictors are displayed along with the predicted age for eachcustomer.
892
Figure 4-4 Regression Results in Oracle Data Miner

Description of "Figure 4-4 Regression Results in Oracle Data Miner"

Note:
Oracle Data Miner displays the generalized case ID in the DMR$CASE_ID column of the apply
output table. A "1" is appended to the column name of each predictor that you choose to include
in the output. The predictions (the predicted ages in Figure 4-4) are displayed in the PREDICTION
column.

Testing a Regression Model


A regression model is tested by applying it to test data with known target values and comparing
the predicted values with the known values.
The test data must be compatible with the data used to build the model and must be prepared in
the same way that the build data was prepared. Typically the build data and test data come from
the same historical data set. A percentage of the records is used to build the model; the remaining
records are used to test the model.
Test metrics are used to assess how accurately the model predicts these known values. If the
model performs well and meets the business requirements, it can then be applied to new data to
predict the future.

Residual Plot
A residual plot is a scatter plot where the x-axis is the predicted value of x, and the y-axis is the
residual for x. The residual is the difference between the actual value of x and the predicted value
of x.
Figure 4-5 shows a residual plot for the regression results shown in Figure 4-4. Note that most of
the data points are clustered around 0, indicating small residuals. However, the distance between
the data points and 0 increases with the value of x, indicating that the model has greater error for
people of higher ages.

Figure 4-5 Residual Plot in Oracle Data Miner

Description of "Figure 4-5 Residual Plot in Oracle Data Miner"

Regression Statistics
The Root Mean Squared Error and the Mean Absolute Error are commonly used statistics for
evaluating the overall quality of a regression model. Different statistics may also be available
depending on the regression methods used by thealgorithm.

Root Mean Squared Error


The Root Mean Squared Error (RMSE) is the square root of the average squareddistance of a data
point from the fitted line.
This SQL expression calculates the RMSE.
893
SQRT (AVG ((predicted value - actual value) * (predicted value - actual value) This formula shows
the RMSE in mathematical symbols. The large sigma character represents summation; j
represents the current predictor, and n represents the number of predictors.

Description of the illustration RMSE


Mean Absolute Error
The Mean Absolute Error (MAE) is the average of the absolute value of the residuals (error). The
MAE is very similar to the RMSE but is less sensitive to largeerrors.
This SQL expression calculates the MAE. AVG (ABS (predicted value - actual value))

This formula shows the MAE in mathematical symbols. The large sigma character represents
summation; j represents the current predictor, and n represents the number of predictors.
Description of the illustration Mae Test Metrics in Oracle Data Miner Oracle Data Miner calculates
the regression test metrics shown in Figure 4-6.

Figure 4-6 Test Metrics for a Regression Model


Description of "Figure 4-6 Test Metrics for a Regression Model"
Oracle Data Miner calculates the predictive confidence for regression models. Predictive
confidence is a measure of the improvement gained by the model over chance. If the model were
"naive" and performed no analysis, it would simply predict the average. Predictive confidence is
the percentage increase gained by the model over a naive model. Figure 4-7 shows a predictive
confidence of 43%, indicating that the model is 43% better than a naive model.

Figure 4-7 Predictive Confidence for a Regression Model


Description of "Figure 4-7 Predictive Confidence for a Regression Model"

Regression Algorithms
Oracle Data Mining supports two algorithms for regression. Both algorithms are particularly suited
for mining data sets that have very high dimensionality (many attributes), including transactional
and unstructured data.

• Generalized Linear Models (GLM)


GLM is a popular statistical technique for linear modeling. Oracle Data Miningimplements GLM for
regression and for binary classification.
GLM provides extensive coefficient statistics and model statistics, as well as row diagnostics.
GLM also supports confidence bounds.

•Support Vector Machines (SVM)


SVM is a powerful, state-of-the-art algorithm for linear and nonlinear regression. Oracle Data
Mining implements SVM for regression and other miningfunctions.
SVM regression supports two kernels: the Gaussian kernel for nonlinear regression, and the linear
kernel for linear regression. SVM also supports activelearning.

Support Vector Machines

894
Support Vector Machines (SVM) is a powerful, state-of-the-art algorithm with strong theoretical
foundations based on the Vapnik-Chervonenkis theory. SVM has strong regularization properties.
Regularization refers to the generalization ofthe model to new data.

Advantages of SVM
SVM models have similar functional form to neural networks and radial basis functions, both
popular data mining techniques. However, neither of these algorithms has the well-founded
theoretical approach to regularization that forms the basis of SVM. The quality of generalization
and ease of training of SVM is farbeyond the capacities of these more traditional methods.
SVM can model complex, real-world problems such as text and image classification, hand-writing
recognition, and bioinformatics and bio sequenceanalysis.
SVM performs well on data sets that have many attributes, even if there are very few cases on
which to train the model. There is no upper limit on the number of attributes; the only constraints
are those imposed by hardware. Traditional neural nets do not perform well under these
circumstances.

Advantages of SVM in Oracle Data Mining


Oracle Data Mining has its own proprietary implementation of SVM, which exploits the many
benefits of the algorithm while compensating for some of the limitations inherent in the SVM
framework. Oracle Data Mining SVM provides the scalability and usability that are needed in a
production quality data mining system.

Usability
Usability is a major enhancement, because SVM has often been viewed as a tool for experts. The
algorithm typically requires data preparation, tuning, and optimization. Oracle Data Mining
minimizes these requirements. You do not need to be an expert to build a quality SVM model in
Oracle Data Mining. For example:
• Data preparation is not required in most cases.
• Default tuning parameters are generally adequate.

Scalability
When dealing with very large data sets, sampling is often required. However, sampling is not
required with Oracle Data Mining SVM, because the algorithm itself uses stratified sampling to
reduce the size of the training data as needed.
Oracle Data Mining SVM is highly optimized. It builds a model incrementally by optimizing small
working sets toward a global solution. The model is trained until convergence on the current
working set, then the model adapts to the new data. The process continues iteratively until the
convergence conditions are met. The Gaussian kernel uses caching techniques to manage the
working sets.
Oracle Data Mining SVM supports active learning, an optimization method that builds a smaller,
more compact model while reducing the time and memory resources required for training the
model. See "Active Learning".
Kernel-Based Learning
895
SVM is a kernel-based algorithm. A kernel is a function that transforms the input data to a high-
dimensional space where the problem is solved. Kernel functions can be linear or nonlinear.
Oracle Data Mining supports linear and Gaussian (nonlinear) kernels.
In Oracle Data Mining, the linear kernel function reduces to a linear equation on the original
attributes in the training data. A linear kernel works well when there are many attributes in the
training data.
The Gaussian kernel transforms each case in the training data to a point in an n- dimensional
space, where n is the number of cases. The algorithm attempts to separate the points into
subsets with homogeneous target values. The Gaussian kernel uses nonlinear separators, but
within the kernel space it constructs a linearequation.

Active Learning
Active learning is an optimization method for controlling model growth and reducing model build
time. Without active learning, SVM models grow as the size of the build data set increases, which
effectively limits SVM models to small and medium size training sets (less than 100,000 cases).
Active learning provides a

way to overcome this restriction. With active learning, SVM models can be built on very large
training sets.
Active learning forces the SVM algorithm to restrict learning to the most informative training
examples and not to attempt to use the entire body of data. In most cases, the resulting models
have predictive accuracy comparable to thatof a standard (exact) SVM model.
Active learning provides a significant improvement in both linear and Gaussian SVM models,
whether for classification, regression, or anomaly detection.
However, active learning is especially advantageous for the Gaussian kernel, because nonlinear
models can otherwise grow to be very large and can place considerable demands on memory and
other system resources.

Tuning an SVM Model


SVM has built-in mechanisms that automatically choose appropriate settings based on the data.
You may need to override the system-determined settings forsome domains.
The build settings described in Table 18-1 are available for configuring SVM models. Settings
pertain to regression, classification, and anomaly detectionunless otherwise specified.
Table 18-1 Build Settings for Support Vector Machines

Setting Name Configures.... Description

896
Linear or [Link]
algorithm automatically uses
SVMS_KERNEL_FUNCTION Kernel
the kernel functionthat is most
appropriate to the

Setting Name Configures.... Description

data.
SVM uses the linear kernel when there are many attributes (more than 100) in the training data,
otherwise it uses the Gaussian kernel.
The number of attributes does not correspond to the number of columns in the training data.
SVM explodes categorical attributes to binary,numeric attributes. In addition, Oracle Data Mining
interprets each rowin a nested column as a separate attribute.

Standard deviationfor Gaussian Controls the spreadof the


SVMS_STD_DEV
kernel Gaussian

Setting Name Configures.... Description

kernel function.

SVM uses a data- driven


approach to find a
standard deviation value
thatis on the same scale
as distances between
typical cases.

897
Amount of memory
allocated to the Gaussian
kernel cache maintained
Cache size for Gaussian
SVMS_KERNEL_CACHE_SIZE inmemory to improve
kernel
model build time.
The default cachesize is
50 MB.

Whether or not to use


active learning. This
setting is especially
SVMS_ACTIVE_LEARNING Active learning
importantfor nonlinear
(Gaussian) SVM models.
By default, active

Setting Name Configures.... Description

learning is enabled.

898
Regularization setting that
balancesthe complexity of
the model against model
robustness toachieve good
SVMS_COMPLEXITY_FACTOR Complexity factor
generalization on new data.
SVM uses a data-driven
approach to finding the
complexity factor.

The criterion for completing


SVMS_CONVERGENCE_TOLERANCE Convergencetolerance the model training process.
The defaultis 0.001.

Regularization setting for


regression, similar to
Epsilon factor for complexity [Link]
SVMS_EPSILON
regression specifies theallowable
residuals,
or noise, in the data.

Setting Name Configures.... Description

The expected outlierrate in


SVMS_OUTLIER_RATE Outliers for anomaly detection anomaly detection. The
default rate is 0.1.

899
Data Preparation for SVM
The SVM algorithm operates natively on numeric attributes. The algorithm automatically
"explodes" categorical data into a set of binary attributes, one per category value. For example, a
character column for marital status with
values married or single would be transformed to two numeric
attributes: married and single. The new attributes could have the value 1 (true) or0 (false).
When there are missing values in columns with simple data types (not nested), SVM interprets
them as missing at random. The algorithm automatically replaces missing categorical values with
the mode and missing numerical values with the mean.
When there are missing values in nested columns, SVM interprets them as sparse. The algorithm
automatically replaces sparse numerical data with zeros and sparse categorical data with zero
vectors.

Normalization
SVM requires the normalization of numeric input. Normalization places the values of numeric
attributes on the same scale and prevents attributes with a large original scale from biasing the
solution. Normalization also minimizes the likelihood of overflows and underflows. Furthermore,
normalization brings the numerical attributes to the same scale (0,1) as the exploded categorical
data.

SVM and Automatic Data Preparation


The SVM algorithm automatically handles missing value treatment and the transformation of
categorical data, but normalization and outlier detection must be handled by ADP or prepared
manually. ADP performs min-max normalizationfor SVM.

Note:
Oracle Corporation recommends that you use Automatic Data Preparation with SVM. The
transformations performed by ADP are appropriate for most models.

SVM Classification
SVM classification is based on the concept of decision planes that define decision boundaries. A
decision plane is one that separates between a set of objects having different class
memberships. SVM finds the vectors ("support vectors") that define the separators giving the
widest separation of classes.
SVM classification supports both binary and multiclass targets.
Class Weights
In SVM classification, weights are a biasing mechanism for specifying the relative importance of
target values (classes).
SVM models are automatically initialized to achieve the best average predictionacross all classes.
However, if the training data does not represent a realistic distribution, you can bias the model to
compensate for class values that are under-represented. If you increase the weight for a class, the

900
percent of correctpredictions for that class should increase.
The Oracle Data Mining APIs use priors to specify class weights for SVM. To use priors in training
a model, you create a priors table and specify its name as a buildsetting for the model.
Priors are associated with probabilistic models to correct for biased sampling procedures. SVM
uses priors as a weight vector that biases optimization and favors one class over another.

One-Class SVM
Oracle Data Mining uses SVM as the one-class classifier for anomaly detection. When SVM is
used for anomaly detection, it has the classification mining functionbut no target.
One-class SVM models, when applied, produce a prediction and a probability for each case in the
scoring data. If the prediction is 1, the case is considered typical. If the prediction is 0, the case is
considered anomalous. This behavior reflects thefact that the model is trained with normal data.
You can specify the percentage of the data that you expect to be anomalous with the
SVMS_OUTLIER_RATE build setting. If you have some knowledge that the number of
ÒsuspiciousÓ cases is a certain percentage of your population, then you can set the outlier rate to
that percentage. The model will identify approximately that many ÒrareÓ cases when applied to
the general population. The default is 10%, which is probably high for many anomaly detection
problems.

SVM Regression
SVM uses an epsilon-insensitive loss function to solve regression problems.
SVM regression tries to find a continuous function such that the maximum number of data points
lie within the epsilon-wide insensitivity tube. Predictions falling within epsilon distance of the true
target value are not interpreted as errors.
The epsilon factor is a regularization setting for SVM regression. It balances the margin of error
with model robustness to achieve the best generalization to newdata.

K Nearest Neighbors - Classification

K nearest neighbors is a simple algorithm that stores all available cases and classifies new cases
based on a similarity measure (e.g., distance functions). KNN has been used in statistical
estimation and pattern
recognition already in the beginning of 1970’s as a non-parametrictechnique.

Algorithm

901
A case is classified by a majority vote of its neighbors, with the case being assigned to the class
most common amongst its K nearest neighbors measured by a distance function. If K = 1, then
the case issimply assigned to the class of its nearest neighbor.

It should also be noted that all three distance measures are only validfor continuous variables. In
the instance of categorical variables, the Hamming distance must be used. It also brings up the
issue of

standardization of the numerical variables between 0 and 1 when there is a mixture of numerical
and categorical variables in the dataset.

Choosing the optimal value for K is best done by first inspecting the data. In general, a large K
value is more precise as it reduces the overallnoise but there is no guarantee. Cross-validation is
another way to retrospectively determine a good K value by using an independent dataset to
validate the K value. Historically, the optimal K for most datasets has been between 3-10. That
produces much better results than 1NN.

Example:

Consider the following data concerning credit default. Age and Loanare two numerical variables
(predictors) and Default is the target.

We can now use the training set to classify an unknown case (Age=48and Loan=$142,000) using
Euclidean distance. If K=1 then the nearestneighbor is the last case in the training set with
Default=Y.

D = Sqrt[(48-33)^2 + (142000-150000)^2] = 8000.01 >> Default=Y

902
With K=3, there are two Default=Y and one Default=N out of threeclosest neighbors. The
prediction for the unknown case is again Default=Y.

Standardized Distance

One major drawback in calculating distance measures directly from thetraining set is in the case
where variables have different measurement scales or there is a mixture of numerical and
categorical variables. For example, if one variable is based on annual income in dollars, and the
other is based on age in years then income will have a much higher influence on the distance
calculated. One solution is to standardize the
training set as shown below.

Hidden Markov Model (HMM)


A hidden Markov model (HMM) is a kind of statistical model that is a variation on the Markov
chain. In a hidden Markov model, there are "hidden" states, or unobserved, in contrast to a
standard Markov chain where all states are visible to the observer. Hidden Markov models are
used for machine learning and data mining tasks including speech, handwriting and gesture
recognition.

Hidden Markov Model (HMM)


The hidden Markov model was developed by the mathematician L.E. Baum and his colleagues in
the 1960s. Like the popular Markov chain, the hidden Markov model attempts to predict the future
state of a variable using probabilities based on the current and past state. The key difference
between a Markov chain and the hidden Markov model is that the state in the latter is not directly
visible to anobserver, even though the output is.
Hidden Markov models are used for machine learning and data mining tasks. Some of these
include speech recognition, handwriting recognition, part-of- speech tagging and bioinformatics.

Dependency Modeling

Dependency Modeling consists of finding a model which describes significant dependencies


between variables.
Dependency models exist at two levels:
• The structural level of the model specifies (often graphically) which variables are locally
dependent on each other, and
• The quantitative level of the model specifies the strengths of thedependencies using some
903
numerical scale.
Link Analysis
Link analysis is a data analysis technique used in network theory that is used to evaluate the
relationships or connections between network nodes. These relationships can be between various
types of objects (nodes), including people,organizations and even transactions.
Link analysis is essentially a kind of knowledge discovery that can be used to visualize data to
allow for better analysis, especially in the context of links, whether Web links or relationship links
between people or between different entities. Link analysis is often used in search engine
optimization as well as inintelligence, in security analysis and in market and medical research.

Link Analysis
Link analysis is literally about analyzing the links between objects, whether they are physical,
digital or relational. This requires diligent data gathering. For example, in the case of a website
where all of the links and backlinks that are present must be analyzed, a tool has to sift through all
of the HTML codes and various scripts in the page and then follow all the links it finds in order to
determine what sort of links are present and whether they are active or dead. This information can
be very important for search engine optimization, as it allows the analyst to determine whether the
search engine is actually able to findand index the website.
In networking, link analysis may involve determining the integrity of the connection between each
network node by analyzing the data that passes through the physical or virtual links. With the data,
analysts can find bottlenecks and possible fault areas and are able to patch them up more quickly
or even helpwith network optimization.
Link analysis has three primary purposes:

• Find matches for known patterns of interests between linked objects.


• Find anomalies by detecting violated known patterns.

• Find new patterns of interest (for example, in social networking andmarketing and business
intelligence).

Social Network Analysis (SNA)


Social network analysis (SNA) is a process of quantitative and qualitative analysis of a social
network. SNA measures and maps the flow of relationships and relationship changes between
knowledge-possessing entities. Simple and complex entities include websites, computers,
animals, humans, groups, organizations and nations.
The SNA structure is made up of node entities, such as humans, and ties, such as relationships.
The advent of modern thought and computing facilitated a gradual evolution of the social
networking concept in the form of highly complex, graph- based networks with many types of
nodes and ties. These networks are the key toprocedures and initiatives involving problem solving,
administration and operations.

Social Network Analysis (SNA)


SNA usually refers to varied information and knowledge entities, but most actual studies focus on

904
human (node) and relational (tie) analysis. The tie value is social
capital.
SNA is often diagrammed with points (nodes) and lines (ties) to present the intricacies related to
social networking. Professional researchers perform analysis using software and unique theories
and methodologies.
SNA research is conducted in either of the following ways:

• Studying the complete social network, including all ties in a definedpopulation.


• Studying egocentric components, including all ties and personal communities, which
involves studying relationship between the focal points in the network and the social ties
they make in their communities.
A snowball network forms when alters become egos and can create, or nominate,additional alters.
Conducting snowball studies is difficult, due to logistical limitations. The abstract SNA concept is
complicated further by studying hybrid networks, in which complete networks may create unlisted
alters available for ego observation. Hybrid networks are analogous to employees affected by
outside consultants, where data collection is not thoroughly defined.

Three analytical tendencies make SNA distinctive, as follows:


• Groups are not assumed to be societal building blocks.
• Studies focus on how ties affect individuals and other relationships, versus discrete
individuals, organizations or states.
• Studies focus on structure, the composition of ties and how they affect societal norms,
versus assuming that socialized norms determine behavior.

Sequence mining
Sequence mining has already proven to be quite beneficial in many domains such as marketing
analysis or Web click-stream analysis. A sequence s is defined as a set of ordered items denote
by 〈s1, s2, ⋯, sn〉. In activity recognition problems, the sequence is typically ordered using
timestamps. The goal of sequence mining is to discover interesting patterns in data with respect
to some subjective or objective measure of how interesting it is. Typically, this task involves
discoveringfrequent sequential patterns with respect to a frequency support measure.
The task of discovering all the frequent sequences is not a trivial one. In fact, it can be quite
challenging due to the combinatorial and exponential search space. Over the past decade, a
number of sequence mining methods have
been proposed that handle the exponential search by using various heuristics. The first sequence
mining algorithm was called GSP, which was based on the a priori approach for mining frequent
item sets. GSP makes several passes over the database to count the support of each sequence
and to generate candidates.
Then, it prunes the sequences with a support count below the minimum support.
Many other algorithms have been proposed to extend the GSP algorithm. One example is the PSP
algorithm, which uses a prefix-based tree to represent candidate patterns. FREESPAN and
PREFIXSPAN are among the first algorithms to consider a projection method for mining
sequential patterns, by recursively projecting sequence databases into smaller projected

905
databases.
SPADE is another algorithm that needs only three passes over the database to discover
sequential patterns. SPAM was the first algorithm to use a vertical bitmap representation of a
database. Some other algorithms focus on discovering specific types of frequent patterns. For
example, BIDE is an efficient algorithm for mining frequent closed sequences without candidate
maintenance; there are alsomethods for constraint-based sequential pattern mining

Big Data
According to Gartner, the definition of Big Data –
“Big data” is high-volume, velocity, and variety information assets that demand cost-effective,
innovative forms of information processing for enhanced insight and decision making.”
This definition clearly answers the “What is Big Data?” question – Big Data refers to complex and
large data sets that have to be processed and analyzed to uncover valuable information that can
benefit businesses and organizations.
However, there are certain basic tenets of Big Data that will make it even simplerto answer what is
Big Data:
• It refers to a massive amount of data that keeps on growing exponentiallywith time.
• It is so voluminous that it cannot be processed or analyzed using conventional data
processing techniques.
• It includes data mining, data storage, data analysis, data sharing, and datavisualization.
• The term is an all-comprehensive one including data, data frameworks, along with the tools
and techniques used to process and analyze the data.

Types of Big Data


Now that we are on track with what is big data, let’s have a look at the types ofbig data:

Structured
Structured is one of the types of big data and By structured data, we mean data that can be
processed, stored, and retrieved in a fixed format. It refers to highly organized information that
can be readily and seamlessly stored and accessed from a database by simple search engine
algorithms. For instance, the employee table in a company database will be structured as the
employee details, their job positions, their salaries, etc., will be present in an organized manner.

Unstructured
Unstructured data refers to the data that lacks any specific form or structure whatsoever. This
makes it very difficult and time-consuming to process and analyze unstructured data. Email is an
example of unstructured data. Structuredand unstructured are two important types of big data.

Semi-structured
Semi structured is the third type of big data. Semi-structured data pertains to the data containing
both the formats mentioned above, that is, structured and unstructured data. To be precise, it
refers to the data that although has not been classified under a particular repository (database)
yet contains vital information or tags that segregate individual elements within the data. Thus, we
906
come to the end of types of data. Let’s discuss the characteristics of data.

Characteristics of Big Data


Back in 2001, Gartner analyst Doug Laney listed the 3 ‘Vs of Big Data – Variety, Velocity, and
Volume. Let’s discuss the characteristics of big data.
These characteristics, isolated Ly, are enough to know what big data is. Let’s lookat them in depth:

1) Variety
Variety of Big Data refers to structured, unstructured, and semi structured data that is gathered
from multiple sources. While in the past, data could only be collected from spreadsheets and
databases, today data comes in an array of forms such as emails, PDFs, photos, videos, audios,
SM posts, and so much [Link] is one of the important characteristics of big data.

2) Velocity
Velocity essentially refers to the speed at which data is being created in real-time. In a broader
prospect, it comprises the rate of change, linking of incoming data sets at varying speeds, and
activity bursts.

3) Volume
Volume is one of the characteristics of big data. We already know that Big Data indicates huge
‘volumes’ of data that is being generated on a daily basis from various sources like social media
platforms, business processes, machines, networks, human interactions, etc. Such a large amount
of data is stored in datawarehouses. Thus, comes to the end of characteristics of big data.

Advantages of Big Data (Features)

o One of the biggest advantages of Big Data is predictive analysis. Big Data analytics
tools can predict outcomes accurately, thereby, allowing businesses and
organizations to make better decisions, while simultaneously optimizing their
operational efficiencies and reducing risks.
o By harnessing data from social media platforms using Big Data analytics tools,
businesses around the world are streamlining their digital marketing strategies to
enhance the overall consumer experience. Big Data provides insights into the
customer pain points and allows companies to improve upon their products and
services.
o Being accurate, Big Data combines relevant data from multiple sources to produce
highly actionable insights. Almost 43% of companies lack the necessary tools to filter
out irrelevant data, which eventually costs them millions of dollars to hash out useful
data from the bulk. Big Data tools can help reduce this, saving you both time and
money.
o Big Data analytics could help companies generate more sales leads which would
naturally mean a boost in revenue. Businesses are using Big Data analytics tools to
understand how well their products/services are doing in the market and how the
907
customers are responding to them. Thus, the can understand better where to invest
their time and money.

o With Big Data insights, you can always stay a step ahead of your competitors. You can
screen the market to know what kind of promotions and offers your rivals are providing,
and then you can come up with better offers for your customers. Also, Big Data insights
allow you to learn customer behavior to understand the customer trends and provide a
highly‘personalized’ experience to them.

Who is using Big Data? 5 Applications


The people who’re using Big Data know better that, what is Big Data. Let’s look at some such
industries:
1) Healthcare
Big Data has already started to create a huge difference in the healthcare sector. With the help of
predictive analytics, medical professionals and HCPs are now able to provide personalized
healthcare services to individual patients. Apart from that, fitness wearables, telemedicine, remote
monitoring – all powered by Big Data and AI – are helping change lives for the better.

2) Academia
Big Data is also helping enhance education today. Education is no more limited to the physical
bounds of the classroom – there are numerous online educational courses to learn from.
Academic institutions are investing in digital courses powered by Big Data technologies to aid the
all-round development of budding learners.

3) Banking
The banking sector relies on Big Data for fraud detection. Big Data tools can efficiently detect
fraudulent acts in real-time such as misuse of credit/debit cards, archival of inspection tracks,
faulty alteration in customer stats, etc.

4) Manufacturing
According to TCS Global Trend Study, the most significant benefit of Big Data in manufacturing is
improving the supply strategies and product quality. In the manufacturing sector, Big data helps
create a transparent infrastructure, thereby, predicting uncertainties and incompetencies that can
affect the business adversely.

5) IT
One of the largest users of Big Data, IT companies around the world are using BigData to optimize
their functioning, enhance employee productivity, and minimize risks in business operations. By
combining Big Data technologies with ML and AI, the IT sector is continually powering innovation
to find solutions even for the most complex of problems.

6. Retail
908
Big Data has changed the way of working in traditional brick and mortar retail stores. Over the
years, retailers have collected vast amounts of data from local demographic surveys, POS
scanners, RFID, customer loyalty cards, store inventory, and so on. Now, they’ve started to
leverage this data to create personalized customer experiences, boost sales, increase revenue,
and deliveroutstanding customer service.
Retailers are even using smart sensors and Wi-Fi to track the movement of customers, the most
frequented aisles, for how long customers linger in the aisles, among other things. They also
gather social media data to understand what customers are saying about their brand, their
services, and tweak their product design and marketing strategies accordingly.

7. Transportation
Big Data Analytics holds immense value for the transportation industry. In countries across the
world, both private and government-run transportation companies use Big Data technologies to
optimize route planning, control traffic, manage road congestion and improve services.
Additionally, transportation services even use Big Data to revenue management, drive
technological innovation, enhance logistics, and of course, to gain the upper hand in the market.

Big Data Case studies

1. Walmart
Walmart leverages Big Data and Data Mining to create personalized product recommendations
for its customers. With the help of these two emerging technologies, Walmart can uncover
valuable patterns showing the most frequently bought products, most popular products, and even
the most popular product bundles (products that complement each other and are usually
purchased together).
Based on these insights, Walmart creates attractive and customized recommendations for
individual users. By effectively implementing Data Mining techniques, the retail giant has
successfully increased the conversion rates and improved its customer service substantially.
Furthermore, Walmart
uses Hadoop and NoSQL technologies to allow customers to access real-time data accumulated
from disparate sources.

2. American Express
The credit card giant leverages enormous volumes of customer data to identify indicators that
could depict user loyalty. It also uses Big Data to build advanced predictive models for analyzing
historical transactions along with 115 different variables to predict potential customer churn.
Thanks to Big Data solutions and tools, American Express can identify 24% of the accounts that
are highly likely toclose in the upcoming four to five months.

3. General Electric
In the words of Jeff Immelt, Chairman of General Electric, in the past few years, GE has been
successful in bringing together the best of both worlds – “the physical and analytical worlds.” GE

909
thoroughly utilizes Big Data. Every machine operating under General Electric generates data on
how they work. The GE analytics team then crunches these colossal amounts of data to extract
relevantinsights from it and redesign the machines and their operations accordingly.
Today, the company has realized that even minor improvements, no matter how small, play a
crucial role in their company infrastructure. According to GE stats, Big Data has the potential to
boost productivity by 1.5% in the US, which compiled over a span of 20 years could increase the
average national income by a staggering 30%!

4. Uber
Uber is one of the major cab service providers in the world. It leverages customerdata to track and
identify the most popular and most used services by the users.
Once this data is collected, Uber uses data analytics to analyze the usage patterns of customers
and determine which services should be given more emphasis and importance.
Apart from this, Uber uses Big Data in another unique way. Uber closely studies the demand and
supply of its services and changes the cab fares accordingly. It is the surge pricing mechanism
that works something like this – suppose when you are in a hurry, and you have to book a cab
from a crowded location, Uber will charge you double the normal amount!

5. Netflix
Netflix is one of the most popular on-demand online video content streaming platform used by
people around the world. Netflix is a major proponent of the recommendation engine. It collects
customer data to understand the specific needs, preferences, and taste patterns of users. Then it
uses this data to predict what individual users will like and create personalized content
recommendationlists for them.
Today, Netflix has become so vast that it is even creating unique content for users. Data is the
secret ingredient that fuels both its recommendation engines and new content decisions. The
most pivotal data points used by Netflix include titles that users watch, user ratings, genres
preferred, and how often users stop the playback, to name a few. Hadoop, Hive, and Pig are the
three core components of the data structure used by Netflix.

6. Procter & Gamble


Procter & Gamble has been around us for ages now. However, despite being an “old” company,
P&G is nowhere close to old in its ways. Recognizing the potential of Big Data, P&G started
implementing Big Data tools and technologies in each of its business units all over the world. The
company’s primary focus behind using Big Data was to utilize real-time insights to drive smarter
decision making.
To accomplish this goal, P&G started collecting vast amounts of structured and unstructured data
across R&D, supply chain, customer-facing operations, and customer interactions, both from
company repositories and online sources. The global brand has even developed Big Data systems
and processes to allow managers to access the latest industry data and analytics.

7. IRS
910
Yes, even government agencies are not shying away from using Big Data. The
US Internal Revenue Service actively uses Big Data to prevent identity theft, fraud, and untimely
payments (people who should pay taxes but don’t pay them in due time).
The IRS even harnesses the power of Big Data to ensure and enforce compliance with tax rules
and laws. As of now, the IRS has successfully averted fraud and scams involving billions of
dollars, especially in the case of identity theft. In the past three years, it has also recovered over
US$ 2 billion.

Introduction to MapReduce
MapReduce is a programming model for processing large data sets with a parallel, distributed
algorithm on a cluster (source: Wikipedia). Map Reduce when coupled with HDFS can be used to
handle big data. The fundamentals of this HDFS-MapReduce system, which is commonly referred
to as Hadoop.
The basic unit of information, used in MapReduce is a (Key,value) pair. All types of structured and
unstructured data need to be translated to this basic unit, before feeding the data to MapReduce
model. As the name suggests, MapReduce model consist of two separate routines, namely Map-
function and Reduce-function. This article will help you understand the step by step functionality
of Map-Reduce model. The computation on an input (i.e. on a set of pairs) in MapReduce model
occurs in three stages:

Step 1: The map stage Step 2 : The shuffle stage Step 3 : The reduce stage. Semantically, the
map and shuffle phases distribute the data, and the reduce phase performs the computation. In
this article we will discuss about each ofthese stages in detail.

[stextbox id=” section”] The Map stage [/stextbox]


MapReduce logic, unlike other data frameworks, is not restricted to just structured datasets. It
has an extensive capability to handle unstructured data as well. Map stage is the critical step
which makes this possible. Mapper brings a structure to unstructured data. For instance, if I want
to count the number of photographs on my laptop by the location (city), where the photo was
taken, I need to analyze unstructured data. The mapper makes (key, value) pairs from thisdata set.
In this case, key will be the location and value will be the photograph.
After mapper is done with its task, we have a structure to the entire dataset.
In the map stage, the mapper takes a single (key, value) pair as input and produces any number of
(key, value) pairs as output. It is important to think of the map operation as stateless, that is, its
logic operates on a single pair at a time (even if in practice several input pairs are delivered to the
same mapper). To summarize, for the map phase, the user simply designs a map function that
maps an input (key, value) pair to any number (even none) of output pairs. Most of the time, the
map phase is simply used to specify the desired location of the input value by changing its key.

[stextbox id=” section”] The shuffle stage [/stextbox]


The shuffle stage is automatically handled by the MapReduce framework, i.e., the engineer has
nothing to do for this stage. The underlying system implementing MapReduce routes all of the
values that are associated with an individual key to the same reducer.

911
[stextbox id=” section”] The Reduce stage [/stextbox]
In the reduce stage, the reducer takes all of the values associated with a single key k and outputs
any number of (key, value) pairs. This highlights one of the sequential aspects of MapReduce
computation: all of the maps need to finish before the reduce stage can begin. Since the reducer
has access to all the values with the same key, it can perform sequential computations on these
values. In the reduce step, the parallelism is exploited by observing that reducers operating on
different keys can be executed simultaneously. To summarize, for the reduce phase, the user
designs a function that takes in input a list of values associated with a single key and outputs any
number of pairs. Often the output keys of a reducer equal the input key (in fact, in the original
MapReduce paper the outputkey must equal to the input key, but Hadoop relaxed this constraint).
Overall, a program in the MapReduce paradigm can consist of many rounds(usually called jobs) of
different map and reduce functions, performed sequentially one after another.

[stextbox id=” section”] An example [/stextbox]


Let’s consider an example to understand Map-Reduce in depth. We have thefollowing 3 sentences:
1. The quick brown fox
2. The fox ate the mouse
3. How now brown cow

Our objective is to count the frequency of each word in all the sentences. Imagine that each of
these sentences acquire huge memory and hence are allotted to different data nodes. Mapper
takes over this unstructured data and creates key value pairs. In this case key is the word and
value are the count of this word in the text available at this data node. For instance, the 1st Map
node generates 4 key- value pairs: (the,1), (brown,1), (fox,1), (quick,1). The first 3 key-value pairs
go to the first Reducer and the last key-value go to the second Reducer.

Similarly, the 2nd and 3rd map functions do the mapping for the other two sentences. Through
shuffling, all the similar words come to the same end. Once, the key value pairs are sorted, the
reducer function operates on this structured data to come up with a summary.
[stextbox id=” section”] End Notes: [/stextbox]

Let’s take some examples of Map-Reduce function usage in the industry:


• At Google:
– Index building for Google Search
– Article clustering for Google News
– Statistical machine translation
• At Yahoo!:
– Index building for Yahoo! Search
– Spam detection for Yahoo! Mail
• At Facebook:
– Data mining
– Ad optimization
– Spam detection Example
• At Amazon:
912
– Product clustering
– Statistical machine translation

The constraint of using Map-reduce function is that user has to follow a logic format. This logic is
to generate key-value pairs using Map function and then summarize using Reduce function. But
luckily most of the data manipulation operations can be tricked into this format. In the next article
we will take some examples like how to do data-set merging, matrix multiplication, matrix
transpose,etc. using Map-Reduce.

Introduction to Hadoop
Hadoop is a complete eco-system of open-source projects that provide us the framework to deal
with big data. Let’s start by brainstorming the possible challenges of dealing with big data (on
traditional systems) and then look at thecapability of Hadoop solution.
Following are the challenges I can think of in dealing with big data :
1. High capital investment in procuring a server with high processing capacity.
2. Enormous time taken
3. In case of long query, imagine an error happens on the last step. You will waste so much
time making these iterations.
4. Difficulty in program query building
5. Here is how Hadoop solves all of these issues:

1. High capital investment in procuring a server with high processing capacity: Hadoop clusters
work on normal commodity hardware and keep
multiple copies to ensure reliability of data. A maximum of 4500 machines can be connected
together using Hadoop.
2. Enormous time taken: The process is broken down into pieces and executed in parallel, hence
saving time. A maximum of 25 Petabyte (1 PB = 1000 TB) data can be processed using Hadoop.
3. In case of long query, imagine an error happens on the last step. You will waste so much time
making these iterations: Hadoop builds back up datasets at every level. It also executes query on
duplicate datasets to avoid process loss in case of individual failure. These steps make Hadoop
processing more precise andaccurate.
4. Difficulty in program query building: Queries in Hadoop are as simple as coding in any
language. You just need to change the way of thinking around building a query to enable parallel
processing.

Background of Hadoop
With an increase in the penetration of internet and the usage of the internet, the data captured by
Google increased exponentially year on year. Just to give you an estimate of this number, in 2007
Google collected on an average 270 PB of data every month. The same number increased to
20000 PB every day in 2009.
Obviously, Google needed a better platform to process such an enormous data. Google
implemented a programming model called MapReduce, which could process this 20000 PB per
day. Google ran these MapReduce operations on a special file system called Google File System

913
(GFS). Sadly, GFS is not an open source.
Doug cutting and Yahoo! reverse engineered the model GFS and built a parallel Hadoop
Distributed File System (HDFS). The software or framework that supports HDFS and MapReduce
is known as Hadoop. Hadoop is an open source anddistributed by Apache.

Framework of Hadoop Processing


Let’s draw an analogy from our daily life to understand the working of Hadoop. The bottom of the
pyramid of any firm are the people who are individual contributors. They can be analyst,
programmers, manual labors, chefs, etc.
Managing their work is the project manager. The project manager is responsible for a successful
completion of the task. He needs to distribute labor,
smoothen the coordination among them etc. Also, most of these firms have a people manager,
who is more concerned about retaining the head count.

Hadoop works in a similar format. On the bottom we have machines arranged in parallel. These
machines are analogous to individual contributor in our analogy. Every machine has a data node
and a task tracker. Data node is also known as HDFS (Hadoop Distributed File System) and Task
tracker is also known as map- reducers.
Data node contains the entire set of data and Task tracker does all the operations. You can
imagine task tracker as your arms and leg, which enables you to do a task and data node as your
brain, which contains all the information which you want to process. These machines are working
in silos, and it is very essential to coordinate them. The Task trackers (Project manager in our
analogy) in different machines are coordinated by a Job Tracker. Job Tracker makes sure that
each operation is completed and if there is a process failure at any node, it needs to assign a
duplicate task to some task tracker. Job tracker also distributes the entire task to all the
machines.

A name node on the other hand coordinates all the data nodes. It governs the distribution of data
going to each machine. It also checks for any kind of purging which have happened on any
machine. If such purging happens, it finds the duplicate data which was sent to other data node
and duplicates it again. You can think of this name node as the people manager in our analogy
which is concernedmore about the retention of the entire dataset.

When not to use Hadoop?


Till now, we have seen how Hadoop has made handling big data possible. But in some scenarios
Hadoop implementation is not recommended. Following are some of those scenarios:
o Low Latency data access: Quick access to small parts of data
o Multiple data modification: Hadoop is a better fit only if we are primarily concerned about
reading data and not writing data.
o Lots of small files: Hadoop is a better fit in scenarios, where we have fewbut large files.

Distributed File System (DFS)


A distributed file system (DFS) is a file system with data stored on a server. The data is accessed
914
and processed as if it was stored on the local client machine. The DFS makes it convenient to
share information and files among users on a network in a controlled and authorized way. The
server allows the client users to share files and store data just like they are storing the information
locally. However, theservers have full control over the data and give access control to the clients.

Distributed File System (DFS)


There has been exceptional growth in network-based computing recently and client/server-based
applications have brought revolutions in this area. Sharing storage resources and information on
the network is one of the key elements in both local area networks (LANs) and wide area
networks (WANs). Different technologies have been developed to bring convenience to sharing
resources andfiles on a network; a distributed file system is one of the processes used regularly.

One process involved in implementing the DFS is giving access control and storage management
controls to the client system in a centralized way, managed by the servers. Transparency is one of
the core processes in DFS, so files are accessed, stored, and managed on the local client
machines while the process itself is actually held on the servers. This transparency brings
convenience to the end user on a client machine because the network file system efficiently
manages all the processes. Generally, a DFS is used in a LAN, but it can be used in a WAN or over
the Internet.

A DFS allows efficient and well-managed data and storage sharing options on a network
compared to other options. Another option for users in network-based computing is a shared disk
file system. A shared disk file system puts the access control on the client’s systems, so the data
is inaccessible when the client system goes offline. DFS is fault-tolerant, and the data is
accessible even if some of the network nodes are offline.
A DFS makes it possible to restrict access to the file system depending on access lists or
capabilities on both the servers and the clients, depending on how the protocol is designed.

HDFS
Hadoop File System was developed using distributed file system design. It is run on commodity
hardware. Unlike other distributed systems, HDFS is highly faulttolerant and designed using low-
cost hardware.
HDFS holds very large amount of data and provides easier access. To store such huge data, the
files are stored across multiple machines. These files are stored in redundant fashion to rescue
the system from possible data losses in case of failure. HDFS also makes applications available
to parallel processing.

Features of HDFS
o It is suitable for the distributed storage and processing.
o Hadoop provides a command interface to interact with HDFS.
o The built-in servers of namenode and datanode help users to easily check the status
of cluster.
o Streaming access to file system data.
915
o HDFS provides file permissions and authentication.

HDFS Architecture
Given below is the architecture of a Hadoop File System.

HDFS follows the master-slave architecture, and it has the following elements.

Name node
The name node is the commodity hardware that contains the GNU/Linux operating system and
the name node software. It is a software that can be run on commodity hardware. The system
having the name node acts as the master serverand it does the following tasks −
o Manages the file system namespace.
o Regulates client’s access to files.
o It also executes file system operations such as renaming, closing, and opening files
and directories.
Data node

The datanode is a commodity hardware having the GNU/Linux operating system and datanode
software. For every node (Commodity hardware/System) in a

cluster, there will be a datanode. These nodes manage the data storage of theirsystem.
• Datanodes perform read-write operations on the file systems, as per client
request.
• They also perform operations such as block creation, deletion, and replication
according to the instructions of the name node.
Block

Generally, the user data is stored in the files of HDFS. The file in a file system will be divided into
one or more segments and/or stored in individual data nodes.
These file segments are called as blocks. In other words, the minimum amount of data that HDFS
can read or write is called a Block. The default block size is 64MB, but it can be increased as per
the need to change in HDFS configuration.

Goals of HDFS
Fault detection and recovery − Since HDFS includes a large number of commodity hardware,
failure of components is frequent. Therefore, HDFS should have mechanisms for quick and
automatic fault detection and recovery.

Huge datasets − HDFS should have hundreds of nodes per cluster to manage the applications
having huge datasets.

Hardware at data − A requested task can be done efficiently, when the computation takes place
near the data. Especially where huge datasets are involved, it reduces the network traffic and
916
increases the throughput.

NoSQL
NoSQL databases (aka "not only SQL") are non-tabular, and store data differently than relational
tables. NoSQL databases come in a variety of types based on theirdata model. The main types are
document, key-value, wide-column, and graph.

They provide flexible schemas and scale easily with large amounts of data andhigh user loads.

What is NoSQL?
When people use the term “NoSQL database”, they typically use it to refer to any non-relational
database. Some say the term “NoSQL” stands for “non-SQL” while others say it stands for “not
only SQL.” Either way, most agree that NoSQL databases are databases that store data in a format
other than relational tables.
A common misconception is that NoSQL databases or non-relational databases don’t store
relationship data well. NoSQL databases can store relationship data— they just store it differently
than relational databases do. In fact, when compared with SQL databases, many find modeling
relationship data in NoSQL databases to be easier than in SQL databases, because related data
doesn’t have to be split between tables.
NoSQL data models allow related data to be nested within a single data structure.

NoSQL databases emerged in the late 2000s as the cost of storage dramatically decreased. Gone
were the days of needing to create a complex, difficult-to- manage data model simply for the
purposes of reducing data duplication.
Developers (rather than storage) were becoming the primary cost of software development, so
NoSQL databases optimized for developer productivity.

The benefits of NoSQL databaseData Models

NoSQL databases often leverage data models more tailored to specific use cases, making them
better at supporting those workloads than relational databases. For example, key-value databases
support simple queries very efficiently while graph databases are the best for queries that involve
identifying complex relationships between separate pieces of data.

Performance
NoSQL databases can often perform better than SQL/relational databases for your use case. For
example, if you’re using a document database and are storing all the information about an object
in the same document (so that it matches the objectsin your code), the database only needs to go
to one place for those queries. In a SQL database, the same query would likely involve joining
multiple tables and records, which can dramatically impact performance while also slowing down
how quickly developers write code.

Scalability

917
SQL/relational databases were originally designed to scale up and although there are ways to get
them to scale out, those solutions are often bolt-ons, complicated, expensive to manage, and hard
to evolve. Some core SQL functionality also only really works well when everything is on one
server. In contrast, NoSQL databases are designed from the ground up to scale-out horizontally,
making it much easier to maintain performance as your workload grows beyond the limits of a
single server.

Data Distribution
Because NoSQL databases are designed from the ground up as distributed systems, they can
more easily support a variety of business requirements. For example, suppose the business needs
a globally distributed application that provides excellent performance to users all around the
world. NoSQL databases can allow you to deploy a single distributed cluster to support that
application and ensure low latency access to data from anywhere. This approach also makes it
much easier to comply with data sovereignty mandates required by modern privacy regulations.

Reliability
NoSQL databases ensure high availability and uptime with native replication andbuilt-in failover for
self-healing, resilient database clusters. Similar failover systems can be set up for SQL databases
but since the functionality is not native to the underlying database, this often means more
resources to deploy and maintain a separate clustering layer that then takes longer to identify and
recoverfrom underlying systems failures.

Flexibility
NoSQL databases are better at allowing users to test new ideas and update data structures. For
example, MongoDB, the leading document database, stores data in flexible, JSON-like documents,
meaning fields can vary from document to document and the data structures can be easily
changed over time, as application requirements evolve. This is a better fit for modern
microservices architectures where developers are continuously integrating and deploying new
application functionality.

Queries Optimization
Queries can be executed in many different ways. All paths lead to the same queryresult. The Query
optimizer evaluates the possibilities and selects the efficient plan. Efficiency is measured in
latency and throughput, depending on the workload. The cost of Memory, CPU, disk usage is
added to the cost of a plan in acost-based optimizer.
Now, most NoSQL databases have SQL-like query language support. So, a good optimizer is
mandatory. When you don't have a good optimizer, developers haveto live with feature restrictions
and DBAs have to live with performance issues.

Database Optimizer
A query optimizer chooses an optimal index and access paths to execute the query. At a very high
level, SQL optimizers decide the following before creatingthe execution tree:

918
1. Query rewrite based on heuristics, cost or both.
2. Index selection.
• Selecting the optimal index(es) for each of the table (key spaces inCouchbase
N1QL, collection in case of MongoDB)
• Depending on the index selected, choose the predicates to push down, see
the query is covered or not, decide on sort and paginationstrategy.
3. Join reordering
4. Join type

Queries Optimization
Query optimization is the science and the art of applying equivalence rules to rewrite the tree of
operators evoked in a query and produce an optimal plan. Aplan is optimal if it returns the answer
in the least time or using the least space. There are well known syntactic, logical, and semantic
equivalence rules used during optimization. These rules can be used to select an optimal plan
among semantically equivalent plans by associating a cost with each plan and
selecting the lowest overall cost. The cost associated with each plan is generated using accurate
metrics such as the cardinality or the number of result tuples in the output of each operator, the
cost of accessing a source and obtaining results fromthat source, and so on. One must also have
a cost formula that can calculate the processing cost for each implementation of each operator.
The overall cost is typically defined as the total time needed to evaluate the query and obtain all of
the answers.

The characterization of an optimal, low-cost plan is a difficult task. The complexityof producing an
optimal, low-cost plan for a relational query is NP-complete.
However, many efforts have produced reasonable heuristics to solve this problem. Both dynamic
programming and randomized optimization based onsimulated annealing provide good solutions.
A BIS could be improved significantly by exploiting the traditional database technology for
optimization extended to capture the complex metrics presented in Section 4.4.1. Many of the
systems presented in this book address optimization at different levels. K2 uses rewriting rules
and a cost model. P/FDM combines traditional optimization strategies, such as query rewriting
and selection of the best execution plan, with a query-shipping approach. DiscoveryLink performs
two types of optimizations: query rewriting followed by a cost-based optimization plan. KIND is
addressing the use of domain knowledge into executable meta-data. The knowledge of biological
resources can be used to identify the best plan with query

(Q) defined in Section 4.4.2 as illustrated in the following.


The two possible plans illustrated in Figures 4.1 and 4.2 do not have the same cost. Evaluation
costs depend on factors including the number of accesses to each data source, the size
(cardinality) of each relation or data source involved in the query, the number of results returned
or the selectivity of the query, the number of queries that are submitted to the sources, and the
order of accessing sources.
Each access to a data source retrieves many documents that need to be parsed. Each object

919
returned may generate further accesses to (other) sources. Web accesses are costly and should
be as limited as possible. A plan that limits the number of accesses is likely to have a lower cost.
Early selection is likely to limit the number of accesses. For example, the call to PubMed in the
plan illustrated in Figure 4.1 retrieves 81,840 citations, whereas the call to GenBank in the plan in
Figure 4.2 retrieves 1616 sequences. (Note that the statistics and results cited in this paper were
gathered between April 2001 and April 2002 and may no longer be up to date.) If each of the
retrieved documents (from PubMed or GenBank) generated an additional access to the second
source, clearly the second plan has the potential to be much less expensive when compared to
the first plan.
The size of the data sources involved in the query may also affect the cost of the evaluation plan.
As of May 4, 2001, Swiss-Port contained 95,674 entries whereas PubMed contained more than 11
million citations; these are the values of cardinality for the corresponding relations. A query
submitted to PubMed (as used in the first plan) retrieves 727,545 references that mention brain,
whereas itretrieves 206,317 references that mention brain and were published since 1995.

This is the selectivity of the query. In contrast, the query submitted to Swiss-Prot in the second
plan returns 126 proteins annotated with calcium channel.
In addition to the previously mentioned characteristics of the resources, the order of accessing
sources and the use of different capabilities of sources also affects the total cost of the plan. The
first plan accesses PubMed and extracts values for identifiers of records in Swiss-Prot from the
results. It then passes these values to the query on Swiss-Prot via the join operator. To pass each
value, the plan may have to send multiple calls to the Swiss-Prot source, one for each value, and
this can be expensive. However, by passing these values of identifiers to Swiss-Prot, the Swiss-
Prot source has the potential to constrain the query, and this could reduce the number of results
returned from Swiss-Prot. On the other hand, the second plan submits queries in parallel to both
PubMed and Swiss-Prot. It does not pass values of identifiers of Swiss-Prot records to Swiss-Prot;
consequently, more results may be returned from Swiss-Prot. The results from both PubMed and
Swiss-Prot have to be processed (joined) locally, and this could be computationally expensive.
Recall that for this plan, 206,317 PubMed references and 126 proteins from Swiss-Prot are
processed locally. However, the advantage is that a single query has been submitted to Swiss-
Prot in the second plan. Also, both sources are accessed in parallel.

Although it has not been described previously, there is a third plan that should be considered for
this query. This plan would first retrieve those proteins annotated with calcium channel from
Swiss-Prot and extract MEDLINE identifiers from these records. It would then pass these
identifiers to PubMed and restrict the results to those matching the keyword brain. In this
particular case, this third plan has the potential to be the least costly. It submits one sub-query to
Swiss-Prot, and it will not download 206,317 PubMed references. Finally, it will not join 206,317
PubMed references and 126 proteins from Swiss-Prot locally.
Optimization has an immediate impact in the overall performance of the system. The
consequences of the inefficiency of a system to execute users’ queries may affect the
satisfaction of users as well as the capabilities of the system to returnany output to the user.
920
NoSQL Database

Databases can be divided in 3 types:


1. RDBMS (Relational Database Management System)
2. OLAP (Online Analytical Processing)
3. NoSQL (recently developed database)

NoSQL Database

NoSQL Database is used to refer a non-SQL or non relational database.


It provides a mechanism for storage and retrieval of data other than tabular relations model used
in relational databases. NoSQL database doesn't use tables for storing data. It is generally used to
store big data and real-time web applications.

History behind the creation of NoSQL Databases


In the early 1970, Flat File Systems are used. Data were stored in flat files and the biggest
problems with flat files are each company implement their own flat files and there are no
standards. It is very difficult to store data in the files, retrieve data from files because there is no
standard way to store data.
Then the relational database was created by E.F. Codd and these databases answered the
question of having no standard way to store data. But later relational database also gets a
problem that it could not handle big data, due to this problem there was a need of database which
can handle every types of problems then NoSQL database was developed.

Advantages of NoSQL
o It supports query language.
o It provides fast performance.
o It provides horizontal scalability.

Indexing data sets


Indexing is a way to optimize the performance of a database by minimizing the number of disk
accesses required when a query is processed. It is a data structure technique which is used to
quickly locate and access the data in a database.
Indexes are created using a few database columns.
• The first column is the Search key that contains a copy of the primary key or
candidate key of the table. These values are stored in sorted order so that the corresponding data
can be accessed quickly.
Note: The data may or may not be stored in sorted order.

• The second column is the Data Reference or Pointer which contains a set of
pointers holding the address of the disk block where that particular key value can be found.

921
The indexing has various attributes:

• Access Types: This refers to the type of access such as value based search, range access,
etc.
• Access Time: It refers to the time needed to find particular data element orset of elements.
• Insertion Time: It refers to the time taken to find the appropriate space and insert a new
data.
• Deletion Time: Time taken to find an item and delete it as well as update the index
structure.
• Space Overhead: It refers to the additional space required by the index.
• In general, there are two types of file organization mechanism which are followed by the
indexing methods to store the data:
1. Sequential File Organization or Ordered Index File: In this, the indices are based on a sorted
ordering of the values. These are generally fast and a more traditional type of storing mechanism.
These Ordered or Sequential file organization might store the data in a dense or sparse format:
o Dense Index:
o For every search key value in the data file, there is an indexrecord.
o This record contains the search key and also a reference to the first data record
with that search key value.
o Sparse Index:
o The index record appears only for a few items in the data file. Each item points to
a block as shown.
o To locate a record, we find the index record with the largest search key value less
than or equal to the search key value weare looking for.
o We start at that record pointed to by the index record and proceed along with the
pointers in the file (that is, sequentially) until we find the desired record.
2. Hash File organization: Indices are based on the values being distributed uniformly across a
range of buckets. The buckets to which a value is assigned is determined by a function called a
hash function.

There are primarily three methods of indexing:


922
• Clustered Indexing
• Non-Clustered or Secondary Indexing
• Multilevel Indexing

1. Clustered Indexing
When more than two records are stored in the same file these types of storing known as cluster
indexing. By using the cluster indexing we can reduce the cost of searching reason being multiple
records related to the same thing are stored at one place and it also gives the frequent joing of
more than two tables(records).
Clustering index is defined on an ordered data file. The data file is ordered on a non-key field. In
some cases, the index is created on non-primary key columns which may not be unique for each
record. In such cases, in order to identify the records faster, we will group two or more columns
together to get the unique values and create index out of them. This method is known as the
clustering index. Basically, records with similar characteristics are grouped together and indexes
are created for these groups.
For example, students studying in each semester are grouped together. i.e., 1st Semester students,
2nd semester students, 3rd semester students etc. aregrouped. Clustered index sorted according to
first name (Search key)

Primary Indexing:
This is a type of Clustered Indexing wherein the data is sorted according to the search key and the
primary key of the database table is used to create the index. It is a default format of indexing
where it induces sequential file organization. Asprimary keys are unique and are stored in a sorted
manner, the performance of the searching operation is quite efficient.

2. Non-clustered or Secondary Indexing


A non-clustered index just tells us where the data lies, i.e., it gives us a list of virtual pointers or
references to the location where the data is actually stored. Data is not physically stored in the
order of the index. Instead, data is present in leaf nodes. For e.g., the contents page of a book.
Each entry gives us the page number or location of the information stored. The actual data here
(information on each page of the book) is not organized but we have an ordered reference
(contents page) to where the data points actually lie. We can have only dense ordering in the non-
clustered index as sparse ordering is not possible because data is not physically organized
accordingly.
It requires more time as compared to the clustered index because some amount of extra work is
done in order to extract the data by further following the pointer. In the case of a clustered index,
data is directly present in front of the index.

3. Multilevel Indexing
With the growth of the size of the database, indices also grow. As the index is stored in the main
memory, a single-level index might become too large a size to store with multiple disk accesses.
The multilevel indexing segregates the main block into various smaller blocks so that the same
can stored in a single block. The outer blocks are divided into inner blocks which in turn arepointed
923
to the data blocks. This can be easily stored in the main memory with fewer overheads.

NOSQL in Cloud
With the current move to cloud computing, the need to scale applications presents itself as a
challenge for storing data. If you are using a traditional relational database, you may find yourself
working on a complex policy for distributing your database load across multiple database
instances. This solution will often present a lot of problems and probably won’t be great at
elastically scaling.
As an alternative you could consider a cloud-based NoSQL database. Over the past few weeks, I
have been analysing a few such offerings, each of which promises to scale as your application
grows, without requiring you to think abouthow you might distribute the data and load.
Specifically, I have been looking at Amazon’s DynamoDB, Google’s Cloud Datastore and Cloud
Bigtable. I chose to take a look into these 3 databases because we have existing applications
running in Google and Amazon’s clouds and I can see the advantage these databases can offer. In
this post I’ll report on what I’ve learnt.

Consistency, Availability & Partition Tolerance


Firstly — and most importantly — it’s necessary to understand that distributed NoSQL databases
achieve high scalability in comparison to a traditional RDBMS by making some important
tradeoffs.
A good starting-place for thinking about this is the CAP Theorem, which states that a distributed
database can — at most — provide two of the following: Consistency, Availability and Partition
Tolerance. We define each of these as follows:
• Consistency: All nodes contain the same data
• Availability: Every request should receive a response
• Partition Tolerance: Losing a node should not affect the system

Eventually Consistent Operations


All three NoSQL databases I looked at provide Availability and Partition Tolerance for eventually
consistent operations. In most cases these two properties will suffice.
For example, if a user posts to a social media website and it takes a second or two for everyone’s
request to pick up the change, then it’s not usually an issue.
This happens due to write operations writing to multiple nodes before the data is eventually
replicated across all of the nodes, which usually occurs within one second. Read operations are
then read from only one node.

Strongly Consistent Operations

All three databases also provide strongly consistent operations which guarantee that the latest
version of the data will always be returned.
DynamoDB achieves this by ensuring that writes are written out to the majority of nodes before a
success result is returned. Reads are also done in a similar way — results will not return until the

924
record is read from more than half of the nodes.
This is to ensure that the result will be the latest copy of the record.
All this occurs at the expense of availability, where a node being inaccessible can prevent the
verification of the data’s consistency if it occurs a short time after the write operation. Google
achieves this behaviour in a slightly different way by using a locking mechanism where a read
can’t be completed on a node until it has the latest copy of the data. This model is required when
you need to guarantee the consistency of your data. For example, you would not want a financial
transaction being calculated on an old version of the data.
OK, now that we’ve got the hard stuff out of the way, let’s move onto some of the more practical
questions that might come up when using a cloud-based database.

Local Development

Having a database in the cloud is cool, but how does it work if you’ve got a team of developers,
each of whom needs to run their own copy of the database locally? Fortunately, DynamoDB,
Bigtable and Cloud Datastore all have the option of downloading and running a local development
server. All three local development environments are really easy to download and get started with.
They are designedto provide you with an interface that matches the production environment.

Java Object Mapping


If you are going to be using Java to develop your application, you might be used to using
frameworks like Hibernate or JPA to automatically map RDBMS rows to objects. How does this
work with NoSQL databases?
DynamoDB provides an intuitive way of mapping Java classes to objects in DynamoDB Tables.
You simply annotate the Java object as a DynamoDB Table and then annotate your instance
variable getters with the appropriate annotations.
@DynamoDBTable(tableName="users")public class User {
@DynamoDBHashKey(attributeName="username") public String get Username(){
return username.
}
public void set Username (String username) {this. Username = username.
}@DynamoDBAttribute(attributeName = "email")public String get Email(){return email;
}
public void set Email (String email){this. Email = email.
}

Querying
An important thing to understand about all of these NoSQL databases is that they don’t provide a
full-blown query language.
Instead, you need to use their APIs and SDKs to access the database. By using simple query and
scan operations you can retrieve zero or more records from a given table. Since each of the three
databases I looked at provide a slightly different way of indexing the tables, the range of features
in this space varies.

925
DynamoDB for example provides multiple secondary indexes, meaning there is the ability to
efficiently scan any indexed column. This is not a feature in either ofGoogle’s NoSQL offerings.
Furthermore, unlike SQL databases, none of these NoSQL databases give you a means of doing
table joins, or even having foreign keys. Instead, this is something that your application has to
manage itself.
That’s said, one of the main advantages in my opinion of NoSQL is that there is no fixed schema.
As your needs change you can dynamically add new attributes to records in your table.
For example, using Java and DynamoDB, you can do the following, which will return a list of users
that have the same username as a given user:
User = new User(username); DynamoDBQueryExpression<User> queryExpression =
new DynamoDBQueryExpression<User>().withHashKeyValues(user);
List<User> itemList = [Link]().query([Link], queryExpression);
Distributed Database Design
The main benefit of NoSQL databases is their ability to scale, and to do so in an almost seamless
way. But, just like a SQL database, a poorly designed NoSQL database can give you slow query
response times. This is why you need to consider your database design carefully.
In order to spread the load across multiple nodes, distributed databases need to spread the
stored data across multiple nodes. This is done in order for the load to be balanced. The flip-side
of this is that if frequently-accessed data is on a small subset of nodes, you will not be making full
use of the available capacity.
Consequently, you need to be careful of which columns you select as indexes. Ideally you want to
spread your load across the whole table as opposed to accessing only a portion of your data.
A good design can be achieved by picking a hash key that is likely to be randomly accessed. For
example if you have a users table and choose the username as the hash key it will be likely that
load will distributed across all of the nodes. This is due to the likeliness that users will be
randomly accessed.
In contrast to this, it would, for example, be a poor design to use the date as the hash key for a
table that contains forum posts. This is due to the likeliness that most of the requests will be for
the records on the current day so the node or nodes containing these records will likely be a small
subset of all the nodes. Thisscenario can cause your requests to be throttled or hang.

Pricing
Since Google does not have a data centre in Australia, I will only be looking atpricing in the US.
DynamoDB is priced on storage and provisioned read/write capacity. In the Oregon region storage
is charged at $0.25 per GB/Month and at $0.0065 per hourfor every 10 units of Write Capacity and
the same price for every 50 units of read capacity.
Google Cloud Datastore has a similar pricing model. With storage priced at $0.18 per GB of data
per month and $0.06 per 100,000 read operations. Write operations are charged at the same rate.
Datastore also have a Free quota of 50,000 read and 50,000 write operations per day. Since
Datastore is a Beta product it currently has a limit of 100 million operations per day, however you
canrequest the limit to be increased.
The pricing model for Google Bigtable is significantly different. With Bigtable you are charged at a

926
rate of $0.65 per instance/hour. With a minimum of 3 instances required, some basic arithmetic
gives us a starting price for Bigtable of $142.35 per month. You are then charged at $0.17 per
GB/Month for SSD-backed storage. A cheaper HDD-backed option priced at $0.026 per GB/Month
is yet to be released.
Finally you are charged for external network usage. This ranges between 8 and 23 cents per GB of
traffic depending on the location and amount of data transferred. Traffic to other Google Cloud
Platform services in the same region/zone is free.

Database Management Systems


Unit – 4 MCQs
HE LEARN WITH EXPERTIES
1. A relational database consists of acollection of
a) Tables
b) Fields
c) Records
d) Keys
Answer: a
Explanation: Fields are the column of the relation or tables. Records are each row in a relation.
Keys are the constraints in a relation.

2. A in a table represents arelationship among a set of values.


a) Column
b) Key
c) Row
d) Entry

4. The term attribute refers to a


of a table.
a) Record
b) Column
c) Tuple
d) Key
Answer: b
Explanation: Attribute is a specificdomain in the relation which has entries of all tuples.

5. For each attribute of a relation, there is a set of permitted values, called the of that attribute.
a) Domain
b) Relation
927
c) Set
d) Schema
Answer: c
Explanation: Column has only one set of values. Keys are constraints and row is one whole set of
attributes. Entry is just a piece of data.

3. The term _ _ is used to referto a row.


a) Attribute
b) Tuple
c) Field
d) Instance
Answer: b
Explanation: Tuple is one entry of therelation with several attributes whichare fields.
Answer: a
Explanation: The values of the attribute should be present in thedomain. Domain is a set of values
permitted.

6. Database which is thelogical design of the database, and the database which is a snapshot of
the data in the databaseat a given instant in time.
a) Instance, Schema
b) Relation, Schema
c) Relation, Domain
d) Schema, Instance
Answer: d Explanation: Instance is an instance A domain is atomic if elements of the domain are
considered to be of time and schema is a unit representation.

7. Course (course_id, sec_id, semester) Here the course_id,sec_id and semester are and courseis a
a) Relations, Attribute
b) Attributes, Relation
c) Tuple, Relation
d) Tuple, Attributes
Answer: b
Explanation: The relation course hasa set of attributes course_id, sec_id,semester .

8. Department (dept name, building, budget) and Employee (employee,name, dept name, salary)
Here the dept_name attribute appears in both the relations. Here using common attributes in
relationschema is one way of relating
relations.
a) Attributes of common
b) Tuple of common
c) Tuple of distinct
d) Attributes of distinct
Answer: c
928
Explanation: Here the relations are connected by the common attributes.
a) Different
b) Indivisible
c) Constant
d) Divisible
Answer: b Explanation: None.

10. The tuples of the relations can beof order.


a) Any
b) Same
c) Sorted
d) Constant

Answer: a
Explanation: The values only [Link] order of the tuples does not matter.

11. Which one of the following is a set of one or more attributes taken collectively to uniquely
identify a record?
a) Candidate key
b) Sub key
c) Super key
d) Foreign key
Answer: c
Explanation: Super key is the supersetof all the keys in a relation.

12. Consider attributes ID, CITY andNAME. Which one of this can be considered as a super key?
a) NAME
b) ID
c) CITY
d) CITY, ID
Answer: b
Explanation: Here the id is the only attribute which can be taken as a key. Other attributes are not
uniquely identified.

13. The subset of a super key is a candidate key under what condition?
a) No proper subset is a super key
b) All subsets are super keys
c) Subset is a super key
d) Each subset is a super key
Answer: a
Explanation: The subset of a set cannot be the same set. Candidate key is a set from a super key
which cannot be the whole of the super set.

14. A is a property of the entire relation, rather than of the individual tuples in which each tuple is
929
unique.
a) Rows
b) Key
c) Attribute
d) Fields
Answer: b
Explanation: Key is the constraintwhich specifies uniqueness.

15. Which one of the following attributes can be taken as a primarykey?


a) Name
b) Street
c) Id
d) Department
Answer: c
Explanation: The attributes name, street and department can repeat for some tuples. But the id
attribute has to be unique. So it forms a primary key.

16. Which one of the following cannot be taken as a primary key?


a) Id
b) Register number
c) Dept_id
d) Street
Answer: d
Explanation: Street is the only attribute which can occur more thanonce.

17. An attribute in a relation is a foreign key if the _ key from one relation is used as an attribute in
that relation.
a) Candidate
b) Primary
c) Super
d) Sub
Answer: b
Explanation: The primary key has to

be referred in the other relation toform a foreign key in that relation.


18. The relation with the attribute which is the primary key is referenced in another relation. The
relation which has the attribute as a primary key is called
a) Referential relation
b) Referencing relation
c) Referenced relation
d) Referred relation
Answer: b Explanation: None.
19. The is the one in which the primary key of one relation is used as a normal attribute in
930
anotherrelation.
a) Referential relation
b) Referencing relation
c) Referenced relation
d) Referred relation
Answer: c Explanation: None.
20. A integrity constraintrequires that the values appearing in specified attributes of any tuple in
the referencing relation also appear in specified attributes of at least one tuple in the referenced
relation.
a) Referential
b) Referencing
c) Specific
d) Primary

Answer: a
Explanation: A relation, say r1, may include among its attributes the primary key of another
relation, say r2. This attribute is called a foreign key from r1, referencing r2. The relation r1 is also
called the referencing relation of the foreign key dependency, and r2 is called the referenced
relation of the foreign key.
21. Using which language can a userrequest information from a database?
a) Query
b) Relational
c) Structural
d) Compiler

Answer: a
Explanation: Query language is a method through which the databaseentries can be accessed.
22. Student(ID, name, dept name,tot_cred)
In this query which attributes formthe primary key?
a) Name
b) Dept
c) Tot_cred
d) ID

Answer: d
Explanation: The attributes name,dept and tot_cred can have samevalues unlike ID.
23. Which one of the following is aprocedural language?
a) Domain relational calculus
b) Tuple relational calculus
c) Relational algebra
d) Query language

Answer: c
931
Explanation: Domain and Tuple relational calculus are non-procedurallanguage. Query language is
a method through which database entries can be accessed.
24. The operation allows the combining of two relations by merging pairs of tuples, one from
each relation, into a single tuple.
a) Select
b) Join
c) Union
d) Intersection

Answer: b
Explanation: Join finds the common tuple in the relations and combines it.
25. The result which operation contains all pairs of tuples from the two relations, regardless of
whethertheir attribute values match.
a) Join
b) Cartesian product
c) Intersection
d) Set difference

Answer: b
Explanation: Cartesian product is themultiplication of all the values in theattributes.
26. Which one of the following is used to define the structure of the relation, deleting relations
and relating schemas?
a) DML(Data Manipulation Langauge)
b) DDL(Data Definition Langauge)
c) Query
d) Relational Schema
Answer: b
Explanation: Data Definition language is the language which performs all the operation in defining
structure ofrelation.
27. Which one of the following provides the ability to query information from the database and
toinsert tuples into, delete tuples from, and modify tuples in the database?
a) DML(Data Manipulation Langauge)
b) DDL(Data Definition Langauge)
c) Query
d) Relational Schema

Answer: a 30. The basic data type char(n) is a


Explanation: DML performs the length character string and
change in the values of the relation.28.

CREATE TABLE employee (name


VARCHAR, id INTEGER)

What type of statement is this?


932
a) DML
b) DDL
c) View
d) Integrity constraint

Answer: b
Explanation: Data Definition language is the language which performs all the operation in defining
structure of
varchar(n) is length character.
a) Fixed, equal
b) Equal, variable
c) Fixed, variable
d) Variable, equal
Answer: c
Explanation: Varchar changes its length accordingly whereas char has a specific length which has
to be filledby either letters or spaces.
31. An attribute A of datatype varchar(20) has the value “Avi”. The attribute B of datatype
char(20) hasvalue ”Reed”. Here attribute A has
relation. spaces and attribute B has
spaces.

[Link] * FROM employee What type of statement is this?


a) DML
b) DDL
c) View
d) Integrity constraint

Answer: a
Explanation: Select operation justshows the required fields of the relation. So it forms a DML.
a) 3, 20
b) 20, 4
c) 20, 20
d) 3, 4

Answer: a
Explanation: Varchar changes its length accordingly whereas char has a specific length which has
to be filledby either letters or spaces.

32. To remove a relation from an SQLdatabase, we use the command.

a) Delete
b) Purge
c) Remove
d) Drop table
933
Answer: d
Explanation: Drop table deletes the whole structure of the relation .purge removes the table which
cannot be obtained again.
33.
DELETE FROM r; //r - relation

This command performs which of thefollowing action?


a) Remove relation
b) Clear relation entries
c) Delete fields
d) Delete rows

Answer: b
Explanation: Delete command removes the entries in the table.
34. INSERT INTO instructor VALUES
(10211, ’Smith’, ’Biology’, 66000);

What type of statement is this?


a) Query
b) DML
c) Relational
d) DDL

Answer: b
Explanation: The values aremanipulated. So it is a DML.
35. Updates that violate _ are disallowed.
a) Integrity constraints
b) Transaction control
c) Authorization
d) DDL constraints

Answer: a
Explanation: Integrity constraint has to be maintained in the entries of therelation.
36.

Name

Annie

Bob

934
Callie

Derek

Which of these query will display thethe table given above ?


a) Select employee from name
b) Select name

c) Select name from employee


d) Select employee

Answer: c
Explanation: The field to be displayed is included in select and the table is included in the from
clause.
37. Here which of the following displays the unique values of thecolumn?

SELECT dept_nameFROM instructor;


a) All
b) From
c) Distinct
d) Name

Answer: c
Explanation: Distinct keyword selectsonly the entries that are unique.

38. The clause allows us to select only those rows in the result relation of the _ clause that
satisfy a specified predicate.
a) Where, from
b) From, select
c) Select, from
d) From, where

Answer: a
Explanation: Where selects the rowson a particular condition. From gives
the relation which involves theoperation.

39. The query given below will notgive an error. Which one of the following has to be replaced to
getthe desired output?

a) Salary*1.1
b) ID
c) Where
d) Instructor

935
Answer: c
Explanation: Where selects the rows on a particular condition. From gives the relation which
involves the operation. Since Instructor is a relation it has to have from clause.

40. The clause is used to list the attributes desired in the resultof a query.
a) Where
b) Select
c) From
d) Distinct

Answer: b Explanation: None


41. This Query can be replaced bywhich one of the following?
SELECT name, course_id
FROM instructor, teaches
WHERE instructor_ID= teaches_ID;
a) Select name,course_id fromteaches,instructor where instructor_id=course_id;
b) Select name, course_id frominstructor natural join teaches;
c) Select name, course_id frominstructor;
d) Select course_id from instructorjoin teaches;

Answer: b
Explanation: Join clause joins twotables by matching the common colum

42. SELECT * FROM employee WHERE


salary>10000 AND dept_id=101;
Which of the following fields aredisplayed as output?
a) Salary, dept_id
b) Employee
c) Salary
d) All the field of employee relation

Employee_id Name Salary

1001 Annie 6000

1009 Ross 4500

1018 Zeith 7000

This is Employee table.


Which of the following employee will be displayed for the given query?

a) 1009, 1001, 1018

936
b) 1009, 1018
c) 1001
d) 1018

Answer: d
Explanation: Greater than symboldoes not include the given value unlike >=.
Answer: d
Explanation: Here * is used to selectall the fields of the relation.

43. Which keyword must be used here torename the field name?
a) From
b) Rename
c) As
d) Join

Answer: c
Explanation: As keyword is used torename.

[Link] * FROM employee WHERE


dept_name="Comp Sci";
In the SQL given above there is anerror . Identify the error.
a) Dept_name
b) Employee
c) “Comp Sci”
d) From

Answer: c
Explanation: For any string operationssingle quoted(‘) must be used to enclose.

[Link] emp_name
FROM department
WHERE dept_name LIKE’
Computer Science’;
Which one of the following has to be added into the blank to select the dept_name which has
Computer Science as its ending string?
a) %
b) _
c) ||
d) $

Answer: a
Explanation: The % charactermatches any substring.
47. ’_ _ _ ’ matches any string of
three characters. ’_ _ _ %’ matches any string of at threecharacters.

937
a) Atleast, Exactly
b) Exactly, Atleast
c) Atleast, All
d) All, Exactly

Answer: b Explanation: None.

[Link] default, the order by clause listsitems in order.


a) Descending
b) Any
c) Same
d) Ascending

Answer: d
Explanation: Specification of descending order is essential but itnot for ascending.

[Link] *
FROM instructor
ORDER BY salary, name ;
To display the salary from greater to smaller and name in ascending order which of the following
options shouldbe used?
a) Ascending, Descending
b) Asc, Desc
c) Desc, Asc
d) Descending, Ascending

Answer: c Explanation: None.


50. The union operation isrepresented by
a) ∩
b) U
c) –
d) *

Answer: b
Explanation: Union operatorcombines the relations.
51. The intersection operator is usedto get the tuples.
a) Different
b) Common
c) All
d) Repeating

Answer: b
Explanation: Intersection operator ignores unique tuples and takes onlycommon ones.

938
52. The union operation automatically unlike theselect clause.
a) Adds tuples
b) Eliminates unique tuples
c) Adds common tuples
d) Eliminates duplicate

Answer: d Explanation: None.


53. If we want to retain all duplicates,we must write in place of union.
a) Union all
b) Union some
c) Intersect all
d) Intersect some

Answer: a
Explanation: Union all will combineall the tuples including duplicates.
54.

This query displays


a) Only tuples from second part
b) Only tuples from the first part which has the tuples from secondpart
c) Tuples from both the parts
d) Tuples from first part which do nothave second part

Answer: d
Explanation: Except keyword is usedto ignore the values.

55. For like predicate which of thefollowing is true.


i) % matches zero OF morecharacters.
ii) _ matches exactly one
CHARACTER.
a) i-only
b) ii-only
c) i & ii
d) None of the mentioned

Answer: a
Explanation:% is used with like and _is used to fill in the character.
56. The number of attributes inrelation is called as its
a) Cardinality
b) Degree
c) Tuples
d) Entity
939
Answer: b Explanation: None.
57. clause is an additional filterthat is applied to the result.
a) Select
b) Group-by
c) Having
d) Order by

Answer: c
Explanation: Having is used toprovide additional aggregate filtration to the query.
58. joins are SQL serverdefault
a) Outer
b) Inner
c) Equi
d) None of the mentioned

Answer: b
Explanation: It is optional to give theinner keyword with the join as it is default.

59. The is essentiallyused to search for patterns in target string.


a) Like Predicate
b) Null Predicate
c) In Predicate
d) Out Predicate

Answer: a
Explanation: Like predicate matchesthe string in the given pattern.

60. Aggregate functions are functionsthat take a as input andreturn a single value.
a) Collection of values
b) Single value
c) Aggregate value
d) Both Collection of values & Singlevalue

Answer: a Explanation: None.

61. SELECT _
FROM instructor
WHERE dept name= ’Comp. Sci.’;
Which of the following should be used to find the mean of the salary ?
a) Mean(salary)
b) Avg(salary)
c) Sum(salary)
940
d) Count(salary)

Answer: b
Explanation: Avg() is used to find themean of the values.

62. If we do want to eliminate duplicates,we use the keyword in the


aggregate expression.
a) Distinct
b) Count
c) Avg
d) Primary key

Answer: a
Explanation: Distinct keyword is usedto select only unique items from the relation.

63. All aggregate functions except


ignore null values in their inputcollection.
a) Count(attribute)
b) Count(*)
c) Avg
d) Sum

Answer: b
Explanation: * is used to select allvalues including null.

64. A Boolean data type that can takevalues true, false, and
a) 1
b) 0
c) Null
d) Unknown

Answer: d
Explanation: Unknown values do nottake null value but it is not known.

65. The connective tests for setmembership, where the set is a collection of values produced by
aselect clause. The connectivetests for the absence of set membership.
a) Or, in
b) Not in, in
c) In, not in
d) In, or

Answer: c
Explanation: In checks, if the queryhas the value but not in checks if itdoes not have the value.
66. The phrase “greater than at leastone” is represented in SQL by
941
a) < all
b) < some
c) > all
d) > some

Answer: d
Explanation: >some takes atlest onevalue above it .

67. Which of the following is used to find all courses taught in both the Fall 2009 semester and
in the Spring 2010semester .
a)SELECT course id FROM SECTION AS S
WHERE semester = ’Fall’ AND YEAR=
WHERE semester = ’Spring’ AND
YEAR= 2010 AND
[Link] id= [Link] id);
b)

c)

d)

Answer: a Explanation: None.

68. We can test for the nonexistenceof tuples in a subquery by using the
construct.
a) Not exist
b) Not exists
c) Exists
d) Exist

Answer: b
Explanation: Exists is used to checkfor the existence of tuples.

69. SELECT dept_name, ID, avg (salary)


FROM instructor
GROUP BY dept_name;
This statement IS erroneous because
a) Avg(salary) should not be selected
b) Dept_id should not be used ingroup by clause
c) Misplaced group by clause
d) Group by clause is not valid in thisquery

Answer: b

942
Explanation: Any attribute that is not present in the group by clause must appear only inside an
aggregate function if it appears in the select clause, otherwise the query is treatedas erroneous.
70. SQL applies predicates in the
clause after groups have been formed, so aggregate functionsmay be used.
a) Group by
b) With
c) Where
d) Having

Answer: b
Explanation: The with clause provides away of defining a temporary relation whose definition is
available only to the query in which the with clause occurs.

71. Aggregate functions can be used in the select list or the clause of a select statement or
subquery. They cannot be used in a clause.
a) Where, having
b) Having, where
c) Group by, having
d) Group by, where

Answer: b
Explanation: To include aggregatefunctions having clause must be included after where.

72. The keyword is used to access attributes of preceding tables or subqueries in the from
clause.
a) In
b) Lateral
c) Having
d) With

Answer: b Explanation:

FROM instructor I2
WHERE [Link] name= [Link]);
Without the lateral clause, thesubquery cannot access the correlation variable
I1 from the outer query.

73. Which of the following creates atemporary relation for the query onwhich it is defined?
a) With
b) From
c) Where
d) Select

Answer: a
943
Explanation: The with clause provides a way of defining a temporary relation whose definition is
available only to the query in which the with clause occurs.

74. A Delete command operates on


relation.
a) One
b) Two
c) Several
d) Null

Answer: a
Explanation: Delete can delete fromonly one table at a time.
75. Delete from r where P;
The above command
a) Deletes a particular tuple from therelation
b) Deletes the relation
c) Clears all entries from the relation
d) All of the mentioned

Answer: a
Explanation: Here P gives the condition for deleting specific rows.

76. Which one of the following deletes all the entries but keeps thestructure of the relation.
a) Delete from r where P;
b) Delete from instructor where deptname= ’Finance’;
c) Delete from instructor where salary between 13000 and 15000;
d) Delete from instructor;

Answer: d
Explanation: Absence of conditiondeletes all rows.

77. are useful in SQL update statements, where they canbe used in the set clause.
a) Multiple queries
b) Sub queries
c) Update
d) Scalar subqueries

Answer: d Explanation: None.

78. The problem of ordering the update in multiple updates is avoidedusing


a) Set
b) Where
c) Case

944
d) When

Answer: c
Explanation: The case statements canadd the order of updating tuples.

79. Which of the following creates a virtual relation for storing the query?
a) Function
b) View
c) Procedure
d) None of the mentioned

Answer: b
Explanation: Any such relation that is not part of the logical model, but is made visible to a user as
a virtual relation, is called a view.

80. Which of the following is thesyntax for views where v is viewname?


a) Create view v as “query name”;
b) Create “query expression” as view;
c) Create view v as “queryexpression”;
d) Create view “query expression”;

Answer: c
Explanation: <query expression> is
any legal query expression. The viewname is represented by v.

81. Here the tuples are selected from [Link] one denotes the view.
a) Course_id
b) Watson
c) Building
d) physics_fall_2009

Answer: c
Explanation: View names may appearin a query any place where a relationname may appear.
82. Materialised views make surethat
a) View definition is kept stable
b) View definition is kept up-to-date
c) View definition is verified for error
d) View is deleted after specified time

Answer: b Explanation: None.


83. Updating the value of the view
a) Will affect the relation from whichit is defined
b) Will not change the view definition
945
c) Will not affect the relation fromwhich it is defined

d) Cannot determine

Answer: a Explanation: None.


84. SQL view is said to be updatable (that is, inserts, updates or deletes can be applied on the
view) if whichof the following conditions are satisfied by the query defining the view?
a) The from clause has only onedatabase relation
b) The query does not have a groupby or having clause
c) The select clause contains only attribute names of the relation and does not have any
expressions, aggregates, or distinct specification
d) All of the mentioned

Answer: d
Explanation: All of the conditions must be satisfied to update the viewin sql.

85. Which of the following is used atthe end of the view to reject the tuples which do not satisfy
the condition in where clause?
a) With
b) Check
c) With check
d) All of the mentioned

Answer: c
Explanation: Views can be defined
with a with check option clause at the end of the view definition; then, if a tuple inserted into the
view does not satisfy the view’s where clause condition, the insertion is rejected by the database
system.

86. For the view Create viewinstructor_info as

If we insert tuple into the view asinsert into instructor info values (’69987’, ’White’, ’Taylor’);
What will be the values of the otherattributes in instructor and department relations?
a) Default value
b) Null
c) Error statement
d) 0

Answer: b
Explanation: The values take null if there is no constraint in the attribute else it is an Erroneous
statement.
87. FROM instructor;
Find the error in this query.
a) Instructor
b) Select
946
c) View …as
d) None of the mentioned

Answer: d
Explanation: Syntax is – create view vas <query expression>;.
88. A consists of a sequence of query and/or updatestatements.
a) Transaction
b) Commit
c) Rollback
d) Flashback

Answer: a
Explanation: Transaction is a set ofoperation until commit.
89. Which of the following makes thetransaction permanent in the database?
a) View
b) Commit
c) Rollback
d) Flashback

Answer: b
Explanation: Commit work commitsthe current transaction.

90. In order to undo the work of transaction after last commit which
one should be used.
a) View
b) Commit
c) Rollback
d) Flashback

Answer: c
Explanation: Rollback work causes the current transaction to be rolled back; that is, it undoes all
the updatesperformed by the SQL statements in the transaction.

91. Consider the following action:

What does Rollback do?


a) Undoes the transactions beforecommit
b) Clears all transactions
c) Redoes the transactions beforecommit
d) No action

Answer: d
Explanation: Once a transaction has executed commit work, its effects canno longer be undone by

947
rollback work.

92. In case of any shut down duringtransaction before commit which of the following statement
is done automatically?

a) View
b) Commit
c) Rollback
d) Flashback

Answer: c
Explanation: Once a transaction has executed commit work, its effects canno longer be undone by
rollback work.

93. In order to maintain the consistency during transactions,database provides


a) Commit
b) Atomic
c) Flashback
d) Retain
95. A transaction completes itsexecution is said to be
a) Committed
b) Aborted
c) Rolled back
d) Failed

Answer: a
Explanation: A complete transactionalways commits.

96. Which of the following is used toget back all the transactions back after rollback?
a) Commit
b) Rollback
c) Flashback
d) Redo

Answer: b
Explanation: By atomic, either all the effects of the transaction are reflected in the database, or
none are(after rollback).

94. Transaction processing is associated with everything belowexcept


a) Conforming an action or triggeringa response
b) Producing detail summary orexception report
c) Recording a business activity
d) Maintaining a data
948
Answer: a Explanation: None.
Answer: c Explanation: None.
97. will undo all statementsup to commit?
a) Transaction
b) Flashback
c) Rollback
d) Abort

Answer: c
Explanation: Flashback will undo allthe statements and Abort will terminate the operation.
98. To include integrity constraint inan existing relation use :
a) Create table

b) Modify table
c) Alter table
d) Drop table

Answer: c
Explanation: SYNTAX – alter table table-name add constraint, where constraint can be any
constraint onthe relation.

99. Which of the following is not anintegrity constraint?


a) Not null
b) Positive
c) Unique
d) Check ‘predicate’
b) Error in create statement
c) Error in insert into Employeevalues(1006,Ted,Finance, );
d) Error in insert into Employeevalues(1008,Ross,Sales,20000);

Answer: d
Explanation: The not null specification prohibits the insertionof a null value for the attribute.
The unique specification says that no two tuples in the relation can be equal on all the listed
attributes.
101.

Answer: b
Explanation: Positive is a value andnot a constraint.
100.
CREATE TABLE Employee(Emp_id
NUMERIC NOT NULL, Name
VARCHAR(20) , dept_name
VARCHAR(20), Salary NUMERIC
949
UNIQUE(Emp_id,Name)); INSERT INTO Employee VALUES(1002, Ross, CSE, 10000)
INSERT INTO Employee VALUES(1006,Ted,Finance, );INSERT INTO Employee

What will be the result of the query?


a) All statements executed
In order to ensure that the value of budget is non-negative which of thefollowing should be used?
a) Check(budget>0)
b) Check(budget<0)
c) Alter(budget>0)
d) Alter(budget<0)

Answer: a
Explanation: A common use of thecheck clause is to ensure that attribute values satisfy specified
conditions, in effect creating a powerful type system.

102. Foreign key is the one in whichthe of one relation is referenced in another relation.
a) Foreign key
b) Primary key
c) References
d) Check constraint

Answer: b
Explanation: The foreign-key declaration specifies that for each course tuple, the department
namespecified in the tuple must exist in the department relation.
[Link] TABLE course( . . .FOREIGN KEY (dept name)REFERENCES department
. . . );
Which of the following is used to delete the entries in the referenced table when the tuple is
deleted in course table?
a) Delete
b) Delete cascade
c) Set null
d) All of the mentioned

Answer: b
Explanation: The delete “cascades” to the course relation, deletes the tuple that refers to the
department that was deleted.
104. Domain constraints, functional dependency and referential integrityare special forms of
a) Foreign key
b) Primary key
c) Assertion
d) Referential constraint

Answer: c
Explanation: An assertion is a predicate expressing a condition we wish the database to always
950
satisfy.
105. Which of the following is theright syntax for the assertion?
a) Create assertion ‘assertion-name’check ‘predicate’;
b) Create assertion check ‘predicate’‘assertion-name’;
c) Create assertions ‘predicates’;
d) All of the mentioned

Answer: a Explanation: None.


106. Data integrity constraints areused to:
a) Control who is allowed access tothe data
b) Ensure that duplicate records arenot entered into the table
c) Improve the quality of data entered for a specific property (i.e.,table column)
d) Prevent users from changing thevalues stored in the table

Answer: c Explanation: None.


107. Which of the following can be addressed by enforcing a referentialintegrity constraint?
a) All phone numbers must includethe area code
b) Certain fields are required (such asthe email address, or phone number) before the record is
accepted
c) Information on the customer mustbe known before anything can be sold to that customer
d) When entering an order quantity, the user must input a number and not some text (i.e., 12
rather than ‘adozen’)

Answer: c
Explanation: The information can bereferred to and obtained.
108. Dates must be specified in theformat
a) mm/dd/yy
b) yyyy/mm/dd
c) dd/mm/yy
d) yy/dd/mm

Answer: b
Explanation: yyyy/mm/dd is thedefault format in sql.

109. A on an attribute of a relation is a data structure that allows the database system to find
those
tuples in the relation that have a specified value for that attribute efficiently, without scanning
throughall the tuples of the relation.
a) Index
b) Reference
c) Assertion
d) Timestamp

Answer: a
951
Explanation: Index is the reference tothe tuples in a relation.

110. Create index studentID_index on student (ID);which one denotes the relation for which index
is created?
a) StudentID_index
b) ID
c) StudentID
d) Student

Answer: d
Explanation: The statement creates an index named studentID index on the attribute ID of the
relation student.

111. Which of the following is used tostore movie and image files?
a) Clob
b) Blob
c) Binary

d) Image

Answer: b
Explanation: SQL therefore provides large-object data types for character data (clob) and binary
data (blob).
The letters “lob” in these data typesstand for “Large OBject”.

112. The user defined data type canbe created using


a) Create datatype
b) Create data
c) Create definetype
d) Create type

Answer: d
Explanation: The create type clause can be used to define new [Link] : create type Dollars
asnumeric(12,2) final; .

113. Values of one type can be converted to another domain usingwhich of the following?
a) Cast
b) Drop type
c) Alter type
d) Convert

Answer: a
Explanation: Example of cast :cast ([Link] to numeric(12,2)). SQL provides drop type
and alter type clauses to drop ormodify types that have been created earlier.

952
114. In order to ensure that an instructor’s salary domain allows only values greater than a
specified value use:
a) Value>=30000.00
b) Not null;
c) Check(value >= 29000.00);
d) Check(value)

Answer: c
Explanation: Check(value ‘condition’)is the syntax.
115. Which of the following closelyresembles Create view?
a) Create table . . .like
b) Create table . . . as
c) With data
d) Create view as

Answer: b
Explanation: The ‘create table . . . as’ statement closely resembles the create view statement and
both are defined by using queries. The main difference is that the contents of the table are set
when the table is created, whereas the contents of a view always reflect the current queryresult.

116. In contemporary databases, thetop level of the hierarchy consists of


each of which can contain

a) Catalogs, schemas
b) Schemas, catalogs
c) Environment, schemas
d) Schemas, Environment

Answer: a Explanation: None.

117. Which of the following statements creates a new table temp instructor that has the same
schema as an instructor.
a) create table temp_instructor;
b) Create table temp_instructor likeinstructor;
c) Create Table as temp_instructor;
d) Create table like temp_instructor;

Answer: b Explanation: None.


118. The database administrator who authorizes all the new users, modifies the database and
takes grants privilege is
a) Super user
b) Administrator
c) Operator of operating system
953
d) All of the mentioned

Answer: d
Explanation: The authorizations
provided by the administrator to theuser is a privilege.

119. Which of the following is a basicform of grant statement?


a)

b)

c)

d)

Answer: a
Explanation: The privilege list allowsthe granting of several privileges in one command .

120. Which of the following is used toprovide privilege to only a particular attribute?
a) Grant select on employee to Amit
b) Grant update(budget) on
department to Raj
c) Grant update(budget,salary,Rate)on department to Raj
d) Grant delete to Amit

Answer: b
Explanation: This grant statement gives user Raj update authorization on the budget attribute of
the department relation.

121. Which of the following statement is used to remove theprivilege from the user Amir?
a) Remove update on departmentfrom Amir
b) Revoke update on employee fromAmir
c) Delete select on department fromRaj
d) Grant update on employee fromAmir

Answer: b
Explanation: revoke on from ;
122. Which of the following is used toprovide delete authorization to instructor?
a)CREATE ROLE instructor ;
GRANT DELETE TO instructor;b)
CREATE ROLE instructor;

GRANT SELECT ON takes


TO instructor.

954
c) All of the mentionedAnswer: c
Explanation: The role is first createdand the authorization is given on relation takes to the role.
123. Which of the following is trueregarding views?
a) The user who creates a view cannot be given update authorization on a view without having
update authorization on the relations used todefine the view
b) The user who creates a view cannot be given update authorization on a view without having
update authorization on the relations used todefine the view
c) If a user creates a view on which no authorization can be granted, the system will allow the
view creation request
d) A user who creates a view receivesall privileges on that view

Answer: c
Explanation: A user who creates a

view does not necessarily receive allprivileges on that view.


124. If we wish to grant a privilege and to allow the recipient to pass the privilege on to other
users, we append the clause to theappropriate grant command.
a) With grant
b) Grant user
c) Grant pass privelege
d) With grant option

Answer: d Explanation: None.


125. In authorization graph, if DBA provides authorization to u1 which inturn gives to u2 which of
the following is correct?
a) If DBA revokes authorization fromu1 then u2 authorization is also revoked
b) If u1 revokes authorization from u2then u2 authorization is revoked
c) If DBA & u1 revokes authorization from u1 then u2 authorization is alsorevoked
d) If u2 revokes authorization then u1authorization is revoked

Answer: c
Explanation: A user has an authorization if and only if there is a path from the root of the
authorization graph down to the node representing the user.

126. Which of the following is used toavoid cascading of authorizations from the user?
a) Granted by current role
b) Revoke select on department fromAmit, Satoshi restrict;
c) Revoke grant option for select ondepartment from Amit;
d) Revoke select on department fromAmit, Satoshi cascade;

Answer: b
Explanation: The revoke statement may specify restrict in order to prevent cascading revocation.
The keyword cascade can be used insteadof restrict to indicate that revocationshould cascade.

955
127. The granting and revoking of roles by the user may cause some confusions when that user
role is revoked. To overcome the above situation
a) The privilege must be granted onlyby roles
b) The privilege is granted by rolesand users
c) The user role cannot be removedonce given
d) By restricting the user access tothe roles

Answer: a
Explanation: The current role associated with a session can be setby executing set role name. The

specified role must have been granted to the user, else the set rolestatement fails.
128. A is a special kind of a store procedure that executes in response to certain action on the
table like insertion, deletion or updation of data.
a) Procedures
b) Triggers
c) Functions
d) None of the mentioned

Answer: b
Explanation: Triggers are automatically generated when aparticular operation takes place.
129. Triggers are supported in
a) Delete
b) Update
c) Views
d) All of the mentioned

Answer: c
Explanation: The triggers run after aninsert, update or delete on a table.
They are not supported for views.
130. The CREATE TRIGGER statementis used to create the trigger. THE
clause specifies the table name on which the trigger is to be attached. The specifies that this is
an AFTER INSERT trigger.
a) for insert, on
b) On, for insert
c) For, insert
d) None of the mentioned

Answer: b
Explanation: The triggers run after aninsert, update or delete on a table.
They are not supported for views.
131. What are the after triggers?
a) Triggers generated after aparticular operation
b) These triggers run after an insert,update or delete on a table
c) These triggers run after an insert,views, update or delete on a table
956
d) All of the mentioned

Answer: b
Explanation: AFTER TRIGGERS can be classified further into three types as: AFTER INSERT
Trigger, AFTER UPDATE
Trigger, AFTER DELETE Trigger.
132. The variables in the triggers aredeclared using
a) –
b) @
c) /
d) /@

Answer: b
Explanation: Example : declare @empid int; where empid is thevariable.

133. The default extension for anOracle SQL*Plus file is:


a) .txt
b) .pls
c) .ora
d) .sql

Answer: d
Explanation: Example :None.
134. Which of the following is NOT anOracle-supported trigger?
a) BEFORE
b) DURING
c) AFTER
d) INSTEAD OF

Answer: b
Explanation: Example: During triggeris not possible in any database.
135. What are the different intriggers?
a) Define, Create
b) Drop, Comment
c) Insert, Update, Delete
d) All of the mentioned

Answer: c
Explanation: Triggers are not possiblefor create, drop.
136. Triggers enabled ordisabled
a) Can be
b) Cannot be
c) Ought to be
957
d) Always

Answer: a
Explanation: Triggers can bemanipulated.
137. Which prefixes are available toOracle triggers?
a) : new only
b) : old only
c) Both :new and : old
d) Neither :new nor : old

Answer: c Explanation: None.


138. OLAP stands for
a) Online analytical processing
b) Online analysis processing
c) Online transaction processing
d) Online aggregate processing

Answer: a
Explanation: OLAP is the manipulation of information tosupport decision making.
139. Data that can be modeled as dimension attributes and measureattributes are called data.
a) Multidimensional
b) Singledimensional
c) Measured
d) Dimensional

Answer: a
Explanation: Given a relation used for

data analysis, we can identify some of its attributes as measure attributes, since they measure
some value, and can be aggregated [Link] attribute define the dimensions on which
measure attributes, and summaries of measure attributes, areviewed.
140. The generalization of cross-tabwhich is represented visually is
which is also called asdata cube.
a) Two dimensional cube
b) Multidimensional cube
c) N-dimensional cube
d) Cuboid

Answer: a
Explanation: Each cell in the cube is identified for the values for the threedimensional attributes.
141. The process of viewing the cross-tab (Single dimensional) with afixed value of one attribute
is
a) Slicing
958
b) Dicing
c) Pivoting
d) Both Slicing and Dicing

Answer: a
Explanation: The slice operation selects one particular dimension from a given cube and provides
a new sub-cube. Dice selects two or more
dimensions from a given cube andprovides a new sub-cube.
142. The operation of moving from finer-granularity data to a coarser granularity (by means of
aggregation)is called a
a) Rollup
b) Drill down
c) Dicing
d) Pivoting

Answer: a
Explanation: The opposite operation—that of moving fromcoarser-granularity data to finer-
granularity data—is called a drill down.
143. In SQL the cross-tabs are createdusing
a) Slice
b) Dice
c) Pivot
d) All of the mentioned

Answer: a
Explanation: Pivot (sum(quantity) forcolor in (’dark’,’pastel’,’white’)).
144.

This can be achieved by using whichof the following ?


a) group by rollup
b) group by cubic
c) group by
d) none of the mentioned

Answer: d
Explanation: ‘Group by cube’ is used .
145. What do data warehousessupport?
a) OLAP
b) OLTP
c) OLAP and OLTP
d) Operational databases

Answer: a Explanation: None.

959
146.

SELECT item name, color, clothes


SIZE, SUM(quantity)FROM sales
GROUP BY rollup(item name, color,clothes SIZE);
How many grouping is possible in thisrollup?
a) 8
b) 4
c) 2
d) 1

Answer: b
Explanation: { (item name, color,
clothes size), (item name, color),(item name), () }.

147. Which one of the following is theright syntax for DECODE?


a) DECODE (search, expression, result[, search, result]… [, default])
b) DECODE (expression, result [,
search, result]… [, default], search)
c) DECODE (search, result [, search,result]… [, default], expression)
d) DECODE (expression, search, result[, search, result]… [, default])

Answer: d Explanation: None.


148. Relational Algebra is a
query language that takes two relations as input and produces another relation as an output of
the query.
a) Relational
b) Structural
c) Procedural
d) Fundamental

Answer: c
Explanation: This language has fundamental and other operationswhich are used on relations.

149. Which of the following is a fundamental operation in relationalalgebra?


a) Set intersection
b) Natural join
c) Assignment
d) None of the mentioned

Answer: d
Explanation: The fundamental operations are select, project, union, set difference, Cartesian
product, andrename.

960
150. Which of the following is used todenote the selection operation in relational algebra?
a) Pi (Greek)
b) Sigma (Greek)
c) Lambda (Greek)
d) Omega (Greek)
another.
a) Union
b) Set difference
c) Difference
d) Intersection

Answer: b
Explanation: The expression r − s produces a relation containing thosetuples in r but not in s.

153. Which is a unary operation:


a) Selection operation
b) Primitive operation
c) Projection operation
d) Generalized selection

Answer: b
Explanation: The select operationselects tuples that satisfy a given predicate.

151. For select operation the


appear in the subscript andthe argument appears in the paranthesis after the sigma.
a) Predicates, relation
b) Relation, Predicates
c) Operation, Predicates
d) Relation, Operation

Answer: a Explanation: None.

152. The operation,


denoted by −, allows us to find tuplesthat are in one relation but are not in
Answer: d
Explanation: Generalization Selectiontakes only one argument for operation.
154. Which is a join condition contains an equality operator:
a) Equijoins
b) Cartesian
c) Natural
d) Left

Answer: a Explanation: None.


961
155. In precedence of set operators,the expression is evaluated from
a) Left to left
b) Left to right
c) Right to left
d) From user specification

Answer: b
Explanation: The expression is evaluated from left to right accordingto the precedence.

156. Which of the following is notouter join?


a) Left outer join
b) Right outer join
c) Full outer join
d) All of the mentioned

Answer: d
Explanation: The FULL OUTER JOIN keyword combines the result of bothLEFT and RIGHT joins.

157. The assignment operator isdenoted by


a) ->
b) <-
c) =
d) ==
b) Э t ∈ r (Q(t))
c) {t | Э s ε instructor (t[ID] = s[ID]𝖠s[salary] > 80000)}
d) None of the mentioned

Answer: a
Explanation: This expression is intuple relational format.

159. A query in the tuple relationalcalculus is expressed as:


a) {t | P() | t}
b) {P(t) | t }
c) {t | P(t)}
d) All of the mentioned

Answer: c
Explanation: The tuple relational calculus, is a nonprocedural query language. It describes the
desired information without giving a specificprocedure for obtaining that information.
160.

Answer: b
Explanation: The result of the

962
expression to the right of the ← is assigned to the relation variable onthe left of the ←.

158. Find the ID, name, dept name, salary for instructors whose salary isgreater than $80,000 .
a) {t | t ε instructor 𝖠 t[salary] >80000}

{t | Э s ε instructor (t[name] =
s[name]
𝖠 Э u ε department (u[dept name] =
s[dept name]
𝖠 u[building] = “Watson”))}
Which of the following best describesthe query?
a) Finds the names of all instructorswhose department is in the Watsonbuilding

b) Finds the names of all departmentis in the Watson building


c) Finds the name of the dapartmentwhose instructor and building is Watson
d) Returns the building name of allthe departments

Answer: a
Explanation: This query has two “there exists” clauses in our tuple- relational-calculus expression,
connected by and (𝖠).

161. Which of the following symbol isused in the place of except?


a) ^
b) V
c) ¬
d) ~

Answer: c
Explanation: The query ¬P negatesthe value of P.
162. “Find all students who have taken all courses offered in the Biology department.” The
expressions that matches this sentence is :
a) Э t ε r (Q(t))
b) ∀ t ε r (Q(t))
c) ¬ t ε r (Q(t))
d) ~ t ε r (Q(t))
Answer: b
Explanation: ∀ is used denote “forall” in SQL.

163. An is a set of entities of the same type that share the sameproperties, or attributes.
a) Entity set
b) Attribute set
c) Relation set
d) Entity model
963
Answer: a
Explanation: An entity is a “thing” or “object” in the real world that is distinguishable from all other
objects.

164. Entity is a
a) Object of relation
b) Present working model
c) Thing in real world
d) Model of relation

Answer: c
Explanation: For example, each person in a university is an entity.

165. The descriptive property possessed by each entity set is

a) Entity
b) Attribute
c) Relation
d) Model

Answer: b
Explanation: Possible attributes of the instructor entity set are ID, name,dept name, and salary.

166. The function that an entity playsin a relationship is called that entity’s

a) Participation
b) Position
c) Role
d) Instance

Answer: c
Explanation: A relationship is an association among several entities.

167. The attribute name could be structured as an attribute consistingof first name, middle initial,
and lastname. This type of attribute is called
a) Simple attribute
b) Composite attribute
c) Multivalued attribute
d) Derived attribute

Answer: b
Explanation: Composite attributes can be divided into subparts (that is,other attributes).

964
168. The attribute AGE is calculated from DATE_OF_BIRTH. The attributeAGE is
a) Single valued
b) Multi valued
c) Composite
d) Derived
Answer: d
Explanation: The value for this type of attribute can be derived from the values of other related
attributes or entities.

169. Not applicable condition can berepresented in relation entry as


a) NA
b) 0
c) NULL
d) Blank Space

Answer: c
Explanation: NULL always representsthat the value is not present.

170. Which of the following can be amultivalued attribute?


a) Phone_number
b) Name
c) Date_of_birth
d) All of the mentioned

Answer: a
Explanation: Name and Date_of_birthcannot hold more than 1 value.
171. Which of the following is a singlevalued attribute
a) Register_number
b) Address
c) SUBJECT_TAKEN
d) Reference

Answer: a Explanation: None.

172. In a relation between the entities the type and condition of the relation should be specified.
That is called as attribute.
a) Desciptive
b) Derived
c) Recursive
d) Relative

Answer: a

965
Explanation: Consider the entity sets student and section, which participate in a relationship set
takes. We may wish to store a descriptive attribute grade with the relationship to record the grade
that a student gotin the class.

172. express the number of entities to which another entity can be associated via a relationship
set.
a) Mapping Cardinality
b) Relational Cardinality
c) Participation Constraints
d) None of the mentioned

Answer: a
Explanation: Mapping cardinality isalso called as cardinality ratio.

173. An entity in A is associated with at most one entity in B, and an entity in B is associated with
at most one entity in [Link] is called as
a) One-to-many
b) One-to-one
c) Many-to-many
d) Many-to-one

Answer: b
Explanation: Here one entity in oneset is related to one one entity in other set.

174. An entity in A is associated with at most one entity in B. An entity in B, however, can be
associated with any number (zero or more) of entities in A.
a) One-to-many
b) One-to-one
c) Many-to-many
d) Many-to-one

Answer: d
Explanation: Here more than one entity in one set is related to one oneentity in other set.
175. Data integrity constraints areused to:
a) Control who is allowed access tothe data
b) Ensure that duplicate records arenot entered into the table
c) Improve the quality of data entered for a specific property
d) Prevent users from changing thevalues stored in the table

Answer: c
Explanation: The data entered will bein a particular cell (i.e., table column).

176. Establishing limits on allowable property values, and specifying a set of acceptable,
predefined options that can be assigned to a property are examples of:
966
a) Attributes
b) Data integrity constraints
c) Method constraints
d) Referential integrity constraints

Answer: b
Explanation: Only particular value satisfying the constraints are enteredin the column.

177. Which of the following can be addressed by enforcing a referentialintegrity constraint?


a) All phone numbers must includethe area code
b) Certain fields are required (such asthe email address, or phone number) before the record is
accepted
c) Information on the customer mustbe known before anything can be sold to that customer
d) Then entering an order quantity, the user must input a number and not some text (i.e., 12
rather than ‘adozen’)

Answer: c Explanation: None.

178. is a special type of integrity constraint that relates tworelations & maintains consistency
across the relations.
a) Entity Integrity Constraints
b) Referential Integrity Constraints
c) Domain Integrity Constraints
d) Domain Constraints

Answer: b Explanation: None.


179. Which one of the following uniquely identifies the elements inthe relation?
a) Secondary Key
b) Primary key
c) Foreign key
d) Composite key

Answer: b
Explanation: Primary key checks fornot null and uniqueness constraint.
180. Drop Table cannot be used todrop a table referenced by a
constraint.
a) Local Key
b) Primary Key
c) Composite Key
d) Foreign Key

Answer: d
Explanation: Foreign key is used when primary key of one relation isused in another relation.
967
181. is preferred method for enforcing data integrity
a) Constraints
b) Stored Procedure
c) Triggers
d) Cursors

Answer: a
Explanation: Constraints are specifiedto restrict entries in the relation.

182. Which of the following gives alogical structure of the database graphically?
a) Entity-relationship diagram
b) Entity diagram
c) Database diagram
d) Architectural representation

Answer: a
Explanation: E-R diagrams are simple and clear—qualities that may well account in large part for
the widespread use of the E-R model.

183. The entity relationship set isrepresented in E-R diagram as


a) Double diamonds
b) Undivided rectangles
c) Dashed lines
d) Diamond

Answer: d
Explanation: Dashed lines link attributes of a relationship set to therelationship set.

184. The Rectangles divided into twoparts represents


a) Entity set
b) Relationship set
c) Attributes of a relationship set
d) Primary key

Answer: a
Explanation: The first part of the rectangle, contains the name of the entity set. The second part
contains the names of all the attributes of theentity set.

185. Consider a directed line(->) from the relationship set advisor to both entity sets instructor
and student. This indicates cardinality
a) One to many
b) One to one
c) Many to many

968
d) Many to one

Answer: b
Explanation: This indicates that an instructor may advise at most one student, and a student may
have atmost one advisor.

186. We indicate roles in E-R diagrams by labeling the lines that connect to
a) Diamond, diamond
b) Rectangle, diamond
c) Rectangle, rectangle
d) Diamond, rectangle

Answer: d
Explanation: Diamond represents a relationship set and rectanglerepresents a entity set.

187. An entity set that does not have sufficient attributes to form a primarykey is termed a
a) Strong entity set
b) Variant set
c) Weak entity set
d) Variable set

Answer: c
Explanation: An entity set that has a primary key is termed a strong entityset.

188. For a weak entity set to be meaningful, it must be associated with another entity set, called
the
a) Identifying set
b) Owner set
c) Neighbour set
d) Strong entity set

Answer: a
Explanation: Every weak entity must be associated with an identifying entity; that is, the weak
entity set is said to be existence dependent on the identifying entity set. The identifying entity set
is said to own the weak entity set that it [Link] is also called as owner entity set.
189. Weak entity set is representedas
a) Underline
b) Double line
c) Double diamond
d) Double rectangle

Answer: c
Explanation: An entity set that has a primary key is termed a strong entityset.

969
190. If you were collecting and storing information about your music collection, an album would
be considered a(n)
a) Relation
b) Entity
c) Instance
d) Attribute

Answer: b
Explanation: An entity set is a logicalcontainer for instances of an entity type and instances of any
type derived from that entity type.

191. What term is used to refer to a specific record in your music database; for instance;
informationstored about a specific album?
a) Relation
b) Instance
c) Table
d) Column
Answer: b
Explanation: The environment of database is said to be an instance. A database instance or an
‘instance’ is made up of the background processes needed by the database.

192. The total participation by entities is represented in E-R diagramas


a) Dashed line
b) Double line
c) Double rectangle
d) Circle

Answer: b
Explanation: It is used to representthe relation between several attributes.
193. Given the basic ER and relationalmodels, which of the following is INCORRECT?
a) An attribute of an entity can havemore than one value
b) An attribute of an entity can becomposite
c) In a row of a relational table, anattribute can have more than onevalue
d) In a row of a relational table, an attribute can have exactly one valueor a NULL value

Answer: c
Explanation: It is possible to have several values for a single attribute provide it is a multi-valued
attribute.

194. Which of the following indicates the maximum number of entities that
can be involved in a relationship?
a) Minimum cardinality
b) Maximum cardinality
970
c) ERD
d) Greater Entity Count

Answer: b
Explanation: In SQL (Structured Query Language), the term cardinality refers to the uniqueness of
data values contained in a particular column (attribute) of a database table.

195. In E-R diagram generalization isrepresented by


a) Ellipse
b) Dashed ellipse
c) Rectangle
d) Triangle

Answer: d
Explanation: Ellipse represents attributes, rectangle representsentity.

196. The entity set person is classifiedas student and employee. This process is called
a) Generalization
b) Specialization
c) Inheritance
d) Constraint generalization

Answer: b
Explanation: The process of designating subgroupings within anentity set is called specialization.

197. Which relationship is used torepresent a specialization entity?


a) ISA
b) AIS
c) ONIS
d) WHOIS

Answer: a
Explanation: In terms of an E-R diagram, specialization is depicted bya hollow arrow-head pointing
from the specialized entity to the other entity.

198. The refinement from an initial entity set into successive levels of entity subgroupings
represents a
design process in whichdistinctions are made explicit.
a) Hierarchy
b) Bottom-up
c) Top-down
d) Radical

Answer: c
971
Explanation: The design process may also proceed in a bottom-up manner,in which multiple entity
sets are synthesized into a higher-level entityset on the basis of common features.

199. There are similarities between the instructor entity set and the secretary entity set in the
sense that they have several attributes that are conceptually the same across the two entity sets:
namely, the identifier,
name, and salary attributes. Thisprocess is called
a) Commonality
b) Specialization
c) Generalization
d) Similarity

Answer: c
Explanation: Generalization is used toemphasize the similarities among lower-level entity sets and
to hide thedifferences.
200. If an entity set is a lower-level entity set in more than one ISA relationship, then the entity set
has
a) Hierarchy
b) Multilevel inheritance
c) Single inheritance
d) Multiple inheritance

Answer: d
Explanation: The attributes of the higher-level entity sets are said to be inherited by the lower-level
entity sets.

201. A constraint requires that an entity belong to no more than one lower-level entity set.
a) Disjointness
b) Uniqueness
c) Special
d) Relational

Answer: a
Explanation: For example, student entity can satisfy only one condition for the student type
attribute; an entity can be either a graduate student or an undergraduate student, but cannot be
both.

202. Consider the employee work- team example, and assume that certain employees participate
in more than one work team. A given employee may therefore appear in more than one of the
team entity sets that are lower level entity sets ofemployee. Thus, the generalization is

a) Overlapping
b) Disjointness
c) Uniqueness

972
d) Relational

Answer: a
Explanation: In overlapping generalizations, the same entity may belong to more than one lower-
levelentity set within a single generalization.
203. In the normal form,a composite attribute is converted toindividual attributes.
a) First
b) Second
c) Third
d) Fourth

Answer: a
Explanation: The first normal form is
used to eliminate the duplicateinformation.

204. A table on the many side of aone to many or many to many relationship must:
a) Be in Second Normal Form (2NF)
b) Be in Third Normal Form (3NF)
c) Have a single attribute key
d) Have a composite key

Answer: d
Explanation: The relation in second normal form is also in first normal form and no partial
dependencies onany column in primary key.

205. Tables in second normal form(2NF):


a) Eliminate all hidden dependencies
b) Eliminate the possibility of ainsertion anomalies
c) Have a composite key
d) Have all non key fields depend onthe whole primary key

Answer: a
Explanation: The relation in second normal form is also in first normal form and no partial
dependencies onany column in primary key.

206. Which-one of the following statements about normal forms isFALSE?


a) BCNF is stricter than 3 NF
b) Lossless, dependency -preserving

decomposition into 3 NF is alwayspossible


c) Loss less, dependency – preservingdecomposition into BCNF is always possible
d) Any relation with two attributes isBCNF

Answer: c
973
Explanation: We say that the decomposition is a lossless decomposition if there is no loss of
information by replacing r (R) withtwo relation schemas r1(R1) andr2(R2).
207. Functional Dependencies are thetypes of constraints that are based on
a) Key
b) Key revisited
c) Superset key
d) None of the mentioned

Answer: a
Explanation: Key is the basic elementneeded for the constraints.

208. Which is a bottom-up approach to database design that design by examining the
relationship betweenattributes:
a) Functional dependency
b) Database modeling
c) Normalization
d) Decomposition
Answer: c
Explanation: Normalisation is the process of removing redundancy andunwanted data.
209. Which forms simplifies and ensures that there are minimal data aggregates and repetitive
groups:
a) 1NF
b) 2NF
c) 3NF
d) All of the mentioned

Answer: c
Explanation: The first normal form isused to eliminate the duplicate information.
210. Which forms has a relation thatpossesses data about an individual entity:
a) 2NF
b) 3NF
c) 4NF
d) 5NF

Answer: c
Explanation: A Table is in 4NF if and only if, for every one of its non-trivial multivalued
dependencies X
\twoheadrightarrow Y, X is a superkey—that is, X is either a candidate key or a superset thereof.

211. Which forms are based on theconcept of functional dependency:


a) 1NF
b) 2NF
c) 3NF

974
d) 4NF

Answer: c
Explanation: The table is in 3NF if every non-prime attribute of R is non- transitively dependent (i.e.
directly dependent) on every superkey of R.

212. Empdt1(empcode, name, street, city,state, pincode).


For any pincode, there is only one city and state. Also, for given street, city and state, there is just
one pincode.
In normalization terms, empdt1 is arelation in
a) 1 NF only
b) 2 NF and hence also in 1 NF
c) 3NF and hence also in 2NF and 1NF
d) BCNF and hence also in 3NF, 2NFand 1NF

Answer: b
Explanation: The relation in second normal form is also in first normal form and no partial
dependencies onany column in primary key.

213. We can use the following three rules to find logically implied functional dependencies. This
collection of rules is called
a) Axioms
b) Armstrong’s axioms
c) Armstrong
d) Closure

Answer: b
Explanation: By applying these rulesrepeatedly, we can find all of F+, given F.

214. An approach to website design with the emphasis on converting visitors to outcomes
required by theowner is referred to as:
a) Web usability
b) Persuasion
c) Web accessibility
d) None of the mentioned

Answer: b
Explanation: In computing, graphical user interface is a type of user interface that allows users to
interactwith electronic devices.

125. A method of modelling and describing user tasks for an interactive application is referred to
as:
a) Customer journey
b) Primary persona

975
c) Use case
d) Web design persona

Answer: c
Explanation: The actions in GUI areusually performed through direct

manipulation of the graphicalelements.


216. Information architectureinfluences:
a) Answer choice
b) Site structure
c) Labeling
d) Navigation design

Answer: b
Explanation: The actions in GUI are usually performed through direct manipulation of the graphical
elements.

217. Also known as schematics, a wayof illustrating the layout of an individual webpage is a:
a) Wireframe
b) Sitemap
c) Card sorting
d) Blueprint

Answer: a
Explanation: An application programming interface specifies how some software components
should interact with each other.
218. A graphical or text depiction of the relationship between different groups of content on a
website is referred to as a:
a) Wireframe
b) Blueprint
c) Sitemap
d) Card sorting

Answer: c
Explanation: An application programming interface specifies how some software components
should interact with each other.

219. Blueprints are intended to:


a) Prototype of the screen layout showing navigation and main designelements
b) Show the grouping of pages anduser journeys
c) Indicate the structure of a siteduring site design and as a user feature
d) Prototype typical customer journeys or clickstreams through awebsite

Answer: c
976
Explanation: A blueprint is a reproduction of a technical drawing, documenting an architecture or
an engineering design, using a contact print process.
220. Storyboards are intended to:
a) Indicate the structure of a siteduring site design and as a user feature
b) Prototype of the screen layout showing navigation and main designelements
c) Integrate consistently available components on the webpage (e.g.

navigation, search boxes)


d) Prototype typical customer journeys or click streams through awebsite

Answer: d
Explanation: An application programming interface specifies how some software components
should interact with each other.
Answer: a
Explanation: Clustering index are alsocalled primary indices; the term primary index may appear to
denote an index on a primary key, but such indices can in fact be built on any search key.
223. Indices whose search key specifies an order different from the sequential order of the file
are called
221. Which of the following occupies indices.
boot record of hard and floppy disksand activated during computer startup?
a) Worm
b) Boot sector virus
c) Macro virus
d) Virus

Answer: b
Explanation: A blueprint is a reproduction of a technical drawing, documenting an architecture or
an engineering design, using a contact print process.

222. In ordered indices the file containing the records is sequentiallyordered, a is an index whose
search key also defines the sequential order of the file.
a) Clustered index
b) Structured index
c) Unstructured index
d) Nonclustered index
a) Nonclustered
b) Secondary
c) All of the mentioned
d) None of the mentioned

Answer: c
Explanation: Nonclustering index isalso called secondary indices.

224. An consists of a search-key value and pointers to one or more records with that value as
977
their search-key value.
a) Index entry
b) Index hash
c) Index cluster
d) Index map

Answer: a
Explanation: The pointer to a record consists of the identifier of a disk block and an offset within
the disk block to identify the record within theblock.

225. In a clustering index, the index record contains the search-key value and a pointer to the first
data record with that search-key value and the rest of the records will be in the sequential
pointers.
a) Dense
b) Sparse
c) Straight
d) Continuous

Answer: a
Explanation: In a dense non clustering index, the index must store a list of pointers to all records
with the same search-key value.

226. In a index, an indexentry appears for only some of the search-key values.
a) Dense
b) Sparse
c) Straight
d) Continuous

Answer: a
Explanation: Sparse indices can be used only if the relation is stored in sorted order of the search
key, that isif the index is a clustering index.

227. Incase the indices values are larger, index is created for these values of the index. This is
called
a) Pointed index
b) Sequential index
c) Multilevel index
d) Multiple index

Answer: c
Explanation: Indices with two ormore levels are called multilevelindices.

228. A search key containing more than one attribute is referred to as a


search key.
978
a) Simple
b) Composite
c) Compound
d) Secondary

Answer: b
Explanation: The structure of the index is the same as that of any other index, the only difference
being that the search key is not a single attribute, but rather is a list of attributes.

229. In B+ tree the node which pointsto another node is called


a) Leaf node
b) External node
c) Final node
d) Internal node

Answer: d
Explanation: Nonleaf nodes are alsoreferred to as internal nodes.

230. Insertion of a large number ofentries at a time into an index is referred to as of the
index.
a) Loading
b) Bulk insertion
c) Bulk loading
d) Increase insertion

Answer: c
Explanation: Bulk loading is used toimprove efficiency and scalability.

231. While inserting the record intothe index, if the search-key value does not appear in the index.
a) The system adds a pointer to thenew record in the index entry
b) The system places the record being inserted after the other records with the same search-
key values
c) The system inserts an index entry with the search-key value in the index at the appropriate
position
d) None of the mentioned

Answer: c
Explanation: If the index entry stores pointers to all records with the same search key value, the
system adds a pointer to the new record in the index entry.

232. A(n) can be used to preserve the integrity of a documentor a message.


a) Message digest
b) Message summary
c) Encrypted message
979
d) None of the mentioned

Answer: c
Explanation: Encryption algorithmsare used to keep the contents safe.

233. A hash function must meet


criteria.
a) Two
b) Three
c) Four
d) None of the mentioned

Answer: b
Explanation: Only if the criteria isfulfilled the values are hashed.

234. What is the main limitation ofHierarchical Databases?


a) Limited capacity (unable to holdmuch data)
b) Limited flexibility in accessing data
c) Overhead associated withmaintaining indexes
d) The performance of the databaseis poor

Answer: b
Explanation: In this, the data items are placed in a tree like hierarchicalstructure.

235. The property (or set of properties) that uniquely defineseach row in a table is called the:
a) Identifier
b) Index
c) Primary key
d) Symmetric key

Answer: c
Explanation: Primary is used touniquely identify the tuples.

236. The separation of the data definition from the program is knownas:
a) Data dictionary
b) Data independence
c) Data integrity
d) Referential integrity

Answer: b
Explanation: Data dictionary is the place where the meaning of the dataare organized.

237. Bitmap indices are a specializedtype of index designed for easy querying on

980
a) Bit values
b) Binary digits
c) Multiple keys
d) Single keys

Answer: c
Explanation: Each bitmap index isbuilt on a single key.

238. A on the attribute A ofrelation r consists of one bitmap for each value that A can take.
a) Bitmap index
b) Bitmap
c) Index
d) Array

Answer: a
Explanation: A bitmap is simply anarray of bits.

239. In this selection, we fetch the bitmaps for gender value f and the bitmap for income level
value L2, andperform an _ of the two bitmaps.
a) Union
b) Addition
c) Combination
d) Intersection

Answer: d
Explanation: We compute a new bitmap where bit i has value 1 if the ith bit of the two bitmaps are
both 1,and has a value 0 otherwise.
240. To identify the deleted recordswe use the
a) Existence bitmap
b) Current bitmap
c) Final bitmap
d) Deleted bitmap

Answer: a
Explanation: The bitmaps which aredeleted are denoted by 0.

241. What is the purpose of the indexin sql server?


a) To enhance the query performance
b) To provide an index to a record
c) To perform fast searches
d) All of the mentioned

Answer: d
981
Explanation: A database index is a data structure that improves the speed of data retrieval
operations ona database table at the cost of additional writes.

242. How many types of indexes arethere in sql server?


a) 1
b) 2
c) 3
d) 4

Answer: b
Explanation: They are clustered indexand non clustered index.

243. How non clustered index pointto the data?


a) It never points to anything
b) It points to a data row
c) It is used for pointing data rowscontaining key values
d) None of the mentioned
Answer: c
Explanation: Nonclustered indexes have a structure separate from the data rows. A nonclustered
index contains the nonclustered index key values and each key value entry has a pointer to the
data row that containsthe key value.
244. Which one is true aboutclustered index?
a) Clustered index is not associatedwith table
b) Clustered index is built by defaulton unique key columns
c) Clustered index is not built onunique key columns
d) None of the mentioned

Answer: b
Explanation: Nonclustered indexes have a structure separate from the data rows. A nonclustered
index contains the nonclustered index key values and each key value entry has a pointer to the
data row that containsthe key value.

245. What is true about indexes?


a) Indexes enhance the performanceeven if the table is updated frequently
b) It makes harder for sql server engines to work to work on indexwhich have large keys
c) It doesn’t make harder for sql server engines to work to work on
index which have large keys
d) None of the mentioned

Answer: b
Explanation: Indexes tend to improvethe performance.

246. A collection of data designed tobe used by different people is calleda/an


a) Organization
982
b) Database
c) Relationship
d) Schema

Answer: b
Explanation: Database is a collectionof related tables.

247. Which of the following is theoldest database model?


a) Relational
b) Deductive
c) Physical
d) Network

Answer: d
Explanation: The network model is a database model conceived as a flexible way of representing
objects and their relationships.

248. Which of the following schemas does define a view or views of the database for particular
users?
a) Internal schema
b) Conceptual schema
c) Physical schema
d) External schema

Answer: d
Explanation: An externally-defined schema can provide access to tables that are managed on any
PostgreSQL,Microsoft SQL Server, SAS, Oracle, or MySQL database.

249. Which of the following are the process of selecting the data storage and data access
characteristics of thedatabase?
a) Logical database design
b) Physical database design
c) Testing and performance tuning
d) Evaluation and selecting

Answer: b
Explanation: The physical design of the database optimizes performance while ensuring data
integrity by avoiding unnecessary data redundancies.

250. Which of the following terms does refer to the correctness and completeness of the data in
a database?
a) Data security
b) Data constraint
c) Data independence
983
d) Data integrity

Answer: d
Explanation: ACID property is satisfied by transaction in database.

251. The relationship between DEPARTMENT and EMPLOYEE is a


a) One-to-one relationship
b) One-to-many relationship
c) Many-to-many relationship
d) Many-to-one relationship

Answer: b
Explanation: One entity departmentis related to several employees.

252. A table can be logically connected to another table bydefining a


a) Super key
b) Candidate key
c) Primary key
d) Unique key

Answer: c
Explanation: A superkey is a combination of attributes that can be uniquely used to identify a
database record.

253. If the state of the database no longer reflects a real state of the world that the database is
supposed to capture, then such a state is called
a) Consistent state
b) Parallel state
c) Durable state
d) Inconsistent state

Answer: d
Explanation: SQL data consistency is that whenever a transaction is performed, it sees a
consistent database.

254. Ensuring isolation property is theresponsibility of the


a) Recovery-management componentof the DBMS
b) Concurrency-control component ofthe DBMS
c) Transaction-management component of the DBMS
d) Buffer management component inDBMS

Answer: b
Explanation: Concurrency control ensures that correct results for concurrent operations are
generatedwhile getting those results as quicklyas possible.
984
255. is a procedural extension of Oracle – SQLthat offers language constructs similar to those in
imperative programming languages.
a) SQL
b) PL/SQL
c) Advanced SQL
d) PQL

Answer: b
Explanation: PL/SQL is an imperative 3GL that was designed specifically for the seamless
processing of SQL commands.

256. combines the data manipulating power of SQL with the data processing power of
Procedural languages.
a) PL/SQL
b) SQL
c) Advanced SQL
d) PQL

Answer: a
Explanation: PL/SQL is an imperative 3GL that was designed specifically for the seamless
processing of SQL commands.

257. has made PL/SQL code run faster without requiring any additional work on the part of the
programmer.
a) SQL Server
b) My SQL
c) Oracle
d) SQL Lite

Answer: c
Explanation: An Oracle database is a collection of data treated as a unit. The purpose of a
database is to storeand retrieve related information.
258. A line of PL/SQL text containsgroups of characters known as
a) Lexical Units
b) Literals
c) Textual Units
d) Identifiers

Answer: a
Explanation: Lexical items can be generally understood to convey a single meaning, much as a
lexeme,but are not limited to single words.
259. We use namePL/SQL program objects and units.
a) Lexical Units
985
b) Literals
c) Delimiters
d) Identifiers

Answer: d
Explanation: The database object name is referred to as its identifier.
260. Consider money is transferred from (1)account-A to account-B and
(2) account-B to account-A. Which ofthe following form a transaction?
a) Only 1
b) Only 2
c) Both 1 and 2 individually
d) Either 1 or 2

Answer: c
Explanation: The term transaction refers to a collection of operations that form a single logical
unit of work.

261. A transaction is delimited by statements (or function calls) of theform


a) Begin transaction and endtransaction
b) Start transaction and stoptransaction
c) Get transaction and posttransaction
d) Read transaction and writetransaction

Answer: a
Explanation: The transaction consists of all operations executed between the begin transaction
and end transaction.
262. Identify the characteristics oftransactions
a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned

Answer: d
Explanation: Because of the above three properties, transactions are an ideal way of structuring
interaction with a database.
263. Which of the following has “all-or-none” property?
a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned

Answer: a
Explanation: Either all operations of the transaction are reflected properly in the database, or none

986
are.
264. The database system must takespecial actions to ensure that transactions operate properly
without interference from concurrently executing database statements. This property is referredto
as
a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned

Answer: c
Explanation: Even though multiple transactions may execute concurrently, the system guarantees
that, for every pair of transactions Tiand Tj, it appears to Ti that either Tj finished execution before
Ti started or Tj started execution after Ti finished.
265. The property of a transactionthat persists all the crashes is
a) Atomicity
b) Durability
c) Isolation
d) All of the mentioned

Answer: b 268. The Oracle RDBMS uses the


Explanation: After a transaction statement to declare a new
completes successfully, the changes it has made to the database persist, even if there are system
failures.
266. states that onlyvalid data will be written to the database.
a) Consistency
b) Atomicity
c) Durability
d) Isolation

Answer: a
Explanation: If for some reason, a transaction is executed that violates the database’s
consistency rules, the entire transaction will be rolled back and the database will be restored to a
state consistent with those rules.
267. Transaction processing is associated with everything belowexcept
a) Producing detail summary orexception reports
b) Recording a business activity
c) Confirming an action or triggering aresponse
d) Maintaining a data

Answer: c
Explanation: Collections of operations that form a single logical unit of work are called
transactions.
transaction start and its properties.
a) BEGIN
987
b) SET TRANSACTION
c) BEGIN TRANSACTION
d) COMMIT

Answer: b
Explanation: Commit is used to storeall the transactions.
269. means that the data used during the execution of a transactioncannot be used by a second
transaction until the first one is completed.
a) Consistency
b) Atomicity
c) Durability
d) Isolation

Answer: d
Explanation: Even though multiple transactions may execute concurrently, the system guarantees
that, for every pair of transactions Tiand Tj, it appears to Ti that either Tj finished execution before
Ti started or Tj started execution after Ti finished.
270. In SQL, which command is used to issue multiple CREATE TABLE, CREATE VIEW and
GRANT statementsin a single transaction?
a) CREATE PACKAGE

b) CREATE SCHEMA
c) CREATE CLUSTER
d) All of the mentioned

Answer: b
Explanation: A database schema of a database system is its structure described in a formal
language supported by the database management system and refers to the organization of data
as a blueprint of how a database is constructed.
271. In SQL, the CREATE TABLESPACEis used
a) To create a place in the database for storage of scheme objects, rollback segments, and
naming the data files to comprise the tablespace
b) To create a database trigger
c) To add/rename data files, tochange storage
d) All of the mentioned

Answer: a
Explanation: Triggers are used to initialize the actions for an activity.
272. Which character function can beused to return a specified portion of acharacter string?
a) INSTR
b) SUBSTRING
c) SUBSTR
d) POS

988
Answer: c
Explanation: SUBSTR are used to match the particular characters in astring.
273. Which of the following is TRUEfor the System Variable $date$?
a) Can be assigned to a globalvariable
b) Can be assigned to any field onlyduring design time
c) Can be assigned to any variable orfield during run time
d) Can be assigned to a local variable

Answer: b
Explanation: A database schema of a database system is its structure described in a formal
language supported by the database management system and refers to the organization of data
as a blueprint of how a database is constructed.
275. What are the different events inTriggers?
a) Define, Create
b) Drop, Comment
c) Insert, Update, Delete
d) Select, Commit

Answer: c
Explanation: A database trigger is a procedural code that is automatically executed in response to
certain

events on a particular table or view ina database.


276. Which of the following is not aproperty of transactions?
a) Atomicity
b) Concurrency
c) Isolation
d) Durability

Answer: d
Explanation: ACID properties are theproperties of transactions.
277. SNAPSHOT is used for (DBA)
a) Synonym
b) Tablespace
c) System server
d) Dynamic data replication

Answer: d
Explanation: Snapshot gets the instance of the database at that time.
278. Isolation of the transactions isensured by
a) Transaction management
b) Application programmer
c) Concurrency control
989
d) Recovery management

Answer: c
Explanation: ACID properties are theproperties of transactions.
279. Constraint checking can be disabled in existing and _ constraints so
that any data you modify or add to the table is not checked against theconstraint.
a) CHECK, FOREIGN KEY
b) DELETE, FOREIGN KEY
c) CHECK, PRIMARY KEY
d) PRIMARY KEY, FOREIGN KEY

Answer: a
Explanation: Check and foreign constraints are used to constraint thetable data.
280. In order to maintain transactional integrity and database consistency, what technology does
aDBMS deploy?
a) Triggers
b) Pointers
c) Locks
d) Cursors

Answer: c
Explanation: Locks are used to maintain database consistency.
281. A lock that allows concurrent transactions to access different rows of the same table is
known as a
a) Database-level lock
b) Table-level lock
c) Page-level lock
d) Row-level lock

Answer: d
Explanation: Locks are used to maintain database consistency.

282. Which of the following are introduced to reduce the overheads caused by the log-based
recovery?
a) Checkpoints
b) Indices
c) Deadlocks
d) Locks

Answer: a
Explanation: Checkpoints are introduced to reduce overheads caused by the log-based recovery.
283. Which of the following protocolsensures conflict serializability and safety from deadlocks?
a) Two-phase locking protocol
990
b) Time-stamp ordering protocol
c) Graph based protocol
d) None of the mentioned

Answer: b
Explanation: Time-stamp ordering protocol ensures conflict serializability and safety from
deadlocks.
284. A system is in a state if there exists a set of transactions such that every transaction in the
set is waiting for another transaction in theset.
a) Idle
b) Waiting
c) Deadlock
d) Ready
Answer: c
Explanation: When one data item iswaiting for another data item in a transaction then system is in
deadlock.
285. The deadlock state can be changed back to stable state by using
statement.
a) Commit
b) Rollback
c) Savepoint
d) Deadlock

Answer: b
Explanation: Rollback is used to rollback to the point before lock isobtained.
286. What are the ways of dealingwith deadlock?
a) Deadlock prevention
b) Deadlock recovery
c) Deadlock detection
d) All of the mentioned

Answer: d
Explanation: Deadlock prevention isalso called as deadlock recovery.
Prevention is commonly used if the probability that the system would enter a deadlock state is
relatively high; otherwise, detection and recovery are more efficient.
287. The most recent version ofstandard SQL prescribed by the

American National StandardsInstitute is


a) SQL 2016
b) SQL 2002
c) SQL – 4
d) SQL2

991
Answer: a
Explanation: SQL-2016 is the mostrecent version of standard SQL prescribed by the ANSI.
288. ANSI-standard SQL allows the use of special operators in conjunction with the WHERE
clause.A special operator used to check whether an attribute value is null is
a) BETWEEN
b) IS NULL
c) LIKE
d) IN

Answer: b
Explanation: Exists is used to check whether an attribute value is null ornot in conjunction with the
where clause.
289. The method of access that useskey transformation is called as
a) Direct
b) Hash
c) Random
d) Sequential
Answer: b
Explanation: Hash technique usesparticular hash key value.
290. Why do we need concurrencycontrol on B+ trees ?
a) To remove the unwanted data
b) To easily add the index elements
c) To maintain accuracy of index
d) All of the mentioned

Answer: c
Explanation: Indices do not have tobe treated like other database structures.
291. How many techniques are available to control concurrency onB+ trees?
a) One
b) Three
c) Four
d) None of the mentioned

Answer: d
Explanation: Two techniques arepresent.
292. In crabbing protocol locking
a) Goes down the tree and back up
b) Goes up the tree and back down
c) Goes down the tree and releases
d) Goes up the tree and releases

Answer: a
Explanation: It moves in a crab likemanner.
992
293. The deadlock can be handled by
a) Removing the nodes that aredeadlocked
b) Restarting the search afterreleasing the lock
c) Restarting the search withoutreleasing the lock
d) Resuming the search

Answer: b
Explanation: Crabbing protocolmoves in a crab like manner.
294. The recovery scheme must alsoprovide
a) High availability
b) Low availability
c) High reliability
d) High durability

Answer: a
Explanation: It must minimize thetime for which the database is notusable after a failure.
295. Which one of the following is afailure to a system
a) Boot crash
b) Read failure
c) Transaction failure
d) All of the mentioned

Answer: c
Explanation: Types of system failureare transaction failure, system crashand disk failure.
296. Which of the following belongsto transaction failure
a) Read error
b) Boot error
c) Logical error
d) All of the mentioned

Answer: c
Explanation: Types of system transaction failure are logical andsystem error.
297. The system has entered an undesirable state (for example, deadlock), as a result of which a
transaction cannot continue with itsnormal execution. This is
a) Read error
b) Boot error
c) Logical error
d) System error

Answer: c
Explanation: The transaction, can bere-executed at a later time.
298. The transaction can no longer continue with its normal execution because of some internal
993
condition, such as bad input, data not found, overflow, or resource limit exceeded.
This is
a) Read error
b) Boot error
c) Logical error
d) System error

Answer: c
Explanation: The transaction, can bere-executed at a later time.
299. The assumption that hardware errors and bugs in the software bringthe system to a halt, but
do not corrupt the nonvolatile storage contents, is known as the
a) Stop assumption
b) Fail assumption
c) Halt assumption
d) Fail-stop assumption
301. The log is a sequence of
recording all the updateactivities in the database.
a) Log records
b) Records
c) Entries
d) Redo
Answer: a
Explanation: The most widely usedstructure for recording database modifications is the log.
Answer: d
302. In the
scheme, a
Explanation: Well-designed systems
have numerous internal checks, at the hardware and the software level, that bring the system to a
halt when there is an error. Hence, the fail-stopassumption is a reasonable one.
300. Which kind of failure loses its data in head crash or failure during atransfer operation.
a) Transaction failure
b) System crash
c) Disk failure
d) All of the mentioned

Answer: c
Explanation: Copies of the data on other disks, or archival backups on tertiary media, such as DVD
or tapes,are used to recover from the failure.
transaction that wants to update thedatabase first creates a complete copy of the database.
a) Shadow copy
b) Shadow Paging
c) Update log records
d) All of the mentioned

994
Answer: a
Explanation: If at any point the transaction has to be aborted, the system merely deletes the new
[Link] old copy of the database has notbeen affected.
303. The scheme uses a page table containing pointers to all pages; the page table itself and all
updated pages are copied to a new location.

a) Shadow copy
b) Shadow Paging
c) Update log records
d) All of the mentioned
Answer: b
Explanation: Any page which is not updated by a transaction is not copied, but instead the new
page table just stores a pointer to the original page.
304. The current copy of the database is identified by a pointer, called which is storedon disk.
a) Db-pointer
b) Update log
c) Update log records
d) All of the mentioned
Answer: a
Explanation: Any page which is not updated by a transaction is not copied, but instead the new
page table just stores a pointer to the original page.
305. If a transaction does not modify the database until it has committed, it is said to use the _
technique.
a) Deferred-modification
b) Late-modification
c) Immediate-modification
d) Undo

Answer: a
Explanation: Deferred modification has the overhead that transactions need to make local copies
of all updated data items; further, if a transaction reads a data item that it has updated, it must
read the valuefrom its local copy.
306. If database modifications occurwhile the transaction is still active, the transaction is said to
use the
technique.
a) Deferred-modification
b) Late-modification
c) Immediate-modification
d) Undo
Answer: c
Explanation: We say a transaction modifies the database if it performs an update on a disk buffer,
or on the disk itself; updates to the private part of main memory do not count as database
modifications.
995
307. using a log recordsets the data item specified in the logrecord to the old value.
a) Deferred-modification
b) Late-modification
c) Immediate-modification
d) Undo

Answer: d
Explanation: Undo brings theprevious contents.
308. In the phase, the system replays updates of all transactions by scanning the log forward
from the last checkpoint.
a) Repeating
b) Redo
c) Replay
d) Undo

Answer: b
Explanation: Undo brings theprevious contents.
309. In order to reduce the overheadin retrieving the records from the storage space we use
a) Logs
b) Log buffer
c) Medieval space
d) Lower records

Answer: b
Explanation: The output to stablestorage is in units of blocks.
the log buffer.
a) Must be exactly the same
b) Can be different
c) Is opposite
d) Can be partially same
Answer: a
Explanation: As a result of log buffering, a log record may reside in only main memory (volatile
storage)for a considerable time before it is output to stable storage.
311. Before a block of data in main memory can be output to the database, all log records
pertaining todata in that block must have been output to stable storage. This is
a) Read-write logging
b) Read-ahead logging
c) Write-ahead logging
d) None of the mentioned

Answer: c
Explanation: The WAL rule requires only that the undo information in the log has been output to
stable storage,and it permits the redo information to be written later.
996
312. Writing the buffered log to
310. The order of log records in the is sometimes referred to
stable storage as theorder in which they were written to
as a log force.
a) Memory

b) Backup
c) Redo memory
d) Disk

Answer: d
Explanation: If there are insufficientlog records to fill the block, all log records in main memory are
combined into a partially full block and are output to stable storage.
313. The silicon chips used for dataprocessing are called
a) RAM chips
b) ROM chips
c) Micro processors
d) PROM chips

Answer: d
Explanation: PROM is ProgrammableRead Only Memory.
314. Which of the following is usedfor manufacturing chips?
a) Control bus
b) Control unit
c) Parity unit
d) Semiconductor

Answer: d
Explanation: A semiconductor is amaterial which has electrical conductivity between that of a
conductor such as copper and that ofan insulator such as glass.
315. What was the name of the firstcommercially available microprocessor chip?
a) Intel 308
b) Intel 33
c) Intel 4004
d) Motorola 639

Answer: c
Explanation: The Intel 4004 is a 4-bit central processing unit (CPU) released by Intel Corporation in
1971
316. Which lock should be obtained to prevent a concurrent transaction from executing a
conflicting read, insert or delete operation on the same key value.
a) Higher-level lock
b) Lower-level lock
997
c) Read only lock
d) Read write
Answer: a
Explanation: Operations acquire lower-level locks while they execute, but release them when they
complete; the corresponding transaction must however retain a higher-level lock in a two-phase
manner to prevent concurrent

transactions from executingconflicting actions.


317. Once the lower-level lock is
backup site where all the data fromthe primary site are replicated.
319. Remote backup system must be
released, the operation cannot be with the primary site.
undone by using the old values of updated data items, and must insteadbe undone by executing a
compensating operation; such an operation is called
a) Logical operation
b) Redo operation
c) Logical undo operation
d) Undo operation
Answer: a
Explanation: It is important that the lower-level locks acquired during an operation are sufficient to
perform asubsequent logical undo of the operation.
318. The remote backup site issometimes also called the
a) Primary Site
b) Secondary Site
c) Tertiary Site
d) None of the mentioned
Answer: b
Explanation: We can achieve high availability by performing transaction processing at one site,
called the primary site, and having a remote
a) Synchronised
b) Separated
c) Connected
d) Detached but related

Answer: a
Explanation: We can achieve high availability by performing transaction processing at one site,
called the primary site, and having a remote backup site where all the data from the primary site
are replicated.
320. The backup is taken by
a) Erasing all previous records
b) Entering the new records
c) Sending all log records from primary site to the remote backupsite
998
d) Sending selected records from primary site to the remote backupsite
Answer: c
Explanation: We can achieve high availability by performing transaction processing at one site,
called the primary site, and having a remote

backup site where all the data fromthe primary site are replicated.
321. When the the backup site takes over processing andbecomes the primary.
a) Secondary fails
b) Backup recovers
c) Primary fails
d) None of the mentioned

Answer: c
Explanation: When the original primary site recovers, it can eitherplay the role of remote backup, or
323. In the phase, the system replays updates of all transactions by scanning the log forward
from the last checkpoint.
a) Repeating
b) Redo
c) Replay
d) Undo

Answer: b
Explanation: Undo brings theprevious contents.
324. The actions which are played inthe order while recording it is called
take over the role of primary site history.
again.

322. The simplest way of transferring control is for the old primary to receive from the old backup
site.
a) Undo logs
b) Redo Logs
c) Primary Logs
d) All of the mentioned
Answer: c
Explanation: If control must be transferred back, the old backup site can pretend to have failed,
resultingin the old primary taking over.
a) Repeating
b) Redo
c) Replay
d) Undo
Answer: a
Explanation: Undo brings theprevious contents.
325. A special redo-only log record < Ti, Xj, V1> is written to the log, where V1 is the value being
999
restored to dataitem Xj during the rollback. These logrecords are sometimes called
a) Log records
b) Records
c) Compensation log records
d) Compensation redo records

Answer: c
Explanation: Such records do not need undo information since we never need to undo such an
undooperation.
326. The process of designating subgroupings within the entity set is called as
a) Specialization
b) Division
c) Aggregation
d) Finalization
Answer: a
Explanation: The process of designating sub-groupings within the entity set is called as
specialization. Specialization allows us to distinguishamong entities.
327. State true or false: Specializationcan be applied only once
a) True
b) False

Answer: a
Explanation: We can apply specialization multiple times to refine a design. An entity set may also
be specialized by more than one distinguishing feature.
328. Which of the following is the specialization that permits multiplesets
a) Superclass specialization
b) Disjoint specialization
c) Overlapping specialization
d) None of the mentioned
Answer: c
Explanation: Overlapping specialization is the type of specialization that permits multiple sets. But
disjoint specialization does not permit multiple sets. Disjoint specialization permits at most one
set.
329. The similarities between the entity set can be expressed by whichof the following features?
a) Specialization
b) Generalization
c) Uniquation
d) Inheritance

Answer: b
Explanation: The similarities betweenthe entity set can be expressed by the generalization feature.
It is a containment o the relationship that exists between a higher level entity set and one or more
1000
lower level entity sets.

330. Higher level entity sets are designated by the term


a) Sub class
b) Super class
c) Parent class
d) Root class
Answer: b
Explanation: Higher level entity sets can also be designated by the term super class. In the similar
manner lower level entity sets can also be designated by the term sub class.
331. State true or false: The attributes of the higher level entity sets are inherited by the attributes
ofthe lower level entity sets
a) True
b) False
Answer: a
Explanation: The attributes of the higher level entity sets are inherited by the attributes of the
lower level entity sets. But the inverse is not truein this case.
332. Which of the following is not ageneralization constraint?
a) Condition-defined
b) User defined
c) Disjoint
d) Machine defined
Answer: d
Explanation: Machine definition is not a generalization constraint. Condition defined, user defined,
disjoint and overlapping are 4 generalization constraints.
333. Condition defined generalizationconstraint is also said to be
a) Attribute defined
b) Constraint defined
c) Value defined
d) Undefined
Answer: a
Explanation: Condition defined generalization constraint is also saidto be attribute defined.
334. Which of the following is not afeature of a good relational design?
a) Specifying primary keys
b) Specifying foreign keys
c) Preserving integrity constraints
d) Allowing redundancy of attributes
Answer: d
Explanation: Allowing redundancy of attributes makes it very difficult for data extraction. So, It is
not a good relational design feature.
335. The dependency rules specifiedby the database designer are known

1001
as
a) Designer dependencies
b) Database rules
c) Functional dependencies
d) None of the mentioned
Answer: c
Explanation: The dependency rules specified by the database designer are known as functional
dependencies. The normal forms arebased on functional dependencies.
a) Proper relation
b) Ideal relation
c) Perfect relation
d) Legal relation
Answer: d
Explanation: A relation that satisfies all the real world constraints is called as a legal relation. An
instance of a legal relation is called as a legal instance.
338. If K → R then K is said to be the
336. If the decomposition is unable to of R
represent certain important factsabout the relation, then such a decomposition is called as?
a) Lossless decomposition
b) Lossy decomposition
c) Insecure decomposition
d) Secure decomposition
Answer: b
Explanation: If the decomposition is unable to represent certain important facts about the relation,
then such a decomposition is called as lossy decomposition. Lossy decompositions should be
avoided asthey result in the loss of data.
337. An instance of a relation that satisfies all real world constraints isknown as?
a) Candidate key
b) Foreign key
c) Super key
d) Domain
Answer: c
Explanation: If K → R then k is said to be the superkey of R i.e. K uniquely identifies every tuple in
the relation R.
339. X → Y holds on a schema k(K) if?
a) At least one legal instance satisfiesthe functional dependency
b) No legal instance satisfies thefunctional dependency
c) Each and every legal instance satisfies the functional dependency
d) None of the mentioned

Answer: c
Explanation: X → Y holds on a schemak(K) if each and every legal instance satisfies the functional
dependency.
1002
Even if one instance does not satisfythe functional dependency X→ Y does not hold on a schema.
340. X→ Y is trivial if?
a) X⊂Y
b) Y⊂X
c) X⊇Y
d) None of the mentioned
Answer: a
Explanation: X→ Y is said to be trivialif X is a subset of Y. Thus X ⊂ Y implies X→Y is trivial.
341. Which of the following is not acondition for X→ Y in Boyce codd normal form?
a) X → Y is trivial
b) X is the superkey for the relationalschema R
c) Y is the superkey for the relationalschema R
d) All of the mentioned
Answer: c
Explanation: Y does not need to be a superkey of the relation for the given functional dependency
to satisfy BCNF. X→ Y must be trivial and X
must be the superkey of the relationR.
342. Which of the following is used toexpress database consistency?
a) Primary keys
b) Functional dependencies
c) Check clause
d) All of the mentioned

Answer: d
Explanation: Primary keys, Functional dependencies, Check clause are all used to express
database consistency.
343. introduces the Management Data Warehouse (MDW) to SQL Server Management Studio for
streamlined performancetroubleshooting.
a) SQL Server 2005
b) SQL Server 2008
c) SQL Server 2012
d) SQL Server 2014
Answer: b
Explanation: MDW is a set of components that enable a database developer or administrator to
quicklytrack down problems that could be causing performance degradation.

344. Point out the correct statement.


a) MDW consist of three components
b) SQL Server Express instances canbe targets
c) Setting up the MDW is a one-stepprocess
d) All of the mentioned
Answer: a
1003
Explanation: MDW consists of three components: Data Collector, MDW database and MDW
reports.
345. Which of the following mode allows for the collection and uploading of data to occur on
demand?
a) Non-cached mode
b) Cached mode
c) Mixed mode
d) All of the mentioned
Answer: a
Explanation: In non-cached mode,collection and upload are on the same schedule.
346. Which of the following scenariofavours cached mode?
a) Continuous collection of data
b) Less frequent uploads
c) Data collection and uploading ofjobs on different schedules
d) All of the mentioned

Answer: d
Explanation: Cached mode uses separate schedules for collection andupload.
347. Point out the wrong statement.
a) The Data Collection is performed primarily through SSIS packages thatcontrol the collection
frequency on the target
b) You should change the databasename after creation
c) Do not change any of the job specifications for the data collectionand upload jobs
d) None of the mentioned
Answer: b
Explanation: You should not change the database name after creation, because all of the jobs
created to manage the database collection refer to the database by the original name and will
generate errors if the name is changed.
348. Which of the following is thebest Practice and Caveat for Management Data Warehouse?
a) Use a centralized server for theMDW database

b) The XML parameters for a single T-SQL collection item can have multiple
<Query> elements
c) Use a distributed server for theMDW database
d) All of the mentioned
Answer: a
Explanation: Centralized server allows you to use a single point for viewing reports for multiple
instances.
349. stores information about how the management data warehouse reports should group and
aggregate performance counters.
a) core.snapshots_internalb)
1004
core.supported_collector_types_internal
c) core.wait_categoriesd)
core.performance_counter_report_gr oup_items
Answer: d
Explanation: core.wait_categories contains the categories used to group wait types according to
wait_type characteristic.
350. Which of the following table isused in the management data
warehouse schema that is requiredfor the Server Activity?
a) snapshots.query_stat
b) snapshots.os_latch_stats
c) snapshots.active_sessions
d) all of the mentioned
Answer: b Explanation:
snapshots.os_latch_stats is a Systemlevel resource table.
351. Which of the following is syntaxfor sp_add_collector_type procedure?
a) core.sp_add_collector [@collector_type_uid = ] ‘collector_type_uid’
b) core.sp_add_collector_type [@collector_type_uid = ].
c) core.sp_add_collector_type [@collector_type_uid = ]
‘collector_type_uid’
d) none of the mentioned

Answer: c Explanation:
core.sp_add_collector_type adds a new entry to the core.supported_collector_types view in the
management data warehouse database.

352. What does collector_type_id stands for in the following code snippet?
core.sp_remove_collector_type [ @collector_type_uid = ]
‘collector_type_uid’
a) uniqueidentifier
b) membership role
c) directory
d) none of the mentioned

Answer: a
Explanation: collector_type_uid is theGUID for the collector type.
353. Which of the following clusteringtype has characteristic shown in the below figure?

1005
a) Partitional
b) Hierarchical
c) Naive bayes
d) None of the mentioned
Answer: b
Explanation: Hierarchical clusteringgroups data over a variety of scales
by creating a cluster tree ordendrogram.
354. Point out the correct statement.
a) The choice of an appropriate metric will influence the shape of theclusters
b) Hierarchical clustering is also calledHCA
c) In general, the merges and splits are determined in a greedy manner
d) All of the mentioned
Answer: d
Explanation: Some elements may be close to one another according to one distance and farther
away according to another.
355. Which of the following is finallyproduced by Hierarchical Clustering?
a) final estimate of cluster centroids
b) tree showing how close things areto each other
c) assignment of each point toclusters
d) all of the mentioned
Answer: b
Explanation: Hierarchical clustering isan agglomerative approach.
356. Which of the following is required by K-means clustering?

a) defined distance metric


b) number of clusters
c) initial guess as to cluster centroids
d) all of the mentioned
Answer: d
Explanation: K-means clusteringfollows partitioning approach.
357. Point out the wrong statement.
a) k-means clustering is a method ofvector quantization
b) k-means clustering aims to partition n observations into kclusters
c) k-nearest neighbor is same as k-means
d) none of the mentioned
Answer: c
Explanation: k-nearest neighbor hasnothing to do with k-means.
358. Which of the followingcombination is incorrect?
a) Continuous – euclidean distance
b) Continuous – correlation similarity
c) Binary – manhattan distance
d) None of the mentioned
1006
Answer: d
Explanation: You should choose a distance/similarity that makes sensefor your problem.
359. Hierarchical clustering should beprimarily used for exploration.
a) True
b) False
Answer: a
Explanation: Hierarchical clustering isdeterministic.
360. Which of the following functionis used for k-means clustering?
a) k-means
b) k-mean
c) heatmap
d) none of the mentioned

Answer: a
Explanation: K-means requires anumber of clusters.
361. Which of the following clusteringrequires merging approach?
a) Partitional
b) Hierarchical
c) Naive Bayes
d) None of the mentioned
Answer: b
Explanation: Hierarchical clusteringrequires a defined distance as well.
362. K-means is not deterministic andit also consists of number of iterations.

a) True
b) False

Answer: a
Explanation: K-means clustering produces the final estimate of clustercentroids.
363. Which of the following term isappropriate to the below figure?

a) Large Data
b) Big Data
c) Dark Data
d) None of the mentioned
Answer: b
Explanation: Big data is a broad term for data sets so large or complex that traditional data
processing applications are inadequate.
364. Point out the correct statement.
1007
a) Machine learning focuses on prediction, based on known properties learned from the
trainingdata
b) Data Cleaning focuses on prediction, based on known properties learned from the training
data
c) Representing data in a form which both mere mortals can understand and get valuable
insights is as much ascience as much as it is art
d) None of the mentioned
Answer: d
Explanation: Visualization is becoming a very important aspect.
365. Which of the following characteristic of big data is relatively more concerned to data
science?
a) Velocity
b) Variety
c) Volume
d) None of the mentioned

Answer: b
Explanation: Big data enables organizations to store, manage, and manipulate vast amounts of
disparatedata at the right speed and at the right time.
366. Which of the following analytical capabilities are provided by information management
company?
a) Stream Computing
b) Content Management
c) Information Integration
d) All of the mentioned

Answer: d
Explanation: With stream computing,store less, analyze more and make better decisions faster.
367. Point out the wrong statement.
a) The big volume indeed representsBig Data
b) The data growth and social media explosion have changed how we lookat the data
c) Big Data is just about lots of data
d) All of the mentioned
Answer: c
Explanation: Big Data is actually a concept providing an opportunity to find new insight into your
existing data as well guidelines to capture andanalysis your future data.
368. Which of the following step isperformed by data scientist after acquiring the data?
a) Data Cleansing
b) Data Integration
c) Data Replication
d) All of the mentioned
Answer: a
1008
Explanation: Data cleansing, data cleaning or data scrubbing is the process of detecting and
correcting(or removing) corrupt or inaccurate
records from a record set, table, ordatabase.
369. 3V’s are not sufficient todescribe big data.
a) True
b) False

Answer: a
Explanation: IBM data scientists break big data into four dimensions: volume, variety, velocity and
veracity.
370: Which of the following appliedon warehouse?
a) write only
b) read only

c) both a & b
d) none of theseAnswer:B

371: Data can be store , retrive andupdated in …


a) SMTOP
b) OLTP

c) FTP
d) OLAP Answer:B

372: Which of the following is a goodalternative to the star schema?


a) snow flake schema
b) star schema

c) star snow flake schema


d) fact constellationAnswer :D

373: Patterns that can be discoveredfrom a given database are which type…
a) More than one type
b) Multiple type always
c) One type only
d) No specific typeAnswer :A

374:Background knowledge is…


a) It is a form of automatic learning.

b) A neural network that makes useof a hidden layer


c) The additional acquaintance usedby a learning algorithm to facilitate the learning process
d) None of these
1009
Answer:C

375: Which of the following is true forClassification?


a) A subdivision of a set

b) A measure of the accuracy


c) The task of assigning aclassification
d) All of theseAnswer:A

376: Data mining is?


a) time variant non-volatile collectionof data
b) The actual discovery phase of aknowledge
c) The stage of selecting the rightdata
d) None of theseAnswer -:B

377: ——- is not a data miningfunctionality?


A) Clustering and Analysis

B) Selection and interpretation


C) Classification and regression

D) Characterization andDiscrimination
Answer -:B
378: Which of the following can alsoapplied to other forms?
a) Data streams & Sequence data
b) Networked data
c) Text & Spatial data
d) All of theseAnswer -:D

379:Which of the following is generalcharacteristics or features of a targetclass of data?


a) Data selection
b) Data discrimination
c) Data Classification
c) Data CharacterizationAnswer -:D

380: ——– is the out put of KDD…


a) Query

b) Useful Information
c) Data
d) informationAnswer -:B

381: What is noise?

a) component of a network
1010
b) context of KDD and data mining

c) aspects of a data warehouse

d) None of theseAnswer -:B

382. Firms that are engaged in sentiment mining are analyzing datacollected from?
A. social media sites.
B. in-depth interviews.
C. focus groups.
D. experiments.
E. observations.
Answer -:A. social media sites.

Which of the following forms of datamining assigns records to one of a predefined set of classes?
(A). Classification(B). Clustering (C). Both A and B

(D). None

Answer -:(B). Clustering

383. What is the adaptive systemmanagement?


a) machine language techniques
b) machine learning techniques
c) machine procedures techniques
d) none of theseAnswer -:B

384. An essential process used for applying intelligent methods to extract the data patterns is
named as

a) data mining
b) data analysis
c) data implementation
d) data computationAnswer -:A
385. Classification and regression arethe properties of…
a) data analysis
b) data manipulation’
c) data mining
d) none of these
Answer -:C

386. A class of learning algorithm thattries to find an optimum classificationof a set of examples
using the probabilistic theory is named as …
a) Bayesian classifiers
1011
b) Dijkstra classifiers
c) doppler classifiers

d) all of theseAnswer -:A

387. Which of the following can beused for finding deep knowledge?
a) stacks

b) algorithms
c) clues

d) none of theseAnswer -:C

388. We define a as a subdivison of a set of examples intoa number of classes.


a) kingdom

b) tree
c) classification

d) array Answer -:C

389. Group of similar objects that differ significantly from other objectsis named as …
a) classification
b) cluster

c) community
d) none of theseAnswer -:B

390. Combining different type ofmethods or information is ….


a) analysis
b) computation

c) stack

d) hybrid Answer -:D

391. What i sthe name of database having a set of databases from different vendors, possibly
using different database paradigms?
a) homogeneous database
b) heterogeneous database
c) hybrid database

d) none of theseAnswer -:B

1012
392. What is the strategic value ofdata mining?
a) design sensitive

b) cost sensitive
c) technical sensitive

d) time sensitiveAnswer -:D

393. The amount of information with in data as opposed to the amount of redundancy or noise is
known as …
a) paragraph content

b) text content

c) information content
d) none of theseAnswer -:C

394. What is inductive learning?

a) learning by hypothesis
b) learning by analyzing

c) learning by generalizing

d) none of theseAnswer -:C

395: Which of the following appliedon warehouse?


a) write only
b) read only

c) both a & b
d) none of theseAnswer -:B

396: Data can be store , retrive andupdated in …


a) SMTOP

b) OLTP
c) FTP

d) OLAP Answer -:B

397: Which of the following is a goodalternative to the star schema?


a) snow flake schema

b) star schema

1013
c) star snow flake schema

d) fact constellation
Answer -:D

398: Patterns that can be discoveredfrom a given database are which type…
a) More than one type

b) Multiple type always


c) One type only

d) No specific typeAnswer -:A

399:Background knowledge is…


a) It is a form of automatic learning.

b) A neural network that makes useof a hidden layer


c) The additional acquaintance usedby a learning algorithm to facilitate the learning process
d) None of theseAnswer -:C

400: Which of the following is true forClassification?


a) A subdivision of a set

b) A measure of the accuracy

c) The task of assigning aclassification


d) All of theseAnswer -:A

401. As companies move past the experimental phase with Hadoop, many cite the need for
additionalcapabilities, including

a) Improved data storage andinformation retrieval


b) Improved extract, transform andload features for data integration
c) Improved data warehousingfunctionality
d) Improved security, workloadmanagement, and SQL support
Answer: d
Explanation: Adding security to Hadoop is challenging because all the interactions do not follow
the classic client-server pattern.
402. Point out the correct statement.
a) Hadoop do need specializedhardware to process the data
b) Hadoop 2.0 allows live streamprocessing of real-time data
c) In Hadoop programming framework output files are divided
into lines or records

1014
d) None of the mentioned

Answer: b
Explanation: Hadoop batch processes data distributed over a number of computers ranging in
100s and 1000s.
403. According to analysts, for what can traditional IT systems provide a foundation when they’re
integratedwith big data technologies like Hadoop?
a) Big data management and datamining
b) Data warehousing and businessintelligence
c) Management of Hadoop clusters
d) Collecting and storing unstructureddata
Answer: a
Explanation: Data warehousing integrated with Hadoop would give abetter understanding of data.
404. Hadoop is a framework that works with a variety of related tools.
Common cohorts include

a) MapReduce, Hive and HBase


b) MapReduce, MySQL and GoogleApps

c) MapReduce, Hummer and Iguana


d) MapReduce, Heron and Trumpet

Answer: a
Explanation: To use Hive with HBase you’ll typically want to launch two clusters, one to run HBase
and the other to run Hive.
405. Point out the wrong statement.
d) A sound Cutting’s laptop madeduring Hadoop development
Answer: c
Explanation: Doug Cutting, Hadoop creator, named the framework after his child’s stuffed toy
elephant.
407. All of the following accuratelydescribe Hadoop, EXCEPT
a) Hardtop processing capabilities are
huge and its real advantage lies in theability to process terabytes & petabytes of data
b) Hadoop uses a programming model called “MapReduce”, all theprograms should confirm to
this model in order to work on Hadoopplatform
c) The programming model, MapReduce, used by Hadoop isdifficult to write and test
d) All of the mentioned

Answer: c
Explanation: The programming model, MapReduce, used by Hadoopis simple to write and test.
406. What was Hadoop named after?
a) Creator Doug Cutting’s favoritecircus act
1015
b) Cutting’s high school rock band
c) The toy elephant of Cutting’s son
a) Open-source
b) Real-time
c) Java-based
d) Distributed computing approach

Answer: b
Explanation: Apache Hadoop is an open-source software framework for distributed storage and
distributed processing of Big Data on clusters of commodity hardware.
408. can best be described as a programming model used to develop Hadoop-based
applications that can process massiveamounts of data.
a) MapReduce
b) Mahout
c) Oozie
d) All of the mentioned

Answer: a
Explanation: MapReduce is a programming model and an associated implementation for
processing and generating large datasets with a parallel, distributed algorithm.
409. has the world’slargest Hadoop cluster.
a) Apple
b) Datamatics
c) Facebook
d) None of the mentioned
Answer: c
Explanation: Facebook has many Hadoop clusters, the largest among them is the one that is used
for Datawarehousing.
410. Facebook Tackles Big Data With
based on Hadoop.
a) ‘Project Prism’
b) ‘Prism’
c) ‘Project Big’
d) ‘Project Data’
Answer: a
Explanation: Prism automatically replicates and moves data wherever it’s needed across a vast
network ofcomputing facilities.
411. IBM and have announced a major initiative to use Hadoop to support university courses in
distributed computer programming.
a) Google Latitude
b) Android (operating system)
c) Google Variations
d) Google
1016
Answer: d
Explanation: Google and IBM Announce University Initiative toAddress Internet-Scale.
412. Point out the correct statement.
a) Hadoop is an ideal environment forextracting and transforming small volumes of data
b) Hadoop stores data in HDFS andsupports data compression/decompression
c) The Giraph framework is less useful than a MapReduce job to solve graph and machine
learning
d) None of the mentioned

Answer: b
Explanation: Data compression can be achieved using compression algorithms like bzip2, gzip,
LZO, [Link] algorithms can be used in

different scenarios based on theircapabilities.


413. What license is Hadoopdistributed under?
a) Apache License 2.0
b) Mozilla Public License
c) Shareware
d) Commercial

Answer: a
Explanation: Hadoop is Open Source,released under Apache 2 license.
414. Sun also has the Hadoop Live CD
project, which allows running a fully functional Hadoopcluster using a live CD.
a) [Link]
b) OpenSolaris
c) GNU
d) Linux

Answer: b
Explanation: The OpenSolaris HadoopLiveCD project built a bootable CD- ROM image.
415. Which of the following genresdoes Hadoop produce?
a) Distributed file system
b) JAX-RS
c) Java Message Service
d) Relational Database ManagementSystem
Answer: a
Explanation: The Hadoop Distributed File System (HDFS) is designed to store very large data sets
reliably, and to stream those data sets at highbandwidth to the user.
416. What was Hadoop written in?
a) Java (software platform)
b) Perl
1017
c) Java (programming language)
d) Lua (programming language)

Answer: c
Explanation: The Hadoop framework itself is mostly written in the Java programming language,
with some native code in C and command-line utilities written as shell-scripts.
417. A serves as the masterand there is only one NameNode per cluster.
a) Data Node
b) NameNode
c) Data block
d) Replication

Answer: b
Explanation: All the metadata relatedto HDFS including the information

about data nodes, files stored on HDFS, and Replication, etc. are stored and maintained on the
NameNode.
418. Point out the correct statement.
a) DataNode is the slave/worker nodeand holds the user data in the form ofData Blocks
b) Each incoming file is broken into32 MB by default
c) Data blocks are replicated across different nodes in the cluster to ensure a low degree of
fault tolerance
d) None of the mentioned

Answer: a
Explanation: There can be any number of DataNodes in a HadoopCluster.
419. HDFS works in a fashion.
a) master-worker
b) master-slave
c) worker/slave
d) all of the mentioned
Answer: a
Explanation: NameNode servers asthe master and each DataNode servers as a worker/slave
420. NameNode is used when the Primary NameNode goesdown.
a) Rack
b) Data
c) Secondary
d) None of the mentioned
Answer: c
Explanation: Secondary namenode isused for all time availability and reliability.
421. Point out the wrong statement.
a) Replication Factor can be configured at a cluster level (Default is set to 3) and also at a file
1018
level
b) Block Report from each DataNode contains a list of all the blocks that are stored on that
DataNode
c) User data is stored on the local filesystem of DataNodes
d) DataNode is aware of the files to which the blocks stored on it belongto

Answer: d
Explanation: NameNode is aware ofthe files to which the blocks stored on it belong to.
422. Which of the following scenariomay not be a good fit for HDFS?

a) HDFS is not suitable for scenariosrequiring multiple/simultaneous writes to the same file
b) HDFS is suitable for storing data related to applications requiring lowlatency data access
c) HDFS is suitable for storing data related to applications requiring lowlatency data access
d) None of the mentioned

Answer: a
Explanation: HDFS can be used for storing archive data since it is cheaper as HDFS allows storing
thedata on low cost commodity hardware while ensuring a high degree of fault-tolerance.
423. The need for data replicationcan arise in various scenarios like

a) Replication Factor is changed


b) DataNode goes down
c) Data Blocks get corrupted
d) All of the mentioned

Answer: d
Explanation: Data is replicated across different DataNodes to ensure a high degree of fault-
tolerance.
424. is the slave/worker node and holds the user data in the
form of Data Blocks.
a) DataNode
b) NameNode
c) Data block
d) Replication
Answer: a
Explanation: A DataNode stores data in the [HadoopFileSystem]. A functional filesystem has more
than one DataNode, with data replicated across them.
425. HDFS provides a command lineinterface called used tointeract with HDFS.
a) “HDFS Shell”
b) “FS Shell”
c) “DFS Shell”

1019
d) None of the mentioned
Answer: b
Explanation: The File System (FS) shell includes various shell-like commands that directly interact
withthe Hadoop Distributed File System (HDFS).
426. HDFS is implemented in
programminglanguage.
a) C++
b) Java

c) Scala
d) None of the mentioned

Answer: b
Explanation: HDFS is implemented in Java and any computer which can run Java can host a
NameNode/DataNodeon it.
427. For YARN, the Manager UI provides host and portinformation.
a) Data Node
b) NameNode
c) Resource
d) Replication

Answer: c
Explanation: All the metadata related to HDFS including the information about data nodes, files
stored on HDFS, and Replication, etc. are storedand maintained on the NameNode.
428. Which of the following is not aNoSQL database?
a) SQL Server
b) MongoDB
c) Cassandra
d) None of the mentioned

Answer: a
Explanation: Microsoft SQL Server is a
relational database managementsystem developed by Microsoft.
429. Point out the correct statement.
a) Documents can contain many different key-value pairs, or key-array pairs, or even nested
documents
b) MongoDB has official drivers for a variety of popular programming languages and
development environments
c) When compared to relational databases, NoSQL databases are more scalable and provide
superiorperformance
d) All of the mentioned

Answer: d
1020
Explanation: There are also a large number of unofficial or community- supported drivers for other
programming languages and frameworks.
430. Which of the following is aNoSQL Database Type?
a) SQL
b) Document databases
c) JSON
d) All of the mentioned

Answer: b
Explanation: Document databases

pair each key with a complex datastructure known as a document.


431. Which of the following is a wide-column store?
a) Cassandra
b) Riak
c) MongoDB
d) Redis

Answer: a
Explanation: Wide-column stores such as Cassandra and HBase are optimized for queries over
large datasets, and store columns of datatogether, instead of rows.

432. Point out the wrong statement.


a) Non-Relational databases requirethat schemas be defined before youcan add data
b) NoSQL databases are built to allowthe insertion of data without a predefined schema
c) NewSQL databases are built to allow the insertion of data without apredefined schema
d) All of the mentioned
Answer: a
Explanation: There’s also no way,using a relational database, to
effectively address data that’s
completely unstructured or unknownin advance.

1021
System software
System software is a type of computer program that is designed to run a computer’s hardware
and application programs. If we think of the computer system as a layered model, the system
software is the interface between the hardware and user applications. The operating system (OS)
is the best-known example of system software. The OS manages all the other programs in a
computer.

Other examples of system software include:


• The BIOS (basic input/output system) gets the computer system startedafter you turn it on and
manages the data flow between the operating system and attached devices such as the hard
disk, video adapter, keyboard, mouse and printer.
• The boot program loads the operating system into the computer's main memory or random-
access memory (RAM).
• An assembler takes basic computer instructions and converts them into a pattern of bits that
the computer's processor can use to perform its basicoperations.
• A device driver controls a particular type of device that is attached to your computer, such as a
keyboard or a mouse. The driver program converts the more general input/output instructions
of the operating system to messages that the device type can understand.

Additionally, system software can also include system utilities, such as the disk defragmenter and
System Restore, and development tools, such
as compilers and debuggers.

System software and application programs are the two main types of computer software. Unlike
system software, an application program (often just called an application or app) performs a
particular function for the user. Examples include browsers, email clients, word processors and
spreadsheets.

System Software is a set of programs that control and manage the operations of computer
hardware. It also helps application programs to execute correctly.

System Software are designed to control the operation and extend the processing functionalities
of a computer system. System software makes the operation of a computer more fast, effective,
and secure. Example: Operating system, programming language, Communication software, etc.

Types of System Software


Important types of System Software:
• Operating systems:- Operating system software helps you for the effective utilization of all
hardware and software components of a computer system.
• Programming language translators:- Transforms the instructions prepared by developers in a
programming language into a form that can be interpreted or compiled and executed by a
computer system.
• Communication Software : - Communication software allows us to transfer data and programs
from one computer system to another.
• Utility programs: - Utility programs are a set of programs that help users in system
maintenance tasks, and in performing tasks of routine nature.

Features of System Software


1022
An important feature of System Software are:
• System Software is closer to the system
• Generally written in a low-level language
• The system software is difficult to design and understand
• Fast in speed
• Less interactive
• Smaller in size
• Hard to manipulate

Machine language
Machine language, or machine code, is a low-level language comprised of binary digits (ones and
zeros). High-level languages, such as Swift and C++ must be compiled into machine language
before the code is run on a computer.

Since computers are digital devices, they only recognize binary data. Every program, video, image,
and character of text is represented in binary. This binary data, or machine code, is processed as
input by the CPU. The resulting output is sent to the operating system or an application, which
displays the data visually. For example, the ASCII value for the letter "A" is 01000001 in machine
code, but this data is displayed as "A" on the screen. An image may have thousands or even
millions of binary values that determine the color of each pixel.

While machine code is comprised of 1s and 0s, different processor architectures use different
machine code. For example, a PowerPC processor, which has a RISC architecture, requires
different code than an Intel x86 processor, which has a CISC architecture. A compiler must
compile high-level source code for the correct processor architecture in order for a program to run
correctly.

Assembly Language
Programming in Machine language is tedious (you have to program every command from scratch)
and hard to read & modify (the 1s and 0s are kind of hard to work with…). For these reasons,
Assembly language was developed as an alternative to Machine language.
Assembly Language uses short descriptive words (mnemonic) to represent each of the Machine
Language instructions.

For example, the mnemonic add means to add numbers together, and sub means to subtract the
numbers. So if you want to add the numbers 2 and 3 in assembly language, it would look like this:
add 2, 3, result So Assembly Languages were developed to make programming easier. However,
the computer cannot directly execute the assembly language. First another program called the
assembler is used to translate the Assembly Language into machine code.

Machine Language vs Assembly Language


Machine language and assembly language are both low-level languages, but machine code is
1023
below assembly in the hierarchy of computer languages.
Assembly language includes human-readable commands, such as mov, add, and sub, while
machine language does not contain any words or even letters. Some developers manually write
assembly language to optimize a program, but they do not write machine code. Only developers
who write software compilersneed to worry about machine language.

NOTE: While machine code is technically comprised of binary data, it may also be represented in
hexadecimal values. For example, the letter "Z," which is 01011010 in binary, may be displayed as
5A in hexadecimal code.

High Level Language


The high-level language is simple and easy to understand and it is similar to English language. For
example, COBOL, FORTRAN, BASIC, C, C+, Python, etc.
High-level languages are very important, as they help in developing complex software and they
have the following advantages −
• Unlike assembly language or machine language, users do not need to learn the high-level
language in order to work with it.
• High-level languages are similar to natural languages, therefore, easy tolearn and understand.
• High-level language is designed in such a way that it detects the errorsimmediately.
• High-level language is easy to maintain and it can be easily modified.
• High-level language makes development faster.
• High-level language is comparatively cheaper to develop.
• High-level language is easier to document.

Although a high-level language has many benefits, yet it also has a drawback. It has poor control
on machine/hardware.
The following table lists down the frequently used languages –

A high-level language is a programming language that uses English and mathematical symbols,
like +, -, % and many others, in its instructions. When using the term 'programming languages,'
most people are actually referring to high-level languages. High-level languages are the languages
most often used by programmers to write programs. Examples of high-level languages are C++,
Fortran, Java and Python.
1024
To get a flavor of what a high-level language actually looks like, consider an ATM machine where
someone wants to make a withdrawal of $100. This amount needs to be compared to the account
balance to make sure there are enough funds. The instruction in a high-level computer language
would look something like this:
x = 100
if balance x:
print 'Insufficient balance'else:
print 'Please take your money'
This is not exactly how real people communicate, but it is much easier to followthan a series of 1s
and 0s in binary code.

There are a number of advantages to high-level languages. The first advantage is that high-level
languages are much closer to the logic of a human language. A high-level language uses a set of
rules that dictate how words and symbols can beput together to form a program. Learning a high-
level language is not unlike learning another human language - you need to learn vocabulary and
grammar so you can make sentences. To learn a programming language, you need to learn
commands, syntax and logic, which correspond closely to vocabulary and grammar.

The second advantage is that the code of most high-level languages is portable and the same
code can run on different hardware. Both machine code and assembly languages are hardware
specific and not portable. This means that the machine code used to run a program on one
specific computer needs to be modified to run on another computer. Portable code in a high-level
language can run on multiple computer systems without modification. However, modifications to
code in high-level languages may be necessary because of the operating system. For example,
programs written for Windows typically don't run on a Mac.

A high-level language cannot be understood directly by a computer, and it needs to be translated


into machine code. There are two ways to do this, and they are related to how the program is
executed: a high-level language can be compiled orinterpreted.

Types of Programming Languages


• Data-oriented Language: These programming languages are designed for searching and
manipulating relation that have been described as entity relationship tables which map one set
of things into other sets. Example: SQL
• Imperative Language: ?
• Object-oriented programming (OOP) support objects defined by their class.
• Focuses on objects over action, data over logic.

Compiler
A compiler is a computer program that transforms code written in a high-level programming
language into the machine code. It is a program which translates the human-readable code to a
language a computer processor understands (binary 1 and 0 bits). The computer processes the
machine code to perform thecorresponding tasks.
A compiler should comply with the syntax rule of that programming language in which it is written.
However, the compiler is only a program and cannot fix errors found in that program. So, if you
make a mistake, you need to make changes in the syntax of your program. Otherwise, it will not
compile.
1025
Interpreter
An interpreter is a computer program, which coverts each high-level program statement into the
machine code. This includes source code, pre-compiled code, and scripts. Both compiler and
interpreters do the same job which is converting higher level programming language to machine
code. However, a compiler will convert the code into machine code (create an exe) before
program run.
Interpreters convert code into machine code when the program is run.

Difference Between Compiler and Interpreter

Basis of
Compiler Interpreter
difference
• Create the program.
• Compile will parse oranalyses
all of the language statements
for its correctness. Ifincorrect, • Create the Program
throws an error • No linking of files or machinecode
Programming
• If no error, the compiler will generation
Steps
convertsource code to • Source statements executed line by line
machine code. DURING Execution
• It links different code files into
a runnable program(know as
exe)

1026
Basis of
Compiler Interpreter
difference

• Run the Program

The program code is already


translated into machine code.
Interpreters are easier to use,especially for
Thus, it code executiontime is
Advantage beginners.
less.

You can't change the program


Interpreted programs can run oncomputers
without going backto the source
Disadvantage that have the corresponding interpreter.
code.

Store machine language as


Machine code Not saving machine code at all.
machine code on the disk

Running time Compiled code run faster Interpreted code run slower

It is based on language
Model translationlinking-loadingmodel. It is based on Interpretation Method.

Generates output program(in the


Do not generate output program. Sothey
form of exe) which can be run
Program evaluate the source program atevery time
independently from the original
generation during execution.
program.

Program execution is separate


from the compilation. It
Program Execution is a part ofInterpretation
performed only after the entire
Execution process, so it isperformed line by line.
outputprogram is compiled.

Memory Target program execute


independently and The interpreter exists in the memory

1027
Basis of
Compiler Interpreter
difference

do not require the compilerin the


requirement during interpretation.
memory.

For web environments, where load times are


Bounded to the specific target
important. Due to all the exhaustive analysis
machine and cannotbe ported. C
is done, compilestake relatively larger time to
and C++ are amost popular a
compileeven small code that may not be run
programming language which
Best suited for multiple times. In such cases, interpreters
uses compilation model.
are better.

The compiler sees the entirecode


upfront. Hence, they perform lots
Interpreters see code line by line, andthus
Code of optimizations that make code
optimizations are not as robust as compilers
Optimization run faster

Difficult to implement as
Interpreted languages supportDynamic
DynamicTyping compilers cannot predict what
Typing
happens at turn time.

It is best suited for the Production It is best suited for the program and
Usage
Environment developmentenvironment.

Compiler displays all errors and


The interpreter reads a single statement and
warning at the compilation time.
shows the error if [Link] must correct the
Therefore,you can't run the
Error execution error to interpret next line.
program without fixing errors

Input It takes an entire program It takes a single line of code.

1028
Basis of
Compiler Interpreter
difference

Output Compliers generates intermediate Interpreter never generate any intermediate


machnie code. machnie code.

Display all errors after, Displays all errors of each line one byone.
Errors compilation, all at the sametime.

Pertaining C,C++,C#, Scala, Java all use


Programming complier. PHP, Perl, Ruby uses an interpreter.
languages

Role of Compiler
• Compliers reads the source code, outputs executable code
• Translates software written in a higher-level language into instructions that computer can
understand. It converts the text that a programmer writes into a format the CPU can
understand.
• The process of compilation is relatively complicated. It spends a lot of time analyzing and
processing the program.
• The executable result is some form of machine-specific binary code.

Role of Interpreter
• The interpreter converts the source code line-by-line during RUN Time.
• Interpret completely translates a program written in a high-level languageinto machine level
language.
• Interpreter allows evaluation and modification of the program while it isexecuting.
• Relatively less time spent for analyzing and processing the program
• Program execution is relatively slow compared to compiler

HIGH-LEVEL LANGUAGES
High-level languages, like C, C++, JAVA, etc., are very near to English. It makes programming
process easy. However, it must be translated into machine language before execution. This
translation process is either conducted by either a compileror an interpreter. Also known as source
code.

MACHINE CODE
Machine languages are very close to the hardware. Every computer has its machine language. A
machine language programs are made up of series of binarypattern. (Eg. 110110) It represents the
1029
simple operations which should be performed by the computer. Machine language programs are
executable so that they can be run directly.

OBJECT CODE
On compilation of source code, the machine code generated for different processors like Intel,
AMD, an ARM is different. tTo make code portable, the source code is first converted to Object
Code. It is an intermediary code (similar to machine code) that no processor will understand. At
run time, the object code is converted to the machine code of the underlying platform.

Java is both Compiled and Interpreted.


To exploit relative advantages of compilers are interpreters some programming language like Java
are both compiled and interpreted. The Java code itself is compiled into Object Code. At run time,
the JVM interprets the Object code intomachine code of the target computer.

Linking and Loading


Linking and Loading are the utility programs that play a important role in the execution of a
program. Linking intakes the object codes generated by the assembler and combines them to
generate the executable module. On the other hand, the loading loads this executable module to
the main memory for execution.

Loading:
Bringing the program from secondary memory to main memory is called Loading.

Linking:
Establishing the linking between all the modules or all the functions of the program in order to
continue the program execution is called linking.

Linker is a program in a system which helps to link a object modules of program into a single
object file. It performs the process of linking. Linker are also called link editors. Linking is process
of collecting and maintaining piece of code and data into a single file. Linker also link a particular
module into system library. It takes object modules from assembler as input and forms an
executable file as output for loader.
Linking is performed at both compile time, when the source code is translated into machine code
and load time, when the program is loaded into memory by the loader. Linking is performed at the
last step in compiling a program.
Source code -> compiler -> Assembler -> Object code -> Linker -> Executable file ->Loader
Linking is of two types:

1030
1. Static Linking –
It is performed during the compilation of source program. Linking is performed before
execution in static linking. It takes collection of relocatable object file and command-line
argument and generate fully linked object file that can be loaded and run.
Static linker perform two major task:
• Symbol resolution – It associates each symbol reference with exactly one symbol definition
.Every symbol have predefined task.
• Relocation – It relocate code and data section and modify symbol references to the relocated
memory location.
The linker copy all library routines used in the program into executable image. As a result, it
require more memory space. As it does not require the presence of library on the system when
it is run . so, it is faster and more portable. No failurechance and less error chance.

2. Dynamic linking – Dynamic linking is performed during the run time. This linking is
accomplished by placing the name of a shareable library in the executable image. There is
more chances of error and failure chances. It require less memory space as multiple program
can share a single copy of the library.
Here we can perform code sharing. it means we are using a same object a number of times in
the program. Instead of linking same object again and again into the library, each module
share information of a object with other module having same object. The shared library
needed in the linking is stored in virtual memory to save RAM. In this linking we can also
relocate the code for the smooth running of code but all the code is not [Link] fixes the
address at run time.

Differences between Linking and Loading:


1. The key difference between linking and loading is that the linking generates the executable file
of a program whereas, the loading loads the executable file obtained from the linking into main
memory for execution.
2. The linking intakes the object module of a program generated by the assembler. However, the
loading intakes the executable module generatedby the linking.
3. The linking combines all object modules of a program to generate executable modules it also
links the library function in the object module to built-in libraries of the high-level programming
language. On the other hand, loading allocates space to an executable module in main
memory.

Loading and Linking are further categorized into 2 types:

STATIC DYNAMIC

Loading the entire program into the main


memory before start of the program Loading the program into the mainmemory on
execution is called asstatic loading. demand is called as dynamic loading.

1031
Inefficent utilization of memory because
whether it is required ornot required entire
program is brought into the main memory.
Efficent utilization of memory.

Program execution will be faster. Program execution will be slower.

Statically linked program takes constant


load time every time it isloaded into the
Dynamic linking is performed at runtime by the
memory for execution.
operating system.

If the static loading is used thenaccordingly


static linking is If the dynamic loading is used then

STATIC DYNAMIC

applied. accordingly dynamic linking is applied.

In dynamic linking this is not the case and individual


Static linking is performed by programs
shared modules can beupdated and [Link]
called linkers as the laststep in compiling a
is one ofthe greatest advantages dynamic linking
program.
offers.
Linkers are also called link editors.

In static linking if any of the external


programs has changed then they have to be
recompiledand re-linked again else the
changes won’t reflect in existing In dynamic linking load time might be
executable file. reduced if the shared library code isalready present
in memory.

Macros

1032
Writing a macro is another way of ensuring modular programming in assemblylanguage.
• A macro is a sequence of instructions, assigned by a name and could beused anywhere
in the program.
• In NASM, macros are defined with %macro and %endmacro directives.
• The macro begins with the %macro directive and ends with the %endmacrodirective.
The Syntax for macro definition −
%macro macro_name number_of_params
<macro body>
%endmacro

Where, number_of_params specifies the number parameters, macro_name specifies the name of
the macro.
The macro is invoked by using the macro name along with the necessary parameters. When you
need to use some sequence of instructions many times in a program, you can put those
instructions in a macro and use it instead of writingthe instructions all the time.
For example, a very common need for programs is to write a string of characters in the screen.
For displaying a string of characters, you need the following sequence of instructions −

mov edx,len ;message length


mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel

In the above example of displaying a character string, the registers EAX, EBX, ECX and EDX have
been used by the INT 80H function call. So, each time you need to display on screen, you need to
save these registers on the stack, invoke INT 80H and then restore the original value of the
registers from the stack. So, it could be useful to write two macros for saving and restoring data.
We have observed that, some instructions like IMUL, IDIV, INT, etc., need some of the information
to be stored in some particular registers and even return values in some specific register(s). If the
program was already using those registers for keeping important data, then the existing data from
these registers should be saved in the stack and restored after the instruction is executed.

Example
Following example shows defining and using macros −

; A macro with two parameters


; Implements the write system call
%macro write_string 2
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2

1033
int 80h
%endmacro

section .text
global _start ;must be declared for using gcc

_start: ;tell linker entry point


write_string msg1, len1
write_string msg2, len2
write_string msg3, len3

mov eax,1 ;system call number (sys_exit)


int 0x80 ;call kernel

section .data
msg1 db 'Hello, programmers!',0xA,0xD
len1 equ $ - msg1

msg2 db 'Welcome to the world of,', 0xA,0xD


len2 equ $- msg2

msg3 db 'Linux assembly programming! '


len3 equ $- msg3

When the above code is compiled and executed, it produces the following result
Hello, programmers! Welcome to the world of, Linux assembly programming!

Debugger
A debugger is a software program used to test and find bugs (errors) in otherprograms.
A debugger is also known as a debugging tool.
A debugger is a computer program used by programmers to test and debug a target program.
Debuggers may use instruction-set simulators, rather than running a program directly on the
processor to achieve a higher level of control over its execution. This allows debuggers to stop or
halt the program according tospecific conditions. However, use of simulators decreases execution
speed.

When a program crashes, debuggers show the position of the error in the target program. Most
debuggers also are capable of running programs in a step-by-step mode, besides stopping on
specific points. They also can often modify the state ofprograms while they are running.

Even the most experienced software programmers usually don't get it right on their first try.
Certain errors, often called bugs, can occur in programs, causing them to not function as the
1034
programmer expected. Sometimes these errors are easy to fix, while some bugs are very difficult
to trace. This is especially true forlarge programs that consist of several thousand lines of code.
Fortunately, there are programs called debuggers that help software developers find and eliminate
bugs while they are writing programs. A debugger tells the programmer what types of errors it
finds and often marks the exact lines of code where the bugs are found. Debuggers also allow
programmers to run a program step by step so that they can determine exactly when and why a
program crashes. Advanced debuggers provide detailed information about threads and memory
being used by the program during each step of execution. You could say a powerful debugger
program is like OFF! with 100% deet.

Operating System
An operating system (OS) is a collection of software that manages computer hardware resources
and provides common services for computer programs. Theoperating system is a vital component
of the system software in a computer system. This tutorial will take you through step by step
approach while learning Operating System concepts.

An Operating System (OS) is an interface between a computer user and computer hardware. An
operating system is a software which performs all the basic tasks like file management, memory
management, process management, handling input and output, and controlling peripheral devices
such as disk drives and printers.

Some popular Operating Systems include Linux Operating System, Windows Operating System,
VMS, OS/400, AIX, z/OS, etc.

Definition
An operating system is a program that acts as an interface between the user and the computer
hardware and controls the execution of all kinds of programs.

Why to Learn Operating System?


An Operating System (OS) is an interface between a computer user and computer hardware. An
1035
operating system is a software which performs all the basic tasks like file management, memory
management, process management, handling input and output, and controlling peripheral devices
such as disk drives and printers.

Some popular Operating Systems include Linux Operating System, Windows Operating System,
VMS, OS/400, AIX, z/OS, etc.
Following are some of important functions of an operating System.
• Memory Management
• Processor Management
• Device Management
• File Management
• Security
• Control over system performance
• Job accounting
• Error detecting aids
• Coordination between other software and users

Applications of Operating System


Following are some of the important activities that an Operating System performs
• Security − By means of password and similar other techniques, it prevents unauthorized
access to programs and data.
• Control over system performance − Recording delays between request for a service and
response from the system.
• Job accounting − Keeping track of time and resources used by various jobsand users.
• Error detecting aids − Production of dumps, traces, error messages, and other debugging
and error detecting aids.
• Coordination between other softwares and users − Coordination and assignment of
compilers, interpreters, assemblers and other software tothe various users of the computer
systems.

Operating System Structure


An operating system is a construct that allows the user application programs to interact with the
system hardware. Since the operating system is such a complex structure, it should be created
with utmost care so it can be used and modified easily. An easy way to do this is to create the
operating system in parts. Each of these parts should be well defined with clear inputs, outputs
and functions.

Simple Structure
There are many operating systems that have a rather simple structure. These started as small
systems and rapidly expanded much further than their scope. A common example of this is MS-
DOS. It was designed simply for a niche amount for people. There was no indication that it would
become so popular.

An image to illustrate the structure of MS-DOS is as follows −

1036
It is better that operating systems have a modular structure, unlike MS-DOS. That would lead to
greater control over the computer system and its various applications. The modular structure
would also allow the programmers to hide information as required and implement internal
routines as they see fit without changing the outer specifications.

Layered Structure
One way to achieve modularity in the operating system is the layered approach. In this, the bottom
layer is the hardware and the topmost layer is the user interface.

An image demonstrating the layered approach is as follows –

As seen from the image, each upper layer is built on the bottom layer. All the layers hide some
structures, operations etc from their upper layers.
One problem with the layered structure is that each layer needs to be carefully defined. This is
necessary because the upper layers can only use the functionalities of the layers below them.

Operating System Services


Operating system services are responsible for the management of platform resources, including
1037
the processor, memory, files, and input and output. They generally shield applications from the
implementation details of the [Link] system services include:
• Kernel operations provide low-level services necessary to:
• create and manage processes and threads of execution
• execute programs
• define and communicate asynchronous events
• define and process system clock operations
• implement security features
• manage files and directories, and
• control input/output processing to and from peripheral devices.
• Some kernel services have analogues described in the paragraph on Object Services, such as
concurrency control services.

• Command interpreter and utility services include mechanisms for services at the operator
level, such as:
• comparing, printing, and displaying file contents
• editing files
• searching patterns
• evaluating expressions
• logging messages
• moving files between directories
• sorting data
• executing command scripts
• local print spooling
• scheduling signal execution processes, and
• accessing environment information.

• Batch processing services support the capability to queue work (jobs) and manage the
sequencing of processing based on job control commands and lists of data. These services
also include support for the management of the output of batch processing, which frequently
includes updated files or databases and information products such as printed reports or
electronic documents. Batch processing is performed asynchronously from the user requesting
the job.

• File and directory synchronization services allow local and remote copies of files and
directories to be made identical. Synchronization services are usually used to update files after
periods of off line working on a portablesystem.

Operating System Operations


An operating system is a construct that allows the user application programs to interact with the
system hardware. Operating system by itself does not provide any function but it provides an
atmosphere in which different applications and programs can do useful work.
The major operations of the operating system are process management, memory management,

1038
device management and file management. These are given in detailas follows:

Process Management
The operating system is responsible for managing the processes i.e assigning the processor to a
process at a time. This is known as process scheduling. The different algorithms used for process
scheduling are FCFS (first come first served), SJF (shortest job first), priority scheduling, round
robin scheduling etc.
There are many scheduling queues that are used to handle processes in process management.
When the processes enter the system, they are put into the job queue. The processes that are
ready to execute in the main memory are kept in the ready queue. The processes that are waiting
for the I/O device are kept in thedevice queue.

Memory Management
Memory management plays an important part in operating system. It deals with memory and the
moving of processes from disk to primary memory for executionand back again.
The activities performed by the operating system for memory management are −
• The operating system assigns memory to the processes as required. Thiscan be done using
best fit, first fit and worst fit algorithms.
• All the memory is tracked by the operating system i.e. it nodes what memory parts are in
use by the processes and which are empty.
• The operating system deallocated memory from processes as required. This may happen
when a process has been terminated or if it no longer needs the memory.

Device Management
There are many I/O devices handled by the operating system such as mouse, keyboard, disk drive
etc. There are different device drivers that can be connected to the operating system to handle a
specific device. The device controller is an interface between the device and the device driver. The
user applications can access all the I/O devices using the device drivers, which are device specific
codes.

File Management
Files are used to provide a uniform view of data storage by the operating system. All the files are
mapped onto physical devices that are usually non volatile so data is safe in the case of system
1039
failure.
The files can be accessed by the system in two ways i.e. sequential access anddirect access −
• Sequential Access
• The information in a file is processed in order using sequential access. The files records are
accessed on after another. Most of the file systems such as editors, compilers etc. use
sequential access.
• Direct Access
• In direct access or relative access, the files can be accessed in random for read and write
operations. The direct access model is based on the disk model of a file,since it allows random
accesses.

System Calls
In computing, a system call is the programmatic way in which a computer program requests a
service from the kernel of the operating system it is executed on. A system call is a way for
programs to interact with the operating system. A computer program makes a system call when
it makes a request to the operating system’s kernel. System call provides the services of the
operating system to the user programs via Application Program Interface(API). It provides an
interface between a process and operating system to allow user-level processes to request
services of the operating system. System calls are the only entry points into the kernel system. All
programs needing resources must use system calls.

Services Provided by System Calls :


1. Process creation and management
2. Main memory management
3. File Access, Directory and File system management
4. Device handling(I/O)
5. Protection
6. Networking, etc.

Types of System Calls : There are 5 different categories of system calls –


1. Process control: end, abort, create, terminate, allocate and freememory.
2. File management: create, open, close, delete, read file etc.
3. Device management
4. Information maintenance
5. Communication

Examples of Windows and Unix System Calls –

WINDOWS UNIX

fork()
CreateProcess() ExitProcess()
exit()
WaitForSingleObject()
Process Control wait()

1040
open()
CreateFile()ReadFile() WriteFile()
read()
CloseHandle()
write()close()
File Manipulation

SetConsoleMode()ReadConsole() ioctl() read()


WriteConsole() write()
Device Manipulation

GetCurrentProcessID() SetTimer() getpid()alarm()


Information Maintenance Sleep() sleep()

pipe()
CreatePipe() CreateFileMapping()
shmget()
MapViewOfFile()
Communication mmap()

SetFileSecurity() chmod()
InitlializeSecurityDescriptor() umask()
Protection SetSecurityDescriptorGroup() chown()

Operating System Design and Implementation


An operating system is a construct that allows the user application programs to interact with the
system hardware. Operating system by itself does not provide any function but it provides an
atmosphere in which different applications and programs can do useful work.
There are many problems that can occur while designing and implementing anoperating system.

1041
These are covered in operating system design and implementation.

Operating System Design Goals


It is quite complicated to define all the goals and specifications of the operating system while
designing [Link] design changes depending on the type of the operating system i.e if it is batch
system, time shared system, single user system,multi user system, distributed system etc.
There are basically two types of goals while designing an operating system. Theseare –

User Goals
The operating system should be convenient, easy to use, reliable, safe and fast according to the
users. However, these specifications are not very useful as thereis no set method to achieve these
goals.

System Goals
The operating system should be easy to design, implement and maintain. These are
specifications required by those who create, maintain and operate the operating system. But there
is not specific method to achieve these goals as well.

Operating System Mechanisms and Policies


There is no specific way to design an operating system as it is a highly creative task. However,
there are general software principles that are applicable to all operating systems.
A subtle difference between mechanism and policy is that mechanism shows howto do something
and policy shows what to do. Policies may change over time and this would lead to changes in
mechanism. So, it is better to have a general mechanism that would require few changes even
when a policy change occurs.

For example - If the mechanism and policy are independent, then few changes are required in
mechanism if policy changes. If a policy favours I/O intensive processes over CPU intensive
processes, then a policy change to preference of CPU intensive processes will not change the
mechanism.

Operating System Implementation


The operating system needs to be implemented after it is designed. Earlier they were written in
assembly language but now higher level languages are used. The first system not written in
assembly language was the Master Control Program (MCP) for Burroughs Computers.

1042
Advantages of Higher Level Language
There are multiple advantages to implementing an operating system using a higher level language
such as: the code is written more fast, it is compact and alsoeasier to debug and understand. Also,
the operating system can be easily moved from one hardware to another if it is written in a high
level language.

Disadvantages of Higher Level Language


Using high level language for implementing an operating system leads to a loss in speed and
increase in storage requirements. However in modern systems only a small amount of code is
needed for high performance, such as the CPU scheduler and memory manager. Also, the
bottleneck routines in the system can be replaced by assembly language equivalents if required.

System Boot
The BIOS, operating system and hardware components of a computer system should all be
working correctly for it to boot. If any of these elements fail, it leadsto a failed boot sequence.
Booting the system is done by loading the kernel into main memory, and startingits execution.
The CPU is given a reset event, and the instruction register is loaded with a predefined memory
location, where execution starts.
• The initial bootstrap program is found in the BIOS read-only memory.
• This program can run diagnostics, initialize all components of the system, loads and starts
the Operating System loader. (Called bootstrapping)
• The loader program loads and starts the operating system.
• When the Operating system starts, it sets up needed data structuresin memory, sets several
registers in the CPU, and then creates and starts the first user level program. From this
point, the operating system only runs in response to interrupts.

System Boot Process


The following diagram demonstrates the steps involved in a system boot process

Here are the steps −


• The CPU initializes itself after the power in the computer is first turned on. This is done by
triggering a series of clock ticks that are generated by the system clock.
1043
• After this, the CPU looks for the system’s ROM BIOS to obtain the first instruction in the
start-up program. This first instruction is stored in the ROM BIOS and it instructs the
system to run POST (Power On Self Test) in amemory address that is predetermined.
• POST first checks the BIOS chip and then the CMOS RAM. If there is no battery failure
detected by POST, then it continues to initialize the CPU.
• POST also checks the hardware devices, secondary storage devices such as hard drives,
ports etc. And other hardware devices such as the mouse and keyboard. This is done to
make sure they are working properly.
• After POST makes sure that all the components are working properly, thenthe BIOS finds an
operating system to load.
• In most computer system’s, the operating system loads from the C driveonto the hard drive.
The CMOS chip typically tells the BIOS where the operating system is found.
• The order of the different drives that CMOS looks at while finding the operating system is
known as the boot sequence. This sequence can bechanged by changing the CMOS setup.
• After finding the appropriate boot drive, the BIOS first finds the boot record which tells it to
find the beginning of the operating system.
• After the initialization of the operating system, the BIOS copies the files into the memory.
Then the operating system controls the boot process.
• In the end, the operating system does a final inventory of the system memory and loads the
device drivers needed to control the peripheraldevices.
• The users can access the system applications to perform various tasks.

Without the system boot process, the computer users would have to download all the software
components, including the ones not frequently required. With the system boot, only those
software components need to be downloaded that are legitimately required and all extraneous
components are not required. This process frees up a lot of space in the memory and
consequently saves a lot of time.

Process
A process is basically a program in execution. The execution of a process must progress in a
sequential fashion.
A process is defined as an entity which represents the basic unit of work to be implemented in the
system.
To put it in simple terms, we write our computer programs in a text file and when we execute this
program, it becomes a process which performs all the tasks mentioned in the program.
When a program is loaded into the memory and it becomes a process, it can be divided into four
sections ─ stack, heap, text and data. The following image shows a simplified layout of a process
inside main memory −

1044
S.N. Component & Description

Stack
1
The process Stack contains the temporary data such as method/functionparameters,
return address and local variables.

Heap
2
This is dynamically allocated memory to a process during its run time.

Text
3
This includes the current activity represented by the value of ProgramCounter and the
contents of the processor's registers.

1045
Data
4
This section contains the global and static variables.

Program
A program is a piece of code which may be a single line or millions of lines. Acomputer program is
usually written by a computer programmer in a programming language. For example, here is a
simple program written in C programming language −

#include <stdio.h>

int main() {

printf("Hello, World! \n");

return 0;

A computer program is a collection of instructions that performs a specific task when executed by
a computer. When we compare a program with a process, we can conclude that a process is a
dynamic instance of a computer program.
A part of a computer program that performs a well-defined task is known as
an algorithm. A collection of computer programs, libraries and related data are referred to as a
software.
Process Life Cycle

When a process executes, it passes through different states. These stages may differ in different
operating systems, and the names of these states are also notstandardized.
In general, a process can have one of the following five states at a time.

S.N. State & Description

1 Start
This is the initial state when a process is first started/created.

1046
2 Ready

The process is waiting to be assigned to a processor. Ready processes are


waiting to have the processor allocated to them by the operating system so that
they can run. Process may come into this state after Start state orwhile running
it by but interrupted by the scheduler to assign CPU to some other process.

3 Running

Once the process has been assigned to a processor by the OS scheduler, the
process state is set to running and the processor executes its instructions.

4 Waiting
Process moves into the waiting state if it needs to wait for a resource, such as
waiting for user input, or waiting for a file to become available.

5 Terminated or Exit
Once the process finishes its execution, or it is terminated by the operating
system, it is moved to the terminated state where it waits to be removed from
main memory.

Process Control Block (PCB)


A Process Control Block is a data structure maintained by the Operating System for every
1047
process. The PCB is identified by an integer process ID (PID). A PCB keeps all the information
needed to keep track of a process as listed below in thetable −

S.N. Information & Description

Process State
1
The current state of the process i.e., whether it is ready, running, waiting,or whatever.

Process privileges
2
This is required to allow/disallow access to system resources.

Process ID
3
Unique identification for each of the process in the operating system.

Pointer
4
A pointer to parent process.

Program Counter
5
Program Counter is a pointer to the address of the next instruction to beexecuted for this
process.

CPU registers
6
Various CPU registers where process need to be stored for execution forrunning state.

CPU Scheduling Information


7
Process priority and other scheduling information which is required toschedule the
process.

1048
Memory management information
8 This includes the information of page table, memory limits, Segment tabledepending on
memory used by the operating system.

Accounting information
9
This includes the amount of CPU used for process execution, time limits,execution ID etc.

IO status information
10
This includes a list of I/O devices allocated to the process.

The architecture of a PCB is completely dependent on Operating System and maycontain different
information in different operating systems. Here is a simplified diagram of a PCB −

The PCB is maintained for a process throughout its lifetime, and is deleted once the process
terminates.
Process Scheduling
The process scheduling is the activity of the process manager that handles the removal of the
running process from the CPU and the selection of another process on the basis of a particular
strategy.

Process scheduling is an essential part of a Multiprogramming operating systems. Such operating


systems allow more than one process to be loaded into the executable memory at a time and the
loaded process shares the CPU using time multiplexing.

Process Scheduling Queues


The OS maintains all PCBs in Process Scheduling Queues. The OS maintains a separate queue for

1049
each of the process states and PCBs of all processes in the same execution state are placed in
the same queue. When the state of a process is changed, its PCB is unlinked from its current
queue and moved to its new statequeue.
The Operating System maintains the following important process schedulingqueues −
• Job queue − This queue keeps all the processes in the system.
• Ready queue − This queue keeps a set of all processes residing in main memory, ready and
waiting to execute. A new process is always put in thisqueue.
• Device queues − The processes which are blocked due to unavailability of an I/O device
constitute this queue.

The OS can use different policies to manage each queue (FIFO, Round Robin, Priority, etc.). The OS
scheduler determines how to move processes between the ready and run queues which can only
have one entry per processor core on the system; in the above diagram, it has been merged with
the CPU.

Two-State Process Model


Two-state process model refers to running and non-running states which aredescribed below −

S.N. State & Description

1 Running

When a new process is created, it enters into the system as in the runningstate.

1050
2 Not Running

Processes that are not running are kept in queue, waiting for their turn to execute.
Each entry in the queue is a pointer to a particular process. Queue is implemented
by using linked list. Use of dispatcher is as follows. When a process is interrupted,
that process is transferred in the waiting queue. If the process has completed or
aborted, the process is discarded. In either case, the dispatcher then selects a
process from the queue to execute.

Schedulers
Schedulers are special system software which handle process scheduling in various ways. Their
main task is to select the jobs to be submitted into the systemand to decide which process to run.
Schedulers are of three types −
• Long-Term Scheduler
• Short-Term Scheduler
• Medium-Term Scheduler

Long Term Scheduler


It is also called a job scheduler. A long-term scheduler determines which programs are admitted
to the system for processing. It selects processes from the queue and loads them into memory for
execution. Process loads into the memoryfor CPU scheduling.
The primary objective of the job scheduler is to provide a balanced mix of jobs, such as I/O bound
and processor bound. It also controls the degree of multiprogramming. If the degree of
multiprogramming is stable, then the average rate of process creation must be equal to the
average departure rate of processesleaving the system.

On some systems, the long-term scheduler may not be available or minimal. Time-sharing
operating systems have no long term scheduler. When a process changes the state from new to
ready, then there is use of long-term scheduler.

Short Term Scheduler


It is also called as CPU scheduler. Its main objective is to increase system performance in
accordance with the chosen set of criteria. It is the change of ready state to running state of the
process. CPU scheduler selects a process among the processes that are ready to execute and
allocates CPU to one of them.
Short-term schedulers, also known as dispatchers, make the decision of which process to execute
next. Short-term schedulers are faster than long-term schedulers.

Medium Term Scheduler


Medium-term scheduling is a part of swapping. It removes the processes from the memory. It
reduces the degree of multiprogramming. The medium-term scheduler is in-charge of handling
the swapped out-processes.
A running process may become suspended if it makes an I/O request. A suspended processes
cannot make any progress towards completion. In this condition, to remove the process from
1051
memory and make space for other processes, the suspended process is moved to the secondary
storage. This process is called swapping, and the process is said to be swapped out or rolled out.
Swapping may be necessary to improve the process mix.

Comparison among Scheduler

S.N. Long-Term Scheduler Short-Term Scheduler Medium-Term Scheduler

1 It is a job scheduler It is a CPU scheduler It is a process swapping


scheduler.

2 Speed is lesser than short Speed is fastest among Speed is in between both
term scheduler other two short and long term
scheduler.

3 It controls the degree of It provides lesser control It reduces the degree of


multiprogramming over degree of multiprogramming.
multiprogramming

4 It is almost absent or It is also minimal in time It is a part of Time sharing


minimal in time sharing sharing system systems.
system

5 It selects processes from It selects those It can re-introduce the


pool and loads them into processes which are process into memory and
memory forexecution ready to execute execution can be
continued.

Context Switch
A context switch is the mechanism to store and restore the state or context of a CPU in Process
Control block so that a process execution can be resumed from the same point at a later time.
Using this technique, a context switcher enables multiple processes to share a single CPU.
Context switching is an essential part ofa multitasking operating system features.
When the scheduler switches the CPU from executing one process to execute another, the state
from the current running process is stored into the process control block. After this, the state for
the process to run next is loaded from its own PCB and used to set the PC, registers, etc. At that
point, the second processcan start executing.

1052
Context switches are computationally intensive since register and memory state must be saved
and restored. To avoid the amount of context switching time, some hardware systems employ two
or more sets of processor registers. When the process is switched, the following information is
stored for later use.
• Program Counter
• Scheduling information
• Base and limit register value
• Currently used register
• Changed State
• I/O State information
• Accounting information

Process Operations
Process operations, also called process manufacturing or process production, is the mass
production method of producing products in a continuous flow. In other words, this is a conveyer
belt system that produces identical, standardized items at a high rate of speed.

Different Operations on Processes


There are many operations that can be performed on processes. Some of these are process
creation, process preemption, process blocking, and process
termination. These are given in detail as follows −

Process Creation
Processes need to be created in the system for different operations. This can be done by the

1053
following events −
• User request for process creation
• System initialization
• Execution of a process creation system call by a running process
• Batch job initialization

A process may be created by another process using fork(). The creating process is called the
parent process and the created process is the child process. A child process can have only one
parent but a parent process may have many children. Both the parent and child processes have
the same memory image, open files, and environment strings. However, they have distinct address
spaces.

A diagram that demonstrates process creation using fork() is as follows –

Process Preemption
An interrupt mechanism is used in preemption that suspends the process executing currently and
the next process to execute is determined by the short- term scheduler. Preemption makes sure
that all processes get some CPU time forexecution.
A diagram that demonstrates process preemption is as follows −

Process Blocking
The process is blocked if it is waiting for some event to occur. This event may be I/O as the I/O
events are executed in the main memory and don't require the processor. After the event is
complete, the process again goes to the ready state.

1054
A diagram that demonstrates process blocking is as follows –

Process Termination
After the process has completed the execution of its last instruction, it is terminated. The
resources held by a process are released after it is terminated.
A child process can be terminated by its parent process if its task is no longer relevant. The child
process sends its status information to the parent process before it terminates. Also, when a
parent process is terminated, its child processes are terminated as well as the child processes
cannot run if the parentprocesses are terminated.
Inter Process Communication (IPC)

A process can be of two types:


• Independent process.
• Co-operating process.
An independent process is not affected by the execution of other processes while a co-operating
process can be affected by other executing processes. Though one can think that those
processes, which are running independently, will execute very efficiently, in reality, there are many
situations when co-operative nature can be utilised for increasing computational speed,
convenience and modularity. Inter process communication (IPC) is a mechanism which allows
processes to communicate with each other and synchronize their actions. The communication
between these processes can be seen as a method of co-operation between them. Processes can
communicate with each other through both:
1. Shared Memory
2. Message passing

The Figure 1 below shows a basic structure of communication between processes via the shared
memory method and via the message passing method.
An operating system can implement both method of communication. First, we will discuss the
shared memory methods of communication and then message passing. Communication between
1055
processes using shared memory requires processes to share some variable and it completely
depends on how programmer will implement it. One way of communication using shared memory
can be imagined like this: Suppose process1 and process2 are executing simultaneously and they
share some resources or use some information from another process.

Process1 generate information about certain computations or resources being used and keeps it
as a record in shared memory. When process2 needs to use theshared information, it will check in
the record stored in shared memory and take note of the information generated by process1 and
act accordingly. Processes can use shared memory for extracting information as a record from
another process as well as for delivering any specific information to other processes.
an example of communication between processes using shared memory method.

i) Shared Memory Method

Ex: Producer-Consumer problem


There are two processes: Producer and Consumer. Producer produces some item and Consumer
consumes that item. The two processes share a common space or memory location known as a
buffer where the item produced by Producer is stored and from which the Consumer consumes
the item, if needed. There are two versions of this problem: the first one is known as unbounded
buffer problem in which Producer can keep on producing items and there is no limit on the size of
the buffer, the second one is known as the bounded buffer problem in which Producer can
produce up to a certain number of items before it starts waiting for Consumer to consume it. We
will discuss the bounded buffer problem. First, the Producer and the Consumer will share some
common memory, then producer will start producing items. If the total produced item is equal to
the size of buffer, producer will wait to get it consumed by the Consumer. Similarly, the consumer
will first check for the availability of the item. If no item is available, Consumer will wait for
Producer to produce it. If there are items available, Consumer will consume it. The pseudo code to
demonstrate is provided below:

Shared Data between the two Processes


#define buff_max 25#define mod %
struct item{

// different member of the produced data


1056
// or consumed data

// An array is needed for holding the items.


// This is the shared place which will be

// access by both process

// item shared_buff [ buff_max ];


// Two variables which will keep track of

// the indexes of the items produced by producer


// and consumer The free index points to

// the next free index. The full index points to


// the first full [Link] free_index = 0; int full_index = 0;
Producer Process Code

item nextProduced;while(1){

// check if there is no space

// for production.
// if so keep waiting.

while((free_index+1) mod buff_max == full_index); shared_buff[free_index] = nextProduced;


free_index = (free_index + 1) mod buff_max;
}

Consumer Process Code


item nextConsumed;while(1){
// check if there is an available
// item for consumption.

// if not keep on waiting for


// get them produced. while((free_index == full_index);

nextConsumed = shared_buff[full_index]; full_index = (full_index + 1) mod buff_max;


}

In the above code, the Producer will start producing again when the (free_index+1) mod buff max
will be free because if it it not free, this implies that there are still items that can be consumed by
the Consumer so there is no need to

produce more. Similarly, if free index and full index point to the same index, this implies that there
are no items to consume.

1057
ii) Messaging Passing Method
Now, We will start our discussion of the communication between processes viamessage passing.
In this method, processes communicate with each other without using any kind of shared
memory. If two processes p1 and p2 want to communicate with each other, they proceed as
follows:
• Establish a communication link (if a link already exists, no need to establish it
again.)
• Start exchanging messages using basic [Link] need at least two primitives:
– send(message, destinaion) or send(message)
– receive(message, host) or receive(message)

The message size can be of fixed size or of variable size. If it is of fixed size, it is easy for an OS
designer but complicated for a programmer and if it is of variable size then it is easy for a
programmer but complicated for the OS designer. A standard message can have two parts:
header and body.

The header part is used for storing message type, destination id, source id, message length, and
control information. The control information contains information like what to do if runs out of
buffer space, sequence number, [Link], message is sent using FIFO style.

Message Passing through Communication Link.

Direct and Indirect Communication link


Now, We will start our discussion about the methods of implementing communication link. While
implementing the link, there are some questionswhich need to be kept in mind like :
1. How are links established?
2. Can a link be associated with more than two processes?
3. How many links can there be between every pair of communicatingprocesses?
4. What is the capacity of a link? Is the size of a message that the link can accommodate fixed or
variable?
5. Is a link unidirectional or bi-directional?
1058
A link has some capacity that determines the number of messages that can reside in it temporarily
for which every link has a queue associated with it which can be of zero capacity, bounded
capacity, or unbounded capacity. In zero capacity, the sender waits until the receiver informs the
sender that it has received the message. In non-zero capacity cases, a process does not know
whether a message has been received or not after the send operation. For this, the sender must
communicate with the receiver explicitly. Implementation of the link depends on the situation, it
can be either a direct communication link or an in-directed communication link.
Direct Communication links are implemented when the processes uses a specific process
identifier for the communication, but it is hard to identify the sender ahead of time.
For example: the print server.

In-direct Communication is done via a shared mailbox (port), which consists of a queue of
messages. The sender keeps the message in mailbox and the receiver picks them up.

Message Passing through Exchanging the Messages. Synchronous and Asynchronous Message
Passing:
A process that is blocked is one that is waiting for some event, such as a resource becoming
available or the completion of an I/O operation. IPC is possible between the processes on same
computer as well as on the processes running on different computer i.e. in networked/distributed
system. In both cases, the process may or may not be blocked while sending a message or
attempting to receive a message so message passing may be blocking or non-blocking. Blocking
is considered synchronous and blocking send means the sender will be blockeduntil the message
is received by receiver. Similarly, blocking receive has the receiver block until a message is
available. Non-blocking is considered asynchronous and Non-blocking send has the sender sends
the message and continue. Similarly, Non-blocking receive has the receiver receive a valid
message or null. After a careful analysis, we can come to a conclusion that for a sender it is more
natural to be non-blocking after message passing as there may be a need to send the message to
different processes. However, the sender expects acknowledgement from the receiver in case the
send fails. Similarly, it is more natural for a receiver to be blocking after issuing the receive as the
information from the received message may be used for further execution. At the same time, if the
message send keep on failing, the receiver will have to wait indefinitely. That is why we also
consider the other possibility of message passing. There are basically three preferred
combinations:
• Blocking send and blocking receive
• Non-blocking send and Non-blocking receive
• Non-blocking send and Blocking receive (Mostly used)

In Direct message passing, The process which want to communicate must explicitly name the
recipient or sender of communication.
e.g. send(p1, message) means send the message to p1.
similarly, receive(p2, message) means receive the message from p2.

In this method of communication, the communication link gets established automatically, which
can be either unidirectional or bidirectional, but one link can be used between one pair of the
sender and receiver and one pair of sender and receiver should not possess more than one pair of
links. Symmetry and asymmetry between sending and receiving can also be implemented i.e.
1059
either both process will name each other for sending and receiving the messages or only the
sender will name receiver for sending the message and there is no need for receiver for naming
the sender for receiving the message. The problem with this method of communication is that if
the name of one process changes, this method will not work.

In Indirect message passing, processes use mailboxes (also referred to as ports) for sending and
receiving messages. Each mailbox has a unique id and processes can communicate only if they
share a mailbox. Link established only if processes share a common mailbox and a single link can
be associated with many processes. Each pair of processes can share several communication
links and these links may be unidirectional or bi-directional. Suppose two process want to
communicate though Indirect message passing, the required operations are: create a mail box,
use this mail box for sending and receiving messages, then destroy the mail box.

The standard primitives used are: send(A, message) which means send the message to mailbox
A. The primitive for the receiving the message also works in the same way e.g. received (A,
message). There is a problem in this mailbox implementation. Suppose there are more than two
processes sharing the same mailbox and suppose the process p1 sends a message to the
mailbox, which process will be the receiver? This can be solved by either enforcing that only two
processes can share a single mailbox or enforcing that only one process is allowed to execute the
receive at a given time or select any process randomly and notify the sender about the receiver.

A mailbox can be made private to a single sender/receiver pair and can also be shared between
multiple sender/receiver pairs. Port is an implementation of such mailbox which can have multiple
sender and single receiver. It is used in client/server applications (in this case the server is the
receiver). The port is owned by the receiving process and created by OS on the request of the
receiver process and can be destroyed either on request of the same receiver process or when the
receiver terminates itself. Enforcing that only one process is allowed to execute the receive can be
done using the concept of mutual exclusion. Mutex mailbox is create which is shared by n
process. Sender is non-blocking and sends the message. The first process which executes the
receivewill enter in the critical section and all other processes will be blocking and will wait.

Now, lets discuss the Producer-Consumer problem using message passing concept. The producer
places items (inside messages) in the mailbox and the consumer can consume an item when at
least one message present in the mailbox. The code is given below:

Producer Code
void Producer(void){int item; Message m; while(1){
receive(Consumer, &m); item = produce(); build_message(&m , item ) ;send(Consumer, &m);
}
}

Consumer Code
filter_none edit play_arrow brightness_4
void Consumer(void){int item; Message m; while(1){
receive(Producer, &m); item = extracted_item();send(Producer, &m); consume_item(item);
}
}

1060
Examples of IPC systems
1. Posix : uses shared memory method.
2. Mach : uses message passing
3. Windows XP : uses message passing using local procedural calls

Communication in client/server Architecture:


There are various mechanism:
• Pipe
• Socket
• Remote Procedural calls (RPCs)

The above three methods will be discussed in later articles as all of them are quite conceptual and
deserve their own separate articles.

Operating Systems Client/Server Communication


Client/Server communication involves two components, namely a client and a server. They are
usually multiple clients in communication with a single server. The clients send requests to the
server and the server responds to the client requests.
There are three main methods to client/server communication. These are given asfollows –

Sockets
Sockets facilitate communication between two processes on the same machine or different
machines. They are used in a client/server framework and consist of the IP address and port
number. Many application protocols use sockets for data connection and data transfer between a
client and a server.
Socket communication is quite low-level as sockets only transfer an unstructured byte stream
across processes. The structure on the byte stream is imposed by the client and server
applications.

A diagram that illustrates sockets is as follows –

Remote Procedure Calls


These are interprocess communication techniques that are used for client-server based
applications. A remote procedure call is also known as a subroutine call or afunction call.
A client has a request that the RPC translates and sends to the server. This request may be a
procedure or a function call to a remote server. When the server receives the request, it sends the
required response back to the client.
A diagram that illustrates remote procedure calls is given as follows −

1061
Pipes
These are interprocess communication methods that contain two end points. Data is entered from
one end of the pipe by a process and consumed from theother end by the other process.

The two different types of pipes are ordinary pipes and named pipes. Ordinary pipes only allow
one way communication. For two way communication, two pipes are required. Ordinary pipes have
a parent child relationship between the processes as the pipes can only be accessed by
processes that created or inherited them.
Named pipes are more powerful than ordinary pipes and allow two way communication. These
pipes exist even after the processes using them haveterminated. They need to be explicitly deleted
when not required anymore.
A diagram that demonstrates pipes are given as follows –

Process Synchronization
Process Synchronization means sharing system resources by processes in a such a way that,
Concurrent access to shared data is handled thereby minimizing the chance of inconsistent data.
Maintaining data consistency demands mechanisms to ensure synchronized execution of
cooperating processes.

Process Synchronization was introduced to handle problems that arose while multiple process
executions. Some of the problems are discussed below.

Critical Section Problem


A Critical Section is a code segment that accesses shared variables and has to be executed as an
atomic action. It means that in a group of cooperating processes, at a given point of time, only one
process must be executing its critical section. If any other process also wants to execute its
critical section, it must wait until thefirst one finishes.

1062
Solution to Critical Section Problem
A solution to the critical section problem must satisfy the following threeconditions:
1. Mutual Exclusion
Out of a group of cooperating processes, only one process can be in its critical section at a
given point of time.
2. Progress
If no process is in its critical section, and if one or more threads want to execute their critical
section then any one of these threads must be allowed to get into itscritical section.
3. Bounded Waiting
After a process makes a request for getting into its critical section, there is a limitfor how many
other processes can get into their critical section, before this process's request is granted. So
after the limit is reached, system must grant the process permission to get into its critical
section.

Synchronization Hardware
Many systems provide hardware support for critical section code. The critical section problem
could be solved easily in a single-processor environment if we could disallow interrupts to occur
while a shared variable or resource is being modified.
In this manner, we could be sure that the current sequence of instructions would be allowed to
execute in order without pre-emption. Unfortunately, this solution is not feasible in a
multiprocessor environment.
Disabling interrupt on a multiprocessor environment can be time consuming as the message is
passed to all the processors.
This message transmission lag, delays entry of threads into critical section and the system
efficiency decreases.

Mutex Locks
As the synchronization hardware solution is not easy to implement for everyone, a strict software
approach called Mutex Locks was introduced. In this approach, in the entry section of code, a
LOCK is acquired over the critical resources modified and used inside critical section, and in the
exit section that LOCK is released.
As the resource is locked while a process executes its critical section hence no other process can
access it.
Classical Problems of Synchronization
Semaphore can be used in other synchronization problems besides MutualExclusion.
Below are some of the classical problem depicting flaws of process synchronaization in systems

1063
where cooperating processes are present.

The following three problems:


1. Bounded Buffer (Producer-Consumer) Problem
2. Dining Philosophers Problem
3. The Readers Writers Problem

Bounded Buffer Problem


• This problem is generalised in terms of the Producer Consumer problem, where a finite buffer
pool is used to exchange messages between producerand consumer processes.
Because the buffer pool has a maximum size, this problem is often called the Bounded buffer
problem.
• Solution to this problem is, creating two counting semaphores "full" and "empty" to keep track
of the current number of full and empty buffers respectively.

Dining Philosophers Problem


• The dining philosopher's problem involves the allocation of limited resources to a group of
processes in a deadlock-free and starvation-freemanner.
• There are five philosophers sitting around a table, in which there are five chopsticks/forks kept
beside them and a bowl of rice in the centre, When a philosopher wants to eat, he uses two
chopsticks - one from their left and one from their right. When a philosopher wants to think, he
keeps down both chopsticks at their original place.

The Readers Writers Problem


• In this problem there are some processes(called readers) that only read the shared data, and
never change it, and there are other processes(called writers) who may change the data in
addition to reading,or instead of reading it.
• There are various type of readers-writers problem, most centred on relative priorities of readers
and writers.

Critical Section Problem


The critical section is a code segment where the shared variables can be accessed. An atomic
action is required in a critical section i.e. only one process can execute in its critical section at a
time. All the other processes have to wait to execute in their critical sections.
A diagram that demonstrates the critical section is as follows –

In the above diagram, the entry section handles the entry into the critical section. It acquires the

1064
resources needed for execution by the process. The exit section handles the exit from the critical
section. It releases the resources and also informs the other processes that the critical section is
free.

Solution to the Critical Section Problem


The critical section problem needs a solution to synchronize the different processes. The solution
to the critical section problem must satisfy the followingconditions −

• Mutual Exclusion
Mutual exclusion implies that only one process can be inside the critical section atany time.
If any other processes require the critical section, they must wait until itis free.
• Progress
Progress means that if a process is not using the critical section, then it should notstop any
other process from accessing it. In other words, any process can enter a critical section if it
is free.
• Bounded Waiting
Bounded waiting means that each process must have a limited waiting time. Itt should not
wait endlessly to access the critical section.

Peterson’s solution
Peterson’s solution provides a good algorithmic description of solving the critical- section problem
and illustrates some of the complexities involved in designing software that addresses the
requirements of mutual exclusion, progress, and bounded waiting.

do {

flag[i] = true;

turn = j;

while (flag[j] && turn == j);

/* critical section */

flag[i] = false;

/* remainder section */

}
while (true);

The structure of process Pi in Peterson’s solution. This solution is restricted to two processes that
alternate execution between their critical sections and remainder sections. The processes are
numbered P0 and P1. We use Pj for convenience to denote the other process when Pi is present;
that is, j equals 1 − I, Peterson’s solution requires the two processes to share two data items −
int turn; boolean flag[2];
The variable turn denotes whose turn it is to enter its critical section. I.e., if turn
1065
== i, then process Pi is allowed to execute in its critical section. If a process is ready to enter its
critical section, the flag array is used to indicate that. For E.g., if flag[i] is true, this value indicates
that Pi is ready to enter its critical section. With an explanation of these data structures complete,
we are now ready to describe the algorithm shown in above. To enter the critical section, process
Pi first sets flag[i] to be true and then sets turn to the value j, thereby asserting that if the other
process wishes to enter the critical section, it can do so. Turn will be set to both i and j at roughly
the same time, if both processes try to enter at the same time. Only one of these assignments will
occur ultimately; the other will occur but will be overwritten immediately. The final value of turn
determines which of the two processes is allowed to enter its critical section first. We now prove
that this solution is correct. We need to show that –
• Mutual exclusion is preserved.
• The progress requirement is satisfied.
• The bounded-waiting requirement is met.
To prove 1, we note that each Pi enters its critical section only if either flag[j] == false or turn == i.
Also note that, if both processes can be executing in their critical sections at the same time, then
flag[0] == flag[1] == true. These two observations indicate that P0 and P1 could not have
successfully executed their while statements at about the same time, since the value of turn can
be either 0 or 1 but cannot be both. Hence, one of the processes — say, Pj — must have
successfully executed the while statement, whereas Pi had to execute at least one additional
statement (“turn == j”). However, at that time, flag[j] == true and turn == j, and this condition will
persist as long as Pj is in its critical section; as a result,mutual exclusion is preserved.

To prove properties 2 and 3, we note that if a process is stuck in the while loop with the condition
flag[j] == true and turn == j, process Pi can be prevented from entering the critical section only; this
loop is the only one possible. flag[j] will be == false, and Pi can enter its critical section if Pj is not
ready to enter the critical section. If Pj has set, flag[j] = true and is also executing in its while
statement, then either turn == i or turn == j. If turn == i, Pi will enter the critical section then. Pj will
enter the critical section, If turn == j. Although once Pj exits its critical section, it will reset flag[j] to
false, allowing Pi to enter its critical section. Pj must also set turn to i, if Pj resets flag[j] to true.
Hence, since Pi does not change the value of the variable turn while executing the while
statement, Pi will enter the critical section (progress) after at most one entry by Pj (bounded
waiting).

Disadvantage
• Peterson’s solution works for two processes, but this solution is best scheme in user mode
for critical section.
• This solution is also a busy waiting solution so CPU time is wasted. So that “SPIN LOCK”
problem can come. And this problem can come in any ofthe busy waiting solution.

Semaphores
Semaphores are integer variables that are used to solve the critical section problem by using two
atomic operations, wait and signal that are used for processsynchronization.
The definitions of wait and signal are as follows –

• Wait
The wait operation decrements the value of its argument S, if it is positive. If S is negative or zero,
then no operation is performed.
1066
wait(S)

{
while (S<=0);

S--;

• Signal
The signal operation increments the value of its argument S.

signal(S)

S++;

Types of Semaphores
There are two main types of semaphores i.e. counting semaphores and binarysemaphores. Details
about these are given as follows −
• Counting Semaphores
These are integer value semaphores and have an unrestricted value domain. These
semaphores are used to coordinate the resource access, where the semaphore count is the
number of available resources. If the resources are added, semaphore count automatically
incremented and if the resources areremoved, the count is decremented.

• Binary Semaphores
The binary semaphores are like counting semaphores but their value is restricted to 0 and 1.
The wait operation only works when the semaphore is 1 and the signal operation succeeds
when semaphore is 0. It is sometimes easier to implement binary semaphores than counting
semaphores.

Advantages of Semaphores
Some of the advantages of semaphores are as follows −
• Semaphores allow only one process into the critical section. They follow the mutual exclusion
principle strictly and are much more efficient than some other methods of synchronization.
• There is no resource wastage because of busy waiting in semaphores as processor time is not
wasted unnecessarily to check if a condition is fulfilledto allow a process to access the critical
section.
• Semaphores are implemented in the machine independent code of themicrokernel. So they are
machine independent.

Disadvantages of Semaphores
1067
Some of the disadvantages of semaphores are as follows −

• Semaphores are complicated so the wait and signal operations must beimplemented in the
correct order to prevent deadlocks.
• Semaphores are impractical for last scale use as their use leads to loss of modularity. This
happens because the wait and signal operations prevent the creation of a structured layout
for the system.
• Semaphores may lead to a priority inversion where low priority processes may access the
critical section first and high priority processes later.

Threads
Thread is an execution unit which consists of its own program counter, a stack, and a set of
registers. Threads are also known as Lightweight processes. Threads are popular way to improve
application through parallelism. The CPU switchesrapidly back and forth among the threads giving
illusion that the threads are running in parallel.
As each thread has its own independent resource for process execution, multpileprocesses can be
executed parallely by increasing number of threads.

Types of Thread
There are two types of threads:
1. User Threads
2. Kernel Threads
User threads, are above the kernel and without kernel support. These are the threads that
application programmers use in their programs.
Kernel threads are supported within the kernel of the OS itself. All modern OSs support kernel
level threads, allowing the kernel to perform multiple simultaneous tasks and/or to service
multiple kernel system calls simultaneously.

Multithreading Models
The user threads must be mapped to kernel threads, by one of the followingstrategies:
• Many to One Model
• One to One Model
• Many to Many Model

1068
Many to One Model
• n the many to one model, many user-level threads are all mapped onto a single kernel
thread.
• Thread management is handled by the thread library in user space, which is efficient in
nature.

One to One Model


• The one to one model creates a separate kernel thread to handle each and every user
thread.
• Most implementations of this model place a limit on how many threads canbe created.
• Linux and Windows from 95 to XP implement the one-to-one model forthreads.

Many to Many Model


• The many to many model multiplexes any number of user threads onto an equal or smaller
number of kernel threads, combining the best features of the one-to-one and many-to-one
models.
• Users can create any number of the threads.
• Blocking the kernel system calls does not block the entire process.
• Processes can be split across multiple processors.

1069
What are Thread Libraries?
Thread libraries provide programmers with API for creation and management ofthreads.
Thread libraries may be implemented either in user space or in kernel space. The user space
involves API functions implemented solely within the user space, with no kernel support. The
kernel space involves system calls, and requires a kernel with thread library support.

Three types of Thread


1. POSIX Pitheads, may be provided as either a user or kernel library, as anextension to the POSIX
standard.
2. Win32 threads, are provided as a kernel-level library on Windows systems.
3. Java threads: Since Java generally runs on a Java Virtual Machine, the implementation of
threads is based upon whatever OS and hardware the JVM is running on, i.e. either Pitheads or
Win32 threads depending on thesystem.

Benefits of Multithreading
1. Responsiveness
2. Resource sharing, hence allowing better utilization of resources.
3. Economy. Creating and managing threads becomes easier.
4. Scalability. One thread runs on one CPU. In Multithreaded processes,threads can be distributed
over a series of processors to scale.
5. Context Switching is smooth. Context switching refers to the procedure followed by CPU to
change from one task to another

Multithreading Issues
Below we have mentioned a few issues related to multithreading. Well, it's an old saying, All good
things, come at a price.
Thread Cancellation
Thread cancellation means terminating a thread before it has finished working. There can be two
approaches for this, one is Asynchronous cancellation, which terminates the target thread
immediately. The other is Deferred
cancellation allows the target thread to periodically check if it should becancelled.

Signal Handling
Signals are used in UNIX systems to notify a process that a particular event has occurred. Now in
when a Multithreaded process receives a signal, to which thread it must be delivered? It can be
1070
delivered to all, or a single thread.
fork() System Call
fork() is a system call executed in the kernel through which a process creates a copy of itself. Now
the problem in Multithreaded process is, if one thread forks, will the entire process be copied or
not?

Security Issues
Yes, there can be security issues because of extensive sharing of resources between multiple
threads.
There are many other issues that you might face in a multithreaded process, but there are
appropriate solutions available for them. Pointing out some issues here was just to study both
sides of the coin.

Multicore programming
Multicore programming helps to create concurrent systems for deployment on multicore
processor and multiprocessor systems. A multicore processor system is basically a single
processor with multiple execution cores in one chip. It has multiple processors on the
motherboard or chip. A Field-Programmable Gate Array (FPGA) is might be included in a
multiprocessor system. A FPGA is an integrated circuit containing an array of programmable logic
blocks and a hierarchy of reconfigurable interconnects. Input data is processed by to produce
outputs. It can be a processor in a multicore or multiprocessor system, or a FPGA.
The multicore programming approach has following advantages &minus;
• Multicore and FPGA processing helps to increase the performance of anembedded system.
• Also helps to achieve scalability, so the system can take advantage of increasing numbers
of cores and FPGA processing power over time.
Concurrent systems that we create using multicore programming have multiple tasks executing in
parallel. This is known as concurrent execution. When multiple parallel tasks are executed by a
processor, it is known as multitasking. A CPU scheduler, handles the tasks that execute in parallel.
The CPU implements tasks using operating system threads. So that tasks can execute
independently but have some data transfer between them, such as data transfer between a data
acquisition module and controller for the system. Data transfer occurs when there is a data
dependency.

Implicit Threading and Language-based threads

Implicit Threading
One way to address the difficulties and better support the design of multithreaded applications is
to transfer the creation and management of threading from application developers to compilers
and run-time libraries. This, termed implicit threading, is a popular trend today.

Implicit threading is mainly the use of libraries or other language support to hide the management
of threads. The most common implicit threading library is OpenMP, in context of C.
OpenMP is a set of compiler directives as well as an API for programs written in C, C++, or
FORTRAN that provides support for parallel programming in shared- memory environments.
OpenMP identifies parallel regions as blocks of code that may run in parallel. Application
developers insert compiler directives into their code at parallel regions, and these directives
instruct the OpenMP run-time library to execute the region in parallel. The following C program

1071
illustrates a compiler directive above the parallel region containing the printf() statement:
Example

#include <omp.h>

#include <stdio.h>

int main(int argc, char *argv[]){

/* sequential code */

#pragma omp parallel{

printf("I am a parallel region.");

/* sequential code */

return 0;

Output
I am a parallel region.
When OpenMP encounters the directive

#pragma omp parallel

It creates as many threads which are processing cores in the system. Thus, for a dual-core
system, two threads are created, for a quad-core system, four are created; and so forth. Then all
the threads simultaneously execute the parallel region. When each thread exits the parallel region,
it is terminated. OpenMP provides several additional directives for running code regions in
parallel, including parallelizing loops.

In addition to providing directives for parallelization, OpenMP allows developers to choose among
several levels of parallelism. Eg, they can set the number of threads manually. It also allows
developers to identify whether data are shared between threads or are private to a thread.
OpenMP is available on several open- source and commercial compilers for Linux, Windows, and
Mac OS X systems.

Grand Central Dispatch (GCD)


Grand Central Dispatch (GCD)—a technology for Apple’s Mac OS X and iOS operating systems—is
a combination of extensions to the C language, an API, and a run-time library that allows
1072
application developers to spot sections of code to run in parallel. Like OpenMP, GCD also
manages most of the details of threading. It identifies extensions to the C and C++ languages
known as blocks. A block is simply a self-contained unit of work. It is specified by a caret ˆ
inserted in front of a pair of braces { }. A simple example of a block is shown below −

{
ˆprintf("This is a block");
}

It schedules blocks for run-time execution by placing them on a dispatch queue. When GCD
removes a block from a queue, it assigns the block to an available thread from the thread pool it
manages. It identifies two types of dispatch queues: serial and concurrent. Blocks placed on a
serial queue are removed in FIFO order. Once a block has been removed from the queue, it must
complete execution before another block is removed. Each process has its own serial queue
(known as main queue). Developer can create additional serial queues that are local to particular
processes. Serial queues are useful for ensuring the sequential execution of several tasks. Blocks
placed on a concurrent queue are also removed in FIFO order, but several blocks may be removed
at a time, thus allowing multiple blocks to execute in parallel. There are three system-wide
concurrent dispatch queues, and they are distinguished according to priority: low, default, and
high. Priorities represent an estimation of the relative importance of blocks. Quite simply, blocks
with a higher priority should be placed on the high priority dispatch queue. The following code
segment illustrates obtaining the default- priority concurrent queue and submitting a block to the
queue using the dispatch async() function:

dispatch_queue_t queue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch async(queue, ˆ{ printf("This is a block."); });

Internally, GCD’s thread pool is composed of POSIX threads. GCD actively manages the pool,
allowing the number of threads to grow and shrink according to application demand and system
capacity.

Threads as Objects
In alternative languages, ancient object-oriented languages give explicit multithreading support
with threads as objects. In these forms of languages,classes area written to either extend a thread
class or implement a corresponding interface. This style resembles the Pthread approach,
because the code is written with explicit thread management. However, the encapsulation of
informationinside the classes and extra synchronization options modify the task.

Java Threads
Java provides a Thread category and a Runnable interface that can be used. Each need to
implement a public void run() technique that defines the entry purpose of the thread. Once an
instance of the object is allotted, the thread is started by invoking the start() technique on that.
Like with Pthreads, beginning the thread is asynchronous, that the temporal arrangement of the
execution is non- deterministic.

1073
Python Threads
Python additionally provides two mechanisms for multithreading. One approach is comparable to
the Pthread style, wherever a function name is passed to a library method
thread.start_new_thread(). This approach is very much and lacks the flexibility to join or terminate
the thread once it starts. A additional flexible technique is to use the threading module to outline a
class that extends threading. Thread. almost like the Java approach, the category should have a
run() method that gives the thread's entry purpose. Once an object is instantiated from this
category, it can be explicitly started and joined later.

Concurrency as Language Design


Newer programming languages have avoided race condition by building assumptions of
concurrent execution directly into the language style itself. As an example, Go combines a trivial
implicit threading technique (goroutines) with channels, a well-defined style of message-passing
communication. Rust adopts a definite threading approach the same as Pthreads. However, Rust
has terribly strong memory protections that need no extra work by the software engineer.

Goroutines
The Go language includes a trivial mechanism for implicit threading: place the keyword go before
a call. The new thread is passed an association to a message- passing channel. Then, the most
thread calls success := <-messages, that performs a interference scan on the channel. Once the
user has entered the right guess of seven, the keyboard auditor thread writes to the channel,
permitting the most thread to progress.
Channels and goroutines are core components of the Go language, that wasdesigned beneath the
belief that almost all programs would be multithreaded. This style alternative streamlines the
event model, permitting the language itself up-to-date the responsibility for managing the threads
and programing.

Rust Concurrency
Another language is Rust that has been created in recent years, with concurrency as a central
design feature. The following example illustrates the use of thread::spawn() to create a new
thread, which can later be joined by invoking join() on it. The argument to thread::spawn()
beginning at the || is known as a closure, which can be thought of as an anonymous function.
That is, the childthread here will print the value of a.

Example

1074
use std::thread;

fn main() {

/* Initialize a mutable variable a to 7 */

let mut a = 7;

/* Spawn a new thread */

let child_thread = thread::spawn(move || {

/* Make the thread sleep for one second, then print a */

a -= 1;

println!("a = {}", a)

});

/* Change a in the main thread and print it */

a += 1;

println!("a = {}", a);

/* Join the thread and print a again */

child_thread.join();

However, there is a subtle point in this code that is central to Rust's design. Within the new thread
(executing the code in the closure), the a variable is distinct from the a in other parts of this
code. It enforces a very strict memory model (known as "ownership") which prevents multiple
threads from accessing the same memory. In this example, the move keyword indicates that the
spawned thread will receive a separate copy of a for its own use. Regardless of the scheduling of
the two threads, the main and child threads cannot interfere with each other's modifications of a,
because they are distinct copies. It is not possible for the two threads to share access to the
same memory.

Threading Issues
Multithreaded programs allow the execution of multiple parts of a program at the same time.
1075
These parts are known as threads and are lightweight processes available within the process.

Threads improve the application performance using parallelism. They share information like data
segment, code segment files etc. with their peer threadswhile they contain their own registers,
stack, counter etc.
Some of the issues with multithreaded programs are as follows −

one by one −
• Increased Complexity − Multithreaded processes are quite complicated. Coding for these can
only be handled by expert programmers.
• Complications due to Concurrency − It is difficult to handle concurrency in multithreaded
processes. This may lead to complications and future problems.
• Difficult to Identify Errors− Identification and correction of errors is much more difficult in
multithreaded processes as compared to single threadedprocesses.
• Testing Complications− Testing is a complicated process i multithreaded programs as
compared to single threaded programs. This is because defects can be timing related and not
easy to identify.
• Unpredictable results− Multithreaded programs can sometimes lead to unpredictable results
as they are essentially multiple parts of a programthat are running at the same time.
• Complications for Porting Existing Code − A lot of testing is required for porting existing code
in multithreading. Static variables need to be removed and any code or function calls that are
not thread safe need to be replaced.

CPU Scheduling
CPU scheduling is a process which allows one process to use the CPU while the execution of
another process is on hold(in waiting state) due to unavailability of any resource like I/O etc,
thereby making full use of CPU. The aim of CPU scheduling is to make the system efficient, fast
and fair.
Whenever the CPU becomes idle, the operating system must select one of the processes in the
ready queue to be executed. The selection process is carried out by the short-term scheduler (or
1076
CPU scheduler). The scheduler selects from among the processes in memory that are ready to
execute, and allocates the CPUto one of them.

CPU Scheduling: Dispatcher


Another component involved in the CPU scheduling function is the Dispatcher. The dispatcher is
the module that gives control of the CPU to the process selectedby the short-term scheduler. This
function involves:
• Switching context
• Switching to user mode
• Jumping to the proper location in the user program to restart that programfrom where it left
last time.
The dispatcher should be as fast as possible, given that it is invoked during every process switch.
The time taken by the dispatcher to stop one process and start another process is known as the
Dispatch Latency. Dispatch Latency can be explained using the below figure:

Types of CPU Scheduling


CPU scheduling decisions may take place under the following four circumstances:
1. When a process switches from the running state to the waiting state(for I/O request or
invocation of wait for the termination of one of the child processes).
2. When a process switches from the running state to the ready state (for example, when an
interrupt occurs).
3. When a process switches from the waiting state to the ready state(forexample, completion
of I/O).
4. When a process terminates.
In circumstances 1 and 4, there is no choice in terms of scheduling. A new process(if one exists in
the ready queue) must be selected for execution. There is a choice, however in circumstances 2
and 3.
When Scheduling takes place only under circumstances 1 and 4, we say the scheduling scheme is
non-preemptive; otherwise the scheduling scheme

1077
is preemptive.

Non-Preemptive Scheduling

Under non-preemptive scheduling, once the CPU has been allocated to a process, the process
keeps the CPU until it releases the CPU either by terminating or by switching to the waiting state.
This scheduling method is used by the Microsoft Windows 3.1 and by the Apple Macintosh
operating systems.
It is the only method that can be used on certain hardware platforms, because It does not require
the special hardware(for example: a timer) needed for preemptive scheduling.

Preemptive Scheduling
In this type of Scheduling, the tasks are usually assigned with priorities. At times it is necessary to
run a certain task that has a higher priority before another task although it is running. Therefore,
the running task is interrupted for some timeand resumed later when the priority task has finished
its execution.

CPU Scheduling: Scheduling Criteria


There are many different criterias to check when considering the "best" scheduling algorithm, they
are:

CPU Utilization
To make out the best use of CPU and not to waste any CPU cycle, CPU would be working most of
the time(Ideally 100% of the time). Considering a real system, CPU usage should range from 40%
(lightly loaded) to 90% (heavily loaded.)

Throughput
It is the total number of processes completed per unit time or rather say total amount of work
done in a unit of time. This may range from 10/second to 1/hour depending on the specific
processes.
Turnaround Time

It is the amount of time taken to execute a particular process, i.e. The interval from time of
submission of the process to the time of completion of the process(Wall clock time).

Waiting Time
The sum of the periods spent waiting in the ready queue amount of time a process has been
waiting in the ready queue to acquire get control on the CPU.

Load Average
It is the average number of processes residing in the ready queue waiting for their turn to get into
the CPU.

Response Time
Amount of time it takes from when a request was submitted until the first response is produced.
Remember, it is the time till the first response and not the completion of process execution(final
response).
In general CPU utilization and Throughput are maximized and other factors are reduced for proper
1078
optimization.

Scheduling Algorithms
To decide which process to execute first and which process to execute last to achieve maximum
CPU utilisation, computer scientists have defined some algorithms, they are:
1. First Come First Serve(FCFS) Scheduling
2. Shortest-Job-First(SJF) Scheduling
3. Priority Scheduling
4. Round Robin(RR) Scheduling
5. Multilevel Queue Scheduling
6. Multilevel Feedback Queue Scheduling

First Come First Serve Scheduling


In the "First come first serve" scheduling algorithm, as the name suggests, the process which
arrives first, gets executed first, or we can say that the process which requests the CPU first, gets
the CPU allocated first.
• First Come First Serve, is just like FIFO(First in First out) Queue data structure, where the
data element which is added to the queue first, is theone who leaves the queue first.
• This is used in Batch Systems.
• It's easy to understand and implement programmatically, using a Queue data structure,
where a new process enters through the tail of the queue,and the scheduler selects process
from the head of the queue.
• A perfect real life example of FCFS scheduling is buying tickets at ticketcounter.

Calculating Average Waiting Time


For every scheduling algorithm, Average waiting time is a crucial parameter to judge it's
performance.
AWT or Average waiting time is the average of the waiting times of the processes in the queue,
waiting for the scheduler to pick them for execution.

Lower the Average Waiting Time, better the scheduling algorithm.


Consider the processes P1, P2, P3, P4 given in the below table, arrives for execution in the same
order, with Arrival Time 0, and given Burst Time, let's findthe average waiting time using the FCFS
scheduling algorithm.

1079
The average waiting time will be 18.75 ms
For the above given proccesses, first P1 will be provided with the CPU resources,
• Hence, waiting time for P1 will be 0
• P1 requires 21 ms for completion, hence waiting time for P2 will be 21 ms
• Similarly, waiting time for process P3 will be execution time of P1 + execution time for P2,
which will be (21 + 3) ms = 24 ms.
• For process P4 it will be the sum of execution times of P1, P2 and P3. The GANTT chart
above perfectly represents the waiting time for each process. Problems with FCFS
Scheduling

Below we have a few shortcomings or problems with the FCFS schedulingalgorithm:


1. It is Non Pre-emptive algorithm, which means the process priority doesn'tmatter.
If a process with very least priority is being executed, more like daily routine backup
process, which takes more time, and all of a sudden some other high priority process
arrives, like interrupt to avoid system crash, the high priority process will have to wait, and
hence in this case, the system will crash, just because of improper process scheduling.
2. Not optimal Average Waiting Time.
3. Resources utilization in parallel is not possible, which leads to Convoy Effect, and hence
poor resource(CPU, I/O etc) utilization.

What is Convoy Effect?


Convoy Effect is a situation where many processes, who need to use a resource for short time are
blocked by one process holding that resource for a long time.
This essentially leads to poort utilization of resources and hence poorperformance.

Completion Time: Time taken for the execution to complete, starting from arrivaltime.
Turn Around Time: Time taken to complete after arrival. In simple words, it is the difference
1080
between the Completion time and the Arrival time.
Waiting Time: Total time the process has to wait before it's execution begins. It is the difference
between the Turn Around time and the Burst time of the process.
Shortest Job First(SJF) Scheduling

Shortest Job First scheduling works on the process with the shortest bursttime or duration first.
• This is the best approach to minimize waiting time.
• This is used in Batch Systems.
• It is of two types:
1. Non Pre-emptive
2. Pre-emptive
• To successfully implement it, the burst time/duration time of the processes should be
known to the processor in advance, which is practically not feasible all the time.
• This scheduling algorithm is optimal if all the jobs/processes are available at the same
time. (either Arrival time is 0 for all, or Arrival time is same for all)

Non Pre-emptive Shortest Job First


Consider the below processes available in the ready queue for execution, with arrival time as 0 for
all and given burst times.

As we can see in the GANTT chart above, the process P4 will be picked up first as it has the
shortest burst time, then P2, followed by P3 and at last P1.
We scheduled the same set of processes using the First come first serve algorithm in the previous
tutorial, and got average waiting time to be 18.75 ms, whereas with SJF, the average waiting time
comes out 4.5 ms.

Problem with Non Pre-emptive SJF


1081
If the arrival time for processes are different, which means all the processes are not available in
the ready queue at time 0, and some jobs arrive after some time, in such situation, sometimes
process with short burst time have to wait for the current process's execution to finish, because in
Non Pre-emptive SJF, on arrival of a process with short duration, the existing job/process's
execution is not halted/stopped to execute the short job first.

This leads to the problem of Starvation, where a shorter process has to wait for a long time until
the current longer process gets executed. This happens if shorter jobs keep coming, but this can
be solved using the concept of aging.

Pre-emptive Shortest Job First


In Preemptive Shortest Job First Scheduling, jobs are put into ready queue as they arrive, but as a
process with short burst time arrives, the existing process is preempted or removed from
execution, and the shorter job is executed first.

As you can see in the GANTT chart above, as P1 arrives first, hence it's execution starts
immediately, but just after 1 ms, process P2 arrives with a burst time of 3 ms which is less than
the burst time of P1, hence the process P1(1 ms done, 20 msleft) is preemptied and process P2 is
executed.

As P2 is getting executed, after 1 ms, P3 arrives, but it has a burst time greater than that of P2,
hence execution of P2 continues. But after another millisecond, P4 arrives with a burst time of 2
ms, as a result P2(2 ms done, 1 msleft) is preemptied and P4 is executed.
After the completion of P4, process P2 is picked up and finishes, then P2 will get executed and at
last P1.
The Pre-emptive SJF is also known as Shortest Remaining Time First, because at any given point
1082
of time, the job with the shortest remaining time is executed first.

Priority CPU Scheduling


In the Shortest Job First scheduling algorithm, the priority of a process is generally the inverse of
the CPU burst time, i.e. the larger the burst time the lower is the priority of that process.
In case of priority scheduling the priority is not always set as the inverse of the CPU burst time,
rather it can be internally or externally set, but yes the schedulingis done on the basis of priority of
the process where the process which is most urgent is processed first, followed by the ones with
lesser priority in order.

Processes with same priority are executed in FCFS manner.

The priority of process, when internally defined, can be decided based


on memory requirements, time limits ,number of open files, ratio of I/O burst toCPU burst etc.
Whereas, external priorities are set based on criteria outside the operating system, like the
importance of the process, funds paid for the computer resourceuse, makrte factor etc.

Types of Priority Scheduling Algorithm


Priority scheduling can be of two types:
1. Preemptive Priority Scheduling: If the new process arrived at the ready queue has a higher
priority than the currently running process, the CPU is preempted, which means the
processing of the current process is stoped and the incoming new process with higher
priority gets the CPU for its execution.
2. Non-Preemptive Priority Scheduling: In case of non-preemptive priority scheduling
algorithm if a new process arrives with a higher priority than thecurrent running process, the
incoming process is put at the head of the ready queue, which means after the execution of
the current process it willbe processed.

Example of Priority Scheduling Algorithm


Consider the below table fo processes with their respective CPU burst times andthe priorities.

1083
As you can see in the GANTT chart that the processes are given CPU time just on the basis of the
priorities.

Problem with Priority Scheduling Algorithm


In priority scheduling algorithm, the chances of indefinite blocking or starvation.
A process is considered blocked when it is ready to run but has to wait for the CPU as some other
process is running currently.
But in case of priority scheduling if new higher priority processes keeps coming in the ready queue
then the processes waiting in the ready queue with lower priority may have to wait for long
durations before getting the CPU for execution.
In 1973, when the IBM 7904 machine was shut down at MIT, a low-priority process was found
which was submitted in 1967 and had not yet been run.

Using Aging Technique with Priority Scheduling


To prevent starvation of any process, we can use the concept of aging where we keep on
increasing the priority of low-priority process based on the its waiting time.
For example, if we decide the aging factor to be 0.5 for each day of waiting, then if a process with
priority 20(which is comparitively low priority) comes in the ready queue. After one day of waiting,
its priority is increased to 19.5 and so on.
Doing so, we can ensure that no process will have to wait for indefinite time for getting CPU time
for processing.

Round Robin Scheduling


• A fixed time is allotted to each process, called quantum, for execution.
• Once a process is executed for given time period that process is preemptied and other
process executes for given time period.
• Context switching is used to save states of preemptied processes.

1084
Multilevel Queue Scheduling
Another class of scheduling algorithms has been created for situations in which processes are
easily classified into different groups.
For example: A common division is made between foreground(or interactive) processes and
background (or batch) processes. These two types of processes have different response-time
requirements, and so might have different scheduling needs. In addition, foreground processes
may have priority over background processes.
A multi-level queue scheduling algorithm partitions the ready queue into several separate queues.
The processes are permanently assigned to one queue, generally based on some property of the
process, such as memory size, process priority, or process type. Each queue has its own
scheduling algorithm.

For example: separate queues might be used for foreground and background processes. The
foreground queue might be scheduled by Round Robin algorithm, while the background queue is
scheduled by an FCFS algorithm.
In addition, there must be scheduling among the queues, which is commonly implemented as
fixed-priority preemptive scheduling. For example: The foreground queue may have absolute
priority over the background queue.
An example of a multilevel queue-scheduling algorithm with five queues:
1. System Processes
2. Interactive Processes
3. Interactive Editing Processes
4. Batch Processes
5. Student Processes

Each queue has absolute priority over lower-priority queues. No process in the batch queue, for
example, could run unless the queues for system processes, interactive processes, and interactive
1085
editing processes were all empty. If an interactive editing process entered the ready queue while a
batch process wasrunning, the batch process will be preempted.

Multilevel Feedback Queue Scheduling


In a multilevel queue-scheduling algorithm, processes are permanently assigned to a queue on
entry to the system. Processes do not move between queues. Thissetup has the advantage of low
scheduling overhead, but the disadvantage of being inflexible.
Multilevel feedback queue scheduling, however, allows a process to move between queues. The
idea is to separate processes with different CPU-burst characteristics. If a process uses too much
CPU time, it will be moved to a lower- priority queue. Similarly, a process that waits too long in a
lower-priority queue may be moved to a higher-priority queue. This form of aging prevents
starvation.

An example of a multilevel feedback queue can be seen in the below figure.


In general, a multilevel feedback queue scheduler is defined by the followingparameters:
• The number of queues.
• The scheduling algorithm for each queue.
• The method used to determine when to upgrade a process to a higher-priority queue.
• The method used to determine when to demote a process to a lower-priority queue.
• The method used to determine which queue a process will enter when that process needs
service.
1086
The definition of a multilevel feedback queue scheduler makes it the most generalCPU-scheduling
algorithm. It can be configured to match a specific system under design. Unfortunately, it also
requires some means of selecting values for all the parameters to define the best scheduler.
Although a multilevel feedback queue is the most general scheme, it is also the most complex.

Thread Scheduling
Scheduling of threads involves two boundary scheduling,
• Scheduling of user level threads (ULT) to kernel level threads (KLT) vialeightweight process
(LWP) by the application developer.
• Scheduling of kernel level threads by the system scheduler to perform different unique os
functions.

Leightweight Process (LWP) :


Light-weight process are threads in the user space that acts as an interface for the ULT to access
the physical CPU resources. Thread library schedules which thread of a process to run on which
LWP and how long. The number of LWP created by the thread library depends on the type of
application. In the case of an I/O bound application, the number of LWP depends on the number of
user-level threads.
This is because when an LWP is blocked on an I/O operation, then to invoke the other ULT the
thread library needs to create and schedule another LWP. Thus, in an I/O bound application, the
number of LWP is equal to the number of the ULT. In the case of a CPU bound application, it
depends only on the application. Each LWP is attached to a separate kernel-level thread.

1087
In real-time, the first boundary of thread scheduling is beyond specifying the scheduling policy and
the priority. It requires two controls to be specified for the User level threads: Contention scope,
and Allocation domain.
These are explainedas following below.
1. Contention Scope :
The word contention here refers to the competition or fight among the User level threads to
access the kernel resources. Thus, this control defines the extent to which contention takes
place. It is defined by the application developer using the thread library. Depending upon the
extent of contention it is classified as Process Contention Scope and System Contention
Scope.

1. Process Contention Scope (PCS) –


The contention takes place among threads within a same process. Thethread library schedules
the high-prioritized PCS thread to access the resources via available LWPs (priority as
specified by the applicationdeveloper during thread creation).
2. System Contention Scope (SCS) –
The contention takes place among all threads in the system. In this case, every SCS thread is
associated to each LWP by the thread library and are scheduled by the system scheduler to
access the kernel resources.

In LINUX and UNIX operating systems, the POSIX Pthread library provides a function
Pthread_attr_setscope to define the type of contention scope for athread during its creation.
int Pthread_attr_setscope(pthread_attr_t *attr, int scope)
The first parameter denotes to which thread within the process the scope isdefined.
The second parameter defines the scope of contention for the threadpointed. It takes two values.

PTHREAD_SCOPE_SYSTEM
PTHREAD_SCOPE_PROCESS
If the scope value specified is not supported by the system, then the function returns ENOTSUP.

2. Allocation Domain :
The allocation domain is a set of one or more resources for which a thread is competing. In a
multicore system, there may be one or more allocation domains where each consists of one or
more cores. One ULT can be a part of one or more allocation domain. Due to this high complexity
in dealing with hardware and software architectural interfaces, this control is not specified. But by
default, themulticore system will have an interface that affects the allocation domain of a thread.
Consider a scenario, an operating system with three process P1, P2, P3 and 10 user level threads
(T1 to T10) with a single allocation domain. 100% of CPU resources will be distributed among all
the three processes. The amount of CPU resources allocated to each process and to each thread
depends on the contention scope, scheduling policy and priority of each thread defined by the
application developer using thread library and also depends on the system scheduler. These User
level threads are of a different contention scope.

1088
In this case, the contention for allocation domain takes place as follows,

1. Process P1:
All PCS threads T1, T2, T3 of Process P1 will compete among themselves. The PCS threads of
the same process can share one or more LWP. T1 and T2share an LWP and T3 are allocated to
a separate LWP. Between T1 and T2 allocation of kernel resources via LWP is based on
preemptive priority scheduling by the thread library. A Thread with a high priority will preempt
low priority threads. Whereas, thread T1 of process p1 cannot preempt thread T3 of process
p3 even if the priority of T1 is greater than the priority of T3. If the priority is equal, then the
allocation of ULT to available LWPs is based on the scheduling policy of threads by the system
scheduler(not by thread library, in this case).
2. Process P2:
Both SCS threads T4 and T5 of process P2 will compete with processes P1 asa whole and with
SCS threads T8, T9, T10 of process P3. The system scheduler will schedule the kernel
resources among P1, T4, T5, T8, T9, T10, and PCS threads (T6, T7) of process P3 considering
each as a separate process. Here, the Thread library has no control of scheduling the ULT to
thekernel resources.
3. Process P3:
Combination of PCS and SCS threads. Consider if the system scheduler allocates 50% of CPU
resources to process P3, then 25% of resources is for process scoped threads and the remaining
25% for system scoped threads. The PCS threads T6 and T7 will be allocated to access the 25%
resources based on the priority by the thread library. The SCS threads T8, T9, T10 will divide the
1089
25% resources among themselves and access the kernel resources via separate LWP and KLT.
The SCS scheduling is by the system scheduler.

Note:
For every system call to access the kernel resources, a Kernel Level thread is created and
associated to separate LWP by the system scheduler.
Number of Kernel Level Threads = Total Number of LWP
Total Number of LWP = Number of LWP for SCS + Number of LWP for PCS
Number of LWP for SCS = Number of SCS threads
Number of LWP for PCS = Depends on application developer
Here,

Number of SCS threads = 5


Number of LWP for PCS = 3
Number of SCS threads = 5
Number of LWP for SCS = 5
Total Number of LWP = 8 (=5+3)
Number of Kernel Level Threads = 8

Advantages of PCS over SCS :


• If all threads are PCS, then context switching, synchronization, scheduling everything takes
place within the userspace. This reduces system calls andachieves better performance.
• PCS is cheaper than SCS.
• PCS threads share one or more available LWPs. For every SCS thread, a separate LWP is
[Link] every system call, a separate KLT is created.
• The number of KLT and LWPs created highly depends on the number of SCS threads
created. This increases the kernel complexity of handling scheduling and synchronization.
Thereby, results in a limitation over SCS thread creation, stating that, the number of SCS
threads to be smaller than the number of PCS threads.
• If the system has more than one allocation domain, then scheduling and synchronization of
resources becomes more tedious. Issues arise when an SCS thread is a part of more than
one allocation domain, the system has tohandle n number of interfaces.

The second boundary of thread scheduling involves CPU scheduling by the system scheduler. The
scheduler considers each kernel-level thread as a separate process and provides access to the
kernel resources.

Multiple-Processor Scheduling
In multiple-processor scheduling multiple CPU’s are available and hence Load Sharing becomes
1090
possible. However multiple processor scheduling is
more complex as compared to single processor scheduling. In multiple processor scheduling
there are cases when the processors are identical i.e. HOMOGENEOUS, in terms of their
functionality, we can use any processor available to run any process in the queue.

Approaches to Multiple-Processor Scheduling –


One approach is when all the scheduling decisions and I/O processing are handled by a single
processor which is called the Master Server and the other processors executes only the user
code. This is simple and reduces the need of data sharing. This entire scenario is called
Asymmetric Multiprocessing.

A second approach uses Symmetric Multiprocessing where each processor is self scheduling. All
processes may be in a common ready queue or each processor may have its own private queue
for ready processes. The scheduling proceeds further by having the scheduler for each processor
examine the ready queue andselect a process to execute.
Processor Affinity –
Processor Affinity means a processes has an affinity for the processor on which it is currently
running.
When a process runs on a specific processor there are certain effects on the cache memory. The
data most recently accessed by the process populate the cache for the processor and as a result
successive memory access by the process are often satisfied in the cache memory. Now if the
process migrates to another processor, the contents of the cache memory must be invalidated for
the first processor and the cache for the second processor must be repopulated. Because of the
high cost of invalidating and repopulating caches, most of the SMP(symmetric multiprocessing)
systems try to avoid migration of processes from one processor to another and try to keep a
process running on the same processor. This is known as PROCESSOR AFFINITY.
There are two types of processor affinity:
1. Soft Affinity – When an operating system has a policy of attempting to keep a process
running on the same processor but not guaranteeing it willdo so, this situation is called soft
affinity.
2. Hard Affinity – Hard Affinity allows a process to specify a subset of processors on which it
may run. Some systems such as Linux implements soft affinity but also provide some
system calls like sched_setaffinity() thatsupports hard affinity.

Load Balancing –
Load Balancing is the phenomena which keeps
the workload evenly distributed across all processors in an SMP system. Load balancing is
necessary only on systems where each processor has its own private queue of process which are
eligible to execute. Load balancing is unnecessary because once a processor becomes idle it
immediately extracts a runnable process from the common run queue. On SMP(symmetric
multiprocessing), it is important to keep the workload balanced among all processors to fully
utilize the benefits of having more than one processor else one or more processor will sitidle while
other processors have high workloads along with lists of processors awaiting the CPU.
There are two general approaches to load balancing :
1. Push Migration – In push migration a task routinely checks the load on each processor and
if it finds an imbalance then it evenly distributes load on each processors by moving the
processes from overloaded to idle or lessbusy processors.
1091
2. Pull Migration – Pull Migration occurs when an idle processor pulls a waiting task from a
busy processor for its execution.

Multicore Processors –
In multicore processors multiple processor cores are places on the same physical chip. Each core
has a register set to maintain its architectural state and thus appears to the operating system as a
separate physical processor.

SMP systems that use multicore processors are faster and consume less power than systems in
which each processor has its own physical chip.

However multicore processors may complicate the scheduling problems. When processor
accesses memory then it spends a significant amount of time waiting for the data to become
available. This situation is called MEMORY STALL. It occurs for various reasons such as cache
miss, which is accessing the data that is not in the cache memory. In such cases the processor
can spend upto fifty percent of its time waiting for data to become available from the memory. To
solve this problem recent hardware designs have implemented multithreaded processor cores in
which two or more hardware threads are assigned to each core.
Therefore if one thread stalls while waiting for the memory, core can switch toanother thread.
There are two ways to multithread a processor :

1. Coarse-Grained Multithreading – In coarse grained multithreading a thread executes on a


processor until a long latency event such as a memory stall occurs, because of the delay
caused by the long latency event, the processor must switch to another thread to begin
execution. The cost of switching between threads is high as the instruction pipeline must be
terminated before the other thread can begin execution on the processor core. Once this new
thread begins execution it begins filling the pipeline with its instructions.

2. Fine-Grained Multithreading – This multithreading switches between threads at a much finer


level mainly at the boundary of an instruction cycle. The architectural design of fine grained
systems include logic for thread switching and as a result the cost of switching between
threads is small.

Virtualization and Threading –


In this type of multiple-processor scheduling even a single CPU system acts like a multiple-
processor system. In a system with Virtualization, the virtualization presents one or more virtual
CPU to each of virtual machines running on the system and then schedules the use of physical
CPU among the virtual machines. Most virtualized environments have one host operating system
and many guest operating systems. The host operating system creates and manages the virtual
machines. Each virtual machine has a guest operating system installed and applications run
within that [Link] guest operating system may be assigned for specific use
cases,applications or users including time sharing or even real- time operation. Any guest
operating-system scheduling algorithm that assumes a certain amount of progress in a given
amount of time will be negatively impacted by the virtualization. A time sharing operating system
tries to allot 100 milliseconds to each time slice to give users a reasonable response time. A given
100 millisecond time slice may take much more than 100 milliseconds of virtual CPU time.
Depending on how busy the system is, the time slice may take a secondor more which results in a

1092
very poor response time for users logged into that virtual machine. The net effect of such
scheduling layering is that individual virtualized operating systems receive only a portion of the
available CPU cycles, even though they believe they are receiving all cycles and that they are
scheduling all of those [Link], the time-of-day clocks in virtual machines are incorrect
because timers take no longer to trigger than they would on dedicated CPU’s.

Virtualizations can thus undo the good scheduling-algorithm efforts of the operating systems
within virtual machines.

Scheduling in Real Time Systems


Real-time systems are systems that carry real-time tasks. These tasks need to be performed
immediately with a certain degree of urgency. In particular, these tasks are related to control of
certain events (or) reacting to them. Real-time tasks can be classified as hard real-time tasks and
soft real-time tasks.

A hard real-time task must be performed at a specified time which could otherwise lead to huge
losses. In soft real-time tasks, a specified deadline can bemissed. This is because the task can be
rescheduled (or) can be completed after the specified time, In real-time systems, the scheduler is
considered as the most important component which is typically a short-term task scheduler. The
main focus of this scheduler is to reduce the response time associated with each of the
associatedprocesses instead of handling the deadline.

If a preemptive scheduler is used, the real-time task needs to wait until its corresponding tasks
time slice completes. In the case of a non-preemptive scheduler, even if the highest priority is
allocated to the task, it needs to wait untilthe completion of the current task. This task can be slow
(or) of the lower priority and can lead to a longer wait.

A better approach is designed by combining both preemptive and non- preemptive scheduling.
This can be done by introducing time-based interrupts in priority based systems which means the
currently running process is interrupted on a time-based interval and if a higher priority process is
present in a ready queue, it is executed by preempting the current process.

Based on schedulability, implementation (static or dynamic), and the result (self or dependent) of
analysis, the scheduling algorithm are classified as follows.
1. Static table-driven approaches:
These algorithms usually perform a static analysis associated with scheduling and capture the
schedules that are advantageous. This helps in providing a schedule that can point out a task
with which the execution must be started at run time.
2. Static priority-driven preemptive approaches:
Similar to the first approach, these type of algorithms also uses static analysis of scheduling.
The difference is that instead of selecting a particular schedule, it provides a useful way of
assigning priorities amongvarious tasks in preemptive scheduling.
3. Dynamic planning-based approaches:
Here, the feasible schedules are identified dynamically (at run time). It carries a certain fixed
time interval and a process is executed if and only ifsatisfies the time constraint.
4. Dynamic best effort approaches:
These types of approaches consider deadlines instead of feasible schedules. Therefore the
1093
task is aborted if its deadline is reached. This approach is used widely is most of the real-time
systems.

Deadlock
Deadlocks are a set of blocked processes each holding a resource and waiting to acquire a
resource held by another process.

How to avoid Deadlocks


Deadlocks can be avoided by avoiding at least one of the four conditions, because all this four
conditions are required simultaneously to cause deadlock.
1. Mutual Exclusion
Resources shared such as read-only files do not lead to deadlocks but resources, such as
printers and tape drives, requires exclusive access by a single process.
2. Hold and Wait
In this condition processes must be prevented from holding one or more resources while
simultaneously waiting for one or more others.
3. No Preemption
Preemption of process resource allocations can avoid the condition of deadlocks, where
ever possible.
4. Circular Wait
Circular wait can be avoided if we number all resources, and require that processes request
resources only in strictly increasing(or decreasing) order.

Handling Deadlock
The above points focus on preventing deadlocks. But what to do once a deadlock has occured.
Following three strategies can be used to remove deadlock after itsoccurrence.
1. Preemption
We can take a resource from one process and give it to other. This will resolve the deadlock
situation, but sometimes it does causes problems.
2. Rollback
In situations where deadlock is a real possibility, the system can periodically make a record of
the state of each process and when deadlock occurs, roll everything back to the last
checkpoint, and restart, but allocating resources differently so that deadlock does not occur.
3. Kill one or more processes This is the simplest way, but it [Link] is a Livelock?
There is a variant of deadlock called livelock. This is a situation in which two or more
processes continuously change their state in response to changes in the other process(es)
1094
without doing any useful work. This is similar to deadlock in that no progress is made but
differs in that neither process is blocked or waiting for anything.

A human example of livelock would be two people who meet face-to-face in a corridor and each
moves aside to let the other pass, but they end up swaying from side to side without making any
progress because they always move thesame way at the same time.

Deadlock Characterization
A deadlock happens in operating system when two or more processes need some resource to
complete their execution that is held by the other process.
A deadlock occurs if the four Coffman conditions hold true. But these conditions are not mutually
exclusive. They are given as follows –

Mutual Exclusion
There should be a resource that can only be held by one process at a time. In the diagram below,
there is a single instance of Resource 1 and it is held by Process 1only.

Hold and Wait


A process can hold multiple resources and still request more resources from other processes
which are holding them. In the diagram given below, Process 2 holds Resource 2 and Resource 3
and is requesting the Resource 1 which is held by Process 1.

No Preemption
A resource cannot be preempted from a process by force. A process can only release a resource
voluntarily. In the diagram below, Process 2 cannot preempt Resource 1 from Process 1. It will
only be released when Process 1 relinquishes itvoluntarily after its execution is complete.

Circular Wait
A process is waiting for the resource held by the second process, which is waiting for the resource
held by the third process and so on, till the last process is waiting for a resource held by the first
process. This forms a circular chain. For example: Process 1 is allocated Resource2 and it is
1095
requesting Resource 1. Similarly, Process2 is allocated Resource 1 and it is requesting Resource 2.
This forms a circular waitloop.

Deadlock Prevention And AvoidanceDeadlock Prevention


We can prevent Deadlock by eliminating any of the above four conditions.

Eliminate Mutual Exclusion


It is not possible to dis-satisfy the mutual exclusion because some resources, such as the tape
drive and printer, are inherently non-shareable.

Eliminate Hold and wait


1. Allocate all required resources to the process before the start of its execution, this way
hold and wait condition is eliminated but it will lead to low device utilization. for example, if
a process requires printer at a later time and we have allocated printer before the start of its
execution printerwill remain blocked till it has completed its execution.
2. The process will make a new request for resources after releasing the current set of
resources. This solution may lead to starvation.

Eliminate No Preemption
Preempt resources from the process when resources required by other highpriority processes.

Eliminate Circular Wait


Each resource will be assigned with a numerical number. A process can request the resources
increasing/decreasing. order of numbering.
1096
For Example, if P1 process is allocated R5 resources, now next time if P1 ask for R4, R3 lesser
than R5 such request will not be granted, only request for resourcesmore than R5 will be granted.

Deadlock Avoidance
Deadlock avoidance can be done with Banker’s Algorithm.

Banker’s Algorithm
Bankers’s Algorithm is resource allocation and deadlock avoidance algorithm which test all the
request made by processes for resources, it checks for the safe state, if after granting request
system remains in the safe state it allows the request and if there is no safe state it doesn’t allow
the request made by theprocess.

Inputs to Banker’s Algorithm:


1. Max need of resources by each process.
2. Currently allocated resources by each process.
3. Max free available resources in the system.

The request will only be granted under the below condition:


1. If the request made by the process is less than equal to max need to thatprocess.
2. If the request made by the process is less than equal to the freely available resource in the
system.
Example:

1097
Total resources in system:
ABCD
6576
Available system resources are:
ABCD
3112
Processes (currently allocated resources):
ABCD
P1 1 2 2 1
P2 1 0 3 3
P3 1 2 1 0
Processes (maximum resources):
ABCD
P1 3 3 2 2
P2 1 2 3 4
P3 1 3 5 0
Need = maximum resources - currently allocated resources.
Processes (need resources):
ABCD
P1 2 1 0 1
P2 0 2 0 1
P3 0 1 4 0

Note:Deadlock prevention is more strict that Deadlock Avoidance.

Deadlock Detection And RecoveryDeadlock Detection


1. If resources have single instance:
In this case for Deadlock detection we can run an algorithm to check for cycle in the Resource
Allocation Graph. Presence of cycle in the graph is thesufficient condition for deadlock.

1098
In the above diagram, resource 1 and resource 2 have single instances. There is a cycle R1 →
P1 → R2 → P2. So, Deadlock is Confirmed.
2. If there are multiple instances of resources:
Detection of the cycle is necessary but not sufficient condition for deadlock detection, in this
case, the system may or may not be in deadlock varies according to different situations.

Deadlock Recovery
A traditional operating system such as Windows doesn’t deal with deadlock recovery as it is time
and space consuming process. Real-time operating systemsuse Deadlock recovery.
Recovery method

1. Killing the process: killing all the process involved in the deadlock. Killing process one by one.
After killing each process check for deadlock again keep repeating the process till system
recover from deadlock.
2. Resource Preemption: Resources are preempted from the processes involved in the deadlock,
preempted resources are allocated to other processes so that there is a possibility of
recovering the system from deadlock. In this case, the system goes into starvation.

Memory Management
Memory management is the functionality of an operating system which handles or manages
primary memory and moves processes back and forth between main memory and disk during
execution. Memory management keeps track of each and every memory location, regardless of
either it is allocated to some process orit is free. It checks how much memory is to be allocated to
processes. It decides which process will get memory at what time. It tracks whenever some
memory gets freed or unallocated and correspondingly it updates the status.

1099
Process Address Space
The process address space is the set of logical addresses that a process references in its code.
For example, when 32-bit addressing is in use, addresses can range from 0 to 0x7fffffff; that is,
2^31 possible numbers, for a total theoretical size of 2gigabytes.
The operating system takes care of mapping the logical addresses to physical addresses at the
time of memory allocation to the program. There are three types of addresses used in a program
before and after memory is allocated −

S.N. Memory Addresses & Description


1 Symbolic addresses

The addresses used in a source code. The variable names, constants, and
instruction labels are the basic elements of the symbolic address space.
2 Relative addresses
At the time of compilation, a compiler converts symbolic addresses into relative
addresses.
3 Physical addresses
The loader generates these addresses at the time when a program is loaded into
main memory.

Virtual and physical addresses are the same in compile-time and load-time address-binding
schemes. Virtual and physical addresses differ in execution-timeaddress-binding scheme.
The set of all logical addresses generated by a program is referred to as a logical address space.
The set of all physical addresses corresponding to these logical addresses is referred to as a
physical address space.

The runtime mapping from virtual to physical address is done by the memory management unit
(MMU) which is a hardware device. MMU uses following mechanism to convert virtual address to
physical address.
• The value in the base register is added to every address generated by a user process, which
is treated as offset at the time it is sent to memory. For example, if the base register value
is 10000, then an attempt by the user to use address location 100 will be dynamically
reallocated to location 10100.
• The user program deals with virtual addresses; it never sees the realphysical addresses.

Static vs Dynamic Loading


The choice between Static or Dynamic Loading is to be made at the time of computer program
being developed. If you have to load your program statically, then at the time of compilation, the
complete programs will be compiled and linked without leaving any external program or module
dependency. The linker combines the object program with other necessary object modules into an
absolute program, which also includes logical addresses.

If you are writing a Dynamically loaded program, then your compiler will compile the program and
for all the modules which you want to include dynamically, onlyreferences will be provided and rest
1100
of the work will be done at the time of execution.
At the time of loading, with static loading, the absolute program (and data) is loaded into memory
in order for execution to start.
If you are using dynamic loading, dynamic routines of the library are stored on adisk in relocatable
form and are loaded into memory only when they are neededby the program.

Static vs Dynamic Linking


As explained above, when static linking is used, the linker combines all other modules needed by a
program into a single executable program to avoid anyruntime dependency.
When dynamic linking is used, it is not required to link the actual module or library with the
program, rather a reference to the dynamic module is provided at the time of compilation and
linking. Dynamic Link Libraries (DLL) in Windows and Shared Objects in Unix are good examples
of dynamic libraries.

Swapping
Swapping is a mechanism in which a process can be swapped temporarily out ofmain memory (or
move) to secondary storage (disk) and make that memory available to other processes. At some
later time, the system swaps back the process from the secondary storage to main memory.
Though performance is usually affected by swapping process but it helps in running multiple and
big processes in parallel and that's the reason Swapping isalso known as a technique for memory
compaction.

The total time taken by swapping process includes the time it takes to move the entire process to
a secondary disk and then to copy the process back to memory, as well as the time the process
takes to regain main memory.

1101
Assume that the user process is of size 2048KB and on a standard hard disk where swapping will
take place has a data transfer rate around 1 MB per second. The actual transfer of the 1000K
process to or from memory will take
2048KB / 1024KB per second
= 2 seconds
= 2000 milliseconds
Now considering in and out time, it will take complete 4000 milliseconds plus other overhead
where the process competes to regain main memory.

Memory Allocation
Main memory usually has two partitions −
• Low Memory − Operating system resides in this memory.
• High Memory − User processes are held in high memory. Operating system uses the
following memory allocation mechanism.

S.N. Memory Allocation & Description

Single-partition allocation
In this type of allocation, relocation-register scheme is used to protect user processes from
1 each other, and from changing operating-system code and data. Relocation register
contains value of smallest physical address whereaslimit register contains range of logical
addresses. Each logical address must be less than the limit register.

Multiple-partition allocation
In this type of allocation, main memory is divided into a number of fixed- sized partitions
2 where each partition should contain only one process. Whena partition is free, a process is
selected from the input queue and is loaded into the free partition. When the process
terminates, the partition becomes available for another process.

Fragmentation
As processes are loaded and removed from memory, the free memory space is broken into little
pieces. It happens after sometimes that processes cannot be allocated to memory blocks
considering their small size and memory blocks remains unused. This problem is known as
Fragmentation.

1102
Fragmentation is of two types –
S.N. Fragmentation & Description
1 External fragmentation
Total memory space is enough to satisfy a request or to reside a process in
it, but it is not contiguous, so it cannot be used.
2 Internal fragmentation
Memory block assigned to process is bigger. Some portion of memory isleft
unused, as it cannot be used by another process.

The following diagram shows how fragmentation can cause waste of memory and a compaction
technique can be used to create more free memory out of fragmented memory –

External fragmentation can be reduced by compaction or shuffle memorycontents to place all free
memory together in one large block. To make compaction feasible, relocation should be dynamic.
The internal fragmentation can be reduced by effectively assigning the smallest partition but large
enough for the process.

Paging
A computer can address more memory than the amount physically installed on the system. This
extra memory is actually called virtual memory and it is a section of a hard that's set up to emulate
the computer's RAM. Paging technique plays animportant role in implementing virtual memory.
A non-contiguous policy with a fixed size partition is called paging. A computer can address more
memory than the amount of physically installed on the system. This extra memory is actually
called virtual memory. Paging technique is very important in implementing virtual memory.
Secondary memory is divided into equal size partition (fixed) called pages. Every process will have
a separate page table. The entries in the page table are the number of pages a process. At each
entry either we have an invalid pointer which means the page is not in main memory or we will get
the corresponding frame number. When the frame number is combined with instruction of set D
than we will get the corresponding physical address. Size of a page table is generally very large so
cannot be accommodated inside the PCB, therefore, PCB contains a register value PTBR( page

1103
table base register) which leads to the page table.

Paging is a memory management technique in which process address space is broken into blocks
of the same size called pages (size is power of 2, between 512 bytes and 8192 bytes). The size of
the process is measured in the number of pages.

Similarly, main memory is divided into small fixed-sized blocks of (physical) memory called
frames and the size of a frame is kept the same as that of a page to have optimum utilization of
the main memory and to avoid externalfragmentation.

Address Translation
Page address is called logical address and represented by page number andthe offset.
Logical Address = Page number + page offset
Frame address is called physical address and represented by a frame number andthe offset.
Physical Address = Frame number + page offset
A data structure called page map table is used to keep track of the relation between a page of a
process to a frame in physical memory.

1104
When the system allocates a frame to any page, it translates this logical address into a physical
address and create entry into the page table to be used throughout execution of the program.
When a process is to be executed, its corresponding pages are loaded into any available memory
frames. Suppose you have a program of 8Kb but your memory can accommodate only 5Kb at a
given point in time, then the paging concept will come into picture. When a computer runs out of
RAM, the operating system (OS) will move idle or unwanted pages of memory to secondary
memory to free up RAM for other processes and brings them back when needed by the program.
This process continues during the whole execution of the program where the OS keeps removing
idle pages from the main memory and write them onto the secondary memory and bring them
back when required by the program.

Advantages and Disadvantages of Paging


Here is a list of advantages and disadvantages of paging −
• Paging reduces external fragmentation, but still suffer from internalfragmentation.
• Paging is simple to implement and assumed as an efficient memory management
technique.
• Due to equal size of the pages and frames, swapping becomes very easy.
• Page table requires extra memory space, so may not be good for a system having small
RAM.

Segmentation
Segmentation is a memory management technique in which each job is divided into several
segments of different sizes, one for each module that contains pieces that perform related
functions. Each segment is actually a different logical address space of the program.
When a process is to be executed, its corresponding segmentation are loaded into non-contiguous
memory though every segment is loaded into a contiguous block of available memory.
Segmentation memory management works very similar to paging but here segments are of
variable-length where as in paging pages are of fixed size.

A program segment contains the program's main function, utility functions, data structures, and
so on. The operating system maintains a segment map table for every process and a list of free
1105
memory blocks along with segment numbers, their size and corresponding memory locations in
main memory. For each segment, the table stores the starting address of the segment and the
length of the segment. Areference to a memory location includes a value that identifies a segment
and an offset.

Segmentation is a programmer view of the memory where instead of dividing a process into equal
size partition we divided according to program into partition called segments. The translation is
the same as paging but paging segmentation is independent of internal fragmentation but suffers
from external fragmentation.

Reason of external fragmentation is program can be divided into segments but segment must be
contiguous in nature.

Segmentation with paging


In segmentation with paging, we take advantages of both segmentation as well as paging. It is a
kind of multilevel paging but in multilevel paging, we divide a page table into equal size partition
but here in segmentation with paging, we divide it according to segments. All the properties are
the same as that of paging because segments are divided into pages.

Contiguous memory allocation


In contiguous memory allocation, all the available memory space remain together in one place. It
means freely available memory partitions are not scattered here and there across the whole
memory space.
1106
In the contiguous memory allocation, both the operating system and the user must reside in the
main memory. The main memory is divided into two portions one portion is for the operating and
other is for the user program.
In the contiguous memory allocation when any user process request for the memory a single
section of the contiguous memory block is given to that process according to its need. We can
achieve contiguous memory allocation by dividing memory into the fixed-sized partition.
A single process is allocated in that fixed sized single partition. But this will increase the degree of
multiprogramming means more than one process in the main memory that bounds the number of
fixed partition done in memory. Internal fragmentation increases because of the contiguous
memory allocation.

→ Fixed sized partition


In the fixed sized partition the system divides memory into fixed size partition (may or may not be
of the same size) here entire partition is allowed to a process and if there is some wastage inside
the partition is allocated to a process and if there is some wastage inside the partition then it is
called internal fragmentation.
Advantage: Management or book keeping is easy.
Disadvantage: Internal fragmentation

→ Variable size partition


In the variable size partition, the memory is treated as one unit and space allocated to a process is
exactly the same as required and the leftover space canbe reused again.

Advantage: There is no internal fragmentation.


Disadvantage: Management is very difficult as memory is becoming purelyfragmented after some
time.

1107
Demand Paging
According to the concept of Virtual Memory, in order to execute some process, only a part of the
process needs to be present in the main memory which means that only a few pages will only be
present in the main memory at any time.
However, deciding, which pages need to be kept in the main memory and which need to be kept in
the secondary memory, is going to be difficult because we cannot say in advance that a process
will require a particular page at particular time.
Therefore, to overcome this problem, there is a concept called Demand Paging is introduced. It
suggests keeping all pages of the frames in the secondary memoryuntil they are required. In other
words, it says that do not load any page in the main memory until it is required.
Whenever any page is referred for the first time in the main memory, then thatpage will be found in
the secondary memory.
After that, it may or may not be present in the main memory depending upon thepage replacement
algorithm which will be covered later in this tutorial.

What is a Page Fault?


If the referred page is not present in the main memory then there will be a miss and the concept is
called Page miss or page fault.
The CPU has to access the missed page from the secondary memory. If the number of page fault
is very high then the effective access time of the system willbecome very high.

What is Thrashing?
If the number of page faults is equal to the number of referred pages or the number of page faults
are so high so that the CPU remains busy in just reading the pages from the secondary memory
then the effective access time will be the time taken by the CPU to read one word from the
secondary memory and it will be so high. The concept is called thrashing.
If the page fault rate is PF %, the time taken in getting a page from the secondary memory and
again restarting is S (service time) and the memory access time is ma then the effective access
time can be given as;
1. EAT = PF X S + (1 - PF) X (ma)

Page Replacement Algorithms


In an operating system that uses paging for memory management, a page replacement algorithm
is needed to decide which page needs to be replacedwhen new page comes in.
Page Fault – A page fault happens when a running program accesses a memory page that is
mapped into the virtual address space, but not loaded in physical memory.
Since actual physical memory is much smaller than virtual memory, page faults happen. In case of
page fault, Operating System might have to replace one of the existing pages with the newly
needed page. Different page replacement algorithms suggest different ways to decide which page
to replace. The target forall algorithms is to reduce the number of page faults.

Page Replacement Algorithms :


• First In First Out (FIFO) –
This is the simplest page replacement algorithm. In this algorithm, the operating system
keeps track of all pages in the memory in a queue, the oldest page is in the front of the
queue. When a page needs to be replaced page in the front of the queue is selected for
removal.

1108
• Example-1Consider page reference string 1, 3, 0, 3, 5, 6 with 3 page [Link] number of
page faults.

Initially all slots are empty, so when 1, 3, 0 came they are allocated to the empty slots —> 3 Page
Faults.
when 3 comes, it is already in memory so —> 0 Page Faults.
Then 5 comes, it is not available in memory so it replaces the oldest page slot i.e 1. —>1 Page
Fault.
6 comes, it is also not available in memory so it replaces the oldest pageslot i.e 3 —>1 Page Fault.
Finally when 3 come it is not avilable so it replaces 0 1 page fault

Belady’s anomaly – Belady’s anomaly proves that it is possible to have more page faults when
increasing the number of page frames while using the First in First Out (FIFO) page replacement
algorithm. For example, if we consider reference string 3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, 4 and 3 slots, we
get 9 total page faults, but if weincrease slots to 4, we get 10 page faults.

• Optimal Page replacement –


In this algorithm, pages are replaced which would not be used for the longest duration of time in
the future.
Example-2:Consider the page references 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, with 4 page frame. Find
number of page fault.

Initially all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4Page faults
0 is already there so —> 0 Page fault.
when 3 came it will take the place of 7 because it is not used for the longestduration of time in the
future.—>1 Page fault.
0 is already there so —> 0 Page fault.. 4 will takes place of 1 —> 1 Page Fault.

Now for the further page reference string —> 0 Page fault because they arealready available in the
memory.
Optimal page replacement is perfect, but not possible in practice as the operating system cannot
know future requests. The use of Optimal Page replacement is to set up a benchmark so that
other replacement algorithms can be analyzed againstit.

• Least Recently Used –


In this algorithm page will be replaced which is least recently used.
Example-3Consider the page reference string 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2 with 4 page
[Link] number of page faults.

Initially all slots are empty, so when 7 0 1 2 are allocated to the empty slots —> 4Page faults
0 is already their so —> 0 Page fault.
when 3 came it will take the place of 7 because it is least recently used —>1 Pagefault
0 is already in memory so —> 0 Page fault.4 will takes place of 1 —> 1 Page Fault
Now for the further page reference string —> 0 Page fault because they arealready available in the
memory.

Storage Management
1109
The term storage management encompasses the technologies and processes organizations use
to maximize or improve the performance of their data storage resources. It is a broad category
that includes virtualization, replication, mirroring, security, compression, traffic analysis, process
automation, storage provisioning and related techniques.

By some estimates, the amount of digital information stored in the world's computer systems is
doubling every year. As a result, organizations feel constant pressure to expand their storage
capacity. However, doubling a company's

storage capacity every year is an expensive proposition. In order to reduce some of those costs
and improve the capabilities and security of their storage solutions, organizations turn to a variety
of storage management solutions.

Storage Management Benefits


Many storage management technologies, like storage virtualization, deduplication and
compression, allow companies to better utilize their existing storage. The benefits of these
approaches include lower costs -- both the one-time capital expenses associated with storage
devices and the ongoing operational costs for maintaining those devices.
Most storage management techniques also simplify the management of storage networks and
devices. That can allow companies to save time and even reduce the number of IT workers
needed to maintain their storage systems, which in turn, also reduces overall storage operating
costs.

Storage management can also help improve a data center's performance. For example,
compression and technology can enable faster I/Os, and automatic storage provisioning can
speed the process of assigning storage resources to various applications.
In addition, virtualization and automation technologies can help an organization improve its agility.
These storage management techniques make it possible to reassign storage capacity quickly as
business needs change, reducing wasted space and improving a company's ability to respond to
evolving market conditions.

Finally, many storage management technologies, such as replication, mirroring and security, can
help a data center improve its reliability and availability. These techniques are often particularly
important for backup and archive storage, although they also apply to primary storage. IT
departments often turn to these technologies for help in meeting SLAs or achieving compliance
goals.

Storage Management: Related Terms


Storage management is very closely related to Storage Resource Management (SRM). SRM often
refers particularly to software used to manage storage networks and devices. By contrast, the
term "storage management" can refer to devices and processes, as well as actual software. In
addition, SRM usually refers specifically to software for allocating storage capacity based on
company policies and ongoing events. It may include asset management, charge back, capacity
management, configuration management, data and media migration, event management,
performance and availability management, policy management, quota management, and media
management capabilities. In short, SRM is a subset of storage management; however, the two
terms are sometimes used interchangeably.

1110
Storage management is also closely associated with networked storage solutions,such as storage
area networks (SANs) and network-attached storage (NAS) devices. Because using SAN and NAS
devices is more complicated than using direct-attached storage (DAS), many organizations deploy
SRM software when they deploy their storage networking environments. However, storage
management techniques like replication, mirroring, security, compression and others can be
utilized with DAS devices as well as with SANs and NAS arrays.

Storage management is often used in virtualized or cloud computingenvironments.

Storage Management Implementation


Because storage management is such a broad category, it's difficult to provide detailed
instructions on how to install or how to use storage management technologies. In general,
storage management technology can be deployed as software or it can be included in a hardware
device. Storage management techniques can be applied to primary, backup or archived storage.
Deployment and implementation procedures will vary widely depending on the type of storage
management selected and the vendor. In addition, the skills and training of storage administrators
and other personnel add another level to an organization'sstorage management capabilities.

Storage Management Technology


The primary organization involved in establishing storage management standards is the Storage
Networking Industry Association (SNIA). It has put forth several important storage specifications,
including the Storage Management Initiative Specification (SMI-S) and the Cloud Data
Management Interface (CDMI). SMI-S defines the attributes of storage hardware, such as Fibre
Channel switches, Fibre Channel and iSCI arrays, NAS devices, tape libraries and host profiles. It
also addresses storage management software issues, such as configuration discovery,
provisioning and trending, security, asset management, compliance and cost management, event
management and data protection. The CDMI specification provides standards for cloud storage
services, enabling interoperability among various storage management solutions.

Mass storage
Mass storage refers to various techniques and devices for storing large amounts of data. The
earliest storage devices were punched paper cards, which were used as early as 1804 to control
silk-weaving looms. Modern mass storage devices include all types of disk drives and tape drives.
Mass storage is distinct from memory, which refers to temporary storage areas within the
computer. Unlike main memory, mass storage devices retain data even when the computer is
turned off.
Examples of Mass Storage Devices (MSD)
Common types of mass storage include the following:
• solid-state drives (SSD)
• hard drives
• external hard drives
• optical drives
• tape drives
• RAID storage
• USB storage
• flash memory cards
1111
Today, mass storage is measured in gigabytes (1,024 megabytes)
and terabytes(1,024 gigabytes). Older mass storage technology, such as floppy drives, are
measured in kilobytes (1,024 bytes), megabytes (1,024 kilobytes), Mass storage is sometimes
called auxiliary storage.

RAID
RAID is short for redundant array of independent disks.
Originally, the term RAID was defined as redundant array of inexpensive disks, but now it usually
refers to a redundant array of independent disks. RAID storage uses multiple disks in order to
provide fault tolerance, to improve overall performance, and to increase storage capacity in a
system. This is in contrast with older storage devices that used only a single disk drive to store
data.

RAID allows you to store the same data redundantly (in multiple paces) in a balanced way to
improve overall performance. RAID disk drives are used frequently on servers but aren't generally
necessary for personal computers.

How RAID Works


With RAID technology, data can be mirrored on one or more disks in the same array, so that if one
disk fails, the data is preserved. Thanks to a technique known as striping (a technique for
spreading data over multiple disk drives), RAID also offers the option of reading or writing to more
than one disk at the same time in order to improve performance.
In this arrangement, sequential data is broken into segments which are sent to the various disks in
the array, speeding up throughput. A typical RAID array uses multiple disks that appear to be a
single device so it can provide more storage capacity than a single disk.

Standard RAID Levels


RAID devices use many different architectures, called levels, depending on the desired balance
between performance and fault tolerance. RAID levels describe how data is distributed across the
drives. Standard RAID levels include the following:

Level 0: Striped disk array without fault tolerance


Provides data striping (spreading out blocks of each file across multiple disk drives) but no
redundancy. This improves performance but does not deliver fault tolerance. If one drive fails then
all data in the array is lost.

Level 1: Mirroring and duplexing


Provides disk mirroring. Level 1 provides twice the read transaction rate of single disks and the
same write transaction rate as single disks.

Level 2: Error-correcting coding


Not a typical implementation and rarely used, Level 2 stripes data at the bit level rather than the
block level.

Level 3: Bit-interleaved parity


Provides byte-level striping with a dedicated parity disk. Level 3, which cannot service
simultaneous multiple requests, also is rarely used.
1112
Level 4: Dedicated parity drive
A commonly used implementation of RAID, Level 4 provides block-level striping (like Level 0) with
a parity disk. If a data disk fails, the parity data is used to create a replacement disk. A
disadvantage to Level 4 is that the parity disk can create write bottlenecks.

Level 5: Block interleaved distributed parity


Provides data striping at the byte level and also stripe error correction information. This results in
excellent performance and good fault tolerance. Level 5 is one of the most popular
implementations of RAID.

Level 6: Independent data disks with double parity


Provides block-level striping with parity data distributed across all disks.

Level 10: A stripe of mirrors


Not one of the original RAID levels, multiple RAID 1 mirrors are created, and a RAID 0 stripe is
created over these.

Non-Standard RAID Levels


Some devices use more than one level in a hybrid or nested arrangement, and some vendors also
offer non-standard proprietary RAID levels. Examples of non- standard RAID levels include the
following:

Level 0+1: A Mirror of Stripes


Not one of the original RAID levels, two RAID 0 stripes are created, and a RAID 1 mirror is created
over them. Used for both replicating and sharing data among disks.

Level 7
A trademark of Storage Computer Corporation that adds caching to Levels 3 or 4.

RAID 1E
A RAID 1 implementation with more than two disks. Data striping is combined with mirroring each
written stripe to one of the remaining disks in the array.

RAID S
Also called Parity RAID, this is EMC Corporation's proprietary striped parity RAIDsystem used in its
Symmetrix storage systems.

RAID History and Alternative Storage Options


Before RAID devices became popular, most systems used a single drive to store data. This
arrangement is sometimes referred to as a SLED (single large expensive disk). However, SLEDs
have some drawbacks. First, they can create
I/O bottlenecks because the data cannot be read from the disk quickly enough to keep up with the
other components in a system, particularly the processor.
Second, if a SLED fails, all the data is lost unless it has been recently backed up onto another disk
or tape.

In 1987, three University of California, Berkeley, researchers -- David Patterson, Garth A. Gibson,
1113
and Randy Katz -- first defined the term RAID in a paper titled A Case for Redundant Arrays of
Inexpensive Disks (RAID). They theorized that spreading data across multiple drives could
improve system performance, lower costs and reduce power consumption while avoiding the
potential reliability problems inherent in using inexpensive, and less reliable, disks. The paper also
described the five original RAID levels.

Today, RAID technology is nearly ubiquitous among enterprise storage devices and is also found
in many high-capacity consumer storage devices. However, some non-RAID storage options do
exist. One alternative is JBOD (Just a Bunch of Drives). JBOD architecture utilizes multiple disks,
but each disk in the device is addressed separately. JBOD provides increased storage capacity
versus a single disk, but doesn't offer the same fault tolerance and performance benefits as RAID
devices.

Another RAID alternative is concatenation or spanning. This is the practice of combining multiple
disk drives so that they appear to be a single drive. Spanning increases the storage capacity of a
drive; however, as with JBOD, spanning doesnot provide reliability or speed benefits.

RAID Is Not Data Backup


RAID should not be confused with data backup. Although some RAID levels do provide
redundancy, experts advise utilizing a separate storage system for backup and disaster recovery
purposes.

Setting Up a RAID Array


In order to set up a RAID array, you'll need a group of disk drives and either a software or a
hardware controller. Software RAID runs directly on a server, utilizing server resources. As a result,
it may cause some applications to run more slowly. Most server operating systems include some
built-in RAID management capabilities.
You can also set up your own RAID array by adding a RAID controller to a server or a desktop PC.
The RAID controller runs essentially the same software, but it uses its own processor instead of
the system's CPU. Some less expensive "fake RAID" controllers provide RAID management
software but don't have a separate processor.
Alternatively, you can purchase a pre-built RAID array from a storage vendor. These appliances
generally include two RAID controllers and a group of disks intheir own housing.
Using a RAID array is usually no different than using any other kind of primary storage. The RAID
management will be handled by the hardware or software controller and is generally invisible to
the end user.

RAID Technology Standards


The Storage Networking Industry Association has established the Common RAIDDisk Data Format
(DDF) specification. In an effort to promote interoperability among different RAID vendors, it
defines how data should be distributed acrossthe disks in a RAID device.
Another industry group called the RAID Advisory Board worked during the 1990s to promote RAID
technology, but the group is no longer active.

Disk Structure Secondary Storage


Secondary storage devices are those devices whose memory is non volatile, meaning, the stored
data will be intact even if the system is turned off. Here are a few things worth noting about
secondary storage.
1114
• Secondary storage is also called auxiliary storage.
• Secondary storage is less expensive when compared to primary memorylike RAMs.
• The speed of the secondary storage is also lesser than that of primarystorage.
• Hence, the data which is less frequently accessed is kept in the secondarystorage.
• A few examples are magnetic disks, magnetic tapes, removable thumbdrives etc.

Magnetic Disk Structure


In modern computers, most of the secondary storage is in the form of magnetic disks. Hence,
knowing the structure of a magnetic disk is necessary to understand how the data in the disk is
accessed by the computer.

Structure of a magnetic disk


A magnetic disk contains several platters. Each platter is divided into circular shaped tracks. The
length of the tracks near the centre is less than the length of the tracks farther from the centre.
Each track is further divided into sectors, as shown in the figure.
Tracks of the same distance from centre form a cylinder. A read-write head is used to read data
from a sector of the magnetic disk.
The speed of the disk is measured as two parts:
• Transfer rate: This is the rate at which the data moves from disk to thecomputer.
• Random access time: It is the sum of the seek time and rotational latency.

Seek time is the time taken by the arm to move to the required track. Rotational latency is defined
as the time taken by the arm to reach the required sector in thetrack.
Even though the disk is arranged as sectors and tracks physically, the data is logically arranged
and addressed as an array of blocks of fixed size. The size of a block can be 512 or 1024 bytes.
Each logical block is mapped with a sector on the disk, sequentially. In this way, each sector in the
disk will have a logical address.

Operating System Input Output I/O


The three main jobs of a computer are Input, Output, and Processing. In most of the cases, the
most important job is Input / Output, and the processing is simplyincidental. For an example, when
we browse a web page or edit any file, our immediate attention is to read or enter some
information, not for computing an answer. The fundamental role of the operating system in
1115
computer Input / Output is to manage and organize I/O operations and all I/O devices.
The various devices that are connected to the computer need to be controlled and it is a key
concern of operating-system designers. This is as I/O devices vary so widely in their functionality
and speed (for example a mouse, a hard disk and a CD-ROM), varied methods are required for
controlling them. These methods form the I/O sub-system of the kernel of OS that separates the
rest of the kernel from the complications of managing I/O devices.

File Access Methods


When a file is used, information is read and accessed into computer memory andthere are several
ways to access this information of the file. Some systems provide only one access method for
files. Other systems, such as those of IBM, support many access methods, and choosing the right
one for a particular application is a major design problem.
There are three ways to access a file into a computer system: Sequential-Access, Direct Access,
Index sequential Method.

1. Sequential Access –
It is the simplest access method. Information in the file is processed in order, one record after
the other. This mode of access is by far the most common; for example, editor and compiler
usually access the file in thisfashion.
Read and write make up the bulk of the operation on a file. A read operation - read next- read
the next position of the file and automatically advance a file pointer, which keeps track I/O
location. Similarly, for the writewrite next appendto the end of the file and advance to the newly
written material.
Key points:
• Data is accessed one record right after another record in an order.
• When we use read command, it move ahead pointer by one
• When we use write command, it will allocate memory and move thepointer to the end of the file
• Such a method is reasonable for tape.

2. Direct Access –
Another method is direct access method also known as relative access method. A filed-length
logical record that allows the program to read and write record rapidly. in no particular order.
The direct access is based on the disk model of a file since disk allows random access to any
file block. For direct access, the file is viewed as a numbered sequence of block or record.
Thus, we may read block 14 then block 59 and then we can write block 17. There is no
restriction on the order of reading and writing for a direct access file.
A block number provided by the user to the operating system is normally a relative block
number, the first relative block of the file is 0 and then 1 and soon.

3. Index sequential method –


It is the other method of accessing a file which is built on the top of the direct access method.
These methods construct an index for the file. The index, like an index in the back of a book,
contains the pointer to the various blocks. To find a record in the file, we first search the index
and then by the help of pointer we access the file directly.

Key points:
• It is built on top of Sequential access.

1116
• It control the pointer by using index.

Structures of Directory
A directory is a container that is used to contain folders and file. It organizes files and folders into
a hierarchical manner.

There are several logical structures of a directory, these are given below.
1. Single-level directory –
Single level directory is simplest directory [Link] it all files are contained in same directory
which make it easy to support and understand.
A single level directory has a significant limitation, however, when the number of files increases or
when the system has more than one user. Since all the files are in the same directory, they must
have the unique name . if two users call their dataset test, then the unique name rule violated.

Advantages:
• Since it is a single directory, so its implementation is very easy.
• If the files are smaller in size, searching will become faster.
• The operations like file creation, searching, deletion, updating are very easy in such a
directory structure.
Disadvantages:

1117
• There may chance of name collision because two files can not havethe same name.
• Searching will become time taking if the directory is large.
• In this can not group the same type of files together.

2. Two-level directory –
As we have seen, a single level directory often leads to confusion of files names among different
users. the solution to this problem is to create aseparate directory for each user.
In the two-level directory structure, each user has there own user files directory (UFD). The UFDs
has similar structures, but each lists only the files of a single user. system’s master file directory
(MFD) is searches whenever a new user id=s logged in. The MFD is indexed by username or
account number, and each entry points to the UFD for that user.

Advantages:
• We can give full path like /User-name/directory-name/.
• Different users can have same directory as well as file name.
• Searching of files become more easy due to path name and user-grouping.
Disadvantages:
1.
• A user is not allowed to share files with other users.
• Still it not very scalable, two files of the same type cannot be grouped together in the same
user.
2. Tree-structured directory –
Once we have seen a two-level directory as a tree of height 2, the naturalgeneralization is to extend
the directory structure to a tree of arbitrary height.
This generalization allows the user to create there own subdirectories andto organize on their files
accordingly.

1118
A tree structure is the most common directory structure. The tree has a root directory, and every
file in the system have a unique path.

Advantages:
• Very generalize, since full path name can be given.
• Very scalable, the probability of name collision is less.
• Searching becomes very easy, we can use both absolute path as wellas relative.
Disadvantages:
• Every file does not fit into the hierarchical model, files may be savedinto multiple directories.
• We can not share files.
• It is inefficient, because accessing a file may go under multipledirectories.

3. Acyclic graph directory –


An acyclic graph is a graph with no cycle and allows to share subdirectories and files. The same
file or subdirectories may be in two different directories. It is a natural generalization of the tree-
structured directory.
It is used in the situation like when two programmers are working on a joint project and they need
to access files. The associated files are stored in a subdirectory, separating them from other
projects and files of other programmers, since they are working on a joint project so they want the
subdirectories to be into their own directories. The common subdirectories should be shared. So
here we use Acyclic directories.
It is the point to note that shared file is not the same as copy file . If any programmer makes some
changes in the subdirectory it will reflect in bothsubdirectories.

1119
Advantages:
• We can share files.
• Searching is easy due to different-different paths.
Disadvantages:
• We share the files via linking, in case of deleting it may create theproblem,
• If the link is softlink then after deleting the file we left with a danglingpointer.
• In case of hardlink, to delete a file we have to delete all the referenceassociated with it.

4. General graph directory structure –


In general graph directory structure, cycles are allowed within a directory structure where multiple
directories can be derived from more than one parent directory.
The main problem with this kind of directory structure is to calculate total size or space that has
been taken by the files and directories.

Advantages:
• It allows cycles.
• It is more flexible than other directories structure.
Disadvantages:
• It is more costly than others.
• It needs garbage collection.

Disk Data Structures


1120
There are various on disk data structures that are used to implement a file system. This
structure may vary depending upon the operating system.

1. Boot Control Block


Boot Control Block contains all the information which is needed to boot an operating system
from that volume. It is called boot block in UNIX file system. In NTFS, it is called the partition
boot sector.
2. Volume Control Block
Volume control block all the information regarding that volume such as number of blocks, size
of each block, partition table, pointers to free blocks and free FCB blocks. In UNIX file system,
it is known as super block. In NTFS, this information isstored inside master file table.
3. Directory Structure (per file system)
A directory structure (per file system) contains file names and pointers to corresponding FCBs.
In UNIX, it includes inode numbers associated to file names.
4. File Control Block
File Control block contains all the details about the file such as ownership details, permission
details, file size,etc. In UFS, this detail is stored in inode. In NTFS, this information is stored
inside master file table as a relational database structure. A typical file control block is shown
in the image below.

File system Mounting


Each filesystem has its own root directory . The filesystem whose root directory is the root of the
system’s directory tree is called root filesystem . Other filesystems can be mounted on the
system’s directory tree; the directories on which they are inserted are called mount points . A
mounted filesystem is the child of the mounted filesystem to which the mount point directory
belongs. For instance, the /proc virtual filesystem is a child of the root filesystem (and the root
filesystem is the parent of /proc).
In most traditional Unix-like kernels, each filesystem can be mounted only once. Suppose that an
Ext2 filesystem stored in the /dev/fd0 floppy disk is mounted on /flp by issuing the command:
1121
mount -t ext2 /dev/fd0 /flp
Until the filesystem is unmounted by issuing a umount command, any other mount command
acting on /dev/fd0 fails.
However, Linux 2.4 is different: it is possible to mount the same filesystem several times. For
instance, issuing the following command right after the previous one will likely succeed in Linux:

mount -t ext2 -o ro /dev/fd0 /flp-ro


As a result, the Ext2 filesystem stored in the floppy disk is mounted both on /flp and on /flp-ro;
therefore, its files can be accessed through
both /flp and /flp-ro (in this example, accesses through /flp-ro are read-only).
Of course, if a filesystem is mounted n times, its root directory can be accessed through n mount
points, one per mount operation. Although the same filesystemcan be accessed .

File Sharing
File sharing is the practice of sharing or offering access to digital information or resources,
including documents, multimedia (audio/video), graphics, computer programs, images and e-
books. It is the private or public distribution of data or resources in a network with different levels
of sharing privileges.
File sharing can be done using several methods. The most common techniques for file storage,
distribution and transmission include the following:
• Removable storage devices
• Centralized file hosting server installations on networks
• World Wide Web-oriented hyperlinked documents
• Distributed peer-to-peer networks

Explained File Sharing


File sharing is a multipurpose computer service feature that evolved from removable media via
network protocols, such as File Transfer Protocol (FTP). Beginning in the 1990s, many remote file-
sharing mechanisms were introduced,including FTP, hotline and Internet relay chat (IRC).
Operating systems also provide file-sharing methods, such as network file sharing(NFS). Most file-
sharing tasks use two basic sets of network criteria, as follows:
• Peer-to-Peer (P2P) File Sharing: This is the most popular, but controversial, method of file
sharing because of the use of peer-to-peer software. Network computer users locate shared
data with third-party software. P2P file sharing allows users to directly access, download and
edit files. Some third-party software facilitates P2P sharing by collecting and segmenting large
files into smaller pieces.
• File Hosting Services: This P2P file-sharing alternative provides a broad selection of popular
online material. These services are quite often used with Internet collaboration methods,
including email, blogs, forums, or other mediums, where direct download links from the file
hosting services can be included. These service websites usually host files to enable users to
download them.
Once users download or make use of a file using a file-sharing network, their computer also
becomes a part of that network, allowing other users to download files from the user's computer.
File sharing is generally illegal, with the exception of sharing material that is not copyrighted or
proprietary. Another issue with file- sharing applications is the problem of spyware or adware, as
1122
some file-sharing websites have placed spyware programs in their websites. These spyware
programs are often installed on users' computers without their consent and awareness.

File Systems
File system is the part of the operating system which is responsible for file management. It
provides a mechanism to store the data and access to the file contents including data and
programs. Some Operating systems treats everythingas a file for example Ubuntu.
The File system takes care of the following issues
• File Structure
We have seen various data structures in which the file can be stored. The task ofthe file system
is to maintain an optimal file structure.
• Recovering Free space
Whenever a file gets deleted from the hard disk, there is a free space created in the disk. There
can be many such spaces which need to be recovered in order toreallocate them to other files.
• disk space assignment to the files
The major concern about the file is deciding where to store the files on the hard disk. There are
various disks scheduling algorithm which will be covered later inthis tutorial.
• tracking data location
A File may or may not be stored within only one block. It can be stored in the non contiguous
blocks on the disk. We need to keep track of all the blocks on which the part of the files reside.

File System Structure


File System provide efficient access to the disk by allowing data to be stored, located and
retrieved in a convenient way. A file System must be able to store the file, locate the file and
retrieve the file.
Most of the Operating Systems use layering approach for every task including file systems. Every
layer of the file system is responsible for some activities.
The image shown below, elaborates how the file system is divided in different layers, and also the
functionality of each layer.

1123
• When an application program asks for a file, the first request is directedto the logical file
system. The logical file system contains the Meta dataof the file and directory structure.
If the application program doesn't have the required permissions of the file then this
layer will throw an error. Logical file systems also verify the path to the file.
• Generally, files are divided into various logical blocks. Files are to be stored in the hard
disk and to be retrieved from the hard disk. Hard disk is divided into various tracks and
sectors. Therefore, in order to store and retrieve the files, the logical blocks need to be
mapped to physical blocks. This mapping is done by File organization module. It is also
responsible for free space management.
• Once File organization module decided which physical block the application program
needs, it passes this information to basic file system. The basic file system is
responsible for issuing the commands toI/O control in order to fetch those blocks.
• I/O controls contain the codes by using which it can access hard disk. These codes are
known as device drivers. I/O controls are also responsible for handling interrupts.

File System Implementation


A file is a collection of related information. The file system resides on secondary storage and
provides efficient and convenient access to the disk by allowing data to be stored, located, and
retrieved.

File system organized in many layers :

• I/O Control level –


Device drivers acts as interface between devices and Os, they help to transfer data
between disk and main memory. It takes block number a input and as output it gives low
level hardware specific instruction.
/li>
• Basic file system –
It Issues general commands to device driver to read and write physical blocks on [Link]
1124
manages the memory buffers and caches. A block in buffer can hold the contents of the
disk block and cache stores frequently used filesystem metadata.
• File organization Module –
It has information about files, location of files and their logical and physical [Link]
blocks do not match with logical numbers of logical block numbered from 0 to N. It also
has a free space which tracks unallocated blocks.
• Logical file system –
It manages metadata information about a file i.e includes all details about a file except the
actual contents of file. It also maintains via file control blocks. File control block (FCB) has
information about a file – owner, size, permissions, location of file contents.

Advantages :
1. Duplication of code is minimized.
2. Each file system can have its own logical file system.
Disadvantages :
If we access many files at same time then it results in low [Link] can implement file
system by using two types data structures :
1. On-disk Structures –
Generally they contain information about total number of disk blocks, free disk blocks, location
of them and etc. Below given are different on-disk structures :
1. Boot Control Block –
It is usually the first block of volume and it contains information needed to boot an operating
[Link] UNIX it is called boot blockand in NTFS it is called as partition boot sector.
2. Volume Control Block –
It has information about a particular partition ex:- free block count, block size and block
pointers [Link] UNIX it is called super block andin NTFS it is stored in master file table.
3. Directory Structure –
They store file names and associated inode [Link] UNIX, includes file names and
associated file names and in NTFS, it is storedin master file table.
4. Per-File FCB –
It contains details about files and it has a unique identifier number to allow association with
directory entry. In NTFS it is stored in master file table.

1125
2. In-Memory Structure :
They are maintained in main-memory and these are helpful for file system management for
caching. Several in-memory structures given below :
5. Mount Table –
It contains information about each mounted volume.

6. Directory-Structure cache –
This cache holds the directory information of recently accesseddirectories.
7. System wide open-file table –
It contains the copy of FCB of each open file.

8. Per-process open-file table –


It contains information opened by that particular process and it maps with appropriate system
wide open-file.

Directory Implementation :
9. Linear List –
It maintains a linear list of filenames with pointers to the data [Link] is time-consuming
[Link] create a new file, we must first search the directory to be sure that no existing file has
the same name then we add a file at end of the [Link] delete a file, we search the
directory for the named file and release the [Link] reuse the directory entry either we can
mark the entry as unused orwe can attach it to a list of free directories.

10. Hash Table –


The hash table takes a value computed from the file name and returns a pointer to the file. It
decreases the directory search time. The insertion and deletion process of files is easy. The
major difficulty is hash tables are its generally fixed size and hash tables are dependent on
hash function on that size.

Directory Implementation
There is the number of algorithms by using which, the directories can be implemented. However,
the selection of an appropriate directory implementation algorithm may significantly affect the
1126
performance of the system.
The directory implementation algorithms are classified according to the data structure they are
using. There are mainly two algorithms which are used in thesedays.

1. Linear List
In this algorithm, all the files in a directory are maintained as singly lined list. Each file contains
the pointers to the data blocks which are assigned to it and the next file in the directory.
Characteristics
1. When a new file is created, then the entire list is checked whether the new file name is
matching to a existing file name or not. In case, it doesn't exist, the file can be created at the
beginning or at the end. Therefore, searching for a unique name is a big concern because
traversing the whole list takes time.
2. The list needs to be traversed in case of every operation (creation, deletion, updating, etc) on
the files therefore the systems become inefficient.

2. Hash Table
To overcome the drawbacks of singly linked list implementation of directories, there is an
alternative approach that is hash table. This approach suggests to use hash table along with the
linked lists.

A key-value pair for each file in the directory gets generated and stored in the hash table. The key
can be determined by applying the hash function on the file name while the key points to the
corresponding file stored in the directory.

Now, searching becomes efficient due to the fact that now, entire list will not besearched on every
operating. Only hash table entries are checked using the key and if an entry found then the
corresponding file will be fetched using the value.

1127
Allocation Methods
There are various methods which can be used to allocate disk space to the files. Selection of an
appropriate allocation method will significantly affect the performance and efficiency of the
system. Allocation method provides a way in which the disk will be utilized and the files will be
accessed.
There are following methods which can be used for allocation.
1. Contiguous Allocation.
2. Extents
3. Linked Allocation
4. Clustering
5. FAT
6. Indexed Allocation
7. Linked Indexed Allocation
8. Multilevel Indexed Allocation
9. Inode

Free Space Management


A file system is responsible to allocate the free blocks to the file therefore it hasto keep track of all
the free blocks present in the disk. There are mainly two approaches by using which, the free
blocks in the disk are managed.

1. Bit Vector
In this approach, the free space list is implemented as a bit map vector. It contains the number
of bits where each bit represents each block.
If the block is empty then the bit is 1 otherwise it is 0. Initially all the blocks areempty therefore
each bit in the bit map vector contains 1.
LAs the space allocation proceeds, the file system starts allocating blocks to the files and
setting the respective bit to 0.

2. Linked List
It is another approach for free space management. This approach suggests linking together all

1128
the free blocks and keeping a pointer in the cache which points to thefirst free block.
Therefore, all the free blocks on the disks will be linked together with a pointer. Whenever a
block gets allocated, its previous free block will be linked to its nextfree block.

File System-Efficiency and Performance


Efficiency
The efficient use of disk space depends heavily on the disk allocation and directory algorithms in
use. For instance, UNIX inodes are preallocated on a volume. Even an "empty" disk has a
percentage of its space lost to inodes. However, by preallocating the inodes and. spreading them
across the volume, we improve the file system's performance. This improved performance results
from the UNIX allocation and free-space algorithms, which try to keep a file's data blocks near that
file's inode block to reduce seek time. As another example, let's reconsider the clustering scheme
discussed in Section 11.4, which aids in file-seek and file-transfer performance at the cost of
internal fragmentation.

To reduce this fragmentation, BSD UNIX varies the cluster size as a file grows. Large clusters are
used where they can be filled, and small clusters are used for small files and the last cluster of a
file. This system is described in Appendix A. Thetypes of data normally kept in a file's directory (or
inode) entry also require consideration. Commonly, a 'last write date" is recorded to supply
information to the user and, to determine whether the file needs to be backed up. Some systems
also keep a "last access date," so that a user can determine when the file was last read.
The result of keeping this information is that, whenever the file is read, a field in the directory
structure must be written to. That means the block must be read into memory, a section changed,
and the block written back out to disk, because operations on disks occur only in block (or cluster)
chunks. So any time a file is opened for reading, its directory entry must be read and written as
well. This requirement can be inefficient for frequently accessed files, so we must weigh itsbenefit
against its performance cost when designing a file system. Generally, every data item associated
with a file needs to be considered for its effect onefficiency and performance.

As an example, consider how efficiency is affected by the size of the pointers used to access
data. Most systems use either 16- or 32-bit pointers throughout the operating system. These
pointer sizes limit the length of a file to either 2 16 (64 KB) or 232 bytes (4 GB). Some systems
implement 64-bit pointers to increase this limit to 264 bytes, which is a very large number indeed.
However, 64-bit pointers take more space to store and in turn make the allocation and free-space-
management methods (linked lists, indexes, and so on) use more disk space. One of the
difficulties in choosing a pointer size, or indeed any fixed allocation size within an operating
system, is planning for the effects of changing technology.

Consider that the IBM PC XT had a 10-MB hard drive and an MS-DOS file systemthat could support
only 32 MB. (Each FAT entry was 12 bits, pointing to an 8-KBcluster.)
As disk capacities increased, larger disks had to be split into 32-MB partitions, because the file
system could not track blocks beyond 32 MB. As hard disks with capacities of over 100 MB
became common, most disk controllers include local memory to form an on-board cache that is
large enough to store entire tracks at a time. Once a seek is performed, the track is read into the
disk cache starting at the sector under the disk head (reducing latency time).

The disk controller then transfers any sector requests to the operating system. Once blocks make
it from the disk controller into main memory, the operating system may cache the blocks there.
1129
Some systems maintain a separate section of main memory for a buffer cache, where blocks are
kept under the assumption that they will be used again shortly. Other systems cache file data
using a page cache.

The page cache uses virtual memory techniques to cache file data as pages rather than as file-
system-oriented blocks. Caching file data using virtual addresses is far more efficient than
caching through physical disk blocks, as accesses interface with virtual memory rather than the
file system. Several systems—including

Solaris, Linux, and Windows NT, 2000, and XP—use page caching to cache both process pages
and file data. This is known as unified virtual memory. Some versions of UNIX and Linux provide a
unified buffer cache. To illustrate the benefits of the unified buffer cache, consider the two
alternatives for opening and accessing a file. One approach is to use memory mapping (Section
9.7); the second is to use the standard system calls readO and write 0 . Without a unified buffer
cache, we have a situation similar to Figure 11.11.

Here, the read() and write () system calls go through the buffer cache. The memory-mapping call,
however, requires using two caches—the page cache and the buffer cache. A memory mapping
proceeds by reading in disk blocks from the file system and storing them in the buffer cache.
Because the virtual memory system does not interface with the buffer cache, the contents of the
file in the buffer cache must be copied into the page cache. This situation is known as double
caching and requires caching file-system data twice. Not only does it waste memory but it also
wastes significant CPU and I/O cycles due to the extra data movement within, system memory.
In add ition, inconsistencies between the two caches can result in corrupt files. In contrast, when a
unifiedthe disk data structures and algorithms in MS-DOS had to be modified to allow larger file
systems. (Each FAT entry was expanded to 16 bits and later to 32 bits.) The initial file-system
decisions were made for efficiency reasons; however, with the advent of MS-DOS version 4,
millions of computer users were inconvenienced when they had to switch to the new, larger file
system. Sun's ZFS file system uses 128-bit pointers, which theoretically should never need to be
extended. (The minimum mass of a device capable of storing 2'2S bytes using atomic-level
storage would be about 272 trillion kilograms.) As another example, consider the evolution of
Sun's Solaris operating system.

Originally, many data structures were of fixed length, allocated at system [Link] structures
included the process table and the open-file table. When the process table became full, no more
processes could be created. When the file table became full, no more files could be opened. The
system would fail to provide services to users. Table sizes could be increased only by recompiling
the kernel and rebooting the system. Since the release of Solaris 2, almost all kernel structures
have been allocated dynamically, eliminating these artificial limits on system performance. Of
course, the algorithms that manipulate these tables are more complicated, and the operating
system is a little slower because it must dynamically allocate and deallocate table entries; but that
price is the usual onefor more general, functionality.

Performance
Even after the basic file-system algorithms have been selected, we can still improve performance
in several ways. As will be discussed in Chapter 13, most disk controllers include local memory to
form an on-board cache that is large enough to store entire tracks at a time. Once a seek is
performed, the track is read into the disk cache starting at the sector under the disk head
1130
(reducing latency time). The disk controller then transfers any sector requests to the operating
system. Once blocks make it from the disk controller into main memory, the operating system
may cache the blocks there. Some systems maintain a separate section of main memory for a
buffer cache, where blocks are kept under the assumption that they will be used again shortly.
Other systems cache file data using a page cache.

The page cache uses virtual memory techniques to cache file data as pages rather than as file-
system-oriented blocks. Caching file data using virtual addresses is far more efficient than
caching through physical disk blocks, as accesses interface with virtual memory rather than the
file system. Several systems—including Solaris, Linux, and Windows NT, 2000, and XP—use page
caching to cache both process pages and file data. This is known as unified virtual memory.
Some versions of UNIX and Linux provide a unified buffer cache.

To illustrate the benefits of the unified buffer cache, consider the two alternatives for opening and
accessing a file. One approach is to use memory mapping (Section 9.7); the second is to use the
standard system calls readO and write 0 .

Without a unified buffer cache, we have a situation similar to Figure 11.11. Here, the read() and
write () system calls go through the buffer cache. The memory- mapping call, however, requires
using two caches—the page cache and the buffer cache. A memory mapping proceeds by reading
in disk blocks from the file system and storing them in the buffer cache. Because the virtual
memory system does not interface with the buffer cache, the contents of the file in the buffer
cache must be copied into the page cache.

1131
This situation is known as double caching and requires caching file-system data twice. Not only
does it waste memory but it also wastes significant CPU and I/O cycles due to the extra data
movement within, system memory. In add ition, inconsistencies between the two caches can
result in corrupt files. In contrast, when a unified buffer cache is provided, both memory mapping
and the read () and write () system calls use the same page cache. This has the benefit of
avoidingdouble caching, and it allows the virtual memory system to manage file-system data. The
unified buffer cache is shown in Figure 11.12. Regardless of whether weare caching disk blocks or
pages (or both), LEU (Section 9.4.4) seems a reasonable general-purpose algorithm for block or
page replacement. However, the evolution of the Solaris page-caching algorithms reveals the
difficulty in choosing an algorithm. Solaris allows processes and the page cache to share unused
inemory.

Versions earlier than Solaris 2.5.1 made no distinction between allocating pages to a process and
allocating them to the page cache. As a result, a system performing many I/O operations used
most of the available memory for caching pages. Because of the high rates of I/O, the page
scanner (Section 9.10.2) reclaimed pages from processes— rather than from the page cache—
when free memory ran low. Solaris 2.6 and Solaris 7 optionally implemented priority paging, in
which the page scanner gives priority to process pages over the page cache.

Solaris 8 applied a fixed limit to process pages and the file-system page cache, preventing either
from forcing the other out of memory. Solaris 9 and 10 again changed the algorithms to maximize
memory use and minimize thrashing. This real-world example shows the complexities of
performance optimizing and caching.

There are other issvies that can affect the performance of I/O such as whether writes to the file
system occur synchronously or asynchronously. Synchronous writes occur in the order in which
the disk subsystem receives them, and the writes are not buffered. Thus, the calling routine must
wait for the data to reach the disk drive before it can proceed. Asynchronous writes are done the
majority of the time. In an asynchronous write, the data are stored in the cache, and control
returns to the caller. Metadata writes, among others, can be synchronous.

Operating systems frequently include a flag in the open system call to allow a process to request
that writes be performed synchronously. For example, databases use this feature for atomic
transactions, to assure that data reach stable storage in the required order. Some systems
optimize their page cache by using different replacement algorithms, depending on the access

1132
type of the file.

A file being read or written sequentially should not have its pages replaced in LRU order, because
the most 11.7 Recovery 435 recently used page will be used last, or perhaps never again. Instead,
sequential access can be optimized by techniques known as free-behind and read-ahead. Free-
behind removes a page from the buffer as soon as the next page is requested. The previous
pages are not likely to be used again and waste buffer space. With read-ahead, a requested page
and several subsequent pages are read and cached. These pages are likely to be requested after
the current page is processed.

Retrieving these data from the disk in one transfer and caching them saves a considerable
amount of time. One might think a track cache on the controller eliminates the need for read-
ahead on a multiprogrammed system. However, because of the high latency and overhead
involved in making many small transfers from the track cache to main memory, performing a read-
ahead remains beneficial. The page cache, the file system, and the disk drivers have some
interesting interactions. When data are written to a disk file, the pages are buffered in the cache,
and the disk driver sorts its output queue according to disk address. These two actions allow the
disk driver to minimize disk-head seeks and to write data at times optimized for disk rotation.

Unless synchronous writes are required, a process writing to disk simply writes into the cache,
and the system asynchronously writes the data to disk when convenient. The user process sees
very fast writes. When data are read from a disk file, the block I/O system does some read-ahead;
however, writes are much more nearly asynchronous than are reads. Thus, output to the disk
through the file system is often faster than is input for large transfers, counter to intuition.

File System-RecoveryRecovery
Files and directories are kept both in main memory and on disk, and care musttaken to ensure that
system failure does not result in loss of data or in data inconsistency. We deal with these issues
in the following sections.

Consistency Checking
As discussed in Section 11.3, some directory information is kept in main memory (or cache) to
speed up access. The directory information in main memory is generally more up to date than is
the corresponding information on the disk, because cached directory information is not
necessarily written to disk as soon asthe update takes place.

Magnetic disks sometimes fail, and care must be taken to ensure that the data lost in such a
failure are not lost forever. To this end, system programs can be used to back up data from disk to
another storage device, such as a floppy disk,magnetic tape, optical disk, or other hard disk.

Recovery from the loss of an individual file, or of an entire disk, may then be a matter of restoring
the data from backup. To minimize the copying needed, we can use information from each file's
directory entry. For instance, if the backup program knows when the last backup of a file was
done, and the file's last write date in the directory indicates that the file has not changed since that
date, then the file does not need to be copied again. A typical backup schedule may then be as
follows:
• Day 1. Copy to a backup medium all files from the disk. This is called a fullbackup.
1133
• Day 2. Copy to another medium all files changed since day 1. This is anincremental backup.
Day 3. Copy to another medium all files changed since day 2.
• Day N. Copy to another medium all files changed since day N— 1. Then go back to Day 1. The
new cycle can have its backup written over the previous set or ontoa new set of backup media.

In this manner, we can restore an entire disk by starting restores with the full backup and
continuing through each of the incremental backups. Of course, the larger the value of N, the
greater the number of tapes or disks that must be read for a complete restore. An added
advantage of this backup cycle is that we can restore any file accidentally deleted during the cycle
by retrieving the deleted filefrom the backup of the previous day.
The length of the cycle is a compromise between the amount of backup medium needed and the
number of days back from which a restore can be done. To decrease the number of tapes that
must be read, to do a restore, an option is to perform a full backup and then each day back up all
files that have changed since the full backup. In this way, a restore can be done via the most
recent incremental backup and. the full backup, with no other incremental backups needed. The
trade-off is that more files will be modified each day, so each successive incremental backup
involves more files and more backup media.

A user may notice that a particular file is missing or corrupted long after the damage was done.
For this reason, we usually plan to take a full backup from time to time that will be saved "forever."
It is a good idea to store these permanent backups far away from the regular backups to protect
against hazard, such as a fire that destroys the computer and all the backups too. And if the
backup cycle reuses media, we must take care not to reuse the media too many times—if the
media wear out, it might not be possible to restore any data from the backups.

I/O Hardware
One of the important jobs of an Operating System is to manage various I/O devices including
mouse, keyboards, touch pad, disk drives, display adapters, USB devices, Bit-mapped screen, LED,
Analog-to-digital converter, On/off switch, network connections, audio I/O, printers etc.
An I/O system is required to take an application I/O request and send it to thephysical device, then
take whatever response comes back from the device and send it to the application. I/O devices
can be divided into two categories −
• Block devices − A block device is one with which the driver communicatesby sending entire
blocks of data. For example, Hard disks, USB cameras, Disk-On-Key etc.
• Character devices − A character device is one with which the driver communicates by
sending and receiving single characters (bytes, octets). For example, serial ports, parallel
ports, sounds cards etc

Device Controllers
Device drivers are software modules that can be plugged into an OS to handle a particular device.
Operating System takes help from device drivers to handle allI/O devices.
The Device Controller works like an interface between a device and a device driver. I/O units
(Keyboard, mouse, printer, etc.) typically consist of a mechanical component and an electronic
component where electronic component is called the device controller.

There is always a device controller and a device driver for each device to communicate with the
Operating Systems. A device controller may be able to handle multiple devices. As an interface its
1134
main task is to convert serial bit stream to block of bytes, perform error correction as necessary.
Any device connected to the computer is connected by a plug and socket, and the socket is
connected to a device controller. Following is a model for connecting theCPU, memory, controllers,
and I/O devices where CPU and device controllers all use a common bus for communication.

Synchronous vs asynchronous I/O


• Synchronous I/O − In this scheme CPU execution waits while I/O proceeds
• Asynchronous I/O − I/O proceeds concurrently with CPU execution

Communication to I/O Devices


The CPU must have a way to pass information to and from an I/O device. There are three
approaches available to communicate with the CPU and Device.
• Special Instruction I/O
• Memory-mapped I/O
• Direct memory access (DMA)

Special Instruction I/O


This uses CPU instructions that are specifically made for controlling I/O devices. These
instructions typically allow data to be sent to an I/O device or read from anI/O device.

Memory-mapped I/O
When using memory-mapped I/O, the same address space is shared by memory and I/O devices.
The device is connected directly to certain main memory locations so that I/O device can transfer
1135
block of data to/from memory withoutgoing through CPU.

While using memory mapped IO, OS allocates buffer in memory and informs I/O device to use that
buffer to send data to the CPU. I/O device operates asynchronously with CPU, interrupts CPU
when finished.
The advantage to this method is that every instruction which can access memory can be used to
manipulate an I/O device. Memory mapped IO is used for most high-speed I/O devices like disks,
communication interfaces.

Direct Memory Access (DMA)


Slow devices like keyboards will generate an interrupt to the main CPU after each byte is
transferred. If a fast device such as a disk generated an interrupt for each byte, the operating
system would spend most of its time handling these interrupts. So a typical computer uses direct
memory access (DMA) hardware to reduce this overhead.
Direct Memory Access (DMA) means CPU grants I/O module authority to read from or write to
memory without involvement. DMA module itself controls exchange of data between main
memory and the I/O device. CPU is only involved at the beginning and end of the transfer and
interrupted only after entire blockhas been transferred.
Direct Memory Access needs a special hardware called DMA controller (DMAC) that manages the
data transfers and arbitrates access to the system bus. The controllers are programmed with
source and destination pointers (where to read/write the data), counters to track the number of
transferred bytes, and settings, which includes I/O and memory types, interrupts and states for the
CPUcycles.

1136
The operating system uses the DMA hardware as follows −
Step Description

1 Device driver is instructed to transfer disk data to a buffer address X.

2 Device driver then instruct disk controller to transfer data to buffer.

3 Disk controller starts DMA transfer.


4 Disk controller sends each byte to DMA controller.
5 DMA controller transfers bytes to buffer, increases the memory address,
decreases the counter C until C becomes zero.
6 When C becomes zero, DMA interrupts CPU to signal transfer
completion.

Polling vs Interrupts I/O


A computer must have a way of detecting the arrival of any type of input. There are two ways that
this can happen, known as polling and interrupts. Both of these techniques allow the processor to
deal with events that can happen at any time and that are not related to the process it is currently
running.

Polling I/O
Polling is the simplest way for an I/O device to communicate with the processor. The process of
periodically checking status of the device to see if it is time for the next I/O operation, is called
1137
polling. The I/O device simply puts the information in a Status register, and the processor must
come and get the information.

Most of the time, devices will not require attention and when one does it will have to wait until it is
next interrogated by the polling program. This is an inefficient method and much of the
processors time is wasted on unnecessarypolls.

Compare this method to a teacher continually asking every student in a class, one after another, if
they need help. Obviously the more efficient method would be for a student to inform the teacher
whenever they require assistance.

Interrupts I/O
An alternative scheme for dealing with I/O is the interrupt-driven method. An interrupt is a signal to
the microprocessor from a device that requires attention.
A device controller puts an interrupt signal on the bus when it needs CPU’s attention when CPU
receives an interrupt, It saves its current state and invokes the appropriate interrupt handler using
the interrupt vector (addresses of OS routines to handle various events). When the interrupting
device has been dealt with, the CPU continues with its original task as if it had never been
interrupted.

Application I/O interface


In this section, we discuss structuring techniques and interfaces for the operating system that
enable I/O devices to be treated in a standard, uniform way. We explain, for instance, how an
application can open a file on a disk without knowing what kind of disk it is and how new disks
and other devices can be added to a computer without disruption of the operating system. Like
other complex software-engineering problems, the approach here involves abstraction,
encapsulation, and software layering. Specifically we can abstract away the detailed differences
in I/O devices by identifying a fewgeneral kinds. Each general kind is accessed through a
standardized set of functions—an interface. The differences are encapsulated in kernel modules
called device drivers that internally are custom-tailored to each device but that export one of the
standard interfaces.

1138
Figure 13.6 illustrates how the I/O-related portions of the kernel are structured in software layers.
The purpose of the device-driver layer is to hide the differences among device controllers from the
I/O subsystem of the kernel, much as the I/O system calls encapsulate the behavior of devices in
a few generic classes that hidehardware differences from applications. Making the I/O subsystem
independent of the hardware simplifies the job of the operating-system developer. It also benefits
the hardware manufacturers. They either design new devices to be compatible with an existing
host controller interface (such as SCSI-2), or they write device drivers to interface the new
hardware to popular operating systems. Thus, we can attach new peripherals to a computer
without waiting for the operating-system vendor to develop support code. Unfortunately for
device- hardware manufacturers, each type of operating system has its own standards for the
device-driver interface. A given device may ship with multiple device drivers— for instance, drivers
for MS-DOS, Windows 95/98, Windows NT/2000, and Solaris. Devices vary on many dimensions,
as illustrated in Figure 13.7.

1139
• Character-stream or block. A character-stream, device transfers bytes one by one, whereas
a block device transfers a block of bytes as a unit.
• Sequential or random-access. A sequential device transfers data in a fixed orderdetermined
by the device, whereas the user of a random-access device can instruct the device to seek
to any of the available data storage locations.
• Synchronous or asynchronous. A synchronous device performs data transfers with
predictable response times. An asynchronous device exhibits irregular or unpredictable
response times.
• Sharable or dedicated. A sharable device can be used concurrently by several processes or
threads; a dedicated device cannot. 8 Speed of operation. Device speeds range from a few
bytes per second to a few gigabytes per second.
• Read-write, read only, or write only. Some devices perform both input and output, but others
support only one data direction.

For the purpose of application access, many of these differences are hidden by the operating
system, and the devices are grouped into a few conventional types. The resulting styles of device
access have been found to be useful and broadly applicable. Although the exact system calls may
differ across operating systems, the device categories are fairly standard. The major access
conventions include block I/O, character-stream I/O, memory-mapped file access, and network
sockets. Operating systems also provide special system calls to access a few additional devices,
such as a time-of- day clock and a timer. Some operating systems provide a set of system calls
for graphical display, video, and audio devices. Most operating systems also have an escape (or
back door) that transparently passes arbitrary commands from an application to a device driver.
In UNIX, this system call is ioctl O (for "I/O" control).The ioctl O system call enables an application
1140
to access any functionality that can be implemented by any device driver, without the need to
invent a new system call. The ioctl O system call has three arguments.

The first is a file descriptor that connects the application to the driver by referring to a hardware
device managed by that driver. The second is an integer that selects one of the commands
implemented in the driver. The third is a pointer to an arbitrary data structure in memory that
enables the application and driver to communicate any necessary control information or data.

Block and Character Devices


The block-device interface captures all the aspects necessary for accessing disk drives and other
block-oriented devices. The device is expected to understand commands such as read () and wr it
e (); if it is a random-access device, it is alsoexpected to have a seek() command to specify which
block to transfer next.

Applications normally access such a device through a file-system interface. We can see that
readO, write (), and seekO capture the essential behaviors of block- storage devices, so that
applications are insulated from the low-level differencesamong those devices.

The operating system itself, as well as special applications such as databasemanagement


systems, may prefer to access a block device as a simple linear array of blocks. This mode of
access is sometimes called raw I/O. If the application performs its own buffering, then using a file
system would cause extra, unneeded buffering. Likewise, if an application provides its own locking
of file blocks or regions, then any operating-system locking services would be redundant at the
least and contradictory at the worst.

To avoid these conflicts, raw-device access passes control of the device directly tothe application,
letting the operating system step out of the way. Unfortunately, no operating-system services are
then performed on this device. A compromise that is becoming common is for the operating
system to allow a mode of operation on a file that disables buffering and locking.

In the UNIX world, this is called direct I/O. Memory-mapped file access can be layered on top of
block-device drivers. Rather than offering read and write operations, a memory-mapped interface
provides access to disk storage via an array of bytes in main memory. The system call that maps
a file into memory returns the virtual memory address that contains a copy of the file. The actual
data transfers are performed only when needed to satisfy access to the memory image. Because
the transfers are handled by the same mechanism as that used for demand-paged virtual memory
access, memory-mapped I/O is efficient.

Memory mapping is also convenient for programmers—access to a memory- mapped file is as


simple as reading from and writing to memory. Operating systems that offer virtual memory
commonly use the mapping interface for kernel services. For instance, to execute a program, the
operating system maps the executable into memory and then transfers control to the entry
address of the executable.

The mapping interface is also commonly used for kernel access to swap space on disk. A
keyboard is an example of a device that is accessed through a characterstream interface. The
basic system calls in this interface enable an application to get() or putO one character. On top of
this interface, libraries can be built that offer line-at-a-time access, with buffering and editing
1141
services (for example, when a user types a backspace, the preceding character is removed from
the input stream). This style of access is convenient for input devices such as keyboards, mice,
and modems that produce data for input "spontaneously" — that is, at times that cannot
necessarily be predicted by the application. This access style is also good for output devices such
as printers and audio boards,which naturally fit the concept of a linear stream of bytes.

Network Devices
Because the performance and addressing characteristics of network I/O differ significantly from,
those of disk I/O, most operating systems provide a network I/O interface that is different from
the read 0 -writ e () -seekO interface used for disks. One interface available in many operating
systems, including UNIX and Windows NT, is the network socket interface. Think of a wall socket
for electricity: Any electrical appliance can be plugged in. By analogy, the system calls in the
socket interface enable an application to create a socket, to connect a local socket to a remote
address (which plugs this application into a socket created by another application), to 13.3
Application I/O Interface 509 listen for any remote application to plug into the local socket, and to
send and receive packets over theconnection.

To support the implementation of servers, the socket interface also provides a function called
selec t () that manages a set of sockets. A call to selec t () returns information about which
sockets have a packet waiting to be received and which sockets have room to accept a packet to
be sent. The use of selec t () eliminates the polling and busy waiting that would otherwise be
necessary for network I/O. These functions encapsulate the essential behaviors of networks,
greatly facilitating the creation of distributed applications that can use any underlying network
hardware and protocol stack.

Many other approaches to interprocess communication and network communication have been
implemented. For instance, Windows NT provides one interface to the network interface card and
a second interface to the network protocols (Section C.6). In UNIX, which has a long history as a
proving ground for network technology, we find half-duplex pipes, full-duplex FIFOs, full-duplex
STREAMS, message queues, and sockets. Information on UNIX networking is given in Appendix A
(Section A.9). Clocks and Timers Most computers have hardware clocks and timers that provide
three basicfunctions:
• Give the current time.
• Give the elapsed time.
Set a timer to trigger operation X at time T. These functions are used heavily by the operating
system, as well as by timesensitive applications. Unfortunately, the system calls that implement
these functions are not standardized across operating systems. The hardware to measure
elapsed time and to trigger operations is called a programmable interval timer. It can be set to
wait a certainamount of time and then generate an interrupt, and it can be set to do this once or to
repeat the process to generate periodic interrupts. The scheduler uses this mechanism to
generate an interrupt that will preempt a process at the end of itstime slice.

The disk I/O subsystem uses it to invoke the flushing of dirty cache buffers to diskperiodically, and
the network subsystem uses it to cancel operations that are proceeding too slowly because of
network congestion or failures. Hie operating system may also provide an interface for user
processes to use timers. The operating system can support more timer requests than the number
of timer hardware channels by simulating virtual clocks. To do so, the kernel (or the timer device

1142
driver) maintains a list of interrupts wanted by its own routines and by user requests, sorted in
earliest-time-first order. It sets the timer for the earliest time. When the timer interrupts, the kernel
signals the requester and reloads thetimer with the next earliest time.

On many computers, the interrupt rate generated by the hardware clock is between 18 and 60
ticks per second. This resolution is coarse, since a modern computer can execute hundreds of
millions of instructions per second. The precision of triggers is limited by the coarse resolution of
the timer, together with the overhead of maintaining virtual clocks. Furthermore, if the timer 510
Chapter13 I/O Systems ticks are used to maintain the system tiine-of-day clock, the system? clock
can drift. In most computers, the hardware clock is constructed from a highfrequency counter. In
some computers, the value of this counter can he read from a device register, in which case the
counter can be considered a highresolution clock. Although this clock does not generate
interrupts, it offers accurate measurements of time intervals.

Blocking and Nonblocking IO


Another aspect of the system-call interface relates to the choice between blocking I/O and
nonblocking I/O. When an application issues a blocking system call, the execution of the
application is suspended. The application is moved from the operating system's run queue to a
wait queue. After the system call completes, the application is moved back to the run queue,
where it is eligible to resume execution, at which time it will receive the values returned by the
systemcall. The physical actions performed by I/O devices are generally asynchronous— they take
a varying or unpredictable amount of time. Nevertheless, most operating systems use blocking
system calls for the application interface, because blocking application code is easier to
understand than nonblocking application code. Some user-level processes need nonblocking I/O.
One example is a user interface that receives keyboard and mouse input while processing and
displaying data on the screen. Another example is a video application that reads frames from a
file on disk while simultaneously decompressing and displaying the output on the display. One
way an applicationwriter can overlap execution with I/O is to write a multithreaded application.

Some threads can perform blocking system calls, while others continue executing. The Solaris
developers used this technique to implement a user-level library for asynchronous I/O, freeing the
application writer from that task. Some operating systems provide nonblocking I/O system calls. A
nonblocking call does not halt the execution of the application for an extended time. Instead, it
returns quickly, with a return value that indicates how many bytes were transferred. An alternative
to a nonblocking system call is an asynchronous system call. An asynchronous call returns
immediately, without waiting for the I/O to complete. The application continues to execute its
code.

The completion of the I/O at some future time is communicated to the application, either through
the setting of some variable in the address space of the application or through the triggering of a
signal or software interrupt or a call-back routine that is executed outside the linear control flow of
the application.

The difference between nonblocking and asynchronous system calls is that a nonblocking readQ
returns immediately with whatever data are available — the full number of bytes requested, fewer,
or none at all. An asynchronous read() call requests a transfer that will be performed in its entirety
but that will complete atsome future time. These two I/O methods are shown in Figure 13.8.

1143
A good example of nonblocking behavior is the selec t () system call for network sockets. This
system call takes an argument that specifies a maximum waiting time. By setting it to 0, an
application can poll for network activity without blocking. But using select() introduces extra
overhead, because the selec t () call only checks whether I/O is possible. For a data transfer,
selectO must be followed by some kind of readO or writeO command. A variation on this
approach, found in Mach, is a blocking multiple-read call. It specifies desired reads for several
devicesin one system call and returns as soon as any one of them completes.

Kernel I/O Subsystem


The kernel provides many services related to I/O. Several services such as scheduling, caching,
spooling, device reservation, and error handling – are provided by the kernel, s I/O subsystem built
on the hardware and device-driver

infrastructure. The I/O subsystem is also responsible for protecting itself from the errant
processes and malicious users.
1. I/O Scheduling –
To schedule a set of I/O request means to determine a good order in which to execute them.
The order in which application issues the system call are the best choice. Scheduling can
improve the overall performance of the system, can share device access permission fairly to
all the processes, reduce the average waiting time, response time, turnaround time for I/O to
complete.
OS developers implement scheduling by maintaining a wait queue of the request for each
device. When an application issue a blocking I/O system call, The requestis placed in the queue
for that device. The I/O scheduler rearrange the order to improve the efficiency of the system.
2. Buffering –
A buffer is a memory area that stores data being transferred between two devices or between
a device and an application. Buffering is done for threereasons.
1. First is to cope with a speed mismatch between producer andconsumer of a data stream.
2. The second use of buffering is to provide adaptation for data that have different data-transfer
sizes.
3. Third use of buffering is to support copy semantics for the application I/O, “copy semantic ”
means, suppose that an application wants to write data on a disk that is stored in its buffer. it
1144
calls the write() system’s call, providing a pointer to the buffer and the integer specifying the
number of bytes to write.

Q. After the system call returns, what happens if the application of the buffer changes the content
of the buffer?

Ans. With copy semantic, the version of the data written to the disk is guaranteedto be the version
at the time of the application system call.
3. Caching –
A cache is a region of fast memory that holds a copy of data. Access to the cached copy is much
easier than the original file. For instance, the instruction of the currently running process is stored
on the disk, cached in physical memory, and copied again in the CPU’s secondary and primary
cache.
The main difference between a buffer and a cache is that a buffer may hold only the existing copy
of a data item, while cache, by definition, holds a copy on faster storage of an item that resides
elsewhere.
4. Spooling and Device Reservation –
A spool is a buffer that holds the output of a device, such as a printer that cannot accept
interleaved data streams. Although a printer can serve only one job at a time, several applications
may wish to print their output concurrently, without having their output mixes together.
The OS solves this problem by preventing all output continuing to the printer. The output of all
applications is spooled in a separate disk file. When an application finishes printing then the
spooling system queues thecorresponding spool file for output to the printer.
5. Error Handling –
An Os that uses protected memory can guard against many kinds of hardware and application
errors, so that a complete system failure is not the usual result of each minor mechanical glitch,
Devices, and I/O transfers can fail in many ways, either for transient reasons, as when a network
becomes overloaded or for permanent reasons, as when a disk controller becomes defective.
6. I/O Protection –
Errors and the issue of protection are closely related. A user process may

attempt to issue illegal I/O instructions to disrupt the normal function of a system. We can use the
various mechanisms to ensure that such disruptioncannot take place in the system.
To prevent illegal I/O access, we define all I/O instructions to be privileged instructions. The user
cannot issue I/O instruction directly.

Transforming of I/O Requests to Hardware Operations


We know that there is handshaking between device driver and device controller but here question
is that how operating system connects application request or we can say I/O request to set of
network wires or to specific disk sector or we cansay to hardware -operations.
To understand concept example which is as follows.

Example –
We are reading file from disk. The application we request for will refers to data byfile name. Within
disk, file system maps from file name through file-system directories to obtain space allocation
for file. In MS-DOS, name of file maps to number that indicates as entry in file-access table, and
that entry to table tells us that which disk blocks are allocated to file. In UNIX, name maps to
1145
inode number, and inode number contains information about space-allocation. But here question
arises that how connection is made from file name to disk controller?
The method that is used by MS-DOS, is relatively simple operating system. Thefirst part of MS-DOS
file name, is preceding with colon, is string that identifies that there is specific hardware device.
The UNIX uses different method from MS-DOS. It represents device names in regular file-system
name space. Unlike MS-DOS file name, which has colon separator, but UNIX path name has no
clear separation of device portion. In fact, no part of path name is name of device. Unix has mount
table that associates withprefixes of path names with specific hardware device names.

Modern operating systems gain significant flexibility from multiple stages of lookup tables in path
between request and physical device stages controller. There is general mechanisms is which is
used to pass request between application and drivers. Thus, without recompiling kernel, we can
introduce new devices and drivers into computer. In fact, some operating system have the ability
to load device drivers on demand. At the time of booting, system firstly probes hardware buses to
determine what devices are present. It is then loaded to necessary drivers, accordingly I/O
request.
The typical life cycle of blocking read request, is shown in the following figure. From figure, we can
suggest that I/O operation requires many steps that together consume large number of CPU
cycles.

Figure – The life cycle of I/O request


1. System call –
Whenever, any I/O request comes, process issues blocking read() system call to previously
opened file descriptor of file. Basically, role of system-call code is to check parameters for
correctness in kernel. If data we put in form of input is already available in buffer cache, data is
going to returned toprocess, and in that case I/O request is completed.
2. Alternative approach if input is not available –
If the data is not available in buffer cache then physical I/O must be performed. The process is

1146
removes from run queue and is placed on wait queue for device, and I/O request is scheduled.
After scheduling, I/O subsystem sends request to device driver via subroutine call or in-kernel
message but it depends upon operating system by which mode request willsend.
3. Role of Device driver –
After receiving the request, device driver have to receive data and it will receive data by allocating
kernel buffer space and after receiving data it will schedules I/O. After all this, command will be
given to device controller by writing into device-control registers.
4. Role of Device Controller –
Now, device controller operates device hardware. Actually, data transfer is done by device
hardware.
5. Role of DMA controller –
After data transfer, driver may poll for status and data, or it may have set up DMA transfer into
kernel memory. The transfer is managed by DMA controller. At last when transfers complete, it
will generates interrupt.
6. Role of interrupt handler –
The interrupt is send to correct interrupt handler through interrupt-vector table. It store any
necessary data, signals device driver, and returns from interrupt.
7. Completion of I/O request –
When, device driver receives signal. This signal determines that I/O request has completed and
also determines request’s status, signals kernel I/O subsystem that request has been completed.
After transferring data or return codes to address space kernel moves process from wait queue
backto ready queue.
8. Completion of System call –
When process moves to ready queue it means process is unblocked. Whenthe process is assigned
to CPU, it means process resumes execution at completion of system call.

Operating System Security (OS Security)


Operating system security (OS security) is the process of ensuring OS integrity, confidentiality and
availability.

OS security refers to specified steps or measures used to protect the OS from threats, viruses,
worms, malware or remote hacker intrusions. OS security encompasses all preventive-control
techniques, which safeguard any computer assets capable of being stolen, edited or deleted if OS
security is compromised.
Security refers to providing a protection system to computer system resources such as CPU,
memory, disk, software programs and most importantly data/information stored in the computer
system. If a computer program is run by an unauthorized user, then he/she may cause severe
damage to computer or data stored in it. So a computer system must be protected against
unauthorized access, malicious access to system memory, viruses, worms etc.

Operating System Security (OS Security)


OS security encompasses many different techniques and methods which ensure safety from
threats and attacks. OS security allows different applications and programs to perform required
tasks and stop unauthorized interference.

OS security may be approached in many ways, including adherence to thefollowing:


• Performing regular OS patch updates
1147
• Installing updated antivirus engines and software
• Scrutinizing all incoming and outgoing network traffic through a firewall
• Creating secure accounts with required privileges only (i.e., usermanagement)
Protection
Protection refers to a mechanism which controls the access of programs, processes, or users to
the resources defined by a computer system. We can take protection as a helper to multi
programming operating system, so that many users might safely share a common logical name
space such as directory or files.

Need of Protection:
• To prevent the access of unauthorized users and
• To ensure that each active programs or processes in the system usesresources only as the
stated policy,
• To improve reliability by detecting latent errors.

Role of Protection:
The role of protection is to provide a mechanism that implement policies which defines the uses
of resources in the computer [Link] policies are defined at the time of design of the
system, some are designed by management of the system and some are defined by the users of
the system to protect their own filesand programs.
Every application has different policies for use of the resources and they may change over time so
protection of the system is not only concern of the designer of the operating system. Application
programmer should also design the protection mechanism to protect their system against
misuse.
Policy is different from mechanism. Mechanisms determine how something will be done and
policies determine what will be [Link] are changed over time and place to place.
Separation of mechanism and policy is important for theflexibility of the system.

Access Matrix

Access Matrix is a security model of protection state in computer system. It is represented as a


matrix. Access matrix is used to define the rights of each process executing in the domain with
respect to each object. The rows of matrix represent domains and columns represent objects.
Each cell of matrix represents set of access rights which are given to the processes of domain
means each entry(i, j) defines the set of operations that a process executing in domain Di can
invoke on object Oj.

F1 F2 F3 PRINTER

D1 read read

D2 print

1148
D3 read execute

read write read


D4 write

According to the above matrix: there are four domains and four objects- three files(F1, F2, F3) and
one printer. A process executing in D1 can read files F1 and F3. A process executing in domain D4
has same rights as D1 but it can also write on files. Printer can be accessed by only one process
executing in domain D2. Themechanism of access matrix consists of many policies and semantic
properties.
Specifically, We must ensure that a process executing in domain Di can access only those objects
that are specified in row i.

Policies of access matrix concerning protection involve which rights should be included in the (i,
j)th entry. We must also decide the domain in which each process executes. This policy is usually
decided by the operating system. The Users decide the contents of the access-matrix entries.
Association between the domain and processes can be either static or dynamic. Access matrix
provides an mechanism for defining the control for this association between domain and
processes. When we switch a process from one domain to another, we execute a switch operation
on an object(the domain). We can control domain switching by including domains among the
objects of the access matrix.
Processes should be able to switch from one domain (Di) to another domain (Dj) if and only is a
switch right is given to access(i, j).

F1 F2 F3 PRINTER D1 D2 D3 D4

D1 read read switch

D2 print switch switch

D3 read execute

read write read write


D4 switch

According to the matrix: a process executing in domain D2 can switch to domain D3 and D4. A
process executing in domain D4 can switch to domain D1 and process executing in domain D1
can switch to domain D2.

Access Control
Access control is a method of guaranteeing that users are who they say they are and that they
have the appropriate access to company data.
1149
At a high level, access control is a selective restriction of access to data. It consists of two main
components: authentication and authorization, says Daniel Crowley, head of research for IBM’s X-
Force Red, which focuses on data security.
Authentication is a technique used to verify that someone is who they claim to be. Authentication
isn’t sufficient by itself to protect data, Crowley notes. What’s needed is an additional layer,
authorization, which determines whether a user should be allowed to access the data or make the
transaction they’re attempting.

Without authentication and authorization, there is no data security, Crowley says. “In every data
breach, access controls are among the first policies investigated,” notes Ted Wagner, CISO at SAP
National Security Services, Inc. “Whether it be the inadvertent exposure of sensitive data
improperly secured by an end user or the Equifax breach, where sensitive data was exposed
through a public-facing web server operating with a software vulnerability, access controls are a
key component. When not properly implemented or maintained, the result can becatastrophic.”
Any organization whose employees connect to the internet—in other words, every organization
today—needs some level of access control in place. “That’s especially true of businesses with
employees who work out of the office and require access to the company data resources and
services,” says Avi Chesla, CEOof cybersecurity firm empow.

Put another way: If your data could be of any value to someone without proper authorization to
access it, then your organization needs strong access control, Crowley says.

Another reason for strong access control: Access mining


The collection and selling of access descriptors on the dark web is a growing problem. For
example, a new report from Carbon Black describes how one cryptomining botnet, Smominru,
mined not only cryptcurrency, but also sensitive information including internal IP addresses,
domain information, usernames and passwords. The Carbon Black researchers believe it is "highly
plausible" that this threat actor sold this information on an "access marketplace" to others who
couldthen launch their own attacks by remote access.

These access marketplaces "provide a quick and easy way for cybercriminals to purchase access
to systems and organizations These systems can be used as zombies in large-scale attacks or as
an entry point to a targeted attack," said the report's authors. One access marketplace, Ultimate
Anonymity Services (UAS) offers 35,000 credentials with an average selling price of $6.75 per
credential.
The Carbon Black researchers believe cybercriminals will increase their use of access
marketplaces and access mining because they can be "highly lucrative" for them. The risk to an
organization goes up if its compromised user credentials have higher privileges than needed.

Access control policy: Key considerations


Most security professionals understand how critical access control is to their organization. But
not everyone agrees on how access control should be enforced, says Chesla. “Access control
requires the enforcement of persistent policies in a dynamic world without traditional borders,”
Chesla explains. Most of us work in hybrid environments where data moves from on-premises
servers or the cloud to offices, homes, hotels, cars and coffee shops with open wi-fi hot spots,
which canmake enforcing access control difficult.
“Adding to the risk is that access is available to an increasingly large range of devices,” Chesla
1150
says, including PCs, laptops, smart phones, tablets, smart
speakers and other internet of things (IoT) devices. “That diversity makes it a real challenge to
create and secure persistency in access policies.”
In the past, access control methodologies were often static. “Today, network access must be
dynamic and fluid, supporting identity and application-based usecases,” Chesla says.
A sophisticated access control policy can be adapted dynamically to respond to evolving risk
factors, enabling a company that’s been breached to “isolate the relevant employees and data
resources to minimize the damage,” he says.

Enterprises must assure that their access control technologies “are supported consistently
through their cloud assets and applications, and that they can be smoothly migrated into virtual
environments such as private clouds,” Chesla advises. “Access control rules must change based
on risk factor, which means that organizations must deploy security analytics layers using AI and
machine learning that sit on top of the existing network and security configuration. They also need
to identify threats in real-time and automate the access control rules accordingly.”

4 Types of access control


Organizations must determine the appropriate access control model to adopt based on the type
and sensitivity of data they’re processing, says Wagner. Older access models include discretionary
access control (DAC) and mandatory access control (MAC), role based access control (RBAC) is
the most common model today, and the most recent model is known as attribute based access
control (ABAC).

Discretionary access control (DAC)


With DAC models, the data owner decides on access. DAC is a means of assigning access rights
based on rules that users specify.

Mandatory access control (MAC)


MAC was developed using a nondiscretionary model, in which people are grantedaccess based on
an information clearance. MAC is a policy in which access rights are assigned based on
regulations from a central authority.

Role Based Access Control (RBAC)


RBAC grants access based on a user’s role and implements key security principles, such as “least
privilege” and “separation of privilege.” Thus, someone attempting to access information can only
access data that’s deemed necessary for their role.

Attribute Based Access Control (ABAC)


In ABAC, each resource and user are assigned a series of attributes, Wagner explains. “In this
dynamic method, a comparative assessment of the user’s attributes, including time of day,
position and location, are used to make a decision on access to a resource.”
It’s imperative for organizations to decide which model is most appropriate for them based on
data sensitivity and operational requirements for data access. In particular, organizations that
process personally identifiable information (PII) or other sensitive information types, including
Health Insurance Portability and Accountability Act (HIPAA) or Controlled Unclassified Information
(CUI) data, must make access control a core capability in their security architecture, Wagner
advises.

1151
Access control solutions
A number of technologies can support the various access control models. In some cases, multiple
technologies may need to work in concert to achieve the desired level of access control, Wagner
says.
“The reality of data spread across cloud service providers and SaaS applications and connected to
the traditional network perimeter dictate the need to
orchestrate a secure solution,” he notes. “There are multiple vendors providing privilege access
and identity management solutions that can be integrated into a traditional Active Directory
construct from Microsoft. Multifactor authentication can be a component to further enhance
security.”

Why authorization remains a challenge


Today, most organizations have become adept at authentication, says Crowley, especially with the
growing use of multifactor authentication and biometric-based authentication (such as facial or
iris recognition). In recent years, as high-profile data breaches have resulted in the selling of
stolen password credentials on the dark web, security professionals have taken the need for multi-
factor authentication more seriously, he adds.

Authorization is still an area in which security professionals “mess up more often,” Crowley says.
It can be challenging to determine and perpetually monitor who gets access to which data
resources, how they should be able to access them, and under which conditions they are granted
access, for starters. But inconsistent or weak authorization protocols can create security holes
that needto be identified and plugged as quickly as possible.
Speaking of monitoring: However your organization chooses to implement access control, it must
be constantly monitored, says Chesla, both in terms of compliance to your corporate security
policy as well as operationally, to identify any potential security holes. “You should periodically
perform a governance, risk and compliance review,” he says. “You need recurring vulnerability
scans against any application running your access control functions, and you should collect and
monitor logs on each access for violations of the policy.”

In today’s complex IT environments, access control must be regarded as “a living technology


infrastructure that uses the most sophisticated tools, reflects changes in the work environment
such as increased mobility, recognizes the changes in the devices we use and their inherent risks,
and takes into account the growing movement toward the cloud,” Chesla says.

Revocation of Access RightsRevocation of Access Rights


In a dynamic protection system, we may sometimes need to revoke access rights to objects
shared by different users. Various questions about revocation may arise:
• Immediate versus delayed. Does revocation occur immediately/ or is it delayed? If
revocation is delayed, can we find out when it will take place?
• Selective versus general. When an access right to an object is revoked, does it affect all the
users who have an access right to that object, or can we specify a select group of users
whose access rights should be revoked?

1152
• Partial versus total. Can a subset of the rights associated with an object be revoked, or
must we revoke all access rights for this object?
• Temporary versus permanent. Can access be revoked permanently (that is, the revoked
access right will never again be available), or can access be revoked and later be obtained
again? With an access-list scheme, revocation is easy.

The access list is searched for any access rights to be revoked, and they are deleted from the list.
Revocation is immediate and can be general or selective, total or partial, and permanent or
temporary. Capabilities, however, present a much more difficult revocation problem. Since the
capabilities are distributed throughout the system, we must find them before we can revoke them.
Schemesthat implement revocation for capabilities include the following:

Reacquisition. Periodically, capabilities are deleted from each domain. If a process wants to use a
capability, it may find that that capability has been deleted. The process may then try to reacquire
the capability. If access has been revoked, the process will not be able to reacquire the capability.
• Back-pointers. A list of pointers is maintained with each object, pointing to all capabilities
associated with that object. When revocation is required, we can follow these pointers,
changing the capabilities as necessaryy. This scheme was adopted in the MULTICS
system. It is quite general, but its implementation is costly.
• Indirection. The capabilities point indirectly, not directly, to the objects. Each capability
points to a unique entry in a global table, which in turn points to the object. We implement
revocation by searching the global table for the desired entry and deleting it. Then, when
1153
an access is attempted, the capability is foundto point to an illegal table entry.

Table entries can be reused for other capabilities without difficulty, since both the capability and
the table entry contain the unique name of the object. The object for a 14.8 Capability-Based
Systems 547 capability and its table entry must match. This scheme was adopted in the CAL
system. It does not allow selective revocation. Keys. A key is a unique bit pattern that can be
associated with a capability. Tliis key is defined when the capability is created, and it can be
neithermodified nor inspected by the process owning the capability.

A master key is associated with each object; it can be defined or replaced with the set-key
operation. When a capability is created, the current value of the master key is associated with the
capability. When the capability is exercised, its key is compared with the master key. If the keys
match, the operation is allowed to continue; otherwise, an exception condition is raised.
Revocation replaces the master key with a new value via the set-key operation, invalidating all
previous capabilities for this object. This scheme does not allowr selective revocation, since only
one master key is associated with each object. If we associate a list of keys with each object, then
selective revocation can beimplemented.

Finally, we can group all keys into one global table of keys. A capability is valid only if its key
matches some key in the global table. We implement revocation by removing the matching key
from the table. With this scheme, a key can be associated with several objects, and several keys
can be associated with each object, providing maximum flexibility. In key-based schemes, the
operations of defining keys, inserting them into lists, and deleting them from lists should not be
available to all users. In particular, it would be reasonable to allow only the owner of an object to
set the keys for that object. This choice, however, is a policy decision that the protection system
can implement but should not define.

Threats
Threats can be classified into the following two categories:
1. Program Threats:
A program written by a cracker to hijack the security or to change the behaviour of a normal
process.
2. System Threats:
These threats involve the abuse of system services. They strive to create a situation in which
operating-system resources and user files are misused. They are also used as a medium to
launch program threats.
System threats refers to misuse of system services and network connections to put user in
trouble. System threats can be used to launch program threats on a complete network called as
program attack. System threats creates such an environment that operating system resources/
userfiles are misused. Following is the list of some well-known system threats.

Types of Program Threats –


1. Virus:
An infamous threat, known most widely. It is a self-replicating and a malicious thread which
attaches itself to a system file and then rapidly replicates itself, modifying and destroying
essential files leading to a systembreakdown.
Further, Types of computer viruses can be described briefly as follows:

1154
– file/parasitic – appends itself to a file
– boot/memory – infects the boot sector
– macro – written in a high-level language like VB and affects MS Office files
– source code – searches and modifies source codes
– polymorphic – changes in copying each time
– encrypted – encrypted virus + decrypting code
– stealth – avoids detection by modifying parts of the system that can be used to detect it, like
the read system call
– tunneling – installs itself in the interrupt service routines and device drivers
– multipartite – infects multiple parts of the system

2. Trojan Horse:
A code segment that misuses its environment is called a Trojan Horse. Theyseem to be attractive
and harmless cover program but are a really harmful hidden program which can be used as the
virus carrier. In one of the versions of Trojan, User is fooled to enter its confidential login details on
an application. Those details are stolen by a login emulator and can be further used as a way of
information breaches.
Another variance is Spyware, Spyware accompanies a program that the user has chosen to install
and downloads ads to display on the user’s system, thereby creating pop-up browser windows and
when certain sites are visited by the user,it captures essential information and sends it over to the
remote server. Such attacks are also known as Covert Channels.

3. Trap Door:
The designer of a program or system might leave a hole in the software that only he is capable of
using, the Trap Door works on the similar principles. Trap Doors are quite difficult to detect as to
analyze them, oneneeds to go through the source code of all the components of the system.

4. Logic Bomb:
A program that initiates a security attack only under a specific situation.

Types of System Threats –


Aside from the program threats, various system threats are also endangering the security of our
system:

1. Worm:
An infection program which spreads through networks. Unlike a virus, they target mainly LANs. A
computer affected by a worm attacks the target system and writes a small program “hook” on it.
This hook is further used to copy the worm to the target computer. This process repeats
recursively, and soon enough all the systems of the LAN are affected. It uses the spawn
mechanism to duplicate itself. The worm spawns copies of itself, using up a majority of system
resources and also locking out all other processes.
The basic functionality of a the worm can be represented as:

1155
2. Port Scanning:
It is a means by which the cracker identifies the vulnerabilities of the system to attack. It is an
automated process which involves creating a TCP/IP connection to a specific port. To protect the
identity of the attacker, port scanning attacks are launched from Zombie Systems, that is systems
which were previously independent systems that are also serving their owners while being used
for such notorious purposes.

3. Denial of Service:
Such attacks aren’t aimed for the purpose of collecting information or destroying system files.
Rather, they are used for disrupting the legitimateuse of a system or facility.
These attacks are generally network based. They fall into two categories:
– Attacks in this first category use so many system resources that no useful work can be
performed.
For example, downloading a file from a website that proceeds to use all availableCPU time.
– Attacks in the second category involves disrupting the network of the [Link] attacks are
a result of the abuse of some fundamental TCP/IP principles. fundamental functionality of
TCP/IP.

Security Measures Taken –


To protect the system, Security measures can be taken at the following levels:
• Physical:
The sites containing computer systems must be physically secured against armed and malicious
intruders. The workstations must be carefully protected.
• Human:
Only appropriate users must have the authorization to access the system. Phishing(collecting
confidential information) and Dumpster Diving(collecting basic information so as to gain
unauthorized access) mustbe avoided.
• Operating system:
The system must protect itself from accidental or purposeful securitybreaches.
• Networking System:
Almost all of the information is shared between different systems via a network. Intercepting
these data could be just as harmful as breaking into a computer. Henceforth, Network should be
properly secured against such attacks.
Usually, Anti Malware programs are used to periodically detect and remove such viruses and
1156
threats. Additionally, to protect the system from the Network Threats, Firewall is also be used.
Network Security ThreatsTypes of Network Threats

Network-delivered threats are typically of two basic types:


• Passive Network Threats: Activities such as wiretapping and idle scans that are designed to
intercept traffic traveling through the network.
• Active Network Threats: Activities such as Denial of Service (DoS) attacks and SQL injection
attacks where the attacker is attempting to execute commands to disrupt the network’s normal
operation.

To execute a successful network attack, attackers must typically actively hack a company’s
infrastructure to exploit software vulnerabilities that allow them to remotely execute commands
on internal operating systems. DoS attacks and shared network hijacking (example: when
corporate user is on a public WiFi network) of communications are exceptions.
Attackers typically gain access to internal operating systems via email-delivered network threats
which first compromise a set of machines, then install attacker controlled malware, and so
provide ability for the attacker to move laterally. Thisincreases the likelihood of not being detected
up front while providing an almosteffortless entry point for the attacker.

According to a recent Microsoft security intelligence report, more than 45% of malware requires
some form of user interaction, suggesting that user-targeted email, designed to trick users, is a
primary tactic used by attackers to establishtheir access.
Some threats are designed to disrupt an organisation’s operations rather than silently gather
information for financial gain or espionage. The most popular approach is called a Denial of
Service (DoS) attack. These attacks overwhelm network resources such as web and email
gateways, routers, switches, etc. and prevent user and application access, ultimately taking a
service offline or severely degrading the quality of a service. These do not necessarily require
active hacking,but instead rely on attackers’ ability to scale traffic towards an organisation to take
advantage of misconfigured and poorly protected infrastructure. This means they often make use
of a network of compromised computer systems that work in tandem to overwhelm the target,
known as a Distributed Denial of Service (DDoS) attack. In many cases, attackers will launch DoS
and DDoS attacks while attempting active hacking or sending in malicious email threats to
camouflage their real motives from the information security teams by creating distractions.

While detection, perimeter hardening, and patching processes are required to mitigate network
threats from active and passive network threats, as a basic starting point organisations need to
protect themselves especially from the email-delivered security threats that subsequently
enable network-threats to be successful.

Cryptography
Cryptography is the science to encrypt and decrypt data that enables the users to store sensitive
information or transmit it across insecure networks so that it can be read only by the intended
recipient.
Data which can be read and understood without any special measures is called plaintext, while the
method of disguising plaintext in order to hide itssubstance is called encryption.

Encrypted plaintext is known as cipher text and process of reverting the encrypted data back to
1157
plain text is known as decryption.
• The science of analyzing and breaking secure communication is known as cryptanalysis.
The people who perform the same also known as attackers.
• Cryptography can be either strong or weak and the strength is measured by the time and
resources it would require to recover the actual plaintext.
• Hence an appropriate decoding tool is required to decipher the strong encrypted
messages.
• There are some cryptographic techniques available with which even a billion computers
doing a billion checks a second, it is not possible to decipher the text.
• As the computing power is increasing day by day, one has to make the encryption
algorithms very strong in order to protect data and critical information from the attackers.

How Encryption Works?


A cryptographic algorithm works in combination with a key (can be a word, number, or phrase) to
encrypt the plaintext and the same plaintext encrypts todifferent cipher text with different keys.
Hence, the encrypted data is completely dependent couple of parameters such as the strength of
the cryptographic algorithm and the secrecy of the key.

Cryptography Techniques
Symmetric Encryption − Conventional cryptography, also known as conventional encryption, is the
technique in which only one key is used for both encryption and decryption. For example, DES,
Triple DES algorithms, MARS by IBM, RC2, RC4, RC5, RC6.

Asymmetric Encryption − It is Public key cryptography that uses a pair of keys for encryption: a
public key to encrypt data and a private key for decryption. Public key is published to the people
while keeping the private key secret. For example,RSA, Digital Signature Algorithm (DSA), Elgamal.

Hashing − Hashing is ONE-WAY encryption, which creates a scrambled output that cannot be
reversed or at least cannot be reversed easily. For example, MD5 algorithm. It is used to create
Digital Certificates, Digital signatures, Storage of passwords, Verification of communications, etc.

Authentication
Authentication refers to identifying each user of the system and associating the executing
programs with those users. It is the responsibility of the Operating System to create a protection
system which ensures that a user who is running a particular program is authentic. Operating
Systems generally identifies/authenticates users using following three ways −
• Username / Password − User need to enter a registered username and password with
Operating system to login into the system.
• User card/key − User need to punch card in card slot, or enter key generated by key
generator in option provided by operating system to logininto the system.
• User attribute - fingerprint/ eye retina pattern/ signature − User need to pass his/her
attribute via designated input device used by operating systemto login into the system.

One Time passwords


One-time passwords provide additional security along with normal authentication. In One-Time
1158
Password system, a unique password is required every time user tries to login into the system.
Once a one-time password is used, then it cannot be used again. One-time password are
implemented in various ways.
• Random numbers − Users are provided cards having numbers printed alongwith corresponding
alphabets. System asks for numbers corresponding to few alphabets randomly chosen.
• Secret key − User are provided a hardware device which can create a secret id mapped with
user id. System asks for such secret id which is to be generated every time prior to login.
• Network password − Some commercial applications send one-time passwords to user on
registered mobile/ email which is required to beentered prior to login.
• Program Threats
Operating system's processes and kernel do the designated task as instructed. If a user
program made these process do malicious tasks, then it is known as Program Threats. One of
the common example of program threat is a program installed in a computer which can store
and send user credentials via network to some hacker. Following is the list of some well-
known program threats.
• Trojan Horse − Such program traps user login credentials and stores themto send to malicious
user who can later on login to computer and can access system resources.
• Trap Door − If a program which is designed to work as required, have a security hole in its code
and perform illegal action without knowledge ofuser then it is called to have a trap door.
• Logic Bomb − Logic bomb is a situation when a program misbehaves only when certain
conditions met otherwise it works as a genuine program. It isharder to detect.
• Virus − Virus as name suggest can replicate themselves on computer system. They are highly
dangerous and can modify/delete user files, crash systems. A virus is generatlly a small code
embedded in a program. As user accesses the program, the virus starts getting embedded in
other files/ programs and can make system unusable for user

Computer Security Classifications


As per the U.S. Department of Defense Trusted Computer System's Evaluation Criteria there are
four security classifications in computer systems: A, B, C, and [Link] is widely used specifications
to determine and model the security of systems and of security solutions. Following is the brief
description of each classification.

S.N. Classification Type & Description

1 Type A

Highest Level. Uses formal design specifications and verification techniques.


Grants a high degree of assurance of process security.

1159
2 Type B

Provides mandatory protection system. Have all the properties of a class C2


system. Attaches a sensitivity label to each object. It is of three types.
• B1 − Maintains the security label of each object in the system. Label is
used for making decisions to access control.
• B2 − Extends the sensitivity labels to each system resource, such as
storage objects, supports covert channels and auditing of events.
• B3 − Allows creating lists or user groups for access-control to grant
access or revoke access to a given named object.

3 Type C
Provides protection and user accountability using audit capabilities. It is of two
types.
• C1 − Incorporates controls so that users can protect their privateinformation
and keep other users from accidentally reading / deleting their data. UNIX
versions are mostly Cl class.
• C2 − Adds an individual-level access control to the capabilities of a Cl level
system.
4 Type D
Lowest level. Minimum protection. MS-DOS, Window 3.1 fall in thiscategory.

Virtual Machine
A Virtual Machine (VM) is a compute resource that uses software instead of a physical computer
to run programs and deploy apps. One or
more virtual “guest” machines run on a physical “host” machine. Each virtual machine runs its own
operating system and functions separately from the other VMs, even when they are all running on
the same host. This means that, for example, a virtual MacOS virtual machine can run on a
physical PC.
Virtual machine technology is used for many use cases across on-premises and cloud
environments. More recently, public cloud services are using virtual machines to provide virtual
application resources to multiple users at once, foreven more cost efficient and flexible compute.

What are virtual machines used for?


Virtual machines (VMs) allow a business to run an operating system that behaveslike a completely
separate computer in an app window on a desktop. VMs may be deployed to accommodate
different levels of processing power needs, to
run software that requires a different operating system, or to test applications ina safe, sandboxed
environment.
Virtual machines have historically been used for server virtualization, which enables IT teams to
consolidate their computing resources and improve efficiency. Additionally, virtual machines can
perform specific
tasks considered too risky to carry out in a host environment, such as accessing virus-infected
data or testing operating systems. Since the virtual machine
is separated from the rest of the system, the software inside the virtual machine cannot tamper
with the host computer.
1160
How do virtual machines work?
The virtual machine runs as a process in an application window, similar to any other application,
on the operating system of the physical machine. Key files that make up a virtual machine include
a log file, NVRAM setting file, virtual disk file and configuration file.

Advantages of virtual machines


Virtual machines are easy to manage and maintain, and they offer several advantages over
physical machines:
• VMs can run multiple operating system environments on a single physical computer, saving
physical space, time and management costs.
• Virtual machines support legacy applications, reducing the cost
• of migrating to a new operating system. For example, a Linux virtual machine running a
distribution of Linux as the guest operating system can exist on a host server that is running a
non-Linux operating system, such asWindows.
• VMs can also provide integrated disaster recovery and applicationprovisioning options.

Disadvantages of virtual machines


While virtual machines have several advantages over physical machines, there are also some
potential disadvantages:
• Running multiple virtual machines on one physical machine can result in unstable performance
if infrastructure requirements are not met.
• Virtual machines are less efficient and run slower than a full physical computer. Most
enterprises use a combination of physical and virtual infrastructure to balance the
corresponding advantages and disadvantages.
• The two types of virtual machines

Users can choose from two different types of virtual machines—process VMs andsystem VMs:
A process virtual machine allows a single process to run as an application on a host machine,
providing a platform-independent programming environment by masking the information of the
underlying hardware or operating system. An example of a process VM is the Java Virtual
Machine, which enables any operating system to run Java applications as if they were native to
that system.

A system virtual machine is fully virtualized to substitute for a physical machine. A system
platform supports the sharing of a host computer’s physical resources between multiple virtual
machines, each running its own copy of the
operating system. This virtualization process relies on a hypervisor, which can run on bare
hardware, such as VMware ESXi, or on top of an operating system.

What are 5 types of virtualization?


All the components of a traditional data center or IT infrastructure can be virtualized today, with
various specific types of virtualization:
• Hardware virtualization: When virtualizing hardware, virtual versions of computers and
operating systems (VMs) are created and consolidated into a single, primary, physical server. A
hypervisor communicates directly with a physical server’s disk space and CPU to manage the

1161
VMs. Hardware virtualization, which is also known as server virtualization, allows hardware
resources to be utilized more efficiently and for one machine
to simultaneously run different operating systems.
• Software virtualization: Software virtualization creates a computer system complete with
hardware that allows one or more guest operating
systems to run on a physical host machine. For example, Android OS can run on a host machine
that is natively using a Microsoft Windows OS, utilizing the same hardware as the host machine
does. Additionally, applications can be virtualized and delivered from a server to an end user’s
device, such as a laptop or smartphone.
This allows employees to access centrally hosted applications whenworking remotely.
• Storage virtualization: Storage can be virtualized by consolidating multiple physical storage
devices to appear as a single storage device. Benefits include increased performance and speed,
load balancing and reduced costs. Storage virtualization also helps with disaster recovery
planning,
as virtual storage data can be duplicated and quickly transferred to another location, reducing
downtime.
• Network virtualization: Multiple sub-networks can be created on the same physical network by
combining equipment into a single, software-
based virtual network resource. Network virtualization also divides available bandwidth into
multiple, independent channels, each of which can be assigned to servers and devices in real
time. Advantages include increased reliability, network speed, security and better monitoring of
datausage. Network virtualization can be a good choice for companies with
a high volume of users who need access at all times.

• Desktop virtualization: This common type of virtualization separates the desktop environment
from the physical device and stores a desktop on a remote server, allowing users to access their
desktops from anywhere on any device. In addition to easy accessibility, benefits of virtual
desktops include better data security, cost savings on software licenses and updates, and ease of
management.

Container vs virtual machine


Like virtual machines, container technology such as Kubernetes is similar in the sense of running
isolated applications on a single platform. While virtual machines virtualize the hardware layer to
create a “computer,” containers package up just a single app along with its dependencies. Virtual
machines are often managed by a hypervisor, whereas container systems provide shared
operating system services from the underlying host and isolate the applications using virtual-
memory hardware.

A key benefit of containers is that they have less overhead compared to virtual machines.
Containers include only the binaries, libraries and other required dependencies, and the
application. Containers that are on the same host share the same operating system kernel,
making containers much smaller than virtual machines. As a result, containers boot faster,
maximize server resources, and make delivering applications easier. Containers have become
popluar for use cases such as web applications, DevOps testing, microservices and maximizing
the number of apps that can be deployed perserver.

Virtual machines are larger and slower to boot than containers. They are logically isolated from
one another, with their own operating system kernel, and offer the benefits of a completely
1162
separate operating system. Virtual machines are best for running multiple applications together,
monolithic applications, isolation between apps, and for legacy apps running on older operating
systems. Containers and virtual machines may also be used together.

Virtualization
With the help of OS virtualization nothing is pre-installed or permanently loaded on the local device
and no-hard disk is needed. Everything runs from the network using a kind of virtual disk. This
virtual disk is actually a disk image file stored on a remote server, SAN (Storage Area Network) or
NAS (Non-volatile Attached Storage). The client will be connected by the network to this virtual
disk and will boot with the Operating System installed on the virtual disk.

How does OS Virtualization works?


Components needed for using OS Virtualization in the infrastructure are givenbelow:
The first component is the OS Virtualization server. This server is the center point in the OS
Virtualization infrastructure. The server manages the streaming of the information on the virtual
disks for the client and also determines which client willbe connected to which virtual disk (using a
database, this information is stored).
Also the server can host the storage for the virtual disk locally or the server is connected to the
virtual disks via a SAN (Storage Area Network). In high availability environments there can be more
OS Virtualization servers to create noredundancy and load balancing. The server also ensures that
the client will be unique within the infrastructure.
Secondly, there is a client which will contact the server to get connected to thevirtual disk and asks
for components stored on the virtual disk for running the operating system.

The available supporting components are database for storing the configuration and settings for
the server, a streaming service for the virtual disk content, a (optional) TFTP service and a (also
optional) PXE boot service for connecting theclient to the OS Virtualization servers.
As it is already mentioned that the virtual disk contains an image of a physical disk from the
system that will reflect to the configuration and the settings of those systems which will be using
the virtual disk. When the virtual disk is created then that disk needs to be assigned to the client
that will be using this disk for starting.

The connection between the client and the disk is made through the administrative tool and saved
within the database. When a client has a assigneddisk, the machine can be started with the virtual
disk using the following process

Figure: as displayed in the given below

1163
1) Connecting to the OS Virtualization server:
First we start the machine and set up the connection with the OS Virtualization server. Most of the
products offer several possible methods to connect with the server. One of the most popular and
used methods is using a PXE service, but also a boot strap is used a lot (because of the
disadvantages of the PXE service).
Although each method initializes the network interface card (NIC), receiving a (DHCP-based) IP
address and a connection to the server.

2) Connecting the Virtual Disk:


When the connection is established between the client and the server, the server will look into its
database for checking the client is known or unknown and which virtual disk is assigned to the
client. When more than one virtual disk are connected then a boot menu will be displayed on the
client side. If only one disk isassigned, that disk will be connected to the client which is mentioned
in step number 3.

3) VDisk connected to the client:


After the desired virtual disk is selected by the client, that virtual disk is connected through the OS
Virtualization server . At the back-end, the OS Virtualization servermakes sure that the client will be
unique (for example computer name and identifier) within the infrastructure.

4) OS is "streamed" to the client:


As soon the disk is connected the server starts streaming the content of the virtual disk. The
software knows which parts are necessary for starting the operating system smoothly, so that
these parts are streamed first. The information streamed in the system should be stored
somewhere (i.e. cached). Most products offer several ways to cache that information. For
examples on theclient hard disk or on the disk of the OS Virtualization server.

5) Additional Streaming:
After that the first part is streamed then the operating system will start to run as expected.
Additional virtual disk data will be streamed when required for runningor starting a function called
by the user (for example starting an application available within the virtual disk).
Linux
1164
Linux is one of popular version of UNIX operating System. It is open source as its source code is
freely available. It is free to use. Linux was designed considering UNIX compatibility. Its
functionality list is quite similar to that of UNIX.

Components of Linux System


Linux Operating System has primarily three components
• Kernel − Kernel is the core part of Linux. It is responsible for all major activities of this
operating system. It consists of various modules and it interacts directly with the underlying
hardware. Kernel provides the required abstraction to hide low level hardware details to
system or application programs.

• System Library − System libraries are special functions or programs using which application
programs or system utilities accesses Kernel's [Link] libraries implement most of the
functionalities of the operating system and do not requires kernel module's code access
rights.
• System Utility − System Utility programs are responsible to do specialized, individual level
tasks.

Kernel Mode vs User Mode


Kernel component code executes in a special privileged mode called kernel mode with full access
to all resources of the computer. This code represents a single process, executes in single
address space and do not require any context switch and hence is very efficient and fast. Kernel
runs each processes and provides system services to processes, provides protected access to
hardware toprocesses.

Support code which is not required to run in kernel mode is in System Library. User programs and
other system programs works in User Mode which has no access to system hardware and kernel
code. User programs/ utilities use System libraries to access Kernel functions to get system's low
level tasks.

Basic Features

1165
Following are some of the important features of Linux Operating System.
• Portable − Portability means software can works on different types of hardware in same way.
Linux kernel and application programs supports their installation on any kind of hardware
platform.
• Open Source − Linux source code is freely available and it is community based development
project. Multiple teams work in collaboration to enhance the capability of Linux operating
system and it is continuously evolving.
• Multi-User − Linux is a multiuser system means multiple users can access system resources
like memory/ ram/ application programs at same time.
• Multiprogramming − Linux is a multiprogramming system means multiple applications can run
at same time.
• Hierarchical File System − Linux provides a standard file structure in which system files/ user
files are arranged.
• Shell − Linux provides a special interpreter program which can be used to execute commands
of the operating system. It can be used to do various types of operations, call application
programs. etc.
• Security − Linux provides user security using authentication features like password protection/
controlled access to specific files/ encryption of data.

Architecture
The following illustration shows the architecture of a Linux system –

The architecture of a Linux System consists of the following layers −


• Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/CPU etc).
• Kernel − It is the core component of Operating System, interacts directly with hardware,
1166
provides low level services to upper layer components.
• Shell − An interface to kernel, hiding complexity of kernel's functions from users. The shell
takes commands from the user and executes kernel's functions.
• Utilities − Utility programs that provide the user most of the functionalities of an operating
systems.

Linux Design Principles


In its overall design, Linux resembles another non-microkernel
UNIX implementation. It is a multi-user, multi-tasking system with completeUNIX-compatible tools.
The Linux file system follows the traditional UNIX semantics, and the UNIX standard network
model is implemented as a whole. The internal characteristics of Linux design have been
influenced by the history of the development of this operating system.
Although Linux can run on a variety of platforms, at first it was developed exclusively on PC
architecture. Most of the initial development was carried out byindividual enthusiasts, not by large
funded research facilities, so that from the start Linux tried to include as much functionality as
possible with very limited funds. Currently, Linux can run well on multi-processor machines with
very large main memory and disk space that is also very large, but still capable of operating in a
useful amount of RAM smaller than 4 MB.

1. Linux Design Principles


As a result of the development of PC technology, the Linux kernel is also becoming more
complete in implementing UNIX functions. Fast and efficient are important design goals, but lately
the concentration of Linux development has focused more on the third design goal,
standardization. The POSIX standard consists of a collection of specifications from different
aspects of operating system behavior. There are POSIX documents for ordinary operating system
functions and for extensions such as processes for threads and real-time operations. Linux is
designed to fit the relevant POSIX documents; there are at least two Linux distributions that have
received POSIX official certification.

Because Linux provides a standard interface to programmers and users, Linux does not make
many surprises to anyone who is familiar with UNIX. But the Linuxprogramming interface refers to
the UNIX SVR4 semantics rather than BSD behavior. A different collection of libraries is available
to implement the BSD semantics in places where the two behaviors are very different.
There are many other standards in the UNIX world, but Linux’s full certification of other UNIX
standards sometimes becomes slow because it is more often available at a certain price (not
freely), and there is a price to pay if it involves certification of approval or compatibility of an
operating system with most standards .

Supporting broad applications is important for all operating systems so that the implementation of
the standard is the main goal of developing Linux even though its implementation is not formally
valid. In addition to the POSIX standard, Linux currently supports POSIX thread extensions and
subsets of extensions for POSIX real-time process control.

2. Linux System Components


The Linux system consists of three important code parts:
1. Kernel: Responsible for maintaining all important abstractions of the operating system,
including things like processes and virtual memory.
1167
2. System library: defines a set of standard functions where applications can interact with the
kernel, and implements almost all operating system functions that do not require full rights to the
kernel.
3. System Utility: is a program that performs management work individuallyand specifically.

Kernel
Although various modern operating systems have adopted a message-passing architecture for
their internal kernel, Linux uses the historical UNIX model: the kernel was created as a single,
monolithic binary. The main reason is to improve performance: Because all data structures and
kernel code are stored in one address space, context switching is not needed when a process
calls an operating system function or when a hardware interrupt is sent. Not only scheduling core
and virtual memory code occupies this address space; all kernel code, including all device drivers,
file systems, and network code, come in the same address space.
The Linux kernel forms the core of the Linux operating system. It provides all the functions needed
to run the process, and is provided with system services to provide settings and protection for
access to hardware resources. The kernel implements all the features needed to work as an
operating system. However, ifalone, the operating system provided by the Linux kernel is not at all
similar to UNIX systems. It does not have many extra UNIX features, and the features provided are
not always in the format expected by the UNIX application. The interface of the operating system
that is visible to the running application is not maintained directly by the kernel. Instead, the
application makes calls to the system library, which then invokes the operating system services
that are needed.

System Library
The system library provides many types of functions. At the easiest level, they allow applications
to make requests to the kernel system services. Making a system call involves transferring
controls from non-essential user mode to important kernel mode; the details of this transfer are
different for each architecture. The library has the duty to collect system-call arguments and, if
necessary, arrange those arguments in the special form needed to make systemcalls.
Libraries can also provide more complex versions of basic system calls. For example, the buffered
file-handling functions of the C language are all implemented in the system library, which results in
better control of file I / O than those provided by the basic kernel system call. The library also
provides routines that have nothing to do with system calls, such as sorting algorithms,
mathematical functions, and string manipulation routines. All functions needed to support the
running of UNIX or POSIX applications are implemented in the systemlibrary.

System Utilities
Linux systems contain many user-mode programs: system utilities and user utilities. The system
utilities include all the programs needed to initialize the system, such as programs for configuring
network devices or for loading kernel modules. Server programs that are running continuously are
also included as system utilities; This kind of program manages user login requests, incoming
network connections, and printer queues.

Not all standard utilities perform important system administration functions. The UNIX user
environment contains a large number of standard utilities for doing daily work, such as making
directory listings, moving and deleting files, or showing the contents of a file. More complex
utilities can perform text-processing functions, such as compiling textual data or performing

1168
pattern-searches on text input. When combined, these utilities form the standard toolset expected
by users on any UNIX system; even if it doesn’t perform any operating system functions, utilities
are still an important part of a basic Linux system.
Linux Process Management
In this article we will cover the basics of process management in Linux. This topic is of particular
importance if you are responsible for administering a system whichhas not yet been proven stable,
that is not fully tested in its configuration. You may find that as you run software, problems arise
requiring administrator intervention. This is the world of process management

Process Management
Any application that runs on a Linux system is assigned a process ID or PID. This is a numerical
representation of the instance of the application on the system. In most situations this
information is only relevant to the system administrator who may have to debug or terminate
processes by referencing the PID. Process Management is the series of tasks a System
Administrator completes to monitor,manage, and maintain instances of running applications.

Multitasking
Process Management beings with an understanding concept of Multitasking. Linux is what is
referred to as a preemptive multitasking operating system.
Preemptive multitasking systems rely on a scheduler. The function of the scheduler is to control
the process that is currently using the CPU. In contrast, symmetric multitasking systems such as
Windows 3.1 relied on each running process to voluntary relinquish control of the processor. If an
application in thissystem hung or stalled, the entire computer system stalled. By making use of an
additional component to pre-empt each process when its “turn” is up, stalled programs do not
affect the overall flow of the operating system.

Each “turn” is called a time slice, and each time slice is only a fraction of a second long. It is this
rapid switching from process to process that allows a computer to “appear’ to be doing two
things at once, in much the same way a movie
“appears” to be a continuous picture.

Types of Processes
There are generally two types of processes that run on Linux. Interactive processes are those
processes that are invoked by a user and can interact with the user. VI is an example of an
interactive process. Interactive processes can be classified into foreground and background
processes. The foreground process is the process that you are currently interacting with, and is
using the terminal as its stdin (standard input) and stdout (standard output). A background
process is not interacting with the user and can be in one of two states – paused or running.
The following exercise will illustrate foreground and background processes.
1. Logon as root.
2. Run [cd \]
3. Run [vi]
4. Press [ctrl + z]. This will pause vi
5. Type [jobs]
6. Notice vi is running in the background
7. Type [fg %1]. This will bring the first background process to the foreground.
8. Close vi.
1169
The second general type of process that runs on Linux is a system process or Daemon (day-mon).
Daemon is the term used to refer to process’ that are running on the computer and provide
services but do not interact with the console. Most server software is implemented as a daemon.
Apache, Samba, and inn are all examples of daemons.
Any process can become a daemon as long as it is run in the background, and does not interact
with the user. A simple example of this can be achieved using the [ls –R] command. This will list
all subdirectories on the computer, and is similar to the [dir /s] command on Windows. This
command can be set to run in the background by typing [ls –R &], and although technically you
have control over the shell prompt, you will be able to do little work as the screen displays the
output of the process that you have running in the background. You will also notice that the
standard pause (ctrl+z) and kill (ctrl+c) commands do little to helpyou.

Linux Scheduling
The Linux scheduler is a priority based scheduler that schedules tasks based upon their static and
dynamic priorities. When these priorities are combined they form a task's goodness . Each time
the Linux scheduler runs, every task on the run queue is examined and its goodness value is
computed. The task with the highest goodness is chosen to run next.

When there are cpu bound tasks running in the system, the Linux scheduler may not be called for
intervals of up to .40 seconds. This means that the currently running task has the CPU to itself for
periods of up to .40 seconds (how long depends upon the task's priority and whether it blocks or
not). This is good for throughput because there are few computationally uneccessary context
switches. However it can kill interactivity because Linux only reschedules when a task blocks or
when the task's dynamic priority (counter) reaches zero. Thus under Linux's default priority based
scheduling method, long scheduling latencies can occur.

Looking at the scheduling latency in finer detail, the Linux scheduler makes use of a timer that
interrupts every 10 msec. This timer erodes the currently running task's dynamic priority
(decrements its counter). A task's counter starts out at the same value its priority contains. Once
its dynamic priority (counter) has eroded to0 it is again reset to that of its static priority (priority). It
is only after the counter reaches 0 that a call to schedule() is made. Thus a task with the default
priority of20 may run for .200 secs (200 msecs) before any other task in the system gets a chance
to run. A task at priority 40 (the highest priority allowed) can run for .400 secs without any
scheduling occurring as long as it doesn't block or yield.

Linux scheduler has been gone through some big improvements since kernel version 2.4. There
were a lot of complaints about the interactivity of the scheduler in kernel 2.4. During this version,
the scheduler was implemented with one running queue for all available processors. At every
scheduling, this queue was locked and every task on this queue got its timeslice update. This
implementation caused poor performance in all aspects. The scheduler algorithm and supporting
code went through a large rewrite early in the 2.5 kernel development series. The new scheduler
was arisen to achieveO(1 ) run-time regardless number of runnable tasks in the system. To
achieve this, each processor has its own running queue. This helps a lot in reducing lock
contention. The priority array was introduced which used active array and expired array to keep
track running tasks in the system. TheO(1 ) running time is primarily drawn from this new data
structure. The scheduler puts all expired processes into expired array. When there is no active
process available in active array, it swaps active array with expired array, which makes active
array becomes expired array and expired array becomes active array. There were some twists
1170
made into this scheduler to optimize further by putting expired task back to active array instead of
expired array in some cases.O(1 ) scheduler uses a heuristic calculation to update dynamic
priority of tasks based on their interactivity (I/O bound versus CPU bound) The industry was happy
with this new scheduler until Con Kolivas introduced his new scheduler named Rotating Staircase
Deadline (RSDL) and then later Staircase Deadline (SD). His new schedulers proved the fact that
fair scheduling among processes can be achieved without any complex computation. His
scheduler was designed to run inO(n ) but its performance exceeded the currentO(1 ) scheduler.
The result achieved from SD scheduler surprised all kernel developers and designers. The fair
scheduling approach in SD scheduler encouraged Igno Molnar to re-implement the new Linux
scheduler named Completely Fair Scheduler (CFS).CFS scheduler was a big improvement over the
existing scheduler not only in its performance and interactivity but also in simplifying the
scheduling logic and putting more modularized code into the scheduler. CFS scheduler was
merged into mainline version 2.6.23. Since then, there have been some minor improvements
made to CFS scheduler in some areas such as optimization, load balancing and group scheduling
feature.

Kernel 2.4 Major Features


• An O(n) scheduler - Goes through the entire “ global runqueue” to determine the next task to be
run. This is an O(n) algorithm where 'n' is the number of processes. The time taken was
proportional to the number of active processes in the system
• A Global runqueue - All CPUs had to wait for other CPUs to finish execution. A Global runqueue
for all processors in a symmetric multiprocessing system (SMP). This meant a task could be
scheduled on any processor -- which can be good for load balancing but bad for memory
caches. For example, suppose a task executed on CPU-1, and its data was in that processor's
cache. If the task got rescheduled to CPU-2, its data would need to be invalidated in CPU-1 and
brought into CPU-2 .
• This lead to large performance hits during heavy workload

Kernel 2.4 Scheduler Policies:


• SCHED_FIFO - A First-In, First-Out real-time process. When the scheduler assigns the CPU to
the process, it leaves the process descriptor in its current position in the runqueue list. If no
other higher-priority realtime process is runnable, the process will continue to use the CPU as
long as itwishes, even if other real-time processes having the same priority are runnable
• SCHED_RR - A Round Robin real-time process. When the scheduler assigns the CPU to the
process, it puts the process descriptor at the end of the runqueue list. This policy ensures a
fair assignment of CPU time to all SCHED_RR real-time processes that have the same priority
• SCHED_OTHER - A conventional, time-shared process. The policy field also encodes a
SCHED_YIELD binary flag. This flag is set when the process invokes the sched_ yield( ) system
call (a way of voluntarily relinquishing the processor without the need to start an I/O operation
or go to sleep. Thescheduler puts the process descriptor at the bottom of the runqueue list.

O(1) Algorithm ( Constant time algorithm )


• Choose the task on the highest priority list to execute
• To make this process more efficient, a bitmap is used to define when tasks are on a given
priority list
• On most architectures, a find-first-bit-set instruction is used to find the highest priority bit set in
one of five 32-bit words (for the 140 priorities
• The time it takes to find a task to execute depends not on the number of active tasks but
1171
instead on the number of priorities
• This makes the 2.6 scheduler an O(1) process because the time to schedule is both fixed and
deterministic regardless of the number of active tasks Kernel 2.6 - Major Features
• The 2.6 scheduler was designed and implemented by Ingo Molnar. His motivation in working
on the new scheduler was to create a completely O(1) scheduler for wakeup, context-switch,
and timer interrupt overhead
• One of the issues that triggered the need for a new scheduler was the use of Java virtual
machines (JVMs). The Java programming model uses many threads of execution, which
results in lots of overhead for scheduling in anO(n) scheduler
• Each CPU has a runqueue made up of 140 priority lists that are serviced in FIFO order. Tasks
that are scheduled to execute are added to the end of their respective runqueue's priority list
• Each task has a time slice that determines how much time it's permitted toexecute
• The first 100 priority lists of the runqueue are reserved for real-time tasks, and the last 40 are
used for user tasks (MAX_RT_PRIO=100 and MAX_PRIO=140)
• In addition to the CPU's runqueue, which is called the active runqueue, there's also an expired
runqueue
• When a task on the active runqueue uses all of its time slice, it's moved to the expired
runqueue. During the move, its time slice is recalculated (andso is its priority)
• If no tasks exist on the active runqueue for a given priority, the pointers for the active and
expired runqueues are swapped, thus making the expired priority list the active one

Kernel 2.6 Scheduler Policies:


• SCHED_NORMAL - A conventional, time-shared process (used to be called SCHED_OTHER), for
normal tasks
1. Each task assigned a “Nice” value
2. PRIO = MAX_RT_PRIO + NICE + 20
3. Assigned a time slice
4. Tasks at the same prio(rity) are round-robined
5. Ensures Priority + Fairness

• SCHED_FIFO - A First-In, First-Out real-time process


1172
1. Run until they relinquish the CPU voluntarily
2. Priority levels maintained
3. Not pre-empted !!
• SCHED_RR - A Round Robin real-time process
1. Assigned a timeslice and run till the timeslice is exhausted.
2. Once all RR tasks of a given prio(rity) level exhaust their timeslices, their timeslices are refilled
and they continue running
3. Prio(rity) levels are maintained

• SCHED_BATCH - for "batch" style execution of processes


1. For computing-intensive tasks
2. Timeslices are long and processes are round robin scheduled
3. lowest priority tasks are batch-processed (nice +19)

• SCHED_IDLE - for running very low priority background job


1. nice value has no influence for this policy
2. extremely low priority (lower than +19 nice)

Completely Fair Scheduler (CFS)


• The main idea behind the CFS is to maintain balance (fairness) in providing processor time to
tasks. This means processes should be given a fair amount of the processor. When the time for
tasks is out of balance (meaning that one or more tasks are not given a fair amount of time
relative to others), then those out-of-balance tasks should be given time toexecute.

To determine the balance, the CFS maintains the amount of time provided to a given task in
what's called the virtual runtime. The smaller a task's virtual runtime—meaning the smaller
amount of time a task has been permitted access to the processor—the higher its need for the
processor. The CFS also includes the concept of sleeper fairness to ensure that tasks that are not
currently runnable (for example, waiting for I/O) receive a comparable share of the processor
when they eventually need it.

But rather than maintain the tasks in a run queue, as has been done in prior Linux schedulers, the
CFS maintains a time-ordered red-black tree (see Figure below).
A red-black tree is a tree with a couple of interesting and useful properties. First,it's self-balancing,
which means that no path in the tree will ever be more than twice as long as any other. Second,
operations on the tree occur in O(log n) time (where n is the number of nodes in the tree). This
means that you can insert or delete a task quickly and efficiently.

1173
Concrete view of Linux Kernel Scheduler

Linux scheduler contains:


• A Running Queue : A running queue (rq) is created for each processor (CPU). It is defined in
kernel/sched.c as struct _runqueue. Each rq contains a list of runnable processes on a given
processor. Thestruct_runqueue is defined in sched.c notsched.h to abstract the internal data
structure of thescheduler.
• Schedule Class : schedule class was introduced in 2.6.23. It is an extensible hierarchy of
scheduler modules. These modules encapsulate scheduling policy details and are called from the
scheduler core without the core code assuming too much about them. Scheduling classes are
implemented through thesched_class structure, which contains hooks to functions that must be
called whenever an interesting event occurs. Tasks refer to their schedule policy through struct
task_struct and sched_class. There are two schedule classes implemented in 2.6.32:

1. Completely Fair Schedule class: schedules tasks following Completely Fair Scheduler (CFS)
algorithm. Tasks which have policy set to SCHED_ NORMA L (SCHED_OTHER), SCHED_BATCH,
1174
SCHED_IDLE are scheduled by this schedule class. The implementation of this class is in kernel
/sched_fai r.c
2. RT schedule class: schedules tasks following real-time mechanism definedin POSIX standard.
Tasks which have policy set to SCHED_FIFO, SCHED_RR are scheduled using this schedule class.
The implementation of this class iskernel/sched_rt.c
• Load balancer: In SMP environment, each CPU has its own rq. These queues might be
unbalanced from time to time. A running queue with empty task pushes its associated CPU to idle,
which does not take full advantage of symmetric multiprocessor systems. Load balancer is to
address this issue. It is called every time the system requires scheduling tasks. If running queues
are unbalanced, load balancer will try to pull idletasks from busiest processors to idle processor.

Interactivity
Interactivity is an important goal for the Linux scheduler, especially given the growing effort to
optimize Linux for desktop environments. Interactivity often flies in the face of efficiency, but it is
very important nonetheless. An example of interactivity might be a keystroke or mouse click. Such
events usually require a quick response (i.e. the thread handling them should be allowed to
execute very soon) because users will probably notice and be annoyed if they do not see some
result from their action almost immediately. Users don’t expect a quick response when, for
example, they are compiling programs or rendering high-resolution images. They are unlikely to
notice if something like compiling the Linux kernel takes an extra twenty seconds. Schedulers
used for interactive computing should be designed in such a way that they respond to user
interaction within a certain time period. Ideally, this should be a time period that is imperceptible
to users and thus gives the impression of an immediate response.
Interactivity estimator
• Dynamically scales a tasks priority based on it's interactivity
• Interactive tasks receive a prio bonus
• Hence a larger timeslice
• CPU bound tasks receive a prio penalty
• Interactivity estimated using a running sleep average.
• Interactive tasks are I/O bound. They wait for events to occur.
• Sleeping tasks are I/O bound or interactive !!
• Actual bonus/penalty is determined by comparing the sleep average against a constant
maximum sleep average.
• Does not apply to RT tasks

When a task finishes it's timeslice :


• It's interactivity is estimated
• Interactive tasks can be inserted into the 'Active' array again
• Else, priority is recalculated
• Inserted into the NEW priority level in the 'Expired' array

Re-inserting interactive tasks


• To avoid delays, interactive tasks may be re-inserted into the 'active' array after their timeslice
has expired
• Done only if tasks in the 'expired' array have run recently
• Done to prevent starvation of tasks
• Decision to re-insert depends on the task's priority level

1175
Timeslice distribution:
• Priority is recalculated only after expiring a timeslice
• Interactive tasks may become non-interactive during their LARGEtimeslices, thus starving other
processes
• To prevent this, time-slices are divided into chunks of 20ms
• A task of equal priority may preempt the running task every 20ms
• The preempted task is requeued and is round-robined in it's priority level.
• Also, priority recalculation happens every 20ms

Memory Management
Linux memory management subsystem is responsible, as the name implies, for managing the
memory in the system. This includes implemnetation of virtual memory and demand paging,
memory allocation both for kernel internal structures and user space programms, mapping of files
into processes addressspace and many other cool things.
The memory management in Linux is a complex system that evolved over the years and included
more and more functionality to support a variety of systems from MMU-less microcontrollers to
supercomputers. The memory management for systems without an MMU is called nommu and it
definitely deserves a dedicated document, which hopefully will be eventually written. Yet, although
some of the concepts are the same, here we assume that an MMU is available and a CPU can
translate a virtual address to a physical address.

Linux File System


A Linux file system is a structured collection of files on a disk drive or a partition. A partition is a
segment of memory and contains some specific data. In our machine, there can be various
partitions of the memory. Generally, every partition contains a file system.
The general-purpose computer system needs to store data systematically so that we can easily
access the files in less time. It stores the data on hard disks (HDD) or some equivalent storage
type. There may be below reasons for maintaining thefile system:
• Primarily the computer saves data to the RAM storage; it may lose the data if it gets turned off.
However, there is non-volatile RAM (Flash RAM and SSD) that is available to maintain the data
after the power interruption.
• Data storage is preferred on hard drives as compared to standard RAM as RAM costs more
than disk space. The hard disks costs are dropping gradually comparatively the RAM.

The Linux file system contains the following sections:


• The root directory (/)
• A specific data storage format (EXT3, EXT4, BTRFS, XFS and so on)
• A partition or logical volume having a particular file system.

What is the Linux File System?


Linux file system is generally a built-in layer of a Linux operating system used to handle the data
management of the storage. It helps to arrange the file on the disk storage. It manages the file
name, file size, creation date, and much more information about a file.
If we have an unsupported file format in our file system, we can downloadsoftware to deal with it.

Linux File System Structure


Linux file system has a hierarchal file structure as it contains a root directory and its
1176
subdirectories. All other directories can be accessed from the root directory. Apartition usually has
only one file system, but it may have more than one file system.
A file system is designed in a way so that it can manage and provide space for non-volatile
storage data. All file systems required a namespace that is a naming and organizational
methodology. The namespace defines the naming process, length of the file name, or a subset of
characters that can be used for the file name. It also defines the logical structure of files on a
memory segment, such as the use of directories for organizing the specific files. Once a
namespace is described, a Metadata description must be defined for that particular file.

The data structure needs to support a hierarchical directory structure; this structure is used to
describe the available and used disk space for a particular block. It also has the other details
about the files such as file size, date & time ofcreation, update, and last modified.
Also, it stores advanced information about the section of the disk, such aspartitions and volumes.
The advanced data and the structures that it represents contain the information about the file
system stored on the drive; it is distinct and independent of the filesystem metadata.
Linux file system contains two-part file system software implementationarchitecture. Consider the
below image:

The file system requires an API (Application programming interface) to access thefunction calls to
interact with file system components like files and directories. API facilitates tasks such as
creating, deleting, and copying the files. It facilitates an algorithm that defines the arrangement of
files on a file system.

The first two parts of the given file system together called a Linux virtual file system. It provides a
single set of commands for the kernel and developers to access the file system. This virtual file
system requires the specific system driverto give an interface to the file system.

Linux File System Features


In Linux, the file system creates a tree structure. All the files are arranged as a tree and its
branches. The topmost directory called the root (/) directory. All other directories in Linux can be
accessed from the root directory.
Some key features of Linux file system are as following:
1177
• Specifying paths: Linux does not use the backslash (\) to separate the components; it uses
forward slash (/) as an alternative. For example, as in Windows, the data may be stored in C:\
My Documents\ Work, whereas, inLinux, it would be stored in /home/ My Document/ Work.
• Partition, Directories, and Drives: Linux does not use drive letters to organize the drive as
Windows does. In Linux, we cannot tell whether we are addressing a partition, a network
device, or an "ordinary" directory anda Drive.
• Case Sensitivity: Linux file system is case sensitive. It distinguishes between lowercase and
uppercase file names. Such as, there is a difference [Link] and [Link] in Linux. This
rule is also applied for directories and Linux commands.
• File Extensions: In Linux, a file may have the extension '.txt,' but it is not necessary that a file
should have a file extension. While working with Shell, it creates some problems for the
beginners to differentiate between files and directories. If we use the graphical file manager, it
symbolizes the filesand folders.
• Hidden files: Linux distinguishes between standard files and hidden files, mostly the
configuration files are hidden in Linux OS. Usually, we don't need to access or read the hidden
files. The hidden files in Linux are represented by a dot (.) before the file name (e.g., .ignore).
To access the files, we need to change the view in the file manager or need to use a specific
command in the shell.

Types of Linux File System


When we install the Linux operating system, Linux offers many file systems suchas Ext, Ext2, Ext3,
Ext4, JFS, ReiserFS, XFS, btrfs, and swap.

1. Ext, Ext2, Ext3 and Ext4 file system


The file system Ext stands for Extended File System. It was primarily developed for MINIX OS. The
Ext file system is an older version, and is no longer used due tosome limitations.
Ext2 is the first Linux file system that allows managing two terabytes of data. Ext3 is developed
1178
through Ext2; it is an upgraded version of Ext2 and contains backward compatibility. The major
drawback of Ext3 is that it does not support servers because this file system does not support file
recovery and disk snapshot.
Ext4 file system is the faster file system among all the Ext file systems. It is a very compatible
option for the SSD (solid-state drive) disks, and it is the default file system in Linux distribution.

Linux-Input & outputInput and Output


To the user, the I/O system in Linux looks much like that in any UNIX system. That is, to the extent
possible, all device drivers appear as normal files. A user can open an access channel to a device
in the same way she opens any other file—devices can appear as objects within the file system.
The system administrator can create special files within a file system that contain references to a
specific device driver, and a user opening such a file will be able to read from and write to the
device referenced. By using the normal file-protection system, which determines who can access
which file, the administrator can set access permissions for each device. Linux splits all devices
into three classes: blockdevices, character devices, and network devices.

Figure 21.10 illustrates the overall structure of the device-driver system. Block devices include all
devices that allow random access to completely independent, fixed-sized blocks of data, including
hard disks and floppy disks, CD-ROMs, and flash memory. Block devices are typically used to
store file systems, but direct access to a block device is also allowed so that programs can create
and repair thefile system that the device contains.

Applications can also access these block devices directly if they wish; for example, a database
application may prefer to perform its own, fine-tuned laying out of data onto the disk, rather than
using the general-purpose file system. Character devices include most other devices, such as
mice and keyboards. The fundamental difference between block and character devices is random
access—block devices may be accessed randomly, while character devices are only accessed
serially.

For example, seeking to a certain position in a file might be supported for a DVD but makes no
sense to a pointing device such as a mouse. Network devices are dealt with differently from block
and character devices. Users cannot directly transfer data to network devices; instead, they must
communicate indirectly by opening a connection to the kernel's networking subsystem. We
discuss the interface to network devices separately in Section 21.10.

1179
Block Devices
Block devices provide the main interface to all disk devices in a system. Performance is
particularly important for disks, and the block-device system must provide functionality to ensure
that disk access is as fast as possible. This functionality is achieved through the scheduling of I/O
operations In the context of block devices, a block represents the unit with which the kernel
performs I/O. When a block is read into memory, it is stored in a buffer. The request manager is
the layer of software that manages the reading and writing of buffer contents to and from a block-
device driver. A separate list of requests is kept for each block- device driver. Traditionally, these
requests have been scheduled according to a unidirectional-elevator (C-SCAN) algorithm that
exploits the order in which requests are inserted in and removed from the per-device lists. The
request lists are maintained in sorted order of increasing starting-sector number. When a request
is accepted for processing by a block-device driver, it is not removed from the list. It is removed
only after the I/O is complete, at which point the driver continues with the next request in the list,
even if new requests have been inserted into the list before the active request. As new I/O
requests are made, the request manager attempts to merge requests in the per-device lists. The
scheduling of I/O operations changed somewhat with version 2.6 of the kernel.
The fundamental problem with the elevator algorithm is that I/O operations concentrated in a
specific region of the disk can result in starvation of requeststhat need to occur in other regions of
the disk.

The deadline I/O scheduler used in version 2.6 works similarly to the elevator algorithm except
that it also associates a deadline with each request, thus addressing the starvation issue. By
default, the deadline for read requests is 0.5 second and that for write requests is 5 seconds. The
deadline scheduler maintains a sorted queue of pending I/O operations sorted by sector number.
However, it also maintains two other queues—a read queue for read operations and a write queue
for write operations. These two queues are ordered according to deadline.

Every I/O request is placed in both the sorted queue and either the read or the write queue, as
appropriate. Ordinarily, I/O operations occur from the sorted queue. However, if a deadline expires
for a request in either the read or the write queue, I/O operations are scheduled from the queue
containing the expired request. This policy ensures that an I/O operation will wait no longer than
its expiration time

Character Devices
A character-device driver can be almost any device driver that does not offer random access to
fixed blocks of data. Any character-device drivers registered to the Linux kernel must also register
a set of functions that implement the file I/O operations that the driver can handle. The kernel
performs almost no preprocessing of a file read or write request to a character device; it simply
passesthe request to the device in question and lets the device deal with the request.

The main exception to this rule is the special subset of character-device drivers that implement
terminal devices. The kernel maintains a standard interface to these drivers by means of a set of
tty_struc t structures. Each of these structures provides buffering and flow control on the data
stream from the terminal deviceand feeds those data to a line discipline.
A line discipline is an interpreter for the information from the terminal device. The most common
line discipline is the tt y discipline, which glues the terminal's data stream onto the standard input
and output streams of a user's running processes, allowing those processes to communicate
directly with user's terminal. This job is complicated by the fact that several such processes may
1180
be running simultaneously, and the tt y line discipline is responsible for attaching and detaching
the terminal's input and output from the various processes connected to it as those processes are
suspended or awakened by the user.

Other line disciplines also are implemented that have nothing to do with I/O to auser process. The
PPP and SLIP networking protocols are ways of encoding a networking connection over a terminal
device such as a serial line. These protocols are implemented under Linux as drivers that at one
end appear to the terminal system as line disciplines and at the other end appear to the
networkingsystem as network-device drivers. After one of these line disciplines has been enabled
on a terminal device, any data appearing on that terminal will be routed directly to the appropriate
network-device driver.

Methods in Interprocess Communication


Inter-process communication (IPC) is set of interfaces, which is usually programmed in order for
the programs to communicate between series of processes. This allows running programs
concurrently in an Operating [Link] are the methods in IPC:
1. Pipes (Same Process) –
This allows flow of data in one direction only. Analogous to simplex systems (Keyboard). Data
from the output is usually buffered until input process receives it which must have a common
origin.
2. Names Pipes (Different Processes) –
This is a pipe with a specific name it can be used in processes that don’t have a shared common
process origin. E.g. is FIFO where the details writtento a pipe is first named.
3. Message Queuing –
This allows messages to be passed between processes using either a single queue or several
message queue. This is managed by system kernel these messages are coordinated using an API.
4. Semaphores –
This is used in solving problems associated with synchronization and to avoid race condition.
These are integer values which are greater than orequal to 0.
5. Shared memory –
This allows the interchange of data through a defined area of memory. Semaphore values have to
be obtained before data can get access to shared memory.
6. Sockets –
This method is mostly used to communicate over a network between a client and a server. It
allows for a standard connection which is computerand OS independent.

Network Structure in Linux Operating System

1181
Discussing the network structure in a Linux operating system gets a bit complicated. By itself,
Linux does not address networking; it is, after all, a server operating system intended to run
applications, not networks. OpenStack, however, does provide a networking service that’s meant
to be used with Linux.

OpenStack is a combination of open source software tools for building and managing virtualized
cloud computing services, providing services including compute, storage and identity
management. There’s also a networking component, Neutron, which enables all the other
OpenStack components to communicate with one another. Given that OpenStack was designed to
run on aLinux kernel, it could be said that Neutron is a networking service for Linux – butonly when
used in an OpenStack cloud environment.

Neutron enables network virtualization in an OpenStack environment, providing software-defined


network services through a series of plug-ins. It is intended to enable organizations to spin up
network services on demand, including virtual LANS and virtual private networks (VPNs), as well
as services such as firewalls, intrusion detection and load balancing.

In practice, the networking capabilities of Neutron are somewhat limited, with its main drawback
being a lack of scalability. While companies may use Neutron in alab environment, when it comes
to production they typically look for other options.

A number of companies have developed SDN and network virtualization software that is more
enterprise-ready. Pica8, for example, offers PICOS, an open network operating system built on a
Debian Linux kernel. PICOS is a white box NOS intended to run on white box network switches and
be used in a virtualized, SDN environment. But it provides the scalability required to extend to
hundreds or thousands of white box switches, making it a viable option for enterprise use.

Windows Operating Systems


Windows is a graphical operating system developed by Microsoft. It allows usersto view and store
files, run the software, play games, watch videos, and provides a way to connect to the internet. It
was released for both home computing and professional works.

1182
Windows is a general name for Microsoft Windows. It is developed and marketed by an American
multinational company Microsoft. Microsoft Windows is a collection of several proprietary
graphical operating systems that provide a simple method to store files, run the software, play
games, watch videos, and connect to the Internet.

What is an Operating System?


An operating system or OS is system software. It provides an interface between computer user
and computer hardware. An operating system is used to perform all the basic tasks like file
management, process management, memory management, handling input and output devices,
and controlling peripheral devices such as disk drives and printers.

History of Windows
Windows was first introduced by Microsoft on 20 November 1985. After that, it was gaining
popularity day by day. Now, it is the most dominant desktop operating system around the world,
with a market share of around 82.74%. The macOS Operating system by Apple Inc. is the second
most popular with the shareof 13.23%, and all varieties of Linux operating systems are collectively
in third place with the market share of 1.57%.

Early History
Bill Gates is known as the founder of Windows. Microsoft was founded by Bill Gates and Paul
Allen, the childhood friends on 4 April 1975 in Albuquerque, NewMexico, U.S.
The first project towards the making of Windows was Interface Manager. Microsoft was started
to work on this program in 1981, and in November 1983, it was announced under the name
"Windows," but Windows 1.0 was not released until November 1985. It was the time of Apple's
Macintosh, and that's the reason Windows 1.0 was not capable of competing with Apple's
operating system, but it achieved little popularity. Windows 1.0 was just an extension of MS-DOS
(an already released Microsoft's product), not a complete operating system. The first Microsoft
Windows was a graphical user interface for MS-DOS. But, in the later 1990s, this product was
evolved as a fully complete and modern operating system.

Windows Versions
The versions of Microsoft Windows are categorized as follows:

Early versions of Windows


The first version of Windows was Windows 1.0. It cannot be called a complete operating system
because it was just an extension of MS-DOS, which was already developed by Microsoft. The shell
of Windows 1.0 was a program named MS-DOS Executive. Windows 1.0 had introduced some
components like Clock, Calculator, Calendar, Clipboard viewer, Control Panel, Notepad, Paint,
Terminal, and Write, etc.
In December 1987, Microsoft released its second Windows version as Windows
2.0. It got more popularity than its previous version Windows 2.0. Windows 2.0has some improved
features in user interface and memory management.
The early versions of Windows acted as graphical shells because they ran on top of MS-DOS and
used it for file system services.

Windows 3.x
The third major version of Windows was Windows 3.0. It was released in 1990 and had an
improved design. Two other upgrades were released as Windows 3.1and Windows 3.2 in 1992 and
1183
1994, respectively. Microsoft tasted its first broad commercial success after the release of
Windows 3.x and sold 2 million copies injust the first six months of release.

Windows 9x (Windows 95, Windows 98)


Windows 9x was the next release of Windows. Windows 95 was released on 24 August 1995. It
was also the MS-DOS-based Windows but introduced support for native 32-bit applications. It
provided increased stability over its predecessors, added plug and play hardware, preemptive
multitasking, and also long file namesof up to 255 characters.
It had two major versions Windows 95 and Windows 98

Windows NT (3.1/3.5/3.51/4.0/2000)
Windows NT was developed by a new development team of Microsoft to make it a secure, multi-
user operating system with POSIX compatibility. It was designed with a modular, portable kernel
with preemptive multitasking and support for multiple processor architectures.

Windows XP
Windows XP was the next major version of Windows NT. It was first released on 25 October 2001.
It was introduced to add security and networking features.
It was the first Windows version that was marketed in two main editions: the "Home" edition and
the "Professional" edition.
The "Home" edition was targeted towards consumers for personal computer use, while the
"Professional" edition was targeted towards business environments and power users. It included
the "Media Center" edition later, which was designed for home theater PCs and provided support
for DVD playback, TV tuner cards, DVR functionality, and remote controls, etc.
Windows XP was one of the most successful versions of Windows.

Windows Vista
After Windows XP's immense success, Windows Vista was released on 30 November 2006 for
volume licensing and 30 January 2007 for consumers. It had included a lot of new features such
as a redesigned shell and user interface to significant technical changes. It extended some
security features also.

Windows 7
Windows 7 and its Server edition Windows Server 2008 R2 were released as RTMon 22 July 2009.
Three months later, Windows 7 was released to the public.
Windows 7 had introduced a large number of new features, such as a redesigned Windows shell

1184
with an updated taskbar, multi-touch support, a home networking system called HomeGroup, and
many performance improvements.
Windows 7 was supposed to be the most popular version of Windows to date.

Windows 8 and 8.1


Windows 8 was released as the successor to Windows 7. It was released on 26 October, 2012. It
had introduced a number of significant changes such as the introduction of a user interface based
around Microsoft's Metro design language with optimizations for touch-based devices such as
tablets and all-in-one PCs. It was more convenient for touch-screen devices and laptops.

Microsoft released its newer version Windows 8.1 on 17 October 2013 and includes features such
as new live tile sizes, deeper OneDrive integration, andmany other revisions.
Windows 8 and Windows 8.1 were criticized for the removal of the Start menu.

Windows 10
Microsoft announced Windows 10 as the successor to Windows 8.1 on 30 September 2014.
Windows 10 was released on 29 July 2015. Windows 10 is the part of the Windows NT family of
operating systems.
Microsoft has not announced any newer version of Windows after Windows 10.

Design Principles
Microsoft's design goals for Windows XP include security, reliability, Windows and POSIX
application compatibility, high performance, extensibility, portability, and international support.

Security
Windows XP security goals required more than just adherence to the design standards that
enabled Windows NT 4.0 to receive a C-2 security classification from the U.S. government (which
signifies a moderate level of protection fromdefective software and malicious attacks).
Extensive code review and testing were combined with sophisticated automatic analysis tools to
identify and investigate potential defects that might represent security vulnerabilities.

Reliability
Windows 2000 was the most reliable, stable operating system Microsoft had ever shipped to that
point. Much of this reliability came from maturity in the source code, extensive stress testing of
the system, and automatic detection of many serious errors in drivers.

The reliability requirements for Windows XP were even more stringent. Microsoft used extensive
manual and automatic code review to identify over 63,000 lines in the source files that might
contain issues not detected by testing and then set about reviewing each area to verify that the
code was indeed correct.

Windows XP extends driver verification to catch more subtle bugs, improves the facilities for
catching programming errors in user-level code, and subjects third- party applications, drivers, and
devices to a rigorous certification process.

Furthermore, Windows XP adds new facilities for monitoring the health of the PC, including
downloading fixes for problems before they are encountered by users. The perceived reliability of
Windows XP was also improved by making the graphical user interface easier to use through
1185
better visual design, simpler menus,and measured improvements in the ease with which users can
discover how to perform common tasks.

Windows and POSIX Application Compatibility


Windows XP is not only an update of Windows 2000; it is a replacement for Windows 95/98.
Windows 2000 focused primarily on compatibility for business applications. The requirements for
Windows XP include a much higher compatibility with consumer applications that run on Windows
95/98. Application compatibility is difficult to achieve because each application checks for a
particular version of Windows, may have some dependence on the quirks of the implementation
of APIs, may have latent application bugs that were masked in the previous system, and so forth.
Windows XP introduces a compatibility layer that falls between applications and the Win32 APIs.
This layer makes Windows XP look (almost) bug-for-bug compatible with previous versions of
Windows. Windows XP, like earlier NT releases, maintains support for running many 16-bit
applications using a thunking, or conversion, layer that translates 16-bit API calls into equivalent
32-bit calls.

Similarly, the 64-bit version of Windows XP provides a thunking layer thattranslates 32-bit API calls
into native 64-bit calls.

POSIX support in Windows XP is much improved. A new POSIX subsystem called Interix is now
available. Most available UNIX-compatible software compiles and runs under Interix without
modification.

High Performance
Windows XP is designed to provide high performance on desktop systems (which are largely
constrained by I/O performance), server systems (where the CPU is often the bottleneck), and
large multithreaded and multiprocessor environments (where locking and cache-line management
are key to scalability). High performance has been an increasingly important goal for Windows XP.
Windows 2000 with SQL 2000 on Compaq hardware achieved top TPC-C numbers at the time it
shipped.

To satisfy performance requirements, NT uses a variety of techniques, such as asynchronous I/O,


optimized protocols for networks (for example, optimistic locking of distributed data, batching of
requests), kernel-based graphics, and sophisticated caching of file-system data. The memory-
management and synchronization algorithms are designed with an awareness of the performance
considerations related to cache lines and multiprocessors.

Windows XP has further improved performance by reducing the code-path length in critical
functions, using better algorithms and per-processor data structures, using memory coloring for
NUMA (non-uniform memory access) machines, and implementing more scalable locking
protocols, such as queued spinlocks. The new locking protocols help reduce system bus cycles
and include lock-free lists and queues, use of atomic read-modify-write operations (like
interlocked increment), and other advanced locking techniques.
The subsystems that constitute Windows XP communicate with one another efficiently by a local
procedure call (LPC) facility that provides highperformance message passing. Except while
executing in the kernel dispatcher, threads in thesubsystems of Windows XP can be preempted by
higher-priority threads. Thus, the system responds quickly to external events. In addition, Windows
XP is designed for symmetrical multiprocessing; on a multiprocessor computer, several threads
1186
can run at the same time.

Extensibility
Extensibility refers to the capacity of an operating system to keep up with advances in computing
technology. So that changes over time are facilitated, the developers implemented Windows XP
using a layered architecture. The Windows XP executive runs in kernel or protected mode and
provides the basic system services. On top of the executive, several server subsystems operate in
user mode. Among them are environmental subsystems that emulate different operating
systems. Thus, programs written for MS-DOS, Microsoft Windows, and POSIX all run on Windows
XP in the appropriate environment. Because of the modular structure, additional environmental
subsystems can be added without affecting the executive.
In addition, Windows XP uses loadable drivers in the I/O system, so new file systems, new kinds
of I/O devices, and new kinds of networking can be added while the system is running. Windows
XP uses a client-server model like the Machoperating system and supports distributed processing
by remote procedure calls (RPCs) as defined by the Open Software Foundation.

Portability
An operating system is portable if it can be moved from one hardware architecture to another with
relatively few changes. Windows XP is designed to be portable. As is true of the UNIX operating
system, the majority of the system is written in C and C++. Most processor-dependent code is
isolated in a dynamic linklibrary (DLL) called the hardware-abstraction layer (HAL).
A DLL is a file that is mapped into a process's address space such that any functions in the DLL
appear to be part of the process. The upper layers of the Windows XP kernel depend on the HAL
interfaces rather than on the underlying hardware, bolstering Windows XP portability. The HAL
manipulates hardware directly, isolating the rest of Windows XP from hardware differences among
theplatforms on which it runs.

Although for market reasons Windows 2000 shipped only on Intel IA32- compatible platforms, it
was also tested on IA32 and DEC Alpha platforms until just prior to release to ensure portability.
Windows XP runs on IA32-compatible and IA64 processors. Microsoft recognizes the importance
of multiplatform development and testing, since, as a practical matter, maintaining portability is a
matter of use it or lose it.

International Support
Windows XP is also designed for international and multinational use. It provides support for
different locales via the national-language-support (NLS) API. The NLS API provides specialized
routines to format dates, time, and money in accordancewith various national customs.
String comparisons are specialized to account for varying character sets. UNICODE is Windows
XP's native character code. Windows XP supports ANSI characters by converting them to
UNICODE characters before manipulating them (8-bit to 16-bitconversion). System text strings are
kept in resource files that can be replaced to localize the system for different languages. Multiple
locales can be used concurrently, which is important to multilingual individuals and businesses.

Main Components of Windows


The main components of the Windows Operating System are the following:
• Configuration and maintenance
• User interface
• Applications and utilities
1187
• Windows Server components
• File systems
• Core components
• Services
• DirectX
• Networking
• Scripting and command-line
• Kernel
• NET Framework
• Security
• Deprecated components and apps
• APIs

Fast User Switching


Fast user switching is a feature Microsoft implemented within Windows XP Home Edition and
Windows XP Professional that allows users to switch between users without having to log out of
their user accounts. It allows applications to remain open and in the same state, despite someone
new logging in. This allows the previous user to get back to his or her tasks more quickly.

Explained Fast User Switching


Windows allows multiple users to have their own profile set-ups associated with their account.
These profiles are usually password protected, and their settings, files and other information are
set up to meet each individual user's needs.

Setting up different profiles allows multiple users to share one computer. However, there is often
a delay when logging in and out of different [Link] is where fast user switching comes in.

Fast users switching allows multiple users to be logged in simultaneously and switch between
their open accounts while other applications are running andnetwork connections are preserved.

Terminal Services
Terminal Services is a component in Microsoft Windows that allows a user to access applications
and data on a remote computer over a network. Terminal Services is a thin-client terminal server
sort of computing environment developedby Microsoft.

Terminal Services allows Windows applications or even the entire desktop of a computer running
terminal services to be accessible from a remote client computer.
Widely used these days with Microsoft Windows Server 2003, Terminal Services provides the
ability to host multiple, simultaneous client sessions.

What is Terminal Services good for?


Terminal Services lets administrators install, configure, manage, and maintain applications
centrally on a few servers.

Time is money...

This goes in hand with IT budgets and staffing. Managing software in a central location is usually
1188
much faster, easier, and cheaper than deploying applications to end-users' desktops. Centrally-
deployed applications are also easier to maintain, especially as related to patching and upgrading.
Running applications from one central location also can be beneficial for the configuration of
desktops. Since a terminal server hosts all the application logic which also runs on the server, the
processing and storage requirements for clientmachines are minimal.

Terminal Services history


Terminal Services was first introduced in Windows NT 4.0 Terminal Server Edition. Unfortunately,
this early implementation of Terminal Services in Windows NT did not gain too much popularity.
Terminal Services has been significantly improved in Windows 2000 and even more in Windows
Server 2003.

Both the underlying protocol as well as the service was again fundamentally overhauled for
Windows Vista and Windows Server 2008.

Are there any limitations on the network connection?


In general, there are no explicit limitations for network connectivity related to terminal services. It
can be used over a Local Area Network (LAN) as well as over aWide Area Network (WAN).

Terminal Services in Windows XP


Windows includes the following two client applications which utilize TerminalServices:
• Remote Assistance
• Remote Desktop

The Remote Assistance component is available in all versions of Windows. Remote Assistance
allows one user to assist another user.
The Remote Desktop application is available in Windows XP Professional, Media Center Edition,
Windows Vista Business, Enterprise, and Ultimate. Remote Desktop allows a user to log into a
remote system and access the desktop, applications, and data. Remote Desktop can also be used
to control the system remotely.

Terminal Services on client versions of Windows versus server Windows


In the client versions of Windows, that is for example Windows XP, Terminal Services supports
only one logged in user at a time. On the other hand, concurrent remote sessions are allowed in a
server Windows operating system,for example the Microsoft Windows Server 2003.

What are the disadvantages of Terminal Services?


As one may expect, running an application from a central location also has somedisadvantages.
• The terminal server needs to be powerful enough to be able to handle allconnections.
• The network needs to be sized appropriately so that it is not the bottleneck when terminal
server sessions are established.
• The terminal server is the major source of risk of downtime. If the terminal server fails, the
whole system fails unless a fail-over terminal server is in place.
• The functionality of the system as a whole is also affected by the network reliability. If the
network is down, the whole system is down as well.
• Running applications from a terminal server can also be an issue from performance

1189
perspective. In some cases, no matter how good the network is, the performance
associated with running an application locally on a desktop workstation can still
overshadow the benefits of a terminal serverenvironment.
Another disadvantage can be the availability of skilled administrator. Support for a terminal server
needs to have the necessary knowledge and be available asthe business needs commands.

What Microsoft Terminal Services has to offer?


Terminal Services is a built-in component in Windows Server 2003. Terminal Services provides
especially the following functionality:

Terminal Services and Group Policy


Terminal Services can be configured and managed through Group Policy settings. This is a new
feature in Windows Server 2003 which allows administrators to take advantage of the flexibility
and power of the Group Policy component to simplify the configuration and management of
Windows Terminal servers. User accounts can be assigned permissions based on group policies.

Remote Administration Built in...


The remote administration mode is already built into the operating system and no longer requires
installation of additional components. Allowing users to remotely connect to a server requires just
a simple step of selecting a checkbox onthe Remote tab of the System tool in Control Panel.

Remote Desktop Protocol (RDP)...


The Remote Desktop Protocol (RDP) has been very much enhanced in Windows Server 2003. The
display and device redirection as well as the security have beenenhanced. Terminal Services does
not need a VPN tunnel anymore when connecting to it over a public network.

Session Directory component...


The terminal server can be configured with so called Session Directory component. This add-in
allows to scale Terminal Services upwards. This is used by large enterprises that need a load-
balanced terminal server network.

Windows File System

1190
What is file system?
In computing, file system controls how data is stored and retrieved. In other words, it is the
method and data structure that an operating system uses to keep track of files on a disk or
partition.
It separates the data we put in computer into pieces and gives each piece a name, so the data is
easily isolated and identified.
Without file system, information saved in a storage media would be one large body of data with no
way to tell where the information begins and ends.

Types of Windows File System


There are five types of Windows file system, such as FAT12, FAT16, FAT32, NTFSand exFAT. Most
of us like to choose the latter three, and I would like to introduce them respectively for you.

FAT32 in Windows
In order to overcome the limited volume size of FAT16 (its supported maximum volume size is
2GB) Microsoft designed a new version of the file system FAT32, which then becomes the most
frequently used version of the FAT (File AllocationTable) file system.

NTFS in Windows
NTFS is the newer drive format. Its full name is New Technology File System. Starting with
Windows NT 3.1, it is the default file system of the Windows NT family.
Microsoft has released five versions of NTFS, namely v1.0, v1.1, v1.2, v3.0, andv3.1.
exFAT in Windows
exFAT (Extended File Allocation Table) was designed by Microsoft back in 2006 and was a part of
1191
the company's Windows CE 6.0 operating system.

This file system was created to be used on flash drives like USB memory sticks and SD cards,
which gives a hint for its precursors: FAT32 and FAT16.

Comparisons among the Three Types of Windows File System


Everything comes in advantages and shortcomings. Comparisons among the three types of
Windows File System will be showed in following content to help you make a choice about
selecting one type of file system.

Compatibility
The three types can work in all versions of Windows.
For FAT32, it also works in game consoles and particularly anything with a USB port; for exFAT, it
requires additional software on Linux; for NTFS, it is read only by default with Mac, and may be
read only by default with some Linux distributions.
With respect to the ideal use, FAT32 is used on removable drives like USB and Storage Card;
exFAT is used for USB flash drives and other external drivers, especially if you need files of more
than 4 GB in size; NTFS can be used for servers.

Security
The files belonging to FAT32 and NTFS can be encrypted, but the flies belong to the latter can be
compressed.
The encryption and compression in Windows are very useful. If other users do not use your user
name to login Windows system, they will fail to open the encrypted and compressed files that
created with your user name.
In other word, after some files are encrypted, such files only can be opened when people use our
account to login Windows system.

Distributed Systems
A distributed system contains multiple nodes that are physically separate but linked together
using the network. All the nodes in this system communicate with each other and handle
processes in tandem. Each of these nodes contains a small part of the distributed operating
system software.
A diagram to better explain the distributed system is –

Types of Distributed Systems


1192
The nodes in the distributed systems can be arranged in the form of client/server systems or peer
to peer systems. Details about these are as follows –

Client/Server Systems
In client server systems, the client requests a resource and the server provides that resource. A
server may serve multiple clients at the same time while a client is in contact with only one server.
Both the client and server usually communicate via a computer network and so they are a part of
distributed systems.

Peer to Peer Systems


The peer to peer systems contains nodes that are equal participants in data sharing. All the tasks
are equally divided between all the nodes. The nodes interact with each other as required as share
resources. This is done with the helpof a network.

Advantages of Distributed Systems


Some advantages of Distributed Systems are as follows −
• All the nodes in the distributed system are connected to each other. So nodes can easily share
data with other nodes.
• More nodes can easily be added to the distributed system i.e. it can bescaled as required.
• Failure of one node does not lead to the failure of the entire distributed system. Other nodes
can still communicate with each other.
• Resources like printers can be shared with multiple nodes rather than being restricted to just
one.

Disadvantages of Distributed Systems


Some disadvantages of Distributed Systems are as follows −
• It is difficult to provide adequate security in distributed systems because the nodes as well as
the connections need to be secured.
• Some messages and data can be lost in the network while moving from onenode to another.
• The database connected to the distributed systems is quite complicated and difficult to handle
as compared to a single user system.
• Overloading may occur in the network if all the nodes of the distributed system try to send data
at once.

NETWORK BASED OPERATING SYSTEM


Unlike operating systems, such as Windows, that are designed for single users to control one
computer, network operating systems (NOS) coordinate the activities of multiple computers
across a network. The network operating system acts as a director to keep the network running
smoothly

Network Based Operating System


The term network operating system is used to refer to two rather differentconcepts:
1. A specialized operating system for a network device such as a router , switch orfirewall
2. An operating system oriented to computer networking, to allow shared file and printer access
among multiple computers in a network, to enable the sharing of data, users, groups, security,
applications, and other networking functions, typically over a local area network (LAN), or private
1193
network. This sense is now largely historical, as common operating systems generally now have
such features included Network operating systems can be embedded in a router or hardware
firewallthat operates the functions in the network layer(layer 3)

NETWORK DEVICE OPERATING SYSTEM


Examples:
• pfSense, a fork of M0n0wall uses Pf
• IPOS, used in routers from Ericsson
• FortiOS, used in Fortigates from Fortinet
• TiMOS used in routers from Alcatel-Lucent
• Versatile Routing Platform (VRP), used in routers from Huawei
• RouterOS, software which turns a PC or MikroTik hardware into a dedicatedrouter
• Extensible Operating System used in switches from Arista
• ExtremeXOS(EXOS), used in network devices made by Extreme Networks

There are two types of network operating systemHistorical Network Operating System
We can think a client as a computer in your network, where a network user is performing some
network activity. For Example: Downloading a file from a File Server, Browsing Intranet/Internet
etc. The network user normally uses a clientcomputer to perform his day to day work

CLIENT SERVER (NOS)


The client–server model is a distributed application structure that partitions tasks or workloads
between the providers of a resource or service, called servers, and service requesters, called
clients. Often clients and servers communicate over a computer network on separate hardware,
but both client and server may reside in the same system. A server host runs one or more server
programs which share their resources with clients. A client does not share any of its resources,
but requests a server's content or service function. Clients therefore initiate communication
sessions with servers which await incoming requests. Examples ofcomputer applications that use
the client–server model are Email, network printing, and the World Wide Web

Advantages
• Centralized servers are more stable.
• Security is provided through the server.
• New technology and hardware can be easily integrated into the system.
• Hardware and the operating system can be specialized, with a focus onperformance.
• Servers are able to be accessed remotely from different locations and typesof systems.
• Buying and running a server raises costs.
• Dependence on a central location for operation.
• Requires regular maintenance and updates.

Disadvantages
We can think a client as a computer in your network, where a network user is performing some
network activity. For Example: Downloading a file from a File Server, Browsing Intranet/Internet
etc. The network user normally uses a clientcomputer to perform his day to day work

Peer to Peer (Nos)


In a peer-to-peer network operating system users are allowed to share resources and files located
on their computers and access shared resources from others.
1194
This system is not based with having a file server or centralized management source. A peer-to-
peer network sets all connected computers equal; they all share the same abilities to use
resources available on the network.
• Ease of setup
• Less hardware needed, no server need be acquired
Advantages
• No central location for storage
• Less security than the client–server model

Disadvantages
Why build a distributed system?
• Microprocessors are getting more and more powerful.
• A distributed system combines (and increases) the computing power ofindividual computer.
• Some advantages include:
• Resource sharing
(but not as easily as if on the same machine)
• Enhanced performance
(but 2 machines are not as good as a single machine that is 2 times asfast)
• Improved reliability & availability
(but probability of single failure increases, as does difficulty ofrecovery)
• Modular expandability
• Distributed OS's have not been economically successful!!!

System models:
• the minicomputer model (several minicomputers with each computersupporting multiple users
and providing access to remote resources).
• the workstation model (each user has a workstation, the system provides some common
services, such as a distributed file system).
• the processor pool model (the model allocates processor to a user according to the user's
needs).

Where is the knowledge of distributed operating systems likely to be useful?


• custom OS's for high performance computer systems
• OS subsystems, like NFS, NIS
• distributed ``middleware'' for large computations
• distributed applications

Lack of Global Knowledge


• Communication delays are at the core of the problem
• Information may become false before it can be acted upon
• these create some fundamental problems:
• no global clock -- scheduling based on fifo queue?
• no global state -- what is the state of a task? What is a correctprogram?

Naming
• named objects: computers, users, files, printers, services
• namespace must be large

1195
• unique (or at least unambiguous) names are needed

• logical to physical mapping needed


• mapping must be changeable, expandable, reliable, fast

Scalability
• How large is the system designed for?
• How does increasing number of hosts affect overhead?
• broadcasting primitives, directories stored at every computer -- these design options will not
work for large systems.

Compatibility
• Binary level: same architecture (object code)
• Execution level: same source code can be compiled and executed (sourcecode).
• Protocol level: only requires all system components to support a commonset of protocols.

Process synchronization
• test-and-set instruction won't work.
• Need all new synchronization mechanisms for distributed systems.

Distributed Resource Management


• Data migration: data are brought to the location that needs them.
• distributed filesystem (file migration)
• distributed shared memory (page migration)
• Computation migration: the computation migrates to another location.
• remote procedure call: computation is done at the remote machine.
• processes migration: processes are transferred to other processors.

Security
• Authetication: guaranteeing that an entity is what it claims to be.
• Authorization: deciding what privileges an entity has and making only thoseprivileges available.

Structuring
• the monolithic kernel: one piece
• the collective kernel structure: a collection of processes
• object oriented: the services provided by the OS are implemented as a setof objects.
• client-server: servers provide the services and clients use the services.

Communication Networks
• WAN and LAN
• traditional operating systems implement the TCP/IP protocol stack: host to network layer, IP
layer, transport layer, application layer.
• Most distributed operating systems are not concerned with the lower layer communication
primitives.
Communication Models
• message passing
• remote procedure call (RPC)

1196
Message Passing Primitives
• Send (message, destination), Receive (source, buffer)
• buffered vs. unbuffered
• blocking vs. nonblocking
• reliable vs. unreliable
• synchronous vs. asynchronous

Example: Unix socket I/O primitives

#include <sys/socket.h>

ssize_t sendto(int socket, const void *message,

size_t length, int flags,

const struct sockaddr *dest_addr, size_t dest_len);

ssize_t recvfrom(int socket, void *buffer,

size_t length, int flags, struct sockaddr *address,

size_t *address_len);

int poll(struct pollfd fds[], nfds_t nfds,


int timeout);

int select(int nfds, fd_set *readfds, fd_set *writefds,

fd_set *errorfds, struct timeval *timeout);

RPC
With message passing, the application programmer must worry about manydetails:
• parsing messages
• pairing responses with request messages
• converting between data representations
• knowing the address of the remote machine/server
• handling communication and system failures

RPC is introduced to help hide and automate these details. RPC is based on a ``virtual'' procedure
call model
• client calls server, specifying operation and arguments
• server executes operation, returning results

1197
RPC Issues
• Stubs (See Unix rpcgen tool, for example.)
• are automatically generated, e.g. by compiler
• do the ``dirty work'' of communication
• Binding method
• server address may be looked up by service-name
• or port number may be looked up
• Parameter and result passing
• Error handling semantics

RPC Diagram

Communication Protocols
When we are designing a communication network, we must deal with the inherent complexity of
coordinating asynchronous operations communicating in a potentially slow and error-prone
environment. In addition, the systems on the network must agree on a protocol or a set of
protocols for determining host names, locating hosts on the network, establishing connections,
and so on.

We can simplify the design problem (and related implementation) by partitioning the problem into
multiple layers. Each layer on one system communicates with the equivalent layer on other
systems. Typically, each layer has its own protocols, and communication takes place between

1198
peer layers using a specific protocol. Theprotocols may be implemented in hardware or software.
For instance, Figure 16.6 shows the logical communications between two computers, with the
three lowest-level layers implemented in hardware. Following the International Standards
Organization (ISO), we refer to the layers asfollows:

1. Physical layer. The physical layer is responsible for handling both the mechanical and the
electrical details of the physical transmission of a bit stream. At the physical layer, the
communicating systems must agree on the electrical representation of a binary 0 and 1, so that
when data are

1199
2. Figure 16.7 summarizes the ISO protocol stack—a set of cooperating protocols— showing the
physical flow of data. As mentioned, logically each layer of a protocol stack communicates with
the equivalent layer on other systems. But physically, a message starts at or above the application
layer and is passed through each lower level in turn. Each layer may modify the message and
include message-header data for the equivalent layer on the receiving side. Ultimately, the
message reaches the data-network layer and is transferred as one or more packets (Figure 16.8).
The data-link layer of the target system receives these data, and the message ismoved up through
the protocol stack; it is analyzed, modified, and stripped of headers as it progresses. It finally
reaches the application layer for use by the receiving process.

1200
1201
The ISO model formalizes some of the earlier work done in network protocols butwas developed in
the late 1970s and is currently not in widespread use. Perhaps the most widely adopted protocol
stack is the TCP/IP model, which has been adopted by virtually all Internet sites. The TCP/IP
protocol stack has fewer layers than does the ISO model. Theoretically, because it combines
several functions in each layer, it is more difficult to implement but more efficient than ISO
networking. The relationship between the ISO and TCP/IP models is shown in Figure 16.9.
The TCP/IP application layer identifies several protocols in widespread use in the Internet,
including HTTP, FTP, Telnet, DNS, and SMTP. The transport layer identifies the unreliable,
connectionless user datagram protocol (UDP) and the reliable, connection-oriented transmission
control protocol (TCP). The Internet protocol (IP) is responsible for routing IP datagrams through
the Internet. The TCP/IP model does not formally identify a link or physical layer, allowing TCP/IP
traffic to run across any physical network. In Section 16.9, we consider the TCP/IP model running
over an Ethernet network.

Design Issues of Distributed System


The distributed information system is defined as “a number of interdependent computers linked
by a network for sharing information among them”. A distributed information system consists of
multiple autonomous computers that communicate or exchange information through a computer
network.

Design issues of distributed system –


1. Heterogeneity : Heterogeneity is applied to the network, computer hardware, operating system
and implementation of different developers. Akey component of the heterogeneous distributed
system client-server environment is middleware. Middleware is a set of service that enables
application and end-user to interacts with each other across a heterogeneous distributed
system.
2. Openness: The openness of the distributed system is determined primarily by the degree to
1202
which new resource sharing services can be made available to the users. Open systems are
characterized by the fact that their key interfaces are published. It is based on a uniform
communication mechanism and published interface for access to shared resources. It can be
constructed from heterogeneous hardware and software.
3. Scalability: Scalability of the system should remain efficient even with a significant increase in
the number of users and resources connected.
4. Security : Security of information system has three components Confidentially, integrity and
availability. Encryption protects shared resources, keeps sensitive information secrets when
transmitted.
5. Failure Handling : When some faults occur in hardware and the software program, it may
produce incorrect results or they may stop before they have completed the intended
computation so corrective measures shouldto implemented to handle this case.
Failure handling is difficult in distributed systems because the failure is partial i, e, some
components fail while others continue to function.
6. Concurrency: There is a possibility that several clients will attempt to accessa shared resource
at the same time. Multiple users make requests on the same resources, i.e read, write, and
update. Each resource must be safe in a concurrent environment. Any object that represents a
shared resource a distributed system must ensure that it operates correctly in a concurrent
environment.
7. Transparency : Transparency ensures that the distributes system should be perceived as the
single entity by the users or the application programmers rather than the collection of
autonomous systems, which is cooperating. The user should be unaware of where the
services are located and the transferring from a local machine to a remote one should be
transparent.

Distributed File System (DFS)


A distributed file system (DFS) is a file system with data stored on a server. The data is accessed
and processed as if it was stored on the local client machine. The DFS makes it convenient to
share information and files among users on a network in a controlled and authorized way. The
server allows the client users to share files and store data just like they are storing the information
locally. However, theservers have full control over the data and give access control to the clients.
Distributed file system (DFS) is a method of storing and accessing files based in a client/server
architecture. In a distributed file system, one or more central servers store files that can be
accessed, with proper authorization rights, by anynumber of remote clients in the network.
Much like an operating system organizes files in a hierarchical file management system, the
distributed system uses a uniform naming convention and a mapping scheme to keep track of
where files are located. When the client device retrievesa file from the server, the file appears as a
normal file on the client machine, andthe user is able to work with the file in the same ways as if it
were stored locally on the workstation. When the user finishes working with the file, it is returned
over the network to the server, which stores the now-altered file for retrieval at a later time.
Distributed file systems can be advantageous because they make it easier to distribute
documents to multiple clients and they provide a centralized storage system so that client
machines are not using their resources to store files.

Explained Distributed File System (DFS)


There has been exceptional growth in network-based computing recently and client/server-based
applications have brought revolutions in this area. Sharing storage resources and information on
1203
the network is one of the key elements in both local area networks (LANs) and wide area networks
(WANs). Different technologies have been developed to bring convenience to sharing resources
andfiles on a network; a distributed file system is one of the processes used regularly.

One process involved in implementing the DFS is giving access control and storage management
controls to the client system in a centralized way, managed by the servers. Transparency is one of
the core processes in DFS, so files are accessed, stored, and managed on the local client
machines while the process itself is actually held on the servers. This transparency brings
convenience to the end user on a client machine because the network file system efficiently
manages all the processes. Generally, a DFS is used in a LAN, but it can be used in a WAN or over
the Internet.

A DFS allows efficient and well-managed data and storage sharing options on a network
compared to other options. Another option for users in network-based computing is a shared disk
file system. A shared disk file system puts the access control on the client’s systems so the data
is inaccessible when the client systemgoes offline. DFS is fault-tolerant and the data is accessible
even if some of the network nodes are offline.

A DFS makes it possible to restrict access to the file system depending on access lists or
capabilities on both the servers and the clients, depending on how theprotocol is designed.

1204
MCQs
1. The physical devices of a computer :
a) Software
b) Package
c) Hardware
d) System Software
Answer: c
Explanation: Hardware refers to the physical devices of a computer system. Software refers to a
collection of programs.A program is a sequence of instructions.

2. Software Package is a group of programs that solve multiple problems.


a) True
b) False
Answer: b
Explanation: The statement is false. The software package is a group of programs that solve a
specific problem or perform a specific type of job.

3. refer to renewing or changing components like increasing the main memory, or hard disk
capacities, or adding speakers, or modems, etc.
a) Grades
b) Prosody
c) Synthesis
d) Upgrades
Answer: d
Explanation: Upgrades is the right term to be used. Upgrades are installed to renew or implement a
new feature. Except for upgrades, hardware is normally one-time expense.

4. The memory unit is made up of bytes.


a) 256
b) 124
c) 4096
d) 3096
Answer: c
Explanation: The memory unit is made up of 4,096 bytes. Memory unit is responsible for the
storage of data. It is an important entity in the computer system.

5. Which of the following is not an example of system software?


a) Language Translator
b) Utility Software
c) Communication Software
d) Word Processors
Answer: d
Explanation: A system software is responsible for controlling the operations of a computer system.
Word Processor is an application software since it is specific to its purpose.

6. A person who designs the programs in asoftware package is called :

1205
a) User
b) Software Manager
c) System Developer
d) System Programmer
Answer: d
Explanation: The programs included in a system software package are called system programs.
The programmers who design them and prepare them are called system programmers.

7. is designed to solve a specific problem or to do a specific


task.
a) Application Software
b) System Software
c) Utility Software
d) User
Answer: a
Explanation: An application software is specific to solving a specific problem. System software is
designed for controlling the operations of a computer system.

8. Assembler is used as a translator for?


a) Low level language
b) High Level Language
c) COBOL
d) C
Answer: a
Explanation: Assembler is used in case of low level languages. It is generally used to make the
binary code into an understandable format. Interpreter is used with the high level languages
similarly.

9. What do you call a program in execution?


a) Command
b) Process
c) Task
d) Instruction
Answer: b
Explanation: Option Process is correct. A program is a set of instructions. A program in execution
is called a process.

10. Which of the following is not a process state?


a) Terminated
b) Running
c) Blocked
d) Execution
Answer: c
Explanation: There is no blocked state in a process model. The different states are ready, running,
executing, waiting and terminated.

11. The language made up of binary coded instructions.


a) Machine
1206
b) C
c) BASIC
d) High level
Answer: a
Explanation: The language made up of binary coded instructions built into the hardware of a
particular computer and used directly by the computer is machine language.

12. Binary code comprises of digits from 0 to 9.


a) True
b) False
Answer: b
Explanation: The statement is false. Binary as the word suggests contains only 2 digits :0 and 1.
0 denotes false and 1 denotes a truth value.

13. The contains the address of the next instruction to be executed.


a) IR
b) PC
c) Accumulator
d) System counter
Answer: b
Explanation: PC stands for program counter (It contains the address of the next instruction to be
executed).

14. A document that specifies how many times and with what data the program must be run in
order to thoroughly test it.
a) addressing plan
b) test plan
c) validation plan
d) verification plan
Answer: b
Explanation: Test plan is the A document that specifies how many times and with what data the
program must be run in order to thoroughly test it. It comes under testing.

15. Each personal computer has a


that manages the computer’s arithmetical, logical and control activities.
a) Microprocessor
b) Assembler
c) Microcontroller
d) Interpreter
Answer: a
Explanation: Microprocessor handles all these activities. Each family of processors has its own
set of instructions for handling various operations like getting input from keyboard, displaying
information on a screen and performing various other jobs.

16. Assembly Language requires less memory and execution time.


a) True
b) False
Answer: a
1207
Explanation: The statement is true. Advantages of using assembly language are:
• It requires less memory and execution time.
• It allows hardware-specific complex jobs in an easier way.
• It is suitable for time-critical jobs.

17. The data size of a word is


a) 2-byte
b) 4-byte
c) 8-byte d)16-byte
Answer: a
Explanation: The processor supports thefollowing data sizes:
• Word: a 2-byte data item
• Double word: a 4-byte (32 bit) data item, etc.

18. A direct reference of specific location.


a) Segment Address
b) Absolute Address
c) Offset
d) Memory Address
Answer: b
Explanation: There are two kinds of memory addresses:
• An absolute address – a direct reference of specific location.
• The segment address (or offset) – starting address of a memory segment with the offset
value.

19. A Borland Turbo Assembler.


a) nasm
b) tasm
c) gas
d) asm
Answer: b
Explanation: Tasm is the borland turbo assembler. Nasm is used with linux generally. Gas is the
GNU assembler.

20. Prolog comes under


a) Logic Programming
b) Procedural Programming
c) OOP
d) Functional
Answer: a
Explanation: Prolog stands for Programming in Logic. The options mentioned are the four
categories of programming. Prolog is a type of logic programming.

21. Java is procedural programming.


a) True
b) False
Answer: b
Explanation: The statement is false. Java is a type of object oriented programming language. It
1208
involves solving real-life problems as well.

22. A program that can execute high-level language programs.


a) Compiler
b) Interpreter
c) Sensor
d) Circuitry
Answer: b
Explanation: Interpreter is a program that can execute high-level language programs
“directly,” without first being translated into machine language.

23. Executables might be called


a) native code
b) executable code
c) complex code
d) machine code
Answer: a
Explanation: The executables are sometimes called native code. HLL are translated to Machine
language called the native code.

24. Source program is compiled to an intermediate form called


a) Byte Code
b) Smart code
c) Executable code
d) Machine code
Answer: a
Explanation: The Source program is compiled to an intermediate form called byte code. For each
supported platform, write a “virtual machine” emulator that reads byte code and emulates its
execution.

25. What is operating system?


a) collection of programs that manages hardware resources
b) system service provider to the application programs
c) link to interface the hardware and application programs
d) all of the mentioned
Answer: d Explanation: None.

26. To access the services of operating system, the interface is provided by the
a) System calls
b) API
c) Library
d) Assembly instructions
Answer: a Explanation: None.

27. Which one of the following is not true?


a) kernel is the program that constitutes thecentral core of the operating system
b) kernel is the first part of operating system to load into memory during booting
c) kernel is made of various modules which can not be loaded in running operating system
1209
d) kernel remains in the memory during theentire computer session
Answer: c Explanation: None.
28. Which one of the following error will behandle by the operating system?
a) power failure
b) lack of paper in printer
c) connection failure in the network
d) all of the mentioned
Answer: d Explanation: None.

29. What is the main function of the command interpreter?


a) to get and execute the next user-specified command
b) to provide the interface between the API and application program
c) to handle the files in operating system
d) none of the mentioned
Answer: a Explanation: None.

30. By operating system, the resource management can be done via


a) time division multiplexing
b) space division multiplexing
c) time and space division multiplexing
d) none of the mentioned
Answer: c Explanation: None.

31. If a process fails, most operating system write the error information to a
a) log file
b) another running process
c) new file
d) none of the mentioned
Answer: a Explanation: None.

32. Which facility dynamically adds probes to a running system, both in user processes and in the
kernel?
a) DTrace
b) DLocate
c) DMap
d) DAdd
Answer: a Explanation: None.

33. Which one of the following is not a real time operating system?
a) VxWorks
b) Windows CE
c) RTLinux
d) Palm OS
Answer: d Explanation: None.

34. The OS X has


a) monolithic kernel
b) hybrid kernel
1210
c) microkernel
d) monolithic kernel with modules
Answer: b Explanation: None.

35. The initial program that is run when thecomputer is powered up is called
a) boot program
b) bootloader
c) initializer
d) bootstrap program
Answer: d Explanation: None.

36. How does the software trigger an interrupt?


a) Sending signals to CPU through bus
b) Executing a special operation called system call
c) Executing a special program calledsystem program an error
b) software generated interrupt caused by an error
c) user generated interrupt caused by an error
d) none of the mentioned
Answer: b Explanation: None.

38. What is an ISR?


a) Information Service Request
b) Interrupt Service Request
c) Interrupt Service Routine
d) Information Service Routine
Answer: c Explanation: None.

39. What is an interrupt vector?


a) It is an address that is indexed to an interrupt handler
b) It is a unique device number that is indexed by an address
c) It is a unique identity given to an interrupt
d) None of the mentioned
Answer: a Explanation: None.

40. The systems which allow only one process execution at a time, are called
d) Executing a special program called
interrupt trigger program
Answer: b Explanation: None.

41. What is a trap/exception?


a) hardware generated interrupt caused by
a) uniprogramming systems
b) uniprocessing systems
c) unitasking systems
d) none of the mentioned
Answer: b
Explanation: Those systems which allows
more than one process execution at a time, are called multiprogramming systems.
1211
Uniprocessing means only one processor.

42. In operating system, each process has its own


a) address space and global variables
b) open files
c) pending alarms, signals and signal handlers
d) all of the mentioned
Answer: d Explanation: None.

43. In Unix, Which system call creates the new process?


a) fork
b) create
c) new
d) none of the mentioned
Answer: a Explanation: None.

44. A process can be terminated due to


a) normal exit
b) fatal error
c) killed by another process
d) all of the mentioned
Answer: d Explanation: None.

45. What is the ready state of a process?


a) when process is scheduled to run after some execution
b) when process is unable to run until some task has been completed
c) when process is using the CPU
d) none of the mentioned
Answer: a
Explanation: When process is unable to run until some task has been completed, the process is in
blocked state and if process is using the CPU, it is in running state.

46. What is interprocess communication?


a) communication within the process
b) communication between two process
c) communication between two threads of same process
d) none of the mentioned
Answer: b Explanation: None.

47. A set of processes is deadlock if


a) each process is blocked and will remain so forever
b) each process is terminated
c) all processes are trying to kill each other
d) none of the mentioned
Answer: a Explanation: None.

48. A process stack does not contain


a) Function parameters
1212
b) Local variables
c) Return addresses
d) PID of child process
Answer: d Explanation: None.

49. Which system call returns the process identifier of a terminated child?
a) wait
b) exit
c) fork
d) get
Answer: a Explanation: None.

50. The address of the next instruction to be executed by the current process is provided by the
a) CPU registers
b) Program counter
c) Process stack
d) Pipe
Answer: b Explanation: None.

51. Which of the following do not belong to queues for processes?


a) Job Queue
b) PCB queue
c) Device Queue
d) Ready Queue
Answer: b Explanation: None.

52. When the process issues an I/O request


a) It is placed in an I/O queue
b) It is placed in a waiting queue
c) It is placed in the ready queue
d) It is placed in the Job queue
Answer: a Explanation: None.

53. What will happen when a process terminates?


a) It is removed from all queues
b) It is removed from all, but the job queue
c) Its process control block is de-allocated
d) Its process control block is never de- allocated
Answer: a Explanation: None.

54. Which process can be affected by other processes executing in the system?
a) cooperating process
b) child process
c) parent process
d) init process
Answer: a Explanation: None.

55. When several processes access the same data concurrently and the outcome of the
1213
execution depends on the particular order in which the access takes place, is called?
a) dynamic condition
b) race condition
c) essential condition
d) critical condition
Answer: b Explanation: None.

56. If a process is executing in its critical section, then no other processes can be executing in
their critical section. This condition is called?
a) mutual exclusion
b) critical exclusion
c) synchronous exclusion
d) asynchronous exclusion
Answer: a Explanation: None.

57. Which one of the following is asynchronization tool?


a) thread
b) pipe
c) semaphore
d) socket
Answer: c Explanation: None.

58. A semaphore is a shared integer variable


a) that can not drop below zero
b) that can not be more than zero
c) that can not drop below one
d) that can not be more than one
Answer: a Explanation: None.

59. Mutual exclusion can be provided by the


a) mutex locks
b) binary semaphores
c) both mutex locks and binary semaphores
d) none of the mentioned
Answer: c
Explanation: Binary Semaphores are known as mutex locks.

60. When high priority task is indirectly preempted by medium priority task effectively inverting
the relative priority of the two tasks, the scenario is called
a) priority inversion
b) priority removal
c) priority exchange
d) priority modification
Answer: a Explanation: None.

61. Process synchronization can be done on


a) hardware level
b) software level
1214
c) both hardware and software level
d) none of the mentioned
Answer: c Explanation: None.

62. What is Inter process communication?


a) allows processes to communicate and synchronize their actions when using the same address
space
b) allows processes to communicate and synchronize their actions without using the same
address space
c) allows the processes to only synchronize their actions without communication
d) none of the mentioned
Answer: b Explanation: None.

63. Message passing system allows processes to


a) communicate with one another without resorting to shared data
b) communicate with one another by resorting to shared data
c) share data
d) name the recipient or sender of the message
Answer: a Explanation: None.

64. Which of the following two operations are provided by the IPC facility?
a) write & delete message
b) delete & receive message
c) send & delete message
d) receive & send message
Answer: d Explanation: None.

65. Messages sent by a process


a) have to be of a fixed size
b) have to be a variable size
c) can be fixed or variable sized
d) None of the mentioned
Answer: c Explanation: None.

66. The link between two processes P and Q to send and receive messages is called
a) communication link
b) message-passing link
c) synchronization link
d) all of the mentioned
Answer: a Explanation: None.

67. Which of the following are TRUE for direct communication?


a) A communication link can be associated with N number of process(N = max. number of
processes supported by system)
b) A communication link can be associated with exactly two processes
c) Exactly N/2 links exist between each pair of processes(N = max. number of processes
supported by system)
d) Exactly two link exists between each pair of processes
1215
Answer: b Explanation: None.

68. In indirect communication between processes P and Q


a) there is another process R to handle and pass on the messages between P and Q
b) there is another machine between the two processes to help communication
c) there is a mailbox to help communication between P and Q
d) none of the mentioned
Answer: c Explanation: None.

69. In the non blocking send


a) the sending process keeps sending until the message is received
b) the sending process sends the message and resumes operation
c) the sending process keeps sending until it receives a message
d) none of the mentioned
Answer: b Explanation: None.

70. In the Zero capacity queue


a) the queue can store at least one message
b) the sender blocks until the receiver receives the message
c) the sender keeps sending and the messages don’t wait in the queue
d) none of the mentioned
Answer: b Explanation: None.

71. The Zero Capacity queue


a) is referred to as a message system with buffering
b) is referred to as a message system with no buffering
c) is referred to as a link
d) none of the mentioned
Answer: b Explanation: None.

72. Which module gives control of the CPU to the process selected by the short-term scheduler?
a) dispatcher
b) interrupt
c) scheduler
d) none of the mentioned
Answer: a Explanation: None.

73. The processes that are residing in main memory and are ready and waiting to execute are
kept on a list called
a) job queue
b) ready queue
c) execution queue
d) process queue
Answer: b Explanation: None.

74. The interval from the time of submission of a process to the time of completion is termed as
a) waiting time
b) turnaround time
1216
c) response time
d) throughput
Answer: b Explanation: None.

75. Which scheduling algorithm allocates the CPU first to the process that requests the CPU first?
a) first-come, first-served scheduling
b) shortest job scheduling
c) priority scheduling
d) none of the mentioned
Answer: a Explanation: None.

76. In priority scheduling algorithm


a) CPU is allocated to the process with highest priority
b) CPU is allocated to the process withlowest priority
c) Equal priority processes can not be scheduled
d) None of the mentioned
Answer: a Explanation: None.

77. In priority scheduling algorithm, when a process arrives at the ready queue, its priority is
compared with the priority of
a) all process
b) currently running process
c) parent process
d) init process
Answer: b Explanation: None.

78. Which algorithm is defined in Time quantum?


a) shortest job scheduling algorithm
b) round robin scheduling algorithm
c) priority scheduling algorithm
d) multilevel queue scheduling algorithm
Answer: b Explanation: None.

79. Process are classified into different groups in


a) shortest job scheduling algorithm
b) round robin scheduling algorithm
c) priority scheduling algorithm
d) multilevel queue scheduling algorithm
Answer: d Explanation: None.

80. CPU scheduling is the basis of


a) multiprocessor systems
b) multiprogramming operating systems
c) larger memory sized systems
d) none of the mentioned
Answer: b Explanation: None.

81. With multiprogramming is used productively.


1217
a) time
b) space
c) money
d) all of the mentioned
Answer: a Explanation: None.

82. What are the two steps of a process execution?


a) I/O & OS Burst
b) CPU & I/O Burst
c) Memory & I/O Burst
d) OS & Memory Burst
Answer: b Explanation: None.

83. An I/O bound program will typically have


a) a few very short CPU bursts
b) many very short I/O bursts
c) many very short CPU bursts
d) a few very short I/O bursts
Answer: c Explanation: None.

84. A process is selected from the queue by the scheduler, to be executed.


a) blocked, short term
b) wait, long term
c) ready, short term
d) ready, long term
Answer: c Explanation: None.

85. Round robin scheduling falls under thecategory of


a) Non-preemptive scheduling
b) Preemptive scheduling
c) All of the mentioned
d) None of the mentioned
Answer: b Explanation: None.

86. With round robin scheduling algorithm in a time shared system


a) using very large time slices converts it into First come First served scheduling algorithm
b) using very small time slices converts it into First come First served scheduling algorithm
c) using extremely small time slices increases performance
d) using very small time slices converts it into Shortest Job First algorithm
Answer: a
Explanation: All the processes will be able to get completed.

87. The portion of the process scheduler in an operating system that dispatches processes is
concerned with
a) assigning ready processes to CPU
b) assigning ready processes to waitingqueue
c) assigning running processes to blocked queue
d) all of the mentioned
1218
Answer: a Explanation: None.

88. Complex scheduling algorithms


a) are very appropriate for very large computers
b) use minimal resources
c) use many resources
d) all of the mentioned
Answer: a
Explanation: Large computers are overloaded with a greater number of processes.

89. What is FIFO algorithm?


a) first executes the job that came in last in the queue
b) first executes the job that came in first in the queue
c) first executes the job that needs minimal processor
d) first executes the job that has maximum processor needs
Answer: b Explanation: None.

90. The strategy of making processes that are logically runnable to be temporarily suspended is
called
a) Non preemptive scheduling
b) Preemptive scheduling
c) Shortest job first
d) First come First served
Answer: b Explanation: None.

91. What is Scheduling?


a) allowing a job to use the processor
b) making proper use of processor
c) all of the mentioned
d) none of the mentioned
Answer: a Explanation: None.

92. Which is the most optimal schedulingalgorithm?


a) FCFS – First come First served
b) SJF – Shortest Job First
c) RR – Round Robin
d) None of the mentioned
Answer: b Explanation: None.

93. The real difficulty with SJF in short term scheduling is


a) it is too good an algorithm
b) knowing the length of the next CPU request
c) it is too complex to understand
d) none of the mentioned
Answer: b Explanation: None.

94. The FCFS algorithm is particularly troublesome for


a) time sharing systems
1219
b) multiprogramming systems
c) multiprocessor systems
d) operating systems
Answer: b
Explanation: In a time sharing system, each user needs to get a share of the CPU at regular
intervals.

95. Consider the following set of processes, the length of the CPU burst time given in
milliseconds.
Process Burst time P1 6
P2 8
P3 7
P4 3
Assuming the above process beingscheduled with the SJF scheduling algorithm.
a) The waiting time for process P1 is 3ms
b) The waiting time for process P1 is 0ms
c) The waiting time for process P1 is 16ms
d) The waiting time for process P1 is 9ms
Answer: a Explanation: None.

96. Preemptive Shortest Job First scheduling is sometimes called


a) Fast SJF scheduling
b) EDF scheduling – Earliest Deadline First
c) HRRN scheduling – Highest Response Ratio Next
d) SRTN scheduling – Shortest Remaining Time Next
Answer: d Explanation: None.

97. An SJF algorithm is simply a priority algorithm where the priority is


a) the predicted next CPU burst
b) the inverse of the predicted next CPU burst
c) the current CPU burst
d) anything the user wants
Answer: a
Explanation: The larger the CPU burst, thelower the priority.

98. Choose one of the disadvantages of the priority scheduling algorithm?


a) it schedules in a very complex manner
b) its scheduling takes up a lot of time
c) it can lead to some low priority process waiting indefinitely for the CPU
d) none of the mentioned
Answer: c Explanation: None.

99. Concurrent access to shared data may result in


a) data consistency
b) data insecurity
c) data inconsistency
d) none of the mentioned
Answer: c Explanation: None.
1220
100. A situation where several processes access and manipulate the same data concurrently and
the outcome of the execution depends on the particular order in which access takes place is called
a) data consistency
b) race condition
c) aging
d) starvation
Answer: b Explanation: None.

101. The segment of code in which the process may change common variables, update tables,
write into files is known as
a) program
b) critical section
c) non – critical section
d) synchronizing
Answer: b Explanation: None.

102. Which of the following conditions must be satisfied to solve the critical section problem?
a) Mutual Exclusion
b) Progress
c) Bounded Waiting
d) All of the mentioned
Answer: d Explanation: None.

103. Mutual exclusion implies that


a) if a process is executing in its critical section, then no other process must be executing in their
critical sections
b) if a process is executing in its critical section, then other processes must be executing in their
critical sections
c) if a process is executing in its critical section, then all the resources of the system must be
blocked until it finishes execution
d) none of the mentioned Answer: a
Explanation: None.

104. Bounded waiting implies that there exists a bound on the number of times a process is
allowed to enter its critical section
a) after a process has made a request to enter its critical section and before the request is
granted
b) when another process is in its critical section
c) before a process has made a request to enter its critical section
d) none of the mentioned
Answer: a Explanation: None.

104. A minimum of variable(s) is/are required to be shared between processes to solve the critical
section problem.
a) one
b) two
c) three
1221
d) four
Answer: b Explanation: None.

105. An un-interruptible unit is known as


a) single
b) atomic
c) static
d) none of the mentioned
Answer: b Explanation: None.

106. TestAndSet instruction is executed


a) after a particular process
b) periodically
c) atomically
d) none of the mentioned
Answer: c Explanation: None.

107. Semaphore is a/an to solve the critical section problem.


a) hardware for a system
b) special program for a system
c) integer variable
d) none of the mentioned
Answer: c Explanation: None.

108. What are the two atomic operations permissible on semaphores?


a) wait
b) stop
c) hold
d) none of the mentioned
Answer: a Explanation: None.

109. What are Spinlocks?


a) CPU cycles wasting locks over critical sections of programs
b) Locks that avoid time wastage in context switches
c) Locks that work better on multiprocessor systems
d) All of the mentioned
Answer: d Explanation: None.

110. What is the main disadvantage of spinlocks?


a) they are not sufficient for many process
b) they require busy waiting
c) they are unreliable sometimes
d) they are too complex for programmers
Answer: b Explanation: None.

111. The wait operation of the semaphore basically works on the basic system call.
a) stop()
b) block()
1222
c) hold()
d) wait()
Answer: b Explanation: None.

112. What will happen if a non-recursivemutex is locked more than once?


a) Starvation
b) Deadlock
c) Aging
d) Signaling
Answer: b
Explanation: If a thread which had already locked a mutex, tries to lock the mutex again, it will
enter into the waiting list of that mutex, which results in a deadlock. It is because no other thread
can unlock the mutex.

113. What is a semaphore?


a) is a binary mutex
b) must be accessed from only one process
c) can be accessed from multiple processes
d) none of the mentioned
Answer: c Explanation: None.

114. What are the two kinds of semaphores?


a) mutex & counting
b) binary & counting
c) counting & decimal
d) decimal & binary
Answer: b Explanation: None.

115. What is a mutex?


a) is a binary mutex
b) must be accessed from only one process
c) can be accessed from multiple processes
d) none of the mentioned
Answer: b Explanation: None.

116. At a particular time of computation the value of a counting semaphore is [Link] 20 P


operations and 15 V operations were completed on this semaphore. The resulting value of the
semaphore is?
a) 42
b) 2
c) 7
d) 12
Answer: b
Explanation: P represents Wait and V represents Signal. P operation will decrease the value by 1
every time and V operation will increase the value by 1 every time.

117. The bounded buffer problem is also known as


a) Readers – Writers problem
1223
b) Dining – Philosophers problem
c) Producer – Consumer problem
d) None of the mentioned
Answer: c Explanation: None.

118. In the bounded buffer problem, there are the empty and full semaphores that
a) count the number of empty and full buffers
b) count the number of empty and full memory spaces
c) count the number of empty and full queues
d) none of the mentioned
Answer: a Explanation: None.

119. In the bounded buffer problem


a) there is only one buffer
b) there are n buffers ( n being greater than one but finite)
c) there are infinite buffers
d) the buffer size is bounded
Answer: b Explanation: None.

120. To ensure difficulties do not arise in the readers – writers problem are given exclusive access
to the shared object.
a) readers
b) writers
c) readers and writers
d) none of the mentioned
Answer: b Explanation: None.

121. The dining – philosophers problem willoccur in case of


a) 5 philosophers and 5 chopsticks
b) 4 philosophers and 5 chopsticks
c) 3 philosophers and 5 chopsticks
d) 6 philosophers and 5 chopsticks
Answer: a Explanation: None.

122. A deadlock free solution to the dining philosophers problem


a) necessarily eliminates the possibility of starvation
b) does not necessarily eliminate the possibility of starvation
c) eliminates any possibility of any kind of problem further
d) none of the mentioned
Answer: b Explanation: None.

123. What is a reusable resource?


a) that can be used by one process at a time and is not depleted by that use
b) that can be used by more than one process at a time
c) that can be shared between various threads
d) none of the mentioned
Answer: a Explanation: None.

1224
124. Which of the following condition is required for a deadlock to be possible?
a) mutual exclusion
b) a process may hold allocated resources while awaiting assignment of other resources
c) no resource can be forcibly removed from a process holding it
d) all of the mentioned
Answer: d Explanation: None.

125. A system is in the safe state if


a) the system can allocate resources to each process in some order and still avoid a deadlock
b) there exist a safe sequence
c) all of the mentioned
d) none of the mentioned
Answer: a Explanation: None.

126. The circular wait condition can be prevented by


a) defining a linear ordering of resource types
b) using thread
c) using pipes
d) all of the mentioned
Answer: a Explanation: None.

127. Which one of the following is the deadlock avoidance algorithm?


a) banker’s algorithm
b) round-robin algorithm
c) elevator algorithm
d) karn’s algorithm
Answer: a Explanation: None.

128. What is the drawback of banker’s algorithm?


a) in advance processes rarely know how much resource they will need
b) the number of processes changes as time progresses
c) resource once available can disappear
d) all of the mentioned
Answer: d Explanation: None.

129. For an effective operating system, when to check for deadlock?


a) every time a resource request is made
b) at fixed time intervals
c) every time a resource request is made at fixed time intervals
d) none of the mentioned
Answer: c Explanation: None.

130. A problem encountered in multitasking when a process is perpetually denied necessary


resources is called
a) deadlock
b) starvation
c) inversion
d) aging
1225
Answer: b Explanation: None.

131. Which one of the following is a visual ( mathematical ) way to determine the deadlock
occurrence?
a) resource allocation graph
b) starvation graph
c) inversion graph
d) none of the mentioned
Answer: a Explanation: None.

132. To avoid deadlock


a) there must be a fixed number of resources to allocate
b) resource allocation must be done only once
c) all deadlocked processes must be aborted
d) inversion technique can be used
Answer: a Explanation: None.

133. The number of resources requested by a process


a) must always be less than the total number of resources available in the system
b) must always be equal to the total number of resources available in the system
c) must not exceed the total number of resources available in the system
d) must exceed the total number of resources available in the system
Answer: c Explanation: None.

134. The request and release of resources are


a) command line statements
b) interrupts
c) system calls
d) special programs
Answer: c Explanation: None.

135. What are Multithreaded programs?


a) lesser prone to deadlocks
b) more prone to deadlocks
c) not at all prone to deadlocks
d) none of the mentioned
Answer: b
Explanation: Multiple threads can compete for shared resources.

136. For a deadlock to arise, which of the following conditions must hold simultaneously?
a) Mutual exclusion
b) No preemption
c) Hold and wait
d) All of the mentioned
Answer: d Explanation: None.

137. For Mutual exclusion to prevail in the system


a) at least one resource must be held in a non sharable mode
1226
b) the processor must be a uniprocessor rather than a multiprocessor
c) there must be at least one resource in a sharable mode
d) all of the mentioned
Answer: a
Explanation: If another process requests that resource (non – shareable resource), the requesting
process must be delayed until the resource has been released.

138. For a Hold and wait condition to prevail


a) A process must be not be holding a resource, but waiting for one to be freed, and then request
to acquire it
b) A process must be holding at least one resource and waiting to acquire additional resources
that are being held by other processes
c) A process must hold at least one resource and not be waiting to acquire additional resources
d) None of the mentioned
Answer: b Explanation: None.

139. Each request requires that the system consider the to decide whether the current request can
be satisfied or must wait to avoid a future possible deadlock.
a) resources currently available
b) processes that have previously been in the system
c) resources currently allocated to each process
d) future requests and releases of each process
Answer: a Explanation: None.

140. Given a priori information about the


number of resources of each type that maybe requested for each process, it is possible to
construct an algorithm that ensures that the system will never enter a deadlock state.
a) minimum
b) average
c) maximum
d) approximate
Answer: c Explanation: None.

141. A deadlock avoidance algorithm dynamically examines the to ensure that a circular wait
condition can never exist.
a) resource allocation state
b) system storage state
c) operating system
d) resources
Answer: a
Explanation: Resource allocation states are used to maintain the availability of the already and
current available resources.

142. A state is safe, if


a) the system does not crash due to deadlock occurrence
b) the system can allocate resources to each process in some order and still avoid a deadlock
c) the state keeps the system protected and safe
d) all of the mentioned
1227
Answer: b Explanation: None.

143. A system is in a safe state only if there exists a


a) safe allocation
b) safe resource
c) safe sequence
d) all of the mentioned
Answer: c Explanation: None.

144. All unsafe states are


a) deadlocks
b) not deadlocks
c) fatal
d) none of the mentioned
Answer: b Explanation: None.

145. The wait-for graph is a deadlock detection algorithm that is applicable when
a) all resources have a single instance
b) all resources have multiple instances
c) all resources have a single 7 multiple instances
d) all of the mentioned
Answer: a Explanation: None.

146. An edge from process Pi to Pj in a wait for graph indicates that


a) Pi is waiting for Pj to release a resource that Pi needs
b) Pj is waiting for Pi to release a resource that Pj needs
c) Pi is waiting for Pj to leave the system
c) rarely & frequently
d) none of the mentioned
Answer: b Explanation: None.

147. What is the disadvantage of invoking the detection algorithm for every request?
a) overhead of the detection algorithm due to consumption of memory
b) excessive time consumed in the request to be allocated memory
c) considerable overhead in computation time
d) all of the mentioned
Answer: c Explanation: None.

148. If the wait for graph contains a cycle


a) then a deadlock does not exist
b) then a deadlock exists
c) then the system is in a safe state
d) either deadlock exists or system is in a
Answer: a Explanation: None.

149. If deadlocks occur frequently, the detection algorithm must be invoked


a) rarely
b) frequently
1228
a) Abort all deadlocked processes
b) Abort all processes
c) Abort one process at a time until the deadlock cycle is eliminated
d) All of the mentioned
Answer: c Explanation: None.

150. Those processes should be aborted onoccurrence of a deadlock, the termination of which?
a) is more time consuming
b) incurs minimum cost
c) safety is not hampered
d) all of the mentioned
Answer: b Explanation: None.

151. The process to be aborted is chosen on the basis of the following factors?
a) priority of the process
b) process is interactive or batch
c) how long the process has computed
d) all of the mentioned
Answer: d Explanation: None.

152. Cost factors for process termination include


a) Number of resources the deadlock process is not holding
b) CPU utilization at the time of deadlock
c) Amount of time a deadlocked process has thus far consumed during its execution
d) All of the mentioned
Answer: c Explanation: None.

153. If we preempt a resource from a process, the process cannot continue with its normal
execution and it must be
a) aborted
b) rolled back
c) terminated
d) queued
Answer: b Explanation: None.

154. To to a safe state, the system needs to keep more information about the states of processes.
a) abort the process
b) roll back the process
c) queue the process
d) none of the mentioned
Answer: b Explanation: None.

155. If the resources are always preemptedfrom the same process can occur.
a) deadlock
b) system crash
c) aging
d) starvation
Answer: d Explanation: None.
1229
156. What is the solution to starvation?
a) the number of rollbacks must be included in the cost factor
b) the number of resources must beincluded in resource preemption
c) resource preemption be done instead
d) all of the mentioned
Answer: a Explanation: None.

157. CPU fetches the instruction from memory according to the value of
a) program counter
b) status register
c) instruction register
d) program status word
Answer: a Explanation: None.

158. A memory buffer used to accommodate a speed differential is called


a) stack pointer
b) cache
c) accumulator
d) disk buffer
Answer: b Explanation: None.

159. Which one of the following is theaddress generated by CPU?


a) physical address
b) absolute address
c) logical address
d) none of the mentioned
Answer: c Explanation: None.

160. Run time mapping from virtual to physical address is done by


a) Memory management unit
b) CPU
c) PCI
d) None of the mentioned
Answer: a Explanation: None.

161. Memory management technique in which system stores and retrieves data from secondary
storage for use in main memory is called?
a) fragmentation
b) paging
c) mapping
d) none of the mentioned
Answer: b Explanation: None.

162. The address of a page table in memory is pointed by


a) stack pointer
b) page table base register
c) page register
1230
d) program counter
Answer: b Explanation: None.

163. Program always deals with


a) logical address
b) absolute address
c) physical address
d) relative address
Answer: a Explanation: None.

164. The page table contains


a) base address of each page in physical memory
b) page offset
c) page size
d) none of the mentioned
Answer: a Explanation: None.

165. What is compaction?


a) a technique for overcoming internalfragmentation
b) a paging technique
c) a technique for overcoming external fragmentation
d) a technique for overcoming fatal error
Answer: c Explanation: None.

166. Operating System maintains the page table for


a) each process
b) each thread
c) each instruction
d) each address
Answer: a Explanation: None.

167. The main memory accommodates


a) operating system
b) cpu
c) user processes
d) all of the mentioned
Answer: a Explanation: None.

168. What is the operating system?


a) in the low memory
b) in the high memory
c) either low or high memory (depending on the location of interrupt vector)
d) none of the mentioned
Answer: c Explanation: None.

169. In contiguous memory allocation


a) each process is contained in a single contiguous section of memory
b) all processes are contained in a single contiguous section of memory
1231
c) the memory space is contiguous
d) none of the mentioned
Answer: a Explanation: None.

170. The relocation register helps in


a) providing more address space to processes
b) a different address space to processes
c) to protect the address spaces of processes
d) none of the mentioned
Answer: c Explanation: None.

171. With relocation and limit registers, each logical address must be thelimit register.
a) less than
b) equal to
c) greater than
d) none of the mentioned
Answer: a Explanation: None.

172. The operating system and the other processes are protected from being modified by an
already running process because
a) they are in different memory spaces
b) they are in different logical addresses
c) they have a protection algorithm
d) every address generated by the CPU is being checked against the relocation and limit
registers
Answer: d Explanation: None.

173. In internal fragmentation, memory is internal to a partition and


a) is being used
b) is not being used
c) is always used
d) none of the mentioned
Answer: b Explanation: None.

174. A solution to the problem of external fragmentation is


a) compaction
b) larger memory space
c) smaller memory space
d) none of the mentioned
Answer: a Explanation: None.

175. Another solution to the problem of external fragmentation problem is to


a) permit the logical address space of a process to be noncontiguous
b) permit smaller processes to be allocated memory at last
c) permit larger processes to be allocated memory at last
d) all of the mentioned
Answer: a Explanation: None.

1232
176. If relocation is static and is done at assembly or load time, compaction
a) cannot be done
b) must be done
c) must not be done
d) can be done
Answer: a Explanation: None.

177. The disadvantage of moving all process to one end of memory and all holes to the other
direction, producing one large hole of available memory is
a) the cost incurred
b) the memory used
c) the CPU used
d) all of the mentioned
Answer: a Explanation: None.

178. is generally faster than and


a) first fit, best fit, worst fit
b) best fit, first fit, worst fit
c) worst fit, best fit, first fit
d) none of the mentioned
Answer: a Explanation: None.

179. Physical memory is broken into fixed- sized blocks called


a) frames
b) pages
c) backing store
d) none of the mentioned
Answer: a Explanation: None.

180. The size of a page is typically


of the same size called
a) frames
b) pages
c) backing store
d) none of the mentioned
Answer: b Explanation: None.

181. Every address generated by the CPU is divided into two parts. They are
a) frame bit & page number
b) page number & page offset
c) page offset & frame bit
d) frame offset & page offset
Answer: b Explanation: None.

182. The is used as an index into the page table.


a) frame bit
b) page number
c) page offset
1233
d) frame offset
Answer: b Explanation: None.

183. The table contains the base address of each page in physical memory.
a) process
b) memory
c) page
d) frame
a) varied
b) power of 2
c) power of 4
d) none of the mentioned
Answer: b Explanation: None.

184. Each entry in a translation lookaside buffer (TLB) consists of


a) key
b) value
c) bit value
d) constant
Answer: a Explanation: None.

185. If a page number is not found in the TLB, then it is known as a


a) TLB miss
b) Buffer miss
c) TLB hit
d) All of the mentioned
Answer: a Explanation: None.

186. An uniquely identifies processes and is used to provide address space protection for that
process.
a) address space locator
b) address space identifier
c) address process identifier
d) none of the mentioned
Answer: b Explanation: None.

187. The percentage of times a page number is found in the TLB is known as
a) miss ratio
b) hit ratio
c) miss percent
d) none of the mentioned
Answer: b Explanation: None.

188. Memory protection in a paged environment is accomplished by


a) protection algorithm with each page
b) restricted access rights to users
c) restriction on page visibility
d) protection bit with each page
1234
Answer: d Explanation: None.

189. When the valid – invalid bit is set to valid, it means that the associated page
a) is in the TLB
b) has data in it
c) is in the process’s logical address space
d) is the system’s physical address space
Answer: c Explanation: None.

190. In segmentation, each address is specified by


a) a segment number & offset
b) an offset & value
c) a value & segment number
d) a key & value
Answer: a Explanation: None.

191. In paging the user provides only


which is partitioned by the hardware into and
a) one address, page number, offset
b) one offset, page number, address
c) page number, offset, address
d) none of the mentioned
Answer: a Explanation: None.

192. Each entry in a segment table has a


a) segment base
b) segment peak
c) segment value
d) none of the mentioned
Answer: a Explanation: None.

193. The segment base contains the


a) starting logical address of the process
b) starting physical address of the segment in memory
c) segment length
d) none of the mentioned
Answer: b Explanation: None.

194. The segment limit contains the


a) starting logical address of the process
b) starting physical address of the segment in memory
c) segment length
d) none of the mentioned
Answer: c Explanation: None.

195. The offset ‘d’ of the logical address must be


a) greater than segment limit
b) between 0 and segment limit
1235
c) between 0 and the segment number
d) greater than the segment number
Answer: b Explanation: None.

196. If the offset is legal


a) it is used as a physical memory address itself
b) it is subtracted from the segment base to produce the physical memory address
c) it is added to the segment base to produce the physical memory address
d) none of the mentioned
Answer: a Explanation: None.

197. When the entries in the segment tables of two different processes point to the same physical
location
a) the segments are invalid
b) the processes get blocked
c) segments are shared
d) all of the mentioned
Answer: c Explanation: None.

198. The protection bit is 0/1 based on


a) write only
b) read only
c) read – write
d) none of the mentioned
Answer: c Explanation: None.

199. If there are 32 segments, each of size 1Kb, then the logical address should have
a) 13 bits
b) 14 bits
c) 15 bits
d) 16 bits
Answer: a
Explanation: To specify a particular segment, 5 bits are required. To select a particular byte after
selecting a page, 10 more bits are required. Hence 15 bits are required.

200. If one or more devices use a common set of wires to communicate with the computer
system, the connection is called
a) CPU
b) Monitor
c) Wirefull
d) Bus
Answer: d Explanation: None.

201. A a set of wires and a rigidly defined protocol that specifies a set of messages that can be
sent on the wires.
a) port
b) node
c) bus
1236
d) none of the mentioned
Answer: c Explanation: None.

202. When device A has a cable that plugs into device B, and device B has a cable that plugs into
device C and device C plugs into aport on the computer, this arrangement is called a
a) port
b) daisy chain
c) bus
d) cable
Answer: b Explanation: None.

203. The present a uniform device-access interface to the I/O subsystem, much as system calls
provide a standard interface between the application and the operating system.
a) Devices
b) Buses
c) Device drivers
d) I/O systems
Answer: c Explanation: None.

204. A is a collection of electronics that can operate a port, a bus, or a device.


a) controller
b) driver
c) host
d) bus
Answer: a Explanation: None.

205. An I/O port typically consists of four registers status, control, and registers.
a) system in, system out
b) data in, data out
c) flow in, flow out
d) input, output
Answer: b Explanation: None.

206. The register is read by the host to get input.


a) flow in
b) flow out
c) data in
d) data out
Answer: c Explanation: None.

207. The register is written by the host to send output.


a) status
b) control
c) data in
d) data out
Answer: d Explanation: None.

208. The hardware mechanism that allows a device to notify the CPU is called
1237
a) polling
b) interrupt
c) driver
d) controlling
Answer: b Explanation: None.

209. The CPU hardware has a wire called that the CPU senses after executing every instruction.
a) interrupt request line
b) interrupt bus
c) interrupt receive line
d) interrupt sense line
Answer: a Explanation: None.

210. In real time operating system


a) all processes have the same priority
b) a task must be serviced by its deadline period
c) process scheduling can be done only once
d) kernel is not required
Answer: b Explanation: None.

211. For real time operating systems, interrupt latency should be


a) minimal
b) maximum
c) zero
d) dependent on the scheduling
Answer: a
Explanation: Interrupt latency is the time duration between the generation of interrupt and
execution of its service.

212. In rate monotonic scheduling


a) shorter duration job has higher priority
b) longer duration job has higher priority
c) priority does not depend on the duration of the job
d) none of the mentioned
Answer: a Explanation: None.

213. In which scheduling certain amount of CPU time is allocated to each process?
a) earliest deadline first scheduling
b) proportional share scheduling
c) equal share scheduling
d) none of the mentioned
Answer: b Explanation: None.

214. The problem of priority inversion can be solved by


a) priority inheritance protocol
b) priority inversion protocol
c) both priority inheritance and inversionprotocol
d) none of the mentioned
1238
Answer: a Explanation: None.

215. Earliest deadline first algorithm assigns priorities according to


a) periods
b) deadlines
c) burst times
d) none of the mentioned
Answer: b Explanation: None.

216. A process P1 has a period of 50 and a CPU burst of t1 = 25, P2 has a period of 80 and a CPU
burst of 35. The total CPU
utilization is a) 0.90
b) 0.74
c) 0.94
d) 0.80
Answer: c Explanation: None.

217. A process P1 has a period of 50 and a CPU burst of t1 = 25, P2 has a period of 80 and a CPU
burst of 35., the priorities of P1 and P2 are?
a) remain the same throughout
b) keep varying from time to time
c) may or may not be change
d) none of the mentioned
Answer: b Explanation: None.

218. A process P1 has a period of 50 and a CPU burst of t1 = 25, P2 has a period of 80 and a CPU
burst of 35., can the two processes be scheduled using the EDF algorithm without missing their
respective deadlines?
a) Yes
b) No
c) Maybe
d) None of the mentioned
Answer: a Explanation: None.

219. Using EDF algorithm practically, it is impossible to achieve 100 percent utilization due to
a) the cost of context switching
b) interrupt handling
c) power consumption
d) all of the mentioned
Answer: a Explanation: None.

220. T shares of time are allocated among all processes out of N shares in scheduling algorithm.
a) rate monotonic
b) proportional share
c) earliest deadline first
d) none of the mentioned
Answer: b Explanation: None.

1239
221. If there are a total of T = 100 shares to be divided among three processes, A, B and
C. A is assigned 50 shares, B is assigned 15shares and C is assigned 20 shares.
A will have percent of the total processor time.
a) 20
b) 15
c) 50
d) none of the mentioned
Answer: c Explanation: None.

222. If there are a total of T = 100 shares to be divided among three processes, A, B and
C. A is assigned 50 shares, B is assigned 15shares and C is assigned 20 shares.
B will have percent of the total processor time.
a) 20
b) 15
c) 50
d) none of the mentioned
Answer: b Explanation: None.

223. If there are a total of T = 100 shares to be divided among three processes, A, B and
C. A is assigned 50 shares, B is assigned 15shares and C is assigned 20 shares.
C will have percent of the total processor time.
a) 20
b) 15
c) 50
d) none of the mentioned
Answer: a Explanation: None.

224. If there are a total of T = 100 shares to be divided among three processes, A, B and
C. A is assigned 50 shares, B is assigned 15shares and C is assigned 20 shares.
If a new process D requested 30 shares, the admission controller would
a) allocate 30 shares to it
b) deny entry to D in the system
c) all of the mentioned
d) none of the mentioned
Answer: b Explanation: None.

225. To schedule the processes, they are considered


a) infinitely long
b) periodic
c) heavy weight
d) light weight
Answer: b Explanation: None.

226. If the period of a process is ‘p’, then what is the rate of the task?
a) p2
b) 2*p
c) 1/p
d) p
1240
Answer: c Explanation: None.

227. The scheduler admits a process using


a) two phase locking protocol
b) admission control algorithm
c) busy wait polling
d) none of the mentioned
Answer: c Explanation: None.

228. The scheduling algorithm schedules periodic tasks using a static priority policy with
preemption.
a) earliest deadline first
b) rate monotonic
c) first cum first served
d) priority
Answer: b Explanation: None.

229. Rate monotonic scheduling assumes that the


a) processing time of a periodic process is same for each CPU burst
b) processing time of a periodic process is different for each CPU burst
c) periods of all processes is the same
d) none of the mentioned
Answer: a Explanation: None.

230. The can be turned off by the CPU before the execution of critical instruction sequences that
must not be interrupted.
a) nonmaskable interrupt
b) blocked interrupt
c) maskable interrupt
d) none of the mentioned
Answer: c Explanation: None.

231. The is used by device controllers to request service.


a) nonmaskable interrupt
b) blocked interrupt
c) maskable interrupt
d) none of the mentioned
Answer: c Explanation: None.

232. The interrupt vector contains


a) the interrupts
b) the memory addresses of specialized interrupt handlers
c) the identifiers of interrupts
d) the device addresses
Answer: b Explanation: None.

233. Division by zero, accessing a protected or non existent memory address, or attempting to
execute a privileged instruction from user mode are all categorized as
1241
a) errors
b) exceptions
c) interrupt handlers
d) all of the mentioned
Answer: b Explanation: None.

234. For large data transfers, is used.


a) dma
b) programmed I/O
c) controller register
d) none of the mentioned
Answer: a Explanation: None.

235. Buffering is done to


a) cope with device speed mismatch
b) cope with device transfer size mismatch
c) maintain copy semantics
d) all of the mentioned
Answer: d Explanation: None.

236. Caching is spooling.


a) same as
b) not the same as
c) all of the mentioned
d) none of the mentioned
Answer: b Explanation: None.

237. Caching
a) holds a copy of the data
b) is fast memory
c) holds the only copy of the data
d) holds output for a device
Answer: a Explanation: None.

238. Spooling
a) holds a copy of the data
b) is fast memory
c) holds the only copy of the data
d) holds output for a device
Answer: c Explanation: None.

239. The keeps state information about the use of I/O components.
a) CPU
b) OS
c) kernel
d) shell
Answer: c Explanation: None.

1242
240. The kernel data structures include
a) process table
b) open file table
c) close file table
d) all of the mentioned
Answer: b Explanation: None.

241. Windows NT uses a implementation for I/O.


a) message – passing
b) draft – passing
c) secondary memory
d) cache
Answer: a Explanation: None.

242. A is a full duplex connection between a device driver and a user level process.
a) Bus
b) I/O operation
c) Stream
d) Flow
Answer: c Explanation: None.

243. The process of dividing a disk into sectors that the disk controller can read and write, before a
disk can store data is known as
a) partitioning
b) swap space creation
c) low-level formatting
d) none of the mentioned
Answer: c Explanation: None.

244. The header and trailer of a sector contain information used by the disk controller such as and
a) main section & disk identifier
b) error correcting codes (ECC) & sector number
c) sector number & main section
d) disk identifier & sector number
Answer: b Explanation: None.

245. The two steps the operating system takes to use a disk to hold its files are and
a) partitioning & logical formatting
b) swap space creation & caching
c) caching & logical formatting
d) logical formatting & swap space creation
Answer: a Explanation: None.

246. The program initializes all aspects of the system, from CPU registers to device controllers
and the contents of main memory, and then starts the operating system.
a) main
b) bootloader
c) bootstrap
1243
d) rom
Answer: c Explanation: None.

247. For most computers, the bootstrap is stored in


a) RAM
b) ROM
c) Cache
d) Tertiary storage
Answer: b Explanation: None.

248. A disk that has a boot partition is called a


a) start disk
b) end disk
c) boot disk
d) all of the mentioned
Answer: c Explanation: None.

249. In information is recorded magnetically on platters.


a) magnetic disks
b) electrical disks
c) assemblies
d) cylinders
Answer: a Explanation: None.

250. The heads of the magnetic disk are attached to a that moves all the heads as a unit.
a) spindle
b) disk arm
c) track
d) none of the mentioned
Answer: b Explanation: None.

251. The set of tracks that are at one arm position make up a
a) magnetic disks
b) electrical disks
c) assemblies
d) cylinders
Answer: d Explanation: None.

252. The time taken to move the disk arm to the desired cylinder is called the
a) positioning time
b) random access time
c) seek time
d) rotational latency
Answer: c Explanation: None.

253. Whenever a process needs I/O to or from a disk it issues a


a) system call to the CPU
b) system call to the operating system
1244
c) a special procedure
d) all of the mentioned
Answer: b Explanation: None.

254. If a process needs I/O to or from a disk, and if the drive or controller is busy then
Considering SSTF (shortest seek time first) scheduling, the total number of head movements is, if
the disk head is initially at 53 is?
a) 224
b) 236
c) 245
d) 240
Answer: b Explanation: None.

255. Random access in magnetic tapes is


a) the request will be placed in the queue of compared to magnetic disks. pending requests for
that drive
b) the request will not be processed and will be ignored completely
c) the request will be not be placed
d) none of the mentioned
Answer: a Explanation: None.

256. Consider a disk queue with requestsfor I/O to blocks on cylinders.


98 183 37 122 14 124 65 67
Considering FCFS (first cum first served) scheduling, the total number of head movements is, if
the disk head is initially at 53 is?
a) 600
a) fast
b) very fast
c) slow
d) very slow
Answer: d Explanation: None.

256.I/O hardware contains


a) Bus
b) Controller
c) I/O port and its registers
d) All of the mentioned
Answer: d Explanation: None.

[Link] data-in register of I/O port is


b) 620
c) 630
d) 640
Answer: d Explanation: None.

258. Consider a disk queue with requestsfor I/O to blocks on cylinders.


98 183 37 122 14 124 65 67
a) Read by host to get input
1245
b) Read by controller to get input
c) Written by host to send output
d) Written by host to start a command
Answer: a Explanation: None.

[Link] host sets bit when a command is available for the controller to execute.
a) write
b) status
c) command-ready
d) control
Answer: c Explanation: None.

260. When hardware is accessed by reading and writing to the specific memory locations, then it is
called
a) port-mapped I/O
b) controller-mapped I/O
c) bus-mapped I/O
d) none of the mentioned
Answer: d
Explanation: It is called memory-mapped I/O.

261. Device drivers are implemented to interface


a) character devices
b) block devices
c) network devices
d) all of the mentioned
Answer: d Explanation: None.

262. Which hardware triggers some operation after certain programmed count?
a) programmable interval timer
b) interrupt timer
c) programmable timer
d) none of the mentioned
Answer: a Explanation: None.

263. The device-status table contains


a) each I/O device type
b) each I/O device address
c) each I/O device state
d) all of the mentioned
Answer: d Explanation: None.

264. The model in which one kernel threadis mapped to many user-level threads is called
a) Many to One model
b) One to Many model
c) Many to Many model
d) One to One model
Answer: a Explanation: None.
1246
265. The model in which one user-levelthread is mapped to many kernel level threads is called
a) Many to One model
b) One to Many model
c) Many to Many model
d) One to One model
Answer: b Explanation: None.

266. In the Many to One model, if a thread makes a blocking system call
a) the entire process will be blocked
b) a part of the process will stay blocked, with the rest running
c) the entire process will run
d) none of the mentioned
Answer: a Explanation: None.

267. In the Many to One model, multiple threads are unable to run in parallel on multiprocessors
because of
a) only one thread can access the kernel at a time
b) many user threads have access to just one kernel thread
c) there is only one kernel thread
d) none of the mentioned
Answer: a Explanation: None.

[Link] the One to One model when a thread makes a blocking system call
a) other threads are strictly prohibited from running
b) other threads are allowed to run
c) other threads only from other processes are allowed to run
d) none of the mentioned
Answer: b Explanation: None.

269. When is the Many to One model at an advantage?


a) When the program does not need multithreading
b) When the program has to be multi- threaded
c) When there is a single processor
d) None of the mentioned
Answer: a Explanation: None.

270. In the Many to Many model true concurrency cannot be gained because
a) the kernel can schedule only one threadat a time
b) there are too many threads to handle
c) it is hard to map threads with each other
d) none of the mentioned
Answer: a Explanation: None.

271. In the Many to Many models when a thread performs a blocking system call
a) other threads are strictly prohibited from running
b) other threads are allowed to run
c) other threads only from other processes are allowed to run
1247
d) none of the mentioned
Answer: b Explanation: None.

272. 1. Thread pools are useful when


a) when we need to limit the number of threads running in the application at the same time
b) when we need to limit the number of threads running in the application as a whole
c) when we need to arrange the ordering of threads
d) none of the mentioned
Answer: a Explanation: None.

273. Instead of starting a new thread for every task to execute concurrently, the task can be
passed to a
a) process
b) thread pool
c) thread queue
d) none of the mentioned
Answer: b Explanation: None.

274. Each connection arriving at multi threaded servers via network is generally
a) is directly put into the blocking queue
b) is wrapped as a task and passed on to athread pool
c) is kept in a normal queue and then sent to the blocking queue from where it is dequeued
d) none of the mentioned
Answer: b Explanation: None.

275. What are the parts of network structure?


a) Workstation
b) Gateway
c) Laptop
d) All of the mentioned
Answer: d Explanation: None.

276. What is a valid network topology?


a) Multiaccess bus
b) Ring
c) Star
d) All of the mentioned
Answer: d Explanation: None.

277. What are sites in network topology compared?


a) Basic cost
b) Communication cost
c) Reliability
d) All of the mentioned
Answer: d Explanation: None.

278. Which design features of a communication network are important?


a) Naming and name resolution
1248
b) Routing strategies
c) Connection strategies
d) All of the mentioned
Answer: d Explanation: None.

279. What are the characteristics of Namingand Name resolution?


a) name systems in the network
b) address messages with the process-id
c) virtual circuit
d) message switching
Answer: b Explanation: None.

280. What are routing strategies which is not used in distributed systems?
a) Fixed routing
b) Token routing
c) Virtual circuit
d) Dynamic routing
Answer: c Explanation: None.

281. What are the connection strategies not used in distributed systems?
a) Circuit switching
b) Message switching
c) Token switching
d) Packet switching
Answer: c Explanation: None.

282. How is are collisions avoided in network?


a) Carrier sense with multiple access (CSMA); collision detection (CD)
b) Carrier sense multiple access with collision avoidance
c) Message slots
d) All of the mentioned
Answer: d Explanation: None.

283. In distributed system, each processor has its own


a) local memory
b) clock
c) both local memory and clock
d) none of the mentioned
Answer: c Explanation: None.

284. If one site fails in distributed system then


a) the remaining sites can continueoperating
b) all the sites will stop working
c) directly connected sites will stop working
d) none of the mentioned
Answer: a Explanation: None.

285. Network operating system runs on


1249
a) server
b) every system in the network
c) both server and every system in the network
d) none of the mentioned
Answer: a Explanation: None.

286. Which technique is based on compile- time program transformation for accessing remote
data in a distributed-memory parallel system?
a) cache coherence scheme
b) computation migration
c) remote procedure call
d) message passing
Answer: b Explanation: None.

287. Logical extension of computation migration is


a) process migration
b) system migration
c) thread migration
d) data migration
Answer: a Explanation: None.

288. Processes on the remote systems are identified by


a) host ID
b) host name and identifier
c) identifier
d) process ID
Answer: b Explanation: None.

289. Which routing technique is used in a distributed system?


a) fixed routing
b) virtual routing
c) dynamic routing
d) all of the mentioned
Answer: d Explanation: None.

290. In distributed systems, link and site failure is detected by


a) polling
b) handshaking
c) token passing
d) none of the mentioned
Answer: b Explanation: None.

291. What is not true about a distributed system?


a) It is a collection of processor
b) All processors are synchronized
c) They do not share memory
d) None of the mentioned
Answer: b Explanation: None.
1250
292. What are the characteristics of processor in distributed system?
a) They vary in size and function
b) They are same in size and function
c) They are manufactured with single purpose
d) They are real-time devices
Answer: a Explanation: None.

293. What are the characteristics of a distributed file system?


a) Its users, servers and storage devices are dispersed
b) Service activity is not carried out across the network
c) They have single centralized datarepository
d) There are multiple dependent storage devices
Answer: a Explanation: None.

294. What is not a major reason for building distributed systems?


a) Resource sharing
b) Computation speedup
c) Reliability
d) Simplicity
Answer: d Explanation: None.

295. What are the types of distributed operating system?


a) Network Operating system
b) Zone based Operating system
c) Level based Operating system
d) All of the mentioned
Answer: a Explanation: None.

296. What are characteristic of Network Operating Systems?


a) Users are aware of multiplicity of machines
b) They are transparent
c) They are simple to use
d) All of the mentioned
Answer: a Explanation: None.

297. What are routing strategies which is not used in distributed systems?
a) Fixed routing
b) Token routing
c) Virtual circuit
d) Dynamic routing
Answer: c Explanation: None.

298. What are the connection strategies not used in distributed systems?
a) Circuit switching
b) Message switching
c) Token switching
d) Packet switching
1251
Answer: c Explanation: None.

299. How is are collisions avoided in network?


a) Carrier sense with multiple access
(CSMA); collision detection (CD)
b) Carrier sense multiple access with collision avoidance
c) Message slots
d) All of the mentioned
Answer: d Explanation: None.

300. What is a common problem found in distributed system?


a) Process Synchronization
b) Communication synchronization
c) Deadlock problem
d) Power failure
Answer: c Explanation: None.

301. How many layers does the Internet model ISO consist of?
a) Three
b) Five
c) Seven
d) Eight
Answer: c Explanation: None.

302. Which layer is responsible for The process-to-process delivery?


a) Network
b) Transport
c) Application
d) Physical
Answer: b Explanation: None.

303. Which layer is the layer closest to the transmission medium?


a) Physical
b) Data link
c) Network
d) Transport
Answer: a Explanation: None.

304. Header are when data packet moves from upper to the lower layers?
a) Modified
b) Removed
c) Added
d) All of the mentioned
Answer: c Explanation: None.

305. Which layer lies between the transport layer and data link layer?
a) Physical
b) Network
1252
c) Application
d) Session
Answer: b Explanation: None.

306. Which of the following is an application layer service?


a) Mail service
b) File transfer
c) Remote access
d) All of the mentioned
Answer: d Explanation: None.

307. What are the different ways in which clients and servers are dispersed across machines?
a) Servers may not run on dedicated machines
b) Servers and clients can be on same machines
c) Distribution cannot be interposed between a OS and the file system
d) OS cannot be distributed with the file system a part of that distribution
Answer: b Explanation: None.

308. What are not the characteristics of a DFS?


a) login transparency and access transparency
b) Files need not contain information abouttheir physical location
c) No Multiplicity of users
d) No Multiplicity if files
Answer: c Explanation: None.

309. What are characteristic of a DFS?


a) Fault tolerance
b) Scalability
c) Heterogeneity of the system
d) Upgradation
Answer: d Explanation: None.

310. What are the different ways file accesses take place?
a) sequential access
b) direct access
c) indexed sequential access
d) all of the mentioned
Answer: d Explanation: None.

311. Which is not a major component of afile system?


a) Directory service
b) Authorization service
c) Shadow service
d) System service
Answer: c Explanation: None.

312. What are the different ways mounting of the file system?
a) boot mounting
1253
b) auto mounting
c) explicit mounting
d) all of the mentioned
Answer: d Explanation: None.

313. Implementation of a stateless file server must not follow?


a) Idempotency requirement
b) Encryption of keys
c) File locking mechanism
d) Cache consistency
Answer: b Explanation: None.

314. What are the advantages of file replication?


a) Improves availability & performance
b) Decreases performance
c) They are consistent
d) Improves speed
Answer: a Explanation: None.

315. What are characteristic of NFS protocol?


a) Search for file within directory
b) Read a set of directory entries
c) Manipulate links and directories
d) All of the mentioned
Answer: d Explanation: None.

316. The file once created can not be changed is called


a) immutable file
b) mutex file
c) mutable file
d) none of the mentioned
Answer: a Explanation: None.

317. of the distributed file system are dispersed among various machines of distributed system.
a) Clients
b) Servers
c) Storage devices
d) All of the mentioned
Answer: d Explanation: None.

318. is not possible in distributed file system.


a) File replication
b) Migration
c) Client interface
d) Remote access
Answer: b Explanation: None.

319. Which one of the following hides thelocation where in the network the file is stored?
1254
a) transparent distributed file system
b) hidden distributed file system
c) escaped distribution file system
d) spy distributed file system
Answer: a Explanation: None.

320. A process can be


a) single threaded
b) multithreaded
c) both single threaded and multithreaded
d) none of the mentioned
Answer: c Explanation: None.

321. If one thread opens a file with read privileges then


a) other threads in the another process can also read from that file
b) other threads in the same process can also read from that file
c) any other thread can not read from that file
d) all of the mentioned
Answer: b Explanation: None.

322. The time required to create a new thread in an existing process is


a) greater than the time required to createa new process
b) less than the time required to create a new process
c) equal to the time required to create a new process
d) none of the mentioned
Answer: b Explanation: None.

323. When the event for which a thread is blocked occurs?


a) thread moves to the ready queue
b) thread remains blocked
c) thread completes
d) a new thread is provided
Answer: a Explanation: None.

324. A thread is also called


a) Light Weight Process(LWP)
b) Heavy Weight Process(HWP)
c) Process
d) None of the mentioned
Answer: a Explanation: None.

325. A thread shares its resources(like data section, code section, open files, signals) with
a) other process similar to the one that thethread belongs to
b) other threads that belong to similar processes
c) other threads that belong to the same process
d) all of the mentioned
Answer: c Explanation: None.

1255
326. A heavy weight process
a) has multiple threads of execution
b) has a single thread of execution
c) can have multiple or a single thread for execution
d) none of the mentioned
Answer: b Explanation: None.

327. A process having multiple threads of control implies


a) it can do more than one task at a time
b) it can do only one task at a time, butmuch faster
c) it has to use only one thread per process
d) none of the mentioned
Answer: a Explanation: None.

328. Multithreading an interactive program will increase responsiveness to the user by


a) continuing to run even if a part of it is blocked
b) waiting for one part to finish before the other begins
c) asking the user to decide the order of multithreading
d) none of the mentioned
Answer: a Explanation: None.

329. Resource sharing helps


a) share the memory and resources of the process to which the threads belong
b) an application have several different threads of activity all within the same address space
c) reduce the address space that a process could potentially use
d) all of the mentioned
Answer: d Explanation: None.

330. Multithreading on a multi – CPU machine


a) decreases concurrency
b) increases concurrency
c) doesn’t affect the concurrency
d) can increase or decrease the concurrency
Answer: b Explanation: None.

331. The kernel is of user threads.


a) a part of
b) the creator of
c) unaware of
d) aware of
Answer: c Explanation: None.

332. is a unique tag, usually a number identifies the file within the file system.
a) File identifier
b) File name
c) File type
d) None of the mentioned
Answer: a Explanation: None.
1256
333. To create a file
a) allocate the space in file system
b) make an entry for new file in directory
c) allocate the space in file system & make
an entry for new file in directory
d) none of the mentioned
Answer: c Explanation: None.

334. By using the specific system call, we can


a) open the file
b) read the file
c) write into the file
d) all of the mentioned
Answer: d Explanation: None.

335. File type can be represented by


a) file name
b) file extension
c) file identifier
d) none of the mentioned
Answer: b Explanation: None.

336. Which file is a sequence of bytes organized into blocks understandable by the system’s
linker?
a) object file
b) source file
c) executable file
d) text file
Answer: a Explanation: None.

337. What is the mounting of file system?


a) crating of a filesystem
b) deleting a filesystem
c) attaching portion of the file system into a directory structure
d) removing the portion of the file system into a directory structure
Answer: c Explanation: None.

338. Mapping of file is managed by


a) file metadata
b) page table
c) virtual memory
d) file system
Answer: a Explanation: None.

339. Mapping of network file system protocol to local file system is done by
a) network file system
b) local file system
1257
c) volume manager
d) remote mirror
Answer: a Explanation: None.

340. Which one of the following explains the sequential file access method?
a) random access according to the given byte number
b) read bytes one at a time, in order
c) read/write sequentially by record
d) read/write randomly by record
Answer: b Explanation: None.

341. When will file system fragmentation occur?


a) unused space or single file are not contiguous
b) used space is not contiguous
c) unused space is non-contiguous
d) multiple files are non-contiguous
Answer: a Explanation: None.

342. What is the mount point?


a) an empty directory at which the mounted file system will be attached
b) a location where every time file systems are mounted
c) is the time when the mounting is done
d) none of the mentioned
Answer: a Explanation: None.

343. When a file system is mounted over a directory that is not empty then
a) the system may not allow the mount
b) the system must allow the mount
c) the system may allow the mount and the directory’s existing files will then be made obscure
d) all of the mentioned
Answer: c Explanation: None.

344. In UNIX, exactly which operations can be executed by group members and other users is
definable by
a) the group’s head
b) the file’s owner
c) the file’s permissions
d) all of the mentioned
Answer: b Explanation: None.

345. A process lower the priority of another process if both are owned by the same owner.
a) must
b) can
c) cannot
d) none of the mentioned
Answer: b Explanation: None.

346. In distributed file system


1258
directories are visible from the local machine.
a) protected
b) local
c) private
d) remote
Answer: d Explanation: None.

347. In the world wide web, a is needed to gain access to the remote files, and separate operations
are used to transfer files.
a) laptop
b) plugin
c) browser
d) player
Answer: c Explanation: None.

348. Anonymous access allows a user totransfer files


a) without having an account on the remote system
b) only if he accesses the system with a guest account
c) only if he has an account on the remote system
d) none of the mentioned
Answer: a
Explanation: The world wide web uses anonymous file exchange almost exclusively.

349. The machine containing the files is the


and the machine wanting to access the files is the
a) master, slave
b) memory, user
c) server, client
d) none of the mentioned
Answer: c Explanation: None.

350. Distributed naming services/Distributed information systems have been devised to


a) provide information about all thesystems
b) provide unified access to the information needed for remote computing
c) provide unique names to all systems in a network
d) all of the mentioned
Answer: b Explanation: None.

351. Domain name system provides


a) host-name-to-network-address translations for the entire internet
b) network-address-to-host-name translations for the entire internet
c) binary to hex translations for the entireinternet
d) all of the mentioned
Answer: a Explanation: None.

352. Reliability of files can be increased by


a) keeping the files safely in the memory
b) making a different partition for the files
1259
c) by keeping them in external storage
d) by keeping duplicate copies of the file
Answer: d Explanation: None.

353. Protection is only provided at the level.


a) lower
b) central
c) higher
d) none of the mentioned
Answer: a Explanation: None.

354. What is the main problem with access control lists?


a) their maintenance
b) their length
c) their permissions
d) all of the mentioned
Answer: b Explanation: None.

355. Many systems recognize three classifications of users in connection with each file (to
condense the access control list).
a. Owner
b. Group
c. Universe
d. All of the mentioned
Answer: d Explanation: None.

356. The three major methods of allocating disk space that are in wide use are
a) contiguous
b) linked
c) indexed
d) all of the mentioned
Answer: d Explanation: None.

357. In contiguous allocation


a) each file must occupy a set of contiguous blocks on the disk
b) each file is a linked list of disk blocks
c) all the pointers to scattered blocks are placed together in one location
d) none of the mentioned
Answer: a Explanation: None.

358. In linked allocation


a) each file must occupy a set of contiguous blocks on the disk
b) each file is a linked list of disk blocks
c) all the pointers to scattered blocks are placed together in one location
d) none of the mentioned
Answer: b Explanation: None.

359. In indexed allocation


1260
a) each file must occupy a set of contiguous blocks on the disk
b) each file is a linked list of disk blocks
c) all the pointers to scattered blocks are placed together in one location
d) none of the mentioned
Answer: c Explanation: None.

360. On systems where there are multiple operating system, the decision to load a particular one is
done by
a) boot loader
b) bootstrap
c) process control block
d) file control block
Answer: a Explanation: None.

361. The VFS (virtual file system) activates file system specific operations to handle local
requests according to their
a) size
b) commands
c) timings
d) file system types
Answer: d Explanation: None.

362. A device driver can be thought of like a translator. Its input consists of commands and output
consists of instructions.
a) high level, low level
b) low level, high level
c) complex, simple
d) low level, complex
Answer: a Explanation: None.

363. The file organization module knows about


a) files
b) logical blocks of files
c) physical blocks of files
d) all of the mentioned
Answer: d Explanation: None.

364. Metadata includes


a) all of the file system structure
b) contents of files
c) both file system structure and contents of files
d) none of the mentioned
Answer: c Explanation: None.

365. For each file there exists a that contains information about the file, including ownership,
permissions and location of the file contents.
a) metadata
b) file control block
1261
c) process control block
d) all of the mentioned
Answer: b Explanation: None.

366. For processes to request access to file contents, they need


a) to run a seperate program
b) special interrupts
c) to implement the open and close system calls
d) none of the mentioned
Answer: c Explanation: None.

367. A better way of contiguous allocation to extend the file size is


a) adding an extent (another chunk of contiguous space)
b) adding an index table to the first contiguous block
c) adding pointers into the first contiguous block
d) none of the mentioned
Answer: a Explanation: None.

368. If the extents are too large, then what is the problem that comes in?
a) internal fragmentation
b) external fragmentation
c) starvation
d) all of the mentioned
Answer: a Explanation: None.

369. The FAT is used much as a


a) stack
b) linked list
c) data
d) pointer
Answer: b Explanation: None.

[Link] UNIX, even an ’empty’ disk has a percentage of its space lost to
a) programs
b) inodes
c) virtual memory
d) stacks
Answer: b Explanation: None.

271. Some directory information is kept in main memory or cache to


a) fill up the cache
b) increase free space in secondary storage
c) decrease free space in secondary storage
d) speed up access
Answer: d Explanation: None.

272. A systems program such as fsck in


is a consistency checker.
1262
a) UNIX
b) Windows
c) Macintosh
d) Solaris

273.A consistency checker bottleneck in system performance. and tries to fix any
a) CPUs
b) Disks
c) Programs
d) I/O
Answer: b Explanation: None.

274. Each set of operations for performing a specific task is a


a) program
b) code
c) transaction
d) all of the mentioned
Answer: c Explanation: None.

275. Once the changes are written to the log, they are considered to be
a) committed
b) aborted
c) completed
d) none of the mentioned
Answer: a Explanation: None.

276. When an entire committed transaction is completed,


a) it is stored in the memory
b) it is removed from the log file
c) it is redone
d) none of the mentioned
Answer: b Explanation: None.

277. A machine in Network file system (NFS) can be


a) client
b) server
c) both client and server
d) neither client nor server
Answer: c Explanation: None.

278. A directory is mounted over a directory of a file system.


a) local, remote
b) remote, local
c) local, local
d) none of the mentioned
Answer: d Explanation: None.

279. What is Address Binding?


1263
a) going to an address in memory
b) locating an address with the help of another address
c) binding two addresses together to form a new address in a different memory space
d) a mapping from one address space to another
View Answer
Answer: d Explanation: None.

280. Binding of instructions and data tomemory addresses can be done at


a) Compile time
b) Load time
c) Execution time
d) All of the mentioned
Answer: d Explanation: None.

281. Which one of the following is a process that uses the spawn mechanism to revage the
system performance?
a) worm
b) trojan
c) threat
d) virus
Answer: a Explanation: None.

282. What is true regarding ‘Fence’?


a) Its a method to confine users to one side of a boundary
b) It can protect Operating system from one user
c) It cannot protect users from each other
d) All of the mentioned
Answer: d Explanation: None.

283. What is not true regarding ‘Fence’?


a) It is implemented via hardware register
b) It doesn’t protect users from each other
c) It good to protect OS from abusive users
d) Its implementation is unrestricted and can take any amount of space in Operating system.
Answer: d Explanation: None.

284. What is correct regarding ‘relocation’


w.r.t protecting memory?
a) It is a process of taking a program as if it began at address 0
b) It is a process of taking a program as if it began at address 0A
c) Fence cannot be used within relocation process
d) All of the mentioned
Answer: a Explanation: None.

285. What are the incorrect methods of revocation of access rights?


a) Immediate/Delayed
b) Selective/General
c) Partial/total
1264
d) Crucial
Answer: d Explanation: None.

286. Why is it difficult to revoke capabilities?


a) They are too many
b) They are not defined precicely
c) They are distributed throughout the system
d) None of the mentioned
Answer: c Explanation: None.

287. What is the reacquisition scheme to revoke capability?


a) When a process capability is revoked then it won’t be able to reacquire it
b) Pointers are maintained for each object which can be used to revoke
c) Indirect pointing is done to revokeobject’s capabilities
d) Master key can be used compare and revoke.
Answer: a Explanation: None.

288. What is false regarding Back-Pointers scheme to revoke capability?


a) List of pointers is maintained with each object
b) When revocation is required these pointers are followed
c) This scheme is not adopted in MULTICS system
d) These point to all capabilities associated with that object
Answer: c Explanation: None.

289. From the following, which is not a common file permission?


a) Write
b) Execute
c) Stop
d) Read
Answer: c Explanation: None.

290. Which of the following is a good practice?


a) Give full permission for remote transferring
b) Grant read only permission
c) Grant limited permission to specified account
d) Give both read and write permission but not execute
Answer: c
Explanation: Limited access is a key method to circumvent unauthorized access and exploits.

291. What is breach of availability?


a) This type of violation involves unauthorized reading of data
b) This violation involves unauthorized modification of data
c) This violation involves unauthorized destruction of data
d) This violation involves unauthorized use of resources
Answer: c Explanation: None.

292. What is Trojan horse?


a) It is a useful way to encrypt password
1265
b) It is a user which steals valuable information
c) It is a rogue program which tricks users
d) It’s a brute force attack algorithm
Answer: c Explanation: None.

293. What is trap door?


a) IT is trap door in WarGames
b) It is a hole in software left by designer
c) It is a Trojan horse
d) It is a virus which traps and locks user terminal
Answer: b Explanation: None.

294. Which mechanism is used by worm process?


a) Trap door
b) Fake process
c) Spawn Process
d) VAX process
Answer: c Explanation: None.

295. Which of the following is not a characteristic of a virus?


a) Virus destroy and modify user data
b) Virus is a standalone program
c) Virus is a code embedded in a legitimate program
d) Virus cannot be detected
Answer: d
Explanation: Virus can be detected by having an antivirus program.

296. What is not an important part of security protection?


a) Large amount of RAM to support antivirus
b) Strong passwords
c) Audit log periodically
d) Scan for unauthorized programs in system directories
Answer: a
Explanation: RAM has no effect on security of a system. System’s protection remains unchanged
in increasing or decreasing amount of RAM.

297. What is used to protect network from outside internet access?


a) A trusted antivirus
b) 24 hours scanning for virus
c) Firewall to separate trusted and untrusted network
d) Deny users access to websites which can potentially cause security leak
Answer: c
Explanation: Firewall create a protective barrier to secure internal network. An antivirus can only
detect harmful viruses but cannot stop illegal access by remote attacker.

298. What is the best practice in the firewall domain environment?


a) Create two domain trusted and untrusted domain
b) Create strong policy in firewall to support different types of users
1266
c) Create a Demilitarized zone
d) Create two DMZ zones with one untrusted domain
Answer: c
Explanation: All live servers or workstations are kept in a separate zone than inside and outside to
enhance protection.

299. Which direction access cannot happen using DMZ zone by default?
a) Company computer to DMZ
b) Internet to DMZ
c) Internet to company computer
d) Company computer to internet
Answer: c
Explanation: Connection from internet is never allowed to directly access internal PCs but is routed
through DMZ zone to prevent atta

300. A process is thrashing if


a) it spends a lot of time executing, rather than paging
b) it spends a lot of time paging than executing
c) it has no memory allocated to it
d) none of the mentioned
Answer: b Explanation: None.

301. Thrashing the CPU utilization.


a) increases
b) keeps constant
c) decreases
d) none of the mentioned View Answer
Answer: c Explanation: None.

302. RAID level 3 supports a lower numberof I/Os per second, because
a) Every disk has to participate in every I/O request
b) Only one disk participates per I/O request
c) I/O cycle consumes a lot of CPU time
d) All of the mentioned
Answer: a Explanation: None.

303. RAID level is also known as block interleaved parity organisation and uses block level striping
and keeps a parity block on a separate disk.
a) 1
b) 2
c) 3
d) 4
Answer: d Explanation: None.

304. A performance problem with


is the expense of computing and writing parity.
a) non-parity based RAID levels
b) parity based RAID levels
1267
c) all RAID levels
d) none of the mentioned
Answer: b Explanation: None.

305. In RAID level 4, one block read, accesses


a) only one disk
b) all disks simultaneously
c) all disks sequentially
d) none of the mentioned
Answer: a
Explanation: Other requests are allowed to be processed by other disks.

306. The overall I/O rate in RAID level 4 is


a) low
b) very low
c) high
d) none of the mentioned
Answer: c
Explanation: All disks can be read in parallel.

307. Linux uses a time-sharing algorithm


a) to pair preemptive scheduling between
multiple processes
b) for tasks where absolute priorities are more important than fairness
c) all of the mentioned
d) none of the mentioned
Answer: a Explanation: None.

308. The first linux kernel which supports the SMP hardware?
a) linux 0.1
b) linux 1.0
c) linux 1.2
d) linux 2.0
Answer: d Explanation: None.

309. What is Linux?


a) single user, single tasking
b) single user, multitasking
c) multi user, single tasking
d) multi user, multitasking
Answer: d Explanation: None.

310. Which one of the following is not a linux distribution?


a) debian
b) gentoo
c) open SUSE
d) multics
Answer: d Explanation: None.
1268
311. In distributed systems, a logical clock is associated with
a) each instruction
b) each process
c) each register
d) none of the mentioned
Answer: b Explanation: None.

312. If timestamps of two events are same, then the events are
a) concurrent
b) non-concurrent
c) monotonic
d) non-monotonic
Answer: a Explanation: None.

313. If a process is executing in its criticalsection


a) any other process can also execute in its critical section
b) no other process can execute in its critical section
c) one more process can execute in its critical section
d) none of the mentioned
Answer: b Explanation: None.

314. A process can enter into its critical section


a) anytime
b) when it receives a reply message from its parent process
c) when it receives a reply message from all other processes in the system
d) none of the mentioned
Answer: c Explanation: None.

315. For proper synchronization in distributed systems


a) prevention from the deadlock is must
b) prevention from the starvation is must
c) prevention from the deadlock & starvation is must
d) none of the mentioned
Answer: c Explanation: None.

1269

You might also like