You are on page 1of 10

Mathematics for Computer Science

Overview Notes

Prepared by
Dalos D. Miguel
Faculty
School of Accountancy, Management, Computing and Information Studies
Saint Louis University
Baguio City

V. Fundamentals of Progressions
A Sequence is a discrete structure that represents an ordered list. A Sequence may be denoted by {an}.
However, a Sequence may be described by listing the terms of the sequence.

Definition of a Sequence: A sequence is a function from a subset of the set of integers to a set S. Each
image of an element of the subset of integers is denoted by an and an is called the term of the sequence.

Example of a sequence: {an} where an = 1/n, n is a positive integer .


{an} = a1, a2, a3, a4, … = 1, 1/2, 1/3, 1/4, …

The above is a function from {1,2,3,4,..} to {1, 1/2, 1/3, 1/4, …}.

Example of a sequence : {an} where an = (-1)n, n is a positive integer


{an} = a1, a2, a3, a4, … = 1, -1, 1, -1, …

The above is a function from {1,2,3,4,…} to { -1, 1}

Fibonacci sequence
The Fibonacci sequence is a sequence of integers called terms such that the first term is 0 and the second
is 1 and every term after the second is the sum of the preceding two terms. Alternatively, the Fibonacci
sequence is a sequence of integers called terms such that the first term is 1 and the second term is 1 and
each term after the second is the sum of the preceding two terms.

0,1,1,2,3,5,8,13,21,34,55,… is the Fibonacci sequence that has 0 and 1 as the first two terms.

1,1,2,3,5,8,13,21,34,55,… is the Fibonacci sequence that has 1 and 1 as the first two terms.

Arithmetic progression
Consider the sequence 5, 11, 17, 23, 29, 35, 41, 47, 53, 59. In this sequence, the first term is 5 and each
term after the first term is obtained by adding 6 to the immediately preceding term. The observed
common difference which is 6 is a key to determining the nth term of the sequence.. Intuitively, the nth
term of the sequence could be produced by adding (n-1)*6 to 5. Hence, the nth term is 5+6(n-1)=5+6n-
6=6n-1.
For the 1st term, n=1; the term is 5

1 | Page
For the 2nd term, n=2; the term is 6(2)-1=11
For the 3rd term, n=3; the term is 6(3)-1=17
...
For the 10th term, n=10; the term is 6(10)-1=59.

This is an example of an Arithmetic Progression. An Arithmetic Progression begins with a first term,
conventionally denoted by a and there is a common difference, conventionally denoted by d. Hence, an
Arithmetic Progression has the terms a, a+d, a+2d, a+3d, ... , a + nd. In some references, the last term of
the Arithmetic progression is singled out for the purpose of speccifying a formula and the last term is
denoted by l.

In some applications, the sum of the first n terms of an Arithmetic Progression may be of interest. Hence,
remembering a formula for getting the sum of the first n terms of an Arithmetic Progression is a good
idea. Suppose S denotes the sum of the first n terms of an Arithmetic Progression, a is the first term and d
is the common difference, it can be verified that S=(n/2)(2a+(n-1)d).

The first n consecutive positive integers forms an Arithmetic progression, the first term of which is
1.  1,2,3,4,5,6,7,8,9,10,…,n

The formula
n
 i = n(n+1)
i=i 2
is equivalent to the proven claim that the sum of the first n positive integers is easily computed as
n(n+1)/2.

Hence, the sum of the first 10 positive integers is (10)(10+1)/2 which is equal to 55. This can be verified
by performing the long process of addition(i.e. 1+2+3+4+5+6+7+8+9+10 = 55 ).

Sequences and formulas associated with the sequences are sometimes involved in an analytic concern in
Computer Science(e.g. Algorithm Analysis).

Geometric Progression
A Geometric Progression is a sequence of the form a, ar, ar2, ar3, …, ark, where a is the initial term and r
is a common ratio. A term, after the first term, of a Geometric Progression is obtained by multiplying the
immediately preceding term by a non-zero number called a common ratio. The sum of the first (n+1)
terms of a geometric progression where r is not equal to 1 is (arn+1-a)/(r-1).

Take note that S = (arn+1-a)/(r-1) works if r is not equal to 1 and that S is the sum of the first (n+1) terms.
If r=1, S = (n+1)a.

Topics Not Necessarily Under Sequences but are needed to be reviewed by the potential Computer
Scientist.

Numbers:
Set of Positive Integers, Z+ = {1,2,3,4,5,6,7,8,9,….}
Set of Natural Numbers, N = { 0,1,2,3,4,5,6,7,8,9,…}
Set of Integers, Z = {…,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,…}

2 | Page
Commutativity Property of an Operation
An operation on a set is commutative if the order of the operands do not matter.
Addition of integers is commutative: a+b = b+a
Multiplication of integers is commutative: a(b) = b(a)

Associativity Property of an Operation


An operation on a set is associative if the grouping of operands do not matter.
Addition on integers is associative = ((a+b)+c) = (a+(b+c))
Multiplication on integers is associative = ((a)(b))(c) = (a)((b)(c))

Closure Property of an Operation.


An operation is closed with respect to a set if the result of the operation is an element of the same set.

Addition is closed with respect to the set of integers:


An integer plus an integer is an integer.
Suppose x is an element of Z and y is an element of Z. (x+y) is an element of Z

Multiplication is closed with respect to the set of integers:


An integer multiplied by an integer is an integer.
Suppose x is an element of Z and y is an element of Z, x(y) is an element of Z

Identity element for integer addition ( Addition Property of Zero).


0 is the identity element for integer addition. Obviously, this is because the identity of an integer is
maintained if 0 is added to the former. For example, 5+0=5.

Identity element for integer multiplication ( Identity Property of Multiplication).


1 is the identity element for integer multiplication because the identity of an integer is maintained if the
integer is multiplied by 1. For example, 3(1)=3.

Additive Inverse of an integer.


The additive inverse of an integer x is the integer y such that x + y equals the identity element for
addition (i.e. 0). For example, -5 is the additive inverse of 5 because 5 +(-5) = 0.

Multiplicative Inverse of an integer.


The multiplicative inverse of an integer n is 1/n. The product of an integer and its multiplicative inverse
is equal to the identity element for multiplication(i.e. 1). For example, the multiplicative inverse of 7 is
1/7 because 7(1/7)=1.

The Factorization (or Factoring) an integer X is the process of determining the integers such that if these
integers are multiplied the result is X.
For example, if X is 15, the factors of X may be 3 and 5. That is, (3)(5)=15.
Because 1(15)=15, 1 and 15 are also factors of 15.
Collectively, 1,3,5 and 15 are factors of 15.

For example, if X is 42, the factors of X may be 2,3 and 7. That is (2)(3)(7)=42
Because 1(42) = 42, 1 and 42 are also factors of 42.
Because (6)(7)= 42, 6 is also a factor of 42.
Because (3)(14) = 42, 14 is also a factor of 42.
Because (2)(21) = 42, 21 is also a factor of 42.

3 | Page
Collectively, 1,2,3,6,7,14,21 and 42 are factors of 42.

Prime Numbers.
An integer that is greater than 1 that has no other factors aside from 1 and itself is a Prime Number.
For example, 2 is a prime number because 2 is greater than 1 and there are no others factors of 2 aside
from 1 and 2.

For example, 3 is a prime number because 3 is greater than 1 and there are no others factors of 3 aside
from 1 and 3.

For example, 5 is a prime number because 5 is greater than 1 and there are no others factors of 5 aside
from 1 and 5.

Composite Numbers.
An integer that is greater than 1 that has factors other than 1 and itself is a Composite Number.
For example, 4 is a composite number because 4 is greater than 1 and 2 is a factor of 4 aside from 1 and 4.

For example, 6 is a composite number because 6 is greater than 1 and 2 and 3 are factors of 6 aside from 1
and 6.

Prime Factorization.
Every composite number may be expressed as a product of prime numbers.
For example, 6 = 2 (3). 6 is a composite number and 2 and 3 are prime numbers.
For example, 8=2(2)(2). 8 is a composite number and 2 is a prime number.
For example, 10=2(5). 10 is a composite number and 2 and 5 are prime numbers.
For example, 42=(2)(3)(7). 42 is a composite number and 2, 3 and 7 are prime numbers.

You may read that Prime Numbers have applications in Computer Science algorithms(e.g.Cryptography).
An interesting task in Computer Programming is to write an efficient program that evaluates a very large
integer in order to determine if the very large integer is a prime number or not. This is, in fact, a
challenging problem. Writing a program for prime factorization of a very large integer is a fundamental
exercise for parallel programming/computing. (i.e. Write a program for determine if a very large integer
is a prime number or not).

Fundamental Equation for Division of integers.

N = Q(D) + R ( i.e. Numerator/Denominator = Integer Quotient + Remainder)

Consider for example dividing 9 by 4 ( i.e. N=9, D=4). Then Integer Quotient, Q=2 and Remainder, R=1]

Therefore, the pertinent equation is 9 = 2(4) + 1

Divisibility
A Divides B ( notation: A | B)

A divides B if the remainder when B is divided by A is zero. (i.e. A = Q(B) + 0 )

2 | 42 = 2 divides 42. 42/2 = 21 remainder 0.

4 | Page
6 | 42 = 6 divides 42. 42/6 = 7 remainder 0

Note on Prime Factorization.


To determine the prime factors of N, attempt a division by the lowest prime number. If divisibility holds,
repeat the process with the quotient else attempt a division starting with the next prime number. Repeat
the process until the quotient is prime.

For example. What are the prime factors of 2394.

2394/2 = 1197 remainder 0. Hence. 2 is a factor


1197/2 does not yield a zero remainder
1197/3 = 399 remainder 0. Hence, 3 is a factor.
399/3 = 133 reminder 0. Hence, 3 is a factor (twice)
133/3 does not yield a zero remainder
133/7 = 19 remainder 0. Hence, 7 is a factor. In addition, 19 which is a prime number, is a factor.

Therefore, 2394 = (2)(3)(3)(7)(19).

Modular Arithmetic
The mod ( i.e. modulo) operator in computer programming returns the remainder.
For example, (10 mod 3) = 1 because 10/3 = 3 remainder 1.
For example, (99 mod 11) = 0 because 99/11 = 9 remainder 0.

Modular Arithmetic is sometimes referred to as clock arithmetic because the concept of modular
arithmetic is applied with problems such as the following.
Consider a clock that follows time from 0.0 hundred hour to 24.0 hundred hour (Military time!). If a 25-
hour journey begins at 7.0 hundred, AT what time will the journey end?

Solution: (7 + 25) mod 24 = 32 mod 24 = 8. The journey ends at 8.0 hour.

Euclidean algorithm for determining the Greatest Common Factor (GCF) of X and Y where X is lesser
than Y .

1. R = Y mod X.
2. If R is equal to zero: {
GCF = X
End
}
else {
Y=X
X=R
Repeat from step 1
}

Example. Determine the Greatest Common Factor of 246 and 72. [i.e. GCD(246,72)]

Solution.
Because 72 < 246, X=72 , Y=246

5 | Page
R = Y mod X = 246 mod 72 = 30
Y = 72, X = 30
R = 72 mod 30 = 12
Y =30, X =12
R = 30 mod 12 = 6
Y = 12, X=6
R = 12 mod 6 = 0
Therefore, GCF (246,72) = 6

Rational Number (Usually denoted as Q)


A number that can be written in the form a/b where a and b are integers and b is not equal to 0.

Relatively Prime Integers. ( also called Co-primes)


Two integers are relatively prime if the greater common factor of the two numbers is 1. In some
references, this definition is stated as two integers are relatively prime if the two integers do not have a
common factor aside from 1.

For example:
1/2 is a rational number since it is of the form a/b where a=1 and b=2.

1 and 2 are relatively prime integers because the two numbers do not have a common factor aside from 1.

Note:
You may find a reference that defines a rational number as any number that may be expressed in the form
a/b where a and b are relatively prime integers. This definition is needed when making a proof that a
number is irrational.

Irrational Number
Numbers that cannot be expressed in the form a/b where a and b are integers are called Irrational
Numbers. The square root of 2 is an example of an irrational number.

Real Numbers ( usually denoted as R)


The numbers that may written in the form a/b together with the irrational numbers are called real
numbers. Real numbers are usually presented with an integer part, the decimal point and fractional part.
1.25 is an example of a real number.

Floor and Ceiling Function


In some Computer programming languages, some functions that are applied to real numbers are included.
-The floor function returns the highest whole number (integer) that is lesser than or equal to a given real
number. In other words, the floor function returns the integer part of a real number. For example,
floor(10.25)= 10, floor(1.99)=1, floor(5.00)=5, etc.
- The ceiling function returns the lowest integer that is greater than or equal to a given real number. For
example, ceiling(10.25)=11, ceiling(1.99)=2, ceiling(5.00)=5.

6 | Page
Recursion
The idea of recursion has been introduced in fundamentals of computer programming. As a Computer
Science fellow, you may need to include the idea of recursion in your knowledge base.

Recursion is a process of expressing the solution to a problem in terms of a simpler version of the
problem. (Gosset, 2003)

A program that implements a recursive algorithm is one where the program invokes itself during
execution.

The following are some algorithms that illustrates recursion.


1. Algorithm for computing the factorial of n. The factorial of n, denoted as n!, is the product of the
integers from 1 to n[i.e. n!=1(2)(3)…(n-2)(n-1)(n)]. In essence, n! is the product of n and the
factorial of (n-1)[i.e. n!=(n)(n-1)!].

factorial(n)
If n == 1
return 1
else
return n*factorial(n-1)

2. Algorithm for the Numerical Coefficients of the Expansion of a Binomial through Pascal’s
Triangle.
When expanding (x+y)n, the numerical coefficient of the term xn-kyk is the (k+1)th entry in the
(n+1)th row of the Pascal’s Triangle. Below is a part of the Pascal’s Triangle as is usually shown
in references in Mathematics.

Row 0 1
Row 1 1 1
Row 2 1 2 1
Row 3 1 3 3 1
Row 4 1 4 6 4 1

An alternative representation and visualization may be followed in programming. The above


Pascal’s Triangle is intuitively the same as the one below.
Column 0 Column 1 Column 2 Column 3 Column 4
Row 0 1
Row 1 1 1
Row 2 1 2 1
Row 3 1 3 3 1
Row 4 1 4 6 4 1

The entries in column 0 and the final column of each row are always equal to 1. The other entries
in a column is the sum of the two entries in the previous row that are nearest neighbors. If each

7 | Page
entry is denoted as PascalTriangle(row, column), the formula for each entry may be presented as
follows.

PascalTTriangle(row,column) = 1 if column=0 or column=row.


and
PascalTTriangle(row,column) = PascalTriangle(row-1,column-1) + PascalTriangle(row-
1,column) if column not equal to 0 or column is not equal to row.

The following is the algorithm for determining the entry in the Pascal’s Triangle at a specified
row and column.

PascalTriangle(row, column)
If (column=0) or (column=row)
Return 1
Else
Return PascalTriangle(row-1, column-1) + PascalTriangle(row-1, column)

3. Algorithm for getting a term of an Arithmetic Progression


Suppose the first term of an arithmetic progression is f and the common difference is d. That is,
the arithmetic progression has the terms a0, a1, a2, … an where a0=f, a1=f+d, a2=f+2d, a3=f+3d,…,
an= f+ nd. Notice that the first term is identified by the subscript 0, the second term is identified
by the subscript 1 and so on. The first term is 0th term such that the nth term is actually the
(n+1)th member of the sequence. A recursive algorithm for getting a term of the arithmetic
progression which has f as its first term and a common difference d is as follows.

arithmeticProgression(n)
If n==0
return f
else
return arithmeticProgression(n-1)+d

Suggested Reading (The Tower of Hanoi Puzzle).


One application of Recursion is the Programming-based solution to the Tower of Hanoi Puzzle.
Every computer science-oriented enthusiast must be familiar with the Tower of Hanoi Puzzle.
Such a Puzzle is very interesting in that some references have interesting analytic and
programming problems based on the Tower of Hanoi Puzzle.

Read about the “End of the World Problem through the Tower of Hanoi Puzzle”.
The Tower of Hanoi Puzzle involves three rods called pegs and a number of disks of different sizes.
The disks can slide onto any peg. Initially, the disks are neatly stacked in ascending order of size on
one peg(first peg) such that the smallest disk is at the top. A conical shape is then formed by the
disks in a peg.
The objective of the puzzle is to move the entire stack of disks to another peg (third peg) by obeying
the following rules.

1. Only one disk can be moved from one peg to another peg at a time.
2. Each move consists of taking the upper disk from one of the pegs and placing it on top of
another peg or on an empty peg.
3. No larger disk may be placed on top of a smaller disk in any peg.

8 | Page
The fundamental question is the minimum number of moves that must be done in order to solve the
Tower of Hanoi Puzzle that has n disks?

Suggested Reading.
Recall that some sequences and the formula for getting the sum of the first k terms of them have been
presented in Discrete Structures. The formulas for the sum of the terms were proven using the principle of
Mathematical Induction. As previously mentioned, the sequences may become relevant in your future
Computer Science-based endeavors(e.g. Algorithm Analysis). Find time to read about these sequences and
the formulas for getting the sum of their first k terms.

In addition, there are more challenging sequences that you may have to understand as you advance your
career in Computer Science. The so called Taylor Series is one example. The comprehension and
appreciation of sequences may rest on your familiarity with requisite concepts in Calculus.

Exercise V
1. Give very short narrative description of the “End of the World Problem as an application of the
Tower of Hanoi Puzzle”. ( Search the details from the internet )

2. Suppose the sequence {an} is a function from {1,2,3,4,…} to {1,5,25,125, … } is such that an =
5n. Show the first 10 terms of the sequence.

3. Compute the sum of the first 100 positive integers by using an appropriate formula. Show a
solution that involves a sequence (i.e. Show the sequence).

4. How many pairs of rabbits are produced in one year out of one pair at the beginning of the year?
(Janacek & Lemmon, 2011):
A certain man had one pair of baby rabbits at the beginning of a year. How many pairs of rabbits
will the man have at the end of the year if it is the nature of the rabbits to mature after one month.
A pair of mature rabbits will then give birth to a pair of baby rabbits after one month and every
after one month thereafter. Every pair that is born that matures after one month will also give
birth to a pair after one month and every after one month thereafter. Derive the answer by
completing the following incomplete solution/table.

Solution: The answer is a term of the Fibonacci Sequence (Which term?).


Month 0 1 2 3 4 5 …
Pairs of 1 0 1 1 2 3 …
Baby
Rabbits
Pairs of 0 1 1 2 3 5 …
Mature
Rabbits
Total Pairs 1 1 2 3 5 8 …
of Rabbits

9 | Page
References:

Banks, J., et al. (1996). Discrete Event System Simulation. 2nd Edition. Prentice Hall, Inc. New Jersey. U.S.A.
Gosset, E. (2003). Discrete Mathematics with Proof. Pearson Education Inc. USA.

Hillier, F. and M. Hillier. (2011). Introduction to Management Science A Modeling and Case Studies Approach with
Spreadsheets. 4th Edition. McGraw-Hill Education. Singapore.

Janacek,G and M. Lemmon. (2011). Mathematics for Computer Science. Gareth J. Janacek, Mark Lemmon Close &
Ventus Publishing

Love, C. & E. Rainville. (1981). Differential and Integral Calculus. . Macmillan Publishing Co., Inc. USA.

Rainville, E. & P. Bedient. (1974). Elementary Differential equations. Macmillan Publishing Co., Inc. USA.

Rosen, K. (2001). Discrete Mathematics and Its Applications. Mc-Graw Hill Book Co. Singapore.

Walpole, R.(1997). Introduction to Statistics. 3rd Edition. Prentice Hall International, Inc. Singapore.

10 | Page

You might also like