Scs1210 Computer Science Discrete Mathematics Outline
Scs1210 Computer Science Discrete Mathematics Outline
PROGRAMME
BSC Honours in Computer Science
LEVEL Part 1
Module TITLE
Computer Science Discrete Mathematics
Module CODE SCS1210
MODULE AIM By the end of the module, you should be able to apply fundamental
concepts and techniques in problem-solving and program
development in Computer Science and IT-related areas.
LEARNING OUTCOMES Programming skills, Present mathematical arguments in
programming. Problem solving.
1
Prove that a relation is an equivalence relation by applying
the relation properties.
Prove that a function is surjective, injective, and bijective.
Determine the inverse and compositions of functions.
Apply the laws and properties of probability to solve
problems involving discrete probability.
Apply combinations and permutations in solving problems
and making use of product and sum rules.
Find and ascertain the truth values of sentences using
logical connectives.
Determine the truth value of a proposition and make a
representation on the truth table.
Construct truth tables to determine the truth values of given
sentences
Analyse and evaluate the characteristics of a Purely-
functional programming language.
Develop algorithms that traverse a tree.
1.1. Introduction:
Sets are a collection of objects. The objects in the collection are its members or elements.
For example, we are all members of the set of all humans. Anything can be in a set. There
are sets of numbers, people, shapes, etc.
Notation: Set notation: Listing elements { }. Elements are listed in brackets and
separated by commas.
Set builder notation: P = {x: x is even, 2≤x<9}. This describes the set and elements are
listed using the given description. We list elements of sets like this: {0,1} The set
containing 0 and 1. {1, 2, 3, 4, 6, 7} The set containing natural numbers from 1 to 7. {1,
2, ...}. The set contains all the natural numbers. (Note: this set has infinitely many
2
members). {x: x is an even number} The set containing the even numbers {0, 2, 4, ...}
There are three main ways to specify a set:
(a) by listing all its members (list notation);
(b) by stating a property of its elements (predicate notation);
(c) by defining a set of rules which generates (defines) its members (recursive rules).
It is often intuitive to speak of “collecting” things together and “putting them into” a set,
but the idea is that the sets exist whether or not anyone has ever done any collection.
Moreover, notice that a set’s members do not need to be similar but must be drawn from
the same domain.
Key terms
Sets, objects, elements, collection.
Sets: Collection of objects.
Elements: Members of the set are referred to as objects.
Collection: Grouping of well-defined elements of a set using set notation
Universal Set
When we define a set, we should specify where the elements in the set come from. This is a
specification of the Universal set and is denoted by the symbol . When all our sets are
subsets of real numbers, then our Universal set may be taken as the set of all real numbers.
Draw the Venn Diagrams to illustrate the concept of the Universal set.
Or Union A ∪ B = {x : x ∈ A ∨ x ∈ B}.
x Є B}.
Intersection
Let A and B be subsets of a universal set . The intersection of A and B, denoted A∩B, is
the set of all elements x in such that x is in A and x is in B. Symbolically, A ∩B = {x Є :
Or Intersection A ∩ B = {x : x ∈ A ∧ x ∈ B}.
x Є A and x Є B}.
Difference
Let A and B be subsets of a universal set . The difference/Compliment of B minus A,
denoted B − A, is the set of all elements x in such that x is in B and x is not A.
Symbolically, B − A = {x Є : x Є B and x is not in A}. Or Difference A − B = {x : x
3
∈ A ∧ x ∉ B}.
Complement
A. Symbolically, Ac = {x Є : x ∉ A}.
The complement of A, denoted Ac, is the set of all elements x in such that x is not in
Singleton Set
A set with one element. A = {7}.
Subsets
If A and B are sets, the set A is called a subset of B, written A B,
if every element of A is also an element of B. Symbolically, we have
A B x, if x Є A x Є B. Define a proper subset.
Cartesian Product
Given two sets A and B, the Cartesian Product of A and B is defined
By A × B = {(a, b): a Є A b Є B}.
Given that A={a, b, c) B={1, 2, 3},
then AXB ={ (a,1), (a,2), (a,3),(b,1), (b,2), (b,3), (c,1), (c,2), (c,3)}
Power set
Given a set A, the power set of A is a set of all subsets of A and is denoted by p(A). For
example A={1,2}
then p(A) = {{},{1},{2},{1,2}}. For all set A and B if AB then p(A)p(B). For a set
X with n elements then p(X) has 2n elements where nЄZ, n0
Give examples
The power set P(A) of a set A is the set of all subsets of A. Suppose that A = {1; 2; 3; 4;
5}.
How many elements are there in p(A)?
List the elements of p(A)
Activity 1a
4
Show that:
A∪A = A
A∩A=A
2. Given that A= {a, b}
Write down the expression for the number of elements in the
power set.
Find the power set of A.
List the elements of AxA.
3. Given that X = {a, b, c, d} and Y = {a, d, e, f}, find
i) X – Y
ii) Y + X
iii) (X∩Y)
4. Prove that:
(A∪ B)c = (A∩B)c
P∪ (Q ∩ R) = (P ∪ Q) ∩ (P ∪ R)
(A∩ B)c=Ac∪Bc
1.3. Sub topic 2: Properties of sets/ The Boolean identities for sets
A∪B=B∪A A∪A=A
Commutativity Idempotent Laws
A∩B=B∩A A∩A=A
A ∪ (B ∪ C) = (A ∪ B) ∪ C A∪∅=A
Associativity Empty set
A ∩ (B ∩ C) = (A ∩ B) ∩C A∩∅=∅
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) A ∪ (A ∩ B) = A
Distributivity Absorption
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∩ (A ∪ B) = A
A ∩ (B U C) = (A∩ B) U (A ∩ C)
From LHS : xЄA∩(BC)
xЄA and xЄ(BC) give reasons
xЄ(BC)
xЄA and xЄ B or xЄA and xЄC
xЄ(A∩ B) xЄ (A∩C)
xЄ[(A∩ B) (A∩C)], justify the steps
A ∩ (B U C) (A∩ B) U (A ∩ C)
5
same steps from RHS
De Morgan’s Laws
(A U B)c = Ac ∩ Bc (A ∩ B)c = Ac U Bc .
Sets in Computers
Data: Unique storage, duplicate removal.
Algorithms: Membership checks, graph work.
Databases: Queries, unique records.
Code: Data structures, character handling.
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-
Hill, 2012. ISBN 978-0072899054. QA39.3 R67 2012 (LC).
2 Topic 2: RELATIONS
2.1. Introduction:
The most direct way to express a relationship between elements of two sets is to use
ordered pairs made up of two related elements. For this reason, sets of ordered pairs are
called binary relations. In this topic we introduce the basic terminology used to describe
binary relations. Later we will use relations to solve problems involving communications
networks, project scheduling and identifying elements in sets with common properties
such as reflexive, symmetric, transitive and equivalence.
6
A relation R on a set A is called symmetric if (b, a) ∈ R whenever (a, b) ∈ R, for all a, b
∈ A.
A relation R on a set A such that for all a, b ∈ A, if (a, b) ∈ R and (b, a) ∈ R, then a = b
Key Applications:
Relational Algebra:
SQL (Structured Query Language), the standard language for interacting with relational
databases, is based on relational algebra.
Concepts like functional dependencies and normalization, which are crucial for
7
maintaining data integrity, are based on the properties of relations studied in discrete
mathematics.
Constraints, such as primary key and foreign key constraints, enforce rules that
ensure the consistency and accuracy of data, and these rules are based on the
mathematical definition of relations.
Query Optimization:
Activity 2a
3 Topic 3: FUNCTIONS
3.1 Introduction
A function is an expression, rule, or law that defines a relationship between one variable
(the independent variable) and another variable (the dependent variable). It is defined as
rule or law that defines a relationship between two or more sets. A function is like a
computing device that takes an input and gives an output. Functions enable programmers
to break down or decompose a problem into smaller chunks, each of which performs a
particular task. Once a function is created, the details of how it works can almost be
forgotten about. In this way the detail is abstracted, allowing the programmer to focus on
8
the bigger picture. Functions are used in the definition of such discrete structures as
sequences and strings. Functions are also used to represent how long it takes a computer
to solve problems of a given size. Many computer programs and subroutines are
designed to calculate values of functions. Recursive functions, which are functions
defined in terms of themselves, are used throughout computer science; In this topic we
will introduce the concept of a function, types of functions such as injective, surjective
and bijective; Also introduced are inverse of a function and composite functions; Proofs
and properties of functions.
Let A and B be sets. A function f from A to B assigns to each x ∈ A and element f(x) in
B. This is also referred to as a mapping or transformation between sets. WE write f: A →
B: x →f(x). In this case A is called the domain of the function and B is called the co-
function.
Linear Functions:
Definition:
A linear function has a degree of 1.
It's represented by the form: y = mx + b, where 'm' is the slope and 'b' is the y-
intercept.
Characteristics:
Forms a straight line when graphed.
Has a constant rate of change.
Example:
y = 2x + 3
Cubic Functions:
Definition:
A cubic function has a degree of 3.
It's represented by the form: y = ax³ + bx² + cx + d, where 'a' is not equal to 0.
Characteristics:
9
Forms an "S" shaped curve when graphed.
The rate of change is not constant.
can have up to 3 roots.
Example:
y = x³ - 6x² + 11x - 6
set C. The composition of the functions f and g, denoted for all a ∈ A by f ◦ g, is defined
Let g be a function from the set A to the set B and let f be a function from the set B to the
by (f ◦ g)(a) = f (g(a)). In other words, f ◦ g is the function that assigns to the element a of
A the element assigned by f to g(a). That is, to find (f ◦ g)(a) we first apply the function g
to a to obtain g(a) and then we apply the function f to the result g(a) to obtain (f ◦ g)(a) =
f (g(a)). Note that the composition f ◦ g cannot be defined unless the range of g is a subset
of the domain of f.
10
Activity 3a
1 Investigate whether the function f(x) = 3x – 4 is bijective under real
numbers.
2 Given that f(x) = 3x – 2 and g(x) = x2 + x, find
a) f(x) + g(x)
b) g(x) – 3f(x)
c) (fOg)(x)
e) f(x)-1
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-Hill, 2012.
ISBN 978-0072899054. QA39.3 R67 2012 (LC).
Topic 4: COMBINATORICS
4.1 Introduction
Combinatorics is the study of finite or countable discrete structures and includes counting the
structures of a given kind and size, deciding when certain criteria can be met, and constructing and
analysing objects meeting the criteria, finding "largest", "smallest", or "optimal" objects, and
studying combinatorial structures arising in an algebraic context, or applying algebraic techniques
to combinatorial problems.
11
The two tasks are performed simultaneously.
Activity 4a
Example of the rule of sum
i. A college library has 40 textbooks on sociology and 50 textbooks dealing
with anthropology. In sum, a student at this college can select among
40†50=90 ways
If there are n distinct objects and r, at time is an integer, with 1≤ r ≤n, then by the rule of
product, the numbers of size r for the n objects is
P(n,r)=n×(n-1)×(n-2)..........(n-r†1)
=n!÷(n-r)!
Where n! =1 ×2×3...............×n is called n factorial
when the number of objects n is equal to the size of arrangements r the permutation is
P(n ,n)= n!÷(n-n)!
=n!÷o!
=n!
Activity 4b
Example of Permutation
The number of permutations of the letters COMPUTER is
=8!
If only 5 of the letters are used, the number of permutations
P (8,5) = 8!÷(8-5)!
=6720
12
DATABASES
=9!÷3!2!
=30 240 possible arrangements
On many occasions we are not interested in the order of arrangement, but the number of
possible arrangements. Under such circumstances, we apply the combination principle.
The combination of r objects chosen from a set containing n of them is given by the
formulae: C(n,r)=P(n,r)÷r!
Activity 4c
Example of Combinations
i. A student taking a calculus exam is directed to answer any 7 of 10
essay questions. Find the number of ways he can answer the exam
C(10,7)= 10!÷7!(10-7)!
=10!÷7!3!
=120wayz
ii. If the student must answer 3 questions from the 5 and 4 from the last
5, for the first 3 is
C(5,3)=5!÷3!2! =10 ways
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-Hill, 2012.
ISBN 978-0072899054. QA39.3 R67 2012 (LC).
5.1 Introduction
Logical connectives are symbols used to connect two or more logical statements. They
are also called logical operators because they are used to connect logical statements to
form compound statements from one or more logical statements.
13
5.2 Key terms
Proposition, Atomic
Proposition: sentence/statement that is true or false.
Atomic: a statement that cannot be logically broken into smaller statements.
Taking p and q to denote sentences: take T/1 – True and F/0 – False
Propositional logic is composed of propositional symbols, logical connectives, and/or
parenthesis.
Negation: P is True: p for NOT: p is T if p is F and F if p is T
Disjunction: p q for OR is T if at least one of the sentences is T and is F otherwise
Conjunction: p q for AND is T if the two sentences are both T and is F otherwise
Conditional: pq for IF THEN: is T if P is F or q is T or both and is F otherwise
Bi-conditional: pq for IF AND ONLY IF: T is both p, q are T or both F and are F
otherwise.
14
Inverse: The inverse is formed by negating the hypothesis and negating the conclusion.
p → q: If you have a Sprite, then you have a root beer. ~ p → ~ q: If you do not have a
Sprite, then you do not have a root beer.
Converse: The converse is formed by interchanging the hypothesis and the conclusion.
p → q: If it rained, then the ground got wet. q → p: If the ground got wet, then it rained.
Contrapositive: The contrapositive is formed by negating both the hypothesis and the
conclusion, and then interchanging the resulting negations. p → q: If 15 is an odd
number, then 15 is a prime number. ~ q → ~ p: If 15 is not a prime number, then 15 is
not an odd number.
Activity 5a
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-Hill, 2012.
ISBN 978-0072899054. QA39.3 R67 2012 (LC).
6.1 Introduction
Graphs are discrete structures consisting of vertices and edges that connect these vertices.
There are different kinds of graphs, depending on whether edges have directions, whether
multiple edges can connect the same pair of vertices, and whether loops are allowed.
Problems in almost every conceivable discipline can be solved using graph models. Using
15
graph models, we can determine whether it is possible to walk down all the streets in a city
without going down a street twice, and we can find the number of colors needed to color
the regions of a map. Graphs can be used to determine whether a circuit can be
implemented on a planar circuit board. We can distinguish between two chemical
compounds with the same molecular formula but different structures using graphs. We can
determine whether two computers are connected by a communications link using graph
models of computer networks.
For a set V with n elements, how many possible edges are there? Number of edges
(vallency)in a directed graph ¿ n ( n−1 ) .The number of edges¿ n(n−1)/2
(undirected graph). Number of graphs = 2 n(n−1)/2
Activity 6a
How many edges are there in a graph with 10 vertices, each of degree 6?
Applying handshaking theorem.
Let G=(V , E)be an undirected graph with m edges.
16
2 m=∑ deg (v), N (V )=10 , deg (1)=deg (2)=… … ..=6.
∑ deg ( v ) = 60
2 m=60thus sum of the degrees of vertices is an even number, meaning graph
G has an odd degree.
m=30.
Graph theory helps in understanding and designing network topologies (e.g., star, mesh, tree) for
optimal performance and reliability.
Optimization:
Graph algorithms help in designing efficient network layouts, minimizing cable lengths, and reducing
costs.
2. Routing Algorithms:
Graph theory aids in analyzing network traffic patterns and developing strategies to prevent
congestion and bottlenecks.
3. Network Security:
It helps in analyzing network security vulnerabilities and developing strategies to protect against
attacks.
17
Intrusion Detection:
Graph-based techniques can be used to detect anomalies and suspicious patterns in network traffic,
indicating potential security breaches.
Information Flow:
Social networks are inherently graphs, with users as nodes and connections as edges.
Graph theory helps analyze information flow, identify influential users, and understand network
dynamics.
Data Mining:
Graph-based data mining techniques are used to discover patterns and relationships in social
network data.
5. Database Systems:
Graph Databases:
Graph databases use graph structures to store and query data, which is particularly useful for
representing and querying relationships between data entities.
These databases are well-suited for applications involving complex relationships, such as social
networks and recommendation systems.
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-Hill, 2012.
ISBN 978-0072899054. QA39.3 R67 2012 (LC).
7.1 Introduction
A tree traversal, also known as tree searches, are algorithms executed on graphs containing
only tree edges, that visit each node exactly once. Algorithms in this category differ only in the
order in which each node is visited. Two classic methods to traverse a tree are breadth-first
search (bfs), where nodes in the same level or distance away from the root are visited before
proceeding to the next level; and depth-first-search, where all the nodes in a branch, or one set
path from root to leaf, are visited before passing on to the next branch.
18
tree, Height of a node.
Tree: A tree is a collection of nodes.
Parent: The root of each subtree is said to be a child of r and r is said to be the parent of
each subtree root.
Leaves: Nodes with no children /external nodes.
Internal Nodes: nodes with children.
Siblings: Nodes with the same parent.
Binary tree: A tree in which no node can have more than two children. Each node has an
element, a reference to a left child, and a reference to a right child
Depth of node: The length of the unique path from the root to a node.
Depth of tree: The depth of a tree is equal to the depth of its deepest leaf.
Height of node: The length of the longest path from a node to a leaf.
Activity 7a
19
Solution
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-Hill, 2012.
ISBN 978-0072899054. QA39.3 R67 2012 (LC).
8.1 Introduction
A quantifier is used to quantify the variable of predicates. It contains a formula, which is a type
of statement whose truth value may depend on the values of some variables. When we assign a
fixed value to a predicate, then it becomes a proposition. In another way, we can say that if we
quantify the predicate, then the predicate will become a proposition. So quantify is a type of
word that refers to quantifies like "all" or "some".
20
8.2 Key terms
Predicate, Quantifiers
Predicate: A predicate is a property that describes a variable.
Quantifiers: These are phrases such as “For all”, “For very”, “For each”, “For some”,
that tell some sense how many objects have a certain property.
21
Activity 8a
Compute - x y x2 y.
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-Hill, 2012.
ISBN 978-0072899054. QA39.3 R67 2012 (LC).
9.1 Introduction
A recurrence relation for a sequence {an} is an equation that expresses an in terms of
one or more of the previous terms in the sequence, a0, a1, . . . , an−1 for all integers n
n0 where n0 is a nonnegative integer. Sequence is called a solution of a recurrence
relation if its terms satisfy the recurrence relation.
Algorithm Analysis Recurrence relations are frequently used to determine the time complexity
of recursive algorithms. The most common example is the analysis of the divide-and-conquer
strategy, which breaks a problem into smaller subproblems, solves them recursively, and
combines the results. The recurrence relation helps establish the overall time complexity.
Example: Merge Sort follows the recurrence relation: Solving this using the Master
22
Theorem gives a complexity of .
Graph Algorithms Graph traversal algorithms, such as Depth-First Search (DFS) and Breadth-
First Search (BFS), often have recursive implementations whose efficiency is analyzed using
recurrence relations.
Example: The Tower of Hanoi problem is a classic recursive problem defined by:
Solving this gives an exponential complexity of .
Cryptography and Security Many cryptographic protocols, such as RSA encryption and
elliptic curve cryptography, rely on recurrence relations for key generation, encryption, and
decryption processes.
Activity 9a
Consider the recurrence relation an = 5an−1 − 6an−2 (2) with initial
conditions a0 = 1 and a1 = 4.
The characteristic equation is s2 − 5s + 6 = (s − 2)(s − 3) = 0.
Since the roots are s = 2 and s = 3,
any solution of (2) has the form an = 3n + 2n.
Therefore, a0 = + = 1 a1 = 3 + 2 = 4.
Solving this linear system, we get = 2 and = −1. The solution of (2) with
the given initial conditions is then an = 2 · 3n − 2n
23
m=30.
Reading sources/links
Kenneth H. Rosen. Discrete Mathematics and Its Applications, Seventh Edition, McGraw-Hill, 2012.
ISBN 978-0072899054. QA39.3 R67 2012 (LC).
4 PRACTICUUM
5 REVISION
6 EXAMINATION
24