Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Whatsapp 0726 733 444: Mathematics For Computing

Download as pdf or txt
Download as pdf or txt
You are on page 1of 189

4

44
3
73

MATHEMATICS FOR COMPUTING


26
07
p
ap
ts
ha
W
Table of Contents

CHAPTER 1: NUMBER BASES .................................................. 1-1


1.1 Introduction .............................................................................................. 1-2
1.2 Level of Precisions ................................................................................... 1-2
1.3 Number Base ............................................................................................ 1-3
1.4 Column System ........................................................................................ 1-3
1.5 Conversion from Other Bases to Denary ................................................. 1-4
1.6 Conversion from Denary to Other Bases ................................................. 1-4
1.7 Conversion Among Other Base ............................................................... 1-7
1.8 Real Number ............................................................................................ 1-8
1.9 Octal Arithmetic....................................................................................... 1-9
1.10 Hexadecimal Arithmetic ........................................................................ 1-10
1.11 Modular Arithmetic ............................................................................... 1-11
1.12 Past Years Questions.............................................................................. 1-13

4
44
CHAPTER 2: COMPUTER BASED ARITHMETIC ................. 2-1 3
73
2.1 Binary Addition ....................................................................................... 2-2
2.2 Binary Subtraction ................................................................................... 2-3
26

2.3 Binary Multiplication ............................................................................... 2-4


07

2.4 Binary Division ........................................................................................ 2-6


2.5 Number Storage in the Computer Word .................................................. 2-8
p

2.6 Storage of Numbers ................................................................................. 2-9


ap

2.7 Storage of Fractions ............................................................................... 2-12


2.8 Storage of Mixed Numbers .................................................................... 2-12
ts

2.9 Storage of Number Using 2's Complement Method .............................. 2-13


ha

2.10 Ten's Complement ................................................................................. 2-14


W

2.11 Two's Complement ................................................................................ 2-14


2.12 Recomplementing Cases ........................................................................ 2-16
2.13 Shift Operations ..................................................................................... 2-16
2.14 Past Years Questions.............................................................................. 2-18

CHAPTER 3: FLOATING POINT REPRESENTATION ......... 3-1


3.1 Introduction .............................................................................................. 3-2
3.2 Fixed Point and Floating Point Binary..................................................... 3-2
3.3 Floating Point Storage.............................................................................. 3-2
3.4 Floating Point Storage.............................................................................. 3-3
3.5 Floating Point Notation ............................................................................ 3-4
3.6 Normalised Floating Point Form (Decimal) ............................................ 3-4
3.7 Normalised Exponent Exponent Form (Binary) ...................................... 3-4
3.8 Storing Negative Mantissa ....................................................................... 3-5
3.9 Storing Negative Exponent ...................................................................... 3-5

2
3.10 Exercises .................................................................................................. 3-6
3.11 Past Years Questions................................................................................ 3-9

CHAPTER 4: SET NOTATION REPRESENTATION AND


PROBABILITY ............................................................................... 4-1
4.1 Introduction .............................................................................................. 4-2
4.2 Definition of Set ....................................................................................... 4-2
4.3 Notation.................................................................................................... 4-2
4.4 Venn Diagrams ........................................................................................ 4-2
4.5 Relation Between Sets ............................................................................. 4-3
4.6 Properties ................................................................................................. 4-9
4.7 Applications ........................................................................................... 4-10
4.8 Other Logical Relation ........................................................................... 4-11
4.9 Past Years Questions (Set Theory and Venn Diagram) ......................... 4-13

4
44
CHAPTER 5: BOOLEAN ALGEBRA I ....................................... 5-1
5.1
3
Introduction .............................................................................................. 5-2
73
5.2 Logic Programming ................................................................................. 5-2
5.3 Logic and Hardware ................................................................................. 5-3
26

5.4 Language and Symbols ............................................................................ 5-3


07

5.5 Truth Tables ............................................................................................. 5-3


5.6 Logical Equivalence................................................................................. 5-5
p

5.7 Switching Diagrams ................................................................................. 5-6


ap

5.8 Combining Logic Gates ......................................................................... 5-15


5.9 The Algebra of Logic ............................................................................. 5-17
ts
ha
W

CHAPTER 6: BOOLEAN ALGEBRA (II)................................... 6-1


6.1 Introduction .............................................................................................. 6-2
6.2 The Laws of Boolean Algebra ................................................................. 6-2
6.3 Simplification of Expressions .................................................................. 6-4
6.4 De Morgan's Laws ................................................................................... 6-7
6.5 Past Years Questions................................................................................ 6-8

CHAPTER 7: DATA STRUCTURES (I) ...................................... 7-1


7.1 Introduction .............................................................................................. 7-2
7.2 The Concept of Unit Matrix ..................................................................... 7-2
7.3 Arrays and Spreadsheets .......................................................................... 7-6
7.4 Lists .......................................................................................................... 7-8
7.5 Linked List ............................................................................................. 7-10
7.6 Queues.................................................................................................... 7-12
7.7 Stacks ..................................................................................................... 7-13

3
CHAPTER 8: DATA STRUCTURES (II) .................................... 8-1
8.1 Introduction .............................................................................................. 8-2
8.2 Tree .......................................................................................................... 8-2
8.3 Tables ....................................................................................................... 8-4
8.4 Binary Trees ............................................................................................. 8-5
8.5 Traversing of Binary Trees ...................................................................... 8-6
8.6 Binary Search Tree .................................................................................. 8-7
8.7 Searching and Inserting in Binary Search Trees ...................................... 8-8
8.8 Past Years Questions.............................................................................. 8-10

CHAPTER 9: MATRIX AND TRANSFORMATION ................ 9-1


9.1 Introduction .............................................................................................. 9-2
9.2 Definitions................................................................................................ 9-2
9.3 Rules/Matrix Algebra............................................................................... 9-3
9.4 Equivalent Matrices ................................................................................. 9-7

4
9.5 Transformations ..................................................................................... 9-11

44
CHAPTER 10: REPRESENTATION OF INSTRUCTION ..... 10-1
3
73
10.1 Introduction ............................................................................................ 10-2
26

10.2 Construction of an Instruction Word ..................................................... 10-2


10.3 Instruction Word Formats ...................................................................... 10-4
07

10.4 Representation of Instruction and Data.................................................. 10-4


10.5 Addressing Techniques .......................................................................... 10-4
p

10.6 Instruction Types ................................................................................... 10-5


ap

10.7 Exercises ................................................................................................ 10-8


ts
ha

CHAPTER 11: ERRORS AND ACCURACY ............................ 11-1


W

11.1 Introduction ............................................................................................ 11-2


11.2 Mistakes ................................................................................................. 11-2
11.3 Errors...................................................................................................... 11-6
11.4 Measurement of Error ............................................................................ 11-7
11.5 Error Propagation ................................................................................... 11-7
11.6 To Control Errors ................................................................................. 11-14
11.7 Past year Questions .............................................................................. 11-19

CHAPTER 12: STATISTICS ....................................................... 12-1


12.1 Introduction ............................................................................................ 12-2
12.2 Raw Data ................................................................................................ 12-2
12.3 Grouped data .......................................................................................... 12-3
12.4 Presentation of Statistical Data .............................................................. 12-4
12.5 Three Statistical quantities Of Central Tendency .................................. 12-8
12.6 Dispersion and Variation ..................................................................... 12-13
12.7 Past year Questions .............................................................................. 12-19

4
Chapter 1 : Number Bases

Chapter Objectives

At the completion of this chapter, you should be able to:

 identify the different types of numbers;

 convert between denary and other base;

 convert between binary, octal and hexadecimal;

 understand the column system and number bases;

 understand modular arithmetic;

4
44
 hexadecimal, octal addition.
3
73
1.1 Introduction
26

In this chapter, we start to explore various sets of numbers which are used to
represent data in real life problems. Namely, natural numbers, integers, rational,
07

irrational, real and complex numbers. Numbers are used to represent quantities,
measurement, and others in our surroundings. They are essential representations
p

of data that will be processed by computer systems to produce useful information.


ap

The computer system, being a digital electronic device, has to handle data in
binary numbers.
ts
ha

In binary numbers, each binary digit has only two states rather than ten states in
decimal numbers. Therefore, binary, octal and hexadecimal number systems are
W

dealt with in subsequent parts of the chapter.

1.1.1 Number Sets

N Natural Positive integers Example: 3, 71

Z Integers Whole numbers Example: 3, -71

Rational Real numbers which can be expressed as the ratio


Q
of 2 integer Example: 1/2, 0.57, -3

Irrational Real numbers which are not rational Example:


F
2,

5
Real Can be represented by points a the straight
R
line Example: -2.31, 5 , 6

Complex No real number that can satisfy the equation X2


C
= -1 Example:  1 ,  5.75 ,  88

1.2 Level of Precisions


Some translator software have two levels of precisions in storing real numbers.
Namely single-precision and double precision.

4
44
3
73
26
07
p
ap
ts
ha
W

6
1.2.1 Single Precision

The real number is calculated to 8 and displayed to 7 significant figures.

Example:  = 3.1415926 calculated


= 3.141593 displayed

1.2.2 Double Precision

The computer will need longer processing time to produce double precision
numbers. The real number is calculated to 16 and displayed on the screen to 15
significant figures.

Example:  = 3.141592653589793 calculated


= 3.14159265358979 displayed

1.3 Number Base

4
44
A fundamental counting group consists of a number of various symbols.

Counting Groups
3
Symbols of the Group No. of Symbols
73
Binary 0, 1 2
26

Octal 0, 1, 2, 3, 4, 5, 6, 7 8
Hexadecimal 0, 1, 2, 3, ... 9, A, B, C, D, E, F 16
07

Denary 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 10
p
ap
ts

1.4 Column System


ha
W

Enable us to represent any conceivable number by combining numerals and


zeros.

For e example, 423524 is derived from this column system:

Column No 6 5 4 3 2 1
100,00
Value 10,000 1,000 100 10 1
0
Power of
105 104 103 102 101 100
Magnification
Numerals 4 2 3 5 2 4

423524 = 4 x 105 + 2 x 104 + 3 x 103 + 5 x 102 + 2 x 101 + 4 x 100

The Power of Magnification for each individual column is derived as,


Power of Magnification = Base(Column no - 1)

7
1.5 Conversion from Other Bases to Denary
We can use this column system to convert a number in other bases to its
equivalence in Denary.

Example: Convert 1110012 to denary

Column No 6 5 4 3 2 1
Value 32 16 8 4 2 1
Power of
25 24 23 22 21 20
Magnification
Numerals 1 1 1 0 0 1

1110012 = 1 x 25 + 1 x 24 + 1 x 23 + 1 x 20
= 32 + 16 + 8 + 1
= 5710

4
44
Example: Convert 4BEEF816 to denary

Column No 6
3 5 4 3 2 1
73
104857 6553
Value 4096 256 16 1
6 6
26

Power of
165 164 163 162 161 160
07

Magnification
Numerals 4 B E E F 8
p
ap

4BEEF816 = 4 x 165 + 11 x 164 + 14 x 163 + 14 x 162 + 15 x 161+ 8 x 160


ts

= 497649610
ha
W

1.6 Conversion from Denary to Other Bases


To convert a denary number to other bases, we do a repeated division by the
desired base until a quotient 0 is obtained.

Example: Convert 47510 to octal

8 475
8 59 remainder
3
8 7 remainder

8
3
0 remainder
7

The octal number is obtained by reading the last integer 7 and upwards to include
all remainders; 47510 = 7338

Example: Convert 47510 to binary

2 475 remainder
1
2 237 remainder
1
2 118 remainder
0
2 59 remainder
1

4
2 29 remainder

44
1
3 2 14 remainder
73
0
2 7 remainder
26

1
2 3 remainder
07

1
2 1 remainder
p

1
ap

0
ts
ha

47510 = 1110110112
W

1.7 Conversion Among Other Base


We have illustrated the conversions between denary and other bases. How about
converting a binary number to an octal number? Or, an octal number to a
hexadecimal one?

1.7.1 Binary to Octal

We know that 910 = 10012 and 910 = 118 so, we can conclude that 10012 = 118. To
convert a binary number to an octal number in this case will involve a lot of
calculations.

Is there a better way to convert these numbers?

Yes. How many binary bits do we need to represent an octal digit?

Binary Octal
000 0

9
001 1
010 2
011 3
100 4
101 5
110 6
111 7

No. of symbols in octal = 2 no. of binary bits

We need three binary bits to represent symbols in octal! Likewise, one octal
number will produce three binary bits.

To prove it, try whether 3748 = 011 111 1002?

1.7.2 Binary to Hexadecimal

4
Following the same argument, it is not so difficult to see why we need to have

44
four binary bits to represent one hexadecimal number.
3
No. of symbols in Hexadecimal = 2 no. of binary bits
73

Now can you see why 1101011002 = 1AC16?


26

0001 1010 1100


07

1 A C
p
ap

1.7.3 Conversion Between Octal and Hexadecimal


ts

Since every octal number will produce three binary bits, and every four binary
ha

bits will produce one hexadecimal number. We can make use of the binary base
as the “conversion medium” to convert a hexadecimal number to an octal number
W

or vice versa.

Example: Convert 7338 to a hex no.

Step 1. Convert 7338 to a binary number.


111 011 011

Step 2. Rearrange this binary number into 4-bit groups.


0001 1101 1011

Step 3. Convert this binary number to a hex.


1DB
Hence, 7338 = 1DB16

1.8 Real Number


In real numbers, e.g. (4.75)10, the 4 is an integer part while 0.75 is a fractional
part. What is the way to convert 0.75 to a binary fraction? The method is to

10
multiply 0.75 by 2 continuously until the fraction becomes zero or the degree of
accuracy is satisfied.

4.75 = 4 + 0.75 = (100)2 + (0.11)2 = (100.11)2

2 4 0
2 2 0 0.75 * 2
1 1 1.5 * 2
1.0

0.11

Let's look at another example.

(6.1)10 to be converted to binary places.

6.1 = 6 + 0.1 = (110)2 + (0.000110)2


= (110.000110)2 correct to 6 binary places.

4
44
2 6 0
2
3
3 1
73
1 1 0.1 * 2
0.2 * 2
26

0.4 * 2
0.8 * 2
07

1.6 * 2
1.2 * 2
p

0.4
ap
ts

0 . 0 0 0 1 1 0
ha

On the other hand, how can we convert (110.000110)2 to denary real numbers?
W

Method:

i. Write down the value of each bit (binary digit).


ii. Multiply the value by every bit.
iii. Take the sum of products.

4 2 1 2-1 2-2 2-3 2-4 2-5 2-6


1 1 0 .0 0 0 1 1 0

4*1 + 2*1 + 0*1 + 0*0.5 + 0*0.25 + 0*0.12 5 + 1*0.0625 + 1*0.03125 +


0*0.015625

= 6.09375

1.9 Octal Arithmetic

11
We only cover octal addition. The sum of two octal numbers can be reduced by
the usual addition algorithm to the repeated addition of two digits (with possibly a
carry of 1). The following table shows the addition of Octal number.

++ 0 1 2 3 4 5 6 7
0 0 1 2 3 4 5 6 7
1 1 2 3 4 5 6 7 10
2 2 3 4 5 6 7 10 11
3 3 4 5 6 7 10 11 12
4 4 5 6 7 10 11 12 13
5 5 6 7 10 11 12 13 14
6 6 7 10 11 12 13 14 15
7 7 10 11 12 13 14 15 16

The sum of two octal digits, or the sum of two octal digits plus 1, can be obtained
by:

4
44
i. Finding their decimal sum; and
ii.
3
Modifying the decimal, if it exceeds 7, by subtracting 8 and carrying 1 to the
73
next column.
26

Example: 58 + 68 + 28 = 158
07

58
+ 68
p

28
ap

Decimal sum 13
ts

Modification - 8
ha

Octal sum 158


W

1.10 Hexadecimal Arithmetic


As with the octal system, we cover only hexadecimal addition.

The sum of two hexadecimal digits, or the sum of two hexadecimal digits plus 1,
can be obtained by:
i. Finding their decimal sum; and
ii. Modifying the decimal, if it exceeds 15, by subtracting 16 and carrying 1 to
the next column.

If the base exceeds ten, we need mentally to change each hexadecimal letter digit
to its decimal form when finding the decimal sum, and each decimal difference
greater than nine to its hexadecimal form when modifying the decimal sum.

1. A = 10 B = 11 C = 12 D = 13 E = 14 F = 15

Example: A16 + 916

12
A16
+ 916

Decimal sum 19
Modification - 16
Octal sum 1316

1.11 Modular Arithmetic


In our daily life, there are many counting/measuring systems around us. We know
that 100cm is not the same as 100 inches. It's because the measuring units are
different, however, we do not intend to cover the conversions of this kind.

To demonstrate how modular arithmetic works is to give a test first:

“If Peter starts work at 8 o'clock in the morning and works for 8 hours, at what
time will Peter finish work?”

4 o'clock in the afternoon, right? But how you worked that one out? Because the

4
44
clock only has 12 hours, once the shorthand reaches 12, it will restart from 0. The
numbers we see on the clock-face must be less than or equal to 12. This is a finite
set or finite arithmetics. 3
73
To show it mathematically, we add 8 hours to 8 o'clock, and divide 16 by the
modules number 12, the remainder 4 will be the answer we want.
26
07

8 + 8 = 16
(16) mod 12 = 4
p
ap
ts

Example: (11 + 3 + 7 + 9)mod 12


ha

30/12 = 2 remainder 6
W

30 mod12 = 6

Points to Remember

The various sets of numbers include:


 Natural numbers
 Integers
 Rational numbers
 Irrational numbers
 Real numbers
 Complex numbers

The higher the precision required the longer the processing time in computer
systems.

13
4 number systems
 Decimal (Denary)
 Binary
 Octal
 Hexadecimal

Additional of Octal and Hexadecimal


Convert from other base to decimal integer
Step 1. Write down the weight of each digit;
Step 2. Multiply each weight and each digit;
Step 3. Take the sum of the product.

Convert from decimal integer to other bases


Step 1. Divide the decimal integer by the desired base;
Step 2. Write down the remainder;

4
44
Step 3. Repeat dividing until a quotient 0;
Step 4. Read the remainders from bottom upwards.
3
73
Octal and hexadecimal numbers are used as a shorthand for binary numbers.
26

Each octal digit can be expressed as 3 binary digits


07

Each hexadecimal digit can be expressed as 4 binary digits.

Use modular arithmetic when the data is finite.


p
ap
ts

1.12 Past Year Questions


ha

Express the number 7478 in:


W

a. Binary [1]
b. Denary [1]
c. Hexadecimal [1]

Convert showing all working;


d. 21.625 denary to binary [1]
e. 2AE hexadecimal to denary [1]
f. 16.62 octal to binary [1]
g. 567 octal to binary [1]
h. 684 denary to hexadecimal [1]

Convert the following:


i. 157 denary to binary [1]

14
j. 1100110101 binary to octal [1]
k. ACD hexadecimal to denary [1]
l. 2464 octal to hexadecimal [1]

Convert the following:


m. 101 101 101 Binary to Octal [1]
n. DAB Hexadecimal to Denary [1]
o. 2839 Denary to Hexadecimal [1]
p. 7453 Octal to Hexadecimal [1]
Express the denary number 567:
q. in binary [1]
r. in hexadecimal [1]

Express the number 1038:

4
44
s. in binary [1]
t. hexadecimal 3 [1]
73
Convert:
26

u. 274 Octal to DENARY [1]


07

v. DA3 Hexadecimal to OCTAL [1]


p

1. Convert:
ap

w. ABC Hexadecimal to OCTAL [1]


ts

x. 3974 Denary to HEXADECIMAL [1]


ha
W

2. Convert:
y. 7456 Octal to HEXADECIMAL [1]
z. 9E7 Hexadecimal to DENARY [1]

3. Convert:
aa. 8543 Denary to OCTAL [1]
bb. 9AD Hexadecimal to OCTAL [1]

4. Convert:
cc. A25 HEXADECIMAL to BINARY [1]
dd. 549 DENARY to OCTAL [1]
ee. 3527 OCTAL to HEXADECIMAL [1]

Convert:

15
ff. 5391 Denary to HEXADECIMAL [1]
gg. 6A5 Hexadecimal to OCTAL [1]

Convert:
hh. 5743 Denary to HEXADECIMAL [1]
ii. ABC Hexadecimal to OCTAL [1]

Convert the following: (You MUST show all workings.)


jj. 110100102 to Hexadecimal [2]
kk. 54A16 to Denary [2]
ll. 10178 to Binary [2]
mm. 16710 to Binary [2]

Convert the following:

4
nn. 1752648 to base 16 [1]

44
oo. 110110 to base 16 [1]
pp. 728  28 to base 10
3 [2]
73
qq. B0016 + 1F16 to base 2 [2]
26

a. Express the number 2310 in binary [1]


07

b. Express the number 4610 in binary [1]


p

c. Express the number 9210 in binary [1]


ap

d. Express in binary the result of multiplying 1001101112 by 410 [2]


ts
ha

Convert the following:


W

e. 3578 to base 16 [2]


f. 101110 to base 16 [2]
g. 5048  28 to base 10 [2]
h. 6A16 + D0016 to base 2 [2]

What is the BASE of the number system where 36 + 27 = 65? [2]

By converting to BINARY, evaluate the


HEXADECIMAL expression: 7B + EA.
Give your answer in HEXADECIMAL. [2]

a. Evaluate (7 * 4 + 6 * 5) mod 11 [1]


i. Solve (3 * p = 8) mod 11 [2]

16
a. Evaluate (7 * 3 + 5 * 2 + 2 * 1) mod 11 [1]
j. Evaluate (3 * p) mod 5 for p = 0, 2 and 4 [2]

a. Evaluate (8 * 5 + 7 * 6) mod 11 [1]


k. Solve (3p = 7) mod 11 [2]

Evaluate ((4 * 6) + (35 DIV 4)) MOD 11 [3]

4
44
3
73
26
07
p
ap
ts
ha
W

17
Chapter 2 : Computer Based Arithmetic

Chapter Objectives

At the completion of this chapter, you should understand how to:

 perform binary calculation;

 store numbers into computer words;

 integer
 fraction
 mixed number;

 store numbers into computer words using;

4
44
 sign modulus method
 2‟s complement method; 3
73
 perform 2‟s complement subtraction;
26

 shift operations.
07
p
ap
ts
ha
W

18
2.1 Binary Addition
Binary addition for fixed point numbers is done as follows:

The numbers to be added are aligned by their binary points.


Starting from the least significant (rightmost) digit, a corresponding pair of digits
(in the same column) are added according to the rules of binary addition.
If a column has a carry from the previous column, the carry digit has to be added
also.
Repeat steps (ii) and (iii) for each column until the most significant (leftmost)
digit has been added.

2.1.1 Rules for Binary Addition

1+1 = 0  and carry over 1 to add to next column


1+0 = 1 (i.e. 1+1 = 10)

4
0+1 = 1

44
0+0 = 0
3
73

2.1.2 Examples of Binary Addition


26
07

Example:
Binary
p

Decimal equivalent
ap

1010 10
+ 0111 + 7
ts

10001 17
ha
W

Example:
Binary
Decimal equivalent
1010.01 10.25
+ 0111.11 + 6.75
10001.00 17.00

Example:
Binary
Decimal equivalent
111 carry over 1 carry over

101100 44
+ 011101 + 29
1001001 73

19
Example:
Binary
Decimal equivalent
11 carry over

0.11 0.75
+ 0.01 + 0.25
1.00 1.00

2.2 Binary Subtraction

2.2.1 Rules for Binary Subtraction

0-0 = 0
1-1 = 0
1-0 = 1
0-1 = 1  with borrow “1” from the column to the left of

4
the number subtracted from

44
3
73
2.2.2 Examples of Binary Subtraction
26

Example:
07

Binary
Decimal equivalent
11010 26
p
ap

- 01001 - 9
10001 17
ts
ha

Example:
W

Binary
Decimal equivalent
1010.00 10.00
- 1000.11 - 8.75
00001.01 17

The subtraction process can be more clearly illustrated in the following example.

Example:

20
Step 1 Step 2 Step 3 Step 4
1 11 011 011

11000 11000 11000 11000 11000


- 00001 - 00001 - 00001 - 00001 - 00001
1 1 1 10111

Borrow Continue Until a 1 can be changed


changes 0 changing to a 0, then proceed with
to 1 0‟s to 1‟s subtraction

2.2.3 Examples on Successive Borrows in Binary Subtractions

Example: 810 - 210 = 610

0 1

1 0 0 0 = 810
0 0 1 0 = 210

4
44
0 1 1 0 = 610
3
73
Example: 910 - 710 = 210
26

0 1
07

1 0 0 1 = 910
0 1 1 1 = 710
p
ap

0 0 1 0 = 210
ts
ha
W

2.3 Binary Multiplication


A = Multiplicand
x B = Multiplier
C = Product

2.3.1 Rules for Binary Multiplication

0x0 = 0
0x1 = 0
1x0 = 0
1x1 = 1

Copy the multiplicand when the multiplier digit is 1; do not when it is 0. Shift as
in decimal multiplication. Add the resulting binary numbers according to the
binary addition rules.

21
2.3.2 Examples of Binary Multiplication

Example:

Binary Decimal equivalent

1101 13
x 1100 x 12
0000 26
0000 13
1101 156
1101
10011100

Example:

Binary Decimal equivalent

101 5
x 111 x 7

4
44
101 35
101
101 3
73
100011
26

2.3.3 Handling of Carries in Multiplication


07

0 1 1 1
p
ap

x 1 1 1 1
0 1 1 1
ts

0 1 1 1
ha

0 1 1 1
W

0 1 1 1
1 1 0 1 0 0 1
1 carries
1 0
1
1 0

The product is 11010012

22
Example: 410 x 310 = 1210

0 1 0 02 = 410
x 0 0 1 12 = 310
0 1 0 0
0 1 0 0
0 0 0 0
0 0 0 0
0 0 0 1 1 0 02 = 1210

Example: 1010 x 1410 = 14010

1 0 1 02 = 1010
x 1 1 1 02 = 1410

4
0 0 0 0

44
1 0 1 0
1 0 1
3 0
73
1 0 1 0
26

1 0 0 0 1 1 0 02 = 14010
07
p
ap

2.4 Binary Division


ts

Just as binary multiplication is a series of shift and add operations, binary


ha

division is a series of shift and subtract operations.


W

101.1 quotient
divisor 110 ) 10001.0
110
1001 dividend
110
110
110

Binary

Add digit from dividend to group used above. Subtraction possible, so put 1 in
quotient. Remainder from subtraction possible, so put 1 in quotient. Perform
subtraction, and add digit from dividend to remainder. Subtraction possible, so
put 1 in quotient. No remainder, so stop.

Decimal Equivalent

5.5
6 ) 33

23
30
30
30

2.4.1 Example of Binary Division

3210
Example: = (102/3)10 or 10 remainder 2
310

1010.10
11) 100000.00
11
100
11
100
11
10 remainder

4
44
2.5 Number Storage in the Computer Word
3
Computer storage is arranged in words. A word is defined as a unit of data for the
73
machine. Words vary in length on different types of machines. Common word
sizes are 8, 12, 16, 24 and 32 bits.
26
07

A „bit‟, short for binary digit, is in fact the smallest unit of


information stored in a circuit element such as a „gate‟ or
p

Bit moved through the circuitry as a „pulse‟ or „no-pulse‟. By


ap

itself, it is of course limited in its capacity to carry


ts

information.
ha

A 8-bit string of binary bits is known as a byte. It is


Byte
widely used because it corresponds to one character.
W

A word is usually a multiple number of bytes. It is


Word machine dependent and it is the unit of data for the
machine. e.g. 8-bits, 16-bits, 32-bits, etc.
Characters may be represented by binary codes e.g. ASCII
code. Since character codes are normally no more than 8
Character bits in length, there is a tendency to substitute “byte” for
“character” and “character” for “byte” rather
indiscriminately when describing storage capacities.

2.5.1 16 Bit Microcomputers

Most of the popular microcomputer based systems used in schools and colleges
are “16-bit micros”. In these “machines” each word in memory is 2 bytes in
length (i.e. 8-bits). Each word is sufficiently large to hold the binary code for one
character but program instructions are normally too long to fit into a single word
and are therefore spread over two or three words in sequence.

24
2.5.2 32 Bit Machines
Some of the more modern microcomputers are “32-bit micros”. Many mini-
computers are also “32-bit machines”. Each word is four bytes (32-bits) in length,
i.e. the “word length” is 32-bits.

2.5.3 Size Limits of Data


Computer storage is of finite size. This limits the size of numbers which can be
stored and their accuracy.

Example: 16 bit words are common and hold numbers from -32768 to
32767.

2.6 Storage of Numbers


It is important to know the format of storage before interpreting the given 0‟s and
1‟s stored in a computer word. There are many formats of storing numbers:

4
Integer (using sign modulus format)

44
Integer (using 2‟s complement format) Fixed point format
Fraction
3
73
Mixed number
Floating point number
26
07

2.6.1 Storage of Integers Using Sign Modulas Method


Types of numbers
p
ap

 Even if you know that the data is numeric, make sure you have the right
format
ts

  
ha
W

[00110101|11000000]

 = 13760 decimal integer


 = 0.2099609375 decimal fraction
 = 53.75 decimal mixed
and there are many other formats

2.6.2 Storage of Integers

735 decimal = 1011011111 (10 bits)


Add 2 bits “padding” in a 12 bit word

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

By convention, the first (left-hand) bit is the sign bit

25
Therefore only 11 bits are left for the number value

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

Sign bit

For sign modulus method 0 Positive


1 Negative

Small numbers stored in 12-bit words are mostly “padding” bits

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

Sign bit Padding Decimal

4
Padding is not really wasteful, it is necessary to make the calculation methods

44
work properly
The upper limit for storing a number in a 12-bit word is 011111111111 = 2047
3
73
decimal
The range of a given computer n bit word for sign modulus is -(2n-1) to (2n-1 - 1)
26

Larger numbers need double length


07
p

0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 0 0 0 0 1
ap
ts

Sign This bit is ignored


ha

bit
W

7649 decimal = 1110111100001

22 bits can hold 419430310

2.7 Storage of Fractions


First bit still sign bit
Bicimal point not stored
 Implied after sign bit

Decimal 0.4140625

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

26
Sign bit Implied bicimal point “padding”

This representation is exact.

If 11 bits is not enough for exact representation:


 Truncate
 Round off
 Extend to double length (or more)

Double length fraction:

0.7328 decimal

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

Sign bit Implied bicimal Redundant bit Truncated to fit

4
44
 Double length fractions have increased accuracy, not range
3
73

2.8 Storage of Mixed Numbers


26

(Fixed Point Notation)


07

Single word: 11.75 decimal


p
ap

0 0 1 0 1 1 1 1 0 0 0 0
ts
ha

Sign bit Implied bicimal point


W

Divide as necessary

Double word: 74.890625 decimal

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

Sign bit Implied bicimal point Redundant

Usual convention is one word for integral part, the other for fraction

2.9 Storage of Number Using 2’s Complement Method


Sign-modulus method is unsuitable for calculation. Computers usually use 2‟s
complement method to store numbers and calculation.

27
In 2‟s complement method, no sign bit is reserved to indicate the sign of number.
However, if the leftmost bit is 0, it indicates a positive number. If the leftmost is a
1, then it is an implied negative number.

Stored numbers in 2‟s complement method can be defined in 4 stages.

Steps:

Convert absolute value of given no. into binary.


Store binary no. into given computer word.
Check if given no is positive, the steps are completed.
If given no is negative then
4.1 Invert all bits
0  1
1  0

4.2 Add 1 to the inverted no.

4
Example: Store 45 and -45 into 8 bit register

44
To store 45: 3
73
Steps:
26

1. 45 in binary : 101101
07

2. 45 in 8 bit : 00101101
3. Since no. (45) is positive, task is completed.
p
ap

To store -45:
ts
ha

Steps:
W

4. 45 in binary : 101101
5. 45 in 8 bits: 00101101
6. -45: 11010010
+ 1
11010011

The range of number that can be stored in n-bit comp word in 2‟s complement
format is
- (2n-1) to (2n-1 - 1)

Example: in 8 bit word, the range is

- (28-1) to (28-1 - 1) = -128 to 127

2.10 Ten’s Complement

28
8‟ = 2 because 8 + 2 = 10 as such

8 - 2 = (8 + 8) - 10 = 6
6 - 4 = (6 + 6) - 10 = 2

These findings have a significant impact on the arithmatics operation in


computer.

2.11 Two’s Complement


Computers can only do addition, so subtraction is done by adding the
complement of the subtrahend to the minuend.

(Using four bits to store the binary number)

Example:

5 convert to binary 0101


3 convert to binary 0011

4
1100  step 1 invert the bits of 0011

44
2
+ 1  step 2 add 1 to the least significant bit of 1100
3
73
1101  step 3 add the 2‟s complement of 0011 to 0101
+ 0101
26

carry 1 0010  convert to denary is 2


ignored
07
p

2.12 Recomplementing Cases


ap
ts

If the minuend is lesser than the subtrahend then it is necessary to recomplement


ha

the answer and add a minus sign to it.


W

Example:
3 convert to binary 0011
-5 convert to binary 0101
-2 1010  step 1 invert the bit of 0101
+ 1  step 2 add 1 to the least significant bit of 1010
1011  step 3 add the 2‟s complement of 0101 to 0011
0011
1110  step 4 recomplement 1110 and add a minus
0001 sign to the answer
+ 1
-0010  convert to denary is -2

2.13 Shift Operations


Shifting refers to a process whereby it is possible to physically move the pattern
of bits within a computer word to the left or to the right. A number of different

29
types of shift operations do exist. The most common are circular, logical and
arithmetic shifts. We will only be interested in the arithmetic shift operation.

2.13.1 Shift Operations to Achieve Multiplication

If every bit in a 12-bit word is moved one place to the left it immediately has an
associated place-value which is twice that previously associated with it and so the
effect of shifting one place to the left is to double the value of the quantity
originally stored. If shifted two places to the left, this doubling is repeated, so that
the result is now four times the original; three place shifted to the left has the
effect of multiplying the quantity by eight (since 8 = 23) and so on.

Under these circumstances the gaps which occur at the right hand end of the word
as the shifting takes place are filled with zeros and anything shifted beyond the
left-hand end is lost. Additionally, this process is only valid so long as the sign-
bit remains as zero, (although techniques do exist to cope with negative
quantities). But if a positive number is to be multiplied in this way and there is
possible to avoid the difficulty by going into double-length.

4
Example:

44
original binary number
3
73
0 0 0 0 0 0 1 1 0 0 1 0
+ 50
26

 1 place shift to the left


07

0 0 0 0 0 1 1 0 0 1 0 0
p
ap

+ 100 = (50 x 21)


ts

  2 places shift to the left


ha

0 0 0 0 1 1 0 0 1 0 0 0
W

+ 200 = (50 x 22)

   3 places shift to the left

0 0 0 1 1 0 0 1 0 0 0 0
+ 400 = (50 x 23)

2.13.2 Shift Operations to Achieve Division

Just as shifting to the left effects multiplication by the relevant power of two, so
shifting to the right achieves division by the relevant power of two. In this case
the gaps caused by shifting occur at the left-hand end of the word and are
replaced by copies of the sign-bit to retain arithmetic significance: it is in fact
more straightforward to cope with negative values here than in the case of
multiplication. Any bit shifted beyond the right-hand end of the word is lost and
the result is a truncated form of division.

30
If the last bit to be shifted beyond the right-hand end of the word were to be then
added back on to the right-hand end bit the result would be a rounded form of the
same division.

4
44
3
73
26
07
p
ap
ts
ha
W

31
2.14 Past Years Questions
7. If a computer stores integers in one byte using the two‟s complement:
l. What range of integers can be represented? [1]
m. Show how the computer would evaluate -100 -40.
You must show all working. [5]
n. Briefly comment on your results in (b). [1]

a. Determine the range of integer that could be stored in a 6 bits register


in two‟s complement form.
o. Using two‟s complement, evaluate the following numbers which are
stored in 5 bits registers, evaluate the following:
i. 12 - 15 [2]
ii. 15 - 10 [2]

4
44
A particular computer‟s 8 bit registers store number in two‟s complement form.
p. Show how -96 is represented. 3 [1]
73
q. Show how 85 -120 would be evaluated. [4]
26

a. Express 101.101 and -100.11 in binary using 8 bits for the integer part
and 8 bits for the (unrounded) fraction part. [4]
07

r. Convert the fraction 10011100.10100110 to decimal. [4]


p
ap

Calculate the following using complement subtraction, assuming the numbers are stored
ts

in 8-bit registers 13 - 56. [4]


ha

a. If numbers are held in an 8 BIT register in TWO‟s COMPLEMENT


W

form.
i. Write down the COMPLETE range of INTEGERS which can be
held. [2]
ii. Show how 96 - 124 would be evaluated. [4]

b. If a very simple 4 BIT register were to be used.


i. What would the binary representation of 0.710 be? [2]
ii. What denary value would the register actually hold? [1]

32
Show, in BINARY, how a 12-BIT register would hold.
i. The integer -894 using TWO‟s complement. [4]
ii. Show how -894 would be added to ITSELF using TWO‟s complement
and justify that the CORRECT answer is obtained. [3]
iii. Show what happens if -894 is added yet again. [1]
iv. What is this situation called? [1]

Using TWO‟s COMPLEMENT, base 10 integers are to be stored in an EIGHT bit


register.
s. What range of INTEGERS, (expressed in DENARY form) can be
stored? [2]
t. Show how 7110 is represented. [1]
u. Show how -8310 is represented. [2]
v. Show how 7110 -8310 would be evaluated. [3]

4
44
a. If a computer stores integers in two bytes using TWO‟s complement:
i. What is the range of integers which can be represented?
3 [2]
73
ii. How would the computer evaluate 47 -125? Show all your
working. [4]
26

b. Given 1001 0011 0101 in a 12-bit word, interpret this in denary if it is


07

of format:
i. TWO‟s complement. [3]
p
ap

ii. Fixed point number with 6 decimal places. [3]


ts
ha
W

33
Chapter 3 : Floating Point Representation

Chapter Objectives

At the completion of this chapter, you would have learnt how to:

 perform floating point arithmetic;

 perform number storage.

3.1 Introduction
When working with a single-length 12-bit word size we can cope with integral
values in the range of -2048 to +2047. Similar limitations are imposed upon
mixed or fractional values. However, we do have the option of extending these

4
ranges by the use of double-length words but this is not always convenient.

44
A better alternative to fixed-point representation is the floating-point
3
representation. It is capable of holding, in a single-length word, a greater range of
73
numbers. It also uses the same form for coping with integer mixed numbers or
fractions but at a cost of reduced accuracy.
26

Generally, the floating-point form is suitable for handling quantities of far higher
07

values than usual, or whose values are every small.


p
ap

3.2 Fixed Point and Floating Point Binary


ts

For fixed point binary the binary places are fixed.


ha

Example:
W

0000.0000 (4 bits is reserved for integer part and the other 4 bits is
reserved for fraction part)

Using such representation the numbers that can be represented are limited.
Example, if 01110.11 is to be stored using the above format only 1110.1100
could be reflected (note that most significant bit is a sign bit). To be more
precise in representing number the floating-point format is used.
Using Floating Point, 01110.11 could be represented as follow:
01110.11 = 0.1110110 x 2100 (Using 8 bits to store number. The power is
100 or 4 in denary as four decimal places are
shifted)

Floating Point numbers are made up of three parts


 Mantissa (e.g. 0.11101102)
 Base (Radix) (e.g. 2)
 Exponent (Power) (e.g. 1002)

34
3.3 Floating Point Storage
m x BE where

Mantissa can be in
 Sign modulus
 2‟s complement

Exponent can be in
 2‟s complements
 Excess 2n-1 where n is the no. of storage bits for exponent

3.4 Floating Point Storage


Storing numbers in normalised floating point format can be defined with the

4
44
following steps.

Steps: 3
73
Convert given numbers into binary.
26

Check if converted is normalised, if not normalised it.


07

Store mantissa based on given format.


(which can be sign modulus or 2‟s complement.)
p

Store exponent based on given format.


ap

(which can be 2‟s complements or excess 2n-1 method.)


ts
ha

3.4.1 Store Floating Point Format


W

Format A

Sign modulus mantissa and 2‟s complement exponent.


 Floating point numbers are stored using 16 bits. The first bit is the
mantissa sign bit, next 9 are the normalised mantissa and the final six
bits are the exponents in 2‟s complement.
Format B

2‟s complement‟s mantissa and 2‟s complement exponent.


 Floating point numbers are stored using 16 bits. The first ten bits 2‟s
complement mantissa followed by a six-bit 2‟s complement exponent.
Format C

Sign modulus mantissa and excess 2n-1 method.


 The first bit is the mantissa sign bit, the next 9 bits are normalised
mantissa, the final six bits the exponent in excess 2n-1 form.
Format D

35
2‟s complement‟s mantissa and excess 2n-1 method.
 Given 16 bits storage. First 10 bits 2‟s complement mantissa followed
by 6 bits exponent in excess 2n-1 form.
Note: i. For mantissa stored using sign modulus form, 1 bit will be reserved
to represent the sign, the absolute value of mantissa is stored
without including the first bit before the decimal point.

ii. For mantissa stored using the 2‟s complement method, the first bit
before the decimal point will be stored as it indicates the sign of the
mantissa.

3.5 Floating Point Notation


Scientific notation (decimal).

57429 = 5.7429 x 104

4
Mantissa Exponent

44
Mantissa always 1 or greater, but less than 10.
3
73
1 < |M| < 10
26

Exponent always integer.


07

Note: Mantissa can also be negative.


p
ap

3.6 Normalised Floating Point Form (Decimal)


ts
ha

Divide mantissa by 10, increase exponent by 1.


Mantissa now always fraction, 0.1 or bigger.
W

0.1 < | M | < 1

Example: 0.93 x 108, 0.9 x 10-28

Normalisation gets rid of mixed numbers.


 Better for computers.

3.7 Normalised Exponent Form (Binary)


Same principles as decimal.
Mantissa always fraction 0.1 (binary) or bigger.
0.1 < |M| < 1

Exponent is positive or negative integer.

Note: Mantissa needs a sign bit but doesn‟t use two‟s complement.

36
3.8 Storing Negative Mantissa
The mantissa can either be positive or negative. There are two alternative
conventions used for storing the mantissa:

Sign Bit
 „0‟ is assigned if the mantissa is positive;
 „1‟ is assigned if the mantissa is negative.

Two‟s Complement Method.


 The two‟s complement of the mantissa is used if it is negative.

3.9 Storing Negative Exponent


Two alternative conventions also exist with respect to the storage of the
exponent:

4
Two‟s complement form.

44
 The exponent is stored in its two‟s complement form if it is negative
3
and so we do not need to allocate a separate space to hold the sign of
73
the exponent. Although we must always do so for that of the mantissa.
26

Excess 2n-1 code of form.


(where n is the number of bits assigned for the exponent)
07

 In this method, the value of 2n-1 is added to the actual exponent whether
p

positive or negative to give the stored exponent.


ap

Stored Exponent = True Exponent + 2n-1


OR
ts

True Exponent = Store Exponent -2n-1


ha
W

37
3.10 Exercises
Express the decimal number +20.25 in sign modulus mantissa and 2‟s complement
exponent format.

Solution:

Steps:

i. 20.25 = 20 + 0.25
= 10100 + 0.01
ii. = 10100.01
= 0.1010001 x 25

0 1 0 1 0 0 0 1 0

Sign m (in sign modulus do not store 0 before binary point)

4
44
0 1 0 1 0 0 0 3 1 0 0 0 0 0 1 0 1
73

Exponent
26

Note: Format A Question.


07

Express decimal number +20.25 in 2‟s complement mantissa and 2‟s complement
p
ap

exponent.
ts

Solution:
ha

Steps:
W

i. 20.25 = 20 + 0.25
= 10100 + 0.01
ii. = 0.1010001 x 25

iii.
0 1 0 1 0 0 0 1 0 0

(Note: 0 before binary point is stored, an indicator of sign of


mantissa)
iv.
0 1 0 1 0 0 0 1 0 0 0 0 0 1 0 1

Note: Format B Question.

38
Express -20.25 in 2‟s complement mantissa and 2‟s complement exponent format.
Solution:

Steps:

ii. -20.25 = -(0.1010001) x 25


iii. Note: For negative mantissa in 2‟s comp sys, the way of
representation is the same as negative integer that is

i. Invert all bits 01


10
ii. Add 1

Thus

0 1 0 1 0 0 0 1 0 0
1 0 1 0 1 1 1 0 1 1
+ 1

4
44
1 0 1 0 3 1 1 1 1 0 0
73

m
26

iv.
07

1 0 1 0 1 1 1 1 0 0 0 0 0 1 0 1
p
ap

Note: Format B Question.


ts
ha

Express -0.375 decimal in this format.


W

Express 20.25 in sign modulus mantissa and excess 2n-1 method format.
Solution:

Steps:

ii. 20.25 = 0.1010001 x 25

iii.

0 1 0 1 0 0 0 1 0 0

Sign

39
iv. To store exponent in 2‟s excess method

4.1 Find no of bits for exponent in the case 6

4.2 Add excess 2n-1 to actual exponent


26-1 = 25 = 32
4.3 Store exponent 32 + 5 = 37

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

Exponent

Note: Format C Question.

Express -0.375 in sign modulus mantissa and excess 2n-1 method format.

4
Solution:

44
Steps:
3
73
i. To convert given 0‟s and 1‟s in particular format, express string of 0‟s
and 1‟s in m x 2E form.
26

ii. Convert m x 2E to m1 x 20 = m1 (binary).


07

or
iii. Convert m1 to decimal.
p
ap

Express the floating point number 0 110000000 011111 in decimal.


ts

(Note: Format C Question.)


ha
W

Solution:

0 110000000 011111

m e

Steps:

i. 0.11 x 231-32 = 0.11 x 2-1


ii. 0.11 x 2-1 = 0.011
1 1
iii. 0.011 = + = 0.375
4 8

40
3.11 Past Years Questions
8. A floating point number is stored in normalised form using a ten-bit TWO‟s
complement mantissa followed by a six-bit excess 32 exponent.
w. Express 39.41634 in this form. [4]
x. Express 0111011100 011101 as a decimal number. [4]

An 8 bits register is used to store value in excess form.


y. Show how 14 is stored in it. [2]
z. Calculate the true value from 10101011 which is in excess form. [2]

The number 25.828125 is to be stored using a 24 bit word floating point format. First bit
is reserved for sign bit for mantissa, the next 8 bits for exponent in Excess form and
the rest for Normalised mantissa.

4
aa. Show how the number would be stored. [5]

44
bb. Convert 010000100101101000000000 into denary. [4]
3
73
Five bits of computer cell are allocated to store exponent in TWO‟s complement form.
cc. Show how exponent -12 is store in it. [2]
26

dd. Derive the true value from the stored number, in TWO‟s complement
07

form, as shown below: [2]


p

1 0 1 0 1
ap
ts

A normalised floating point number uses a 10 bit TWO‟s complement mantissa followed
ha

by a 6-bit exponent in excess-32 form.


W

ee. Store the denary number -43.123 into the above word format. [5]
ff. Convert the following binary word from the above format into denary.
[5]
101 001 001 0 101 000

A normalised floating point number, using a 10 bit TWO‟s complement mantissa


followed by a 6-bit exponent in TWO‟s complement.
gg. Store the denary number 68.25 into the above word. [4]
hh. Store the denary number -0.1267 into the above word. [6]

The number -17.546875 is to be stored in floating point format is a SIXTEEN-BIT word.


ONE bit is to be used for the sign of the mantissa, the next FIVE bits for the exponent in
TWO‟s COMPLEMENT and TEN bits for the NORMALISED mantissa. Show how the
number would be stored.
[7]

41
a. Show how 23.7 is held in fixed point form with 4 bits after the point.
[2]
ii. What DENARY value is actually held? [1]

In a SIXTEEN bit register, numbers are stored in NORMALISED, FLOATING-POINT


form i.e. MANTISSA (first 10 bits) then EXPONENT (last 6 bits). Each part is in TWO‟s
COMPLEMENT form, with the binary point assumed to be AFTER the LEFT HAND
binary digit of the mantissa.
jj. What DENARY number is represented 1001011010001001? [3]
kk. Express the denary number, -23.875 in this format. [4]

A floating point number is stored in normalised form using a 16 bit word, with the bit
reserved as sign for the mantissa, the next 9 bits reserved for the mantissa itself, and the
remaining 6 bits reserved for the exponent in excess 32 form.
Express -36.4515 in this form. [4]

4
44
A floating point number is stored in normalised form using a 16 bit word, with the first bit
reserved as the sign for the mantissa, and the last 6 bits reserved for the exponent in
TWO‟s complement. The remaining bits are for the mantissa itself.
3
73
ll. Express -16.875 in this form. [4]
26

mm. Express -0.09375 in this form. [4]


07
p
ap
ts
ha
W

42
Chapter 4 : Set
Notation Representation
And Probability

Chapter Objectives

At the completion of this chapter, you should understand:

 the logical requirements of a set;

 how to enumerate and specify sets;

 the use of Venn diagrams;

 problem solving;

4
44
 relations between sets;


3
that in real life problems, we have to deal with likelihood and not 100%
73
certainty. Probability model allows us to evaluate the chances or likelihood;
26

 probability and know the valid range of values of a probability;


07

 Venn Diagram as probability spaced;


p

 and find probability of combined events;


ap

 and use tree diagrams to depict all possible outcomes in a program, it helps
ts

in determining the probability of relevant event.


ha
W

43
4.1 Introduction
Many real life problems can be analysed further as some collection of objects,
each collection of objects may have logical relationship with another. This
chapter will tell us how sets and Venn diagrams can be used to real life problems.

4.2 Definition of Set


A set is a collection of objects, things or symbols, for instance, numbers, names
of people, colours etc.

The individual objects in a set are called elements or members of the set. All the
members of the set have a common feature, which links them in some way.

The elements in a set must be unique.

4
4.3 Notation

44
To identify specific sets, we may either give them names, or just using capital
3
letters.
73

For example:
26

A = {2,4,6,8,10} or {x: x is even integer and 1 < x < 10}


07

B = {1,3,5,7,9} or {x: x is odd integer and 1 < x < 10}


p

C = {CAT, DOG, HORSE, LION, RABBIT, TIGER}


ap

D = {BLACK, BLUE, GREEN, ORANGE, PINK, RED, YELLOW}


ts

E = {x: x is a month in the year}


ha

Take set E as an example, we know that July is a member of E, while Tuesday is


W

not a member of E. We therefore abbreviate the phrase “is a member of” by using
the Greek letter epsilon, , and , to denote “is not a member of”.

As for the above examples, we may write CAT  C, July  E, but Tuesday  E.

4.4 Venn Diagrams


We have learn two methods of expressing a set:

By listing the elements within brackets, {}.


By specifying the main characteristics of the set.

44
Beside these two ways, we can also use diagram, Venn Diagram. Usually a
rectangle is used to denote the universal set U.

For example, U = {1,2,3,4,5}, A = {1,2,3} and B = {4,5} then the Venn Diagram
is

A B

1 4

2
3 5

Figure 6-1

4
44
4.5 Relation Between Sets
3
73
4.5.1 Universal Set

For all problems, there exists a fixed set which called the Universal Set. This is
26

the largest set which contains all the related items.


07

The Universal Set is denoted by U or .


p
ap

4.5.2 The Null or Empty Set


ts

The sets that we discussed above contain at least one element. There are some
ha

sets that do not contain any element at all. We call them the null or empty set.
W

The Empty Set is denoted by  or a pair of empty brackets {}.

Examples of null set are:

The set of pupils in your class who are less than 12 years old.
The set of months with 12 days.
The set of cats in Singapore with four tails.
The set of cars with 68 doors.

45
4.5.3 The Finite and Infinite Set

Question: How many elements are there in the set of English Letters?

Answer: 26 letters i.e. a..z

If we let E be the set of all English Letters, then the number of element in this set
E is 26, and we write as n(E) = 26.

In most of the cases, we are able to tell the number of elements in a set, but
however, there might have cases which we cannot give an exact figure. For
example, the set of even number, the set of prime number that are more than 10
etc.

Definition: A set which contains a definite number of elements is called a


finite set.

A set which has infinite number of elements is called an infinite


set.

4
44
4.5.4 Subset 3
73
A set P is a subset of a set Q if every elements of P is also element of Q, we write
P  Q.
26

Example:
07

U = {1,2,3,4,5,6,7,8,9,10,11,12}
p
ap

A = {2,4,6,8,10}
B = {1,2,3,4,5,6,7,8,9,10}
ts
ha

So, A  B  U
W

B
A 9
2 6
1 8 7
4 10
3 5
11
12

Figure 6-2

Facts
 A = B  A  B and A  B
 The empty set is a subset of every set.

46
4.5.5 Complement

The complement of the set A is the set of elements which are not in A, denoted
by A.

Figure 6-3

4
Examples:

44
If U = {1,2,3,4,5,6,7,8,9,10}, and A = {1,3,5,7}
then A = {2,4,6,8,9,10} 3
73
If U is the set of real numbers, and A is the set of all negative real numbers then A is the
set of all positive real numbers.
26
07

Facts
 The complement of the universal set is the empty set.
p
ap

 The complement of the empty set is the universal set.


ts

 The complement of A is A
ha

i.e. A = (A) = A
W

47
4.5.6 Union

The union of two sets, A and B, is the set of all elements of A and/or B we write.

i.e. A  B = {x : x  A and / or x  B}

U U

A B A B

AB Disjoint Set

U U

4
A

44
A
B
3
73
26

B C
07

BA ABC
p

Figure 6-4
ap

Example: If A = {1,2,3,4} and B = {1,2,5,6} then A  B = {1,2,3,4,5,6}


ts
ha

U
W

A B

3 1 5
4 2 6

Figure 6-5

48
4.5.7 Intersection

The intersection of two sets A and B is the elements which belong to both A and
B, we write A  B.

i.e. A  B = {x : x  A and x  B}

U U

A B A B

AB Disjoint Set


AB=

4
U U

44
A
A
B 3
73
26

B C
07

BA ABC
p
ap

Figure 6-6
ts

Example: If A = {1,2,3,4} and B = {1,2,5,6} then A  B = {1,2}


ha
W

Fact
 If A  B =  then A and B are disjoint.

4.5.8 More Examples

A B

AB

Figure 6-7

49
U

A B

AB

Figure 6-8

A B

AB

4
44
3
73

Figure 6-9
26
07

4.6 Properties
p
ap

Commutative Property
AB=BA
ts

AB=BA
ha
W

Associative Property
(A  B)  C = A  (B  C)
(A  B)  C = A  (B  C)

Distribution Property
A  (B  C) = (A  B)  (A  C)
A  (B  C) = (A  B)  (A  C)

Example: If A = {1,3,5,7}, B = {1,2,3,4} and C = {3,4,7} then

i. A  (B  C) = {1,3,5,7}  {1,2,3,4,7}
= {1,3,7}

ii. (A  B)  (A  C) = {1,3}  {3,7}


= {1,3,7}

Prove the second distribution property law.

50
4.7 Applications
Use of Venn diagrams in Solving Problems

Example:

In a group of 40 boys, 27 like to play basketball, 25 like tennis while 17 like both.
Deduce the number of boys who play neither game.

Solution:

Let B represent the set of boys who play basketball and T represents those
playing tennis. We are told that 17 like both, that means n(B  T) = 17.

Let the number of boys who play neither game be x.

B T

4
44
27 - 17 25 - 17
17
= 10 3 =8
73
x
26

Figure 6-10
07
p

We are given n(U) = 40


ap

therefore, 40 = 10 + 17 + 8 + x
= 35 + x
ts

x = 40 - 35
ha

= 5
W

51
4.8 Other Logical Relation
Venn diagrams in set theory can also be used to describe logical relationship.
Namely AND, OR, XOR and NAND, they can be illustrated clearly on the
diagram.

U U

A B A B

a. A AND B = A  B b. A OR B = A  B

U U

4
44
A B A B

3 C
73
c. A XOR B = (A  B) \ (A  B) d. A NAND B = A  B
26

Figure 6-11
07

In programming, logical expressions are often in selection statements and


p

repetition statements.
ap

Example:
ts
ha

If Age >21 AND height >= 1.70


W

Age >21, this condition will satisfy a set and height >=1.70 will form
another set:

A = {Age: Age>21}
B = {height: height >= 1.70}

The operator AND, has produced a region that is the common region of
both sets, as shown in Fig 6.11a.

52
Points to Remember

A set is defined as a collection of items which share a common feature and all
items are unique.
Use Venn diagram to represent various sets. It is a good model to solve some real
life problem.
Relationship between sets
Subset 
Intersection   AND
Union   OR
Complement A  NOT

 corresponds to

AND, OR and NOT are logical operators available in many computer


languages.

4
4.9
44
Past Years Questions (Set Theory and Venn Diagram)
3
73
9. If the universal set P consists of all integers from 1 to 30 inclusive set Q
26

consists of all prime numbers in the range 10 to 30 inclusive and set R


contains all integers in the range 10 to 20 inclusive. Find:
07

nn. (R  Q) [1]
oo. (R  Q)‟
p

[3]
ap
ts

Draw Venn diagram for the following:


ha

pp. (A‟  B)  (A‟  C) [2]


W

qq. (A  B)  (A  C) [2]

Use a Venn Diagram to represent the following expressions:


rr. A‟  B‟ [1]
ss. A  B  C‟ [2]
tt. AB [1]

The universal set A consists of all integers from 11 to 30 (both numbers inclusive). Let B
be the set of all odd numbers in A, and C be the set of integers in A which can be wholly
divided by 3 (i.e. 12, 15, 18, ..., 30).
Find
uu. B  C [3]
vv. B‟  C‟ [3]

Given the following Universal set U and its two subsets P and Q, where

53
U = { x: x is an integer, 0 <= x <= 10 }
P = { x: x is prime number }
Q = { x: x2 < 75 }
ww. Draw a VENN diagram for the above [8]
xx. List the elements in P‟  Q [4]

Use a Venn Diagram to represent the following:


yy. A‟  B‟  C [3]
zz. (A  B)  C‟ [3]

If the universal set consists of all integers from -2 to 6 inclusive and P = {-2, 0, 3 }
whilst Q = {1, 3, 5 } what are the elements of:
aaa. P‟  Q‟ [2]

4
bbb. (P‟  Q)‟ [2]

44
A computer school has 33 students, each of whom is sitting for examinations in at least
3
one of the following: BCP, RMS, CP. 12 students take all three subjects, 14 take RMS
73
and CP, 16 take BCP and RMS, 18 take BCP and CP, 21 take CP. The same number of
students take BCP as take RMS.
26

ccc. Put all this information into a Venn Diagram, denoting the number of
students who take RMS only and BCP only by X and Z respectively.
07

[5]
p

ddd. Find the values of X and Z. [5]


ap

eee. How many students are sitting only one subject? [2]
ts
ha

Given U = {integer x: 1<= x <= 40}


W

A = {integers between 1 and 20 inclusive}


B = {x: x2 <100}
C = {prime numbers}
D = {multiples of 3}

List the elements (if any) in

fff. A  B [2]
ggg. B  C [2]
hhh. B  D [2]
iii. (C  D)‟ [2]
jjj. B  C  D [2]

In a class of 63 students, there are 27 students who can speak Spanish, 24 French and 20
German. There are 7 students who can speak both Spanish and French, 5 both French and
German, 6 both Spanish and German, and 6 who speak none of the 3 languages. Let n(S),

54
n(G) denote the number of students who can speak Spanish, French and German
respectively. Using the formula:
 (S  F  G) = (S) + (F) + (G) - (S  F) - (S  G) -
(F  G) + (S  F  G)

kkk. Find the number of students who can speak all 3 languages. [4]
lll. Draw a Venn Diagram and fill in the correct number of students in the
diagram. [8]
mmm. F
ind the number of students who can speak only one of the languages.
[4]
nnn. What is the probability of any one student selected at random being
able to speak exactly 2 of the languages. [2]
ooo. If a studious Spanish only speaker learnt French, what would be the
new probability of any one student selected at random being able to
speak exactly 2 of the languages? [2]

4
44
3
73
26
07
p
ap
ts
ha
W

55
A survey of 100 people is conducted to determine how many students excel in the
following subjects: Maths (denoted by M), Science (S) and Arts (A). Given:
The number of students who excel in all 3 subjects: 8
The number of students who excel in both S and M: 23
The number of students who excel in both M and A: 20
The number of students who excel in both S and A: 28
The number of students who excel in S only: 24
The number of students who excel in M only: x
The number of students who excel in A only: y

ppp. Represent the above information in a VENN diagram. [8]


qqq. Given that the number of students who excel in Maths is more by 8 than
those who excel in Arts, derive a pair of simultaneous equations in x
and y. [6]
rrr. Solve these equations. [3]

4
sss. What us the probability of choosing two people at random, both

44
excelling in only one subject? [3]
3
73
Use a Venn Diagram to represent the following:
ttt. A  (B  C)‟ [4]
26

uuu. (A  B‟)  (A  C) [4]


07
p

A survey of fifty athletes found the following to be true:


ap

12 athletes have not won any medals;


ts

8 athletes have won only bronze medals;


ha

10 athletes have won only silver medals;


W

7 athletes have won only gold medals;


2 athletes have won medals of all three types;
8 athletes have won bronze medals and only one other type of
medal;
17 athletes have won gold medals
(but some of them have won other medals too)

vvv. How many athletes have won both bronze and silver medals but not
gold medals? [1]
www. H
ow many athletes have won silver medals and at least one other type of
medal? [1]
xxx. How many athletes have not won any bronze medals? [1]

56
A survey of animals at a zoo records the following facts about each nature; whether it has
stripes; whether it eats meat; whether it climbs trees. Draw separate Venn diagrams for
each of the following animals, shading those areas which represent true facts:
yyy. Zebra (stripes, not a meat-eater, does not climb trees) [2]
zzz. Leopard (no stripes, meat-eater, climbs trees) [2]
aaaa. C
hipmunk (stripes, not a meat-eater, climbs tress) [2]
bbbb. E
lephant (no stripes, not a meat-eater, does not climb trees) [2]

State whether the following statement are TRUE or FALSE:


cccc. F
or sets, A intersect B is equal to B intersect A. [1]
dddd. F
or sets, A union B is equal to B union A. [1]
eeee. F

4
or sets, if A is the complement of B, A intersect B is empty. [1]

44
ffff. For sets, if B is the complement of A, A intersect B is empty.
3 [1]
73
26

Probability
07

Introduction
p
ap

Probability theory is the science of evaluating uncertainty. It provides the means


ts

by which a certain amount of order and predictability may be derived from the
natural state of uncertainty.
ha
W

We can forecast the likelihood of an occurrence by applying probability model on


statistical data collected.

4.10 Definition of Probability


We can measure probability by considering how often an event occurs in relation
to how often it could occur. It is normally given in terms of a ratio. An event is
simply an occurrence.

No. of outcomes that satisfy event E


P(E) =
No. of total possible outcomes

Example: Tossing a coin, throwing a dice.

If a coin, when tossed, has one chance in two of turning up a head, we say that the
probability of getting a head is 1/2. When many coins are tossed, it is likely
that about one half of them will turn up heads. In symbols, we write this as:

57
1
P(Head) =
2

If a dice, when tossed, has one chance in six of turning up with the face
containing six dots, we say that the probability for the face with six dots to
turn up is 1/6. In symbols, we write this as:
1
P(6) =
6

In arranging three letters A, D, P in a row, what is the probability that they will
appear as PAD. What is the probability that they will appear either as PAD
or DAP?
The letter A, D, P can be arranged as follows:

PAD, PDA, DAP, DPA, ADP, APD

Thus, the letters may be arranged in six different ways.

4
Only one of them is PAD. Hence, the probability of the letters appearing as

44
1
PAD is . In symbols, we write this as:
3
6
73

1
P(PAD) =
26

6
07

The arrangement PAD and DAP are two of the total six arrangements. Thus,
the probability of the letters appearing either as PAD or DAP is 2/6 i.e. 1/3.
p

In symbols, we write this as:


ap
ts

1
P(PAD or DAP) =
ha

3
W

Note: Probability can never be less than 0 or greater than 1.

4.10.1 Success and Failure

In probability theory, if an event occurs, we say we have a success. The


probability of a success is defined as:

No. of successes
p=
No. of possible occurences

If the event we are concerned with does not occur, we have therefore a failure.
The probability of a failure is symbolised as q.

No. of failures
p=
No. of possible occurences

Since we have either failure or success for an event, and the total probability is 1,
therefore

58
p+q=1

Example:

10. What is the probability of turning up a number greater than 2 with one throw
of a dice?
11. What is the probability of turning up a number greater than 0?

Solution:

12. The number greater than 2 which are on the faces of the dice are 3, 4, 5 and
6. Thus 4 successful events are possible i.e. s = 4.

There are 2 possible unsuccessful events, therefore f = 2


(i.e. turning up the number 1 and 2).

s
Hence P (number greater than 2) =
f s

4
44
4
=
24
=
3 2
73
3
26

The numbers 1, 2, 3, 4, 5 and 6 are all greater than 0. Hence there are no unsuccessful
events i.e. f = 0
07

s
Therefore P(number greater 0) =
p

f s
ap

6
=
ts

6
ha

= 1
W

Example:

What is the probability of drawing a clubs from a pack of 52 cards?


(There are 13 hearts, 13 clubs, 13 diamonds and 13 spades in a pack.

Solution:

s = 13
f = 13 + 13 + 13
n = f + s = 13 + 13 + 13 + 13 = 52

13
Therefore P(a club) =
52
1
=
4

where s represents the number of ways a successful event can occur.


f represents the number of ways an unsuccessful event can occur.

59
n represents the number of all possible ways an even can occur.

The following list gives example of some common probability:

Events Probability
Certainty of death p=1
Sun rising tomorrow p=1
3
The card you pick is not a heart p=
4
1
Getting heads in tossing a coin p=
2
1
Newly born baby being a boy (girl) p=
2
A man living 300 years p=0

4
44
4.11 Probability Spaces
3
73
Use Venn diagram to depict all possible outcomes in a problem. The number of
elements in each set or subset are clearly visible, when the number of elements of
the Universal set is known, probability of an event may be obtained.
26
07

Example:

Of 21 typists in an office 5 use (M)annual typewriters, (E)lectronic typewriters


p
ap

AND (W)ord Processors; 9 use (E) and (W); 7 use (M) and (W); 6 use (M) and
(E); but no one uses (M) only.
ts
ha

13. Using M, E and W to denote appropriate sets, represent the above


information in the form of a Venn diagram.
W

14. The same number of typists use (E) as use (W). How many use (W) only?
15. How many typists use (E)?

If typists are selected at random and window replacement:

What is the probability that any 1 person selected is able to use only 1 type of machine?
What is the probability that any 2 people selected can both use word processors?

Solution:

16.

60
M
0

1 2
E 5
W
b 4 a

n(E) = N(W) Let a be n(W only)


b+1+5+4 = a+2+5+4 Let b be
n(E only)
b-a = 1 
n(U) = 21
n(U) = a+b+1+2+5+4
21 = a+b+1+2+5+4

4
a+b = 9 

44
Solve eqn 1 and eqn 2 for a and b
3
eqn  + eqn 
73
2b = 10
b = 5
26
07

Substitute into eqn 1


5-a = 1
p


ap

a = 4
ts

The number of typists who use (W) only is 4


ha

n(E) = b+4+5+1
W

n(E) = 15

P(any 1 person selected is able to use only one type of machine)


No. of typist who use only one typeof machine
=
No. of typist
9
=
21
3
=
7

P(2 persons selected can both use word processors)

= P(First person can use word processor and second person can use
wordprocessor)
15 14
= *
21 20
= 0.5

61
4.12 Probability of Combined Events

4.12.1 Addition Law

If the probability of n mutually exclusive events happening are P1, P2, P3... Pn then
the probability that one of these events will occur is:

P1 + P2 + P3 + ... + Pn

Events A and B are mutually exclusive i.e. (P(A and B) = 0)


A B

4
44
4.12.2 General Addition Law 3
73
If A and B are two events then
26

P(A or B) = P(A) +P(B) - P(A and B)


07


p

A B
ap
ts
ha
W

If P(A and B) = 0

 A and B are mutually exclusive events.

Example: What is the probability of getting a 2 or a 3 with one throw of an


ordinary dice?

1
Solution: Probability of getting a 2 =
6
1
Probability of getting a 3 =
6
1 1 1
Therefore probability of getting a 2 or a 3 = + =
6 6 3

Example: What is the probability of getting a number not more than 5 with
one throw of a dice?

62
1
Solution: Probability of getting a 1 =
6
1
Probability of getting a 2 =
6
1
Probability of getting a 3 =
6
1
Probability of getting a 4 =
6
1
Probability of getting a 5 =
6

Therefore the probability of getting a number not more than 5


1 1 1 1 1 5
with one throw = + + + + =
6 6 6 6 6 6

Alternatively, the probability of getting a number more than 5


1
(i.e. a 6) is

4
6

44
Therefore the probability of getting a number not more than 5
3
1 5
73
=1- =
6 6
26

Example: A card is drawn from a shuffled pack of 52 cards. What is the


07

probability of drawing a king or a heart?

Solution:
p
ap

H K 
ts
ha

12 1 3
W

P(king or heart)
= P(king) + P(heart) - P(king and heart)
4 13 1 4
= + - =
25 52 52 13

4.12.3 Multiplication Law

If the probability of n independent events are P1, P2, P3, ... Pn then the probability
that ALL the events will occur is:
P1 x P2 x P3 x ... x Pn

Example: What is the probability of getting four heads in four tosses of a


coin?

63
1
Solution: Probability of head on 1st throw =
2
1
Probability of head on 2nd throw =
2
1
Probability of head on 3rd throw=
2
1
Probability of head on 4th throw =
2
Therefore probability of getting four heads in four tosses
1 1 1 1 1
= x x x =
2 2 2 2 16
In general, P (A and B) = P(A) * P(B\A)
where P(B\A) means probability of B given that A has
occurred.

If A and B are independent then P(B\A) = P(B) (regardless of A)


i.e. P(A and B) = P(A) x P(B)

4
44
What is the probability of obtaining 5‟s with two throws of a
Example: 3
73
dice?
26

1
Solution: Probability of a 5 on 1st throw =
6
07

1
Probability of a 5 on 2nd throw =
6
p
ap

1 1 1
Therefore probability of throwing two 5‟s = x =
6 6 36
ts
ha

4.12.4 Probability of Events that Occur Together


W

Example: What is the probability of getting a sum of 7 with a toss of two


dice?

Solution: Sample space:

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


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

There are altogether 36 sample points.

64
The set of sample points which give a total of 7 is:
E = {(1,6), (2,5), (3,4), (4,3), (5,2), (6,1)}

n(E) 1 1
Therefore the required probability = = or
n(S) 36 6

Example: Suppose we toss a coin and then a dice. What is the sample space
for this experiment? What is the probability of tossing a (H, 6)?

Solution: If S represent the sample then

S = {(H,1), (H,2), (H,3), (H,4), (H,5), (H,6), (T,1),


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

Therefore n(S) = 12

There is only one sample point with (H,6) in the sample space.

4
Therefore n(E) = 1

44
n(E) 31
Therefore P(E) = =
n(S) 12
73
26

where S (sample space) represents all possible events,


E represents the required event.
07
p
ap
ts
ha
W

65
4.13 Tree Diagrams
A (rooted) tree diagram augments the fundamental principle of counting by
exhibiting all possible outcomes of a sequence of events where each event can
occur in a finite number of ways.

Example:

Marc and Erik are to play a tennis tournament. The first person to win two games
in a row or to win a total of three games wins the tournament.

The figure below gives a tree diagram which shows how the tournament can be.
The tree is constructed from left to right. At each point (a game) other than an
endpoint, there originate two branches which correspond to the two possible
outcomes of that game, i.e. Marx (M) winning or Erik (E) winning. Observe that
there are 10 end-points corresponding to the 10 possible courses of the
tournament:

MM, MEMM, MEMEM, MEMEE, MEE, EMM, EMEMM, EMEME, EMEE

4
44
and EE

The path from the beginning of the tree to a particular endpoint describes who
3
73
won which game in that particular course.
26

M M
M
07

M M
E E
p

E E
ap
ts

M M
ha

M M
W

E E
E
E E

Example:

If the probability that you will use a particular spreadsheet system is 3/4 and the
probability that the software loads correctly is 0.9, there are 4 possible results
when you try to use that spreadsheet. Draw the appropriate probability tree to
illustrate this situation and calculate the probability of each of the 4 possible
outcomes.

66
Solution:

3 0.9 Loads correctly


4 Use spreadsheet
0.1 Loads wrongly

0.9 Loads correctly


1 Use spreadsheet
4
0.1 Loads wrongly

3
P(use spreadsheet, load correctly) = x 0.9 = 0.675
4
3
P(use spreadsheet, load wrongly) = x 0.1 = 0.075
4
1
P(use others, load correctly) = x 0.9 = 0.225
4

4
1

44
P(use others, load correctly) = x 0.1 = 0.025
4
3
73
Example: Produce a probability tree to show the eight outcomes of the
26

experiment including the three events that:


1
07

The company database needs updating with a probability of .


4
p

1
ap

The database manager is in a meeting with a probability of .


4
ts

1
ha

The database maintainer is on holiday with a probability of .


4
W

(Hint: Check that the probabilities of these eight outcomes as


shown on the tree do indeed total 1).

67
Points to Remember

Definition of probability

Probability of an event E

No. of outcomes that satisfy event E


P(E) =
No. of total possible outcomes
Range of Probability

0 < P(E) < 1

When P(E) = 0, it means that event E is not possible.


When P(E) = 1, it means that event E is certain.
The occurrence of an event can be treated as success, otherwise a failure.

4
 P(Success) + P(Failure) = 1

44
Venn diagram from set theory, histogram or cumulative frequency diagram from
3
a statistical frequency distribution; normal distribution, they can form
73
probability spaces on which probability of relevant events can be evaluated.
Two cases of combined events
26

 Probability of one of the mutually exclusive events will occur


07

= P1 + P2 + P3 + ... + Pn
 Probability of ALL of the independent events will occur
p
ap

= P1 * P2 * P3 * ... * Pn
ts

Tree diagrams are useful to show all possible outcomes of a sequence of events,
ha

that helps to determine the probability of a combination of events.


W

68
6.14 Past Years Questions (Probability)
17. A computer generates random odd integers from 1 to 9 inclusive. If three
numbers are generated, calculate the probability that:
gggg. A
ll three numbers are three [2]
hhhh. A
t least two of the numbers are five [2]

From a production run of 10,000 RAM chips, 4% of which are defective, one chip is
selected at random
iiii. What is the probability that the chip is defective? [1]
jjjj. What is the probability that it is not defective? [2]

There are ten numbers, from 0 to 9, in a bag. Three draws are made at random without

4
replacement from it.

44
kkkk. W
hat is the probability of having three different numbers?
3 [2]
73
llll. What is the probability that the sum of the three numbers is less than 4?
[2]
26
07

A prime number is an integer, greater than or equal to 2, which can only be wholly
divided by and by itself. A box contains numbers from 2 to 10 (both numbers inclusive).
If 2 numbers are chosen at random without replacement, what is the probability that:
p
ap

mmmm. B
oth are prime numbers? [2]
ts
ha

nnnn. N
either of them is prime number? [2]
W

The probability that a character transmitted is incorrect is 1/8.


oooo. F
ind the probability that three characters transmitted in a row are all
correct. [2]
pppp. F
ind the probability that at least one of the three characters is not
transmitted correctly. [2]

A computer generates random integers from 1 to 6 inclusive. If two numbers are


generated, calculate the probability that:
qqqq. N
either is a 4. [2]
rrrr. At least one of them is a 4. [2]

The probability that the profits of a company will increase in any one year is 0.7.

69
ssss. Draw a probability tree to show all probabilities over two years. [2]
tttt. Show by marking with an asterisk (*) the nodes which represent an
increase in profit in just ONE of the two years. [2]
a. A box contains three pink and five blue balls. The balls are withdrawn
from the box one after another. Assuming that the balls are not
replaced:
i. Draw a probability tree to show the possible outcomes of three
withdrawals. [6]
ii. What is the probability of withdrawing pink, blue, pink balls?
[2]
iii. Find the probability of withdrawing at least two blues balls in
three withdrawals. [2]
iv. Find the probability of withdrawing three pink balls in three
withdrawals. [2]

uuuu. Assuming that the ball is replaced before the next withdrawal.
Repeat all four parts in a above

4
[8]

44
3
There are six apples and twelve oranges in a box. Three draws are made, at random,
73
without replacement.
vvvv. D
26

raw a probability tree to show all the possible outcomes. [8]


07

wwww. W
hat is the probability of getting first draw an apple, second draw an
p

orange and the third and apple again. [2]


ap

xxxx. W
ts

hat is the probability of getting all oranges from the three draws.
ha

[2]
W

A box contains 15 discs, of which 3 are defective. 3 discs are drawn at random
consecutively, without replacement.
yyyy. D
raw a probability tree to show the possible outcomes of the above 3
draws. Use N to represent a draw of a Non-defective disc and D for a
draw of a Defective disc. [8]
zzzz. C
alculate the probability of drawing 2 discs which are all defective.
[2]

In a certain factory, the probability of a disc being defective is 6%.


aaaaa. D
raw a probability tree to show all the possible outcomes for two discs
chosen at random. [4]

70
bbbbb. F
ind the probability that at least one disc from the two is defective.
[2]

a.A basket contains 8 oranges and 2 pears. The fruits are picked at random from
the basket, one after another. Assuming the fruits are not replaced:
i. Draw a probability tree to show the possible outcomes of three
picks. [7]
ii. Find the probability of picking an orange, a pear and an orange in
that order. [2]
iii. Find the probability of picking at least 2 oranges. [3]

ccccc. R
ecalculate i., ii., iii. above assuming the fruits are picked with
replacement. [8]

Eleven football players hang their boots on hooks on a wall. One day, someone who has

4
come to paint the wall takes off all the boots and throws them randomly on the floor.

44
ddddd. I
3
f a player picks up a boot without looking, what is the probability that it
73
is one of his? [2]
eeeee. I
26

f a player picks up two boots without looking, what is the probability


that they are both his? [2]
07

fffff. If a player picks up two boots from the original pile without looking,
p

what is the probability that one is his and one is someone else? Give
ap

your answer as fractions, rather than as decimals. [2]


ts

A student keeps 10 pens in a drawer. Although the pens all look the same, 2 of them have
ha

red ink, 3 of them have black ink, and the remainder have blue ink.
W

ggggg. The student takes two pens from the drawer at random, one after
the other. Assuming that the pens are not replaced:
i. Draw a probability tree to show the possible outcomes from two
picks. [6]
ii. Find the probability of picking both of the pens that have red ink.
[2]
iii. Find the probability of picking at least one pen with black ink.
[2]

hhhhh. The student puts all the pens back in the drawer, and this time
removes the pens, tests them, and replaces them.
i. Draw a probability tree to show the possible outcomes from two
picks. [6]
ii. Find the probability of picking a pen with red ink on both
occasions. [2]
iii. Find the probability of picking at least one pen with blue ink. [ 2 ]

71
A man throws a six-sided dice three times in a row. What is the probability that he:
iiiii. Rolls three sixes. [1]
jjjjj. Rolls no sixes. [1]
kkkkk. R
olls the same number each time. [1]
lllll. Rolls different numbers each time. [2]

4
44
3
73
26
07
p
ap
ts
ha
W

72
Chapter 5 : Boolean Algebra (I)

Chapter Objectives

At the completion of this chapter, you would have learnt:

 the importance of two-state (TRUE/FALSE) logic in computing;

 model logical relations by truth tables, Venn diagrams, switching circuits or


„gates‟.

5.1 Introduction
In programming, especially in selection or branching statements, we need to
specify conditions. These conditions are either satisfied or not satisfied, in other

4
words they are either TRUE or FALSE. Thus understanding of this two-state

44
(TRUE or FALSE) logic is fundamental in programming, it will help to identify
many logic errors that would be made otherwise.
3
73
In digital electronics, devices like digital computers, calculators fundamentally
work on two-state, 1 or 0, (ON or OFF). There are tiny circuit elements which
26

operate on the two states, they are called Logic Gates. In this chapter, we will
know more about AND, OR, NOT, NAND.
07
p

5.2 Logic in Programming


ap

Sooner or later, in all but the simplest of programs, we meet a situation where we
ts

have to write something like “IF so-and-so THEN DO something, ELSE DO


ha

something different”. This means that we must be able to model the problem in
W

two-state logical terms, i.e. outcome is YES or NO.

In many cases, we may be making several logical decisions within a single line of
code. If, for example, we are sorting data into the classes which we used for our
statistical distribution of the run-times, we might well do so by a line such as:

IF x < 7 THEN
C1  C1 + 1
ELSE IF X < 11 THEN
C2  C2 + 1
ELSE IF X < 15 THEN
C3  C3 + 1
ELSE C4  C4 + 1
ENDIF
ENDIF
ENDIF

This involves compound decisions within which each single decision must be
logically correct, without any doubt whatever.

73
This is the realm of two-state logic, also referred to as Binary Logic and we use
„1‟ for true or yes and „0‟ for false or no.

5.3 Logic and Hardware


We shall also need to know precisely how the logical two-state system maps on
to a physical two-state switching system if we become involved with assembly
languages or the theory and architecture of the computer, or if we need to
program any process control applications.

Today such systems, from controlling traffic lights to running the cycles of a
washing machine, embody the logical models in various arrangements of
miniaturised transistor switches in „chips‟. In this context, „yes‟ ordinarily
translates as „switch on‟ and „no‟ as „switch off‟.

5.4 Language and Symbols

4
A different language & some new symbols:

44
STATEMENT

3
Used in two-state logic to mean any single proposition which can only
73
be TRUE or FALSE.
26

We now venture into total certainty, which associates YES with TRUE and
binary 1; NO with FALSE and binary 0.
07

Statements may be COMPOUND, when we associate two or more by the


p

conjunction AND, or by the disjunction OR.


ap

We often use the small letters p, q and r as the symbols for this sort of logical
ts

statement. In particular, the compound statement p ^ q means „the consequences‟


ha

of the two statements in conjunction. The consequences refer to the four possible
results of any compound of two statements.
W

Similarly, p v q indicates the possible results of the disjunction of p, q. „NOT p‟ is


symbolised by ~p.

5.5 Truth Tables


Let us now use our primary tool for simplifying the NOT, AND and OR models,
the truth table.

p q p ^ q (p AND q) p v q (p OR q)
False False False False
False True False True
True False False True
True True True True

74
In logic, we distinguish between OR, meaning in either of the named sets or their
intersection, and XOR (exclusive OR), which means in either but not both.

5.6 Logical Equivalence


The use of truth tables leads also to another condition, the logical equivalence of
compound statements. If the outcomes of two truth tables are identical, the
statements which they represent are logically equivalent and we use the „=„
symbol to represent this state.

For example, ~(p ^ q) = (p~ v ~q)

p q p^q ~(p ^ q) ~p ~q ~p v ~q
0 0 0 1 1 1 1
0 1 0 1 1 0 1
1 0 0 1 0 1 1

4
1 1 1 0 0 0 0

44
The compound statements will often include more than two propositions and the
3
table may then become quite large.
73

If the compound statement were „p AND q OR r‟ we might find that the


26

interpreter we are using automatically takes the „AND‟ before the „OR‟, but is
often safer to use brackets whilst we are working on the model and write it as (p
07

^ q) v r and to insert result, which is p ^ q:


p

p q (p ^ q) r (p ^ q) v r
ap

0 0 0 0 0
ts

0 0 0 1 1
ha

0 1 0 0 0
W

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

With three statements, we must ensure that the program includes all the
combinations which can give rise to 8 possible results.

Example: For the boolean expression

Z = A + B.C
or
Z = A OR (B AND (NOT) C)

The truth table is as follows:

A B C C B.C Z = A + B.C

75
0 0 0 1 0 0
0 0 1 0 0 0
0 1 0 1 1 1
0 1 1 0 0 0
1 0 0 1 0 1
1 0 1 0 0 1
1 1 0 1 1 1
1 1 1 0 0 1

Example: For the boolean expression

Z = (A.B) + C + D
or
Z = (A AND B) OR (NOT C) OR D

4
The truth table is as follows:

44
A B C D A.B
3 C Z = (A.B) + C + D
73
0 0 0 0 0 1 1
0 0 0 1 0 1 1
26

0 0 1 0 0 0 0
07

0 0 1 1 0 0 1
0 1 0 0 0 1 1
p

0 1 0 1 0 1 1
ap

0 1 1 0 0 0 0
ts

0 1 1 1 0 0 1
ha

1 0 0 0 0 1 1
W

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

Truth Tables can be used to prove the logic equality of two different boolean
expressions, as shown in the example below.

Example: To prove:
A.(A + B) = A + A.B = A

Truth table for A.(A + B)

A B A+B A.(A + B)

76
0 0 0 0
0 1 1 0
1 0 1 1
1 1 1 1

Truth table for A + A . B

A B A.B A + A.B
0 0 0 0
0 1 0 0
1 0 0 1
1 1 1 1

The two expressions A.(A + B) and A + A.B are shown to be logically


equivalent, because they have the same outputs in the above truth tables.

4
44
Note also that these outputs are also exactly the same as the inputs for A.

Therefore it is proven that


3
73
A.(A + B) = A + A.B = A
26

5.7 Switching Diagrams


07

It has long been the practice to illustrate such possibilities, in Control Systems, by
p

reference to diagrams showing the switching On and Off of an electric light.


ap

The switching function is carried out, within the computer, by circuits known as
ts

Logic Gates, for which statements have to be converted to electrical voltages, still
ha

identified as „1‟ or „0‟ for „On‟ and „Off‟ but with individual statements, or
Inputs, labelled as A, B, C, and so on whilst consequences, or Outputs, are
W

labelled X, Y, Z.

These „gates‟ are represented in diagrams as shown below but, just as with a truth
table, compound statements may give any number of „inputs‟ and gates may be
combined in many different ways.

A X A X
B B

The AND gate The OR gate


Here A ^ B is represented as A.B and A v B is represented as A + B. So the two-
input AND gate means that to generate a voltage, indicated by „1‟ at the output,
we must apply voltage at all inputs. For the OR gate, a voltage at the output is
generated by an appropriate voltage at any one or more inputs.

If we have a statement, „IF in A AND NOT in B THEN DO ...‟, then we see that
we need to invert an input (or an output) to conform to our logical model.

A A

77
The NOT gate

5.7.1 AND Function (or AND gate)

The AND gate circuit symbol is as follows:

A C
B

A basic AND gate has two inputs A and B, and one output C. All A, B and C are
logical and binary variables which can only be „0‟ or „1‟ i.e. A, B and C are bits
in nature.

4
The analogy of the AND gate is as follows:

44
Switch A Switch B
3
73
26

Lamp C
07

Battery
p
ap
ts
ha

Switch A Switch B Lamp C


W

OFF OFF OFF


OFF ON OFF
ON OFF OFF
ON ON ON

The AND function output C is a 1 (True) only if both inputs A = 1 AND B = 1, or


else, output C = 0. This can be better represented by a truth table which relates
the output to all possible input conditions.

A Truth Table shows the relationship between input conditions and output.

Switch A Switch B Lamp C


0 0 0
0 1 0
1 0 0

78
1 1 1

When input A and B are both „1‟, the output will be „1‟.

Mathematically, this can be expressed in a boolean equation as:

C = A . B (read as A AND B)
or
C=AB

Example: A 3-input AND gate:

A
B D
C

4
is the same as

44
A
3 C
73
B
D
26

C
07

The truth table is as follows:


p
ap

Input Output
ts

A B C D
ha

0 0 0 0
W

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

5.7.2 OR Function (or OR gate)

The OR gate circuit symbol is as follows:

A C
B

79
The analogy of an OR gate is as follows:

Switch A

Switch B
Lamp C
Battery

Switch A Switch B Lamp C


OFF OFF OFF
OFF ON ON

4
44
ON OFF ON
ON ON
3 ON
73
It can also be represented by the following truth table:
26

Switch A Switch B Lamp C


07

0 0 0
p
ap

0 1 1
ts

1 0 1
ha

1 1 1
W

That is, an OR gate output C = 1 if either A = 1 OR B = 1. Otherwise C = 0

Mathematically, this can be expressed in a boolean equation as:

C = A + B (read as A OR B)
or
C=AB

5.7.3 NOT Function (or NOT gate)

The NOT gate circuit symbol is as follows:

A B

80
The action of a NOT gate is quite simple. It functions like an inverter. That is, the
output is the inverted value of the input. For example, if A = 0 then B = 1, and if
A = 1 then B = 0.

The truth table is as follows:

A B
0 1
1 0

Mathematically, this can be expressed in a boolean equation as:

B = A (read as complement A or bar A)

Note: A can also be represented as A‟.

5.7.4 Other Logical Functions

4
44
AND, OR and NOT are known as the basic gates. There are other gates and
logical functions used in computers which are built from the three basic gates.
3
73
NAND function (i.e. NOT-AND function)
NOR function (i.e. NOT-OR function)
26

NAND and NOR gates are known as the universal building elements which are
07

used to build more complex logical functions like the Adder (which we will cover
later in the chapter).
p
ap
ts

NAND gate
ha

The NAND gate circuit symbol is as follows:


W

A C
B

Mathematically, this can be expressed in a boolean equation as:

C=A.B

The truth table is as follows:

A B A.B C
0 0 0 1
0 1 0 1
1 0 0 1
1 1 1 0

81
The 3-input NAND gate circuit symbol is as follows:

A
B D
C

The truth table is as follows:

A B C A.B.C D
0 0 0 0 1
0 0 1 0 1
0 1 0 0 1
0 1 1 0 1
1 0 0 0 1

4
1 0 1 0 1

44
1 1 0 0 1
1 1
31 1 0
73
26

NOR gate
07

The NOR gate circuit symbol is as follows:


p

Mathematically, this can be expressed in a boolean equation as:


ap
ts
ha

A C
B
W

C=A+B

The truth table is as follows:

A B A+B C
0 0 0 1
0 1 1 0
1 0 1 0
1 1 1 0

NAND gate (Universal gate)

NAND gate can be modified to function as NOT gate, OR gate.

B
X
A 82
C
Note: B, C inputs follow from A.

NOT function

A B C X
0 0 0 1
1 1 1 0

OR function

4
x = A+B

44
= A + B (Double negation)3
73
= A . B (DeMorgan‟s Law)
26
07
p
ap
ts
ha

A
W

A
X

B
B

83
5.8 Combining Logic Gates
Many everyday digital logic problems use several logic gates. The most common
pattern of gates is shown below. This pattern is called the AND-OR pattern. The
outputs of the AND gates (1 and 2) are used as inputs to the OR gate (3). You
will notice that this logic circuit has three inputs (A, B and C). The output of the
entire circuit is labelled as Z.

A
(1)
B

(3) Z

(2)
C
(a) AND-OR logic circuit

4
44
A A.B
(1)
B 3
73
(3) Z
26

B.C
(2)
07

C
p

(b) Same circuit with boolean expressions at the outputs of the AND
ap

gates.
ts
ha

A
(1)
W

(3) Z = A.B + B.C

(2)
C

(c) Same circuit with boolean expressions at the outputs of the OR


gates.

Let us first determine the boolean expression that will describe this logic circuit.
Begin the examination at gate (1). This is a 2-input AND gate. The output of this
gate is A.B (A AND B). This expression is written at the output of gate(1) in
figure (b) above.

84
Gate(2) is also a 2-input AND gate. The output of this gate is B.C (B AND C).
This expression is written at the output of gate(2). Next the output of gate(1) and
(2) are OR-ed together by gate(3). Figure (c) shows A . B being OR-ed with B .
C.

The resulting boolean expression is Z = A . B + B . C. It is read as (A AND B)


OR (B AND C). You will notice that the AND-ing is done first, followed by the
OR-ing.

Example: A logic circuit is given as follows:

A
A A+
B B

Z
C
D C+

4
D

44
The boolean expression is Z = (A + B).(C + D)

Example:
3
A logic circuit is given as follows:
73
26

A A.B
07

Z
p

B
ap

C
D
ts

A.B
A
ha

The boolean expression is Z = A.B + A.B


W

5.8.1 Analysing Circuits

A
A
B B A.B.C
C C

A
B
X
C A. B.C

A.B

X = A.B.C + A.B.C + A.B

85
From the diagram, we see that each of the outputs from the 3 AND gates will be a
„1‟ or a „0‟ and they serve as the inputs to the „OR‟ gate which is represented by
the „+‟ sign.

Switching circuits are often over-complicated because they duplicate or even


triplicate or quadruplicate functions. The results of rigorous simplification can,
however, be quite startling.

A A.C
C

X
A A.B
B

X = A.B + A.C
Simplified circuit

4
5.9 The Algebra of Logic
44
3
73
We shall now investigate how to achieve such results using Boolean Algebra.
Note that in two-state logic, we have A, A and two operators, „+‟ as in A + B for
26

„OR‟ and „.‟ as in A.B for „AND‟.


07

Using these symbols, we have


p
ap

A+A =1 A.A =0
A+0 =A A.1 =A
ts

A.0 =0 A+1 =1
ha

With reference to SETS, where  represents union and  represents intersection.


W

A+B=B+A (A OR B = A  B = B  A)
A.B = B.A (A AND B = A  B = B  A)
(NOT A = A‟)

Further examples are illustrated using Venn diagrams:

A.B

A.B

A.B and its complement of „NOT‟ (shaded region)

86
A+B+C
A+B+C
A A.B B
A.B.C
A.C B.C

A + B + C and its complement or „NOT‟ (shaded region)

Points to Remember

Logic Operators Logic Gates Set Notation

4
A AND B AB A.B AB

44
A OR B AB A+B AB
NOT A ~A 3 A A‟
73
AND operator returns true if all inputs are true or operator returns true if one
input is true.
26

Truth Table is used to show all possible outputs with all possible combination of
07

inputs.
2 Inputs give rise to 4 (= 22) combinations
p

3 Inputs give rise to 8 (= 23) combinations


ap

4 Inputs give rise to 16 (= 24) combinations


ts
ha
W

87
Chapter 6 : Boolean Algebra (II)

Chapter Objectives

At the completion of this chapter, you would have learnt:

 to analyse and simplify circuits by Boolean Algebra;

 to draw a logic circuit.

6.1 Introduction
In addition to our „ordinary‟ Boolean algebra, De Morgan‟s Laws is one tool used
for simplifying complex expressions in Boolean algebra or complex switching
circuits.

4
44
6.2 The Laws of Boolean Algebra 3
73
Commutative law
26

A.B = B.A
A+B = B+A
07

Associative law
p
ap

A.(B.C) = (A.B).C = A.B.C


A + (B + C) = (A + B) + C = A+B+C
ts

(A + B) + (C + D) = A+B+C+D
ha

Distributive law
W

A.(B + C) = A.B + A.C


(A + B)(A + C) = A.A + A.B + A.C + B.C = A + B.C

Boolean rules

A . 0 = 0
A . A = A
A . A = 0
A . 1 = A
A + 1 = 1
A + A = A
A + A = 1
A + 0 = A

Properties of absorption

A + (A.B) = A
A.(A + B) = A

88
A + (A.B) = A+B
A.(A + B) = A.B

6.3 Simplification of Expressions


The rules given may be used to simplify Boolean expression, just as the rules of
normal algebra may be used to simplify expression. Consider the expression

(A + B)(A + B)(A + C)

The first two terms consist of A + B and A + B; these terms may be multiplied
and, since A + AB + AB = A and BB = 0, reduced A.

The expression has been reduced now to A(A + C), which may be expressed as
AA + AC. And since AA is equal to 0, the entire expression (A + B)(A + B)
(A + C) may be reduced to AC.

Another expression that may be simplified is ABC + ABC + ABC. First, the
expression may be written A(BC + BC + BC). Then again, we may simplify to

4
44
A[B(C + C) + BC]; and since C + C = 1, we have A(B + BC).

The expression A(B + BC) may be further reduced to A(B + C). The final
3
73
expression can be written in two ways: A(B + C) or AB + AC. The first
expression is generally preferable if the equation is to be constructed as an
electronic circuit, because it requires only one AND circuit and one OR circuit.
26
07

6.4 De Morgan’s Laws


p
ap

The following two rules constitute De Morgan‟s Laws:


ts

(A + B) = A.B
ha

(A.B) = A+B
W

The complement of any Boolean expression, or part of any expression, may be


found by means by this law. Using these rules, two steps are used to form a
complement:

Step 1 The + symbols are replaced with . symbols and . symbols with +
symbols.

Step 2 Each of the terms in the expression is complemented.

The use of De Morgan‟s laws may be demonstrated by finding the complement of


the expression A + BC. First, note that a multiplication sign has been omitted, and
the expression could be written A + (B.C). To complement this, the addition
symbol is replaced with a multiplication symbols, and the two terms are
complemented, giving A.(B.C); then the remaining term is complemented: A(B
+ C). The following equivalence has been found: (A + BC) = A(B + C).

The complement of AB + CD may be formed by two steps:

89
Step 1 The addition symbol is changed.

Step 2 The complement of each term is formed: (A.B) (CD)

This become (A + B)(C + D)

Since A and D were already complemented, they become uncomplemented by the


laws A = A.

An example of showing how DeMorgan‟s laws can be applied.

Show that A.B + A.B = A.B

L.H.S = A.B + (A + B) A.B + A.B


= A.B + A.1 + B = A.B + A + B
= A.B + A.(B + B) + B (OR) = A(1 + B) + B
= A.B + A.B + B = A+B
= A(B + B) + B = A.B
= A+B

4
= A.B = R.H.S

44
3
73
The problem may also be solved by drawing a truth table:
26

A B A B A.B A.B A.B A.B + A.B


07

0 0 1 1 0 1 1 1
0 1 1 0 0 1 0 1
p
ap

1 0 0 1 0 1 0 1
ts

1 1 0 0 1 0 0 0
ha
W

Law of double complementation

A=A
A+B = A+B
A.B = A.B

Example: Simplify (A + B).(A + B) + A.(A + B)

Solution: (A + B).(A + B) + A.(A + B)


= A + B + A.(A + B)
= A + B + 0 + A.B
= A + A.B + B
= A+B

Example: Simplify A + (B.C) + C.B

90
Solution: A + B.C + C.B A + B.C + C.B
= A . B.C . C.B = A . B.C . C.B
= A .B.C (C + B) OR = A . B.C . C.B
= A.B.C (C + B) = A.B.C
= A.B.C + A.B.C.B
= A.B.C

Points to Remember

Boolean algebra and De Morgan‟s laws are two tools to simplify complicated
logic expressions or logic circuits.

6.5 Past Years Questions


Draw the logic circuit for the following expression using NAND gates only.

4
44
ABC [4]
3
73
Using Boolean algebra, simplify:
(A + C).BC + AC + B [5]
26
07

Using Boolean algebra simplify:


p

ABC + AB (ABC + (A + B + C) [3]


ap
ts

a. Using a Boolean algebra, simplify the expression: A(B + ABC + AC).


ha

[5]
W

mmmmm. F
rom the simplified expression, draw the logic circuit. [2]

a. Use Boolean Algebra to show that:


(A.B + B.C + A.C).(A.B.C) = A.B.C + A.B.C + A.B.C [4]

nnnnn. Draw a logic circuit for the expression.


AB.C + A.B.C + A.B.C [4]

a. If X = A.B + C + A, create a TRUTH TABLE for X. [5]


ooooo. U
sing the truth table, show that X can be represented by a single NAND
gate. [2]

If X = AB + C
ppppp. Using a De Morgan‟s Laws only, prove that

91
X=A+B+C [4]

qqqqq. R
epresent X = AB + C using NAND gates only. [4]

a. A, B and C are switches in the electrical circuit shown below. If a


switch is on, it has a Boolean value of „1‟, otherwise it has „O‟. The
light bulb will light if C = 1 and either A = 1 or B = 1. The light bulb
„X‟ has a Boolean value of „1‟ if it is lit, otherwise it has the value „O‟.
i. Draw a truth table relating the inputs (A, B and C) to the output X.
[4]
ii. Write down, but do not simplify the Boolean Expression of X.
[4]
iii. Simplify the expression using a Boolean Algebra. [4]
iv. Redesign the circuit using NAND gates only. [4]

rrrrr. Using only De Morgan‟s law and Boolean algebra simplify:

4
44
(A + C).AB + BC + A [4]

3
73
a. Simplify using Boolean algebra (AB + AB). [4]
sssss. F
26

rom the following truth table, obtain the expressions for „yes‟ and „no‟
for X and simplify them using Boolean algebra. [ 10 ]
07
p

A B C X
ap

0 0 0 1
ts

0 0 1 1
ha

0 1 0 1
W

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

ttttt. Construct the logic circuit for simplified „yes‟ and „no‟. [6]

In a beauty contest, three judges A, B and C can register their votes as „I‟ or „O‟ through
switches allocated to them. Contestants will be disqualified if two or more judges register
„O‟ votes for them.
uuuuu. C
onstruct a truth table for the above. [6]

92
vvvvv. U
se a Boolean Algebra to obtain a simplified Boolean expression for the
outputs „qualified‟ and „disqualified‟. [ 10 ]
wwwww. C
onstruct a logic circuit for the simplified disqualified output. [4]

a. Find an expression for X from the following truth table and simplify it
using a Boolean algebra. [6]

A B C X
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1

4
1 0 1 1

44
1 1 3 0 1
1 1 1 1
73
26

xxxxx. D
raw a logic circuit for the expression derived in part a. above. [4]
07

18. a. Simplify the following expression using Boolean Algebra:


p
ap

(AB + AC).(A.B + (B + C)) [8]


ts

yyyyy. U
ha

sing a Boolean algebra only, prove that the expression A.


W

(AB + BC) = A.B [6]


zzzzz. O
btain an expression for X from the following truth table, and simplify it
using a Boolean algebra. [4]

A B C X
0 0 0 1
0 0 1 0
0 1 0 0
0 1 1 0
1 0 0 1
1 0 1 1
1 1 0 0
1 1 1 1

93
aaaaaa. D
raw the logic circuit for the expression derived in part (c). [4]

4
44
3
73
26
07
p
ap
ts
ha
W

94
When X = (A + C).(A.B + C)
bbbbbb. C
reate a TRUTH TABLE for X including columns for
(A + C), (A.B + C) and (A.B + C) [6]
cccccc. P
roduce a Boolean expression for this table [2]
dddddd. U
se ONLY De Morgan‟s laws and Boolean algebra to simplify the
original expression for X. [4]

A manufacturing process has three status checks, A,B and C. The process continues
without interruption, if one of the following conditions holds:
all three have a value of 1,
all three have value of 0,
A has a value of 1 and ONE of B or C has a value of 0
A has a value of 0 and C has a value of 1

4
eeeeee. I

44
f the process continues, write down, in terms of A, B and C an
appropriate Boolean expression. 3 [4]
73
ffffff. U
se a Boolean, algebra to simplify this expression. [6]
26

gggggg. I
f the process is interrupted, an electronic signal is produced. Draw the
07

logic circuit necessary to produce such a signal. [5]


p
ap

Using Boolean Algebra prove


ts

A(B + AC) + AC + ABC + BC = A + B + C [5]


ha
W

A spaceship is exploring the distant planet IDCS. There are four components of the
spaceship which are important for landing: the rockets (R); the navigation system (No);
the wheels (W), the hull (H). Because the planet IDCS is so far away, these components
break down quite often. The spaceship can only land if one or more of the following
conditions are met:
i. the hull (H) is functioning and either the rockets (R) or the wheels (W)
are functioning.
ii. the rockets (R) and wheels (W) are both functioning.
iii. the navigation (N) system is functioning and the rockets (R) are
functioning.

hhhhhh. C
onstruct a truth table which indicates whether landing is possible or not,
for all values of R, W, N and H. [8]
iiiiii. Write a Boolean expression which states the conditions under which the
spaceship can land. Simplify your answer as much as possible. [4]

95
jjjjjj. Design a logic circuit to implement the Boolean expression you derived
as your answer to part (b). Use only 2-input AND, 2-input OR and/or l-
input NOT gates (as many of each as is necessary). [4]
kkkkkk. S
uppose the spaceship is approaching to land with all its components in
full working order, when the following events occur, in order:
i. the rockets fail.
ii. the navigation system fails.
iii. the wheels fail.
iv. the hull fails.

After which event will the spaceship be unable to land? [2]

llllll. If, instead of having four components important for landing, a new,
improved spaceship had six such components, how many entries would
be needed in a truth table to cover all the possible combinations of
components‟ functionality? [2]

4
44
3
73
26
07
p
ap
ts
ha
W

96
Chapter 7 : Data Structures (I)

Chapter Objectives

At the completion of this chapter, you would have learnt:

 the basic concepts of different data structures;

 how to acquire the ability to relate the types of data structures to real life
application.

7.1 Introduction
A data structure specifies interrelationships among data. Each data structure has
unique characteristics that make it different from any other.

4
44
The study of data structures involves learning about the various interrelationships
that data can have within each unique structure.
3
73
It is important for you to understand that the data maybe unchanged, while data
structures do change.
26

The study of data structures is important for the system analyst and programmer
07

in the designing of Database Management Systems.


p
ap

7.2 The Concept of Unit Matrix


ts

Constructing of People Matrices for Four Grade of Staff


ha

Below are tables showing the various number of staff for different grades and
W

categories for two towns, together with their salaries.

By organising the numbers logically the following matrices are then constructed.

Andover Town.

Andover
Category ~
Grade A B C D E F A
1
1 0 2 5 16 0 0 0 2 5 0 0
6
1 1 2
2 2 12 12 27 5 1 2 5 1
2 2 7
2 1
3 0 0 24 15 3 2 0 0 3 2
4 5
1
4 0 0 10 9 2 1 0 0 9 2 1
0

97
Bristol Town.

Bristol
Category ~
Grade A B C D E F B
1
1 0 3 18 0 0 1 0 3 0 0 0
8
1 1
2 1 4 12 18 2 1 1 4 2 1
2 8
1 1
3 0 0 16 14 5 1 0 0 5 1
6 4
4 0 0 8 6 1 0 0 0 8 6 1 0

The wage matrix.

4
44
Bristol
Category 3 ~
Grad
73
A B C D E F W
e
1 1 1 1 1 2 2 1 1 1 1 2 2
26

2 2 2 3 3 4 5 2 2 3 3 4 4
07

3 3 3 4 4 6 8 3 3 4 4 6 8
1 1
p

4 8 8 9 9 10 12 8 8 9 9
0 2
ap
ts
ha

Addition of Matrices
W

~ ~ ~
A+B=T

The resultant matrix T can be gotten by simply adding the corresponding


elements of the individual matrices. Hence by adding the matrices of the two
towns the total staffs can be obtained.

Andover Bristol Total


0 2 5 16 0 0 0 3 18 0 0 1 0 5 23 16 0 1
2 12 15 27 5 1


 + 1 4 12 18 2 0 = 3 16 27 45
 7 1
0 0 24 15 3 2 0 0 16 14 5 1 0 0 40 29 8 3
     
0 0 10 9 2 1 0 0 8 6 1 0 0 0 18 15 3 1

7.2.1 Types of Multiplication with Unit Vectors

Pre-Multiplication with Row Vector.


Post-Multiplication with a Column Vector.

98
Multiplication of a Matrix with a Row Vector

(Pre-Multiplication of a Matrix with a unit vector)

~ ~ ~
U*A=R

To sum up all the people “Vertically” under the respective category (i.e. from A
to F) multiply by a row vector.

0 2 5 16 0 0
 
1 1 1 1 * 2 12 15 27 5 1
0 0 24 15 3 2
 
0 0 10 9 2 1
Row Vector Andover

4
A B C D E F

44
= ( 2 14 54 67 10 4 )

Question:
3
Can the Andover matrix be Pre-Multiply by a column vector?
73
26

Multiplication with Column Vector


07

(Post-multiplication of matrix with a unit vector.)


p
ap

~ ~ ~
R*U=S
ts
ha

To sum up all elements “horizontally” across, the matrix is Post-Multiply by a


column vector (i.e. to add 2 + 14 + 54 + 67 + 10 + 4).
W

1 
1 
 
[2 14 54 67 10 4] *  1  = (151)
 
1 
1 
 
 1 

column vector

Question: Can you Post-Multiply by a row-vector?

Calculating the Total Wage Bill

The total wage bill for grade 2 and 3 in category C to E, is obtained by Pre-
Multiply by the appropriate row vector.

99
(Note: the one‟s and zero‟s in the row and column vector.)

CATEGORY

0 
1 0 5 23 16 0 2  0 
  
[0 1 1 0] * 2 6 32 81 135 28 5 *  1 
3 0 0 160 116 48 24  1 
   
4 0 32 162 135 30 12  1 
 
 0 

Question: Can you understand the meaning of the multiplication above?

Increasing/Decreasing by Matrix Method

To increase the wages by 5%, 6%, 4%, 8% for the respective grade, set up the
matrix „I‟ below.

4
44
1.05 0 0 0 0 5 23 16 0 2
 0 1.06 0 0 * 6 32 81 135 28 5

3
 0 0 0 0 160 116 48 24
73
0 1.04
   
 0 0 0 1.08 0 32 162 135 30 12
26

matrix I WAGE MATRIX


07

Question: Can you understand the logic of matrix I?


p
ap
ts

NCC QM DEC. 92 Part Question


ha

Question 8
W

a. A family buys Milk, Bread and Eggs at unit price of 42,74 and 12 cents
respectively the following quantities:

Milk Bread Eggs


Mondays 2 0 6
Tuesday 1 1 12
Wednesday 0 2 0
Thursday 3 3 12

b. Show the quantities as a 4x3 matrix, N, and the prices as a 3x1 matrix P.

c. Calculate each of the following and state what the result means:
i. A = N*P (3) (3)
ii. B = (1111)*A (2) (2)
iii. C = (1111)*N (2) (2)

100
iv. D = C*P (2) (2)

7.3 Arrays and Spreadsheets


It is especially easy to manipulate arrays using spreadsheets. It allows very quick
calculation and re-calculation of large matrices. This allows WHAT IF‟ analysis
to be performed. Try this out during your Lotus 1-2-3 lessons.

Arrays on paper is limited to 2 dimensional but multi-dimensional array can


specify on spreadsheets and even in programming languages more than 2
dimensional arrays are required to store related variable. For example, in the
analysis of aircraft movement such as pitching yaw and rolling.

Aircraft Analysis Arrays in Programming


Languages
Y
12 YA DIM A(25)
9 3 M
6 SPEE NUM[1,2]

4
D

44
TIM PITCHIN
E G Which is Which?
ROLLIN 3 (BASIC, PASCAL)
G
73

How many Dimensional Array Required?


26

Ans: (1, 2, 3, 4 or 5)
07

Another use of the array is the storing numbers and string arrays respectively.
String arrays can be operated on by concatenation of the elements in the
p
ap

respective arrays.
ts

Array addresses, in the computer can be assigned by having two bytes for each
ha

number. For an array size of 4*7, the total number of bytes 4*7*2 = 52, the first
quarter 14 bytes are the first row and next 14 bytes for the next row and so on.
W

7.3.1 Elementary Array Operations

(Examples of the use of arrays in Pascal programming.)

Student Geograph Mathematic


Science History
Number y s
1307 46 58 24 49
1314 71 42 54 83
1318 24 17 20 19
1321 83 46 53 78
1327 75 58 62 88
1334 40 32 6 47

Example: {This program fills the array row by row.}

101
For Row : = 1 to 6 Do
For Col : = 1 to 5 Do
Readln(Table [Row, Col]);

Example: {This program fills the array column by column}

For Col := 1 to 5 Do
For Row : 1 to 6 Do
Readln(Table [Row,Col]);

7.4 Lists
A record consists of different data items stored in an array.

Below is a list consisting of four data items that are not linked. An example is
given below.

Four lists which must stay „linked‟.

4
44
Inv. No. Cust. No. Date Amount
Rec. 1 Rec. 1
3 Rec. 1 Rec. 1
73
26
07
p
ap
ts
ha
W

Four lists which must stay „linked‟

An Example of a Linked Record

Try the following quiz by matching the device to the explanation. This will
provide a better understanding of linked records.

1. Modem A. A device used to receive signals from one


circuit and automatically repeat and amplify
and reshape the signals to another circuit.

2. Front-End Processor B. A system which removes some of the


processing load from a central computer,
typically handling communication co-
ordination functions before the data is sent to
the central system for processing.

102
3. Repeater C. Devices needed at the ends of an analogue
transmission line to translate between the
digital code of computers and the analogue
wave form; an abbreviation for modulation -
demodulation.

4
44
3
73
26
07
p
ap
ts
ha
W

103
7.5 Linked List
A linked list, or one-way list, is a linear collection of data elements, called nodes,
where the linear order is given by means of pointers. That is, each node is divided
into two parts : the first part contains the information of the element, and the
second part, called the link field or next pointer field, contains the address of the
next node in the list.

Example: Linked list with 3 nodes

Name
or
Start

Nextpointer field
Information part

4
44
A more useful application of a list is a linked list. The Invoice Number, Customer
Number, Date and Amount are linked by a two way pointer.
3
73
Inv. No. Cust. No. Date Amount
26

Rec. 1
07

Rec. 1
p
ap
ts

Rec. 1
ha

Rec. 1
W

Two way pointers

The list after ordering

Accessing any of the data items allows the access to the others

104
Example:

A LINKED TABLE holding KEY numerical values in ASCENDING order of


which the POINTER „LISTSTART‟ holds the value 2, contains:

INDEX KEY LINK TO NEXT


LISTSTART RECORD
2 1 96 3
2 84 1
3 105 -1

i. Re-write the table as it would appear if we added, at INDEX 4 THE KEY 95


and KEY 110 at INDEX 5 (4).

4
44
ii. Show the original table as it would appear if KEY 96 were DELETED (2).

 solution for part c(i);


3
73
26

INDEX KEY LINK TO NEXT


LISTSTART RECORD
07

2 1 96 3
p

2 84 4
ap

3 105 5
ts
ha

4 95 1
W

5 110 -1

 solution for part c(ii)(to be solve in class)

7.5.1 System Lists

Program location in main memory and its control during execution by linked list
for example calling of subroutines by main programs.

By managing pointers locations, the economy of storage and speed of execution


are achieved.

105
S/ROUTIN
PROCESS PROGRAM
E
Spool Line 1
Line 1 :
: :
S/R call Line „n‟
:
Line „n‟

Program Lists with pointers

7.6 Queues
The queue is yet another data structure which differs in a number of ways from

4
the stack. It may be used in real-time processing, for scheduling of jobs in the

44
context of an operating systems or in other similar applications such as data
transfer. 3
73
It is a FIFO (First-In-First-Out) structure which means that the first item to enter
the queue is the first item to leave and new items always get added to the end of
26

the queue.
07

As with the stack we can represent a queue by a one-dimensional array with the
need for two pointers. The first to indicate the front of the queue and the other to
p

indicate the next space capable of holding an element joining the queue, these
ap

being the head and tail pointers respectively.


ts

A method of inserting and retrieving data is similar to a stack but on „FIRST-IN-


ha

FIRST-OUT‟.
W

1
Head 1
Pointer 2
3 1. „POP‟
2. „LIST‟
4
2 3. „PUSH‟
5
6
3 7
8

The queue operation is awkward because the elements are pushed to the front and
new elements are added from the bottom, sometimes referred to as a PUSHUP
STACK or LIST.

Other types of queues can be the DEQUE (or DOUBLE - ended - Queue) and the
WRAP - AROUND - STACK.

106
7.6.1 DEQUE

Data are push and pop (add and delete) from both ends.

7.6.2 Wrap-Around-Stack (Circular queue)

In this type the tail pointer cannot be pushed out but moves in a circular manner
ahead of the head pointer.

direction of
tail pointer
6 7
tail
pointer 5 8

head

4
44
4 1 pointer
3
73
3 2 direction of
head pointer
26
07

7.7 Stacks
p
ap

The stack is an example of a data structure found quite commonly in computing


ts

which is especially used in system software. They may by used to carry out stages
of a calculation, for handling interruptions in translation programs or to pass
ha

information from a main program to a subprogram.


W

The main physical characteristic of a stack is that it is a LIFO (Last-In-First-Out)


structure. It can be likened to a pile of plates in which it is easy (if sometime a
little unstable) to add extra plates to the top. Plates can also be easily removed
from the top of the pile, but not by extrication from the bottom of the pile.

We can represent a stock as a one-dimensional array with two pointers, one


pointing to the base of the stack (to identify the first element) and the other
pointing to the position of the first available element, this being called the stack
pointer. These are only two possible operations that can be done with a stack,
namely adding an item to the top of the stack (called stacking or pushing) and the
other is that of popping, or taking an item off the stack.

107
An example of Stack Operation.

DIM S(50)
REM **PUSHING SEQUENCE**
IF P <= 50 THEN 120
PRINT “STACK FULL”
STOP
LET S(P) = E
LET P = P+1
GOTO 90
:

8
7 7
6 6
5 5
4 Push 4

4
Head Pop

44
3 3
pointer
2 3 Head 2
73
1 8 pointer 1 3
Based Base pointer
pointer
26
07

7.7.1 Corruption by Machine

Machines and computers do not „clean up‟!


p
ap

A „POP‟ operation merely copies a datum from a memory location to another


ts

leaving the previous datum intact.


ha

For a push, make sure the location is empty else „Invoice‟; into a location
W

previously held a longer string „calendar‟ on retrieving gives „Invoicer‟.

Hence Corruption of Data!!

108
Points to Remember

An array is a storage area in primary memory. Each data entry stored in an array
is accessed with a single subscript or index value.
Arrays can be one-dimensional or multi-dimensional.
Arithmetic operations applied to a two-dimensional table result in a matrix.
Linked list is data structures that permit records in a file or entries in an array to
be maintained in logical order without remaining in physical order.
Linked list uses a pair of pointers: the head (list) pointer for the start of the list
and tail pointer for the last entry.
Stacks are data structures which exhibit behaviour known as LIFO (last in, first
out).
Additions to a stack are „PUSHED‟ onto the top of it and deletion are „POPED‟
singly off the top.

4
Stacks use a pair of pointers: the head and the tail pointer.

44
Queues are data structures that exhibit FIFO (first in, first out) behaviour.
3
Queues use a pair of pointers: the head pointer and the tail pointer which indicate
73
the next available location.
26
07
p
ap
ts
ha
W

109
Chapter 8 : Data Structures (II)

Chapter Objectives

At the completion of this chapter, you would have learnt:

 how to acquire the ability to manipulate or to use the different types if data
structures;

 how to construct and traverse a binary tree;

 comparison of data structures.

8.1 Introduction

4
So far, we have been studying mainly linear types of data structures: strings,

44
arrays, lists, stacks and queues. This section defines a non-linear data structure
called a tree. This structure is mainly used to represent data containing a
3
hierarchical relationship between elements. E.g. records, family trees and tables
73
of contents.
26

First we investigate a special kind of tree, called a binary tree, which can be
easily maintained in the computer. Although such a tree may seen to be very
07

restrictive, we will see later in the section that more general trees may be viewed
as binary trees.
p
ap

8.2 Tree
ts
ha

Natural Tree
W

What has a natural tree got to do with a computer?

Try a pseudo-code to get the apples and return to the ground.

leaves

branche
s

roots

A natural tree

Computer tree

110
A simplified model of a real tree. Where each node has at most two others below
it. This is a binary tree.

Great-Great-Grand-parents Root

Great-Grand-parents Root

Grand-parents Right Descendent


Left Descendent

Parents Path

Sons and
daughters

The family free model

The countries Malaysia, Namibia, Mauritius, Bahrain, Hong Kong, Pakistan, Sri
Lanka, Botswana, Singapore and India are to be placed in an alphabetical order

4
using pointers.

44
The diagram below is a complete, „linkages‟ of all the countries.
3
73
MALAYSIA 1
26

LAYER 1
Left Descendent Right Descendent
07

BAHRAIN 4 NAMIBIA 2
p

2
ap
ts

HONG KONG 5 MAURITIUS 3 PAKISTAN 6


ha

3
W

BOTSWANA 8 INDIA 10 SRI LANKA 7

SINGAPORE 9

The tree diagram completed

Further Example of Tree Diagram

The text “TREE DIAGRAMS ARE QUITE EASY WHEN YOU KNOW HOW.”
is to be represented in the form of a tree.

111
TREE

DIAGRAMS WHEN

ARE QUITE YOU

EASY

KNOW

HOW

Question: Can you understand the logic of the binary tree?

4
44
3
73
26
07
p
ap
ts
ha
W

112
8.3 Tables
In tables, there are basically 4 types of pointers:

i. Left Pointer;
ii. Right Pointer;
iii. Back Pointer/Parent Pointer;
iv. Trace Pointer.

The Pointers point to the left, right of the tree trace where they come from or to
the next node of the tree. This to preserve the structure of the tree.

The node number takes positive integers and „-1‟ has special meaning.

NODE DATUM LP RP
1 Malaysia 4 2

4
2 Namibia 3 6

44
3 Mauritius -1 -1
4 Bahrain
3 -1 5
73
5 Hong Kong 8 10
6 Pakistan -1 7
26

7 Sri Lanka 9 -1
07

8 Botswana -1 -1
p

9 Singapore -1 -1
ap

10 India -1 -1
ts
ha

The above tree is mapped into to give the following:


W

Malaysia 4 2
Namibia 3 6
Mauritius -1 -1
Bahrain -1 5
Hong Kong 8 10
-1 7
Pakistan 9 -1
Sri Lanka -1 -1
Botswana -1 -1
Singapore -1 -1
India

113
Using the full set of pointers, the final tree can be represented below:

Malaysia 4 2 -1 3
Namibia 3 6 1 6
Mauritius -1 -1 2 2
Bahrain -1 5 1 8
Hong Kong 8 10 4 10
-1 7 2 9
Pakistan
9 -1 6 -1
Sri Lanka -1 -1 5 5
Botswana -1 -1 7 7
Singapore -1 -1 5 1
India

The Back / Trace Pointer

MALAYSIA 1

4
44
Back Pointer (BP)
3
73
BAHRAIN 4
26

Trace Pointer (TP)


07

HONG KONG 5
p
ap

The Pointers
ts
ha

8.4 Binary Trees


W

A binary tree T is defined as finite set of elements, called nodes such that:

T is empty (called the null tree or empty tree), or


T contains a distinguished node R, called the root of T, and the remaining nodes
of T form an ordered pair of disjoint binary trees T1 and T2.

If T does contain a root R, then the two trees T1 and T2 are called, respectively,
the left and right subtrees of R. If T 1 is non-empty, then its root is called the left
successor of R; similarly, if T2 is non-empty, then its root is called the right
successor of R.

114
Example: Software
S

o t

f r
w
a

A binary tree T is frequently presented by means of a diagram. Specifically, the


diagram above represents a binary tree T as follows.

T consists of 8 nodes, represented by the letters s through e.


The root of T is the node s at the top of the diagram.

4
A left-downward slanted line from a node s indicates a left successor of s and a

44
right-downward slanted line from s indicates a right successor of s.

Observe that:
3
73
O is a left successor and t is a right successor of the node s.
26

The left subtle of the root s consists of the nodes o, f, r, a and e, and the right
subtree of s consists of the nodes t and w.
07
p

8.5 Traversing of Binary Trees


ap
ts

There are three standard ways of traversing a binary tree T with root R. These
three algorithms, called preorder, inorder and postorder, are as follows:
ha
W

Preorder: 1. Process the root R.


2. Traverse the left subtree of R in preorder.
3. Traverse the right subtree of R in preorder.

Inorder: 1. Traverse the left subtree of R in inorder.


2. Process the root R.
3. Traverse the right subtree of R in inorder.

Postorder 1. Traverse the left subtree of R in postorder.


2. Traverse the right subtree of R in postorder.
3. Process the root R.

A simple example of Binary Tree

A
LT RT
B C

115
D F
E
8.5.1 Preorder Traversal

The preorder traversal of T processes A, traverses LT and traverses RT. However,


the preorder traversal of LT processes the root B and then D and E, and the
preorder traversal of RT processes the root C and then F. Hence ABDECF is the
preorder traversal of T.

8.5.2 Inorder Traversal

The inorder traversal of T traverses LT, processes A and traverses RT. However,
the inorder traversal of LT processes D, B and then E, and the inorder traversal of
RT processes C and then F. Hence DBEACF is the inorder traversal of T.

8.5.3 Postorder Traversal

The postorder traversal of T traverses LT, traverses RT, and processes A.

4
However, the postorder traversal of LT processes D, E and then B, and the

44
postorder traversal of RT processes F and then C. Accordingly, DEBFCA is the
postorder traversal of T. 3
73

8.6 Binary Search Trees


26

This section discusses one of the most important data structures in computer
07

science, a binary search tree. This structure enables one to search for an element.
It also enables one to easily insert and delete elements. This structure contrasts
p

with the following structures:


ap
ts

Binary Search Tree


ha

38
W

14 56

8 23 45 82

18 70

116
8.7 Searching and Inserting in Binary Search Trees
Suppose T is a binary search tree. This section discusses the basic operations of
searching and inserting with respect to T. In fact, the searching and inserting will
be given by a single search and insertion algorithm.

Suppose an ITEM of information is given. The following algorithm finds the


location of ITEM in the binary search tree T, or inserts ITEM as a new node in its
appropriate place in the tree.

a. Compare ITEM with the root node N of the tree.


i. If ITEM < N, proceed to the left subtree of N.
ii. If ITEM > N, proceed to the right subtree of N.

b. Repeat Step (a) until one of the following occurs:


i. We meet a node N such that ITEM = N. In this case the search is
successful.

4
44
ii. We meet an empty subtree, which indicates that the search is
unsuccessful, and we insert ITEM in place of the empty subtree.
3
73
In other, proceed from the root R down through the tree T until finding ITEM in
T or inserting ITEM as a terminal node in T.
26
07

Example:
p

Consider the binary search tree T below. Suppose ITEM = 20 is given.


ap

Simulating the above algorithm, we obtain the following steps:


ts

Compare ITEM = 20 with the root, 38, of the tree T. Since 20 < 38, proceed to the left
ha

child of 38, which is 14.


W

Compare ITEM = 20 with 14. Since 20 > 14, proceed to the right child of 14, which is 23.
Compare ITEM = 20 with 23. Since 20 < 23, proceed to the left child of 23, which is 18.
Compare ITEM = 20 with 18. Since 20 > 18 and 18 does not have a right child, insert 20
as the right child of 18.

38

14 56

8 23 45 82

18 70

20

117
Points to Remember

Binary trees are non-linear data structures in which the root and each node on the
tree contain a maximum of two children.
A binary tree can be created within an array using left and right child pointers
similar to linked list concepts.
Additions, changes and deletions of a left node are fairly easy.
The 4 types of pointers in a binary can be represented in a form of a table.
Three traversal of binary search tree, Preorder, Inorder and Postorder.
A comparison.

Sorted Linear Linked List Binary Tree


Array
Search Quick Slow Quick

4
(binary Search) (Linear Search) (Binary Search)

44
Insert and Delete Expensive Easy Easy
3
73
26
07
p
ap
ts
ha
W

118
8.8 Past Years Questions
19. Produce a binary tree diagram of the following data:

Node 1 2 3 4 5 6 7 8
Content C J P T K B M S

[4]

a. Construct a dictionary-order binary tree for the fruits below:


Durian, Apple, Pineapple, Mango, Avocado, Mangosteen, Watermelon,
Pear. [8]

mmmmmm. U
se a table to show the left, right, back and trace pointers for the above
tree. [8]
nnnnnn. i. Write down all the pointers for the table below:

4
44
[4]

Note: that contents are to be arranged in ascending order.


3
73
Address Contents Pointer
26

4 101
07

2 90
5 85
p
ap

6 102
7 105
ts
ha

ii. Re-arrange the pointers if contents 102 and 85 are removed. [2]
W

Given the following items in series, construct the dictionary-order binary tree. [4]
Malaysia, India, Singapore, Bahrain, China, Turkey, Pakistan, Hong Kong

4. a. i. Construct the binary tree for the following data:

Keyboard, CPU, Mouse, Monitor, Scanner, Disk, Cables, Drives,


Printer, Software [6]

ii. From the above binary tree, build a table to show its Left, Right,
Back (parent).

Use -1 to represent a null value. [6]

119
b. i. Write down the pointers for the table below, where elements are
linked in numerical order: [2]

Index Key Linked to next record


1 50
2 100
3 87
4 34

ii. Modify the table to reflect the additional of index 5 with key
value 66 and index 6 with key value 104. [4]

iii. Modify the table to reflect the deletion of index 2, key 100. [ 2 ]

Given the following items:


Hockey, Baseball, Soccer, Tennis, Squash, Golf.

4
44
oooooo. C
onstruct an alphabetically-ordered binary tree. [3]
pppppp.
3 F
73
rom the binary tree, build a table with Left and Right Pointers. [2]
26

A table to represent the contents of a BINARY TREE is:


07

Node Contents Left Pointer Right Pointer


p

1 Gooch 2 4
ap

2 Atherton -1 3
ts

3 Botham -1 -1
ha

4 Gower -1 5
W

5 Smith -1 -1

qqqqqq. D
raw the binary tree which this information represents. [5]
rrrrrr. S
how the changes to the TABLE when Fraser is added to the contents.
[2]
ssssss. E
xplain how a BINARY TREE can be used to SORT a large amount of
data amount of data by computer. [3]

a. Produce a BINARY TREE diagram using the data below:

Node 1 2 3 4 5 6 7 8 9 10 11
Contents Rice Soya Tea Coffee Melon Yams Bead Potatoes Cocoa Sugar Bananas

120
tttttt. Represent the tree in the form of a TABLE including columns for the
LEFT and RIGHT pointers. [3]
uuuuuu. S
how how the TABLE would be used to search for SUGAR. [3]
vvvvvv. S
how the changes to the TABLE when MILK is added to the tree. [3]
wwwwww. S
tate two reasons why a BINARY TREE is often preferred to a linear list
for holding data. [2]
xxxxxx. I
f a tree is ideally shaped with 1,000 nodes, what is the MAXIMUM
number of nodes you would expect to check when searching for a given
value? Briefly justify your answer. [2]

a. Produce a Tree diagram using the data below: [6]

4
Node 1 2 3 4 5 6 7 8 9 10

44
Hong
Contents Malaysia India Kuwait Nigeria Bahrain Pakistan Namibia Singapore Australia
Kong
3
73
yyyyyy. Make a table from you tree, ADD Left and Right.
Pointer columns and complete the table. [3]
26
07

A baker sells bread to ten shops every day. When he delivers the bread in the morning, he
collects the bread which was not sold the previous day, and gives it to the local zoo for
p
ap

their animals. One day, he gets the following number of loaves returned:
ShopA 3
ts

ShopB 6
ha

ShopC 2
ShopD 8
W

ShopE 0
ShopF 4
ShopG 7
ShopH 5
ShopI 12
ShopJ 1

zzzzzz. C
onstruct a binary tree for the above data, such that traversing the tree
will list the shops in increasing order of loaves returned. Mark each
node in the tree with both the shop name and the number of loaves e.g.
A(3) [8]
aaaaaaa. F
or your binary tree, build a table to show each node‟s left, right and
back pointer. Use -1 to represent a null pointer. [6]
bbbbbbb. R
edraw your table to reflect the deletion of shop I from the tree. [3]

121
ccccccc. R
edraw your table to reflect the further deletion of shop D from your
tree. [3]

4
44
3
73
26
07
p
ap
ts
ha
W

122
Chapter 9: Matrices And Transformations

Chapter Objectives

At the completion of this chapter, you would have learnt:

 to define a matrix and the types of matrix;

 to understand the order of a matrix;

 to perform simple algebra on matrix;

 to relate shapes and their movements in space through matrices;

 to understand the motion and transforms of 2 dimensional shapes;

 model shapes and operate on them by matrix arithmetic;

4
44
 to perform a range of elementary 2 dimensional spatial operations.
3
73
26

9.1 Introduction
07

Here, we exploit the ability to emulate and to manipulate entities in spatial terms.
p

Ultimately these basic ideas extend to controlling machine and its tools.
ap

Some of us may have seen this in computer applications such as DTP, CAD or
ts

CAM.
ha
W

9.2 Definitions
A matrix is a rectangle array of m rows and n columns, where m and n are natural
numbers. Such a matrix is said to be of order m x n.
Example:

1 2
  a b c  - 9 0
 3 4  ,   and   are matrices.
5 6 d e f   1 2
 

Their orders are 3 x 2, 2 x 3 and 2 x 2 respectively.

An m x 1 matrix is known as a column vector or column matrix.

An n x n matrix is known as a square matrix.

A 1 x m matrix is known as a row matrix.

123
1 0
The matrix   is called the unit matrix. It is usually represented by the
0 1
symbol I. When any matrix is multiplied by the unit matrix. The matrix
remains unchanged. That is I.A = A.I = A where A is a matrix
Example:

1 0 a b a b 1 0 a b
    =     =  
0 1  c d  c d 0 1 c d

An matrix whose elements are all zeros is called a zero matrix.


Example:

 0 0  0 0 0 0
    and   are all zero matrices.
 0 0  0 0 0 0

4
44
3
73
26
07
p
ap
ts
ha
W

124
When any matrix is multiplied by the zero matrix. The result is a zero
matrix.

Example:

0 0 a b a b 0 0 0 0
    =     =  
0 0  c d   c d  0 0 0 0

a b
The zero matrix is sometimes written simply as 0 so that if A =   is
cd 
multiplied by 0, we could write it as: 0.A = A.0 = 0

9.3 Rules/Matrix Algebra


Two matrices can be added only if they are of the same order. The rule for
addition is shown by the following example.

4
Example:

44
a c e f  a e cf 
  +   3=  
b d g h b  g d  h
73

Example:
26

 4  7 9  8
07

 4 9 7 8
  +   =  
 3 5  1 9  3  1 5  9
p
ap

11 17 
 
ts

=
 4 14 
ha
W

Two matrices can be subtracted only if they are of the same order. The rule for
subtraction is shown by the following example.
Example:

a c e f  a c   e  f 
  -   =   +  
b d g h b d  g  h

a e cf 
=  
b  g d  h

125
Example:

 4 9 7 8  4 - 7 9 - 8
  +   =  
 3 5  1 9  3 -1 5 - 9

- 3 1 
=  
 2 - 4

The rule for multiplying matrices is:


a c e f   ae  cg af  ch 
    =  
b d g h  be  dg bf  dh 

Multiplying other matrices is done in the same manner but the number of
columns of the first matrix must be the same as the number of rows of the
second matrix.
Example:

4
44
a c e  ae  cf 
    =  
b d f  3  be  df 
73

a b  ag  bi ah  bj 
  g h  
26

 c d    =  cg  di cj  dj 
e f   i j  eg  fi eh  fj 
07

   
p
ap

Example:
ts

 4 9  6
ha

Multiply    
 3 5  2
W

Solution:

 4 9  6  4x6  9x2 
    =  
 3 5  2  3x6  5x2 

 24  18 
=  
 18  10 

 42 
=  
 28 

126
Example:

 4 9  2 4
Multiply    
 3 5  1 3

Solution:

 4 9  2 4  4x2  9x1 4x4  9x3 


    =  
 3 5  1 3  3x2  5x1 3x4  5x3 

 8  9 16  27 
=  
 6  5 12  15 

17 43 
=  
 11 27 

4
If A and B represent two matrices, then

44
AB  BA
3
73
i.e. in matrices, the order of multiplication is not commutative.
26

Two matrices are equal if and only of their corresponding elements are equal.
07

a c e f 
Thus, if   =  
b d g h
p
ap

then it follows that a = e, b = f, c = g and d = h.


ts
ha

x  2
If   =   then it follows that x = 2 and y = 3.
W

 y  3

When a matrix is multiplied by a constant, every element in the matrix is enlarged


by the constant.

 p q   cp cq 
Thus, c   =  
 r s   cr cs 

127
If A and B are any two matrices, AB = 0 does no necessarily imply that either A
= 0 or B = 0.
Example:

1 0 0 0
If A =   and B =  
0 0 0 1

1 0 0 0 0 0
AB =     =  
0 0 0 1 0 0

Unlike ordinary algebra, the fact that AB = AC does not necessarily imply that B
= C.
Example:

1 0  1 0 1 0
If A =   and B =   and C =  

4
 1 0   0 0   0 1 

44
1 0 
then AB = AC =  
3
73
1 0 
26

But B  C and A  0
07

Example:
p
ap

1 3   2 0  4
Given A =   and B =  
ts

 2 - 1 3 - 2 6 
ha

Solution:
W

Since A is 2 x 2 and B is 2 x 3, the product matrix AB is defined and is a 2 x


3 matrix. To obtain the elements in the first row of the product matrix AB,
multiply the first row (1 3) of A by the columns.

 2  0  - 4
  ,   and   of B respectively.
 3 - 2 6

 1 3   2 0  4
   
 2 - 1  3 - 2 6 

Step 1:

 (1x2 + 3x3 1x0 – 3x(-2) 1x(-4) +3x6)

 (11 –6 14)

128
To obtain the elements in the second row of the product matrix AB, multiply the
second row (2, -1) of A by the columns of B respectively.

 1 3   2 0  4
   
 2 - 1  3 - 2 6 

Step 2:

11 -6 14
 ( 2x2 + (-1)x3 2x0 + (-1)x(-2) 2x(-4) + (-1)x6 )

11 - 6 14 
=  
 1 2 14 

Matrix multiplication does not obey the commutative law, i.e. the products AB
and BA of matrices need not be equal.

4
44
9.4 Equivalent Matrices
3
Two matrices are equal if and only if their corresponding elements are equal. For
73
instance, if
26

 2 3  2 3
A =   , and B =  
 4 5  4 5
07
p

then matrix A = matrix B.


ap

Example:
ts
ha

x 2  3 - 5  8 - 3
Given A =  , B =   and C =  
y 
W

1 4 2  5 0 

ddddddd. Find the values of x and y if A + B = C.


eeeeeee. Is BC = CB?
fffffff. Evaluate 3B.

Solution:

x 2   3 - 5
  + 
y   4 2 
ggggggg. A+B =
1
x  3 2 -5 
=  
 1  4 y  2

x  3 -3 
 
y  2 
=
 5

129
Since A + B = C

 x  3 - 3   8 - 3
   = 
 5 y  2   5 0 

 X - 3 = 8 and y + 2 = 0

Therefore x = 5, y = -2

 3 - 5   8 - 3
hhhhhhh. BC =    
 4 2  5 0 
 24 - 25 - 9 - 6   -1 - 9 
=   =  
 32  10 - 12  0   42 - 12 

 8 - 3  3 - 5 

4
CB =    

44
5 0   4 2 
3
 24 - 12 - 40 - 6 
73
=  
 15  0 - 25  0 
26

12 - 46 
07

=  
15 - 25 
p
ap

Thus BC  CB
ts
ha

 3 - 5
3  
W

iiiiiii. 3B =
4 2 
 3x3 3(-5) 
=  
 3x4 3x2 
 9 - 15 
=  
12 6 

130
Example: (A typical examination question)

A company makes two microcomputers, named SOLAR and GEM, using three
main components X, Y and Z

SOLAR is made of 3 X components and 2Y components.


GEM is made of 2 X components and 3Z components,

i. Express this information as a 2 by 3 array Q.


The company receives an ORDER for 100 SOLAR and 50 GEM
microcomputers.

ii. Express the ORDER as a row matrix (array) P.


iii. Find the product PQ and interpret its meaning.
iv. If it takes 2 hours to produce the component X, 1 hour to produce Y and 3
hours to produce Z, represent this information as a coloumn matrix R.
v. Calculate PQR and interpret its meaning?

4
44
A second order for 50 solar and 100 gem microcomputer is subsequently received
but by then New Production Techniques have resulted in the time needed to
3
produce X cut by 20%, and the time to produce Z cut by a third. The time taken
73
to produce Y is unchanged.
26

vi. Use matrix (array) techniques to determine the COMPONENT


REQUIREMENTS for the Second Order.
07

vii. Determine the HOURS needed to produce the SECOND ORDER.


p

For the FIRST ORDER labour costs were 3 units per hour, but had
ap

INCREASED by 10% for the SECOND ORDER.


ts
ha

viii. Determine whether these LABOUR COSTS are greater or smaller than
those for the FIRST ORDER.
W

X Y Z
Solution: i. Matrix Q: SOLAR  3 2 0 
GEM  
 2 0 3
ii. Matrix P: SOLAR GEM
ORDER (100 50)

iii. PQ is X Y Z
(400 200 150)

This means that the ORDER requires 400 of X, 200 of Y


and 150 of Z.

iv. R is a 3 x 1 matrix.

131
 2
 
1
 3
 

v. PQR is a 1 x 1 matrix (1450)

This means that the order will require 1450 hours To produce (i.e. total time
required to produce all X, Y and Z components to fulfil the order).

vi. A second order requires

 3 2 0
(50 100)   = (350 100 300)
 2 0 3

Hence it requires 350 of X, 100 of Y and 300 of Z.

4
44
vii. Hours to produce the second order is given by:
3
73
1.6 
 
(350 100 300)  1 
26

 2 
 
07

i.e. 560 + 100 + 600 = 1260 hours


p
ap

viii. Labour costs for first order = 3 x 1450 = 4350


ts

Labour costs for second order = 3.3 x 126 = 4158


ha

Hence the labour costs for the second order are smaller than
W

those for the first order.

9.5 Transformations
A transformation is an operation which transforms a point or a figure into another
point or figure.

132
9.5.1 Translation

A translation is a transformation which moves all points in a plane through the


same distance in the same direction.

E.g. The triangle ABC has been transformed onto the triangle A‟B‟C‟ by a
 3
translation   i.e. 3 squares to the right and 2 squares up in the plane of the
2  
paper.

y
C
5 -

4 -
C
3 -
A B
‟ ‟

4
2 -

44
1 -
A B 3
73
| | | | | x
0 1 2 3 4 5
26

 3
07

Point A is mapped onto A‟ by a   , denoted by T.


2  
p
ap

x  x' 
  + T =  
ts

 y  y'
ha

1  3  4
   +   =  
W

1  2  3

9.5.2 Enlargement (E)

An enlargement with centre O, scale factor k is a transformation which enlarges a


given figure by k times the original size.

If k > O, the given figure and its image are on the same side of the centre of
enlargement O.

If k < O, the given figure and its image are on opposite sides of O.

133
The figure and its image after an enlargement are similar. The scale factor

OA' OB' OC'


k= = = C‟
OA OB OC

C
A‟
O
A B
B‟

Area of Image
Under an enlargement, = k2
Area of Figure

If the image of a point (x, y) under a transformation is the point itself i.e. (x, y),
the point (x, y) is called an invariant point of the transformation.

4
If a line is mapped onto itself under a transformation, the line is said to be an

44
invariant line under the transformation.
3
73
9.5.3 Reflection
26

A reflection is a transformation which reflects all points of a plane in a line (on


the plane) called the mirror line.
07

DABC is mapped onto D A‟B‟C‟ under a reflection in the line XY which is the
p

perpendicular bisector of AA‟, BB‟ or CC‟.


ap

Under a reflection, the figure and its image are congruent.


ts
ha

Example:
W

C C‟

B B‟
A A‟

9.5.4 Rotation (R)

A rotation is a transformation which rotates all points on a plane about a fixed


point known as the centre of rotation, through a given angle in anti-clockwise of
clockwise direction.

134
The angle through which the points are rotated is called the angle of rotation.

The triangle ABC is rotated about the origin O through 90o in the anti-clockwise
direction, and mapped onto triangle A‟B‟C‟.

C‟
B‟
C
A‟

B
A
x
0

4
44
9.5.5 Shearing (H)
3
A shear parallel to the x-axis is a transformation which moves a point (x, y)
73
parallel to the x-axis through a distance ky, where k is the shear factor.
26

y
07

C
p

3 - C
ap


B
ts

2 - B
ha


W

1 -

| | | | | | x
0 1 2 3 4 5 6

difference in x- coordinates of corresponding points


k =
y- coordinate of original point

135
OBC is mapped onto OB‟C‟ under a shear along the x-axis with factor k.

OC' 6
k = = = 2
OC 3

A shear parallel to the y-axis is a transformation which moves a point (x, y)


parallel to the y-axis through a distance kx where k is the shear factor.

difference in y - coordinates of corresponding points


k =
x - coordinate of original point

9.5.6 Stretching (S)

One-way stretch.
 A stretch parallel to the x-axis is a transformation which move a point
(x, y) parallel to the x-axis, through a distance kx, where k is the stretch
factor.

4
 A stretch parallel to the y-axis is a transformation which moves a point

44
(x, y) parallel to the y-axis through a distance ky, where k is the stretch
factor. 3
73
difference in x- coordinates of corresponding points
k =
y- coordinate of original point
26
07

i. In the case of stretching parallel to the x-axis, the invariant line is


the x-axis.
p

ii. In the case of stretching parallel to the y-axis, the invariant line is
ap

the y-axis.
ts

i. ii.
y y
ha
W

B(1,4) C‟
C B‟(3,4) B‟(4,4)
0,4 0,4

(0,1)C B
x x
0 A A‟(3,0) 0 A A(4,0)
CB' OC'
k= =3 k= =4
CB OC

Two Way Stretch


If a figure is stretched parallel to the x-axis as well as parallel to the y-axis,
then the stretch is called a two-way stretch.

Under a two-way stretch with h and k as constants of stretch parallel to the


x-axis and y-axis respectively a point (x, y) is mapped onto (hx, ky).

136
y

B(1,4)
C‟(0,5) B‟(6,5)
5
k=
2
B(2,2)
C‟(0,2)
h=3
x
0 A(2,0) A‟(3,0)

OABC  OA‟B‟C‟
(x, y)  (hx, ky)

1 3
Example: Matrix   represents a transformation T.
 2  5

Given (x, y) is the image of the point (a, b) under the

4
transformation T, find x and y in terms of a and b.

44
Solution: Write the ordered pairs, (a, b) and (x, y) as column vectors:
3
73
a x
  and   .
b  y
26
07

a 1 3
Premultiply   by the matrix   , we get
b 2  5 
p
ap

x 1 3 a
  =    
ts

 y  2  5 b
ha

 1 xa  3 xb 
W

=  
 2 xa  (5) xb 
 a  3b
=  
 2 a 5 b 

Therefore, x = a + 3b, y = 2a - 5b

1 3
The matrix   defines a transformation T which
 2  5
maps the point (a, b) onto (a + 3b, 2a - 5b).

Example: Find the co-ordinates of the image of the point (-3, 2) under
 3  1
the transformation represented by the matrix   .
5 0

Solution: Let the image of the point = (x, y).

137
x  3  1   3 
  =    
 y 5 0  2 
 3 x( 3)  (1) x 2 
=  
 5 x( 3)  0 x 2 
 92    11 
=   =  
  15  0    15 

Therefore the image of the point = (-11, -15)

Example: Find the matrix of the transformation which maps (1, 0) onto
(4, 1) and (0, 1) onto (3, 2).

a b
Solution: Let the matrix of transformation =  
c d
(1, 0)  (4, 1)

4
44
 4 a b 1
  =     because (4, 1) is the image of (1, 0)
1  c d 0
3
73

 4  a 0
  =  
26

1  c 0 
07

a 
=  
p

c
ap
ts

Therefore a = 4, c = 1
ha
W

138
Points to Remember

Definition of a matrix.
 A matrix is a rectangle array of m rows and n columns.
Order of matrix.
 A matrix is said to be of order m*n if it has m rows and n columns.
Algebra of matrix.
 Addition/subtraction.
This can be carried out provided the matrices are of the same order. The
resultant matrix will have the same order as well.
 Scalar product.
A matrix can be multiplied by a constant (scalar).
Each element in the matrix will be multiplied by that constant.

4
 Product of matrices.

44
This can be done provided the number of columns of the first matrix
3
corresponds to number of rows of the second matrix.
73
If C = A * B
26

Let ai,j denote the element in matrix A,


bm,n denote the element in matrix B,
07

and cp,q denote the element in matrix C,


where (i, j), (m, n) and (p, q) denote the row and column
p
ap

number respectively.
ts

N
Then Cp,q = a * b r ,q
ha

p,r
r 1
W

where N = number of columns in matrix A


= number of rows in matrix B

For example,
C3,2 = a3,1 b1,2 + a3,2 b2,2 + a3,3 b3,2 + ... + a3,N bN,2

139
Transformations:

Table giving matrices corresponding to transformations:

Transformations Matrices Matrix Equation


h  x'  x   h 
Translation     =   +  
k  y'   y   k 
Enlargement with centre at origin k 0  x'  k 0   x 
    =    
and scale factor k  0 k    
y ' 0 k   y
 1 0  x'  1 0   x 
Reflection in x-axis     =    
 0 1  y'   0 1  y 
 1 0  x'   1 0   x 
Reflection in y-axis     =    
 0 1  y'   0 1  y 
1 0  x'  1 0   x 

4
    =    

44
Reflection in line y = x
0 1  y'   0 1   y 
 0  1  x '   0  1  x 
3
    =    
73
Reflection in line y = -x
 1 0  y'    1 0   y 
26

Rotation of 90o anti-clockwise  0  1  x '   0  1  x 


    =    
07

about origin  1 0  y'   1 0   y 


Rotation of 90o clockwise  0 1  x '   0 1  x 
p

    =    
 1 0  y'    1 0   y 
ap

about origin
ts
ha

Transformations Matrices Matrix Equation


W

 1 0  x'   1 0  x
Rotation of 180 about origin     =    
 0  1  y'   0  1  y
Shear parallel to x-axis, shear 1 k   x'  1 k   x 
    =    
factor k 0 1  y'   0 1   y 
Shear parallel to y-axis, shear  1 0  x'  1 0   x 
    =    
factor h  h 1  y'   h 1   y 
Stretch parallel to x-axis,  k 0  x'  k 0   x 
    =    
stretch factor k  0 1  y'   0 1   y 
Stretch parallel to y-axis, 1 0  x'  1 0   x 
    =    
stretch factor h 0 h  y'   0 h   y 
Stretch parallel to x-axis and y- h 0  x'  h 0   x 
axis with factors k and h     =    
respectively 0 k  y'   0 k   y 

140
Past Years Questions

 3  7
 
Given A =  5 , B = [-4 1] and C =
 6 evaluate
   
 2  6
jjjjjjj. A
*B [3]
kkkkkkk. A
-C [2]

Given:

4   2
  C =   1

4
D= 5 Z = [2 1 3 ]
   

44
6   2
3
73
Calculate, showing all working.

lllllll. D
26

*Z [2]
07

mmmmmmm. Z
*D [1]
p
ap

nnnnnnn. D
-C [1]
ts
ha

2 3  1 0
Let A =   and B =  
W

 1 1  1 1
ooooooo. E
valuate A * B [2]
ppppppp. E
valuate B * A [2]
qqqqqqq. C
omment on the results from a. and b. [2]

  1 5
    4 2 0
Given A = 0 3 and B =  
 
 6 8  0 3 4

rrrrrrr. C
alculate A * B [3]

141
sssssss. G
 5 12  6
iven C =   [3]
 1 3  1

Calculate X = 2AB,
 2  2   5 2
given A =   and B =   [3]
0 5  1 3

 1 0 2 0  1  1

Given A = 0 5 4 and B = 2 1 3
 
 1 8  2  1  2 0

Prove that AB  BA. [6]

Indicate whether each of the following statements concerning matrices is True or False:

4
44
ttttttt. I
f A + B = C, then B + A = C 3 [1]
uuuuuuu. I
73
f A * B = B * A, then A = B [1]
26

vvvvvvv. I
t is always possible to add together matrices which can be multiplied
07

together. [1]
wwwwwww. F
p

or square matrices, it is often possible to show that A * B  B * A.


ap

[1]
ts

xxxxxxx. W
ha

hich of the following is not a valid matrix equation? [1]


W

i. A/B=C

ii. A - B = 2(B - A)

iii. A * B = B * A + C [1]

0  and 4 
2 1 1 2
8. a.. i. Use matrices A = 3 B= 3

to calculate 2A * B. [4]

ii. Calculate A - B [2]


iii. Given matrix C = [4 8], calculate C * 2A [4]

yyyyyyy. i
.Three types of personal computer A, B and C sell at $3,000, $4,000
and $5,000 respectively. Express this information as 3x1 matrix and
label it X. [2]

142
ii. Customer 1 wishes to buy 3 type A, 4 type B and 3 type C.
Customer 2 wishes to buy 1 type A, 2 type B and 5 type C. Express this
information as a 2x3 matrix and label it Y. [ 3 ]

iii. Calculate YX and interpret the answer. [5]

a. A student scores 75%, 85%, 60% and 43% for the subjects Maths,
English, French and Science respectively. The Full mark for each
subject is as follow:
Maths - 100
English - 200
French - 150
Science - 150

i. Arrange the full mark in a 1 * 4 array and label it as Z. [2]


ii. Arrange the scores in a column array and label it as W. [2]
iii. Find the total mark obtained by the student using W and Z. [4]
From the matrix determine the student‟s English and Science

4
iv.

44
marks. [2]
3
zzzzzzz. The following reductions were made, after moderation, from the
73
existing scores 75%, 85%, 60% and 43%:
Maths - 5%
26

English - 10%
French - 8%
07

Science - 3%
p

i. Arrange the new scores in a column array and label it as Y. [2]


ap

ii. Find the new total obtained by the student. [4]


ts

iii. What is the difference in percentage between the new and old total
ha

marks. [4]
W

  8 1
 1 5 0  2 4
a. Using matrices A =   , and B =
 
 0  2 3  4 1

Calculate AB. [4]

aaaaaaaa. There are three types of printer: S for serial printers, L for line
printers, and P for page printers. They cost $250, $500 and $1500
respectively.
i. Express the information above as a row matrix and label it as X.
[2]
ii. Customer A wishes to buy 10 of S, 5 of L and 2 of P while
customer B buys 20 of S, 3 of L and 4 of P. Express the following
information as a matrix of dimension 3x2. Label it as Y. [2]

143
iii. Determine an appropriate matrix R derived from the calculation of
X and Y to represent the total cost to each customer. [5]

iv. Special discounts are given, 5% to customer A and 10% to


customer B. Express this information as a column matrix. [2]

v. Using matrix calculation only, determine the total of the actual


costs paid by both customers. [5]

A company receives bills for rental, heating and lighting twice a year. If i = 1,2 represents
the first and the second half of the year and j = 1, 2, 3 represents the Rental, Heating and
Lighting, then the matrix P whose entries are identified as Pi,j is used to represent the
half-yearly bills.
bbbbbbbb. E
xplain in words, the meaning of P2,1 = $1050 [2]
cccccccc. I
3000 1550 1600
fP=   , using matrix
1550 2050 1800

4
44
calculation determine a matrix R which represents the total expense for
Rental, Heating and Lighting, respectively for each half of the year Q.
3 [4]
73
dddddddd. I
26

f 5% discount is given for Rental, 10% for Heating and 5% for


Lighting, represent this information as a 3x1 matrix Q. [2]
07

eeeeeeee. C
alculate S = PQ. [4]
p
ap

ffffffff. W
hat does this matrix S represent? [2]
ts

gggggggg. C
ha

alculate [1 1]*(R - S). Interpret your answer. [4]


W

hhhhhhhh. W
hat is the expense for heating in the second half of the year, after
discount? [2]

The Computa Co. buys three types of computer, the SL, the SLX and the SLXi.
iiiiiiii. T
he purchase price is $750, $850 & $900 respectively. Express this as a 1
x 3 matrix, P. [1]
jjjjjjjj. T
he Computa Co. sells them at $815, $935 and $1,000. Express this as a
1 x 3 matrix, S. [1]
kkkkkkkk. In a certain month, The Computa Co. makes the following sales
of each type:
First week, 10, 5 and 2. Second week 8, 3 and 1.
Third week, 8, 6 and 0. Fourth week 6, 2 and 2.

Express the sales figures as a 3 x 4 matrix, F. [3]

144
llllllll. I
1
1
f Z =   Calculate, [(S * F) - (P * F)] * Z. [4]
1

1
mmmmmmmm. C
alculate the percentage profit, correct to 1D. [2]

For -3 < x < 5 and -5 < y < 5, and a scale of 2cm : 1 unit on both axes.
nnnnnnnn. i
. Plot the points P(5, -3), Q(4, -2), R(3, -2) and S(2, -3) ON
GRAPH PAPER. [3]
ii. Join P to Q, Q to R, R to S and S to P. Label this as shape A. [ 1 ]

b. i. Write down the matrix representation of shape A. [1]

4
 1 0 0 1

44
ii. If T1 =   and T2 =  1 0 and B = T1 * A, C = T2 * A.
0 1 3  
73
Calculate matrix B and matrix C. [4]
26

c. Plot, draw and LABEL shapes B and C on the same sheet of graph
paper as shape A.
07

i. Calculate the matrix D, where D = T1 * C. [4]


p

ii. Plot, draw and LABEL shape D on the same sheet of graph paper
ap

as shapes A, B and C. [2]


ts

d. Describe fully the SINGLE transformation that move shape A to: [6]
ha

i. Shape B
W

ii. Shape C
iii. Shape D

Using a scale of 2 cm = 1 unit on both axes for -5 < x < 4 and -5 < y < 5.
e. i. Plot the points P(-5, -1), Q(-2, 0) and R(-3, 2) on GRAPH PAPER.
[3]
ii. Using straight lines, join P to Q, Q to R and R to P. LABEL this as shape
A. [ 1 ]

f. i. Write down the matrix representation of shape A. [1]


8 8 8 0  1
ii. If T1 =   and T2 =  1 0 and B = T1 + 2 * A and C
1 1 1  
= T2 * A.

Calculate matrix B and matrix C. [4]

145
g. Plot, draw and LABEL shape B and C on the same sheet of graph paper
as shape A. [2]
h. i. Calculate the matrix D, when D = T2 * B. [2]
ii. Plot, draw and LABEL shape D on the same sheet of graph paper.
[2]

i. If D = 2 * C + E, calculate the matrix E. [3]

a. ON GRAPH PAPER, using a scale of 1 cm : 1 unit on both axes


i. Plot the point P(2, 1). [1]

3
ii. Draw the three vectors, PQ =  
1

 1   2
QR =   RS =  0 . [4]

4
 2  

44
iii. Draw and write the resultant of PQ + QR + RS as a column
3
vector. [2]
73

j. Label the quadrilateral P Q R S as shape A and write down its


26

representation as a 2 by 4 matrix. [2]


 1 0 0 1 0 0 0 0 
07

k. If T1 =   T2 =   B = T1 * A -  
0 1  1 0  2 2 2 2
p
ap

and C = T2 * B.
ts

Calculate matrix B and matrix C. [5]


ha

l. Plot, draw and LABEL shapes B and C on the SAME GRAPH PAPER
W

as shape A. [2]
m. Describe fully the single transformation that moves shape A to:
i. shape B
ii. shape C [4]

On GRAPH PAPER, using a scale 1 cm = 1 unit on both axes for -8 < x < 10 and -10 < y
< 12,
n. i. plot the points P(-4, 3), Q(0, 6), R(-5, 9), S(-3, 5) and T(-6, 5).
[3]
ii. using STRAIGHT lines, join P to Q, Q to R, R to S, S to T and T
to P. Label this shape A. [ 1 ]
iii. write down a 2 by 5 matrix representation of shape A. [1]

146
 0 1  3 3 3 3
o. If T1 =   and T2 = 2 2 2 2 and B = T1 * A and C = 2 *
  1 0  
B - 4 * T2;

calculate matrix B and matrix C. [5]


p. Plot, draw and LABEL shapes B and C on the same sheet of graph
paper as shape A. [4]
q. If D = T1 * C + 2 * A; calculate matrix D. [4]
r. What would be the effect on any of the shapes if D was added? [2]
a. A company sells three products, X, Y and Z at $72, $56 and $67
respectively and sells 109 of X, 147 of Y and 100 of Z in one week and
120 of X, 185 of Y and 94 of Z in the next week.
i. Put the two-weeks quantities in a 3 x 2 matrix, N and the prices in
a 1 x 3 matrix, S. [2]
ii. If R = SN find the matrix R. [2]

4
Products Y and Z cost $n each to produce X costs twice as much

44
as either of the others;
3
iii. Express this information as 1 x 3 matrix, C. [1]
73
iv. If E = CN find the matrix E. [2]
26

If P = R - E find the matrix P and state what it represents? [2]


07

vi. If the total profit in week 2 is 10% more than in week 1 find $n.
[1]
p
ap

a. A company receives its bills for heating, lighting and rent four times a
ts

year. If i = 1, 2, 3, 4 represents the FOUR QUARTERS in a year and j


ha

= 1, 2 or 3 represents HEATING, LIGHTING or RENT, then the


matrix P, whose entries are identified by Pi,j, is used to represent the
W

quarterly bills.
i. Explain in words, the meaning of P3,2 = $1800. [2]

2500 1650 2000


2100 1400 2200
ii. If for one full year, P =  .
2150 1100 2200
 
2260 1350 2400
What is the total of Pi,1 for i = 1, 2, 3 and 4? [1]

iii. Explain in words what the total represents. [2]

s. The 3 x 1 matrix Q, represents in DECIMAL FRACTION form,


discounts received by the company of 10% on heating, 5% on lighting
and 0% on rent
i. Write down the matrix Q. [1]

147
1
ii.

Calculate the matrix R if R = P x 1 . [4]

1

iii. Calculate the matrix S, if S = P x Q. [4]

iv. What does the matrix S represent? [2]

v. Calculate [1 1 1 1] x (R - S). What does this represent? [3]

a. Shape A is represented by the matrix


 0 2 5 4 3 2
  4  2  4  3 2 4
 

i. Calculate

  1  1  1  1  1  1

4
B=   + 2 * A. [2]
 3  3  3  3  3  3

44
3
 
-1 0
 1 2
73
0 1
ii. Calculate C =   * [4]
0 1
26

t. By using a SCALE of 1 cm = 1 unit on both axes, PLOT and DRAW


07

the shapes A, B and C on one sheet of GRAPH PAPER. [ 10 ]


u. i. How are the shapes B and A related? [1]
p
ap

ii. What TRANSFORMS have been made to A to obtain C? [2]


ts
ha
W

148
Chapter 10 : Representation Of Instruction

Chapter Objectives

At the completion of this chapter, you should be able to:

 understand instruction word format;

 describe the differences between addressing techniques;

 have an understanding of instruction types.

10.1 Introduction

4
44
The principles of architecture extend through almost every aspect of computer
organisation. Included are the lengths of the instruction words, whether or not
3
length is variable, and how many addresses in memory are referenced by an
73
instruction word.
26

Other architectural considerations concern the number of bits in each memory


word, whether numbers are handled in 1‟s or 2‟s complement form or in BCD or
07

some combination of these. What are the instructions provided, how are the
memories organised, and how are input/output devices interfaced? As can be
p

seen, computer architecture is a large and rich subject that deals with most
ap

aspects of computer design and organisation.


ts
ha

10.2 Construction of an Instruction Word


W

A computer word is an ordered set of characters handled as a group. Basically all


words consist of a set of binary digits, and the meaning of the digits depends on
several factors. For instance, the bits 01000100 could represent the decimal
number 68 in a pure binary computer, and the decimal number 44 in a BCD
computer that uses an 8, 4, 2, 1 code. Thus, the meaning of a set of digits is
determined by its usage.

Other interpretations are possible, for instruction words are stored just as data
words are, and the digits could represent an instruction to the computer. Since
memory locations can store either instruction words or data words, the
programmers and system operators must see that the instruction words are used to
determine the sequence of operations that the computer performs, and that the
computer performs, and that reasonable meanings are assigned to the words.

10.3 Instruction Word Formats

149
10.3.1 Numbers of Addresses

The number of divisions in the basic instruction word is determined primarily by


the number of addresses referred to. The single-address instruction has been
covered. Most current computers however, have two-address instruction words
with three sections; the first section consists of the op code and the second and
third sections generally each contain the address of an operand. Different
computers used addresses differently.

4
44
3
73
26
07
p
ap
ts
ha
W

150
Operation Code Address of operand
Single-address instruction

Address of Address of
Operation Code
operand (A) operand (B)
Two-address instruction

In many computers, instead of a single accumulator, there are two or more


registers called either multiple or general-purpose registers, or simple general
registers. Instruction words with two addresses can operate in one of the
following modes:

Memory, memory. Both addresses refer to memory locations. For two memory
address A and B, the instruction ADD A, B would cause the operation.
MEM[A]  MEM[A] + MEM[B]

4
Note: MEM[A] means “The contents of address A in memory”.

44
Example: Add the numbers in memory locations 963 and 492, and store
3
into memory location 963.
73

Add 963 492


26

MEM MEM
07

General register, memory. Address A in the instruction word specifies the


p
ap

general register to be used, and the second address indicated the location in
memory. A LOAD ACCUMULATOR instruction (LOAD A, B) would
ts

cause the contents at location B in memory to be transferred into the general


register denoted A. In symbols, GRA  MEM[B].
ha
W

Example: Add the number at memory location 492 into the operand in
GR3 and store into GR3.

Add 3 492
GR MEM

Memory, general register. The memory address A gives the location of the
operand in memory, and the general register code B is the register involved.
An instruction might be a STORE instruction (STO A, B), which would
move the contents of the general register into memory: MEM[A]  GRB.
Example: Add the value in GR4 into the value address at 1738 and store
into address 1738.

Add 1738 4
MEM GR

151
10.4 Representation of Instruction and Data
Important features of a computer‟s architecture are the number of bits in
instruction words, the size of memory words, and the way data is represented in
the computer.

Business data processing involves much manipulation involving character strings


(names, addresses, text, etc.). The desire to create computer architectures that
conserve on instruction word length and also permit efficient storage of character
strings of arbitrary length has led to a number of computer architectures with:

only 8 bits at each address in memory, so that a single alphanumeric character an


be stored at each address, and
instruction words with variable lengths (each word length is some multiple of 8
bits).

As a result, most computers now have memories where addresses are 8-bits bytes.
Instruction words are variable length, with each being some multiple of 8 bits.
Data words are also multiples of 8 bits, with many computers having 8-, 16-, 32-,

4
and even 64-bit data word lengths.

44
3
10.5 Addressing Techniques
73

There are several techniques used to specify a memory address. The use of any of
26

these techniques is generally motivated by one of the following considerations:


07

Desire to shorten address section


p

Programmer convenience
ap

System operation facilities


ts

The basic addressing techniques now in use: direct addressing, indirect


ha

addressing and indexed addressing.


W

10.5.1 Direct Addressing

By simply giving the complete binary memory address is the most direct way to
locate an operand or to jump. As a result, most computers provide for some form
of direct addressing.

Example: MOV AX, TABLE

This instruction loads the contents of data memory location TABLE into the AX
register.

10.5.2 Indirect Addressing

Another widely used addressing variation is called indirect addressing where the
instruction word gives the address not of the operand to be used, but the address
of the address of the operand.

152
For example, if we ADD 302 and the instruction is a conventional direct-
addressing instruction, the number at location 302 will be added to the word
currently in the accumulator. If the addition instruction is indirectly addressed,
and we write IAD 302 (indirect ADD), then the number stored at address 302 will
give the address of the operand to be used. As an example, when the instruction
word at address 5 in the following memory is performed, it will cause the number
164 to be added to the current contents of the accumulator.

Memory 5 : : 302 : : 49 Contents IAD


5 302 : : 495 : : 164

10.5.3 Indexed Addressing

There is a variation on conventional direct memory addressing that facilities


programming, particularly the programming of instruction sequences that are to
be repeated many times on a set of data distributed throughout the machine. This
technique is called indexing.

4
44
10.6 Instruction Types 3
73
The instruction set can be classified under 4 main groups:
26

Data Transfer
Arithmetic
07

Control Transfer
p

String Instructions
ap
ts

10.6.1 Data Transfer Instructions


ha

Data transfer instructions move data and addresses between register and a
W

memory location or I/O ports.

Example: Move [MOV]


The general form is: MOV destination, source

The fundamental general-purpose instruction is move[MOV]. It can transfer byte


or word data between register and a memory location or between two registers.
The source can also be a numeric value. It can also transfer an immediate data
value into a register or memory location.

However, the following must be noted:

data cannot be moved between two memory locations directly.


cannot load an immediate value. E.g. load the offset address of a segment into a
segment register.

153
10.6.2 Arithmetic Instructions

These instructions perform arithmetic operations on binary or BCD numbers.


Three are instructions for the four standard arithmetic functions namely:

addition
subtraction
multiplication
division
logical

10.6.3 Control Transfer

These are instructions that can transfer program execution from one part of
memory to another. These instructions can be divided into 3 groups:

Unconditional transfers

4
Conditional transfers

44
Iteration controls 3
73
10.6.3.1 Unconditional Transfers
26

It is generally used to skip over a group of instructions that executed from some
07

other part of the program.


Example: Call Procedure-name.
p
ap

10.6.3.2 Conditional Transfer


ts
ha

In the conditional Transfer instructions, if the condition is satisfied, the


instruction will be executed, otherwise it will continue on to the next
W

instruction in the program.


All conditional transfer instructions occupy two bytes in memory. The first byte
holds the operations code and the second bytes holds the relative
displacement.

10.6.3.3 Iteration Controls

The general form is LOOP target.


The iteration control instructions are conditional transfer, but have a very special
purpose. They set up repetitive loops.

10.6.4 String Instructions

The string instructions enable us to operate on blocks of bytes or words in


memory. These blocks, or strings, may be up to 64K bytes long, and may
consist of numeric values (either binary or BCD), alphanumeric values (such
as ASCII text characters) or, for that matter, any kind of information that can
be stored in memory as binary patterns.

154
10.7 Exercises
Briefly describe what is direct, indirect and indexed addressing.

Describe the difference between direct and indirect addressing.

Briefly describe three instruction types.

4
44
3
73
26
07
p
ap
ts
ha
W

155
Chapter 11 : Errors And Accuracy

Chapter Objectives

At the completion of this chapter, you should be able to:

 identify different types of errors;

 calculate absolute and relative error;

 estimate maximum absolute error;

 generate check digit.

4
44
11.1 Introduction
3
In building a system, measures must be taken against possible human mistakes.
73
Procedures must be set up to help people to detect any mistakes. The role of data
preparation or data entry are prone to errors, therefore they must not be
26

overlooked as the ill effect may affect the entire system seriously.
07

11.2 Mistakes
p
ap

At the man/machine input interface, i.e. when a person wants to enter data into a
computer system, the common mistakes are:
ts
ha

Lose track of the source documents.


W

Enter data wrongly.


Invalid datatype.
e.g. enter alphabets instead of numeric data.
Out of the valid data range.
e.g. enter 102 while the valid range is 1 to 100.
Transposition of characters.
e.g. enter 23322 while the actual data is 23223.
Interference in data transmission from a remote site.
e.g. 00100101 is transmitted along a cable and on the way due to voltage
surge, the data becomes 10100101.
and many more.

Mistakes are due to human carelessness.

Parity bit check.


Example:

156
If „B‟ is represented as 100 0010, we can use even parity conversion to
produce a parity bit.

IF odd number of 1‟s THEN


parity bit  1
ELSE
parity bit  0
ENDIF

The parity bit may be appended to the left of the 100 0010, „B‟ is
represented as 0100 0010. Suppose the data is received as 0110 0010, there
are three 1‟s which should give 1 in the parity bit, then the mistake is
detected.

Check digit method.


 A Check digit is derived from the true data before transmission, which
is then appended to the right of the true data for validation.

4
Step 1: A true data 445, each of the digits is assigned a weight,

44
4 3 2 Weightage
4 4
3 5
73
5 * 2 = 10
26

4 * 3 = 12
4 * 4 = 16
07

38
p

Step 2: The sum of 38 is to be divided by a modulus.


ap

(In this example, 11 is used as it can detect most of the


mistakes).
ts
ha

38/11 gives quotient 3 and the remainder 5.


W

Step 3: Remainder 5 is subtracted from the modulus (11) to


obtain the check digit „6‟.

11 - 5 = 6

Step 4: The check digit can be appended to the right of 445, to


give 4456, which could be validated.

In order to verify the correctness of 4456, we could just


multiply 4456 by the set of weight, 6 is assigned the
weight of 1,

4 3 2 1 Weightage
4 4 5 6
(4*4) + (4*3) + (5*2) + (6*1) = 44

44 is divisible by 11, thus conclude that 4456 is received correctly.

It has been tested that MOD 11 is most efficient in detecting mistakes,


reason being 11 is a prime number. Though bigger number is better, the

157
small increase in efficiency is overwhelmed by large increase in
processing.

Check point

List five types of mistakes which may occur during the data preparation and data entry
stages of the processing cycle.
Give one other example each of the appropriate use of the hash and batch totals. Describe
the principle of a parity check and how even and odd parity differ.
Using mod 7 and weighting 2,3,4,5..., append appropriate check digits to:
v. 439
w. 1058535

Using the same mod 7, determine whether the following are valid:
x. 1794
y. 10545722

4
11.3 Errors
44
3
73

11.3.1 Inherent Error


26

It is error that already exist by itself in the measurement scale. E.g. Take a ruler
07

of measurement, though there are many small divisions, there is still the smallest
division that is not sub-divided further. Thus there is uncertainty in reading the
p

length as mentioned above.


ap
ts

If the length fall between 5.1cm and 5.2cm, the smallest division is 0.1cm, then
the reported reading may be 5.15 cm and the inherent error is 0.05cm.
ha
W

11.3.2 Induced Error

It is the error which is brought in from „outside‟ due to external factors.

Example: In a fixed point 8-bit register in computer, the implied point is to


the right of 5 bits.

If a data 1010.01110 is to be stored, rounding or truncation is necessary.

Rounding the above data is stored as

0 1 0 1 0 1 0 0

Thus the error is brought in due to the limitation of computer.

Check point

What is the difference between error and mistakes?

158
11.4 Measurement of Error
Absolute error
 If a true value 2.5 is reported to be 3 (round to full number) an error of
0.5 is induced. This error is called the absolute error.
 Absolute error
Ea = | reported value - true value |

| | means the absolute value is taken, the sign is not considered at all.

Relative error
 Another more meaningful measurement of error is relative error,
because it expresses the absolute error as a proportion of the true value
(if the true value is not available, the reported value is used.)
Er = | absolute error / True Value |
= | absolute error / True Value | * 100%

4
44
Maximum relative error between any TWO values reported as
R =
3 100 * (error bound/R)
73
Example: 3.6 is rounded to 1D, the Maximum error between
26

3.55 and 3.65 = 100 * (0.1/3.6) = 2.78 %


07

Check point
p

What is the error bound of the values reported as:


ap

a. 3.5cm
ts

z. 45.3 seconds
ha
W

Calculate the maximum relative error on:


aa. 13.5
bb. 130.5
cc. 1300.5

11.5 Error Propagation


Inherent errors in data values, may produce further errors as they are operated on
arithmetically, these errors may be termed as Induced errors. This spread of errors
is called the Error Propagation.

159
Addition
Example: 5+7, each of the data values are rounded to whole number.

5.5 + 7.5 = 13 Max


4.5 + 6.5 = 11 Min

Er = 100 * (1/12) = 8.33%


Er of 5 = 10%
Er of 7 = 7.1 %

You may try 13 + 6, a conclusion may be derived.

Conclusion: Relative error of the sum is between the relative error of the
individual reported values.

Ea = absolute error of
Ea(A + B) = Ea(A) + Ea(B)

Subtraction

4
Example: 8-4, each rounded to whole number.

44
8.5 - 3.5 = 5 3 Max
7.5 - 4.5 = 3 Min
73

Ea(8-4) = 1 = Ea(8) + Ea(4)


26

Er =100 *(1/4) = 25%


07

Er of 8 = 100 * (0.5/8) = 6.25%


Er of 4 = 100 * (0.5/4) = 12.5%
p
ap

You may try 3-2


ts
ha

Conclusion: Relative error of the subtraction is more than the relative


error of the individual reported values.
W

Ea(A-B) = Ea(A) + Ea(B)

Multiplication
Example: 3*4*5, each rounded to whole number.
3*4*5 = 60,
3.5*4.5*5.5 = 86.625, Max
2.5*3.5*4.5 = 39.375, Min

Error bound = 86.625 - 39.375 = 47.25

This error bound is very big indeed, and it is not symmetrical about 60 (the
result of multiplying 3,4 and 5). If we quantify the relative error, it would be
as follow:

Take half of the error bound,


Er =100 * (23.625/60) = 39.375%
Er of 3 = 100 * (0.5/3) =16.667%

160
Er of 4 = 100 * (0.5/4) =12.5%
Er of 5 = 100 * (0.5/5) =10%

You may try 3*3*3, what conclusion you may draw?

Conclusion: Relative error of the multiplication is approximately the sum of


the relative errors of the individual reported values.

Er(A*B*C) = Ea(A)/A + Ea(B)/B + Ea(C)/C

Induced error in multiplication is the sum of the inherent error in


each reported value.

Division
Example: 7.5/5.3, each is rounded to 1D

7.55/5.25 = 1.438, Max


7.45/5.35 = 1.393, Min

4
Error bound = 1.438 - 1.393 = 0.045

44
Ea = 0.045/2 = 0.0225
3
Er of (7.5/5.3) = 100 * (0.0225/1.415) = 1.59%
73
Er of 7.5 = 100 * (0.05/7.5) = 0.667%
Er of 5.3 = 100 * (0.05/5.3) = 0.943%
26

Try 3.5/1.5,
07

Conclusion: Relative error of the division is approximately the sum of the


p

relative errors of individual reported values.


ap

Er(A/B) = Ea(A)/A + Ea(B)/B


ts
ha

Finally, try a combination of arithmetic operation, multiplying and division.


W

Example: (3.5*13.5*1.5)/(7.0*4.5*40.5)

In what ways the error propagated is maximised?


Multiply the top row and bottom row respectively, then
divide the numerator by the denominator.

In what ways the error may be minimised?


(3.5/7.0) * (13.5/4.5) * (1.5/40.5), the individual divisions
will produce values which are relatively small, overflow
error may be reduced.

Rounding
 Rounding errors frequently occur when doing manual decimal
arithmetic. They occur with even greater frequency in computer
arithmetic.
Example: If 0.0056 is rounded to 3 decimal places the answer is 0.006.
A rounding error of 0.006 - 0.0056 = 0.0004 is therefore
induced.

161
If 0.0055 is rounded to 3 decimal places, we may use the
following rule:
If the third decimal place is odd, do nothing;
else add 1 to the third decimal place.
0.0055 is rounded to 0.005.
If 0.0045 is rounded to 3 decimal places, the reported value
is 0.005.

Truncation
 If a storage space that can only accommodate 4 digits is used to store a
number 67890, the least signification digit „0‟ will be chopped off
giving 6789 as the number stored.
 If 1010.0010111 is to be stored in 12-bit register with 4 bits to the right
of the implied point. The stored data will be

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

4
44
3 Implied point
73
Overflow
 Overflow is different from truncation error in that the most signification
26

digit will be drop-out instead of the least significant. Storing 67890 in 4


digits, the most significant digit „6‟ is chopped off.
07

 This error is very serious in computer programming, thus many


p

compilers and interpreters are written such that they can deliver
ap

‘overflow error’ message.


ts

Significant figures
ha

 At times, we can only take a certain number of significant figures. Take


W

for example the population of Singapore, we may say there are


3,500,000 people taking only 2 significant figures. Even though we may
have found the population to be 3,547,893, as the less significant digits
47,893 is small compared to 3,500,000.
 A real number 2.03452355 may be expressed in 5 significant figures, as
2.0345.

Converting from one number system to another


 To convert 0.7 decimal to binary number will induce an error as shown
below:
.7 * 2
1.4 * 2
0.8 * 2
1.6 * 2
1.2 * 2
0.4 * 2
0.8...

162
The series of multiplication is recurring, if we to stop at 7 binary
places, we have to accept that an error is induced.

0.7 = (0.1011001)2

Rounding, truncation, overflow, significant figures and change of


number system will all lead to induced errors in data.

Check point

What is the effect on error if 3.5*7.25 is:


dd. Calculated to integer precision;
ee. Cut to 1D;
ff. Rounded to 1D;
gg. Calculated to 3 significant figures;
hh. Worked out „in full‟, with no cut or rounding.

4
44
11.6 To Control Errors 3
73
We want to calculate the volume of a sphere of radius 5.5 cm, the formula below
can be used:
26

V = (4/3)*r3
07

Take  = 3.141, and r = 5.5


p
ap

Er
r 5.5 0.91% Inherent
ts

V 696.7785 3*0.91 = 2.73% Induced


ha

This means that V has an absolute error of (2.73/100) * 696.7785 = 19.02.


W

This means that range of Volume is 696  19 cubic centimetres.


The decimal places are not significant.

To reduce the induced error, we should, if possible, take „r‟ to 5D and do the
same for p. Raise „r‟ to the third power, multiply by n, multiply by 4 and finally
divide by 3. Only by taking such precautions, could we minimise the errors.

Answers to check points

20. There are many possible sources of mistakes at this stage;


Document omitted or misread;
Transposition errors;
Characters omitted;
Mis-keying;
Out of range;

163
Invalid datatype;

There are many possible answers:


Hashing the invoice numbers;
Hashing the dates;
Batching totals of amount of money;
Batching totals of number of items withdrawn from store;
Parity checking is testing the make-up of the binary digits in a coded eight-
bit byte.
Even parity: by making the leftmost digit a 1,
if the total numbers of 1‟s in the remaining seven bits is
even;

Odd parity: by making the leftmost digit a 1,


if total number of 1‟s in the remaining seven bits is odd;

4
44
Data
Hash
3
Divide by 7, 7- Final
73
Total take remainder remainder data
439 43 1 6 4396
26

1058535 117 5 2 10585352


07
p

Divide by 7,
ap

Data Hash Total


remainder
ts

1794 47 5 not valid


ha

10545722 105 0 valid


W

Mistakes are made due to human carelessness in handling data. Errors arise from the data
itself, i.e. Inherent error; it may be brought in due to external factors like rounding, limit
of computer systems, i.e. Induced error.

Error bound = 3.45cm -- 3.55cm


Error bound = 45.25s -- 45.35s

Data Relative error


13.5 0.37%
130.5 0.038%
1300.5 0.0038%

164
The reported answer is 25.375.
ii. 3*7 = 21 Relative error = 17.2%
jj. 25.2 Relative error = 0.7%
kk. 3.5*7.3 = 25.55, Relative error = 0.7%
ll. 25.375 = 25.4 (3 sig.f.) Relative error = 0.1%
mm. 3.55*7.255 = 25.75525, Max
3.45*7.245 = 24.99525, Min
Error bound = 0.76
Relative error = 100*(0.38/25.375) = 1.5%

4
44
3
73
26
07
p
ap
ts
ha
W

165
Points to Remember
To distinguish mistake from error.
To be aware of how to reduce mistakes.
The methods are hash total, batch total, parity-bit method and check digit
method.
Inherent error.
 It is error that exist by itself in the measurement scale.

Induced error.
 It is error that is brought in from „outside‟ by external factors. Usually,
induced error is the result of propagation of inherent errors.

To measure error using two quantities.


 Absolute error Ea = „reported value - true value‟

4
 Relative error Er = Ea/True value

44
Error can spread, or propagate. 3
73
 Ea(A+B) = Ea(A) + Ea(B)
As a result of addition, the absolute error of (A+B) is the sum of
26

absolute error of A and that of B.


07

 Ea(A-B) = Ea(A) + Ea(B)


p

 Er(A*B*C) = Ea(A)/A + Ea(B)/B + Ea(C)/C


ap

 Er(A/B) = Ea(A)/A + Ea(B)/B


ts
ha

Types of errors.
 Rounding; Truncation; Overflow; Conversion
W

Divide a number by another, before multiplying them, is a method to reduce


possible overflow error.

166
11.7 Past Year Questions
21. Given that X = 5.63 and Y = 7.82, where each number has been rounded to 2
decimal places, calculate to 4 significant figures.
nn. Relative error when they are added [2]
oo. Relative error for X * Y [2]

x = 0.34 and y = 0.55, both corrected to 2 decimal places.


Find
pp. the absolute error of 2x + y [2]
qq. the relative error of 2x + y [2]

Two values are recorded as 8.7 and -4.3, both correct to 1D.
What is the ABSOLUTE ERROR when they are added together? [2]

4
Calculate the absolute and relative error of a + b given a = 3.5 (corrected to ID) and b =

44
1.55 (corrected to 2D). [4]
3
73
Pick the correct completion for each of the following sentences: [3]
rr. Discarding least significant digits of a number so it will fit in a fixed-
26

size storage location [1]


07

i. is a method of implementing floating-point numbers.


ii. is called truncation.
p
ap

iii. does not happen on modern computers.


ts

ss. The difference between the reported value and the true value of a
ha

quantity [1]
W

i. is the absolute error.


ii. is zero.
iii. is the inherent error.

tt. Error can arise in computations [1]


i. only when the initial readings for values are inaccurate.
ii. if the mantissa of a computed result won‟t fit in the storage space
allocated for it without loss of data.
iii. because no real numbers can be represented exactly in a floating-
point representation.
_

___________________ errors are ones which reflect the smallest measurement possible
one the scale used. [1]
Subtraction is __________________ susceptible to error propagation than is addition.[ 1 ]

167
Explain briefly what is inherent and induced error. [4]

Using mod 11 and weighting of 2, 3 and 4 for units, tens, and hundreds
columns, calculate a check digit for 834. [3]

An account number consists of 10 digits, the tenth digit being a CHECK DIGIT,
MODULES 11.

uu. Calculate an appropriate check digit for 005611350. [4]


vv. Which of these numbers would be declared invalid: 0765213141,
0265073147? [2]

Using mod 7 and weighting of 2, 3, 4 for the units, tens and hundreds columns
append an appropriate CHECK DIGIT to each of 928 and 921.
[3]

4
44
Using modules 11 and weighting of 2, 3 and 4 for the units, tens and hundreds columns:
3
ww. append a CHECK DIGITS to the number 758. [2]
73
xx. show why there is a problem when generating a check digit for 748, and
26

suggest how to overcome this problem. [2]


yy. determine whether or not 8752 is a VALID CODE. [2]
07
p

a. Using mod 11 and weighting of 2, 3 and 4 for the units, tens and hundreds
ap

columns, append a check digit to 974. [2]


ts

zz. Show how a transposition error occurring in the number 974 would be
detected. [2]
ha
W

22. a. What is parity in a parity check? [1]


aaa. When will a parity check fail? [1]

23. a. How is data verification performed? [2]


bbb. Why might data verification be used? [1]
ccc. How might the data entry be validated? [2]

Describe what is the purpose of a check digit? [2]


24. a. Write the decimal fraction 4.0 as binary fraction using only four binary
digits after the decimal point. [1]
ddd. Convert your answer back to denary, and determine the absolute error.
[1]
eee. Calculate the relative error. [2]

168
Chapter 12 : Statistics

Chapter Objectives

At the completion of this chapter, you would have learnt:

 to understand why statistics are used to solve real life problem;

 to use general guidelines to organise data into Frequency Table;

 to use various charts and graph to display data, e.g. Histogram Cumulative
Frequency Diagram;

 to calculate Standard Deviation, Variance as measures of central tendency;

 to calculate Standard Deviation, Variance as measures of spread or

4
dispersion.

44
3
73
12.1 Introduction
26

An addition to our ordinary; Boolean algebra, De Morgan‟s Laws is one tool used
07

for simplifying complex expressions in Boolean algebra or complex switching


circuits.
p
ap

Process that entails destruction of products if physical testing is carried.



ts

E.g. To substantiate the life span of light bulbs from a factory.


ha

Situations are too large and too complicated if physically counting were carried
W

out.
 E.g. The number of people suffering from AIDS in Asia.

Situations where forecast or predictions are to be made based on past information.


 E.g. The weather forecasting.

Statistics involve the process of collecting data from a sample, make appropriate
deductions from the sample. In this chapter, we will look at now to organise data
into frequency table, display data in proper charts and calculate relevant
quantities.

12.2 Raw Data


Raw data, once collected has to be organised numerically. An example is the set
of names of male students obtained from an alphabetical listing of a public school
records.

169
12.2.1 Arrays

An array is an arrangement of raw numerical data in ascending or descending


order of magnitude. The difference between the largest and smallest numbers is
called the range of the data. For example, if the heaviest weight of 100 male
students is 74 kg and the lightest weight is 60 kg, then the range is 74-60 which
gives 14kg.

12.3 Grouped Data

12.3.1 Frequency Distributions

When summarising large masses of raw data it is often useful to distribute the
data into classes or categories and to determine the number of individuals
belonging to each class, called the class frequency. A tabular arrangement of
these data by classes together with the corresponding class frequencies is called a
frequency distribution or frequency table. The table below shows a frequency
distribution of weights (recorded to the nearest kg) of 100 male students at

4
Informatics Computer School.

Mass (Kilogram)
44 Number of Students
3
73
60 - 62 5
63 - 65 18
26

66 - 68 42
07

69 - 71 27
72 - 74 8
p
ap

Total = 100
ts

The first class, for example, consists of weights from 60 to 62kg. Since 5 students
ha

have weights falling between this class, the corresponding class frequency is 5.
W

Data organised and summarised as in the above frequency distribution are often
called grouped data.

12.3.2 Class Intervals and Class Limits

A range of values defining a class such as 60-62 in the above table is called a
class interval. The end numbers, 60 and 62, are called class limits. The smallest
number 60 is the lower limit and the larger number 62 is the upper class limit.

12.3.3 Class Boundaries

If weights are recorded to the nearest kg, the class interval 60-62 theoretically
includes all measurements from 59.5 kg to 62.5kg. These numbers, indicated
briefly by the exact numbers 59.5 and 62.5, are called class boundaries or true
class limits. The smaller number 59.5 is the lower class boundary and the larger
number 62.5 is the upper class boundary.

170
Sometimes, class boundaries are used to symbolise classes. For example, the
various classes in the first column of the previous table could be indicated by
59.5-62.5, 62.5-65.5, etc.

12.3.4 The Size of a Class Interval

The size of a class interval is the difference between the lower and the upper class
boundaries and is also referred to as the class width, class size or class strength.
For instance, the class interval for the above example is 62.5 - 59.5 = 3.

12.3.5 The Class Mark

The class mark is the midpoint of the class interval and is obtained by adding the
lower and upper class limits and dividing by two. Thus the class mark of the
(60  62)
interval 60 - 62 is = 61. The class mark is also known as the class
2
midpoint.

4
General rules for forming frequency distributions:

44
 Determine the largest and smallest numbers in the raw data and thus
find the range. 3
73
 Divide the range into a convenient number of class intervals having the
same size.
26

 Determine the number of observations falling into each class interval.


07

12.4 Presentation of Statistical Data


p
ap

A graph is a pictorial representation of the relationship between variables. Many


ts

types of graphs are employed in statistics, depending on the nature of the data
ha

involved and the purpose for which the graphs are intended. Among these are bar
graphs, pie graphs, pictographs, etc. These graphs are sometimes referred to as
W

charts or diagrams.

12.4.1 Histogram and Frequency Polygons

There are two graphical representations of frequency distributions.

A histogram of a frequency distribution consists of a set of rectangles having


 Bases on a horizontal axis with centres at the class marks and lengths
equal to the class interval sizes; and
 Areas proportional to class frequencies.

A frequency polygon corresponding to the above frequencies plotted against class


marks. It can be obtained by connecting midpoints of the tops of the
rectangles in the histogram.

The histogram and frequency polygon corresponding to the above frequency


distribution of weights are shown on the same set of axes in the graph below. It is
necessary to add the extensions PQ and RS to the next lower and higher-class
marks which have corresponding class frequency of zero.

171
12.4.2 Cumulative Frequency Distributions

The total frequency of all values less than the upper class boundary of a given
class interval is called the cumulative frequency up to and including the class
interval. For example, the cumulative frequency up to and including the class
interval 66-68 is 5 + 18 + 42 = 65, signifying that altogether 65 students have
weights less than 68.5kg.
No. of Students (Frequency)

40 -

30 -

20 -
R

4
10 -
P

44
Q S
| | | |
3 | | | x
73
0 58 61 64 67 70 73 76
26

Mass (Kilograms)
07
p
No. of Students (Frequency)

ap

100 -
ts
ha

80 -
W

60 -

40 -

20 -

0 | | | | | |
59.5 62.5 65.5 68.5 71.5 74.5

Mass (Kilograms)

A graph showing the cumulative frequency less than any upper class boundary
plotted against the upper class boundary is called a cumulative frequency
polygon. (Ogive)

Example:

172
The final marks for Computer Science of 80 students at ABC University are
recorded in the following table.

68 84 75 82 68 90 62 88 76 93
73 79 88 73 60 93 71 59 85 75
61 65 75 87 74 62 95 78 63 72
66 78 82 75 94 77 69 74 68 60
96 78 89 61 75 95 60 79 83 71
79 62 67 97 78 85 76 65 71 75
65 80 73 57 88 78 62 76 53 74
86 67 73 81 72 63 76 75 85 77

Using the above data, draw:

fff. A histogram,
ggg. A frequency polygon, and
hhh. A cumulative frequency curve.

4
44
Solution:
3 Cumulative
73
Class Class Mark Frequency
Frequency
26

56 - 60 58 6 6
61 - 65 63 11 17
07

66 - 70 68 7 24
p

71 - 75 73 19 43
ap

76 - 80 78 15 58
ts

81 - 85 83 8 66
ha

86 - 90 88 7 73
W

91 - 95 93 5 78
96 - 100 98 2 80

173
20 -

18 - Histogram
16 -

14 -

12 - Frequency Polygons
Students
No. of

10 -

8 -

6 -

4 -

4
44
2 -

0 | | | |
3 | | | | | | x
73
53 58 63 68 73 78 83 88 93 98
26

Marks
07
p
ap

80 - x
Cumulative Frequency Curve x
ts

70 - x
ha

x
60 -
No. of Students

x
50 -

40 - x

30 -
x
20 -
x
10 -
x
0 x| | | | | | | | | | x
55.5 60.5 65.5 70.5 75.5 80.5 85.5 90.5 95.5 100.

Marks

174
12.5 Three Statistical Quantities of Central Tendency

12.5.1 The Arithmetic Mean

The arithmetic mean or the mean of a set of n numbers X1, X2, X3, ..., XN is
denoted by X and is defined as

X1  X 2  X 3  ...  X N
X
j1
j
X
X =  
N N N

Example:

The arithmetic mean of the numbers 8, 3, 5, 12, 10 is

8  3  5  12  10 38
X =   7.6
5 5

4
44
If the numbers X1, X2, ..., XN occur f1, f2, ..., fN times respectively the arithmetic
mean is given by:
3
73
N

f1X1  f 2 X 2  f 3 X 3  ...  f N X N
f X
j 1
j j
 fX
X =  
26

f1  f 2  ...  f N
f
N

j
f
07

j 1
p

Example:
ap

The arithmetic mean of the numbers 5, 8, 6 and 2 which occurs 3, 2, 4 and 1 time
ts

respectively is:
ha

(3)(5)  (2)(8)  (4)(6)  (1)(2) 15  16  24  2


W

X =   5.7
3  2  4 1 10

12.5.2 The Median

The median of a set of numbers arranged in order of magnitude (i.e. in an array)


is the middle value or the arithmetic mean of the two middle values.

Example:

The set of numbers 3, 4, 4, 6, 6, 8, 8, 8, 10 has a median of 6.

Example:

1
The set of numbers 5, 5, 7, 9, 11, 12, 15, 18 has a median = (9 + 11) = 10.
2

For a grouped data, the median, obtained by interpolation is given by

175
   f 1 
N 
Median = L1 +  2  xc
 f median 
 
 
where

L1 = Lower class boundary of the median class


(i.e. the class containing the median).

N = Number of items in the data


(i.e. total frequency).

(f)1 = Sum of frequencies of all classes lower than


the median class.

fmedian = Frequency of median class.

4
44
c = Size of median class interval.
3
73
Median of grouped data may also be obtained graphically using cumulative
Frequency Diagram.
26
07

Example:
p

By first creating a cumulative frequency table and then a cumulative frequency


ap

diagram, estimate the median of the following survey of the examination marks
ts

of 80 students on a particular computer course.


ha
W

Marks (%) No. of students


0 - 20 3
21 - 40 19
41 - 60 35
61 - 80 22
81 - 100 1

176
Median is the mark below which 50% of the students‟ score, and therefore above
which another 50% of the student score.

Marks (less than or = ) Cumulative Frequency


20 3
40 22
60 57
80 79
100 80

Cumulative Frequency Table

80 -

70 -
Cumulative Frequency

4
44
60 -

50 - 3
73
40 -
26

30 -
07

20 -
p

10 -
ap

0 | | | | | | | | | | x
ts

10 20 30 40 50 60 70 80 90 100
ha

Marks
W

Figure 12-1

From the above Figure 12-1, there are 40 students who score 52 marks or less and
the other 40 score more than 52 marks. The median is 52 marks.

In Figure 12-1, 39 mark is the lower quartile, which is the mark below which
25% of the population of students score (or 20 out of 80). 61 marks is the upper
quartile below which 75% of the student score, (or 60 out of 80). The range of
(61 - 39) = 22 is the Inter-quartile range.

177
12.5.3 The Mode

The mode of a set of number is that value which occurs with the greatest
frequency, i.e. it is the most common value. The mode may not exist, and even if
it does exist, it may not be unique.

Example:

The set 2, 2, 5, 7, 9, 9, 9, 10, 10, 11, 12, 18 has a mode = 9.

Example:

The set 3, 5, 8, 10, 12, 15, 16 has no mode.

A distribution having only one mode is called uni-modal.

In the case of a grouped data where a frequency curve has been constructed to fit
the data, the mode will be the value (values) of X with the highest frequency.

4
From a frequency distribution or histogram the mode can be obtained using the

44
following formula.
3
73
 1 
Mode = L1 +   x c
 1   2 
26
07

where
p

L1 = Lower class boundary of modal class


ap

(i.e. class containing the mode).


ts
ha

1 = Excess of modal frequency over frequency of


previous lower class.
W

2 = Excess of modal frequency over frequency of next


higher class.

c = Size of modal class interval.

Mode of grouped data may be estimated from Histogram as shown in Figure 12-
1.

178
Example:

Estimate the mode of the following distribution of salaries of employees in a


computer company:

Salary ($) No. of people


4000 - 2
5000 - 12
6000 - 19
7000 - 25
8000 - 36
9000 - 17
10000 - 9

iii. By graphical means; and

4
44
jjj. By calculation means.

Solution:
3
73

a.
26
07

40 -
p
ap
No. of People

30 -
ts
ha

20 -
W

10 -

| | | | | | | | | | |
0 1 2 3 4 5 6 7 8 9 10 11

Salary (Thousand Dollar)

Figure 12-2 : Histogram

The category 8000 - 9000 has the highest frequency, it is called the modal
class. The estimated mode is in this category (or class). It can be estimated
as shown in Figure 12-2.

179
kkk. Mode can be estimated using the formula.

  
Mode = L1 +  1
 x c
 1 2 
 

L1 = 8000

1 = 11

2 = 19

c = 1000

11
Mode = 8000 + x 1000 = 8366.67
11  19

12.6 Dispersion and Variation

4
44
The degree to which numerical data tend to spread about an average value is
called the variation or dispersion of the data. Various measures of dispersion or
variation are available. 3
73

12.6.1 Mean Deviation


26

The mean deviation or average deviation of a set of N numbers X 1, X2, ..., XN is


07

defined by:/*
p

| X  X |
ap

j
j1
Mean Deviation = X =
ts

N
ha

Example:
W

Find the mean deviation of the set of numbers 2, 3, 6, 8, 11.

Solution:
2  3  6  8  11
Arithmetic Mean = X = =6
5

| 2  6 |  | 3  6 |  | 6  6 |  | 8  6 |  | 11  6 |
Mean Deviation (MD) =
5
| 4 |  | 3 |  | 0 |  | 2 |  | 5 |
=
5
43 0 25
= = 2.8
5

If X1, X2, ..., XK occur with frequencies f1, f2, f3, ..., fk respectively, the mean
deviation can be written as :

180
K

f
j1
j | Xj X |
Mean Deviation =
N
K
where N = f
j1
j = f j

This form is useful for grouped data where the Xj‟s represent class marks and the
fj‟s are the corresponding frequencies.

12.6.2 The Standard Deviation

The standard deviation of a set of N numbers X1 , X2 , ..., XK is denoted by SD


and is defined by

 f X  X 
N
2
j j
i 1
SD =

4
N

 X X  44
3 2

=
73
N
26

X 2

 X2
07

=
N
p

If X1, X2, ..., XK occur with frequencies f1, f2, ..., fK respectively, the standard
ap

deviation can be written as:


ts
ha

 f X  X 
K
2
j j
W

i 1
SD =
N

 f X X 
2

=
N

=
 fX 2

 X2
N
K
where N = f i 1
i  f
This form is useful for grouped data.

181
12.6.3 The Variance

The variance of a set N numbers X1, X2, ..., XK is defined as the square of the
standard deviation and is thus given by

 (X  X)
i 1
j
2

Var =
N

=
 (X X) 2

 X2
N

=
X 2

 X2
N

If X1, X2, ..., XK occurs with frequencies f1, f2, ..., fK respectively, the variance
can be written as:

4
44
K

 f (X  X)
i 1
i j
3
2

Var =
73
N

 f(X X) 2
26

=
N
07

 fX 2
p

=  X2
ap

N
K
ts

where N = f i = f
ha

i 1
W

This form is useful for grouped data.

Example:

Find the standard deviation and variance of the following set of numbers:

12, 6, 7, 3, 15, 10, 18, 5

Arithmetic mean = X 
X
N

12  6  7  3  15  10  18  5
=
8

76
= = 9.5
8

182
SD =
 (X  X) 2

N
= (12  9.5) 2  (6  9.5) 2  (7  9.5) 2  (3  9.5) 2  (15  9.5) 2  (10  9.5) 2  (18  9.5) 2  (5  9.5) 2
8

= 23.75
= 4.87
Var = (4.872)2
= 23.75

Example:

Find the standard deviation of the weights of the 100 male students at Informatics
Computer School as shown in the table below.

Mass (Kilogram) Number of Students

4
60 - 62 5

44
63 - 65 18
66 - 68 3 42
73
69 - 71 27
72 - 74 8
26

Total 100
07
p

Solution:
ap

Mass Frequency
ts

Class Mark Fx fX2


(Kg) (f)
ha

60 - 62 61 5 305 18605
W

63 - 65 64 18 1152 73728
66 - 68 67 42 2814 188538
69 - 71 70 27 1890 132300
72 - 74 73 8 584 42632
fX = fX2 =
N = f = 100
6745 455803

X =
 fX =
 fX =
6745
= 67.45kg
f N 100

SD =
 fX 2

 X2
N

455803
=  (67.45) 2 = 2.92kg
100

183
Points to Remember

To use some guidelines to organise data into frequency distribution table


(grouped data).
Use line graph, bar chart, piotogram, pie chart, histogram and cumulative
frequency diagram to display data in graphical form.
Calculate mean, median and mode as measures of central tendency.

Raw Data Grouped Data


Mean x  fx
N f
Median Take the middle data 1. Use cumulative
from a sorted list. frequency
diagram.

4
2. Use formula.

44
Mode Take the data that 1. Use histogram.
appear most 3
73
frequency. 2. Use formula.
26

Calculate standard deviation and variance as measures of spread or dispersion.


07
p

Raw Data Grouped Data


ap

x  x   f(x)   fx 
2 2 2 2
Standard
ts

   
Deviation  N  f  f 
ha

N    
W

Variance (Standard Deviation)2 (Standard Deviation)2

Use time series graph to observe the trend of a variable over time.
Use scatter diagram to observe the correlation between two variables.

184
12.7 Past Years Questions
Given the following collection of numbers 2, 4, 5, 5, 6, 7.
lll. Calculate the mean (round to 1 decimal place). [2]
mmm. C
alculate the mode. [1]
nnn. Calculate the median. [1]

a. What is mean? [1]


ooo. What is mode? [1]

A grade of 1 to 5 could be obtained in an examination and the actual scores were


distributed as follows:

4
Grade 1 2 3 4 5

44
No. of Candidates 4 3 3 9 2 2
73
Find:
26

ppp. the mean; [2]


07

qqq. the median; [2]


rrr. the mode. [1]
p
ap

Given a series of numbers : C, 5, 6, 8, 12, 25, and the mean of these numbers is 15:
ts

sss. Find C; [2]


ha

ttt. Find the median. [2]


W

Given the following collection of integers, where X is unknown:


3, 2, 7, 2, 2, 4, 5, 2, 4, 6, X
uuu. What can be said about the median? [3]
vvv. What can be said about the mode? [2]
www. W
hat can be said about the mean? [2]
xxx. If the mean was given as 4, what would be the value of X? [3]

Ten students have taken an examination and been given their marks. Student X will not
say what his mark is, but the other students have marks of 2, 4, 6, 6, 7, 7, 7, 8 and 10. The
teacher has told everyone that the mean mark was 6.
yyy. What mark did student X obtain? [2]
zzz. What mark is the median? [1]

185
aaaa. W
hat mark is the mode? [1]
The heights of a group of students from a secondary school are distributed as follows:
Height(m) 1.4<=ht<=1.5 1.5<=ht<=1.6 1.6<=ht<=1.7 1.7<=ht<=1.8 1.8<=ht<=1.9 1.9<=ht<=2.0
Frequency 5 30 36 40 8 1

bbbb. D
raw a histogram of this data on graph paper. [4]
cccc. C
alculate the mean and standard deviation. [6]
dddd. P
roduce a cumulative frequency table. [2]
eeee. D
raw the cumulative frequency curve. [3]
ffff. From the cumulative frequency curve, find the median and interquartile
ranges. [3]

4
44
gggg. F
rom the graph, determine the probability that the height of a student
3
selected at random will be at least 1.7m. [2]
73

In a class the heights of a graph of students to the nearest centimetre are as follows:
26

160 - 164 cm  12 students


07

165 - 169 cm  8 students


p

170 - 174 cm  10 students


ap

175 - 179 cm  7 students


ts
ha

hhhh. P
lot a table for the above data in order to calculate: [8]
W

iiii. the mean height rounded to one decimal places; [4]


jjjj. the variance rounded to two decimal places; [4]
kkkk. t
he standard deviation rounded to two decimal places. [4]

The table shows the results of a survey of 100 students about the number of hours they
spent daily in studying for an examination.

No. of study hours 1 2 3 4 5 6


No. of students 15 42 18 10 9 6

llll. Draw the histogram for the above data. [4]


mmmm. W
rite down the mode. [2]
nnnn. C
onstruct a cumulative frequency table. [2]

186
oooo. D
raw the cumulative frequency curve. [3]
pppp. E
stimate to 1 decimal place the median from the curve. [2]
qqqq. F
ind the mean and standard deviation to 2 decimal places. [7]

The scores of 100 students for their computer studies are as follows:
81 -
Score 1 - 20 21 - 40 41 - 60 61 - 80
100
No. of students 17 10 27 33 13

rrrr. Plot the above distribution using a Histogram. [6]


ssss. From the Histogram, estimate the Mode. [2]
tttt. Construct a table for the calculation of the Mean and Standard
Deviation to 2 decimal places. [7]

4
44
uuuu. C
onstruct the Cumulative Frequency table and draw the Cumulative
3
Frequency Curve. [5]
73

The candidates scores of a random sample of marked examination scripts are shown
26

below: (Individual scores)


07

26 30 45 53 96 38 87 76
p

89 18 75 9 35 68 56 28
ap

62 71 54 49 33 77 20 54
ts

6 41 39 76 79 85 93 65
ha

44 65 68 84 84 89 94 18
W

vvvv. U
sing class intervals of 1 -10, 11 -20 and so on, produce a frequency
distribution table of the above data. [5]
wwww. O
n the Graph paper, construct the histogram of the frequency
distribution. [6]
xxxx. C
alculate, by tabulation,
i. the mean score;
ii. the standard deviation. [9]

The distribution of candidates‟ marks obtained in a test is given by:

Marks 1 - 10 11 - 20 21 - 30 31 - 40 41 - 50 51 - 60 61 - 70 71 - 80 81 - 90 91 - 100
Freq 6 5 8 13 12 18 16 15 11 8

187
yyyy. O
n Graph paper draw the Histogram and use it to estimate the MODE.
[6]
zzzz. C
alculate, by tabulation the
i. mean;
ii. standard deviation. [8]

aaaaa. C
onstruct a cumulative frequency table. [2]
bbbbb. P
lot the cumulative frequency curve on a graph paper. [4]
The distribution of a product‟s rating obtained in a survey is given by:

Marks 1 - 20 21 - 40 41 - 60 61 - 80 81 - 100 101 - 120 121 - 140

4
Freq 6 8 14 10 20 22 10

44
ccccc.
3 O
73
n graph paper draw a histogram representing this distribution. [4]
ddddd. C
26

alculate, by tabulation [8]


07

i. the mean rating to 2 decimal places;


ii. the standard deviation to 2 decimal places.
p
ap

eeeee. C
ts

onstruct a cumulative frequency table. [2]


ha

fffff. Plot the cumulative frequency curve on graph paper. [4]


W

ggggg. E
stimate from the graph:
i. the median; [1]
ii. the upper quartile. [1]

Forty students run a marathon. The frequency distribution of their times in minutes are as
follows:
Time (Minutes) f
170 - 189 2
190 - 209 8
210 - 229 4
230 - 249 14
250 - 269 3
270 - 289 2
290 - 309 3

188
310 - 329 1
330 - 349 1
350 - 369 2
f

hhhhh. O
n graph paper, draw a histogram representing the distribution. [4]
iiiii. Construct a cumulative frequency table from your distribution table.
[2]
jjjjj. Plot the cumulative frequency curve on graph paper. [4]
kkkkk. C
alculate to 2 decimal places, by tabulating the data in your distribution
table:
i. the mean time taken by the students to run the marathon; [4]
ii. the standard deviation. [4]

4
44
lllll. The race starter realises that he made a mistake, and that the times
reported are all 5 minutes lower than they should be. How does this
3
affect:
73
i. the mean? [1]
26

ii. the standard deviation? [1]


07
p
ap
ts
ha
W

189

You might also like