Professional Documents
Culture Documents
MATERIAL
CONTENTS
1. COURSE ON MATHS.
2. C PROGRAMMING &
DATA STRUCTURES.
3. COMPUTER ORGANIZATION.
4. SYSTEMS PROGRAMMING.
APPENDIX
1. ASSIGNMENT 1
2. ASSIGNMENT 2
3. MODEL QUESTION PAPER
MATHEMATICS
Contents
1. Functions: Definition Types - Problems.
2. Set Theory: Definition Types Problems Venn
Diagrams.
3. Number Systems: Definition Types Properties
Problems.
4. Matrices & Determinants: Definition - Types Algebra of
matrices properties.
5. Differential calculus: Variables Constants Functions
Types Differential Co-efficient.
6. Linear Programming: Graphical methods and problems.
7. Graph Theory: Meaning Koingbergs Bridge Problem
Utilities Problem Representation of Graph Types o
Graph.
Functions
Definition: - Linear, Quadratic, Cubic, Exponential and logarithmic
functions, multivariate functions, problems.
Demand (D) of a commodity is related to its price (P). It can be
mathematically expressed as D = F (P).
This relationship is read as Demand is function of price or simply
F of P. This mathematical relationship has two variables D and P. These
are called variables because they can take on different numeric values.
For e.g.: D = F (P) is a single variable (or a single dimensional)
function.
D = F (P, A) is a two variable (two dimensional) function.
D = F(C, B, P, N) is a multi variable (multi dimensional) function.
C = Cash flow,
P = Capital,
B = Cash Outlay
N = Life of Project.
Y = F (X) = a + bx.
Y = 3 + 2x
5
3
0
1
Quadratic Equation:
Cubic Equation:
Y = ax2 + bx + c
Y = ax3 + bx2 + cx + d
a1
a1
a1
Y = ax ,
Y = Kax,
Y = Kabx
Y = Kex
Y
Y = kax
a>1,k>0
Y = Kax
(a<1, k>0)
k
X
5
0
Is expressed as Y = log e X
Where a 1 and > 0 is the base. It is read as Y in the log to the base
a of x, this can also be written as X = ay
Thus from an exponential function Y = a x, as we may construct the
logarithmic function X = log
= 50 X (35X+1000) = 15X1000
If 400 units of an item are manufactured and sole then profit is given by
P = 15 X 400 1000 = 5000.
Quadratic functions:
Let the market supply function of an item be Q = 160+SP, where Q
denotes the quantity supplied and P denotes the market price. The unit cost
of production is Rs.4/-. It is felt that total profit should be Rs.500/-. What
market has to be fixed for the item so as to achieve this profit?
Solution: Total profit function is constructed as follows.
P = Total Revenue Total cost.
= (Price/Unit) X (Quantity supplied)
= - (Cost/unit) X (Quantity supplied)
= P.Q C.Q = (P-C) Q
Given c = 4 and 1 =160+8p, then total profit function becomes
P = (P-4) (160-p)
= 8p2+128p 640.
If P = 500 then, we have, 500 = 8p2+128p-640
= 8p2+128p-1140 = 0
P = -128 (128) 2 4 x 8 x (-1140)
2x8
= -128 229.92
16
= 6.36 OR 22.37
Required price / Unit = Rs.6.36.
Set Theory
Any well-defined collection of distinct objects is called a Set. The
objects in a set are called its elements or members. By distinct we mean
that the elements are different i.e., each element in the same set is different
from any other element in the same set. By well defined we mean there is a
rule (rules) by which, it is possible to say without any ambiguity whether a
particular object belongs to or not a given set.
Denotes to Belongs to
Denotes Does not belongs to
If a is a set and a is any object then
A S => a belongs to s i.e., a is an element of S
A S => a does not belongs to s i.e., a is not a member of s
If V = {a, e, i, o, u} here v is a set and a, e, i, o, u, are its members.
Some common terms:
N denotes set of natural numbers.
I denote set of integers
Q denote set of rational numbers
R denote set of real numbers
U denotes universal set
Denotes empty set.
Equal Sets:
Two sets A and B are said to be equal, if the sets contain exactly same
elements, then we write A =B.
Equivalent sets:
B = {c, d, e, f}
AB = {a, b, c, d, e, f}
A = {a, b, c, d, e},
B = {x, y, z}
AB = {a, b, c, d, e, x, y, z}.
So, X AB => X A or X B or X A&B.
Intersection sets:
The intersection of two sets A & B is the set of elements that belong
to both A and B i.e., the common elements of A & B. Symbolically it is
written as AB and is read as A intersection B.
E.g.: If A = {1, 2, 3, 4, 5}
and
B = {4, 5, 6, 7, 8}
B = {2, 3},
C = {4,5,6}
All these three sets A, B and C are the subsets of the set
= {1, 2, 3, 4, 5, 6}
= {1, 2, 3, 4, 5, 6} is said to be the universal set for the sets A, B, & C.
All universal set is defined as that fixed set of which all the sets under
consideration are subsets.
Subset:
A set A is called a subset of a set B if every element of A is also an
element of B.
If X B => X B X A
( for every)
10
U = {1,2,3,4},
B = {2,4,6}
11
solution:
I)
II)
Problems:
i)
solution:
ii) A (BC).
AB = {a,b,c,d,e,f}
(AB) C = {a,b,c,d,e,f,g,h}
BC = {e,f}
A (BC) = {a,b,c,d}{e,f}={a,b,c,d,e,f}
If U = {0,1,2,3,4,5,6,7,8,9}
B = {0,2,3,4,6,8} Verify (AB)1 = A1 B1
A = {3,5,7,9};
Solution:
AB = {3},
{AB}1 = {0,1,2,3,4,5,6,7,8,9}
A1 = {0,1,2,4,6,8}
B1 = {1,5,7,9}
A1B1 = {0,1,2,3,4,5,6,7,8,9}
(AB)1 = A1 B1
Problems:
The Hindustan Times paper and 35,000 read Times of India, paper
while 7,500 read both the newspapers. Indicate how many read neither the
Hindustan Times nor Times of India.
Solution:
Set m(p)
total population
12
m(h)
m(t)
59,500
U
A
Proper Subset
A
B
13
B A
U
B
A
AB
U
A
Disjoint sets
Over-lapping sets
Intersection sets:
a) When the sets are disjoint
U
A
U
A
AB =
When the sets are overlapping
14
m(AB) = m(A) + m(B) m(AB)
(X Y) Z = (XZ) (YZ)
Y
Z
(X Y) Z
(XZ) (YZ)
Problem:
Every student in a class of 42 students studies at least one of the
subjects, maths, English & Commerce. 14 students study maths, 20-student
commerce and 24 English. 3 students study maths and commerce, 2 english
& commerce and tere is no student who studies all the subjects. Find the
number of students who study maths and English and not commerce.
Solution:
Let M,E,C, represents respectively the set of students who study
maths, English and commerce respectively.
m(MEC) = 42; m(M) = 14; m(C) =20; m(E) = 24;
m(MC) = 3; m(EC) = 2 and
m(MEC) = 0
m(MEC) = m(M)+m(E)+m(C)-m(ME)
-m(MC)-m(EC)+m(MEC)
= 42 = 14+24+20-m(ME)-3-2-+0
15
m(B)=22
m(A)=18
AB =10
16
Let A denote the set of students taking economics and B denotes the
set of student taking maths.
AB = Set of students taking either maths or economics or both.
AB = Set of students taking maths and economics both.
m(AB) = m(A)+m(B)-m(AB)
30 = 18+m(B) m(B) = 22.
m(B) = m(BA)+m(BAC)
22 = 10+ m(BAC) = 12.
Students taking maths not economics = 12.
17
Number Systems
Natural numbers:
1 is a natural number (1 belongs to N), for each number say n
belongs to N there exists a natural no, say n1N called successor of N, such
that n1 = n+1, i.e., the set of natural numbers is an infinite set with elements
1,2,3,4 . . . 1 is not a successor of any natural number i.e., 1 is the smallest
natural number.
Natural numbers 1, 2, 3 . .
corresponding to each positive integer there is a negative integer thus 1, 2-3 are called negative integers.
Integers:
The set of integers consists of all the natural numbers their negatives
and the number zero set of integers denoted by (I) i.e.,
I = [ . . . 3, -2, -1, 0, 1, 2, 3 . . . ]
Rational Numbers:
Any number of the form a/b where a and b are integers and b# 0 is
called a rational number set of rational numbers denoted by Q i.e.,
Q = (a/b; a & b are integers but b#0)
It may be noted that between any two rational number there is always
at least one other rational number (if a and b are two rational numbers
then a+b/2 is also a rational number. This property s not possessed by
integers.
18
Irrational Number:
An irrational number is a number corresponding to a non-repeating
infinite decimal. E.g.: radicals are natural numbers, which cannot be
determined completely 34, 5, 3, 2.
Graphical representation of real numbers.
Real numbers can be represented by points on a line called the real
axis as indicated in figure below. The point corresponding to zero is called
the origin. Origin divides the line in two parts, the part on the left of origin is
called ve part. The ve real numbers are represented in this part. The part
on the right of origin is called +ve part. The positive real numbers are
represented here.
-3
-2
-1
To each point on the line these corresponds one and only real number.
If point A corresponding to a real number a ties to the right of a point B
corresponding to a real number b we say a>b or b<a.
Please note that in a set of real nos.
0 is called additive identity element
1 is called the multiplicative identity element
-a is called the additive inverse of a and vice versa.
J/a is called the multiplication inverse of a and vice verse for every aR
A set of real numbers satisfies the following properties.
19
Addition properties
If a, b, c, R then
A1 = a+bR(closure property)
A2 = a+b = b+a (Commutative property)
A3 = (a+b)+c = a+(b+c) (Associative property)
A4 = a+0 = 0+a = 0 (Property of zero)
A5 = a+(-a)=0 (Property of additive inverse)
Multiplication properties:
If a, b, c, R then
M1 = abR(closure property)
M2 = ab = ba (Commutative property)
M3 = (ab)c = a(bc) (Associative property)
M4 = a.1 = 1.a = a (Property of 1)
M5 = a(1/a)=(1/a).a=1 (Property of multiplicative inverse)
AM a(b+c) = (b+c)a = ab+ac(Distributive property).
E.g.: Prove that I) 2, II) log105 are all irrational numbers.
Solution: Suppose 2 is a rational number and can be expressed as a/b in its
lowest terms where a & b are integers then
a/b = 2 = a2/b2 = 2 i.e., a2 = 2b2
Since, 2b2 is an even number, a must be even.
Set a = sc where C is an integer.
i.e., 4c2 = a2 = 2b2 or b2-2c2 => b is an even number i.e., a and b are
both even which contradicts the assumption that there is no common factor
in a & b. Hence, 2 is an irrational number.
20
II) log105
=> 5 is a multiple of 2
Which is not true, hence, log105 is an irrational number.
Prove that only positive integers that have rational square roots are
square of integers.
Solution: If possible let every integer x have a positive square root that can
be expressed as a/b where a, b 1 that are in lowest terms.
X = a/b or x2 = a2/b2
21
Since, a & b are in lowest terms, a2 & b2 will also be in lowest terms.
Since, x is an integer, a2/b2 is also an integer.
b2 = 1 => b = 1
a/b = a but a an integer.
This implies that if a positive integer has a rational square root, the
root must itself be an integer, i.e., x must be a square root of an integer;
hence, only positive integers that have a rational square root are squares of
integers themselves.
3 -4
1
B=
3i
-1
a11
a12
a13
...
a1n
a21
a22
a23
...
a2n
........................
am1 am2 am3 . . .
amn
22
Two suffixes are attached to each element in the matrix A, the first
suffix indicating the row and the second suffix indicating the column in
which the element is located. Thus aij denotes the element in the ith row and
jth column. Rows are numbered from top to bottom and the columns from
left to right.
Dimension and order of a matrix
A matrix with m rows and n column is called an mXn matrix (read as
m by n matrix) or is said to be of order mXn. The numbers m & n are called
dimensions of the matrix.
A=
3 -4
2
B=
3i
-1
2x2
2x3
Types of Matrices
1. Scalar: The simplest matrix is one with a single element, I,e, a 1x1
matrix. Such a matrix is usually identified by the corresponding the
number and is said to be a scalar.
E.X.: (4) = 4, (a) = a
2. Row Matrix: A matrix with a single row (1xn matrix) is called a row
matrix.
E.X.: (3 5 2) 1x3
1/2
3
4
2x1
0
-1
3x1
23
Note: A matrix that consists of only one row is also called a row vector
and that with only one column is called a column vector.
4. Null Matrix: If every element of a matrix is zero, the matrix is called a
null matrix or zero matrix.
E.X.:
A=
0 0
B=
0 0
2x2
2x3
5. Square Matrix: A matrix with equal number of rows and columns (i.e.,
m = n) is called a square matrix.
E.X.:
A=
0 0
B=
0 0
6. Diagonal Matrix:
5 0
B=
0 2
-1
7. Scalar Matrix: A diagonal matrix in which all the diagonal elements are
equal is called the scalar matrix
E.X.:
A=
-4
0 -4
B=
24
B=
Algebra of Matrices
1. Equity of matrices: Two matrices are said to be equal if and only if
they have the same order and all their corresponding elements are equal.
When two matrices A and B are equal, we write A = B, otherwise we
write A # B.
a
-1
E.X.: We have
if and only if a = 2, b = -1, c = 3, d = 4.
2. Scalar multiplication of a matrix: If A be a matrix and k be any scalar
quantity then the product kA is a matrix obtained by multiplying every
element of A by k. Clearly the order of the product kA is the same as that
of A.
E.X.: k[a, b, c]
3. Addition of Matrices:
the same order is the matrix (A+B) whose elements are the sums of the
corresponding elements of the given matrices.
25
A=
-2
then A+B =
B=
2+4
3-1
1+3
4+1
0+2
-2+6
-1
It is clear from the definition that the sum of two matrices is defined
only when their orders are the same and also the order of the sum or the
resultant matrix is the same as that of given matrices.
Subtraction of matrices is defined similarly
E.X.: if A =
-3
and
5-2
-3-8
4-1
1-3
Then A - B =
4. Subtraction of Matrices:
B=
-11
-2
the same order is the matrix (A+B) whose elements are the sums of the
corresponding elements of the given matrices.
Properties of Matrix addition
Let A, B, C be the three matrices of the same order. Then
1. Matrix addition is commutative.
i.e., A + B = B + A
2. Matrix addition is associative.
i.e., A + (B + C) = (A + B) + C
26
Ex. 1: if A = 3
-1
B=
-1
-2
&
Verify that
1. A + B = B + A
2. A + (B + C) = (A + B) + C
3. 2(A + B) = 2A + 2B
Solution:
1)
-1
-1
2)
A+B=
B+C=
A + (B + C) =
=
and (A + B) + C =
-1
-1
-1
and B + A =
(A + B) + C = A + (B + C)
3)
27
2(A + B) =
2 3
2A + 2B = 2 3
2
2A + 2B = 6
10
-1
-2
5 + 2B = 2 0
-2
-4
10
10
12
12
&
2(A + B) = 2A + 2B.
Ex. 2: if 2A + B =
12
-3
22
&
3A 4B =
-10
21
11
find
the
matrices A & B.
Solution:
=
=
11A =
A = 1/11
48
-12
12
88
55
-22
33
99
55
-22
33
99
12
-3
22 - 2A
12
-3
10
-4
22 - 6
18
-3
-10
21
11
-2
28
Ex. 3: If A =
-5
Let B = d
1
Then, 3
=
and O =
-5
= 0
2a
2b 2c
-15
18
21
2d
2e 2f
3+2a
=
6+2b
+2
+
0+2c
6+2b=0
2c=0
B=
-3/2 -3
15/2 -9
21/2
Ex. 4: If A =
unit matrix
-1
-4
29
a1
b1
c1
Let X = a2
b2
c2
a3
b3
c3
-1
-4
2+a1
and I =
a1
a2
a3
a2
b2
c2
a3
b3
c3
-1+b1
c1
2+b2
4+c2 =
-4+a3
1+b3
5+c3
a1 = -1
b1 = 0
c1 = 0
b2 = -1
c2 = -4
b3 = -1
c3 = -4
-1
-3
-1
-4
-1
-4
= 3+a2
= a2 = -3
a3 = 4
X =
Differential Calculus
then
30
I)5
II)8ft.
III)Rs.80.
F: a b
31
The set A is called the domain of the function and the set B is called
the co-domain of the function f.
Note: Clearly for all x A, f(x) B.
Definition: If f is a function from the set A in to the set B then the set of
all images (values) of the elements of a under f is called the range of the
function f and is denoted by f(A).
That is if f: A b is a function, then
Range of f = f(A) ={f(x):x A}
Or Range of f =f (A) = {y B : y=f(x) for some x A}
Clearly the range f (A) of the function f: A B, is a subset of the codomain B that is f(A)B
The following diagram illustrates the above concepts.
A
X
x
Domain
Y=f(x)
x
Co-domain f(A)
Range of F = f (A) B
Ex: 1: Let A = {2, 5, -3, 0, -4, 7, 6, 1} and B = {5, -4, -1, 0, 4, 3, -2, 8, 6}.
Define a function f: A B by means of the following correspondence
f(2) = 5, f(5) = -4, f(-3) = -1, f(0) = -1, f(-4) = 4, f(7) = 3, f(6) = -2, f(1) = 4.
Solution:
Here every element of the set A is associated to a unique element of
the set B. Now, image of 2 under f is 5
32
Image of 5 under f is 4s
Image of 0 under f is 0 etc.
The domain of f = A
The co-domain of f = B
The range of f = f(A) = {5, -4, -1, 0, 4, 3, -2}
Note that the elements 8, 6, B are not the images of any element of
the set A.
Real Valued functions:
We know that the area of a circle depends on the radius of the circle.
Similarly the distance traveled by a moving particle depends on the time.
We say these things as the area of the circle is a function of radius and
the distance traveled by the particle is a function time. If the area of the
circle is denoted by A and the radius is denoted by r, then we know that A =
r2. To denote A is a function of r, we write symbolically as A = f(r) and
read it as A is a function of r. Similarly, if S denotes the sales volume of a
particular item and p denotes the price fixed for tat item, then S=f(p),which
denotes sales volume is a function of the price. Again the profit p is a
function of the price p, i.e., p = f(p).
Consider the function S = f(p) relating the sales volume and the price.
Here if we fix the price we can find the corresponding sales volume. Here
the value of the variable S depends upon the value of the variable p. Thus to
each value of p we associate a unique value for S, by means of the rule f
(which will be normally an algebraic in the form). Therefore in the sense of
our general definition of the function, S = f(p) define a function from a sub
set of real number to the set of real numbers. Such functions are called real
33
valued functions, as the domain and co-domain both are subsets of real
number set. A formal definition is given below.
Definition: If to each value of real variable x a unique real number y
is associated, by means of a rule f, then we say the variable y is a real
valued function of the real variable x. this we denote it by y = f(x).
The variable x is called the independent variable and the variable y is
called the dependent variable.
Thus a real valued function of a real variable is a rule which associates a
unique real number y to each real variable x.
Ex. 1: Consider y = f(x) = x2
Here to each real value of x, the function f associates its square, which is
equal to y.
If, x = 2
y = f(2) =22 = 4
If, x = -3
y = f(-3) =(-3)2 = 9
34
Let f(x) and g(x) be two real valued functions of real variable x, defined
on the same domain. Then the function f+g, f-g, f.g, f/g and k,f where k is a
real constant are defined as below.
35
ii. g(x) = 3x 4
iii. h(x) = 3x3 4x + 2
Special cases:
If the degree of the polynomial involved in the polynomial function is
one, then it is called a linear function.
Ex:
Derivatives:
= f(x)
old relation
On subtraction, we have
y = f(x + x) f(x)
Consider the ratio of the increments, y/x = f(x + x) f(x)/ x
This ratio y/x represents the average change in the variable y with
respect to the variable x, when x is changed to x + x.
Taking the limit as x 0 (ie making the increment smaller and
smaller) on both sides, we have
36
(h#0)
= 2x.
Differential Co-efficient of certain basic functions
1. Differential Coefficient of a constant function.
Consider a constant function defined by y = f(x) = c, where C is a
constant. Since f(x) is always a same constant c for different values of x,
there is no change in y. Thus the ate of change in y is zero. Therefore the
differential Coefficient of a constant is zero. This can also be seeing from
the definition.
d(c)/dx = f(x) = lim f(x+h)-f(x)/h
= lim C-C/h (f(x) = c and f(x+h)=C)
= lim 0/h = 0 (h # 0)
2. Differential Coefficient of the function y = xn, where any rational
number.
37
II)
n = , y=x 1/2 = x
dy/dx = 1/2x 1/2-1 = x-1/2
=1/2x1/2 = 1/2x
38
Linear Programming
One of the most useful applications of linear functions in business
decision making problems is that of maximizing, or minimizing, a linear
restrictions, the technique involved in solving problems of this kind is
known as linear programming. The restrictions that variables must satisfy
are usually in the form of inequalities. Therefore, before we study linear
programming as such, we must study some basic concepts of linear
inequalities.
Linear inequalities
In mathematics we come across statements of the type:
1.
2.
3.
4.
3 is less than 5
14 is greater than 9
a is less than or equal to 6
a is greater than or equal to 5.
39
40
41
Machine
(In hours)
6
8
12
8
4
4
A
B
C
Maximum time
available
(in hours)
380
300
404
x =10, y = 40
y =10, x = 50
42
x = 0, y = 75
y = 0, x = 37.5
100
90
80
70
60
50 D
40
30
20
10
0
10
20
30
A40
50
60
70
80
From the graph it is clear that the region (shaded area) AABCD is the
feasible region. The verticals of this region are
A(101/3, 0), B = (26, 23), C = (22, 31)and D = (0, 47.5)
Substituting for x and y , in the objective function, from these points
we obtain the maximum value of P at C(22, 31).
43
Cost / gmof
1 gm of each product
Vitamin V1 Vitamin V2
Vitamin
each product
Product M
Product N
Minimum daily
6
2
12
2
2
8
V3
4
12
24
20 Paise
16 Paise
requirement of
each vitamin
Find the least expensive combination, which provides the minimum
requirements of the three vitamins.
Solution:
Let the mixture of two products M and N contain x gms. of product M
and y gms. of product N. the objective function is the total cost (in paise) of
the mixture and it is obtained as C = 20x + 16y
We must minimize C subject to the constraints
6x + 2y 12
2x + 2y 8
44
4x + 12y 24 & x 0, y 0.
1) Draw the line 6x + 2y = 12.
Put
x =0, y = 6 & y = 0, x = 2
x = 0, y = 6 & y = 0, x = 4
x = 0, y = 2, y = 0, x = 6.
FEASIBLE REGION
1
0
A
1
Cb
45
Cc
Cd
C PROGRAMMING
&
46
DATA STRUCTURES
Contents
1. C Up to pointers & Data Structures.
Data Structures:
1. Arrays
2. Linked Lists
3. Stacks
4. Queues
5. Introduction to Trees (Numerical Oriented Analysis)
INTRODUCTION
The term problem is used to mean a task or job. Problem solving implies carrying
through the task to arrive at the right solution.
47
Problem Solving Using Computer can be broken down into Three major steps:
1. Problem Analysis.
2. Problem Solution (Design of the Program)
a. Algorithm.
b. Flowchart.
3. Computer Solution.
a. Coding
b. Testing and debugging
c. Documentation and maintenance.
ALGORITHM:
An algorithm is a step by step procedure to solve a given problem; it is English
like language.
FLOWCHARTS:
A flowchart is a visual or graphical representation of the step by step introduction
of any problem. It indicates the process of solution.
CODING (Programming):
ONCE the problem has been analyzed it must be coded in a language which the
Computer can understand. This code is called a program, in other words coding is just
the translation of algorithm into a suitable Computer language.
DEBUGGING:
The process of identifying and correcting or removing the bugs or errors is called
debugging.
TESTING:
Testing a program for correctness is a necessary part of creating a successful
computer solution to a given problem.
DOCUMENTATION:
Documentation is the process of writing explanation about the program in the
form of comments and remarks. Documentation only is divided into two categories
48
namely Technical documentation and user level documentation.
The Technical
documentation is meant for the programmer, who may try to modify the program and it
includes information about the formula used data and programs imported from other
programs, developed by different programmers. The user level documentation helps the
users who may not be programmers, to understand the program and to make use of the
program.
PROGRAM MAINTENCNCE:
It means Periodic review of the programs to ensure that it meets the revised needs
of the organization. A lot of time and money can be saved if attention is paid to
maintenance of the programs which is continuous task.
PSEUDO CODE:
Pseudo code is another notation for expressing an algorithm. An algorithm is a
combination of Computer instructions and English.
CATEGORIES OF PROGRAMMING LANGUAGES
1.
2.
3.
4.
Machine Language
Assembly Language
High Level Language
Fourth Generation Language
MACHINE LANGUAGE:
The language which can be understood by the computer is called a machine level
language. It consists group of binary numbers.(that is 0s and 1s). The processor can
directly understand the machine.
ASSEMBLY LANGUAGE:
The next level lf programming language is assembly language. They are also
classified as low level languages because detailed knowledge of hard ware is required.
This language uses mnemonics in place of 0s and 1s to represent the operation codes.
HIGH LEVEL LANGUAGE:
The language which can be understood by the user is called high level language.
It is a collection of alphabets, numerals and special characters.
49
The lists of High level languages are as follows:1.
2.
3.
4.
5.
6.
INTRODUCTION TO C PROGRAMMING
LANGUAGE:
C is a powerful flexible language that has gained word wide acceptance in
recent years. C is concise yet powerful in its scope it is a high level language that also
incorporates features of low level languages. It is becoming the standard for program
development on small machines and micro computers.
ORIGIN OF C:
C was originally developed by Dennis.M.Ritchie in the early 70s at AT &T.
Bell labs it was created at the time when Ken Thompson & Dennis M Ritchie were
designing the Unix operating System.
50
APPLICATION OF C:
The capability of C language to work at machine level, makes it well suited for
systems programming.C is used for writing.
a)
b)
c)
d)
e)
f)
g)
h)
Operating Systems
Compilers
Interpreters
Assemblers
Editors
Database Managers
Spread Sheets
CAD and animation.
This is the main function and Compiler starts executing from here.
------------ ;
------------ ;
------------- ;
IDENTIFIERS:
It is a collection of characters, which is used to identify a variable or constant or
function identifier. It is user defined word.
VARIABLE:
Is one, whose value changes during the execution of the program.
CONSTANT:
Is one, whose value does not change during the execution of the program.
KEY WORDS or RESERVED WORDS:
All key words have predefined meanings and these meanings cannot be changed.
int
auto
long
void
float
if
while
do
struct
goto
static
for
const
51
SIMPLE DATA TYPES
int (integer) :
This data type is used to store only the integers 0 9. Without a decimal point.
Eg:
char (charcter):
Character data type is used to store only the characters
Eg:
char grade = A;
float (real):
It is used to store the numerals with decimals.
Eg:
INPUT STATEMENT:
Scanf (data type format, address of the variable);
Data Type
Format
Character
%c
Integer
%d
Float
%f
String
%s
ADDRESS:
It is a memory location number (byte number) using an address we can access the
value of that address.
Eg:
char grade;
scanf (%c, &grade);
It accepts a grade from the keyboard and it stores the accepted grade in grade
variable.
Eg:
int age;
scanf(%d, &age);
It is used to accept an integer. the accepted integer will be stored in a age variable.
Eg:
float salary;
scanf(%f, &salary);
52
It is used to accept a float value. the accepted float will be stored in a salary
variable.
Eg:
char name[25];
scanf(%s, &name);
It is used to accept a string. the accepted float will be stored in a name variable.
char grade = A;
printf(Your grade is %c, grade);
Special Characters.
\n
\t
53
# include <stdio.h>
main() {
int age;
char grade;
float salary;
printf(\n Enter age:);
scanf(%d, &age);
printf(\n Enter grade);
scanf(%c, &grade);
printf(\n Enter salary);
scanf(%f, &salary);
printf(\n Enter name);
scanf(%s, name);
printf(\n name is %s\ t age is %d \n
salary is %f \t, grade is %c,
name, age, salary, grade);
}
COMMENT ENTRIES:
These entries are not executable lines. Comment entries will be ignored by the
compiler.
/*
*/
CONTROL STATEMENTS:
1. If statement
2. Switch statement
If Statement: This is used to check one or more conditions.
Syntax:
if (condition)
statement 1;
else if (condition)
54
statement 2;
else
statement n;
Program 2: Write a program to accept the average marks and check the result.
If
Marks > 79
Distinction
Marks > 59
First class
Marks > 49
Second class
Marks > 34
Pass class
switch (expression) {
case value 1: statement_list;
break;
case value 2: statement_list;
55
break;
:
:
default
: statement_list n;
break;
}
Program 3: Write a program to accept day number of the week and display the
corresponding week day.
# include<stdio.h>
main () {
int dayno;
printf(%d, &dayno);
switch(dayno) {
case 1: printf(Sunday);
case 2: printf(Monday);
case 3: printf(Tuesday);
case 4: printf(Wednesday);
case 5: printf(Thursday);
case 6: printf(Friday);
case 7: printf(Saturday);
default: printf(Invalid day number);
}/* End of the Switch*/
} /* End of the Program*/
LOOPING STATEMENTS:
1. The while loop
2. The do-while loop
3. The for loop.
56
The above statements are repetitive statements. To repeat the specified number of
times.
Initialization;
Syntax:
while (condition)
{
Re-initialization;
}
Initialization;
do
{
Re-initialization;
} while (condition);
for(initialization; condition; re-initialization)
{
}
Program 4: Write a program to accept age, name and fees and display the age 10 times,
name 15 times and fees 30 times? Name 15 times and fees 30 times?
Program:
# include <stdio.h>
main( ) {
int age, count;
char name[15];
float fees;
printf(\n Enter age: );
scanf(%d, &age);
printf(\n Enter name:);
scanf(%s, name);
printf(\n Enter fees);
scanf(%f, &fees);
57
while(count<10) {
printf(%d, age);
count = count+1;
}
count = 0;
do {
printf(\n %s, name);
count = count+1;
} while(count<15);
for(count=0; count<30; count=count+1) {
printf(%f, fees);
}
}
Pointers: Pointer is a variable which contains the address of some other variable.
Eg:
int x, *p;
x = 50;
p = &x
x variable
50
p pointer
1001
1001 address
The address of x is 1001, which is stored in the pointer P, using p we can access
the value of the pointer.
&p Gives the address of the variable x
p Gives the address of the pointer
*p Gives the value of the pointer.
Printf(The value of x is %d, x);
58
main() {
int x, y, *p1, *p2;
printf(\n Enter any two integers:);
scanf(%d, &x);
scanf(%d, &y);
p1 = &x; p2 = &y;
printf(\n The sum of 2 integers is %d,*p1+*p2);
printf(\n The difference of 2 integers is %d, *p1 - *p2);
printf(\n The product of the 2 integers is %d, *p1**p2);
}
Program 6: Write a program to accept a name and print character by character on a
separate line.
Note: String is a collection of characters at the end of every string there will be a string
terminator called a NULL character (10 or NULL)
#include<stdio.h>
main( ) {
char name[25], *p;
printf(\n Enter a name :);
scanf(%s, name);
for(p=name; *p !=NULL; p++) {
printf(\n %c, *p);
}
}
FUNCTIONS
Function is a collection of statements to achieve a particular task. A function can
take any input and it can give any output.
Eg:
59
Address() {
printf(Dr. V. Ramprasad);
printf(Director);
printf(Surana College);
printf(Bangalore);
}
Program 7: Write a program to display the address by using a function.
#include<stdio.h>
main() {
address();
}
Address() {
printf(Mr. L. Manjunatha Rao);
printf(Co-ordinator);
printf(Surana College);
printf(Bangalore);
}
Passing parameters from main function to the sub function
There are two ways of passing parameters
1)
call by value
2)
Call by reference
Call by value:
Sending the actual values from a main function and receiving the same values in
the sub-function. While receiving the values either we can receive through the same
variable names or different variable names.
Program 8: Write a program to accept any 2 numbers in the main program and pass the
same 2 numbers to the sub function and print the sum, difference of product in the sub
function.
#include<stdio.h>
60
main( ) {
int num1, num2;
printf(\n Enter an 2 numbers);
scanf(%d, &num1);
scanf(%d, &num2);
calculate(num1, num2);
}
calculate (x, y) int x, y; {
printf(\n the sum of 2 nos %d, x+y);
printf(\n The difference of the 2 nos. %d, x-y);
printf(\n The product of the 2 nos. %d, x*y);
}
Call by Reference:
Sending the actual address of the variables (memory locations) and receiving the
address through pointers is called call by reference.
Program 9: Write a program to accept any 2 numbers in the main program and pass the
address to the sub function and print the sum, difference of product in the sub function.
#include<stdio.h>
main( ) {
int num1, num2;
printf(\n Enter an 2 numbers);
scanf(%d, &num1);
scanf(%d, &num2);
calculate(&num1, &num2);
}
calculate (x, y) int *x, *y; {
printf(\n the sum of 2 nos %d, *x+*y);
printf(\n The difference of the 2 nos. %d, *x-*y);
printf(\n The product of the 2 nos. %d, *x**y);
}
61
Program 9: Write a program to accept an integer and find the square in the sub function
and return the square to the sub function.
#include<stdio.h>
main ( )
{
int num,sq;
printf(\n Enter a number );
scanf(%d,&num);
sq=square(num);
/* square function calculates the square of the number and its assigns the square
to the sq variable */
printf(\n %d to the square is %d,num,sq);
} /* End of the main function */
square (x)
int x;
{
return x*x;
}
/* the function calculates the square and it returns the main program*/
Program 10 : Write a program to accept a character, if it is an alphabet convert the
same alphabet into the other case in the sub function, and print both in the main program.
# include<stdio.h>
main( )
{
char ch,con;
char convert(); /* function declaration */
printf(\n Enter a character );
scanf(%c,&ch);
62
con = convert(ch);
printf(\n The entered character is %c,ch);
printf(\n the converted character is %c,con);
}
char convert(rc)
char rc;
{
/* where rc is a recived variable */
if(rc >=A && rc <=Z)
return rc + 32;
else(rc > a && rc <= z)
return rc 32;
else
return rc;
63
INTRODUCTION:
Data structures are fundamental to computer programming in any language. A
data structure is a representation of data in a program. A data structure is a systematic
way of storing, organizing, manipulating and accessing the data stored in the memory of
a computer. In this chapter the principles for the design and implementation of good data
structure is given briefly which forms the frame work for developing the computer
solutions to some of the important problems.
This section revels you a brief introduction to data structure.
1. Create operation:
This operation creates the data structures .we can create the data structure in two
ways, during compile time and during run time.
Data structure created during compile time is called the static allocation.
For example: int x, float y, char z etc,
Here the memory for x, y, z will be allocated statically during compile time.
Similarly data structure created during run time is called Dynamic Allocation. For
creating the data dynamically in C language we use a function called malloc () which
is defined in a header file called alloch.h. In C++ we use a function new () for the same
operation. In dynamic allocation memory will be allocated for the variables during run
time or execution time.
2. Destroy operation:
This operation destroy the data structures created using create operation. This is
not a necessary operation. If the data is created statically then this static data will be
active as long as the control is there within the block in which it is defined, If the control
comes out of the block the data will be automatically destroyed. Similarly if the data
created dynamically is to be destroyed then we use a function called free () in C and
delete () in C++.
64
3. Selection operation:
This operation is to select which data structure to use to solve a particular
problem.
E.g.: Some problems need arrays and some needs structure or unions
4. Updation operation:
This operation changes the contents of data structure as and when needed. Best
example for updation operation is the assignment statement.
Int x=6;
X=x+1;
5. Sorting operation:
Arranging the elements stored in the data structure either in ascending order or in
descending order.
6. Searching operation:
Finding a particular element stored in the data structure.
65
A Linear data structure is the one, which place the relationship of adjacency
between the elements. Ex: Arrays, lists,stacks and Queues
In a data structure if it is possible to derive any relationship other than adjacency
relationship then it is called Non-linear data structures. For ex: Trees & Graphs.
There are other criteria for judging programs that have more direct relationship.
These have to do with computing time and storage requirements of the algorithms. These
are the two parameters on which the efficiency of the algorithm is measured. Now days
no body bothers about space complexity because memory is very cheap. So time is the
only criteria for measuring efficiency of the algorithm.
Example :
i.
x=x+1;
ii.
for(i=1;i<n;i++)
x=x+1;
iii.
for(i=1;i<n;i++)
for(i=1;i<n;i++)
x=x+1;
This complexity of algorithm M is the function of f(n), which gives running time
of the algorithm in terms of the size of the input data.
66
Big O-Notation
The big O-notation helps to characterize the asymptotic time or space requirement
of running algorithms. This allows us to talk about the complexity classes of the
algorithms. This allows us to talk about the complexity classes of the algorithms.
Defination: We say that f(n) is O (g (n)) if there exist two positive constants K and n
such that | f(n)| <= K | for n>n O-notation gives an asymptotic upper bound for a function
within a constant factor K ( g (n)).
67
Arrays:
Array is a structured data type consisting of a group of components, each
component is of the same type and same name. For example, suppose we wish to find the
largest of group of numbers. If there are a few numbers, then we can solve this problem
by using nested IF statements. Each IF statement would compare two numbers. However
suppose there are 1000 numbers to consider. A set of 10000 IF statement would be very
impractical, as we would have to declare 2000 integer variables:
int num1, num2, num3..num10000;
What we would like to do is group these numbers under one name, say number, and
access the individual components of the group as number[1],number[2],and so on,upto
number[1000]
15
123
46
245
..
..
Number[1]
Number[2]
Number[3]
Number[4]
.
.
Number[1000]
35
Declaration of Arrays
Like any other variable, array must be declared before they are used. We declare
an array by giving the type of its elements, its name, and the number of elements.
General form of array declaration is
Type variable name [size];
Example:
int A[100];
68
Float height[60];
Char name[10];
A height and name are the Array names, A [100], height [60], name [10] are the
elements of array.
When the elements of an array have single subscript, the array is called a Linear
or One-dimensional array or a List or a Vector.
Types Of an Array:
Single Dimensional Array
Two Dimensional Array
Multi dimensional Array
A[01]
A[0,2]
A[1,1] A[1,2]
A[2,1] A[2,1]
69
header
0
0
col 0
2
4
A[0][0]
A[1][0]
col 1
col 2
col 3
A[2][0]
104
A[0][1]
106
A[1][1]
108
A[2][1]
A[0][2]
110
112
A[1][2]
114
A[2][2]
116
A[0][3]
A[1][3]
A[2][3]
col 4
100
102
A[0][4]
118
120
122
A[1][4]
124
126
A[2][4]
128
int a[3][5]=n x m
Location of any element is given by
A[i][j]=L0 + (i * m +j) * c
L0=base
m=column(max)
n=row
c=size of element
i=required row
J=required column
70
In column major order elements are stored in the following manner:
0
0
col 0
A[0][0]
A[1][0]
col 1
col 2
col 3
100
102
104
A[0][1]
106
A[1][1]
108
A[2][1]
A[0][2]
110
112
A[1][2]
114
A[2][2]
116
A[0][3]
A[2][3]
}header
A[2][0]
A[1][3]
col 4
2
4
A[0][4]
118
120
122
A[1][4]
124
126
A[2][4]
128
71
header
0
0
2
0
2
A[0][0][0]
row 0
A[0][0][1]
A[0][0][2]
A[0][0][3]
A[0][1][0]
row1
A[0][1][1]
A[0][1][2]
A[0][1][3]
row0
plane
row
column
100
102
A[1][0][0]
A[1][0][1]
104
106
108
110
112
114
116
118
int a[3][2][4]
Stacks:
A stack is an ordered collection of data items in which the items may be inserted
and deleted at one end called the Top of the stack. Stack works on the principle of last in
first out[LIFO], ie the last element inserted will be the first element to be removed. Top
pointer always points to the top of the stack. The pictorial representation of stack is given
below.
72
Stacked trays
Operations On Stack:
Mainly there are two operations that we can perform on the stack. They are:
Push
Pop
Push means putting the elements onto the stack or inserting the element on to the
stack. Pop means removing the elements from the stack. Both push and pop operation
must be done from the top of the stack. When there is no element in the stack then top
will be pointing to zero. Stacks can be implemented by using an array and by using
linked list.
73
The first step of this algorithm checks for an overflow condition. If such a
condition exists, then the insertion cannot be performed and an appropriate error message
results.
Application of Stack:
Application 1: Recursion:
A function calling itself again and again is called recursion. In a recursive
function termination condition is a must. If you wont specify the termination condition
the program will go to infinite loop. Starting from the problem domain as a go on carry
the function again and again you will be moving towards the solution domain. Using
recursion can easily solve some of the worlds most complicated problems.
74
+AB
AB+
75
press the PLUS(+) key, then 200, and press the EQUAL(=) key. In contrast, many
calculators use postfix notation, in which both operands are entered first and then the
operator is entered. As operands are entered, they are replaced on stack.
Queues:
Another fundamental Data structure is the queue. It is a close Cousin of stack.
It works on the principle of First In First Out [FIFO]. That is, what ever the element
enters into the queue first that will be the first element removed from the queue. Queue
maintains 2 pointers called Front and Rear.
Front Pointer -
Rear pointer
Rear
AA
1
Deletion
Front =1
Rear=4
BB CC DD
2
7
8
insertion
9.N
76
77
Types of Queue:
Linear queue
Circular queue
Dqueue
Priority queue
Circular queue:
In a linear queue even though the memory available in the array, if the rear
pointer touches the end of the array overflow will occur. Instead of having the
program stop when the limit of the array used to store the queue is reached , you
could have both REAR index and FRONT index loop back to the array. In this
way, any number of items could be placed on the queue, so long as items were
also being taken off. This type of implementation of queue is called Circular queue
because it uses its storage array as if it were a circle instead of linear list.
78
79
If F = 0
then F 1
Return.
80
AA
Insertion
Deletion
Rear
BB CC DD
Deletion
81
Priority Queues
A queue in which we are able to insert items or remove items from any position
depending on some property is called priority queue. The given figure represents a
priority queue of jobs of supervisor(S), teachers(T),students(ST),and outside(O) users,
respectively. Therefore, if a job a job is initiated with priority P, it is inserted immediately
at the end of the queue of other jobs with priority P, for P =1,2,3 and 4. Here in the
present example jobs are always removed from the front of the queue.
Front (s) Rear (s) Front (T)
S1
S2
Sn
T1
T2
Tn
ST1 ST2
STn O1
O2
On
.
1
2
3
Priority Queue
In general way, we can say that a priority queue is a series of queues representing
situations in which it is known as prior what priorities are associated with queue
elements. The below figure represents how the single priority queue can be visualized as
four separate queues; each follow FIFO principle. The elements in the second queue are
removed only when the first queue is empty, elements from the third queue are removed
only when the first and second queues are empty and so on.
Priority 1
S1
S2
S3
Front(S)
Priority 2
T1
T2
Front(S)
Priority 3
SN
Rear(S)
T3
TN
Rear(S)
82
ST1
ST2
Front(S)
ST3
STN
Rear(S)
Priority 4
O1
O2
O3
Front(S)
ON
Rear(S)
Applications of Queue :
Application 1: In a computer network messages from one computer to another are generally
created synchronously. These messages need to be buffered until the receiving computer
is ready for it . These communication buffers make use of queues by storing these
messages in a queue. Also the messages need to be sent to receiving computer I the same
order in which they are created.
Application 2: Queues are used in timesharing system in which programs form a queue
while waiting to be executed.
Application 3: The most common use of circular queue is in operating system.
83
Linked Lists
Introduction:
We have understood the concept of arrays, which is an example of linear data
structure. If we try to implement the stacks or queues which are crucial for the
development of any application, with the help of arrays, we will be unable to handle the
following situations:
1. If the size of array is less and the elements to be inserted (push in the case of stack
and insert in the case of queue) are more, then there will be overflow of items in
many cases handling of which itself will be a tedious task.
2. If the size of array declared is large and the elements to be inserted are less then
there will be wastage of memory, which will be overriding the implementation of
data structures.
3. At run time, the size of stack or queue cannot be increased.
To overcome all these disadvantages of arrays, we have another type of data stucture
called Linked Lists.
A Linked List is a special type of data structure, which consists of information
and linkage as its 2 main parts and which allows the user to create and allocate
memory at runtime.
A general structure of linked list can be shown as follows:
Information
Link
Here the information part stores the data to be stored in the node. Information part is
very similar to the individual elements in the general array. Next part is the link part
which is a pointer and which can point to an object of the type node which again
consists of Information and Link. This part makes the linked list superior compared to the
linier array elements. If we consider one node in a linked list of the above structure, then
the link part of the node stores the address of another node which is preceding to it (and
succeeding to it). With help of this pointer, the user can move to another node whose
address is stored in the link part of the current node. Due to the existence of link (pointer)
in the node, user can create a new node and store the information to be stored in it and
store the address of the new node in another node after / before which the newly created
node should exist. As another advantage, the user can create the nodes at run time where
ever the memory is available on the primary memory of the system.
Since it is a List the first element (node) is called the Head pointer which stores the
address of second node in the link part, which in turn stores the address of the third
node in its link part and so on the last node of the linked list will contain the
84
information in the information part and the link or the pointer points to null which
means that it will not points to any other node and it itself is the last node of the linked
list.
Types of linked lists:
1. Singly Linked List.
2. Doubly Linked List.
3. Circular Singly Linked List.
4. Circular Doubly Linked List.
(1) Singly Linked List: Here each node consists of one or more information part(s)
and one link part which will always points to another node which will come after
the current node. Thus the general look of a singly linked list can be given as
follows:
Head
*50
10
20
*120
*100
70
30
*110
40
*90
NULL POINTER
As the above figure shows, there are 5 nodes each consisting of one numeric information
part and one link part. The information part stores the numbers accepted and the link part
stores the address of the next node. Explanation for the above linked list is as follows:
1. The first node consists of 10 in information part which is called information
stored in that node and 100 in its link part which is the address of the next node.
2. The second node consists of 30 in information part which is called information
stored in that node and 110 in its link part which is the address of the next node.
3. The third node consists of 40 in information part which is called information
stored in that node and 90 in its link part which is the address of the next node.
4. The forth node consists of 20 in information part which is called information
stored in that node and 120 in its link part which is the address of the next node.
5. The first node consists of 70 in information part which is called information
stored in that node and blank in its link part which means that this is the last node
of the linked list and this node will not point to any memory address in the main
memory of the system.
85
Doubly Linked List: This is another type of Linked List where in there is one or more
information part(s) and 2 linked parts, one called the left link and another called the
right link.
The left link will store the address of the left node or the previous node ( which is
nearer to the head compared to the current node) and the right link will store the address
of the right node or the next node (which is farther from the head compared to the current
node).
100
*10
*5
200
*20
*5
*10
300
Circular Singly Linked List: This is special type of singly linked list where in the link
part of the last node will store the address of the head node. This can be represented as
follows:
30
*20
20
*30
*10
56
*60
88
40
*50
*40
50
Circular Doubly Linked List: This is a derived type of doubly linked list where in the
left link of the head node will store the address of the last node and the right link of the
last node will store the address of head node. The diagrammatic representation follows:
HEAD
*60
100
*20
*30
200
*10
*40
300
*20
*50
600
*10
*40
500
*60
*30
400
*50
86
Operations with linked lists:
Some of the operations with the linked list are:
1) Creation of Linked List.
2) Insertion of free node to Linked List.
i. Insertion at the beginning.
ii. Insertion at the given position.
iii. Insertion at the end.
3) Deletion of node from Linked List.
i. Deletion of the head node.
ii. Deletion of the node at given position or with the given data.
iii. Deletion of the last node.
4) Display the contents of the Linked List starting from the head node to the
last node.
TREES:
A tree is an abstract data type that stores elements hierarchically. With the
exception of the top element, each element in a tree has a parent element and zero or
more children elements. A tree is usually visualized by placing elements inside ovals or
rectangles and by drawing the connections between parents and children with straight
lines. Computer scientists typically call the top element the root of the tree, but it is
drawn as the highest element, with the other elements being connected below.
a
Properties of a Tree:
A tree T is a set of nodes storing elements in a parent-child relationship with the
following characteristics
1. T has a distinguishable node r, called the root of T
2. Root doesnt have any parents.
3. Each node v of T distinct from r has a parent node u.
87
4. for every node v of T, the root r is an ancestor of v.
BINARY TREE:
A binary tree is an ordered tree in which each internal node has either zero or two
children. In a binary tree the first child of an internal node is called left child and the
second child is called the right child. The subtree rooted at the left and right child of a
node is called left subtree and right subtree respectively.
root
a
b
c
left
right
child
child
If A is a root of the tree and B and C are left and right child of the tree then
A is said to be the father and B and C are said to be the left son and right son
of A respectively. The node that has no sons is called leaf node.
ANSISTER:
Node n1 is called the ansisister of n2 if n1 is the father of n2 or father of
some ansisters of n2.
n
1
n
2
n
2
n
1
siblings
n
1
n
3
n
d3
left son
n
0
n
p
right son
n
2
Siblings:
Two nodes that are the children of the same parent are called siblings.
father
n
3
88
DEPTH OF A TREE:
The depth of a node M in the tree is the length of the path from the root of the tree to M.
HEIGHT OF A TREE:
The height of a tree is one more than the depth of the deepest node in the tree.
SEQUENTIAL REPRESNTATION:
In sequential representation arrays are used to store the binary tree. The nodes of a
complete binary tree may be completely stored in one-dimensional array TREE with the
nodes numbered I being stored in TREE (I).
The following rules shows us how to easily how to easily determine the locations of the
parent, left and right child of any node I in the binary tree without explicitly storing any
link information.
n
2
n
1
n
3
89
For e.g.:
consider the following binary tree
1
A
C
D
5
E
Here nodes are numbered according to full binary tree. The number of nodes in a full
binary tree of level 3 is
representation
1
2
A
3
B
4
-
5
D
6
-
7
E
90
3. Right link field
Information field gives the information about the data item. Left and right
links are the pointers, which contains the memory address of the left and
right sub tree of anode N respectively. Root is a pointer variable contains the
address of the root node.
A
B
R
E
Binary Tree
Nu
*
*
Nu
Nu
Nu
Nu
Nu
Nu
Nu
91
Any process of visiting the nodes of a binary tree in some order is called a traversal.
There are three tree traversal methods,
1.Inorder traversal
2.preorder traversal
3.postorder traversal.
The inorder traversal of a binary tree is given by the following steps.
1. Traverse the left subtree in Inorder.
2. Process the root node R.
3. Traverse the right subtree in Inorder.
The preorder traversal of a binary tree is given by the following steps.
1. Process the root node R.
2. Traverse the left subtree in Preorder.
3.Traverse the right subtree in preorder.
The postorder traversal of a binary tree is given by the following steps.
1. Traverse the left subtree in Postorder.
2. Traverse the right subtree in postorder.
3. Process the root node R.
For example consider a Binary tree T as shown in the below figure:
92
Postorder Traversal of the above tree is: XYDFBTOPLCAQ
93
SYSTEMS PROGRAMMING
Contents
1. Operating Systems Case Studies
Windows/Unix From User Level Point.
2. Compilers
3. Assemblers.
94
[Windows (Graphic User Interface) UNIX, (from users and machine point of view)
Role of Compiler & Assembler]
Operating System:
An operating system is collection of programs that coordinates the operation of
computer hardware and software
Accounting
Communicatio
n
Security
Input /
Output
Operating
System
Functions
Time
Sharing
Command
interpreter
Data
Management
Program
developm
ent tools
Input /Output:
Input and output is essential to the operation of any computer. I/O allows the
computer to store and retrieve data on disk or tapes, to interact with the users terminals,
and to print output on paper every operating system must provide some form of I/O.
Command Interpreter:
The command interpreter reads the command of a user type in at a terminal and
changes, or interprets, them into instructions the computer can understand. Command
interpreters vary widely from one operating system to another, but again, it is something
that almost everyone provides.
Data Management
Data management allows the user to organize their data into logical grouping
called Files. Although not all operating system provide data management, the few that do
not are severely limited in their flexibility and usefulness.
95
Time Sharing:
Time-sharing is a way of allowing several people to run programs on different
terminals at the same time. This feature is usually found only on larger operating systems.
Security:
Security protects one user from another and operating system from all users. Its
main function is to make sure only authorized users access the computer and its data and
those users do only things they are authorized to do. Most operating systems that dont
have time-sharing have little or no security, since only one user is involved. Most large
operating systems provide some measure of security, but the degree varies from one to
another.
Communication:
Communication refers to the ability of one computer to communicate with other
computers and terminals to transfer programs and/or data.
Accounting:
Accounting keeps track of what each person had done on a computer in order to
bill each one for the resources used. This is necessary on computers that have many users
who must be charged on computers that have many users who must be charged for their
use of the machine.
96
a)
b)
c)
d)
Layered Structure.
Kernel Structure.
Virtual Machine.
Client Server structure.
Layered Structure:
In a layer structure operating system consists of several layers. Each layer built on
the top of lower layers. The bottom layer is hardware, and top layer is user interface.
5
4
3
2
1
0
User Interface
Buffering for I/O devices
Device Drivers
Memory management
CPU scheduling
Hardware
The main advantage of this approach is modularity which helps in debugging and
verification of system. A layer can uses operation and services of layer a below it also a
higher layer need know how these operations are implemented. The major disadvantage
with this approach is to differentiate between two layes, since a layer can use services of
layer below it.
Kernal Approach:
97
Note: UNIX is based on Kernel approach and consists of two separate parts.
User Programs
Commands & Utilities
Kernel
Hardware
Shell
The Kernel supports the file system , Process scheduling and other operating
systems through a set of system calls.
User Interaction With the Operating System::
Operating system is an essential component of a computer system. It may define as a
collection of programs used to manage system resources such as memory, processor, I/O
devices etc. It keeps track of each of these resources, for how long and when.
Processor Management: Operating system is responsible to allocate different
processes to processor .It decides how long these processes utilize and finally
deallocate it.
Memory Management: Operating system associates the appropriate memory of
user program and other data; memory protection and sharing are also managed by
operating system.
File Management: Operating system is responsible to stored users file to
different storage devices. File manager (OS) also responsible for protection and
transfer of these files from one location to another.
98
I/O management: Operating system (OS) establishes a co-relation among all I/O
devices connected with system.
User
Application Program
System Utilities
Operating System
Computer
hardware
99
The UNIX operating system can be broken down into three basic components: the
scheduler, the file system, and the shell.
The UNIX Scheduler
The UNIX scheduler is a program that allows more than one person to all, use the
computer at the same time. The scheduler shares computer resources among these' users,
allowing each a small slice of the computer's processor. As mentioned before, this
concept is known as time-sharing.
For example, suppose three people want to run different programs, a, b, and c.
The scheduler copies these three programs from the disk that stores programs into the
computer's memory. In the UNIX system, these copies in memory are referred to as
processes; in this way we make the distinction between programs that is kept in a file on
the disk and a process that is in memory doing things.
The scheduler allows process a to run for a few hundredths of a second and do a
little of the work it was designed to do. After this time slice is over, process a is
temporarily stopped, or suspended, and process b is allowed to run. Later, when process
b's time slice is over, process c gets its chance to run. When each has had a chance to run
a while, the scheduler comes back to process a. It doesn't start a over at the beginning;
instead, it starts a where it left off when it was suspended at the end of its time slice. In
this way, the scheduler allows each process to work its way to completion, a little bit at
time.
a
Time slice 1
Time slice 2
Time slice 3
Most time-sharing systems allow many more than three processes to run at the
same time; in fact, the UNIX scheduler can keep track of several hundred processes. It
also allows each user to effectively run more than one processor at a time. Due to high
speed of computers the overall effect of time sharing is to give the users the impression
that they are all being served simultaneously, Evan though the scheduler servers them
one at a time.
Swapping
This simple model of scheduling works fine at first, but sooner or later all of the
computer's memory gets filled with running processes. At this point, if answer wants to
run a process, the scheduler must find a way to fit it in.
100
This brings up the concept of swapping. When memory is full and a new program
needs to be run, the scheduler takes a process in memory and copies it to a disk. The
scheduler then places the new program in memory (creating a new process) and allows it
to run. Later, the process copied to disk is swapped with one of the processes in memory
i.e , the process in memory is copied to disk, and the process on the disk is copied back
into memory.
MS-WINDOWS:
Microsoft resembles an operating system, an integrated package
and an extension of DOS. However, benefit it is much more than all
these. It is one of the most popular GUI that supports some standardized
methods. Features of windows are
(i)
101
Activating windows : You may open more than one window simultaneously.
However, only one window can be active at any moment. To activate a
particular window , you just click on that window through mouse.
102
Application icons represent applications that were started and then minimized group
icons represent minimized group windows
(iii)Dialog Boxes : A dialog box appears when you have to supply some additional
information before a command can be executed. These are much more flexible than
menus containing a group of child windows such as a buttons, scroll bars etc.
Assembler
An assembler is a program that accepts as input, an assembly language program and produces its machine
language or the object code executable by the machine.
Assembly language
Program
Assembler
Object code
1. Isolate the label, mnemonic operation code and operand field of a statement.
2. Enter the symbol found in label field and address of next available machine
word into the symbol table.
3. Validate the mnemonic operation code by looking it up in the mnemonic
table.
4. Determines the memory requirements of statement by constructing the
mnemonic operation code and operand field of the statement.
Synthesis phase:
103
Pass I
source
Pass II
target program
program
Intermediate
code
Design of a Two pass Assembler:
PassI:
1.
2.
3.
4.
PassII:
1. Synthesize the target program.
Multi-pass assembler:
104
In each pass it is necessary to process every statement of the program which
causes certain duplication in actions performed by each pass. In order to reduce such
duplication, result of analyzing a source statement by 1st pass is represented through an
intermediate form called Intermediate code.
Due to construction and process of intermediate code a multi-pass translator
would function slower than a single pass translator.
COMPILER
The compiler is the one which takes the source code as input and produces machine language code as output of the
machine on which it is to be executed. The important aspect of compilation process is to produce error messages in the source
program.
Source program in
Higher level languge
compiler
Target program
Error Messages
Functions of compiler:
1. Scans the entire program first and then translates it into machine code.
2. Converts the entire program to machine code; when all the syntax errors are
removed execution takes place.
3. Slow for debugging.
4. Execution time is less
Compiler Designing phases:
The compiler being a complex program is developed through several phases. Each
phase transforms the source program from one representation to another.
The tasks of a compiler can be divided very broadly into two sub tasks.
The analysis of a source program.
1. The synthesis of the object program.
The analysis task consists of 3 phases.
1. Lexical analysis
2. Syntax analysis
3. Semantic analysis
105
Source program
Lexical analysis
Syntax analysis
Symbol table
Semantic analysis
Code generation
& optimization
Lexical analysis:
1.
2.
3.
4.
5.
parse
tree
Rest of phases
object
code
106
Semantic analysis:
Symbol table
tokens
parse tree
Syntax analysis
Semantic analysis
Symbol table
Code generation
& optimization
107
COMPUTER ORGANIZATION
Contents
1. Bits & Bytes.
2. Number Representation
3. Arithmetic Operation
4. Memory
5. Logic Circuits
6. ALU & Control Units.
Computer Organization
CONTENTS:
1. Number system and Boolean algebra, logical gates, combinational logic circuits (half
adder, full adder, adder subtracted, multiplexer, de-multiplexer, encoder and decoder
sequential logic circuits (flip-flops, RS, D, JK, Master Slave, Registers and counters).
108
2. Basic structure of computer function units, bus structure
3. Operational concepts, memory organization.
4. Input output organization input and output memory bus asynchronous data transfer,
first in first out button, programmed i/o, internet-intimated i/o, daisy chining
programming, DMA, IOP.
Introduction
Computer organization deals with the way the hardware components are
connected together to farm a computer system. The basic knowledge to understand the
hardware operation of digital computer is a must for any to pursue their carrier I their
computer field
LSB
0x23+1x22 +1x21x1x20
109
8bits =1Byte (B) &
4 bits =1 Nibble.
Tetra
10 9
Gega
10 6
Mega
10 3
Killo
10 -3
milli
10-6
micro
10 -9
Nano
Pico
10 -12 -
Binary
101
110
--------
Decimal
15
20
--------
Binary
1111
10100
------------
1011
--------
35
--------
100011
------------
Decimal
3
5
Binary
11.01
101.11
1001.00
110
BINARY ARITHMETIC OPERATIONS
A different approach is varied to handle fractional values. For example, the decimal
fraction (0.435)10 is
4x 10-1 + 3 x 10 2 + 5 x 10 3(or) 4 / 10 + 3 / 100 + 5 / 1000. Thus, it is not difficult to
convert a function in same --- base to base 10.
(0.34)8 = 3 x 8-1 + 4 x 8-2 = 3/8 + 4/64
(0.101)2=1x2-1 +0x2-2+1x2-3 = +0/4 +1/8 =0.625
(0.011101)2 =(0.35)8
(0.76)8 = (0.111110)2
(0.10100001)2=(0.A1)16
(0.0101111111)2=(0.5FC)16
(0.6)16 =(0.01101111)2
Complement notation
Ones Complement:
In ones complement ------- notation, binary number is the number that results when you
complement each by ones complement.
1s complement
10110110
01001001
Twos complement:
1s complements + 1 is the Twos complement.
2s complement of 10110110 is 01001001 + 1= 01001010.
Binary Subtraction
A B = A+2s complement of B.
101101
-100011
------------------001010
-------------------
A = 45
1s complement of B = 01100
1
B =35
---------------------- 2s complement of B = 011101
10
--------
A+ 2s Complement of B =
101101
011101
-----------------------------1001010
(Ignore the ----, on the MSB)
111
Decimal to Binary
(214) 10
11010110
11010110
(117) 10
01110101
01100001
The result is (01100001) 2 = (97) 10
Binary Multiplication
111 x 101
-------------111
000
111
---------------------------100011
----------------------------
2)11110 x 1001
-------------------11110
00000
11110
---------------------------100001110
----------------------------
Over present number system i.e, the decimal number system provides
modern mathematicians and scientists with great advantages over those
of previous civilizations, since hands are the most convenient tools nature
has provided; human beings have always tended to use them in
converting. An even simpler system, the binary number system, has
proved the most natural and efficient system for computer use.
Number
System
Base
Range of
numbers
M
Base
Range
of
numbers
112
Decimal
Binary
10
2
09
01
9
1
Octal
Hexa
Decimal
8
16
07
0-F
7
F
DECIMAL HEXA
DECIMAL
0
0
1
1
2
2
3
3
4
4
5
5
6
6
7
7
8
8
9
9
10
A
11
B
12
C
13
D
14
E
15
F
16
10
17
11
(345)10=3x102+4x101+5x100
(11011)2=1x24+1x23+0x22+1x21+1x20
1x16+1x8+0x4+1x2+1x1=(27)10
(345)8=3x82+4x81+5x80=(229)10
(C8D)16=12x162+8x161+13x160=(3213)10
BINARY
OCTAL
0
01
10
11
100
101
110
111
1000
1001
1010
1011
1100
1101
1110
1111
10000
10001
0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
17
20
21
BINARY TO OCTAL
Begin at the right and take groups of three bits at a time and assign octal values.
(011010111101001100)2 = 011 010 111 101 001 100
Octal Equivalence of the above = (3
4) 8
7) 8
113
BINARY TO HEXADECIMAL
Begin at the right and take groups of four bits at a time and assign hexadecimal values.
(011010111101001100)2 = 01 1010 1111 0100 1100
Hexadecimal Equivalence of the above = (1
D) 16
F) 16
DECIMAL TO HEXADECIMAL
(5214)10 = ( ? )16
5214/16 = 325 Remainder is 15 i.e., E in hexadecimal.
325/16 = 20
Remainder is 5
20/16 = 1
Remainder is 4
= (145E)16 = (5214)10
1/16 = 0
Remainder is 1.
Weighted Codes:
Weighted codes are Binary codes. Since 10 decimal digits are to be encoded, you
remain at least 4 binary bits. Using weighted codes you can represent numbers. Most
useful weighted codes are Binary Coded Decimal (BCD) and excess three(X S 3) code.
To convert these weighted codes into an equivalent decimal number, we have to weight
each digit (Bit) of Binary number by an appropriate integer power of 2, and add up these
results.
BCD Code
BCD code is also called 8421 code. The numbers 8, 2, 4 and 1 corresponds to the
weight of the positions in the Binary 4 bits of the code.
114
Decimal
Digits
0
1
2
3
4
5
6
7
8
9
BCD Code
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
Excess 3
code
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
Excess
Complement
1100
1011
1010
1001
1000
0111
0110
0101
0100
0011
Gray Code
Gray Code
0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
It is un weighted Code.
In this code only one
change between counts.
This one bit change
takes place not only in
transition in 0 through
9 in 9 to 0 transition.
Due to only one bit
change between
Counts ,it is being in
use for certain analog to
digital techniques.Such
an use results in an error
of not more than one
count.
Note:
Any binary number can be converted to a corresponding gray code number by
combining adjacent binary digits with an EX-OR function.
(1101) 2 = 1 + 1 , 1 + 0, 0 + 1
(1 0 1 1) gray
(1 0 0 1 0) 2 = (1 1 0 1 1) gray
NOTE:
Conversion of gray code to binary numbers can be done conducting sequential
addition from left to right, without carry, starting with zero.
Convert (1011) gray = (
1011
+0
-------1
-------step1
)2
1011
1011
+01
011
----------------(1011)gray =(1101)2
11
110
----------------step2
step3
1011
0110
---------1101
---------step4
Thus
115
Floating
point
Number
1111111
127
Sign
1
-
Number
1111111
127
116
BOOLEAN ALGEBRA
The three basic operations of Boolean algebra are:
a) Complement
b) OR Operation
c) AND Operation.
BASIC BOOLEAN THEOREMS:
X+0=X
X1=X
X+X=X
X +1=1
X0=0
X X = X X + X1 = 0 X . X 1 = 0
XY= YX , X +Y =Y + X
1) X + 0 = X
2)X + 1 = 1
1d) X 1 = X
2d) X 0 = 0
Idem law
3) X + X =X
3d) X X = X
Involution Law
4) (X1)1 = X
Complimentarily
5) X + X1 =1
5d)X X1= 0
Commutative Law
6)X + Y = Y + X
6d)XY = YX
Associative Law
7)(X+Y)+Z=X+(Y+Z) 7d)(XY)2=X(YZ)=XYZ
Distributive Law
8)X(Y+Z)=XY+XZ
8d)X+YZ=(X+Y)(X+Z)
9)XY+XY1=X
9d)(X+Y)(X+Y1)=X
10d)X(X+Y)=X
117
De Morgans law
Duality
Consensus Theory
11)(X+Y1)Y=XY
11d)XY1+Y=X+Y
12)X+Y+2+---)1=X1+Y1+21----12D)(XYZ.)1 =X1 +Y1 +Z1.
13)(X+Y+2+.)D=XYZ
13D) (XYZ)D =X+Y+2+
14)(X+Y)(X1+Z)=XZ+X1Y
14d)XY+X1Z=(X+Z)(X1+Y)
15) XY+YZ+X1Z =XY+Y1Z
15d)(X+Z)(Y+Z)(X1+Z)=(X+Y)(X1+Z)
OR
X=A+B
Truth table
A
0
0
1
1
B
0
1
0
1
X
0
0
0
1
Remarks
Out put is
low, if either
of inputs is
low.
Out put is
118
INVERTER
X= A
NAND(AN
D+NOT)
A
X=AB
B
A
0
0
1
1
B
0
1
0
1
A
0
1
X
1
0
A
0
0
1
1
B
0
1
0
1
X
0
1
1
1
high,
if
either
of
inputs
is
low.
Out put is
complement,
inverse
X
1
0
1
0
either
of
inputs
is
low.
Out put is
high,
when
either
of
inputs
is
low.
NOR(OR+
NOT)
X=A+B
A
0
0
1
1
B
0
1
0
1
X
1
0
0
0
Out put is
low,
when
either
of
inputs
is
high.
119
A
B
0
0
0
1
1
0
1
1
Exclusive OR
X OR
X
0
1
1
0
X=AB
=A B+
A B
Exclusive NOR
X-NOR
A
B
0
0
0
1
1
0
1
1
The output is high for like
Inputs and low for unlike
inputs.
X=AB
X
1
0
0
1
=AB+ A
120
In case of combinational logic circuits, the output value depends only on the
present value of the inputs and not on past values. A combinational
network has no memory. In case of a sequential network, the output
depends on both the present and past input values. The sequential
network is said to have memory because it must remember something
about the past sequence of inputs.
COMBINATIONAL LOGIC CIRCUITS
Half Adder:A half adder is a circuit used to add two binary bits. It has two binary outputs, one
for carry bit and another for sum.
(Carry) C=AB
A
0
0
1
1
B
0
1
0
1
C
0
0
0
1
S
0
1
1
0
(sum) S =A B = A B +A B.
Full Adder:A Full adder is a combinational circuit that forms the arithmetic sum of three
input bits. It consists of three inputs and two outputs.
121
A
0
0
0
0
1
1
1
1
B
0
0
1
1
0
0
1
1
C
0
1
0
1
0
1
0
1
Carry
0
0
0
1
0
1
1
1
Sum
0
1
1
0
1
0
0
1
Carry=AB+BC+AC
Sum=A B C= A B C + A B C + A B C + A B C.
122
Case (1) When control load is low ,i.e, zero. B3 B2 B1 B0 will appear as inputs to Full
adder along with A3 A2 A1 A0 and addition operation takes place with zero in parallel.
Therefore
A3 A2 A1 A0
B3 B2 B1 B0
------------------------
A+B+0=
S 3 S2 S1 S0
A+B(Addition)
------------------------
Case (2) When control load is high ,I .e, One. B 3 B2 B1 B0 will appear as B3 B2 B1 B0
along with One with full adder and becomes two 1s complement of B. Hence, A3 A2
A1 A0 will be added to the twos complement of B the result is A B.
Therefore
A3 A2 A1 A0
B3 B2 B1 B0
1
------------------------
A-B =
S3 S2 S1 S0
------------------------
Multiplexer:
A multiplexer is a circuit which allows one input to appear at the output at a time
from many inputs. It is also called many to one. Depending upon the status of the select
signals the respective input will appear at the output.
A0
A1
A2
A3
S1 S0
4x 1
MUX
O/P
123
A0
A1
A2
A3
A4
A5
A6
A7
S2 S1 S0
OUT PUT
8x 1
O/P
MUX
S1
0
0
1
1
S0
0
1
0
1
S2
0
0
0
0
1
1
1
1
S1
0
0
1
1
0
0
1
1
Output
A0
A1
A2
A3
S0
0
1
0
1
0
1
0
1
Output
A0
A1
A2
A3
A4
A5
A6
A7
De-Multiplexer:
A De- Multiplexer is a circuit which allows one input to appear at many outputs.
It is also called as One Many. Depending upon the status of the select signals the input
will choose the respective output.
124
S1 S0
Input
4x 1
MUX
S2 S1 S0
output
A0
A1
A2
A3
A3
8x 1
MUX
FLIP FLOPS:
Sequential switching networks have the property. The output depends not only
on the present input but also on the past sequence of inputs. Flip flops are the most
commonly used memory devices in sequential networks. A Flip-flop is a memory device
which can store one of two stable output states and has one or more inputs that can cause
the output state to change. It has pair of complementary outputs.
125
R S Flip Flop.
R S Latch
126
Clok
0
1
1
1
1
S
X
0
1
0
1
R
X
0
0
1
1
Output(q)
NC
NC
(1) Set
(0) Reset
(*) Unpredictable
Race condition.
As per the property of NAND gate, it switches to 1 if one of its input is zero. Set
condition is one when the output (Q) switches from 0(previous state) to one , and Reset
condition is when output switches from 1 (previous state) to zero.
Clk
Output
NC
NC
NC
Set
Reset
Toggle state
127
Circuit of JK
flip flop
Memory Organization
The Memory unit is an essential component in any digital computer, since it is
needed for storing programs and data. Most general computers would run more
efficiently if they were equipped with additional storage beyond the capacity of the main
memory. The memory unit that communicates directly with the CPU is called the main
memory. Devices that provide backup storage are called Auxiliary memory. The most
common auxiliary memory devices used in computer system are magnetic disk and other
backup information. Only programs and data currently needed by the processor reside in
main memory. All the other information is stored in auxiliary memory and transferred to
main memory when needed.
Cache Memory:- A special very high speed memory called a Cache and is used to
increase the speed of processing by making current programs and data available to the
128
CPU at a rapid rate. The Cache memory is employed in computer system to compensate
for the speed differential between main memory access time and processor logic.
Magnetic
tapes
I/o Processor
Main
Memory
Magnetic
tapes
Cache
Memory
Memory Terminology:
CPU
Memory Cell: A electrical circuit or device used to store a single bit or binary digit (0
or 1). This is the basic unit of information storage. Ex: Flip flop, a changed capacitor,
and a single spot on magnetic tape or disk.
Memory Word: A group of memory cells in a memory that represents instructions or
data. Ex: Register containing of eight flip flops can be considered to be a memory that is
storing an 8-bit word.
Byte: A graph of 8 bits is known as byte. Information or data is frequently stored in
blocks of eight bits.
Capacity:- A way of specifying how many bits can be stored in a particular memory
device or complete memory system.
Density: It is the measure of how many bits can be stored in some amount of space. It is
another term for capacity.
129
Address: A number that identifies the location of a word in memory. Each word stored in
a memory device or system has a unique address. Addresses are always expressed as a
binary number.
Read Operation: Consider the following operation, the binary word stored in a specific
memory location (address) is sensed and then transferred to another device. This is
known as read operation. It is also known as fetching operation.
Write Operation:- When a new word is placed into a particular memory location, it is
known as write operation. Also, it is known as store operation. Whenever a new word is
written in to a memory location, it always replaces the old data with the new data.
Access Time:- Access time is a measure of memory devices operating speed. The
amount of time required to perform a read operation is known as access time. Access
time is the time between the memory receiving a new address input, and the data
becoming available at the memory output.
Internal Memory:- Internal memory is also referred to as the computers main working
memory. It stores instruction / data of CPU is currently working on. It is the highest
speed memory in the computer and is always a semiconductor memory.
Auxiliary Memory:- Auxiliary memory is also referred to as mass storage because it
stores massive amount of information externally. It is slower in speed than internal
memory and is always non volatile. Magnetic tape and disk are common auxiliary
memory devices.
Volatile Memory:- A volatile memory which requires existence of electrical power in
order to store information. If the electrical power is removed, then all information stored
in the memory will be lost.
Non Volatile Memory:- Non volatile memory means that they can store information
without electrical power. Most of the semi conducting memories is volatile, while all
magnetic memories are non-volatile.
Static Memory devices: Semiconductor memory devices in which the stored data will
remain permanently stored as long as power is applied, without the need for periodically
re-writing the data into memory.
Dynamic memory Devices:- Semiconductor memory devices in which the stored data
will not remain permanently stored even with power applied, unless the data are
periodically rewritten into memory. This periodic re-writing is known as refresh
operation.
130
Random Access Memory (RAM):- If the access time is the same for any address in
memory, then this type of memory is known as random Access Memory (RAM). Most
semiconductor Memories are RAM s. In it the actual physical location of a memory word
has no effect on how long it takes to read from or write into that location.
Sequential Access Memory (SAM): - The access time is not constant, but varies
depending on the address location. A particular stored word is found by sequential
through all address locations until the desired address is reached. This produces access
times which are much larger than those of random access memories.
Read only Memory:- (ROM) A Rom can be written into or programmed only once .
Afterwards, this stored information can be read from the memory. All ROM is
nonvolatile and will store data when electrical power is removed. Also all ROM are
random access memories.
Associative Memory:- The time remained to find an item stored in memory can be
reduced considerably if stored data can be identified for access by the content of data
itself rather than by an address. A memory unit accessed by content is called an
associative memory or Context addressable memory (CAM). This type of memory is
accessed simultaneously and in parallel on the basis of data content rather than by
specific address or location. When a word is written in an associative memory, no address
is given. The memory is capable of finding an empty unused location to store the word.
When a word is to be read from an associative memory, the content of the word or part of
the word, is specified. The memory locates all words, which match the specified content
and marks them for needing.
Argument register(A)
Key register(K)
Input
Read
Write
Associative memory
away and logic m
words n bits per
word
output
131
Block diagram of Associative memory
Word1
Word2
100
101
101
111100
111
000000
Only 3 left most bits of A are compared with memory words because K has 1 in
3 positions. Word2 matches the unmasked argument field because the 3 left most bits of
A and word are equal.
Because of its organization, the associative memory is unequally suited to
do parallel searches by data association moreover, searches can be done on an entire
word or on a specific field within a word. An associative memory is more expensive than
a random access memory because each cell must have storage capacity as well as logic
circuits for matching its content with an external argument. For this reason, associative
memories are used in applications where the search time is very critical and must be very
short.
Virtual Memory:
In a memory hierarchy system, programs and data are first stored in auxillary
memory. Portions of a program or data are brought into main memory as they are needed
by the CPU virtual memory is a concept used in same large computer systems that permit
the user to construct programs as though a large memory space where available, equal to
the totality of auxiliary memory. Each address that is referred by the CPU goes through
an address mapping from the so called virtual address to a physical address in main
memory. Virtual memory is used to give programmers the illusion that they have a very
large memory at their disposal, evan though the computer actually has a relatively small
main memory. A virtual memory system provides a machanism for translating program
generated address into correct main memory locations. This is done dynamically, while
132
programs are being exeuted in the CPU. The translation or mapping is handled
automatically by the hardware by means of mapping.
Page 0
Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Block 0
Block 1
Block 2
Block 3
Into groups into groups of 1K words.
101
0
11 1
00 1
0
0
01 1
10 1
0
01
01
01010 1001
0101010011
Block 0
Block 1
Block 2
Block 3
133
134
INPUT
Control
bus
Address bus
CPU
CONTROL+
ARITHMETIC
Memory
Data bus
Output
BUS STRUCTURE
A collection of wires that connects several devices is called a Bus. In addition to
the wires that carry the data, the computer must have same lines for addressing and
control purpose. There are three main groupings of lines or bus, namely:
135
Data Bus: Which are used for transmission of data, and the number of them corresponds
to the number of bits in a word.
Address Bus: It specifies the location of data in the main memory.
Control Bus: It indicates the direction of data transfer and co-ordinate the timing of
events during the transfer.
input
output
process
memory
Input
process
ouput
Single Bus Structure
Arithmetic Circuit
Select
S1 S0 Cin
0 0
0
0 0
1
0 1
0
Input
Y
B
B
B
Output
D = A + Y + Cin
D=A+B
D = A + B +1
D=A+B
0
1
1
1
1
1
0
0
1
1
1
0
1
0
1
B
0
0
1
1
D=A+B+1
D=A
D=A+1
D = A -1
D=A
Operation/ function
Addition
Addition with carry
Subtract with
common
Subtract
Transfer A
Increment A
Decrement A
Transfer A
memory
136
Cin
S
1S
Aoo
Xo
Co
S1
So
B
o
0
1
2
3
A1
4X1
MUX
FA
Yo
C1
X1
C1
D1
S1
So
B1
0
1
2
3
A2
FA
4X1
MUX
Y1
C2
X2
C2
D2
S1
So
B2
0
1
2
3
A3
FA
4X1
MUX
Y2
C3
X3
C3
S1
So
B3
Logic o
Logic 1
0
1
2
3
D0
D3
4X1
MUX
FA
Y3
C4
Carry
out
137
4x1
MUX
S1
S0
OUTPUT
0
0
1
1
0
1
0
1
E=A^B AND
E=AvB OR
E=AB XOR
E=A
COMPLE
Out put
NOT
Ao
0
1
A1
A2
0
1
S
H1
H1
H2
0
1
S
0
1
Serial input (IL)
H3
138
S
3
S
2
S
1
S
0
Ci
One Stage of
arithmetic
Circuit
Select
Ci + 1
Di
Ei
One Stage of
Logic Circuit
Bi
Ai
Ai - 1
Ai +
1
Shr
Shl
4X1
MUX
0
1
2
3
Fi
139
Operation
Function
S2
S1
S0
Cin
F=A
Tranfer A
F=A+1
Inctrment A
F=A+B
Addition
F=A+B+1
Addition with
carry
Subtraction
with borrow
Subtraction
F= A + B + 1
F=A-1
Decrement
F=A
Transfer A
F=A^B
AND
F=AvB
OR
F=AB
XOR
F=A
F=Sht A
F=Sht A
F=A + B
Complement
Shift right A
into F
Shift left A into
F
140
Universal sets.
b. 1011100101101110
b. 1111101101110100101010010101
2. What is duality in Boolean algebra?
3. State and prove DeMorgans theorem?
4. Obtain the logic functions AND, OR, NOT, XOR, XNOR using only
NOR gate (with the help of DeMorgans theorem?
5. What is a flip-flop? Why do we need it?
6. Discuss the salient features of semi-conductor memories and magnetic
memories?
7. Discuss how do we perform parallel addition and subtraction using a
single circuit?
141
142
X10 = 1101001011012
2. Perform the following additions and check for converting the binary
numbers to decimal and adding.
a. 1010+1111
b. 101.1+111.1
c. 1100.011+1011.011
143
144
b. A C + AC
c. A B + B C
d. A B C + A B C + A B C
145
2. Obtain the logic functions AND, OR, NOT, XOR, XNOR using only
NAND gate (with the help of De-Morgans theorem)?
3. Discuss memory hierarchy.
4. What is cache memory?
5. What is the concept of virtual memory?
6. Discuss the functions of ALU?
146