You are on page 1of 146

FOUNDATION COURSE

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

Course Preparation Team,


Dr.V.Ramprasad
Prof. L. Manjunatha Rao
Prof. Srinivas
Prof. Umesh
Assistance
Mr. Srinivasa Murthy G
Miss. Savitha
Mr. Sudeep K P

Mr. Kumar Swamy

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.

Linear Function: Is a one in which the power of independent variable 1,


the general expression of linear function having only one independent
variable is

Y = F (X) = a + bx.

Where a & b are given real numbers and x is an independent variable


taking all numerical values in an interval be plotted by giving different

values and calculating Y. The graph of such functions will always be a


straight line.
Y
13
11
9

Y = 3 + 2x

5
3
0
1

Quadratic Equation:
Cubic Equation:

Y = ax2 + bx + c

Y = ax3 + bx2 + cx + d

Exponential Functions: - If the independent variable in any functional


relationship appears as an exponent (or power), then the functional
relationship is called exponential function such as
1.
2.
3.
4.

a1
a1
a1

Y = ax ,
Y = Kax,
Y = Kabx
Y = Kex

Where a, b, c, e and k are constants with a taking only positive value.


Y

Y
Y = kax
a>1,k>0

Y = Kax
(a<1, k>0)

k
X

5
0

Such functions are useful for describing sharp increase or decrease in


the value of dependent variable. For E.g. the exponential function Y = Ka x
curve uses to the right for a<1, K>0 as shown in figure.
Logarithmic Functions: -

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

Y. Interchanging the variables. This shows

that the inverse of an exponential function is a logarithmic function.


HA: Draw the graph for
1. y = 3x 5
2. y = x2
Given that f (x) = (x-4) (x+3), find f (4), f (-1) and f (-3)
Linear functions:
A company sells x units of an item each day at the rate of 50 per
unit. The cost of manufacturing and selling these units is Rs.35/- per unit a
fixed daily overhead cost of Rs.1000/-. Determine the profit function. How
would you interpret the situation, if the company manufacture and sells 400
units of the items a day?
Solution:
Total revenue received by the company per day is
given by total revenue R = (Price/Unit) X (No. Of items sells) = 50 X
Total cost of manufacturing item / day = (Variable cost/Unit) X (No. of
items manufactured) +Daily
overhead cost.
= 35X+1000
Thus total profit (P) = Total revenue Total cost.

= 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:

Two sets A & B are said to be equivalent if there is a one to one


correspondence between elements of two set e.g.
A = {9, 11, 13} and B = (e, f, g) are equivalent but not equal.
Finite set:
A set is called finite if it contains finite numbers or elements.
Infinite set:
A set containing infinite number of elements is called infinite set.
Null set:
The set having no element is called the null set and is denoted by the
symbol .

Single out set [or Unit set]:


A set with only one element is called a single out set. E.g.: X1 = { 0 }
Union sets:
The union of two sets A and B is the set of all elements which belong
either to A or to B or to both A & B. Symbolically it is denoted as AB and
is read as A Union B.
AB = {X:X belongs to either A or to B or both}
E.g.: A = {a, b, c, d},

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}

Then AB = {4, 5}.


Universal set:
Suppose we consider the following sets.
A = {1},

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)

Compliment of Set or [Negation of a set]:


Is always w.r.t a universal set, if V is a universal set and AU {i.e., A
is a proper set of U} then the complement of A w.r.t. U is denoted by A c and
is the set of all those elements of U, which do not belong to A. i.e.,
Ac = {X; XU but XA}
Evidently [Ac]C = A
If V = {1,2,3,4,5}, A = {1,2,3} then
Ac ={4,5}

10

U = {1,2,3,4},

A = {1,2} then Ac = {3,4}

Difference of two sets:


Difference of two sets A and B is the set elements of A, which are not
in B, and is denoted by (A-B) for e.g.:
If A = {1,2,3,4,5,6,7};

B = {2,4,6}

Then, (A-B) = {1,3,5,7}


Some more results:
Set A be in a finite set. Then we denote the number of elements in A
by symbol m(a) or n(a) i.e.,
m(A) means no. of elements in A
m(B) means no. of elements in B
m(AB) means no. of elements in (AB) and so on.
In general,
1. m(AB) = m(A)+m(B)-m(AB)
2. m(ABC) = m(A) + m(B) + m(C) - m(AB).
If U is a universal set and A is any proper subset of U then
m(A) = m()-m(A)
Rule of expansion: According to this rule any given set can be expanded in
terms of another set (imp).
1. X = (XY) (XYC)
mX = m(XY) + m(XYC)
2. If we want to expand XY in terms of Z, we have,
XY = (XYZ) (XYZC)
Problems:
i)

If A ={1,2,3}, B = {2,3,4,5} and C = {2,4,6,8} verify


A-(A-B) = AB

ii) A(B-C) = (AB) (BC).

11

solution:
I)

A-B = {1}, A-(A-B) = {2,3}

II)

B-C = {3,5}, A(B-C) = {3}


(AB) (BC) = {2,3} {2,4} = {3}

Problems:
i)
solution:

If A ={a, b, c, d}, B = {e,f,c,d} and C = {e,f,g,h} verify


(AB) C

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:

A town has a total population of 60,000, our of it 32,000 read

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)

No. of reading Hindustan Times.

m(t)

No. of reading Times of India.

m(HT) = Total number of people reading both the news papers.


m(HT) = No. of persons who do not read any paper.
m(HT) = m(H) + m(T) m(HT)
= 32,000+35,000-7500 =

59,500

= No. of people who read either H.T. or T.I.


m(HT)1 = No. of persons who do not read any paper.
= m(P) m(HT)
= (69500 - 59,500) = 500
VENN Diagrams:
Venn diagram is the pictorial representation of the relation between
the sets.
1. Universal set is represented by rectangle.
2. Any proper subset or the universal set is represented by a circle or
oval shaped region within the rectangle representing the universal
set.
Universal Set

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

b) When the sets are overlapping c) Union of two sets

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

So, m(ME) = 11.


Problem:

A Survey discloses that out of a group of 25 students, 20

interested in Music, 15 interested in photography and 10 like sports. Further


15 are interested in music and photography 5 interested in music and sports.
3 are interested in photography and sports and 2 are interested in all. Are the
data correct?
Solution:
If m(M) = No. of students interested in music.
m(P) = No. of students interested in photography
m(S) = No. of students interested in Sports.
m(MPS) = m(M) + m(P) + m(S) m(MP)
-m(PS) m(MS) m(MPS)
= 20+15+10-15-5-3+2 = 24.
But m(MPS) = Total No. of students in the group = 25.
So, the data is not correct.
Venn Diagram (Problem): In a classroom of 30 students, every student
takes either economics or maths or both. 18 students have taken economics
and 10 students have taken maths and economics. Find out the no. of
students who have taken maths and but not economics, show by Venn
Diagram.
Solution:

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 . .

are also called positive integer

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

If possible let p/q = log105


10 p/q = 5
10 p = 5q
(5X2) P = 5q => 5q is a multiple of 2q

=> 5 is a multiple of 2
Which is not true, hence, log105 is an irrational number.

Find all numbers, which are equal to their reciprocals


Solution: Let x = 1/x => x2 = 1
i.e., x = 1 i.e., +1 or 1
b)

Prove that 32 is irrational.

Solution: Let 32 =a/b i.e., a3/b3 i.e., a3=sb3 is a multiple of


2=>a is a multiple of 2 i.e., a = 2c
(2c) 3 = a3 = (2b)3 => b3 = 4c3 => b3 a multiple of 2
Now, `a is a multiple of 2, b is a multiple of 2 means a & b are
both even which contrary to our assumptions that a & b are in their
lowest forms. Hence 32 is irrational.
c)

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.

Matrices and Determinants


A matrix is a rectangular array (i.e., arrangement) of numbers in rows
and columns. The numbers in a matrix are called its elements. These
elements are real and complex numbers.
Notation:
A single letter denotes a matrix and its elements are shown enclosed
in bracket or parentheses. For Ex:
A=

3 -4
1

B=

3i

-1

A general matrix with m row and n columns is usually denoted as follows:


A=

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

(2+I , 0, 1, -1) 1x4.

3. Column Matrix: A matrix with a single column (mx1 matrix) is called a


column matrix.
E.X.:

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:

A Diagonal matrix is a square matrix in which all

the elements except those on the leading diagonal are zero.


E.X.:
A=

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

8. Unit matrix or identity matrix: A diagonal matrix in which each


diagonal element is unity (i.e. 1) is called a unit or identity matrix. The
letter 1 usually denotes a unit matrix.
E.X.:
A=

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]

[ka, kb, kc]

3. Addition of Matrices:

The sum of two matrices A and B both of

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 sum of two matrices A and B both of

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

3. Scalar Multiplication is distribute.


i.e., k(A + B) = kA + kB, where k is a scalar.
1

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:

Multiplying (2A + B) by 4 and then adding to (3A 4B) we

get (8A + 4B) + (3A 4B) =

=
=

11A =
A = 1/11

48

-12

12

88

55

-22

33

99

55

-22

33

99

Again from (2A + B) we get


B=
=

12

-3

22 - 2A

12

-3

10

-4

22 - 6

18

-3

-10

21

11

-2

28

Ex. 3: If A =

-5

find the matrix B such that 3A + 2B =0.

Solution: Since 3A + 2B = 0, it follows that the matrices A, B and O are of


the same order.
a

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

-15+2d 18+2e 21+2f


3+2a=0

6+2b=0

2c=0

-15+2d=0 18+2e=0 21+2f=0

a = 3/2, b = -3, c = 0, d= 15/2, e =-9, f = -21/2

B=

-3/2 -3

15/2 -9

21/2

Ex. 4: If A =
unit matrix

-1

-4

find the matrix X such that A + X is a

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

In this chapter we shall see the concepts like functions (mapping),


limit of a function and derivative of a function. These are the basic concepts
of the branch of mathematics known as Differential Calculus. The subject
calculus was invented independently by two mathematicians, Sir Isac
Newton and Leibnitz, during the same period that is in the year 1684.
Variables & constants:
A quantity that remains same in its value is called a constant. If the
value of the constant is a real number, then it is called a real constant.
Ex:

I)5

II)8ft.

III)Rs.80.

A quantity, which changes in its value, is called a variable. If he value


of the constant is a real number, then it is called a real constant. The
variables are usually denoted by x, y, t, z etc.,
Functions (Mapping):
We shall first give a general definition of a function or mapping from
one set into another set. Then we shall restrict these sets to the sub sets of
real numbers.
Definition: Let A and B be two non empty sets. If to each element x
A, there corresponds a unique element y B, by means of a rule denoted
by f, then we say a function or mapping f is defined from the set A into
B.
If x A is associated y B by means of the function f, we write y =
f(x) and say y is the image of x under the mapping f and x is called the
preimage of y under f. Further in symbols we denote the function f from
the set A in to b by

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

If, x = -1/2 y = f(-1/2) =(-1/2)2 = etc.


2. If f(x) = 2x 3, then
f(0) = -3, f(-1) = -2-3 = -5
f(-2) = -4-3 = -7, f(-1/2) = 1-3 = -2 etc.
Algebra of real valued functions:
We shall mention few laws of algebraic operations performed on the
set of functions of real variables.
Definition:

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.

1. (f+g) (x) = f(x) +g(x)


2. (f-g) (x) = f(x) -g(x)
3. (f.g) (x) = f(x) .g(x)
4. (f/g) (x) = f(x) /g(x), where g(x) # 0
5. (k.f) (x) = k.f(x)
Types of functions:
1. Constant functions: A function y = f(x) is said to be constant function, if
for every value of x the value f(x) of the function is a same constant
say, k. i.e.,

y = f(x) = k for all real values of x.

Ex.: f(x) = 2 is a constant function.


f(0) = 2, f(-1) = 2, f(1/2) = 2, etc.,
2. Identity function: The function f(x) = x, for all real values of x is called
the identity function defined on the set of real numbers.
In this case f(1) = 1, f(2) = 2, f(-3) = -3 etc.,
3. Polynomial function: A function of the form
f(x) = a0xn + a1xn-1 + a2xn-2 + . . . . + an
Where n is a positive integer, a0, a1, a2 . . . are rational constants, is
called a polynomial function. The right hand side expression is called a
polynomial in the variable x of degree n.
The following are few polynomial functions.
i. f(x) = 3x2 4x + 2

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:

f(x) = 2x 4, g(x) = 3x 2 are linear functions.

Derivatives:

Now we shall see the concept of differentiation of a

function, its geometrical meaning and its application.


Differential Co-efficient: Consider a function y = f(x). Here x is the
independent variable and y is the dependent variable, the value of the
function f(x) changes as the variable x changes, the rate at which the
function changes is of create importance in the study of subject calculus.
The process of finding the rate of change of the function is called
Differentiation.
Let y = f(x) be a continuous function of x. let x be the increment given
to the value of x. then there will be a corresponding increment in the value
of y; let this be y.
y + y = f(x + x) new relation
y

= 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

Lim y/x = Lim f(x-x) f(x)/ x

36

If this limit exists, then it is called the differential Co-efficient of y


with respect to x or the rate of change of the dependent variable y with
respect to the variable x. This is denoted by the symbol.
dy/dx or d/dx (f(x)) or f(x).
Thus, if y = f(x) is a function
dy/dx = lim y/x
If the increment in x is denoted by h, then by the definition, we have
f(x) = dy/dx = lim f(x+h) f(x)/h
Ex: 1 Find the differential Co-efficient (derivate) of the function y = x2-4
By definition dy/dx = lim f(x+h) f(x)/h
= lim [(x+h)2 4] (x2-4)/h
= lim x2+2hx+h2-4-x2+4/h
= lim h(2x+h)/h
= lim (2x+h)

(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

If y =xn, then dy/dx = nx n-1


Particular cases:
I)

n = -1, y = x-1 = 1/x


dy/dx = (-1)x 1-1 = (-1)x-2 = -1/x2
d/dx(x-1) = d/dx (1/x) = -1/x2

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.

Such statements are called inequalities. These are represented in


symbols as 3<5, 14>9, a 6 and a 5 respectively. Inequality relationships
between numbers represented by a<b or a>b obey a set of rules. We shall
mention a few of these rules and verify them with given numbers.
An inequality relationship remains unaltered when the same number is
added to or subtracted from both sides of an inequality. For Ex.:
3+2<5+2 and 3-2<5-2 or 14>9 implies that 14+2>9+2 & 14-2>9-2

39

The inequality nature remains the same when an inequality relationship is


multiplied by a positive number; however multiplying both sides of an
inequality by a negative number reverses the inequality sign.
For Ex: 3 < 5 implies that
4.3 < 4.5 i.e., 12 < 20.
and 4.3 > -4.5 i.e., -12 > -20 or 14>9 implies that
2.14 > 2.9 i.e., 28>18 and
-2.14 < -2.9 i.e., -28 < -18.
The rules concerning inequalities of numbers also apply to inequalities of
expressions that involve one or more variable. In this section we shall
restrict our study of these inequalities as they apply to linear functions of
two variables.
Consider the inequality 3x + y 6
Now the problem is to determine what pairs of numbers (x, y) will
satisfy this inequality. Suppose we take 3x + y = 6.
Then, the pairs of numbers (x, y) that satisfy the equation, determine a
straight line as show in the figure.
6
5
4
3
2
1
0

40

To draw the line, we take the following values:


X
0
2
Y
6
0
Clearly the pairs (0,0), (1,0), (0,1), (0,2) and so on, which represent
points below the line as shows by the shaded region satisfy the inequality
3X+Y < 6.
Thus, the shaded region in the figure is represented by the inequality
3x+y 6, which includes the points on the line 3x+y=6. similarly, we can
see that the inequality 3x+y 6 represent the region to the right of the line
3x+y = 6 as shows below.
Draw the line x + 2x = 3 put x = 0, y 3/2, y = 0, x = 3
(0, 3/2) and (3, 0) are points on this line.
Thus the feasible region is the shaded portion i.e., polygon OABC,
Where, A = (1/2, 0), B = (1, 1), C = (0, 3/2)
Substituting for x and y in p we obtain
PA = P at (1/2, 0) = 3(1/2) + 2(0) = 3/2
PB = P at (1, 1) = 3(1) +2(1) = 5
PC = P at (0, 3/2) = 3(0) + 2(3/2) = 3
Clearly, maximum value of P is 5 at x = 1, y = 1.
Ex: 2:
In the production of two types of watches a factory uses three
machines A, B & C. The time required for each watch on each machine and
the maximum time available on each machine are given below.

41

Machine

Time required for


Watch I
Watch II
(In hours)

(In hours)

6
8
12

8
4
4

A
B
C

Maximum time
available
(in hours)
380
300
404

The profit on watch I is Rs.50 and on watch II is Rs.30. Find what


combination of watches should be produced to obtain the maximum profit.
What is the maximum profit?
Solution:
Let

x = no. of watches of type I produced


y = no. of watches of type II produced.

Then, the objective function (i.e., profit in this case) is given by


P = 50x + 30y
Subject to the constraints
6x + 8y 380
8x + 4y 300
12x+ 4y 404 and X 0, y 0.
Clearly the non-negativity conditions of x and y imply that the feasible
region lies in the first quadrant of the plane OXY.
1. Draw the line 6x + 8y = 380.
Put

x =10, y = 40

y =10, x = 50

Points (10. 40) and (50, 10) lie on this line

42

2. Draw the line 8x + 4y = 300


Put

x = 0, y = 75

y = 0, x = 37.5

Points (0.75) and (37.5, 0) lie on this line


3. Draw the line 12x + 4y = 404
Put

x = 0, y = 101 y = 11, x = 30.

Points (0, 101) and (30, 11) lie on this line

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

PMax = 50(22) + 30(31) = 2030.


Hence, the maximum profit of Rs.2030 is obtained by producing 22
watches of type I and 31 watches of type II.
Ex.: 3. A chemist wishes to provide to his customers at least cost the
minimum daily requirements of three vitamins V1, V2, V3 by using a
mixture of two products M and N. The amount of each vitamin in one gram
of each product, the cost per gram of each product and the minimum dauly
requirements are given below:
No. of units of each vitamin contained in

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

Points (0, 6) and (2, 0) lie on this line


2) Draw the line 2x + 2y = 8
Put

x = 0, y = 6 & y = 0, x = 4

Points (0, 4) and (4, 0) lie on this line


3) Draw the line 4x + 12y = 24
Put

x = 0, y = 2, y = 0, x = 6.

Points (0, 2) and (6, 0) lie on this line


7
6 D
5
4

FEASIBLE REGION

1
0

A
1

Clearly from the figure, we observe that the feasible region is an


unbounded region with corners A = (6,0) B =(3, 1), C = (1,3) and D = (0,6),
which are towards the origin.
Substituting for x and y in C from these points, we obtain
Ca

= Value of C at a = 20(6) + 16(0) = 120 Ps.

Cb

= Value of C at b = 20(3) + 16(1) = 76 Ps.

45

Cc

= Value of C at c = 20(1) + 16(3) = 68 Ps.

Cd

= Value of C at d = 20(0) + 16(6) = 96 Ps.

Cost C is minimum at the point (1,3) of the feasible region. Hence,


C min = 68 paise when the mixture contains 1 gm of product M and 3
gms. of product N.

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.

Computer is the best aid to solve

problems. Problems arise in every field of human activity.

USING A COMPUTER TO SOLVE PROBLEMS

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.

BASIC (Beginners All purpose Symbolic Instruction Code)


FORTRAN(Formula Translation)
COBAL(Common Business Oriented Language)
C Language
PASCAL
RPG (Report Program Generator)

FOURTH GENERATION LANGUAGE:


Machine languages are considered First generation assembly languages are
Second generation; and high level languages are Third generation Fourth generation is a
term that describes a variety of programming languages that allows users to create
programs with much less effort than is required by High level languages.

FOURTH GENERATION LANGUAGES ARE:


1. Database Query Language
2. Report Generation
3. Application Generators.

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.

THE STRUCTURE OF A C PROGRAM:main( )


{

This is the main function and Compiler starts executing from here.
------------ ;
------------ ;
------------- ;

These are the instructions.


This is the end of the program.

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:

int age = 30;

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:

float salary = 5000.30;

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.

String it self an address for strings no need to give an address (&).


# include <stdio.h>
The above statement must be written in all the programs. Where # symbol denotes
compiler directive. Include is a subdirectory name, stdio.h is a file name. All input,
output functions are predefined in stdio.h file under a subdirectory called include.
OUTPUT STATEMENT:
printf (format, variable name);
Eg:

int age = 25;


printf (Your age is %d, age);

output: Your age is 25


Eg:

float salary = 5000.30;


printf(Your salary is %f, salary);

output: Your salary is 5000.30


Eg:

char grade = A;
printf(Your grade is %c, grade);

output: Your grade is A

Special Characters.
\n

new line character (Display from a new line / next line)

\t

tab (leaves 8 spaces)

Program 1: Write a program to accept age grade, salary and name.

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.
/*

beginning of the comment entry.

*/

end of the comment entry.

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

Other wise fail.


Program:
#include<stdio.h>
main() {
int marks;
printf (\n Enter the marks);
scanf (%d, &marks);
if (marks > 79)
printf(\n Distinction);
else if(marks > 59)
printf(\n First class);
else if(marks > 49)
printf(\n Second class );
else if(marks > 34)
printf(\n Pass Class);
else
printf(fail);
}
Switch Statement:
Syntax:

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);

Output: The value of x is 50

Printf(the address of the pointer %u, p);


Output: The address of the pointer p is 1001
%u: unsigned integer. Address is an unsigned integer to print an address %u is used.
Program 5: Write a program to accept any two integers and print the sum, difference and
product using pointers?
Program:
#include<stdio.h>

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

Returning the values from a sub function to the main function:


Using return statement the output or the result can be returned to the main
function. When returning the values if the returning value is other than an integer the sub
function has to be proto typed. i.e, declaring the function with the data type i.e. the type
of the value which is returning from the sub function to the main function. Each return
statement can return one and only one value.

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;

DATA AND FILE STRUCTURE

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.

Operation on data structure


There are different operations that we can perform on 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.

Classification in Data structures:


Data structure can be broadly classified into 2 categories.
Primitive data structures.
Non-primitive data structures.
Data structures are typically operated upon machine level instructions that are
called primitive data structures.
Ex: int, float, char, Boolean, pointer.
Data structures that are not directly operated open by machine level instructions
are called Non primitive data structures. Sub classification of Non-primitive data
structure is:

Linear data structure

65

Non -Linear data structure

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.

Time and Space Complexities:


There are many criteria upon which we can judge a program. For instance,

Does it do what we want to do?


Does it work correctly according to the original specifications of the task?
Does the documentation describe how to use it and hoe it works?
Are the procedures created in such a way that they perform logical sub
functions?
Is the code reachable?

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++)

we assume that the statement x=x+1 is not


contained within any loop either explicitly or
implicitly. Then ,its frequency count is 1.
Now the same statement statement will executed n
times.
This will be executed n2 times.

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

These groups of elements are an array of integers.

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

Two Dimensional Arrays:


Two-dimensional array is also called as matrix.
Ex: A[3][2];
Here A is an array, 3 is the number of rows and 2 is the number of columns.
It is stored in the memory as:
Column1 Column2
row1
row2
row3

A[01]

A[0,2]

A[1,1] A[1,2]
A[2,1] A[2,1]

A 2D array can be represented in memory in two ways. They are


1. Row major
2. Column major
In row major the elements are stored row wise in the following manner:

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

Location of any element


a[i][j] =Lo+(i+j*n) *c

Multi Dimensional Array:


Ex: a [i] [j] [k]
Plane row column

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.

Ex: Tray of File


Top tray of file

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.

Algorithm for Push Operation:


[Function: PUSH (S, TOP, X). This procedure inserts an element X to the top of a
stack, which is represented by a vector S, contains N elements with a pointer TOP
denoting the top element in the stack.]
1. [Check for stack overflow]
If TOP N
Then write (STACK OVERFLOW)
Return
2. [Increment TOP]
TOP TOP +1
3. [Insert element]
S[TOP ] X
4. [Finished]
Return

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.

Algorithm for Pop Operation:


[Function POP (S, TOP). This function removes the top element from a stack,
which is represented by a vector S and returns this element. TOP is pointer to the
top element of the stack.]
1. [Check for underflow on stack]
If TOP =0
Then Write (STACK UNDERFLOW ON POP)
Take action in response to underflow
Exit
2. [Decrement pointer]
TOP TOP 1
3. [Return former top element of stack]
Return ( S [TOP + 1])
An underflow condition is checked for in the first step of the algorithm. If there is
an underflow, then some appropriate action should take place. In many applications
involving stacks, an underflow may occur repeatedly and is checked for as elements are
inserted on and deleted from the stack.

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.

For ex: Tower of Hanoi, 8 queens problem, Ackermens problem etc.

74

We can use recursion to compute the factorial of a number.


!n=n * !n-1, as shown in the following program segment.
Long factorial (int N)
{ if (N==0)
return 1;
return N* factorial(n-1); }

Application 2: Polish and Reverse Polish Notation


The designer of compilers is faced with an analogous backtracking situation in the
evaluation of arithmetic expressions. As you scan the expression A * B ? C + D in left-toright-order, it is impossible to tell upon initially encountering the astrik whether or not
you should apply the indicated multiplication operation to A and the immediately
following operand. Instead, you must probe further into the expression to determine
whether an operation with a higher priority occurs. While you undertake this probing of
the expression, you must stack previously encountered operation symbols until you are
certain when they can be applied.
The process of writing the operators of an expression either before their operands
or after them is called the polish notation.
Consider the sum of A and B. We use + symbol to operands A and B and write
this as A+B. This particular representation is called infix. Polish notation refers to the
notation in which the operator symbol is placed before or after its operands.
For ex:

+AB
AB+

Prefix (Reverse polish notation)


Postfix (Polish notation or suffix)

Application 3: Four Function Calculator


An excellent example of stack usage is four-function calculator. Most calculator
today accept standard format of an expression called infix notation, which takes the
general form operand-operator-operand. for example, to add 200 to 100, enter 100, then

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 -

points to front end of the queue.

Rear pointer

points to rear end of the queue.

We can perform 2 operations on queue. They are:


Insertion
Deletion.
In a queue, Insertion will always be done from the rear end and Deletion will be
done from the front end.
Ex: people waiting in a line to get the ticket in a theater.
In any computer system operating system maintains the different queue,
like ready queue, waits queue etc. Queue can be represented diagrammatically as
follows:

Memory representation of Queue:


Front

Rear

AA
1
Deletion

Front =1
Rear=4

BB CC DD
2

7
8
insertion

9.N

76

Algorithm for Insertion Operation:


[Function: Insert(F,R,Q).Let Q be a queue consisting of N elements. F and R are
pointers to the front and rear elements of queue. This algorithm inserts Y at the rear
end of the queue.]
1.[Check for overflow]
If R N
Then write (OVERFLOW)
Return
2. [Increment rear pointer]
R R +1
5. [Insert element]
Q[R ] Y
6. [If F = 0]
then F 1
Return.
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.

Algorithm for Deletion Operation:


[Function QDELETE(Q,F,R) Let Q be a queue consisting of N elements F and R are
pointers to the front and rear elements of queue. This algorithm deletes and returns
the last element of the queue. Y is a temporary variable.
1. [Check for underflow on stack]
If F =0
Then Write ( UNDERFLOW ON POP)
Return
4. [Delete element]
Y Q[F]
5. [Queue empty?]
if F=R
then FR 0
else FF +1
4. [Return element]
Return(Y)

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

Algorithm for Insertion Operation:


[Function: CQINSERTION. Let Q be a queue consisting of N elements. F and R are
pointers to the front and rear elements of queue. This algorithm inserts Y at the rear
end of the queue.]
1. [Reset rear pointer]
If R = N
Then R 1
Else R R + 1
2 .[Check for overflow]
If F=R
Then write (OVERFLOW)
Return
3. [Insert element]
Q[R ] Y
4.[Is front pointer properly set?]

79
If F = 0
then F 1
Return.

Algorithm for Deletion Operation:


[Function CQDELETE(Q,F,R) Let Q be a queue consisting of N elements. F and R
are pointers to the front and rear elements of queue. This algorithm deletes and
returns the last element of the queue. Y is a temporary variable.
1.[Check for underflow on stack]
If F =0
Then Write ( UNDERFLOW ON POP)
Return
2. [Delete element]
Y Q[F]
3. [Queue empty?]
if F=R
then FR 0
Return(Y)
4. [Increment front pointer]
F=0;
Return(Y)

80

Double Ended Queue


A queue that supports insertion and deletion at both the front and rear is called
double-ended queue or dequeue. A dequeue is a linear list in which elements can be
added or removed at either end but not in the middle.
Front
Insertion

AA
Insertion

Deletion

Rear

BB CC DD
Deletion

There are two variation of Dequeue namely, an input-restricted Dequeue and an


Output restricted Dequeue which are intermediate between a Dequeue and a queue.
Specifically, an input-restricted Dequeue is a Dequeue which allows insertions at only
one end of the list but allows deletions at both ends of the list; and an output-restricted
Dequeue is a Dequeue which allows deletions at only one end of the list allows insertion
at both ends of the list.

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

Rear (T) Front (ST)

T2

Tn

Rear (ST) Front (O) Rear(O)

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)

Queue according to their priority


This separation of a single priority queue into a series of queues also suggest an
efficient storage representation of a priority queue. When the elements are added at the
end of one of the queues as determined by priority. If one uses a single sequential storage
structure for the priority queue then insertion may mean that the new element must be
placed in the middle of the queue. This can require the movement of several elements.
This, we can say that it is better to split a priority queue into several queues, each having
its own storage structure.

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

External and internal nodes:


If the node does not have any children(i.e. terminal node)then it is called
external node.If the node contains one or more children then it is called a
Internal Node

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.

MEMORY REPRESENTATION OF A BINARY TREE:


There are two types of memory representation
1. Sequential representation
2. Linked list representation

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.

If a complete binary tree with n nodes is represented sequentially as


described before, then for any node with index I, 1<= I <= n, we have
1.PARENT (I) is at [i/2] if I not equal to 1, when I=1, I is the root node and has no
parent.
2.LCHILD (I) is at 2I if 2I<=n, if 2I> n then that root has no left child.
3.RCHILD (I) is at 2I+1 if 2I+1<=n, if 2I>n then that root has no right child.

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

23-1=7. So we require an array of size 7. Fig shows the array

representation
1

2
A

3
B

4
-

5
D

6
-

7
E

Memory representation of a binary tree

LINKED LIST REPRESENTATION:


A natural way to realize a binary tree is to use a linked structure. In this
approach we represent each node of a tree by an object with references to
the element stored at v and the objects associated with the children and
parent v.
Binary tree are most commonly represented by linked lists. Consider a binary tree T.
Each node of the tree consists of three fields.
1. Information field
2.

Left link field

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

Linked list representation of a binary tree


TRAVERSAL OF A BINARY TREE:

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:

Preorder Traversal of the above tree is: ABDXYFCPTOL


Inorder Traversal of the above tree is: XDYBFATPOCL

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.

System Programming & Operating System

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

Program Development Tools:


The program development tools assist users in writing and maintaining programs.
Assemblers, compilers, debuggers and software maintenance system fall into this
category.

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.

Structure Of operating System:


The different operating structures are:

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:

Kernal is that part of operating system that manages system

resources such as memory, processor etc.

i.e. it directly makes interface with the

operating system. The main functions of Kernal are:

To provide a mechanism for a creation and deletion of processes.

To provide mechanism for synchronization of processes so that process


synchronizes their action.

Provide processor scheduling, memory management and I/O management.

Provide mechanism for Inter process communication.

97
Note: UNIX is based on Kernel approach and consists of two separate parts.

System program and Kernel

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

There are two methods to interact with operating system:


Through system Call: System call is a method by which a system makes a
request to operating sytem.Each user program receives the operating system
services through set of system calls. The way the system calls are generated are:
Prompt message to receive file names from terminal.
Open source and destination file.
Display messages if any (In case if source file is protected against access
or there exist another file having same name as destination file).
Read source file
Copy the file into destination file.
Display error messages like No more disk space or End of file reached.
Close both files.
Through Operating System commands : The another way to interact with the operating
system is by using a set of commands like in DOS
Copy<source filename> < Destination file>

The UNIX Operating System

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.

The UNIX Shell


The shell is the UNIX system's command interpreter. It is a program that reads the
lines you type in at a terminal and performs various operations depending on what you
type in. The shell is the part of the UNIX system that sits between you and the "guts" of
the system, forming a shell around the computer that is relatively consistent in its
outward appearance. It attempts to convert your ratings and ravings in instructions that
the computer can understand and act on. Everyone on a UNIX system has his own copy
of the shell program. So a user can do things without bothering or being bothered by the
other users.

WINDOWS AND THEIR FUNCTIONALITY


Windows or Graphic User Interface is a System that gives the standard way to
application programs employing different graphical objects such as Menus, icons, dialog
boxes, mouse and Keyboard.

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)

Most of windows applications gives the same look i.e all


these have same control objects. Thus once we know one or
two windows applications it is easy to learn other
applications.

(ii) Windows provides a device-independent interface to


applications, i.e. a windows application is not bound to the
underlying hardware as mouse, keyboard or display.

101

(iii) Windows provides a multitasking environment which


means that it can perform more than one task at the
same time. Here, multitasking is implemented by using
the principle of timesharing.
(iv) Windows applications can truly interact with DOS
operating system.
(v) It provides a more efficient memory management scheme
to break the 640 K limits of DOS.

Terms relating to Windows


(i)Window: MS- Windows provides a rectangular portion of a screen for user defined
windows. The different menus in the user defined window are
Control Menu: Every application window has an additional menu box placed above left
corner called control Menu. It has options that allow you to move, size and close a
window. A hyphen is the icon for of the control menu. To access the control menu you
just click on the hyphen.
Title bar: It displays the name of the document, application or
directory that you are working with. if you open more than one
Window at a time, then you will notice that the title bar of the active
window is of a different color or intensity.
MENUS : Menus are displayed at the menu bar. It is interesting here that every
action that can be carried out using a mouse can also be done through keyboard.
Handling windows: You may manipulate your window in the following way:
(a)

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.

(b) Moving windows : If desired, we may locate the windows


to another place of our screen by Dragging the title
window to the new location.
(c) Scrolling windows : Some windows have scroll bars that allow
you to view information that may not fit window.
(ii) Icons: Icons are the small bit-mapped regions used to represent Application programs
(word processing or spreadsheets etc) graphically. It may found in variety of forms such
as Program its icon represent applications that can be started from windows.

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

Design specification of an assembler: There are four steps of assembler specification


1.
2.
3.
4.

Identify the information necessary to perform a task.


Design a suitable data structure to record the information
Determine the processing necessary to obtain and maintain the information.
Determine the processing necessary to perform the task.

Various tasks of an assembler:

The task of an assembler would be shown as:


Translation from source to target text =Analysis of source text + Synthesis of target text
Analysis Phase:

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:

1. Obtain the machine operation code corresponding to the mnemonic operation


code by searching mnemonics table.
2. Obtain address of the operand from the symbol table.
3. Synthesize the machine instruction or machine from the constant.
One pass assembler:

103

The translation performed by an assembler is essentially a collection of


substitutions; machine operation code for mnemonic, machine address for symbolic,
machine encoding of a number for its character representation. These all are performed in
a single pass over the source text.
Data Structures

Pass I

source

Pass II

target program

program
Intermediate
code
Design of a Two pass Assembler:

PassI:
1.
2.
3.
4.

Separate the symbol mnemonic opcode and operand fields.


Build symbol table.
Perform Location counter processing.
Construct intermediate representation.

PassII:
1. Synthesize the target program.
Multi-pass assembler:

Most of the assemblers process an assembly program in multiple passes, while


analyzing the statements of the program for the first time, location counter processing is
performed and symbols defined in a program are entered into the symbol table.
During the 2nd pass, when statement are processed for synthesizing target form, no
problems are faced in their addresses are already entered into the different tables.

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

The synthesis task consists of distinct phases.


1. Intermediate code generation
2. Code optimization

Source program
Lexical analysis

Syntax analysis

Symbol table
Semantic analysis

Code generation
& optimization
Lexical analysis:

1. It is the first phase of the compiler.


2. Scanning the program from left to right character by character and groups them into
tokens. Each token represents a logically cohesive sequence of characters.
3. To make entry of tokens into a symbol table if it is not there.
4. To remove all comments, tabs, blank spaces and machine characters.
5. To produce error messages occurred in a source program.
Syntax analysis:

1.
2.
3.
4.
5.

It is the second phase of compilation process.


Obtains a group of tokens from the lexical analyzer.
It checks whether the expression is syntactically correct or not.
Reports syntax errors if any.
Outputting the syntacting structure of a statement in the form of syntax tree or parse
tree.

source Lexical analysis


program

tokens Syntax analysis

parse
tree

Rest of phases

object
code

106

Semantic analysis:

Symbol table

1. It is the third phase of compilation process.


2. To derive methods by which the structures constructed by the syntax analyzer may be
evaluated or analyzed.
3. It checks the source program for semantic errors and gathers data type
information for the subsequent code generation phase. The important component
of semantic analysis is type checking.
4. The semantic analyzer can determine the types of the intermediate results and thus
propagate the type attributes through the tree checking for compatibility as it
goes.
Code generation and Optimization:

1. This is the final phase of compilation process.


2. The code generator takes input as intermediate representation of the source program
and produces as output an equivalent target program.
3. The code generation is concerned with the choice of machine instruction; allocation
of machine registers addressing, interfacing with operating system.
4. To produce faster and more compact code, the code generator should include some
form of code optimization. This code optimization may incorporate both machine
dependent and machine independent.
5.
source program
Lexical analysis

tokens

parse tree

Syntax analysis

parse tree + data types

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

Bits and Bytes ( the binary number system)


The binary, or base 2, number system, there are only two digits namely 0 and 1.
Binary number system is used in the computer to represent information at lowest level. It
is very much easy and simple to store binary digits on electrical, magnetic and
mechanical devices of a computer. Binary number system is used to carry out actual
computer operations. In the computer, all operations ultimately reduced to simple binary
addition.
The binary number system is base 2 number system with symbols 0 and 1, which
is also called as bit. Binary number system is a positional value system. In binary number
system the left most bit carries the most weight and is refer to as the most significant bit
(MSB) and the right most bit carries least weight and is referred to as least significant bit
(LSB).
(10111) 2 is a binary number.
10 1 1 1
MSB

LSB

0x23+1x22 +1x21x1x20

109
8bits =1Byte (B) &

4 bits =1 Nibble.

B is used to represent - Bytes.


b is used to represent - bits.

Note: Memory capacity is expressed in


terms of Bytes.
10 12

Tetra

10 9

Gega

10 6

Mega

10 3

Killo

10 -3

milli

10-6

micro

10 -9

Nano

Pico

10 -12 -

Binary additions and subtractions:


Binary addition is performed in the same manner as decimal addition.
0+0=0
0+1=1
1+0=1
1 + 1 = 0 plus 0 carry over of 1.
Carry-over is performed in the same manner as in decimal arithmetic. Since 1 is
the largest digit in the binary system, any sum greater than 1 varies that a digit can be
carried over.
Decimal
5
6
----------------11
-----------------

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)

The result is 001010.

111

Decimal to Binary
(214) 10

11010110

11010110

(117) 10

01110101

1s Complement 10001010 2s Complement 10001011


-------------Ignore the MSB
1)

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
----------------------------

NUMBER SYSTEM AND BOOLEAN ALGEBRA:

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

Maximum Coversion into decimal form


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

(110110110000101111) 2 = 110 110 110 000 101 111

Octal Equivalence of the above = (6

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

(110110110000101111) 2 = 11 0110 1100 0010 1111

Octal Equivalence of the above = (3

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

FIXED POINT ARITHMETIC


In Fixed Point Arithmetic, all numbers are treated as binary number. Overflow
and underflow cause difficulties in fixed point arithmetic. The result of an arithmetic
operation on two numbers is said to overflow, if both operands are positive but result is
negative. This is because the result has gone out of the range 1 < = x <= 1.
The result of an arithmetic operation on two numbers is said to underflow, if both
operands are negative range -1 <= x <= 1.

Floating

point

Arithmetic:In it all numbers are expressed as +1 m x Re where m is called mantissa. R is


the radix of number system and e is the exponent. Using this representation ,using small
and very large real numbers can be used in arithmetic.
In floating point arithmetic addition, subtraction, multiplication on division of two
floating point operands produces a floating point result. Floating point arithmetic
represents a considerable extension in the range in comp arising with fixed point-form.

Negative Number Representation


They can be represented in two forms.
a) Single magnitude Notation.
b)Complement Notation.

Single Magnitude Notation:


0 indicates +ve and 1 indicates ve between the sign digits must not be
represented as part of the binary number and must not be shifted as part of the binary
number and must not be shifted during arithmetic operation.
Sign
0
+

Number
1111111
127

Sign
1
-

Number
1111111
127

116

Ones and Twos Complement Notation :+127 = 01111111


-127 in ones complement form as -127 = 10000000
Twos complement = 1s complement + 1 = 10000001 = -127 in twos complement.

BOOLEAN ALGEBRA
The three basic operations of Boolean algebra are:
a) Complement
b) OR Operation
c) AND Operation.
BASIC BOOLEAN THEOREMS:

X May take either 0 or 1 value


(X1)1 = X

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

(XY)Z =X(YZ) (X+X) +Z = Z + (Y +Z) = X+Y+Z

LAWS AND THEORIES OF BOOLEAN ALGEBRA

Operations with 0 and 1

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

Simplification theorems 10)X+XY=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)

LOGIC GATES AND BASIC BUILDING BLOCKS

Binary information is represented in digital computers by physical all


entities called signals. Electrical signals such as voltages exist throughout
the computer in either one of two recognizable systems. The two states
represent a binary variable that can be equal to 1 on 0.
Binary logic deals with binary variable and with operations that
assume a logical meaning. It is used to describe, in algebraic or tabular form.
The manipulation and processing of logic circuits called gates.
Name
AND

OR

Graphics Symbol Algebraic


Function
X=A.B

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

The output is low for like


Inputs and high for unlike
inputs.

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

COMBINATIONAL LOGIC CIRCUITS Vs SEQUENTIAL LOGIC


CIRCUITS:

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.

Full Adder Subtract or (Parallel 4 bit adder subtraction)

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

A-B(subtraction takes place parallaly)

------------------------

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

The above circuit diagram of a positive edge trigger JK flip flop.


When level clock is given to capacitor-register circuit, it gives a narrow
spikes for which the JK flip flops responds and changes outputs only when
positive spike is made available for the respective input combinations. For
negative going of the spike and non-availability of the clock period, one
state (high state) of the clock period will not effect the out put at all,
because, they appear as 0 for the inputs of the first set of NAND gates of the
filp-flop. And the function of flip flop of the positive going of the clock for
various input combinations is as shown in the truth given above.

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.

Memory Hierarchy in a Computer System.

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

111100 (No match)


000001(Match)

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

Address space and Memory space split

Block 0
Block 1
Block 2
Block 3
Into groups into groups of 1K words.

Address space n=8K=213


Memory space M=4k=212

101
0
11 1
00 1
0
0
01 1
10 1
0
01

01

01010 1001

0101010011

Main Memory Address


Register

Block 0
Block 1
Block 2
Block 3

133

Arithmetic and Logic Unit and Control Unit.


Users view: The user means; the person employing the computer to do useful work
(like Word processing or Spreadsheet or Accounting) or the person for when the machine
is designed.
Machine / Assembly Language Programming view: The machine language programmer is concerned with the ---- and performance of
the machine when programmed at the lowest, or Machine Language level.
Computer Architects View: The architect is concerned with the design and performance of the machine at the
higher system and sub system.
Computer System Logic Designers View: The Logic designers main focus is on the machine at the digital logic level.

Computer Organization: 1. Logical Organization


2. Physical Organization.
Physical organization to a computer system refers to the functions performed by the
various components and the ways in which they interact with each other.
Physical Organization refers to the way the computers are installed and connected
inside the computer.

Simplest Computer Architecture


Input data

134

INPUT

Control
bus

Address bus

CPU
CONTROL+
ARITHMETIC
Memory

Data bus

Output

Output data (Result).


The person controls all the units of the system using the control lines. Beside
control line, the address---(16 parallel conductors) selects a certain memory location,
input point, on output point. The data (8 parallel conductors)on the 8 is a two way path
for transferring date in and out of the processor unit. The central processing unit(CPU)
can send date to on receive date from the memory using the date ---.
If a program is stored permanently, it is usually placed in a memory device called
a Read Only Memory (ROM). The ROM is usually a permanently programmed chip (IC).
Temporary data memory is usually stored in an IC device called a Read and Write
Memory. In common practice, the read write memory is referred to an a RAM. Computer
user programs that are of a temporary nature also stored in the RAM selecting of memory
along with the data.

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

A two 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

One Stage Logic circuit


S1
So
OPERATION
Ai
Bi
` AND
OR
XOR

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

4-Bit Combinational circuit shifter Shift operation


Serial input (IR)

Select 0 for shift right (down)


1 for shift left (up)
S
Ho

Ao

0
1

A1

A2

0
1
S

H1
H1

H2

0
1
S
0
1
Serial input (IL)

H3

138

Arithmetic logic shift unit:


The ALU is a combinational circuit so that the entire register
transfer operation from the source register through the ALU and into the
destination register can be performed during one clock pulse period. The
subscript l designator a typical stage. Inputs Ai and Bi are applied to both
the arithmetic and logic units, and this circuit is a one bit arithmetic, logic
and shift circuit.

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

Functional Table of ALU


Operation
select
S3

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

Foundation course in Information Technology


Maths - Assignment 1
1. Define function? Explain the different functions in brief?
2. What is a linear function? Give the formula for LF & explain?
3. Explain the meaning for exponential function?
4. What is a set? Explain different sets in existence?
5. Explain the terms
a. Union sets b. Intersection sets c.

Universal sets.

6. What is a Venn Diagram? Explain the diagram in brief?


7. Explain the difference between rational number and an irrational
number?

Computer Organization - Assignment 1


1. How many bytes are there in each of the numbers?
a. 11000101

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

Systems Programming - Assignment 1


1. What is an operating system? Why do we need it?
2. What are the silent features of the UNIX operating system?
3. Compare and contrast command line interface and graphic user
interface?
4. What is a compiler and why do we need it?
5. Compare and Contrast an assembler and a compiler?
C Language Assignment 1
1. Write a program to accept your name, age & fees and display the
values?
2. Write a program to accept a membership no, name and membership
fees and display the values?
3. Write a program to accept a movie name and the production cost
display a movie name 100 times and production cost 500 times.
4. Write a program to calculate the simple interest?
Data and File Structures Assignment 1
1. Explain the concept of data structures and classify them.
2. Define Linked List. How it will be represented in memory?
3. Give the differences between the array and linked lists.
4. Explain the principle of Stacks.
5. How do you define a Queue? Mention and explain the different
types of queues?
6. Give the differences between the circular and linear Linked Lists?
7. Define a binary tree?
8. Write a function to find the factorial of a number using Recursion.

142

Foundation course in Information Technology


Maths - Assignment 2
1. What is matrix? Explain it by a notation?
2. What do you mean by dimension and order of a matrix?
3. Explain in brief the different types of matrices?
4. What do you mean by variables & constants? Explain the term
domain?
5. Explain the different types of functions with suitable example?
6. What is linear programming? Why it is utilized?
7. What is a graph? Mention briefly the application of graph theory?

Computer Organization - Assignment 2


1. Solve the following

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

3. Simplify the following expressions and draw a block diagram of the


circuit for each simplified expression using AND and OR gates.
Assume the inputs are from flip-flops.
a. A B C + A B C + A B C + A B C
b. ABC + A B C + ABC + ABC + ABC + A B C
c. A(A+B+C)(A+B+C)(A+B+C)(A+B+C)
d. (A+B+C)(A+B+C)(A+B+C)(A+B+C)
4. What is the difference between a Latch and a Flip-flop.
5. What is latency and seek time for a disk.

143

Systems Programming - Assignment 2


1. Discuss the functions of operating system?
2. Discuss the structure of an operating system?
3. How is the directory and file organization in the UNIX?
4. Why windows are considered user friendly?
5. Discuss the terms linker, loader, title bar, menu bar.
C Language Assignment 2
1. Write a program to accept a string and print the length of the string?
2. Write a program to accept a string and count the number of uppercase
alphabets, numerals and special characters?
3. Write a program to count the number of vowels of the accepted string
using pointers?
4. Write a program to accept a string and print the same string in the
reverse order using pointers.

Data and File Structures Assignment2


1. What is Dequeue? What are the different types of Dequeue?
2. Mention any 2 applications of a Stack.
3. What are the different tree traversal techniques? Explain them in brief.
4. Define level and depth of a binary tree.
5. What are the different types of linked lists?
6. Give the differences between Binary tree and Strictly Binary Tree.
7. Compare and contrast linear and circular Queue
8. When the Stack Overflows and Underflows?
9. What do you mean by dynamic memory allocation?

144

Foundation course in Information Technology


Model Question paper
Section A - Maths
1. Define a function.
a. Given that f(x) =(x-4) (x+3) find f(4), f(-1) & f(-3)
b. Draw a graph for y = (3x-5)
2. Explain Venn Diagram in detail
a. In a class of 50 students, students study at least one of the
subjects, computers, statistics and maths. 12 students study
computers, 10 students study statistics, 2 students maths, 4
students each study maths and stats, maths and computers and
there is no student studies all the subjects. Find the number of
students who study maths, stats and computers.
3. a. What is a matrix? Explain in brief the types of matrices?
b. In a matrix
4
3
4
2
A= 2
1
and B =
3
1
find (2A + 4B)
0
5
5
2
4. a. Explain the concept of an variable and constant?
b. What do you mean by differential Co-efficient,
differential w.r.t. x for a function given below.
Y = 8x3+4x2+3x+6
5. a. What is linear programming? What are its applications.
b. What is a graph? Briefly discuss the origin of Graph theory?
c. Explain as to how to represent a graph and different graphs in
existence?

Section B Computer Organization


1. Prepare the truth table for the following Boolean expressions.
a. A B + A B

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?

Section C - Data and file structures


1. Write a program to accept an integer and pass the same integer to a
sub function and find the sum of the digits of an integer in the sub
function? (call by value and call by reference)
2. Write a program to calculate the simple interest using a sub function
(by using call by value or call by reference)
3. Write a program to accept an integer and to find the square and cube
using sub function.
4. Write a program to accept an integer in the main function and pass the
same integer in to the sub function and calculate the reverse of an
integer in the sub function. Return back to the main function and print
both the values?

Section D - Data and file structures


I. Fill up the blanks:

1. Array is a ________________type of data structure .


2. Stack works on the principle of __________________.
3. A function calling itself again and again is called as
________________.
4. Four-function calculator is an application of _______________.

146

5. _____________ function is used to allocate the memory


dynamically in C language.
6. Array is ______________. Whereas Linked List is
__________________.
7. Post fix form of A+D-C*E is ___________.
8. Average case time complexity of Insertion sort is
________________.
9. Examples for Non-linear data structure are ______________ and
______________.
10.A root in a binary tree can have maximum of _______ children.
II. Answer the following Questions:
1. Explain Input restricted and Output restricted De-Queue.
2. Define FIFO Queue.
3. Write a recursive function to find the G.C.D of 2 numbers.
4. Explain different types of Linked Lists.
5. Give any 2 applications of Linked Lists.
6. What are the different operations that can be done on a data
structure?
7. What do you mean by linear and non-linear data structure?
8. How do you represent a tree in a memory?
9. Write the differences between iterative and recursive procedure.
10.Explain Complete Binary Tree. With an example.

You might also like