Whatsapp 0726 733 444: Mathematics For Computing
Whatsapp 0726 733 444: Mathematics For Computing
Whatsapp 0726 733 444: Mathematics For Computing
44
3
73
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.10 Exercises .................................................................................................. 3-6
3.11 Past Years Questions................................................................................ 3-9
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
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
4
9.5 Transformations ..................................................................................... 9-11
44
CHAPTER 10: REPRESENTATION OF INSTRUCTION ..... 10-1
3
73
10.1 Introduction ............................................................................................ 10-2
26
4
Chapter 1 : Number Bases
Chapter Objectives
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
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
5
Real Can be represented by points a the straight
R
line Example: -2.31, 5 , 6
4
44
3
73
26
07
p
ap
ts
ha
W
6
1.2.1 Single 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.
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
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
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.
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
= 497649610
ha
W
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
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
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.
Binary Octal
000 0
9
001 1
010 2
011 3
100 4
101 5
110 6
111 7
We need three binary bits to represent symbols in octal! Likewise, one octal
number will produce three binary bits.
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
1 A C
p
ap
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.
10
multiply 0.75 by 2 continuously until the fraction becomes zero or the degree of
accuracy is satisfied.
2 4 0
2 2 0 0.75 * 2
1 1 1.5 * 2
1.0
0.11
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:
= 6.09375
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
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
12
A16
+ 916
Decimal sum 19
Modification - 16
Octal sum 1316
“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
30/12 = 2 remainder 6
W
30 mod12 = 6
Points to Remember
The higher the precision required the longer the processing time in computer
systems.
13
4 number systems
Decimal (Denary)
Binary
Octal
Hexadecimal
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
a. Binary [1]
b. Denary [1]
c. Hexadecimal [1]
14
j. 1100110101 binary to octal [1]
k. ACD hexadecimal to denary [1]
l. 2464 octal to hexadecimal [1]
4
44
s. in binary [1]
t. hexadecimal 3 [1]
73
Convert:
26
1. Convert:
ap
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]
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
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]
4
44
3
73
26
07
p
ap
ts
ha
W
17
Chapter 2 : Computer Based Arithmetic
Chapter Objectives
integer
fraction
mixed number;
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:
4
0+1 = 1
44
0+0 = 0
3
73
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
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
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
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:
1101 13
x 1100 x 12
0000 26
0000 13
1101 156
1101
10011100
Example:
101 5
x 111 x 7
4
44
101 35
101
101 3
73
100011
26
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
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
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
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
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
information.
ha
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.
Example: 16 bit words are common and hold numbers from -32768 to
32767.
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
Even if you know that the data is numeric, make sure you have the right
format
ts
ha
W
[00110101|11000000]
0 0 1 0 1 1 0 1 1 1 1 1
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
0 0 0 0 0 0 0 0 1 0 0 1
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
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
bit
W
Decimal 0.4140625
0 0 1 1 0 1 0 1 0 0 0 0
26
Sign bit Implied bicimal point “padding”
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
4
44
Double length fractions have increased accuracy, not range
3
73
0 0 1 0 1 1 1 1 0 0 0 0
ts
ha
Divide as necessary
0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 0 0 1 0 0 0 0 0
Usual convention is one word for integral part, the other for fraction
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.
Steps:
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)
28
8‟ = 2 because 8 + 2 = 10 as such
8 - 2 = (8 + 8) - 10 = 6
6 - 4 = (6 + 6) - 10 = 2
Example:
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
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
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.
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
0 0 0 0 0 1 1 0 0 1 0 0
p
ap
0 0 0 0 1 1 0 0 1 0 0 0
W
0 0 0 1 1 0 0 1 0 0 0 0
+ 400 = (50 x 23)
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]
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
Calculate the following using complement subtraction, assuming the numbers are stored
ts
form.
i. Write down the COMPLETE range of INTEGERS which can be
held. [2]
ii. Show how 96 - 124 would be evaluated. [4]
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]
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
of format:
i. TWO‟s complement. [3]
p
ap
33
Chapter 3 : Floating Point Representation
Chapter Objectives
At the completion of this chapter, you would have learnt how to:
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
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)
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
4
44
following steps.
Steps: 3
73
Convert given numbers into binary.
26
Format A
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.
4
Mantissa Exponent
44
Mantissa always 1 or greater, but less than 10.
3
73
1 < |M| < 10
26
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.
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
In this method, the value of 2n-1 is added to the actual exponent whether
p
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
4
44
0 1 0 1 0 0 0 3 1 0 0 0 0 0 1 0 1
73
Exponent
26
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
38
Express -20.25 in 2‟s complement mantissa and 2‟s complement exponent format.
Solution:
Steps:
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
Express 20.25 in sign modulus mantissa and excess 2n-1 method format.
Solution:
Steps:
iii.
0 1 0 1 0 0 0 1 0 0
Sign
39
iv. To store exponent in 2‟s excess method
0 1 0 1 0 0 0 1 0 0 1 0 0 1 0 1
Exponent
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
or
iii. Convert m1 to decimal.
p
ap
Solution:
0 110000000 011111
m e
Steps:
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]
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
1 0 1 0 1
ap
ts
A normalised floating point number uses a 10 bit TWO‟s complement mantissa followed
ha
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
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]
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
42
Chapter 4 : Set
Notation Representation
And Probability
Chapter Objectives
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
and use tree diagrams to depict all possible outcomes in a program, it helps
ts
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.
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.
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
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.
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 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 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?
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.
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 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
U U
4
A
44
A
B
3
73
26
B C
07
BA ABC
p
Figure 6-4
ap
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
4
U U
44
A
A
B 3
73
26
B C
07
BA ABC
p
ap
Figure 6-6
ts
Fact
If A B = then A and B are disjoint.
A B
AB
Figure 6-7
49
U
A B
AB
Figure 6-8
A B
AB
4
44
3
73
Figure 6-9
26
07
4.6 Properties
p
ap
Commutative Property
AB=BA
ts
AB=BA
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)
i. A (B C) = {1,3,5,7} {1,2,3,4,7}
= {1,3,7}
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.
B T
4
44
27 - 17 25 - 17
17
= 10 3 =8
73
x
26
Figure 6-10
07
p
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
repetition statements.
ap
Example:
ts
ha
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
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
nn. (R Q) [1]
oo. (R Q)‟
p
[3]
ap
ts
qq. (A B) (A C) [2]
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]
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
eee. How many students are sitting only one subject? [2]
ts
ha
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
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
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]
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
by which a certain amount of order and predictability may be derived from the
natural state of uncertainty.
ha
W
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:
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
1
P(PAD or DAP) =
ha
3
W
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.
s
Hence P (number greater than 2) =
f s
4
44
4
=
24
=
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:
Solution:
s = 13
f = 13 + 13 + 13
n = f + s = 13 + 13 + 13 + 13 = 52
13
Therefore P(a club) =
52
1
=
4
59
n represents the number of all possible ways an even can occur.
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:
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
14. The same number of typists use (E) as use (W). How many use (W) only?
15. How many typists use (E)?
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
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
ap
a = 4
ts
n(E) = b+4+5+1
W
n(E) = 15
= 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
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
A B
4
44
4.12.2 General Addition Law 3
73
If A and B are two events then
26
p
A B
ap
ts
ha
W
If P(A and B) = 0
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
4
6
44
Therefore the probability of getting a number not more than 5
3
1 5
73
=1- =
6 6
26
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
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
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.
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
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)?
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
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:
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
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
1
ap
1
ha
67
Points to Remember
Definition of probability
Probability of an event E
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
= 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
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 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
wwww. W
hat is the probability of getting first draw an apple, second draw an
p
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]
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
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
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
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
Sooner or later, in all but the simplest of programs, we meet a situation where we
ts
something different”. This means that we must be able to model the problem in
W
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.
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‟.
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
We often use the small letters p, q and r as the symbols for this sort of logical
ts
of the two statements in conjunction. The consequences refer to the four possible
results of any compound of two statements.
W
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.
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
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
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.
Z = A + B.C
or
Z = A OR (B AND (NOT) C)
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
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
A B A+B A.(A + B)
76
0 0 0 0
0 1 1 0
1 0 1 1
1 1 1 1
A B A.B A + A.B
0 0 0 0
0 1 0 0
1 0 0 1
1 1 1 1
4
44
Note also that these outputs are also exactly the same as the inputs for A.
It has long been the practice to illustrate such possibilities, in Control Systems, by
p
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
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
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
A Truth Table shows the relationship between input conditions and output.
78
1 1 1
When input A and B are both „1‟, the output will be „1‟.
C = A . B (read as A AND B)
or
C=AB
A
B D
C
4
is the same as
44
A
3 C
73
B
D
26
C
07
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
A C
B
79
The analogy of an OR gate is as follows:
Switch A
Switch B
Lamp C
Battery
4
44
ON OFF ON
ON ON
3 ON
73
It can also be represented by the following truth table:
26
0 0 0
p
ap
0 1 1
ts
1 0 1
ha
1 1 1
W
C = A + B (read as A OR B)
or
C=AB
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.
A B
0 1
1 0
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
A C
B
C=A.B
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
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
A C
B
W
C=A+B
A B A+B C
0 0 0 1
0 1 1 0
1 0 1 0
1 1 1 0
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
(2)
C
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.
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
A
A
B B A.B.C
C C
A
B
X
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.
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
A+A =1 A.A =0
A+0 =A A.1 =A
ts
A.0 =0 A+1 =1
ha
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‟)
A.B
A.B
86
A+B+C
A+B+C
A A.B B
A.B.C
A.C B.C
Points to Remember
4
A AND B AB A.B AB
44
A OR B AB A+B AB
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
87
Chapter 6 : Boolean Algebra (II)
Chapter Objectives
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 + D) = A+B+C+D
ha
Distributive law
W
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
(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
(A + B) = A.B
ha
(A.B) = A+B
W
Step 1 The + symbols are replaced with . symbols and . symbols with +
symbols.
89
Step 1 The addition symbol is changed.
4
= A.B = R.H.S
44
3
73
The problem may also be solved by drawing a truth table:
26
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
A=A
A+B = A+B
A.B = A.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.
4
44
ABC [4]
3
73
Using Boolean algebra, simplify:
(A + C).BC + AC + B [5]
26
07
[5]
W
mmmmm. F
rom the simplified expression, draw the logic circuit. [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]
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
yyyyy. U
ha
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
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.
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
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
Below are tables showing the various number of staff for different grades and
W
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
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
98
Multiplication of a Matrix with a Row 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
~ ~ ~
R*U=S
ts
ha
1
1
[2 14 54 67 10 4] * 1 = (151)
1
1
1
column vector
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
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
Question 8
W
a. A family buys Milk, Bread and Eggs at unit price of 42,74 and 12 cents
respectively the following quantities:
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)
4
D
44
TIM PITCHIN
E G Which is Which?
ROLLIN 3 (BASIC, PASCAL)
G
73
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
101
For Row : = 1 to 6 Do
For Col : = 1 to 5 Do
Readln(Table [Row, Col]);
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.
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
Try the following quiz by matching the device to the explanation. This will
provide a better understanding of linked records.
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.
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
Accessing any of the data items allows the access to the others
104
Example:
4
44
ii. Show the original table as it would appear if KEY 96 were DELETED (2).
2 1 96 3
p
2 84 4
ap
3 105 5
ts
ha
4 95 1
W
5 110 -1
Program location in main memory and its control during execution by linked list
for example calling of subroutines by main programs.
105
S/ROUTIN
PROCESS PROGRAM
E
Spool Line 1
Line 1 :
: :
S/R call Line „n‟
:
Line „n‟
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
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.
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
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
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
For a push, make sure the location is empty else „Invoice‟; into a location
W
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
how to acquire the ability to manipulate or to use the different types if 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
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
Parents Path
Sons and
daughters
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
3
W
SINGAPORE 9
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
EASY
KNOW
HOW
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
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
MALAYSIA 1
4
44
Back Pointer (BP)
3
73
BAHRAIN 4
26
HONG KONG 5
p
ap
The Pointers
ts
ha
A binary tree T is defined as finite set of elements, called nodes such that:
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
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
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
A
LT RT
B C
115
D F
E
8.5.1 Preorder 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.
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
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
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.
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
Compare ITEM = 20 with the root, 38, of the tree T. Since 20 < 38, proceed to the left
ha
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.
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]
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]
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
ii. From the above binary tree, build a table to show its Left, Right,
Back (parent).
119
b. i. Write down the pointers for the table below, where elements are
linked in numerical order: [2]
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 ]
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
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]
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]
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
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
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
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
4
Example:
44
a c e f a e cf
+ 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 cf
=
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
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:
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
x 2
If = then it follows that x = 2 and y = 3.
W
y 3
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
2 0 - 4
, and of B respectively.
3 - 2 6
1 3 2 0 4
2 - 1 3 - 2 6
Step 1:
(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
Example:
ts
ha
x 2 3 - 5 8 - 3
Given A = , B = and C =
y
W
1 4 2 5 0
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
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
For the FIRST ORDER labour costs were 3 units per hour, but had
ap
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)
iv. R is a 3 x 1 matrix.
131
2
1
3
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).
3 2 0
(50 100) = (350 100 300)
2 0 3
4
44
vii. Hours to produce the second order is given by:
3
73
1.6
(350 100 300) 1
26
2
07
Hence the labour costs for the second order are smaller than
W
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
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
x x'
+ T =
ts
y y'
ha
1 3 4
+ =
W
1 2 3
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
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
DABC is mapped onto D A‟B‟C‟ under a reflection in the line XY which is the
p
Example:
W
C C‟
B B‟
A A‟
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
135
OBC is mapped onto OB‟C‟ under a shear along the x-axis with factor k.
OC' 6
k = = = 2
OC 3
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
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
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
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
137
x 3 1 3
=
y 5 0 2
3 x( 3) (1) x 2
=
5 x( 3) 0 x 2
92 11
= =
15 0 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
number respectively.
ts
N
Then Cp,q = a * b r ,q
ha
p,r
r 1
W
For example,
C3,2 = a3,1 b1,2 + a3,2 b2,2 + a3,3 b3,2 + ... + a3,N bN,2
139
Transformations:
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
=
1 0 y' 1 0 y
ap
about origin
ts
ha
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
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
[1]
ts
xxxxxxx. W
ha
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]
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 ]
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
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
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
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]
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
eeeeeeee. C
alculate S = PQ. [4]
p
ap
ffffffff. W
hat does this matrix S represent? [2]
ts
gggggggg. C
ha
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.
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 ]
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
ii. Plot, draw and LABEL shape D on the same sheet of graph paper
ap
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 ]
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]
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
k. If T1 = T2 = B = T1 * A -
0 1 1 0 2 2 2 2
p
ap
and C = T2 * B.
ts
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;
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
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
quarterly bills.
i. Explain in words, the meaning of P3,2 = $1800. [2]
147
1
ii.
Calculate the matrix R if R = P x 1 . [4]
1
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
148
Chapter 10 : Representation Of Instruction
Chapter Objectives
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
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
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.
149
10.3.1 Numbers of Addresses
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
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
MEM MEM
07
general register to be used, and the second address indicated the location in
memory. A LOAD ACCUMULATOR instruction (LOAD A, B) would
ts
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.
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
Programmer convenience
ap
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.
This instruction loads the contents of data memory location TABLE into the AX
register.
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.
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
Data transfer instructions move data and addresses between register and a
W
153
10.6.2 Arithmetic Instructions
addition
subtraction
multiplication
division
logical
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
154
10.7 Exercises
Briefly describe what is direct, indirect and indexed addressing.
4
44
3
73
26
07
p
ap
ts
ha
W
155
Chapter 11 : Errors And Accuracy
Chapter Objectives
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
156
If „B‟ is represented as 100 0010, we can use even parity conversion to
produce a parity bit.
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.
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
11 - 5 = 6
4 3 2 1 Weightage
4 4 5 6
(4*4) + (4*3) + (5*2) + (6*1) = 44
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
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
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
0 1 0 1 0 1 0 0
Check point
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
Check point
p
a. 3.5cm
ts
z. 45.3 seconds
ha
W
159
Addition
Example: 5+7, each of the data values are rounded to whole number.
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
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
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:
160
Er of 4 = 100 * (0.5/4) =12.5%
Er of 5 = 100 * (0.5/5) =10%
Division
Example: 7.5/5.3, each is rounded to 1D
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
Example: (3.5*13.5*1.5)/(7.0*4.5*40.5)
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
compilers and interpreters are written such that they can deliver
ap
Significant figures
ha
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
Check point
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
Er
r 5.5 0.91% Inherent
ts
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.
163
Invalid datatype;
4
44
Data
Hash
3
Divide by 7, 7- Final
73
Total take remainder remainder data
439 43 1 6 4396
26
Divide by 7,
ap
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.
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.
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
Types of errors.
Rounding; Truncation; Overflow; Conversion
W
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]
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
ss. The difference between the reported value and the true value of a
ha
quantity [1]
W
___________________ 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.
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
a. Using mod 11 and weighting of 2, 3 and 4 for the units, tens and hundreds
ap
zz. Show how a transposition error occurring in the number 974 would be
detected. [2]
ha
W
168
Chapter 12 : Statistics
Chapter Objectives
to use various charts and graph to display data, e.g. Histogram Cumulative
Frequency Diagram;
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
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.
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.
169
12.2.1 Arrays
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.
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.
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.
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.
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
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.
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
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
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
j1
j
X
X =
N N N
Example:
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
X = 5.7
3 2 4 1 10
Example:
Example:
1
The set of numbers 5, 5, 7, 9, 11, 12, 15, 18 has a median = (9 + 11) = 10.
2
175
f 1
N
Median = L1 + 2 xc
f median
where
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
diagram, estimate the median of the following survey of the examination marks
ts
176
Median is the mark below which 50% of the students‟ score, and therefore above
which another 50% of the student score.
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:
Example:
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
Mode of grouped data may be estimated from Histogram as shown in Figure 12-
1.
178
Example:
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
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
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
defined by:/*
p
| X X |
ap
j
j1
Mean Deviation = X =
ts
N
ha
Example:
W
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
43 0 25
= = 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
j1
j | Xj X |
Mean Deviation =
N
K
where N = f
j1
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.
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
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
Example:
Find the standard deviation and variance of the following set of numbers:
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.
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
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
4
2. Use formula.
44
Mode Take the data that 1. Use histogram.
appear most 3
73
frequency. 2. Use formula.
26
x x f(x) fx
2 2 2 2
Standard
ts
Deviation N f f
ha
N
W
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]
4
Grade 1 2 3 4 5
44
No. of Candidates 4 3 3 9 2 2
73
Find:
26
Given a series of numbers : C, 5, 6, 8, 12, 25, and the mean of these numbers is 15:
ts
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
hhhh. P
lot a table for the above data in order to calculate: [8]
W
The table shows the results of a survey of 100 students about the number of hours they
spent daily in studying for an examination.
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
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
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]
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:
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
eeeee. C
ts
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
189