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

MATH1179

Mathematics for
Computer Science
Part 2

𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪 = {𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻𝑻, 𝑫𝑫𝑫𝑫𝑫𝑫𝑫𝑫𝑫𝑫, 𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷𝑷, 𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴𝑴, 𝑩𝑩𝑩𝑩𝑩𝑩𝑩𝑩}


V 5 |𝑪𝑪𝑪𝑪𝑪𝑪𝑪𝑪| = 𝟓𝟓

 0101 -5𝒊𝒊𝟐𝟐

Workbook 2

Dr Yvonne Fryer
September 2021
MATH1179

Contents

Page No.

1: Vectors and Matrices ..................................................................................................................... 1

2: Graph Theory and Networks ........................................................................................................ 5

3: Algorithms .................................................................................................................................... 10

4: Differentiation and Integration .................................................................................................. 16

5: Data and Statistics ....................................................................................................................... 21

6: Probability .................................................................................................................................... 27

Formulae ........................................................................................................................................... 32
Sets .......................................................................................................................................... 32
Logic: Propositional Calculus................................................................................................. 32
Number ................................................................................................................................... 34
Formal Languages and Grammars .......................................................................................... 35
Logic: Predicate Calculus ....................................................................................................... 35
Data & Statistics ..................................................................................................................... 36

Mathematics for Computer Science i


MATH1179

ii Term 1
MATH1179

1: Vectors and Matrices

10   − 2  3 
1. Let p =   q =   and r =  − 2 
3  5   

Find p+3q, q-r, p+q-r _____________________________________________________

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

6 1
1 1
2. Let 𝐴𝐴 = � �, 𝐵𝐵 = �2 −3� , 𝐶𝐶 = (2 0 4)
−2 5
2 1
3
1 −5 8 1 0 2 6
𝐷𝐷 = � 1 �, 𝐸𝐸 = � �, 𝐹𝐹 = � �
2 1 2 −2 5 4 3
−2
Evaluate WHERE POSSIBLE the following, if not possible explain why

i) 2𝐴𝐴 ______________________________________________________________

ii) 𝐴𝐴 + 𝐵𝐵 ___________________________________________________________

iii) 𝐵𝐵𝐵𝐵 ______________________________________________________________

iv) 𝐶𝐶𝐶𝐶 ______________________________________________________________

v) 𝐷𝐷𝐷𝐷 ______________________________________________________________

vi) 𝐵𝐵 − 𝐴𝐴 ____________________________________________________________

vii) 𝐸𝐸 + 𝐹𝐹 ____________________________________________________________

Mathematics for Computer Science Page 1


MATH1179

viii) 𝐴𝐴𝐴𝐴 ______________________________________________________________

ix) 𝐸𝐸𝐸𝐸 ______________________________________________________________

x) 𝐹𝐹 2 ______________________________________________________________

xi) 𝐴𝐴−1 _____________________________________________________________

3. A rectangle R is given by the coordinates P(1,1) , Q(5,1), R(5,2) and S(1,2)


Draw its position on a graph
Draw its position after transformation with EACH of the following matrices
0 1  0 − 1 − 2 0   − 3
W =   V =   U =   and with the translation vector m =  
1 0 1 0   0 − 2  2 
You should start each time with R and describe the effect of each of the transformation.

 −1 0
Using F =   form the product FV and use it to find the position of R after being
 0 1
transformed by V and then F.(note the order of composition). Draw FV(R) and comment on
the result.

Page 2 Vectors and Matrices


MATH1179

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

4. Solve the following simultaneous equations using matrices


(i) 2𝑥𝑥 + 3𝑦𝑦 = 8 (ii) 4𝑥𝑥 – 𝑦𝑦 = 21 (iii) 5𝑥𝑥 + 𝑦𝑦 = 23
𝑥𝑥 + 4𝑦𝑦 = 9 −10𝑥𝑥 + 3𝑦𝑦 = −53 3𝑥𝑥 + 𝑦𝑦 = 15
_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

_____________________________________________________________________________

Mathematics for Computer Science Page 3


MATH1179

 0 − 1
5. Let q be the matrix  
1 0 
Construct a multiplication table using this as the starting element.
Show that it is closed (eventually no new matrices appear). X
The start of the table is shown  0 − 1  − 1 0 
   
 1 0   0 − 1

__________________________________________________________

Page 4 Vectors and Matrices


MATH1179

2: Graph Theory and Networks

1. Draw the graph with vertices,


a, b, c, d, e, f and edges
(a,b), (a,e), (a,f), (b,c), (b,f), (c,e), (d,e), (e,f)
Find one walk of length 2 and two walks
of length 3 from vertex a to vertex e.
Are any of these paths?
Find a cycle in the graph.
_______________________________ _____________________________________
_______________________________ _____________________________________
_______________________________ _____________________________________
2. Draw a graph which has 6 vertices, is not
connected and which has a cycle of
length 4

3. Draw all trees which have 4 vertices. Draw all trees which have 5 vertices. (no
isomorphisms)

4. Find two spanning trees for the graph in question 1.

Mathematics for Computer Science Page 5


MATH1179

5. Write down the adjacency matrix for the graph in question 1.

0 1 1 0
6. A graph 𝐺𝐺 with vertices 𝑣𝑣1 , 𝑣𝑣2 , 𝑣𝑣3 and 𝑣𝑣4 has adjacency matrix 𝐴𝐴, 𝐴𝐴 = �1 0 0 0�
1 0 0 1
0 0 1 0
Draw the graph of 𝐺𝐺.
Find the number of walks of length 2 and 3 between vertices 𝑣𝑣1 and 𝑣𝑣3
Identify these walks.

7. Find a minimum spanning tree for the graph shown.

9 4

a c
11

8 7 2
3

f 5 e d
4

Make sure to draw the minimum spanning tree and identify its length.

Page 6 Graph theory and networks


MATH1179

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

8. Five computers A, B, C, D and E are to be connected. The cost of the possible connections
are
A B C D E
A 52 37 16
B 23 12 15
C 10
D 12

i. Draw this as a graph and using Kruskal's algorithm find a minimum spanning tree for
the graph. Draw the spanning tree.
ii. Hence find the minimum cost of connecting the computers.
iii. If computer A must be connected to computer B, what difference does this make to
your answer ?

Mathematics for Computer Science Page 7


MATH1179

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

9. Put the numbers 23, 43, 15, 37, 25, 46, 67, 12, 18 in a binary search tree with 23 as the
root.

Page 8 Graph theory and networks


MATH1179

10. Find a binary search tree for the words in this sentence. Use 'find' as the root.

11. Using a binary tree evaluate the expression (𝑎𝑎 → ¬𝑏𝑏) ∨ �(¬𝑐𝑐 → 𝑎𝑎) ∧ 𝑏𝑏� when 𝑎𝑎 and 𝑏𝑏 are
true and 𝑐𝑐 is false.

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

Mathematics for Computer Science Page 9


MATH1179

3: Algorithms

1. Given that the input(s) for the following algorithms are drawn from the 𝑁𝑁 with additionally
𝑟𝑟 > 2 for EACH (one giving 12 answers)
(i) draw the design for the algorithm,
(ii) describe the output(s) in words explaining what the algorithm does
(iii) perform the algorithm choosing 2 different sets of input values and stating the output
in each case.

Algorithm a Algorithm b Algorithm c c


a b
READ← p,q READ ←r READ ←p, n
IF p>q THEN i ←2 i ←1
DISPLAY p Answer←“true” Answer←1
ELSE DO DO
DISPLAY q IF r mod i = 0 THEN Answer← Answer *p
ENDIF Answer← “false” i←i+1
End Algorithm a ENDIF LOOP UNTIL i > n
i←i+1 DISPLAY Answer
LOOP UNTIL i = r End Algorithm c
DISPLAY Answer
End Algorithm b

__________________________________________________________
__________________________________________________________
__________________________________________________________

Page 10 Algorithms
MATH1179

__________________________________________________________
__________________________________________________________

__________________________________________________________
__________________________________________________________

Mathematics for Computer Science Page 11


MATH1179

2. In the Linear search algorithm (given below) an ordered list of n items is taken in and each
one compared with the required data to find its position in the list. In the worst case scenario
(last one in the list or not in the list at all) how many comparisons will there be for lists of
i) 8 items ii) 𝑛𝑛 items
e.g. Find position of p
a c g j k l p

LinearSearch p=X(0)?
READ Array(X), w p=X(1)?
i←0
p=X(2)?
Found =false
p=X(3)?
Failure = false
DO p=X(4)?
IF w = X(i) THEN p=X(5)?
DISPLAY i p=X(6)?
Found = true
ELSE
IF w<X(i) THEN
Failure = true
ELSE
i←i+1
ENDIF
IF i>n-1 THEN
Failure = true
ENDIF
LOOP UNTIL Found = true OR Failure = true
End LinearSearch

__________________________________________________________
__________________________________________________________

Page 12 Algorithms
MATH1179

3. In the Binary search algorithm an ordered list of n items is repeatedly halved with one half
discarded until the required data is found. In the worst case scenario (last one in the list or
not in the list at all) how many comparisons will there be for lists of
i) 8 items ii) 9 items iii) 20 items
iv) 56 items v) n items
. Find position of p

a c g j k l p

BinSearch Note  x  is the so called F=0L=6


READ Array(X), w floor function
F←0
 x  is the largest integer p=X(3)?
L←n-1
Found =false not greater than x i.e. the
Failure = false next whole number down. F=4L=6
DO
i←(F+L)/2 p=X(5)?
IF w = X(i) THEN
DISPLAY i
F= 6 L = 6
Found = true
ELSE
IF w<X(i) THEN p=X(6)?
L←i-1
ELSE
F←i+1
ENDIF
IF F>L THEN
Failure = true
ENDIF
LOOP UNTIL Found = true OR Failure = true
End BinSearch

Mathematics for Computer Science Page 13


MATH1179

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

Page 14 Algorithms
MATH1179

4. State the big O for algorithms 2 and 3 ( either work it out or research it on the web).

________________________________________________________________________

________________________________________________________________________

________________________________________________________________________

5. Let T be a Turing machine defined by the quintuples:

(s0, 0, s1, 1, R), (s0, 1, s1, 0, R), (s0, B, s1, 0, R), (s1, 0, s2, 1, L), (s1, 1, s1, 0, R), (s1, B, s2, 0, L)

For each of the initial tapes determine the final tape when M halts assuming it starts in the
leftmost non-blank position and in state s0
i) B B 0 0 1 1 B B

ii) B B 1 0 1 B B B

iii) B B 1 1 B 0 1 B

Mathematics for Computer Science Page 15


MATH1179

4: Differentiation and Integration

𝑑𝑑𝑑𝑑
1. Find in the following cases
𝑑𝑑𝑑𝑑
i. 𝑦𝑦 = 4𝑥𝑥 2 + 3𝑥𝑥 − 2 ii. 𝑦𝑦 = 3 cos 𝑥𝑥 + 4𝑒𝑒 𝑥𝑥

iii. 𝑦𝑦 = 5𝑥𝑥 6 + 3(𝑥𝑥 − 2) iv. 𝑦𝑦 = 2𝑥𝑥– sin 𝑥𝑥

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

2. Find the gradient of 𝑦𝑦 = 4𝑥𝑥 3 + 5𝑥𝑥 2 − 4𝑥𝑥 − 1 when 𝑥𝑥 = 3


__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

3. Find the gradient of 𝑦𝑦 = 𝑥𝑥 2 − 5𝑥𝑥 + 4 when 𝑥𝑥 = 2.5 Sketch the curve and explain your
answer.

_____________________________________

_____________________________________

_____________________________________

_____________________________________

_____________________________________

_____________________________________

_____________________________________

Page 16 Differentiation and Integration


MATH1179
𝑑𝑑𝑑𝑑
4. Find 𝑑𝑑𝑑𝑑 for the following expressions.
i. 𝑦𝑦 = 𝑥𝑥𝑒𝑒 3𝑥𝑥 ii. 𝑦𝑦 = 𝑥𝑥 sin 2𝑥𝑥 ln 3𝑥𝑥
3
iii. 𝑦𝑦 = 𝑥𝑥 2 𝑒𝑒 −𝑥𝑥 iv. 𝑦𝑦 = 𝑒𝑒 2 sin 3𝑥𝑥
2𝑥𝑥−3
v. 𝑦𝑦 = 𝑥𝑥+1
vi. 𝑦𝑦 = 𝑥𝑥 ln 𝑥𝑥

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

𝑑𝑑𝑑𝑑
5. Find 𝑑𝑑𝑑𝑑 for each of the following:
i. 𝑦𝑦 2 = 2𝑥𝑥 + 1 ii. 𝑥𝑥 2 + 𝑦𝑦 2 = 4
iii. 𝑥𝑥𝑦𝑦 2 = 16 iv. 𝑥𝑥 2 + 2𝑥𝑥𝑥𝑥 + 3𝑦𝑦 2 = 6
v. sin 𝑥𝑥 cos 𝑦𝑦 = 1 vi. ln 𝑦𝑦 ln 𝑥𝑥 = 3

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

Mathematics for Computer Science Page 17


MATH1179
𝑑𝑑𝑑𝑑
6. Find 𝑑𝑑𝑑𝑑 for each of the following:
2
i. 𝑥𝑥 = 3𝑡𝑡 2 , 𝑦𝑦 = 2𝑡𝑡 at 𝑡𝑡 = 2 ii. 𝑥𝑥 = 2𝑡𝑡 3 , 𝑦𝑦 = 𝑡𝑡 2 at 𝑡𝑡 = 2

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

7. Integrate to find ∫ 𝑦𝑦 𝑑𝑑𝑑𝑑 for the following cases


i. 𝑦𝑦 = 6𝑥𝑥 2 + 4𝑥𝑥 ii. 𝑦𝑦 = 3 sin 𝑥𝑥

1
iii. 𝑦𝑦 = 2 (𝑥𝑥 2 − 3𝑥𝑥) iv. 𝑦𝑦 = 2𝑒𝑒 𝑥𝑥 – cos 𝑥𝑥

______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

8. Find the value of the following definite integrals


3 4
i. ∫2 𝑥𝑥 2 + 2 𝑑𝑑𝑑𝑑 ii. ∫1 𝑥𝑥 2 − 9 𝑑𝑑𝑑𝑑

__________________________________________________________

Page 18 Differentiation and Integration


MATH1179

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

9. By sketching the curve for 8.ii. and splitting up the integral find the actual area between the
curve and the x axis.

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

Mathematics for Computer Science Page 19


MATH1179

10. Integrate by substitution and evaluate


1
i. ∫0 (3𝑥𝑥 − 1)4 𝑑𝑑𝑑𝑑 let 𝑢𝑢 = 3𝑥𝑥 − 1
3
ii. ∫1 𝑥𝑥√𝑥𝑥 2 + 1𝑑𝑑𝑑𝑑 let 𝑢𝑢 = 𝑥𝑥 2 + 1

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

11. Use integration by parts to integrate 𝑥𝑥 sin 𝑥𝑥

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

Page 20 Differentiation and Integration


MATH1179

5: Data and Statistics

1. Consider the following data which consists of a sample of people and records their height
and weight. Draw a scatter graph of this data in Excel. Does the graph suggest any connection
between height and weight? Would this be expected?

Height (cm) 176 187 152 170 195 158 175 169 190 155
Weight (kg) 80 98 45 76 112 65 78 70 105 50

Sketch the graph by hand

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

Mathematics for Computer Science Page 21


MATH1179

2. Draw a line graph in Excel of the following data, which gives the average London
temperature for each month.

Month Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
Temp (°C) 7 7 9 11 14 16 19 19 17 13 10 7
Sketch the graph here

3. Draw a bar chart in Excel of the following data, which gives the number of votes cast for
each candidate in a Computer Society election.
Adam: 17
Bilal: 24
Charlotte: 22
Deborah: 13
Evgeniya: 18
__________________________________________________________
__________________________________________________________
__________________________________________________________
4. Draw a pie chart in Excel of the following data, which gives the predictions of a sample of
football supporters as to who will win the Premier League in 2019/20.
Chelsea: 35%
Manchester City: 25%
Manchester United: 15%
Arsenal: 10%
Tottenham Hotspur: 10%
Others: 5%
__________________________________________________________

Page 22 Data and Statistics


MATH1179
5. If you got marks of 48% in your Mathematics Exam and 65% in your Computer
Programming exam, which would please you more. What statistics from the exam marks
would help you decide -which was the better performance? Explain your thinking fully.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

6. The company you work for decides to get rid of the 10% worse performers under their
productivity measure. You have a productivity measurement of 5.7. Is it better for you if
a) the company average is 7 and the standard deviation is 1.5
b) the company average is 6 and the standard deviation is 0.1
You may assume the distribution is fairly ‘normal’. Give reasons for your answer.

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

7. The number of children in 50 families (with at least one child are as follows.

4 5 2 2 3 4 4 3 5 4
7 3 3 4 2 2 2 2 2 6
3 2 3 3 1 2 3 2 2 6
5 5 3 2 4 4 2 4 1 2
2 2 1 3 3 2 2 4 5 3
Input the data into a package (usually Excel), draw a bar chart and pie chart.
Construct the frequency distribution and calculate the mean and mode (you can use any of
the methods suitable for your package but must show which formulas have been used).
__________________________________________________________
__________________________________________________________
__________________________________________________________

Mathematics for Computer Science Page 23


MATH1179

8. In a class test, the following marks were obtained. Find the mean, median and mode.
5 10 25 25 25 30 30 30 35 35
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

9. The lives of 120 circuit components were recorded in hours to the nearest hour and grouped
as follows
Life (hours) Frequency
660 – 669 3
670 – 679 10
680 – 689 16
690 – 699 23
700 – 709 34
710 – 719 21
720 – 729 9
730 – 739 4
State the class intervals and the class marks.
Construct the cumulative frequency and draw the cumulative frequency curve.
Use this curve to estimate the median.
Display this information in Excel and mark on the inter quartile range
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
10. A zoologist weighs 100 eggs and records the weights in the following frequency table.
Weight (g) 24 - 29 30 - 35 36 - 41 42 - 47 48 - 53
Frequency 11 23 36 21 9
What are the class intervals and the class marks?
Find the mean and standard deviation correct to two decimal places
__________________________________________________________
__________________________________________________________
__________________________________________________________

Page 24 Data and Statistics


MATH1179

11. Three groups of students sit a test. Their marks are as follows (out of 50)
Frequencies
Class interval A B C
11 - 15 5 2 1
16 - 20 15 10 2
21 - 25 10 10 5
26 - 30 0 5 10
31 - 35 0 3 10
36 - 40 0 0 1
41 - 45 0 0 1

Using Excel calculate the mean and standard deviation of each group and compare their results.
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
12. Copy and paste the following data into Excel.
Use the data analysis tool to form a histogram choosing suitable classes
By manipulating the chart wizard also draw a frequency polygon from it.
56 74 76 1 69 11 86 68 68 15
52 36 88 47 31 15 83 100 29 96
10 33 28 62 95 71 41 74 73 31
52 30 86 25 11 29 3 29 42 15
43 22 82 71 86 26 77 46 21 44
61 32 2 68 57 59 11 74 59 80
54 29 79 8 56 54 100 81 39 29
68 41 63 96 88 52 4 32 45 58
97 80 30 46 83 84 37 68 3 94
29 11 98 70 86 54 19 44 14 3
__________________________________________________________
__________________________________________________________

Mathematics for Computer Science Page 25


MATH1179

13. What is wrong with the following statements?


- In Lake Woebegone all the children are above average
- We don’t stock that size I’m afraid as there’s no demand for it.
- If his average was 2 marks more he would have passed, if only he had got 40 for his
project rather than 38.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Page 26 Data and Statistics


MATH1179

6: Probability

1. What is the probability of choosing a vowel from the alphabet?


__________________________________________________________
__________________________________________________________
__________________________________________________________
2. A number from 1 to 11 is chosen at random. What is the probability of choosing an odd
number?
__________________________________________________________
__________________________________________________________
__________________________________________________________

3. In a math class of 30 students, 17 are boys and 13 are girls. On a unit test, 4 boys and 5 girls
made an A grade. If a student is chosen at random from the class, what is the probability of
choosing a girl or an A student?

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
4. After throwing a dice, what is the probability that the number of dots on the uppermost side
is divisible by 3?

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

5. An unscrupulous gambler has a loaded dice, with the probabilities:


P(1) = 0.1, P(2) = 0.2, P(3) = 0.1, P(4) = 0.2, P(5) = 0.1, P(6) = 0.3
Which is more probable that it falls with an even number or that it falls with a number greater
than 3?

Mathematics for Computer Science Page 27


MATH1179

__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________
__________________________________________________________

6. A fair coin is tossed three times.


i. What is the probability that at least two consecutive heads appear?
ii. What is the probability that exactly two heads, not necessarily consecutive appear?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

7. On New Year's Eve, the probability of a person having a car accident is 0.09. The probability
of a person driving while intoxicated is 0.32 and probability of a person having a car accident
while intoxicated is 0.15. What is the probability of a person driving while intoxicated or
having a car accident?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

8. A dresser drawer contains one pair of socks with each of the following colours: blue, brown,
red, white and black. Each pair is folded together in a matching set. You reach into the sock
drawer and choose a pair of socks without looking. You replace this pair and then choose
another pair of socks. What is the probability that you will choose the red pair of socks both
times?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Page 28 Probability
MATH1179

9. A jar contains 3 red, 5 green, 2 blue and 6 yellow marbles. A marble is chosen at random
from the jar. After replacing it, a second marble is chosen. What is the probability of choosing
a green and then a yellow marble?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

10. Three cards are chosen at random from a deck of 52 cards without replacement. What is the
probability of choosing 3 aces?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

11 Calculate the following using your calculator and Excel. For any that give an error or an
unexpected answer, can you explain why?

______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Mathematics for Computer Science Page 29


MATH1179
12. A Formula 1 race consists of 22 cars. The teams firstly take part in a qualifying session to
determine the order in which they start the race, and then there is the actual race.

(i) In the first part of qualifying, the cars race to set the fastest time. The slowest six
cars are eliminated and the others proceed to the next round of qualifying – the
order in which they finish does not matter. In how many ways can the six cars be
eliminated?
(ii) In the second part, another six cars are eliminated and the remainder proceed to the
final stage, order does not matter. Again, in how many ways can the six cars be
eliminated?
(iii) In the final part of qualifying the remaining cars set their fastest time and their order
is decided by this. In many ways can this be done?
(iv) The race now takes place with all 22 cars. In how many ways can the podium be
formed? The podium consists of the first, second and third placed cars in order.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

13. Consider the following game:

You roll a die. If you roll a 1 then you immediately win. If you do not, then you get to roll
again. This time if you roll a 1 or 2 then you win, otherwise you lose.

Draw a probability tree of this game.


What is your probability of winning?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Page 30 Probability
MATH1179
14. What is the expected value of the following?

(i) Rolling a die with sides 1, 2, 3, 4, 4, 4


(ii) Rolling a die with sides 2, 4, 6, 8, 10, 12
(iii) The sum of the rolls of two standard dice (so sides 1, 2, 3, 4, 5, 6)
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

15. Suppose you are in the following situation:

You are on a game show, with a choice of five boxes. The boxes contain £1, £10, £100,
£1000 and £10000 respectively. You have chosen a box and it contains £1000. You have
the option to take that money, or to reject it and open another box instead.

What should you decide to do under the following criteria?


(i) Expected value criterion
(ii) Maximax criterion
(iii) Minimax criterion
(v) Regret criterion
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

16. The famous Monty Hall problem is as follows:

On a game show there are three closed doors, and only the host Monty knows what is
behind each door. One contains a car and the other two contain goats. Obviously you want
to win the car. You choose a door. One of the other doors is then opened to reveal a goat,
leaving two doors, one with a car and one with a goat. You are then asked whether you
want to stay with the same original choice or switch to the other door.

Are you better to switch, or to stay with original choice? Does it matter?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Mathematics for Computer Science Page 31


MATH1179

Formulae

Sets
Formula for A ∪ B
A B

|𝐴𝐴 ∪ 𝐵𝐵| = (𝑥𝑥 − 𝑟𝑟) + (𝑦𝑦 − 𝑟𝑟) + 𝑟𝑟 x-r r y-r


= 𝑥𝑥 + 𝑦𝑦 − 𝑟𝑟.
|𝐴𝐴 ∪ 𝐵𝐵| = |𝐴𝐴| + |𝐵𝐵| − |𝐴𝐴 ∩ 𝐵𝐵|

Laws of Operations of Sets


1 Commutative Law A∩B=B∩A A∪B=B∪A
2 Associative Law A ∩ (B ∩ C) = (A ∩ B) ∩ C A ∪ (B ∪ C) = (A ∪ B) ∪ C
3 Distributive Law A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
4 Identity Law A∩U=A A∪∅=A
5 Domination Law A∩∅=∅ A∪U=U
6 Idempotent Law A∩A=A A∪A=A
7 Complement Law A ∩ A'= ∅ A ∪ A'= U U'= ∅ ∅'=U
8 De Morgan's Law (A ∩ B)'= A'∪ B' (A ∪ B)'= A'∩ B'
9 Involution Law (A')' = A

Product Set
Let A and B be sets.
The Cartesian product set A × B is the set of all ordered pairs (a, b) where a ∈ A and b ∈ B.

Logic: Propositional Calculus

Truth values and tables

And Or Not
P q p∧q p q p∨q p ¬p
T T T T T T T F
T F F T F T F T
F T F F T T
F F F F F F

A tautology - t - is a proposition which is always true eg p ∨ ¬p; it is wet or dry.


A contradiction - f - is a proposition which is always false eg p ∧ ¬p; it is wet and dry.

Page 32 Formulae
MATH1179
Laws of Propositional Calculus
Given any propositions p, q and r, tautology t and contradiction f, the following hold:
1 idempotent laws p∧p≡p p∨p≡p
2 associative laws (p ∧ q) ∧ r ≡ p ∧ (q ∧ r), (p ∨ q) ∨ r ≡ p ∨ (q ∨ r)
3 commutative laws p ∧ q ≡ q ∧ p, p∨q≡q∨p
4 distributive laws p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r), p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r)
5 De Morgan's laws ¬(p ∧ q) ≡ ¬p ∨ ¬q, ¬(p ∨ q) ≡ ¬p ∧ ¬q
6 identity laws p ∧ f ≡ f, p ∧ t ≡ p, p ∨ t ≡ t, p ∨ f ≡ p
7 complement laws p ∧ ¬p ≡ f, p ∨ ¬p ≡ t, ¬t ≡ f, ¬f ≡ t
8 involution laws ¬¬p ≡ p,

Implication
This logical connective is of the form ' p implies q ', or ' if p then q '.
p is called the premise and q the conclusion. We write this p → q.

p q p→q
T T T
T F F
F T T
F F T

Valid and Invalid Arguments


An argument has the form p1, p2,... pn therefore├ q.

Equivalent systems
In general many aspects of logic can be re-expressed using Boolean forms, Set theory or Logic gates.

and or complement
p∧q p∨q ¬p ~p f t
P∩Q P∪Q P P´ ∅ U

P.Q P+Q P 0 1

Mathematics for Computer Science Page 33


MATH1179
Number

Number systems

N Z Q R

the set of natural numbers N = {1, 2, 3,...} (note 0 is included in some books)
the set of integers Z = { ..., -2, -1, 0, 1, 2,...} extended to include negatives
the set of rational numbers Q = {p/q : p,q ∈ Ζ, q ≠ 0} extended to include fractions
the set of real numbers R extended to include √2 e.t.c.

Exponents and Scientific Notation


It is common on calculators and in programming to find that 5 000 000 is written in a different format
e.g. 5 EXP 6 or 5 6 or 5 e +6 because 5 000 000 is 5 million and a million is 10×10×10×10×10×10,
10 to the power of 6.

Naming conventions
Smallest largest
×10-12 ×10-9 ×10-6 ×10-3 ×10-2 ×10-1 1=100 ×101 ×102 ×103 ×106 ×109 ×1012
Pico nano micro milli centi deci deca hecto kilo mega giga terra
one thousandth of
One millionth of

one thousandth

one hundredth
one millionth
a thousandth
a millionth

a thousand

a thousand
a hundred

a million
one tenth

millionth
thousand
a million
Original

ten

Binary, Octal and Hexadecimal

Binary: Another name for base 2, digits used are 0-1.


Octal: Another name for base 8, digits used are 0-7.
Hexadecimal: Another name for base 16, digits & characters used 0-9,A,B,C,D,E,F

Page 34 Formulae
MATH1179
Changing between Binary, Octal and Hexadecimal
If we compare these three number bases we can see they are all representing powers of 2

System Place value in each system


2n 29 28 27 26 25 24 23 22 21 20
Binary 512 256 128 64 32 16 8 4 2 1
Octal 512 64 8 1
Hex 256 16 1

2’s Complement arithmetic for binary numbers (binary number X – binary


number Y)
Step 1: Take binary number Y and replace 0’s by 1’s and 1’s by 0’s
Step 2: then add 1 to the new binary number.
Step 3: make sure the unaltered binary number X and the altered binary number Y have the same
number of digits then add together.
Step 4: ignore first 1 on left of step 3 result and that is the answer.

Formal Languages and Grammars


Definition
A Phrase Structure Grammar or simply a grammar G consists of four parts
G = {VT, VN, S, P}

VT = A finite set of terminal symbols


VN = A set of variables (or non-terminal symbols)
S = A non-terminal start symbol
P = A set of production rules defining how members of VT and VN can be combined.

V = VT ∪ VN is known as the vocabulary.


The phrase structure of a language can be represented by parse trees which show how a particular
grammar generates the phrases of the language.

Logic: Predicate Calculus


The symbol ∀ is used to denote for every or for all
The symbol used to state existential quantification is ∃ for there exists or at least one.

Mathematics for Computer Science Page 35


MATH1179
Data & Statistics

MEAN

Usually written as x for a sample or µ for the population


n

(x + x 2 + x 3 + .... x n )
∑x
i =1
i
With n values given as x1, x2, ... , xn the mean is = 1 =
n n
If data values are repeated so that value xi occurs fi times, then n = f1 + f2 + ... + fn the total frequency
and
n n

(f1 x 1 + f 2 x 2 + f 3 x 3 + .... f n x n )
∑f x
i =1
i i ∑f x i i
mean = = = i =1

n n n

∑f
i =1
i

MODE
This is defined as the most frequently occurring value and so in a bar chart showing the frequency it will
be the values giving rise to the highest bar.

MEDIAN
The value of the middle term of the sorted data

Measures of dispersion
Range
range = MAXIMUM VALUE - MIN.VALUE

Inter-Quartile Range
If using median use the Inter-Quartile range for the spread

Find Upper Quartile (75% value) and Lower Quartile (25% value)
IQ range = UQ - LQ

The standard deviation


This looks at the difference between the data values and the mean.

∑( x − x ) 2
(Average Deviation)2 =
n
This is also known as the variance written σ2 for a population or s2 for a sample.

∑( x − x ) 2
σ=
n

Page 36 Formulae
MATH1179
The average deviation is given the technical name of the standard deviation

∑ x2
Standard deviation = − x2
n
For grouped data the standard deviation is given by the formula

Standard deviation σ =
∑ fx 2

−x
2

Differentiation and Integration

Differentiation
Table of derivatives, where 𝑦𝑦 = 𝑓𝑓(𝑥𝑥), 𝑥𝑥, 𝑦𝑦 ∈ 𝑅𝑅 and 𝐴𝐴 is a constant
𝑑𝑑𝑑𝑑
𝑦𝑦 = 𝑓𝑓(𝑥𝑥)
𝑑𝑑𝑑𝑑
𝑐𝑐 0
𝑥𝑥 1
𝑥𝑥 2 2𝑥𝑥
𝑥𝑥 3 3𝑥𝑥 2
𝑥𝑥 𝑛𝑛 𝑛𝑛𝑥𝑥 𝑛𝑛−1
sin 𝐴𝐴𝐴𝐴 𝐴𝐴 cos 𝐴𝐴𝐴𝐴
cos 𝐴𝐴𝐴𝐴 −𝐴𝐴 sin 𝐴𝐴𝐴𝐴
𝑒𝑒 𝐴𝐴𝐴𝐴 𝐴𝐴𝐴𝐴 𝐴𝐴𝐴𝐴
ln 𝐴𝐴𝐴𝐴 1
(where 𝑥𝑥 ≠ 0) 𝑥𝑥

Chain rule
Start on the outside and work in
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
= ×
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
Product rule
A product of two functions, where 𝑢𝑢, 𝑣𝑣 are functions of 𝑥𝑥
𝑑𝑑(𝑢𝑢𝑢𝑢) 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
= 𝑢𝑢 + 𝑣𝑣
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
Can be extended to the product of three functions
𝑑𝑑(𝑢𝑢𝑢𝑢𝑤𝑤) 𝑑𝑑𝑤𝑤 𝑑𝑑𝑣𝑣 𝑑𝑑𝑑𝑑
= 𝑢𝑢𝑣𝑣 + 𝑢𝑢𝑤𝑤 + 𝑣𝑣𝑣𝑣
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑

Mathematics for Computer Science Page 37


MATH1179
Quotient rule
Where 𝑢𝑢, 𝑣𝑣 are functions of 𝑥𝑥
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
𝑑𝑑 𝑢𝑢 �𝑣𝑣 − 𝑢𝑢 �
� �= 𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑 𝑣𝑣 𝑣𝑣 2

Parametric differentiation
When 𝑥𝑥, 𝑦𝑦 are defined in terms of a third variable for example 𝑡𝑡, such that parametric differentiation
𝑑𝑑𝑑𝑑
can be used to obtain 𝑑𝑑𝑑𝑑 .
𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
= �𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑

Integration
Table of standard derivatives

𝑦𝑦 = 𝑓𝑓(𝑥𝑥) � 𝑦𝑦 𝑑𝑑𝑑𝑑 𝑦𝑦 = 𝑓𝑓(𝑥𝑥) � 𝑦𝑦 𝑑𝑑𝑑𝑑

cos 𝐴𝐴𝐴𝐴
𝑎𝑎 𝑎𝑎𝑎𝑎 sin 𝐴𝐴𝐴𝐴 −
𝐴𝐴
𝑥𝑥2 sin 𝐴𝐴𝐴𝐴
𝑥𝑥 cos 𝐴𝐴𝐴𝐴
2 𝐴𝐴
𝑥𝑥3 𝑒𝑒 𝐴𝐴𝐴𝐴
𝑥𝑥 2 𝑒𝑒 𝐴𝐴𝐴𝐴
3 𝐴𝐴
𝑥𝑥4 1
𝑥𝑥 3 𝑥𝑥
( 𝑥𝑥 ≠ 0) ln 𝑥𝑥
4
𝑥𝑥 𝑛𝑛+1
𝑥𝑥 𝑛𝑛 (𝑛𝑛 ≠ −1)
𝑛𝑛 + 1 Where 𝐴𝐴 is a constant

Integration by parts
Where 𝑢𝑢, 𝑣𝑣 are functions of 𝑥𝑥

𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑
� 𝑢𝑢 𝑑𝑑𝑑𝑑 = 𝑢𝑢𝑢𝑢 − � 𝑣𝑣 𝑑𝑑𝑑𝑑
𝑑𝑑𝑑𝑑 𝑑𝑑𝑑𝑑

Page 38 Formulae
MATH1179
Rough work/Additional notes/Formulae

____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
Mathematics for Computer Science Page 39
MATH1179

____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________
____________________________________

Page 40 Formulae

You might also like