0% found this document useful (1 vote)
264 views100 pages

IT 123 Discrete Mathematics Module

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
264 views100 pages

IT 123 Discrete Mathematics Module

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100

Instructional Material Lecture

Author: Catleen Glo M. Feliciano


ISUE-CCSICT Faculty
DISCRETE Mathematics
This Instructional Material contains pre-assessment, lessons, exercises
and activities to learn Discrete Mathematics.

Author: CATLEEN GLO M. FELICIANO, MIT


College of Computing Studies, Information and Communication Technology (CCSICT)
Isabela State University

TABLE OF CONTENTS
CHAPTER I. INTRODUCTION TO DISCRETE MATHEMATICS 1
Learning Content
Intended Learning Outcomes
Pre-Assessment 1
The concept of Discrete Structures
• The concept of problem solving
Traditional “GUESS” method
Framework for Problem Solving (Polya)
Self-Check 1
Answer Key

CHAPTER 2. GRAPH THEORY 7


Learning Content
Intended Learning Outcomes
Pre-Assessment 2
• Graph theory and graphs
• Types of graphs
Undirected Graph
Directed Graph
Indegree
Outdegree
Weighted Graph
Unweighted Graph
Self-Check 2
Answer Key

CHAPTER 3. PROBLEM FORMULATION 18


Learning Content
Intended Learning Outcomes
Pre-Assessment 3
• Properties of an formulation
Initial State
Final State

i
List of Operator
Valid Goal Test
Shortest Path
Longest Path
Self-Check 3
Answer Key

CHAPTER 4. SETS 24
Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• The concept of Set Theory
• Representation of a set
• Types of sets
• Venn Diagram
• Set Operations
• Power Sets
Self-Check 1
Answer Key

CHAPTER 5. TREES 40
Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• The concept of trees
• Properties of a Tree
• Types of Trees
Self-Check 1
Answer Key

CHAPTER 6. TREE TRAVERSAL 46


Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• The concept of graph traversal and graph traversal algorithms
• Evaluation of graph traversal algorithms
• Common types of graph traversal algorithm
Self-Check 1
Answer Key

CHAPTER 7. – HUFFMAN CODE 52


Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• The concept of HUFFMAN CODE
• Encrypt and Decrypt words using Huffman code
Self-Check 1

ii
Answer Key

CHAPTER 8. PROPOSITIONS 59
Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• The concept of Propositional Logic
• Connectives
• Tautologies, Contradictions and Contingency
• Propositional Equivalences
• Inverse, Converse and Contra-positive
Self-Check 1
Answer Key

CHAPTER 9. PREDICATE LOGIC 77


Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• The concept of predicate logic
• Primitives
• Quantifiers
• Translating English to Predicate Logic
Self-Check 1
Answer Key

CHAPTER 10. INFERENCE 84


Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• Concept of inference
• Rules of inference
Self-Check 1
Answer Key

CHAPTER 11 SORTING ALGORITHM 94


Learning Content
Intended Learning Outcomes
Pre-Assessment 1
• The concept of discrete structure sorting.
• Bubble Sorting
• Insertion Sorting
• Selection sorting
• Radix Sorting
Self-Check 1
Answer Key
Acknowledgement
About the Author

iii
What to do?
To get the most from this course, you need the following:

1. LEARNING CONTENT: Begin by reading the topic for the chapter. This will tell you
what lesson you will learn in the chapter.
2. INTENDED LEARNING OUTCOMES: This will tell you what will be the output upon
finishing the chapter
3. INFORMATION SHEET: This is where information about the chapter was written. It
includes explanation and examples related to the chapter topics.
4. PRE-ASSESSMENT: Find out what you already know by taking the pre-assessment.
This will identify if you need to learn about the chapter.
5. SELF-CHECK: after reading and understanding the chapter lesson self-check will
measure how much you have learned. Refer to the Answer key for correction.
6. ANSWER KEY: This will show the answer for the pre-assessment and self-check.

iv
CHAPTER I. DISCRETE MATHEMATICS

CHAPTER I
INTRODUCTION TO
DISCRETE STRUCTURE 1
Learning Content:
• The concept of Discrete Structures
• The concept of problem solving
 Traditional “GUESS” method (Heller and Heller, Univ. of Minnesota)
 Framework for Problem Solving (Polya)

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Identify Discrete Mathematics;
2. Enumerate, identify and differentiate the categories of mathematics;
3. Identify Discrete Structure;
4. Enumerate the different topics in discrete mathematics;
5. Identify and describe the general concept of problem solving;
6. Identify and describe traditional and scientific problem solving;
7. Differentiate traditional vs scientific problem solving;

1
CHAPTER I. DISCRETE MATHEMATICS

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about the INTRODUCTION TO DISCRETE STRUTURES

Pre-assessment 1 for LO1, LO2, to LO7

Identification:

1. _______________It is a branch of mathematics involving discrete elements that uses


algebra and arithmetic.
2. _______________It is based upon continuous number line or the real numbers.
3. _______________Is an art and there are no universal approaches to solving problems

Enumeration:

1. What are the The traditional “GUESS” method (Heller and Heller, Univ. of Minnesota)
_______________
_______________
_______________
_______________
_______________
2. What are the Framework for Problem Solving (Polya)
_______________
_______________
_______________
_______________

2
CHAPTER I. DISCRETE MATHEMATICS

INFORMATION SHEET

The concept of Discrete Structures


What is Mathematics?
Discrete Mathematics is a branch of mathematics involving discrete
elements that uses algebra and arithmetic. It is increasingly being
applied in the practical fields of mathematics and computer science. It
is a very good tool for improving reasoning and problem-solving
capabilities. This tutorial explains the fundamental concepts of Sets,
Relations and Functions, Mathematical Logic, Group theory, Counting
Theory, Probability, Mathematical Induction and Recurrence Relations, Graph Theory,
Trees and Boolean Algebra.
Mathematics can be broadly classified into two categories −
 Continuous Mathematics
 Discrete Mathematics
Continuous Mathematics is based upon continuous number line or the real numbers. It is
characterized by the fact that between any two numbers, there are almost always an
infinite set of numbers. For example, a function in continuous mathematics can be plotted
in a smooth curve without breaks.
Discrete Mathematics, on the other hand, involves distinct values; i.e. between any two
points, there are a countable number of points. For example, if we have a finite set of
objects, the function can be defined as a list of ordered pairs having these objects, and can
be presented as a complete list of those pairs.

What is Discrete Structure?


Discrete structure is set of discrete elements on which certain operations are defined.
Discrete implies non-continuous and therefore discrete sets include finite and countable
sets but not uncountable sets such as the real numbers. The term discrete structure covers
many of the concepts of modern algebra, including integer arithmetic, monoids,
semigroups, groups, graphs, lattices, semi-rings, rings, fields, and subsets of these.

Topics in Discrete Mathematics


Though there cannot be a definite number of branches of Discrete Mathematics, the
following topics are almost always covered in any study regarding this matter:
 Sets and Propositions
 Relations and Functions
 Discrete Structure
o Graph Theory
o Trees
o Graph Traversal
 Permutations and Combinations

3
CHAPTER I. DISCRETE MATHEMATICS

The concept of problem solving


A framework for Problem Solving
Problem solving is an art and there are no universal approaches to solving problems.
Basically, one must explore possible avenues to a solution one by one until one comes
across a right path to a solution. Thus generally speaking, there is guessing and hence an
element of luck involved in problem solving. However, in general, as one gains experience
in solving problems, one develops one's own techniques and strategies, though they are
often intangible. Thus the guessing is not an arbitrary guessing but an educated one.

The traditional “GUESS” method (Heller and Heller, Univ. of Minnesota)


 Givens - Identify the “given” information
 Unknown - Identify what is wanted
 Equation - Select equation for solution
 Solution - Solve equation for unknown
 Survey - Make certain solution is realistic

Framework for Problem Solving (Polya)


 Understanding the problem
 Devising a Solution Plan
 Carrying out the plan
 Looking back i.e. verifying
Understanding the Problem
 Extract the principal parts of the problem.
 Consult definitions for unfamiliar (often even familiar) terminologies.
 Construct one or two simple example to illustrate what the problem says.
Devising a Solution Plan
 Where to start?
 What can I do?
 What should I look for?
 Try to use heuristics. Some but not limited to:
o Have you used all the conditions/hypotheses? (simulation)
o Divide into cases (divide and conquer approach)
o Proof by contradiction (cause elimination)
o Working backward (forensic analysis)
o Simplify the problem
Carrying out the plan
 Execute the plan
Looking Back
 Recreate solution(s) with consistent result.
 Conclude which solution is most appropriate.

4
CHAPTER I. DISCRETE MATHEMATICS

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about the INTRODUCTION TO DISCRETE STRUTURES

Self-Check 1 for LO1, LO2, to LO7

Identification:

1. _______________It is a branch of mathematics involving discrete elements that uses


algebra and arithmetic.
2. _______________It is based upon continuous number line or the real numbers.
3. _______________Is an art and there are no universal approaches to solving problems

Enumeration:

2. What are the The traditional “GUESS” method (Heller and Heller, Univ. of Minnesota)
_______________
_______________
_______________
_______________
_______________
2. What are the Framework for Problem Solving (Polya)
_______________
_______________
_______________
_______________

5
CHAPTER II. GRAPH THEORY

CHAPTER II
GRAPH THEORY
Learning Content:
 Graph theory and graphs
 Types of graphs
o Undirected Graph
o Directed Graph
 Indegree
 Outdegree
o Weighted Graph
o Unweighted Graph

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe graph theory and graph
2. List, describe and identify the different types of graph
3. Recall and describe graph representations
4. List, describe and identify the different types of graph representation

7
CHAPTER II. GRAPH THEORY

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about the GRAPH THEORY

Pre-assessment 2 for LO1, LO2, to LO4

IDENTIFICATION

1. ______________________ is a pictorial representation of a set of objects where


some pairs of objects are connected by links
2. ______________________ is a particular position in a one-dimensional, two-
dimensional, or three-dimensional space
3. ______________________ is a connection between two points. It can be
represented with a solid line.
4. ______________________ is a point where multiple lines meet. It is also called a
node
5. A vertex with degree one is called a ______________________.
6. vertex with degree zero is called an ______________________.
7. ______________________ is the mathematical term for a line that connects two
vertices
8. if an edge is drawn from vertex to itself, it is called a ______________________
9. ______________________ has no directed edges
10. ______________________each vertex has an indegree and an outdegree
11. ______________________V is the number of edges which are coming into the
vertex V.
12. ______________________V is the number of edges which are going out from the
vertex V.
13. ______________________ has no value in its edges

APPLICATION
Identify the indegree and outdegree of the graph

Vertex Indegree Outdegree

8
CHAPTER II. GRAPH THEORY

INFORMATION SHEET

Graph theory and graph


History:
Texts typically trace the origin of graph theory to the Königsberg
Bridge Problem and its solution by Leonhard Euler (the book gives
this solution a date of 1736). The book describes the problem and the
history behind it. You may recall that Euler (pronounced “oiler”) was
a brilliant mathematician and perhaps the most prolific of history,
remaining productive into his 70’s or 80’s despite going blind.

Applications:
On p. 229 the book mentions the application of graphs to printed circuit and microchip design.
Graphs seem an intuitively natural way to model many situations in the Creation (connections of
wires/leads, logistics/transportation problems, pipelines between points with known capacities,
family trees, organizational charts, among many more). This suggests why graph theory has grown
so dramatically in the past century.

Definitions:

What is a Graph?
A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links.
The interconnected objects are represented by points termed as vertices, and the links that connect the
vertices are called edges.

Formally, a graph is a pair of sets (V, E), where V is the set of vertices and E is the set of edges, connecting the
pairs of vertices. Take a look at the following graph −

Graph Example
In the above graph,

V = {a, b, c, d, e}

E = {ab, ac, bd, cd, de}

A graph, G, comprises a set V of vertices and a set E of edges. The vertex set can be anything, but is
most commonly a collection of letters or numbers. The set of edges is a set of doubleton subsets of
V. That is E⊆{{a,b}:a,b∈V and a≠b}. We denote the graph by G(V,E).

If G(V,E) is a graph and {a,b}∈E, then we say vertices a and b are adjacent and the edge {a,b} joins
them or connects them or is incident on them. We call a and b the endpoints of the edge. Two edges
that share one vertex, such as {a,b} and {b,c} with a≠c, are adjacent to each other

9
CHAPTER II. GRAPH THEORY

Example 1:
Let V={a,b,c,d} and E={{a,b},{a,c},{b,c},{c,d}}

Example 2:
Let V={a,b,c,d} and E={{a,b},{a,c},{a,d},{b,c},{b,d},{c,d}}. This is called the complete graph
on four vertices, denoted K4.

Example 3:
Let V={a,b,c,d} and E=∅.

The degree of a vertex is the number of edges incident on the vertex. That is, if G(V,E) is a
graph and a∈V, then degree(a)=|{x:{a,x}∈E}|. Put another way, the degree of a vertex is
the number of vertices adjacent to it. If a vertex has no adjacent vertices (degree 0), then
it is isolated.

10
CHAPTER II. GRAPH THEORY

Point
A point is a particular position in a one-dimensional, two-dimensional, or three-dimensional space. For
better understanding, a point can be denoted by an alphabet. It can be represented with a dot.
Example

Line
A Line is a connection between two points. It can be represented with a solid line.
Example

Here, ‘a’ and ‘b’ are the points. The link between these two points is called a line.

Vertex
A vertex is a point where multiple lines meet. It is also called a node. Similar to points, a vertex is also
denoted by an alphabet.
Example

Here, the vertex is named with an alphabet ‘a’.

Pendent Vertex
By using degree of a vertex, we have a two special types of vertices. A vertex with degree one is called a
pendent vertex.
Example

Here, in this example, vertex ‘a’ and vertex ‘b’ have a connected edge ‘ab’. So with respect to the vertex ‘a’,
there is only one edge towards vertex ‘b’ and similarly with respect to the vertex ‘b’, there is only one edge
towards vertex ‘a’. Finally, vertex ‘a’ and vertex ‘b’ has degree as one which are also called as the pendent
vertex.
Isolated Vertex
A vertex with degree zero is called an isolated vertex.
Example

Edge
An edge is the mathematical term for a line that connects two vertices. Many edges can be formed from a
single vertex. Without a vertex, an edge cannot be formed. There must be a starting vertex and an ending
vertex for an edge.
Example

Here, ‘a’ and ‘b’ are the two vertices and the link between them is called an edge.

Graph
A graph ‘G’ is defined as G = (V, E) Where V is a set of all vertices and E is a set of all edges in the graph.
Example 1

11
CHAPTER II. GRAPH THEORY

In the above example, ab, ac, cd, and bd are the edges of the graph. Similarly, a, b, c, and d are the vertices
of the graph.
Example 2

In this graph, there are four vertices a, b, c, and d, and four edges ab, ac, ad, and cd.

Loop
In a graph, if an edge is drawn from vertex to itself, it is called a loop.
Example 1

In the above graph, V is a vertex for which it has an edge (V, V) forming a loop.
Example 2

In this graph, there are two loops which are formed at vertex a, and vertex b.

Graph Subgraph
A graph G′(V′,E′) is a subgraph of the graph G(V,E) if V′⊆V and E′⊆E. Note that this does
require G′(V′,E′) to be a graph, so one cannot form a subgraph of arbitrary subsets of V and
E. The second graph below is a subset of the first.

Graph Path
The notion of a path in a graph is intuitively clear but a little hard to pin down
formally. Suppose G(V,E) is a graph with vertices v0,v1,…,vk (not necessarily distinct) and
edges e1,e2,…,ek (not necessarily distinct) in which edge ei={vi-1,vi} for i=1,…,k. Then the
alternating sequence of vertices and edges v0e1v1e2v2…ekvk is a path from v0 to vk of
length k (note that the length is the number of edges, not vertices). Unless we work with
multigraphs the listing of the edges is redundant, so we may speak more simply of the path
as v0v1v2…vk. This definition allows for incredibly knotty, repetitious paths. If we want to
rule out that possibility, we can speak of simple paths, which are paths in which no vertices
(and thus no edges) are repeated.

12
CHAPTER II. GRAPH THEORY

Example: In the following diagram the red edges show a simple path of length three from
a to e. The path is acde. Of course this could also be the non-simple path acdcacacdede of
length 11

Graph Connectedness
Intuitively a graph is connected if it has no parts that are isolated from each other,
if you can get from each part to every other part. Formally we say a graph is connected if
there exists a path between every pair of distinct vertices. Clearly this is equivalent to
saying there is a simple path between every pair of distinct vertices. The graph just given
is connected, but the following one is not since you cannot, for instance, get from a to d.

13
CHAPTER II. GRAPH THEORY

Types of graphs
There are two kinds of graphs, directed and undirected.

UNDIRECTED GRAPH has no directed edges. Consider the following example.

DIRECTED GRAPH each vertex has an indegree and an outdegree.

Indegree of a Graph
 Indegree of vertex V is the number of edges which are coming into the vertex V.
 Notation − deg−(V).

Outdegree of a Graph
 Outdegree of vertex V is the number of edges which are going out from the vertex V.
 Notation − deg+(V).

Vertex Indegree Outdegree


A 1 1
B 2 0
C 1 1
D 1 1
E 0 2
Graph can also classify into two a weighted and unweighted graph wherein

14
CHAPTER II. GRAPH THEORY

Unweighted graph has no value in its edges


Example:

Weighted graph has a value in its edges


Example:

15
CHAPTER II. GRAPH THEORY

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about the GRAPH THEORY

Self check 2 for LO1, LO2, to LO4

IDENTIFICATION

1. ______________________ is a pictorial representation of a set of objects where


some pairs of objects are connected by links
2. ______________________ is a particular position in a one-dimensional, two-
dimensional, or three-dimensional space
3. ______________________ is a connection between two points. It can be
represented with a solid line.
4. ______________________ is a point where multiple lines meet. It is also called a
node
5. A vertex with degree one is called a ______________________.
6. vertex with degree zero is called an ______________________.
7. ______________________ is the mathematical term for a line that connects two
vertices
8. if an edge is drawn from vertex to itself, it is called a ______________________
9. ______________________ has no directed edges
10. ______________________each vertex has an indegree and an outdegree
11. ______________________V is the number of edges which are coming into the
vertex V.
12. ______________________V is the number of edges which are going out from the
vertex V.
13. ______________________ has no value in its edges

APPLICATION
Identify the indegree and outdegree of the graph

Vertex Indegree Outdegree

16
CHAPTER III. PROBLEM FORMULATION

CHAPTER III
PROBLEM FORMULATION
Learning Content:
 Properties of an problem formulation
o Initial State
o Final State
o List of Operator
o Valid Goal Test
o Shortest Path
o Longest Path

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe problem formulation
2. List problem formulation Properties
3. Identify the sets value based on the problem formulation properties

18
CHAPTER III. PROBLEM FORMULATION

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about PROBLEM FORMULATION

Pre-assessment 3 for LO1, LO2 and LO3

APPLICATION

Give the Problem Formulation Properties of the Graph below:

B D
* %

A F

& #
C E

 Initial state ______________________


 Final State ______________________
 Operators ______________________
 Goal test
 ______________________
 ______________________
 ______________________
 ______________________
 ______________________
 ______________________

 Shortest Path ______________________


 Longest Path ______________________

19
CHAPTER III. PROBLEM FORMULATION

INFORMATION SHEET
A solution is a sequence of operators leading from initial state to the goal state.

Properties of Problem
Formulation
Problem can be defined by the following item:
 Initial State : stating point; symbol is single circle of the
node
 Final State : end point; symbol is the double circle of the
node
 List of Operators : list of nodes, successor function
 Goal Test : It is a valid way from starting point up to the final state
 Shortest Path : it is the goal test w/ smaller number of nodes visited (unweighted graph)
: it is the goal test that when the sum of each line segment connecting node from
one node computed as smallest. lowest path cost(weighted graph)
 Longest Path: it is the goal test w/ got most number of nodes visited (unweighted graph)
: it is the goal test that when the sum of each line segment connecting node from
one node computed the largest among the goal test. Largest path cost (weighted
graph)
 Path Cost: If the given is a weighted graph, it is the totality of the line segment value from
the initial state to final state.
Example
Problem 1
 Travel from Arad to Bucharest (Weighted Graph)

Required:
 Initial state {Arad}
 Final State {Bucharest}
 Operators { Arad, Zerined, Oradea, Timisoana, Lugoj, Nethada, Dobreta,
Craiova, Siblui, Fagaras, Rimricu Vicea, Pitesti, Uziceni, Hirsova, Elorie,
Vaslul, Iasl, Neant, Bucharest}
 Goal test

20
CHAPTER III. PROBLEM FORMULATION

 {Arad, Timisoana, Lugoj, Nethada, Dobreta, Craiova,


Pitesti,Butcharest}
 { Arad, Zerined, Oradea, Siblui, Fagaras, Butcharest}
 {Arad, Siblui, Rimricu Vicea, Pitesti, Butcharest}
 Etc.
 Shortest Path {Arad, Sibliu, Fagaras, Bucharest}
 Longest Path {Arad, Timisoana, Lugoj, Nethada, Dobreta, Craiova, Pitesti,
Rimricu Vilcea, Sibliu, Fagaras, Bucharest}
Problem 2
 Travel from Arad to Bucharest (Unweighted Graph)

 Initial state {Arad}


 Final State {Bucharest}
 Operators { Arad, Zerined, Oradea, Timisoana, Lugoj, Nethada, Dobreta,
Craiova, Siblui, Fagaras, Rimricu Vicea, Pitesti, Uziceni, Hirsova, Elorie,
Vaslul, Iasl, Neant, Bucharest}
 Goal test
 {Arad, Timisoana, Lugoj, Nethada, Dobreta, Craiova,
Pitesti,Butcharest}
 { Arad, Zerined, Oradea, Siblui, Fagaras, Butcharest}
 {Arad, Siblui, Rimricu Vicea, Pitesti, Butcharest}
 Etc.
 Shortest Path
o {Arad, Timisoana, Lugoj, Nethada, Dobreta, Craiova, Pitesti,
Rimricu Vilcea, Sibliu, Fagaras, Bucharest}
o Path Cost : 1+1+2+2+1+1+2+1+2+1=14
 Longest Path
o {Arad, Sibliu, Rimricu Vilcea, Craiova, Pitesti, Bucharest}
o Path Cost : 15+1+5+1+8=30

21
CHAPTER III. PROBLEM FORMULATION

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about PROBLEM FORMULATION

Self-check 3 for LO1, LO2, to LO4

APPLICATION

Give the Problem Formulation Properties of the Graph below:

B D
* %

A F

& #
C E

 Initial state ______________________


 Final State ______________________
 Operators ______________________
 Goal test
 ______________________
 ______________________
 ______________________
 ______________________
 ______________________
 ______________________

 Shortest Path ______________________


 Longest Path ______________________

22
CHAPTER IV SETS

CHAPTER IV
SETS
Learning Content:
 The concept of Set Theory
 Representation of a set
 Types of sets
 Venn Diagram
 Set Operations
 Power Sets

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe a set
2. Identify and describe the different representations of a set
3. Describe Venn Diagram
4. Identify and describe the different types of sets
5. Identify and describe the different set operations
6. Identify the power set of the given sets

24
CHAPTER IV SETS

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about SETS

Pre-assessment 4 for LO1, LO2, to LO6

IDENTIFICATION

1. A _____________ is a collection of well defined objects.


2. The objects of a set are called _____________ or members of the set.
3. _____________ form is known as the descriptive form of specification.
4. _____________ form set is represented by listing all the elements comprising it.
5. _____________ is a notation for describing a set by indicating the properties that its
members must satisfy.
6. _____________ A set which contains a definite number of elements .
7. _____________ A set which contains infinite number of elements .
8. _____________can be defined as “subset of but not equal to”. A Set X is a proper subset
of set Y (Written as X ⊂ Y) if every element of X is an element of set Y and |X| < |Y|.
9. _____________It is a collection of all elements in a particular context or application. All
the sets in that context or application are essentially subsets of this universal set.
Universal sets are represented as U.
10. _____________ contains no elements. It is denoted by ∅. As the number of elements in
an empty set is finite, empty set is a finite set. The cardinality of empty set or null set is
zero.
11. _____________ contains only one element
12. _____________ If two sets contain the same elements they are said to be equal.
13. _____________ If the cardinalities of two sets are same
14. _____________Two sets that have at least one common element
15. _____________If two sets C and D are disjoint sets as they do not have even one element
in common.
16.
_____________

17. _____________

18. _____________

25
CHAPTER IV SETS

19. . _____________

APPLICATION

A. Simplify the given below using sets operations wherein:

U={1,2,3,4,5,…10} A={1,3,5…9} B={2,4,6…10} C ={3,5,7,9}

D={1,4,5,6,7,9} E={2,3,4,5,6,8,9}

1. (AUB) ∩ (A-E)
2. (E-D) ∩ (EUC)
3. D’
4. B-D’
5. (A∩C)’ – (D-E)’

B. Draw the Venn Diagram of the given set

U={A,B,C,D,E,F,G,H,I,J,K}

A={A,B,C,D}

B={A,G,H,J,K}

C={A,D,E,I,K}

C. Draw and shade the Venn Diagram of the given:


1. (A∩B)-(A∩C)
2. (C-B)U(A-C)
3. (AUB) ∩ (AUC)
4. [(CUA)∩ (B∩A)]’
5. C’

26
CHAPTER IV SETS

INFORMATION SHEET

The concept of Set Theory


Sets often deal with a group or a collection of objects, such as a
collection of books, a group of students, a list of states in a country,
a collection of coins, etc. Set may be considered as a mathematical
way of representing a collection or a group of objects.

A set is a collection of well defined objects. The objects of a set are


called elements or members of the set.

The main property of a set in mathematics is that it is well defined.


This means that given any object, it must be clear whether that
object is a member (element) of the set or not.

The objects of a set are all distinct, i.e., no two objects are the same.

Which of the following collections are well defined?

(1) The collection of male students in your class.

(2) The collection of numbers 2, 4, 6, 10 and 12.

(3) The collection of provinces in United States of America.

(4) The collection of all good movies.

(1), (2) and (3) are well defined and therefore they are sets. (4) is not well defined because the
word good is not defined. Therefore, (4) is not a set.

Generally, sets are named with the capital letters A, B, C, etc. The elements of a set are denoted
by the small letters a, b, c, etc.

Reading notation

If x is an element of the set A, we write x ∈ A.

If x is not an element of the set A, we write x ∉ A.

For example,

Consider the set A = { 1, 3, 5, 9 }

1 is an element of A, written as 1 ∈ A

27
CHAPTER IV SETS

3 is an element of A, written as 3 ∈ A
8 is not an element of A, written as 8 ∉ A

Apart from "Basic concepts of sets", let us come to know the other important stuff called
"Representation of a set".

Representation of a set

Sets can be represented in two ways −


 Descriptive form
 Roster or Tabular Form
 Set Builder Notation

Descriptive form

One way to specify a set is to give a verbal description of its elements.

This is known as the descriptive form of specification.

The description must allow a concise determination of which elements belong to the set and
which elements do not.

For example,

(i) The set of all natural numbers.

(ii) The set of all prime numbers less than 100.

(iii) The set of all letters in English alphabets.

Roster or Tabular Form


The set is represented by listing all the elements comprising it. The elements are enclosed
within braces and separated by commas.
 Example 1 − Set of vowels in English alphabet, A = {a,e,i,o,u}
 Example 2 − Set of odd numbers less than 10, B = {1,3,5,7,9}
Note:
 In roster form each element of the set must be listed exactly once. By convention, the
elements in a set should not be repeated.
 Let A be the set of letters in the word “coffee”,
That is, A = { c, o, f, e }. So, in roster form of the set A the following are invalid.
{ c, o, e } -------> (not all elements are listed)

{ c, o, f, f, e } -------> (element ‘f’ is listed twice)

28
CHAPTER IV SETS

 In a roster form the elements in a set can be written in any order.

The following are valid roster form of the set containing the elements 2, 3 and 4.

{ 2, 3, 4 }

{ 2, 4, 3 }

{4, 3, 2 }

Each of them represents the same set.

Set Builder Notation


The set is defined by specifying a property that elements of the set have in common. Set-builder
notation is a notation for describing a set by indicating the properties that its members must satisfy.
. The set is described as A = { x : p(x)}

Example 1 − The set {a,e,i,o,u} is written as − A = { x : x is a vowel in English


alphabet}

Example 2 − The set {1,3,5,7,9} is written as − B = { x : 1≤x<10 and (x%2) ≠ 0}

If an element x is a member of any set S, it is denoted by x ∈ S and if an


element y is not a member of set S, it is denoted by y ∉ S.

Example − If S = {1, 1.2, 1.7, 2}, 1 ∈ S but 1.5 ∉ S

Reading notation :

A = { x : x is a letter in the word "dictionary" }

We read it as

“A is the set of all x such that x is a letter in the word dictionary”

For example,

(i) N = { x : x is a natural number }

(ii) P = { x : x is a prime number less than 100 }

(iii) A = { x : x is a letter in the English alphabet }

29
CHAPTER IV SETS

Representation of sets in Different Forms

Some Important Sets


 N − the set of all natural numbers = {1, 2, 3, 4, .....}
 Z − the set of all integers = {....., −3, −2, −1, 0, 1, 2, 3, .....}
 Z+ − the set of all positive integers
 Q − the set of all rational numbers
 R − the set of all real numbers
 W − the set of all whole numbers
 If there are either infinitely many elements or a large finite number of elements,
then three consecutive dots called ellipsis are used to indicate that the pattern of
the listed elements continues, as in { 5, 6, 7,...... } or { 3, 6, 9, 12, 15,........60 }.
 Ellipsis can be used only if enough information has been given so that one can
figure out the entire pattern.

Cardinality of a Set
Cardinality of a set S, denoted by |S|, is the number of elements of the set. If a set has an
infinite number of elements, its cardinality is ∞.

Example − |{1, 4, 3, 5}| = 4, |{1, 2, 3, 4, 5,…}| = ∞

If there are two sets X and Y,


 |X| = |Y| represents two sets X and Y that have the same cardinality, if there
exists a bijective function ‘f’ from X to Y.
 |X| ≤ |Y| represents set X has cardinality less than or equal to the cardinality
of Y, if there exists an injective function ‘f’ from X to Y.
 |X| < |Y| represents set X has cardinality less than the cardinality of Y, if there
is an injective function f, but no bijective function ‘f’ from X to Y.
 If |X| ≤ |Y| and |X| ≤ |Y| then |X| = |Y|

30
CHAPTER IV SETS

Types of sets
Sets can be classified into many types. Some of which are finite, infinite, subset, universal,
proper, singleton set, etc.

Finite Set
A set which contains a definite number of elements is called a finite set.
Example − S = {x | x ∈ N and 70 > x > 50}

Infinite Set
A set which contains infinite number of elements is called an infinite set.
Example − S = {x | x ∈ N and x > 10}

Subset
A set Y is a subset of set X (Written as X ⊆ Y) if every element of X is an element of
set Y.
Example 1 − Let, X = { 1, 2, 3, 4, 5, 6 } and Y = { 1, 2 }. Here set X is a subset of set Y
as all the elements of set X is in set Y. Hence, we can write X ⊆ Y.
Example 2 − Let, X = {1, 2, 3} and Y = {1, 2, 3}. Here set X is a subset (Not a proper
subset) of set Y as all the elements of set X is in set Y. Hence, we can write X ⊆ Y.

Proper Subset
The term “proper subset” can be defined as “subset of but not equal to”. A Set X is
a proper subset of set Y (Written as X ⊂ Y) if every element of X is an element of set
Y and |X| < |Y|.
Example − Let, X = {1, 2, 3, 4, 5, 6} and Y = {1, 2}. Here set X is a proper subset of set
Y as at least one element is more in set Y. Hence, we can write X ⊂ Y.

Universal Set
It is a collection of all elements in a particular context or application. All the sets in
that context or application are essentially subsets of this universal set. Universal
sets are represented as U.
Example − We may define U as the set of all animals on earth. In this case, set of all
mammals is a subset of U, set of all fishes is a subset of U, set of all insects is a
subset of U, and so on.

Empty Set or Null Set


An empty set contains no elements. It is denoted by ∅. As the number of elements
in an empty set is finite, empty set is a finite set. The cardinality of empty set or null
set is zero.
Example − ∅ = {x | x ∈ N and 7 < x < 8}

Singleton Set or Unit Set


Singleton set or unit set contains only one element. A singleton set is denoted by
{s}.
Example − S = {x | x ∈ N, 7 < x < 9}

31
CHAPTER IV SETS

Equal Set
If two sets contain the same elements they are said to be equal.
Example − If A = {1, 2, 6} and B = {6, 1, 2}, they are equal as every element of set A
is an element of set B and every element of set B is an element of set A.

Equivalent Set
If the cardinalities of two sets are same, they are called equivalent sets.
Example − If A = {1, 2, 6} and B = {16, 17, 22}, they are equivalent as cardinality of
A is equal to the cardinality of B. i.e. |A| = |B| = 3

Overlapping Set
Two sets that have at least one common element are called overlapping sets.
In case of overlapping sets −
 n(A ∪ B) = n(A) + n(B) − n(A ∩ B)
 n(A ∪ B) = n(A − B) + n(B − A) + n(A ∩ B)
 n(A) = n(A − B) + n(A ∩ B)
 n(B) = n(B − A) + n(A ∩ B)
Example − Let, A = {1, 2, 6} and B = {6, 12, 42}. There is a common element ‘6’,
hence these sets are overlapping sets.

Disjoint Set
If two sets C and D are disjoint sets as they do not have even one element in
common. Therefore, n(A ∪ B) = n(A) + n(B)

Example − Let, A = {1, 2, 6} and B = {7, 9, 14}, there is no common element, hence
these sets are overlapping sets.

Venn Diagrams
Venn diagram, invented in 1880 by John Venn, is a schematic diagram that shows all
possible logical relations between different mathematical sets.

Examples

32
CHAPTER IV SETS

Set Operations
Set Operations include Set Union, Set Intersection, Set Difference, Complement of Set, and
Cartesian Product.

Set Union
The union of sets A and B (denoted by A ∪ B) is the set of elements which are in A,
in B, or in both A and B. Hence, A ∪ B = {x | x ∈ A OR x ∈ B}.

Example − If A = {10, 11, 12, 13} and B = {13, 14, 15},


then A ∪ B = {10, 11, 12, 13, 14, 15}.
(The common element occurs only once)

Set Intersection
The intersection of sets A and B (denoted by A ∩ B) is the set of elements which are
in both A and B. Hence, A ∩ B = {x | x ∈ A AND x ∈ B}.

Example − If A = {11, 12, 13} and B = {13, 14, 15},


then A ∩ B = {13}.

Set Difference/ Relative Complement


The set difference of sets A and B (denoted by A − B) is the set of elements which
are only in A but not in B. Hence, A − B = {x | x ∈ A AND x ∉ B}.

Example − If A = {10, 11, 12, 13} and B = {13, 14, 15},


then (A− B) = {10, 11, 12} and (B − A) = {14, 15}.
Here, we can see (A − B) ≠ (B − A)

Complement of a Set
The complement of a set A (denoted by A’) is the set of elements which are not in
set A.
Hence, A' = {x | x ∉ A}. More specifically, A'= (U − A) where U is a universal set which
contains all objects.

Example − If A = {x | x belongs to set of odd integers}


then A' = {y | y does not belong to set of odd integers}

Cartesian Product / Cross Product


The Cartesian product of n number of sets A1, A2 .....An, defined as A1 × A2 ×..... ×
An, are the ordered pair (x1, x2,....xn) where x1 ∈ A1, x2 ∈ A2, ...... xn ∈ An

Example − If we take two sets A = {a, b} and B = {1, 2},


 The Cartesian product of A and B is written as − A × B = {(a, 1), (a, 2), (b,
1), (b, 2)}
 The Cartesian product of B and A is written as − B × A = {(1, a), (1, b), (2,
a), (2, b)}

33
CHAPTER IV SETS

Power Set
Power set of a set S is the set of all subsets of S including the empty set. The cardinality of
a power set of a set S of cardinality n is 2n. Power set is denoted as P(S).

Example − For a set S = {a, b, c, d} let us calculate the subsets −


 Subsets with 0 elements − {∅} (the empty set)
 Subsets with 1 element − {a}, {b}, {c}, {d}
 Subsets with 2 elements − {a,b}, {a,c}, {a,d}, {b,c}, {b,d},{c,d}
 Subsets with 3 elements − {a,b,c},{a,b,d},{a,c,d},{b,c,d}
 Subsets with 4 elements − {a,b,c,d}

Hence, | P(S) | = 24 = 16. Note − The power set of an empty set is also an empty set | P
({∅}) | = 20 = 1

34
CHAPTER IV SETS

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about SETS

Pre-assessment 3 for LO1, LO2 and LO3

IDENTIFICATION

1. A _____________ is a collection of well defined objects.


2. The objects of a set are called _____________ or members of the set.
3. _____________ form is known as the descriptive form of specification.
4. _____________ form set is represented by listing all the elements comprising it.
5. _____________ is a notation for describing a set by indicating the properties that its
members must satisfy.
6. _____________ A set which contains a definite number of elements .
7. _____________ A set which contains infinite number of elements .
8. _____________can be defined as “subset of but not equal to”. A Set X is a proper subset
of set Y (Written as X ⊂ Y) if every element of X is an element of set Y and |X| < |Y|.
9. _____________It is a collection of all elements in a particular context or application. All
the sets in that context or application are essentially subsets of this universal set.
Universal sets are represented as U.
10. _____________ contains no elements. It is denoted by ∅. As the number of elements in
an empty set is finite, empty set is a finite set. The cardinality of empty set or null set is
zero.
11. _____________ contains only one element
12. _____________ If two sets contain the same elements they are said to be equal.
13. _____________ If the cardinalities of two sets are same
14. _____________Two sets that have at least one common element
15. _____________If two sets C and D are disjoint sets as they do not have even one element
in common.
16.
_____________

17. _____________

18. _____________

35
CHAPTER IV SETS

19. . _____________

APPLICATION

A. Simplify the given below using sets operations wherein:

U={1,2,3,4,5,…10} A={1,3,5…9} B={2,4,6…10} C ={3,5,7,9}

D={1,4,5,6,7,9} E={2,3,4,5,6,8,9}

1. (AUB) ∩ (A-E)
2. (E-D) ∩ (EUC)
3. D’
4. B-D’
5. (A∩C)’ – (D-E)’

B. Draw the Venn Diagram of the given set

U={A,B,C,D,E,F,G,H,I,J,K}

A={A,B,C,D}

B={A,G,H,J,K}

C={A,D,E,I,K}

C. Draw and shade the Venn Diagram of the given:


1. (A∩B)-(A∩C)

2. (C-B)U(A-C)

3. (AUB) ∩ (AUC)

4. [(CUA)∩ (B∩A)]’

5. C’

36
CHAPTER V. TREES

CHAPTER V
TREES
Learning Content:
 The concept of trees
 Properties of a Tree
 Types of Trees

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe a tree
2. List, describe and identify the different properties of a tree
3. List, describe and identify the different types of a tree

40
CHAPTER V. TREES

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about TREES

Pre-assessment 5 for LO1, LO2 and L03

ESSAY
What is tree

ENUMERATION
Enumerate and describe the types of tree

APPLICATION:

Root : _______________
Parent of q: _______________
Sibling of k : _______________
Children of i: _______________
Ancestor of k: _______________
Descendant of n: _______________
Internal Vertices: _______________
External Vertices: _______________
List of Leaves: _______________
Height of tree: _______________
Dept of tree: _______________
Size of tree: _______________

41
CHAPTER V. TREES

INFORMATION SHEET

The concept of trees


A tree is a collection of nodes.The collection is either empty OR it consists of a
distinguished node r, called a root and zero or more non-empty distinct
(sub)trees T1, … , Tk, each of whose root are connected by a directed edge from
r. Represents commonly found hierarchical structure
A tree is a connected graph with no cycles. A forest is a graph whose components
are trees. An example appears below. Trees come up in many contexts: tournament brackets, family
trees, organizational charts, and decision trees, being a few examples.

Rooted Trees
Sometimes it is useful to distinguish one vertex of a tree and call it the root of the tree. For instance
we might, for whatever reasons, take the tree above and declare the red vertex to be its root. In
that case we often redraw the tree to let it all “hang down” from the root (or invert this picture so
that it all “grows up” from the root, which suits the metaphor better)

Properties of a Tree
Root : it is the starting node of the tree
Parent: it is the above node of the present node
Sibling: it is the other node but with the same parent
Children: it is the node below the present node
Ancestor: it is the list of node from parent to the root
Descendant: it is the list of node from the present node to children up to the leaves
Internal Vertices: is a vertex that has parent and at least one child
External Vertices: list of nodes without parent or nodes without children

42
CHAPTER V. TREES

List of Leaves: list of nodes without children


Height of tree: the length of the longest path from a leaf to the root
Dept of tree: is the length of the path from it to the root
Size of tree: total number of nodes

Example:

Root : {1}
Parent of 7: {3}
Sibling of 5 :{4}
Children of 2 : {4,5}
Ancestor of 6 : {3,1}
Descendant of 1: {2,3,4,5,6,7}
Internal Vertices: {2,3}
External Vertices: {1,4,5,6,7}
List of Leaves: {4,5,6,7}
Height of tree: 3
Dept of tree: 2
Size of tree: 7

Types of Trees
A directed tree is a digraph whose underlying graph is a tree and which has no loops and no pairs
of vertices joined in both directions. These last two conditions mean that if we interpret a directed
tree as a relation, it is irreflexive and asymmetric. Here is an example.

43
CHAPTER V. TREES

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about TREES

Self Check 1 for LO1, LO2, to LO10

ESSAY
What is tree

ENUMERATION
Enumerate and describe the types of tree

APPLICATION:

Root : _______________
Parent of q: _______________
Sibling of k : _______________
Children of i: _______________
Ancestor of k: _______________
Descendant of n: _______________
Internal Vertices: _______________
External Vertices: _______________
List of Leaves: _______________
Height of tree: _______________
Dept of tree: _______________
Size of tree: _______________

44
CHAPTER VI. TREE TRAVERSAL

CHAPTER VI
TREE TRAVERSAL
Learning Content:
 The concept of graph traversal and graph traversal algorithms
 Evaluation of graph traversal algorithms
 Common types of graph traversal algorithm

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe graph traversal and graph traversal algorithm
2. List and describe the different criteria used in evaluating graph traversal algorithm
3. List and describe the common types of graph traversal algorithms
4. Differentiate the different traversal algorithms
5. Critique solutions using the different evaluation criteria

46
CHAPTER VI. TREE TRAVERSAL

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about TREE TRAVERSAL

Pre-assessment 6 for LO1, LO2 to L05

APPLICATION
Give the tree traversal of the tree below

B C

D E F

H I
G

47
CHAPTER VI. TREE TRAVERSAL

INFORMATION SHEET

The concept of graph traversal and


graph traversal algorithms
For an arbitrary graph and a starting node v, find all nodes
reachable from v (i.e., there exists a path)
Possibly "do something" for each node (print to output, set
some field, return from iterator, etc.)

Evaluation of graph
traversal algorithms
Basic Algorithm for Traversals:
1. Select a starting node
2. Make a set of nodes adjacent to current node
3. Visit each node in the set but "mark" each nodes after visiting them so you don't revisit
them (and eventually stop)
4. Repeat above but skip "marked nodes"

Three types of tree traversal


Pre-order : Root/parent first
In-order: Root/parent at the middle
Post Order: Root/Parent at the last node to visit
Example:

Pre-order:

In-order:

48
CHAPTER VI. TREE TRAVERSAL

Post-order:

Note: It is easy to perform the tree traversal by putting flag in each node

1st step : Place the flag wherein pre order is at the left side of the node, in order at the bottom of
the node and post order at the righ side of the node

Pre-order : a In-order: a Post Order: a

b c b c b c

2nd step : create a line connecting the flag from one node to another but make sure that the line of
the flag does not intersec the line segment of the tree.
Pre-order : In-order: Post Order:

3rd step: get the vertex based from the pattern of connecting the flag
Pre-order: {a,b,c} In-order {b,a,c} post order : {b,c,a}

49
CHAPTER VI. TREE TRAVERSAL

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about TREE TRAVERSAL

Self Check 6 for LO1, LO2, to LO5

APPLICATION
Give the tree traversal of the tree below

B C

D E F

H I
G

50
CHAPTER VII. HUFFMAN CODE

CHAPTER VII
HUFFMAN CODE
Learning Content
 The concept of HUFFMAN CODE
 Encrypt and Decrypt words using Huffman code

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe Huffman code
2. Encrypt word using Huffman code
3. Decrypt word using Huffman code

52
CHAPTER VII. HUFFMAN CODE

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about HUFFMAN CODE

Pre-assessment 7 for LO1, LO2 and L03

APPLICATION: Encrypt the word given using Huffman code

1. ISABELA
2. STATE
3. UNIVERSITY

53
CHAPTER VII. HUFFMAN CODE

INFORMATION SHEET

The concept of Huffman Code


Huffman coding assigns codes to characters such that the length of
the code depends on the relative frequency or weight of the corresponding
character. Huffman codes are of variable-length, and prefix-free (no code is
prefix of any other). Any prefix-free binary code can be visualized as a binary
tree with the encoded characters stored at the leaves.

Huffman coding tree or Huffman tree is a full binary tree in which


each leaf of the tree corresponds to a letter in the given alphabet.

Define the weighted path length of a leaf to be its weight times its depth. The Huffman tree
is the binary tree with minimum external path weight, i.e., the one with the minimum sum of
weighted path lengths for the given set of leaves. So the goal is to build a tree with the minimum
external path weight.

54
CHAPTER VII. HUFFMAN CODE

Encrypt and Decrypt words using Huffman code


Three problems:
Problem 1: Huffman tree building
Problem 2: Encoding
Problem 3: Decoding

Problem 2: Encoding
Encoding a string can be done by replacing each letter in the string with its binary code (the
Huffman code).

Examples:
DEED 10100101 (8 bits)
MUCK 111111001110111101 (18 bits)

Problem 3: Decoding
Decoding an encoded string can be done by looking at the bits in the coded string from left
to right until a letter decoded.
10100101 -> DEED

Problem 1: Huffman tree building


A simple algorithm:
1. Prepare a collection of n initial Huffman trees, each of which is a single leaf node. Put the n
trees onto a priority queue organized by weight (frequency).
2. Remove the first two trees (the ones with lowest weight). Join these two trees to create a
new tree whose root has the two trees as children, and whose weight is the sum of the
weights of the two children trees.
3. Put this new tree into the priority queue.
4. Repeat steps 2-3 until all of the partial Huffman trees have been combined into one.

It's a greedy algorithm: at each iteration, the algorithm makes a "greedy" decision to merge the
two subtrees with least weight. Does it give the desired result?

Lemma: Let x and y be the two least frequent characters. There is an optimal code tree in which
x and y are siblings whose depth is at least as any other leaf nodes in the tree.
Theorem: Huffman codes are optimal prefix-free binary codes (The greedy algorithm builds the
Huffman tree with the minimum external path weight for a given set of letters).

Note: Always remember that the left line of a tree is equivalent to zero and the right line segment
of a tree is equivalent to one.
In terms of decrypting letter equivalent in a Huffman code always, start writing at the root

55
CHAPTER VII. HUFFMAN CODE

Example1
On left tree t= 011 on the right tree letter t=001.
In terms of encrypting letter, remember to start the pattern of reading from the root down to the
letter equivalent.
Example2
On left tree 100=e on the right tree 10=e.

Example3

1. On the left tree the word rate is encoded


=r a t e
=001 000 011 100
=001 000 011 100

2. On the right tree, the same word rate is encoded


= r a t e
= 11 000 001 10
=11 000 001 10

56
CHAPTER VII. HUFFMAN CODE

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about HUFFMAN CODE

Self-Check 7 for LO1, LO2 and LO3

APPLICATION: Encrypt the word given using Huffman code

1. ISABELA
2. STATE
3. UNIVERSITY

57
CHAPTER VIII PROPOSITIONS

CHAPTER VIII
PROPOSITIONS
Learning Content:
 The concept of Propositional Logic
 Connectives
 Tautologies, Contradictions and Contingency
 Propositional Equivalences
 Inverse, Converse and Contra-positive

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe Propositional Logic
2. List and describe the different connectives
3. Recall, describe and identify tautology, contradiction and contingency
4. Recall, describe and identify inverse, converse and contra-positive formula

59
CHAPTER VIII PROPOSITIONS

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about PROPOSITIONS

Pre-assessment 8 for LO1, LO2 to L04

IDENTIFICATION:

I. Identify if the given sentence is a proposition or not. Write P if Propositions and NP


if not propositions

1. “Drilling for oil caused dinosaurs to become extinct.”


2. “Look out!”
3. How far is it to the next town?”
4. “x + 2 = 2x”
5. “x + 2 = 2x when x = −2”
6. All cows are brown.
7. The Earth is further from the sun than Venus.
8. There is life on Mars. Example 1.2.9. 2×2 = 5.
9. “Do you want to go to the movies?”
10. “Clean up your room.”
11. “2x = 2 + x.”
12. “This sentence is false.”

APPLICATION:
II. Draw the truth Table of the different propositional connectives
1. OR (∨)
2. AND (∧)
3. Negation/ NOT (¬)
4. Implication / if-then (→)
5. If and only if (⇔).

III. Create a truth table of the given then identify if the given is Tautologies,
Contradictions and Contingency.

¬ ((A^B)→(AvB))

60
CHAPTER VIII PROPOSITIONS

INFORMATION SHEET

The concept of Propositional Logic


The rules of mathematical logic specify methods of reasoning mathematical
statements.
Greek philosopher, Aristotle, was the pioneer of logical reasoning.
Logical reasoning provides the theoretical base for many areas of mathematics
and consequently computer science. It has many practical applications in
computer science like design of computing machines, artificial intelligence,
definition of data structures for programming languages etc.

The Two Elements of Symbolic Logic: Propositions


A proposition is a statement with a truth value. That is, it is a statement that is true or else a
statement that is false. Here are some examples with their truth values.

Examples:
 Municipality of Echague is municipality celebrating Mengal Festival. (true)
 The main campus of the Isabela State University is in Santiago City. (false)
 Homer was the blind poet who composed the Illiad and the Odyssey. (The statement is
certainly true or false, but we may not know which. Tradition asserts the truth of this
proposition, but some scholars doubt its truth).
 Jesus of Nazareth was God incarnate. (Again the statement is certainly true or false, even
though many people stand on both sides of the question.)
 It will rain in Echague tomorrow. (We cannot know the truth of this statement today, but
it is certainly either true or false.)
 1+1=2(true)
 2+2=10 (false)
 There are only finitely many prime numbers. (false)
 Every positive even integer greater than 2 can be written as the sum of two prime
numbers. (This is certainly true or false, but no one knows which. The proposition is
known as Goldbach’s Conjecture. It holds for every integer yet tested – e.g, 4=2+2, 6=3+3,
8=3+5 – but no one has found a proof that it holds for all even integers greater than two.)
Note: On the other hand, here are some examples of expressions that are not propositions.

 Where is Alba Hall? (This is neither true nor false. It is a question.)


 Find Alba Hall! (This is neither true nor false. It is a command.)
 Green is the best color to paint a house. (This is a matter of opinion, not truth. It may
be your favorite color, but it is not objective truth.)
 Milktea tastes better than coffee. (Again, this is a matter of taste, not truth.)
 The integer n is even. (Since n has no value, this statement is neither true nor false. If
n is given a value, this statement becomes a proposition. Later we will call such
statements predicates or propositional functions. They are not propositions, but they
become propositions when their variables are assigned values.)

Logical Operators

Arithmetic operators (operations) such as addition, subtraction, multiplication, division, and


negation act on numbers to give new numbers.

61
CHAPTER VIII PROPOSITIONS

Logical operators such conjunction (and), disjunction (or), and negation (not) act on propositions
to give new (compound) propositions. Logical operators should be truth functional; that is, the
truth value of the compound proposition should depend only on the truth value of the component
propositions. This makes it easy to specify the effect of a logical operator: we simply list the truth
value of the compound proposition for every combination of truth values of the component
compositions. Such a list is a called a truth table. Note that no such definition of arithmetic
operations is possible because there are infinitely many possible values of numbers.

Propositional Logic is concerned with statements to which the truth values, “true” and “false”, can
be assigned. The purpose is to analyze these statements either individually or in a composite
manner.

• Some examples of Propositions are given below −


 "Man is Mortal", it returns truth value “TRUE”
 "12 + 9 = 3 – 2", it returns truth value “FALSE”
• The following is not a Proposition −
 "A is less than 2". It is because unless we give a specific value of A, we cannot say
whether the statement is true or false.

Connectives
In propositional logic generally we use five connectives which are
• OR (∨)
• AND (∧)
• Negation/ NOT (¬)
• Implication / if-then (→)
• If and only if (⇔).

a) OR (∨) − The OR operation of two propositions A and B (written as A∨BA∨B) is true if at


least any of the propositional variable A or B is true.
The truth table is as follows –

62
CHAPTER VIII PROPOSITIONS

b) AND (∧) − The AND operation of two propositions A and B (written as A∧B) is true if both
the propositional variable A and B is true.
The truth table is as follows −

c) Negation (¬) − The negation of a proposition A (written as ¬A) is false when A is true and is
true when A is false.
The truth table is as follows −

d) Implication / if-then (→) − An implication A→B is the proposition “if A, then B”. It is false if
A is true and B is false. The rest cases are true.
The truth table is as follows −

e) If and only if (⇔) − A⇔B is bi-conditional logical connective which is true when p and q
are same, i.e. both are false or both are true.

63
CHAPTER VIII PROPOSITIONS

The truth table is as follows −

Tautologies, Contradictions and Contingency


Tautology
A Tautology is a formula which is always true for every value of its propositional variables.
A compound proposition that is always true, regardless of the truth values of the individual
propositions involved, is called a tautology.

Example − Prove [(A→B)∧A]→B[(A→B)∧A]→B is a tautology


The truth table is as follows −

Every value of [(A→B)∧A]→B[(A→B)∧A]→B is "True", it is a tautology.

Contradiction
A Contradiction is a formula which is always false for every value of its propositional variables.
A compound proposition that is always false, regardless of the truth values of the individual
propositions involved, is called a contradiction.

Example − Prove (A∨B)∧[(¬A)∧(¬B)] is a contradiction


The truth table is as follows –

64
CHAPTER VIII PROPOSITIONS

Every value of (A∨B)∧[(¬A)∧(¬B)] is “False”, it is a contradiction.

Contingency
A Contingency is a formula which has both some true and some false values for every value of its
propositional variables.
A compound statement that is neither a tautology nor a contradiction is called a contingency.
Example − Prove (A∨B)∧(¬A) a contingency
The truth table is as follows −

Every value of (A∨B)∧(¬A) has both “True” and “False”, it is a contingency

Propositional Equivalences
Logical equivalence We call two algebraic expressions equal if they have the same value for each
possible value of the input variables. For example, we say
𝑥2 − 1 = (𝑥 + 1)(𝑥 − 1)
because for all real numbers 𝑥, the left side and the right side have the same value.
Correspondingly, we should call two compound statements 𝑝 and 𝑞 “equal” if they always share the
same truth value. However, the convention is to call them logically equivalent instead, and to use
the symbol ≡ to represent logical equivalence.
Using the biconditional and the concept of a tautology that we just introduced, we can formally
define logical equivalence as follows:
𝑝 ≡ 𝑞 means that 𝑝 ↔ 𝑞 is a tautology.
An alternative definition is that 𝑝 ≡ 𝑞 means that 𝑝 and 𝑞 share the same truth table.

“Equivalent” vs “Equal” Do not use the words “equivalent” and “equal” interchangeably .
Equivalence applies to statements. Two quantities that are the same are equal. If you fail to keep
this distinction in mind when dealing with statements that are about quantities, you are in danger
of making wholly nonsensical statements.
For example, the inequality 2 < x < 3 is equivalent to 4 < 2x < 6. They always share the same truth
value, no matter what value is inserted for x. However, if you connect them with an equal sign, then

65
CHAPTER VIII PROPOSITIONS

you are making a totally different statement because the equal sign connects quantities, not
statements.
The notation
2 < x < 3 = 4 < 2x < 6
does NOT mean that 2 < x < 3 is equivalent to 4 < 2x < 6. Rather, it is the false statement 2 < x and x
< 3 and 3 = 4 and 4 < 2x and 2x < 6.
Notice why this statement has to be false: 3 is not 4.
An important logical equivalence

When we introduced the conditional, we discussed the idea that the conditional should not only be
true when the conclusion is true, but also when the premise is false. This explains the equivalence
above. A more formal justification can be given using a truth table:
Here is an example application of this law: saying “if I get elected, I will lower unemployment” is
equivalent to saying “I won’t get elected, or I will lower unemployment.”

Unlike other important logical equivalences, 𝑝 → 𝑞 ≡ ¬𝑝 ∨ 𝑞 does not have a commonly agreed upon
name. Technically, we could consider this law the definition of the conditional, so we will refer to it
by that name

Informally, what we mean by “equivalent” should be obvious: equivalent propositions are the same.
But we need to be a little more careful about definitions. Propositions p and q are logically
equivalent if p↔q is a tautology. We will write p≡q for an equivalence. (Some people also write
p⇔q.)
The only way we have so far to prove that two propositions are equivalent is a truth table.
We used truth tables to show that ⊕ and → propositions are equivalent to others written using
only ∨, ∧, and ¬. We can establish some more basic equivalences this way. … and use those to show
things are equivalent in a nicer way. Some equivalences important enough to have names:

The Laws of De Morgan


The two laws of De Morgan explain how negation interacts with conjunction and disjunction. We
will illustrate the principle with an example first:
It is not true that Joe is rich and famous.
This does not mean that Joe is neither rich nor famous. An and statement is true if both
individual statements are true; so if the and statement is false, it means that at least one of the two
statements is false. Therefore, the statement above is logically equivalent to
Joe is not rich or Joe is not famous (perhaps neither).

66
CHAPTER VIII PROPOSITIONS

We conclude that the negation of a conjunction must be the disjunction of the negations.
There is also a symmetric law of De Morgan which is obtained by switching the roles of conjunction
and disjunction. Both laws can be formally proved by truth table.

Negation of Conditionals
When we negate conditionals, we must not jump to tempting conclusions. The negation of
→ 𝑞 is not 𝑞 → 𝑝, nor is it ¬𝑝 → 𝑞, 𝑝 → ¬𝑞,¬𝑝 → ¬𝑞, or any other conditional involving 𝑝 or its
negation on one side, and 𝑞 or its negation on the other side.
You can see that by comparing the truth tables, or you can just reason that any conditional
of the form described is true for 3 out of the 4 rows, whereas ¬ 𝑝 → 𝑞 is only true for 1 out of the 4
rows.
To negate a conditional, we must rewrite it using disjunction and negation, and then carefully apply
De Morgan.

De Morgan and Double Inequalities


The laws of de Morgan explain how to properly negate a double inequality. In the previous
presentation, we stated that the correct negation of 1 ≤ 𝑥 ≤ 2 is
𝑥<1∨𝑥>2
To understand this, consider that the original double inequality is a conjunction of two
inequalities:
1 ≤ 𝑥 ≤ 2 ≡ 1 ≤ 𝑥 ∧ 𝑥 ≤ 2.
Thereby, by De Morgan, the negation is the disjunction of the individual inequalities, which
leads to 𝑥 < 1 ∨ 𝑥 > 2.

67
CHAPTER VIII PROPOSITIONS

Other Logical Equivalences involving conjunction, disjunction and negation

Proving Logical Equivalences


All the logical equivalences on the previous slide can be formally justified by truth table. This is a
tedious exercise and provides little true insight. We shall give an example of a perhaps more
meaningful explanation for one of the absorption laws:
𝑝∧𝑝∨𝑞≡𝑝
The ∨ 𝑞 inside the parentheses has no effect if 𝑝 is true already. It can only upgrade a false 𝑝 to true,
but then the conjunction with 𝑝 reverts that back to false. Therefore, the left side always has the
same truth value as 𝑝.

Simplifying compound statements using logical equivalences


Just like we can use the algebraic laws of numbers to simplify algebraic expressions, we can use the
logical equivalences just discussed to rewrite compound statements as equivalent (and hopefully,
simpler) compound statements. This helps us understand compound statements, and to identify
tautologies and contradictions. The next several slides present examples of such simplifications.

Example 1
Show 𝑝 → 𝑞 ∧ 𝑝 → 𝑟 ≡ 𝑝 → 𝑞 ∧ 𝑟
We will rewrite the left side using logical equivalences until we have transformed it into the right
side.

68
CHAPTER VIII PROPOSITIONS

Example 2
Show 𝑝 → 𝑞 → 𝑝 ≡ 𝑝
Again we rewrite the left side using logical equivalences until we get the right side.

Aren't truth tables easier?


For equivalences with only two propositions, probably. Maybe for three. For more complex
equivalences, you have abandon truth tables and start thinking.

Inverse, Converse and Contra-positive


a) Converse
The converse is created by switching the hypothesis and conclusion, and as you can see, it
changes the logic of the sentence. Even though the logical converse of our original
statement contains the same words, it does not necessarily contain the same truth value or
logical content.
The converse of a conditional statement switches the order of the hypothesis and the
conclusion.

b) Inverse
The next way we can test for logical equivalences is to find the logical inverse of the
conditional statement. The inverse is the negative form of the conditional in which both
hypothesis and conclusion are negated.
The inverse of a conditional negates both the hypothesis and the conclusion.

c) The logical Contrapositive of a conditional statement is reated by negating the hypothesis


and conclusion , then switching them.
The contrapositive of a conditional statement switches the hypothesis with the conclusion
and negates both parts.

Now we can define the converse, the contrapositive and the inverse of a conditional statement.
We start with the conditional statement “If P then Q.”
Example:

69
CHAPTER VIII PROPOSITIONS

We will see how these statements work with an example. Suppose we start with the conditional
statement “If it rained last night, then the sidewalk is wet.”

 The converse of the conditional statement is “If the sidewalk is wet, then it rained last
night.”
 The contrapositive of the conditional statement is “If the sidewalk is not wet, then it did not
rain last night.”
 The inverse of the conditional statement is “If it did not rain last night, then the sidewalk is
not wet.”

Those two statements are logical equivalences - they contain the same logical content. This is how
we construct logical equivalences. We create a:
Sentence: If I were sitting on my floor, then I would be at home.
Hypothesis: If I were sitting on my floor
Conclusion: I'd would be in my home
 Converse
If I were at home, I would be sitting on my floor.
 Inverse
If I were not sitting on my floor, then I would not be at home.
 Contrapositive
If I were not in my home, I would not be sitting on my floor

Example
Original Conditional: P→Q= If it is raining, then the driveway is wet.
P=It is raining.
Q=The driveway is wet.

70
CHAPTER VIII PROPOSITIONS

 Converse
Q→P= If the driveway is wet, then it is raining.

 Inverse
∼P→ ∼Q= If it is not raining, then the driveway is not wet.

 Contrapositive
∼Q→ ∼P= If the driveway is not wet, then it is not raining.

71
CHAPTER VIII PROPOSITIONS

Logical Equivalence of Conditionals


It is an important fact that a conditional is logically equivalent to its contrapositive, but not to its
inverse or converse. We can prove this by truth table or by using the logical equivalences we just
studied.
𝑝 → 𝑞 ≡ ¬𝑞 → ¬𝑝
Since the inverse is the contrapositive of the converse, inverse and converse are logically equivalent
to each other:
𝑞 → 𝑝 ≡ ¬𝑝 → ¬𝑞

An Example Involving The Biconditional


We defined the biconditional p ↔ 𝑞 as (𝑝 → 𝑞) ∧ (𝑞 → 𝑝) We shall explore a consequence of that
definition. Rewriting the conditionals as disjunctions and then using the distributive law, we get
(𝑝 → 𝑞) ∧ (𝑞 → 𝑝) ≡ (¬𝑝 ∨ 𝑞) ∧ (¬𝑞 ∨ 𝑝) ≡ (¬𝑝 ∧ ¬𝑞) ∨ (¬𝑝 ∧ 𝑝) ∨ (𝑞 ∧ ¬𝑞) ∨ (𝑞 ∧ 𝑝) ≡ (¬𝑝 ∧ ¬𝑞) ∨ (𝑞 ∧
𝑝) This confirms what we already learned from the truth table: that p ↔ 𝑞 is true if either both p
and q are true or both p and q are false.

72
CHAPTER VIII PROPOSITIONS

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about PROPOSITIONS

Self Check 8 for LO1, LO2 to LO4

IDENTIFICATION:

I. Identify if the given sentence is a proposition or not. Write P if Propositions and NP


if not propositions

1. “Drilling for oil caused dinosaurs to become extinct.”


2. “Look out!”
3. How far is it to the next town?”
4. “x + 2 = 2x”
5. “x + 2 = 2x when x = −2”
6. All cows are brown.
7. The Earth is further from the sun than Venus.
8. There is life on Mars. Example 1.2.9. 2×2 = 5.
9. “Do you want to go to the movies?”
10. “Clean up your room.”
11. “2x = 2 + x.”
12. “This sentence is false.”

APPLICATION:
II. Draw the truth Table of the different propositional connectives
1. OR (∨)
2. AND (∧)
3. Negation/ NOT (¬)
4. Implication / if-then (→)
5. If and only if (⇔).

III. Create a truth table of the given then identify if the given is Tautologies,
Contradictions and Contingency.

¬ ((A^B)→(AvB))

IV. Create the Inverse, Converse and Contra-positive statement of the given.
1. If two angles are congruent, then they have the same measure.
2. If a quadrilateral is a rectangle, then it has two pairs of parallel sides.

73
CHAPTER IX. PREDICATE LOGIC

CHAPTER IX
PREICATE LOGIC
Learning Content:
 The concept of predicate logic
 Propositional Functions
 Quantifiers
 Translating English to Predicate Logic

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe predicate logic
2. List, describe and identify the different symbols used in an expression
3. List, describe and identify the different quantifiers used in predicate logic
4. Recall and describe English to Predicate Logic translation

77
CHAPTER IX. PREDICATE LOGIC

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about PREDICATE LOGIC

Pre-assessment 7 for LO1, LO2 ,LO3 and L04

APPLICATION: Translate the given statement to predicate logic

Statement Predicate Logic


1. All A's are B's
2. No A's are B's
3. Some A's are B's
4. Some A's are not B's
5. All and only A's are B's
6. Only A's are B's
7. Not all A's are B's
8. All A's are not B's

78
CHAPTER IX. PREDICATE LOGIC

INFORMATION SHEET

The concept of predicate logic


Predicate logic is an extension of propositional logic that
permits concisely reasoning about whole classes of entities.
E.g., “x>1”, “x+y=10”
Such statements are neither true or false when the values of
the variables are not specified.

Predicate logic
 It is the formal notation for writing perfectly clear, concise, and unambiguous
mathematical definitions, axioms, and theorems for any branch of mathematics.
 Supported by some of the more sophisticated database query engines.
 Basis for automatic theorem provers and many other Artificial Intelligence systems

Subjects and Predicate

The proposition
“The dog is sleeping”

has two parts:


“the dog” denotes the subject - the object or entity that the sentence is about.
“is sleeping” denotes the predicate- a property that the subject can have.

Propositional Functions
A predicate is modeled as a function P(·) from objects to propositions.
P(x) = “x is sleeping” (where x is any object).

The result of applying a predicate P to an object x=a is the proposition P(a).


e.g. if P(x) = “x > 1”,
then P(3) is the proposition “3 is greater than 1.”

Note: The predicate P itself (e.g. P=“is sleeping”) is not a proposition (not a complete sentence).

Predicate logic includes propositional functions of any number of arguments.


e.g. let P(x,y,z) = “x gave y the grade z”,
x=“Mike”, y=“Mary”, z=“A”,
P(x,y,z) = “Mike gave Mary the grade A.”

Universe of Discourse

79
CHAPTER IX. PREDICATE LOGIC

The collection of values that a variable x can take is called x’s universe of discourse.
e.g., let P(x)=“x+1>x”.
we could define the course of universe as the set of integers.

Example

Let P(x) be the predicate “x is full.”


Let the u.d. of x be parking spaces at UNR.
The universal quantification of P(x),
x P(x), is the proposition:
• “All parking spaces at SM Store are full.” or
• “Every parking space at SM Store is full.” or
• “For each parking space at SM Store, that space is full.”

To prove that a statement of the form


x P(x) is false, it suffices to find a counterexample (i.e., one value of x in the universe of
discourse such that P(x) is false)
• e.g., P(x) is the predicate “x>0”

Quantifier Expressions
Quantifiers allow us to quantify (count) how many objects in the universe of discourse satisfy a
given predicate:
- “” is the FORLL or universal quantifier.
x P(x) means for all x in the u.d., P holds.
- “” is the XISTS or existential quantifier.
x P(x) means there exists an x in the u.d. (that is, one or more) such that P(x) is true.

Universal Quantifier : Example

Let P(x) be the predicate “x is full.”


Let the u.d. of x be parking spaces at UNR.
The universal quantification of P(x),
x P(x), is the proposition:
• “All parking spaces at SM Store are full.” or
• “Every parking space at SM Store is full.” or
• “For each parking space at SM Store, that space is full.”

To prove that a statement of the form


x P(x) is false, it suffices to find a counterexample (i.e., one value of x in the universe of
discourse such that P(x) is false)
• e.g., P(x) is the predicate “x>0”

Existential Quantifier  Example

• Let P(x) be the predicate “x is full.”


• Let the u.d. of x be parking spaces at UNR.

80
CHAPTER IX. PREDICATE LOGIC

• The universal quantification of P(x),


x P(x), is the proposition:
• “Some parking space at UNR is full.” or
• “There is a parking space at UNR that is full.” or
• “At least one parking space at UNR is full.”

Translating English into Predicate Logic


Why do we need functions?
Translate the sentence. “every child is younger than their mother.”
1. The domain is the set of people.
𝐶ℎ𝑖𝑙𝑑(𝑥)means𝑥is a child.
𝐼𝑠𝑀𝑜𝑡ℎ(𝑥,𝑦)means𝑥is𝑦’s mother.
𝐼𝑠𝑌𝑜𝑢(𝑥,𝑦)means𝑥is younger than𝑦.
2. Use the same set of definitions above and the function𝑚𝑜𝑡ℎ𝑒𝑟(𝑥)which returns𝑥’s
mother.

Using functions allows us to avoid ugly/inelegant predicate formulas. Try translating the following
sentence with and without functions. “Andy and Paul have the same maternal grandmother.”

A Summary of Translation Idioms

 Every/All/Each/Any
∀𝑥
 Some/At least one/There exists a/There is a
∃𝑥
 None/No x
¬(∃𝑥…)
 Not every/Not all
¬(∀𝑥…)
 Every P-ish x has property Q
∀𝑥𝑃(𝑥)→𝑄(𝑥)
 Some P-ish x has property Q
∃𝑥𝑃(𝑥)∧𝑄(𝑥)

81
CHAPTER IX. PREDICATE LOGIC

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about PREDICATE LOGIC

Self Check 7 for LO1, LO2,LO3 and LO4

APPLICATION: Translate the given statement to predicate logic

Statement Predicate Logic


9. All A's are B's
10. No A's are B's
11. Some A's are B's
12. Some A's are not B's
13. All and only A's are B's
14. Only A's are B's
15. Not all A's are B's
16. All A's are not B's

82
CHAPTER X. INFERENCE

CHAPTER 10
CHAPTER X
INFERENCE.docx

INFERENCE
Learning Content:
 Concept of inference
 Rules of inference

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
1. Recall and describe inference
2. List and describe the different rules of inference
3. Infer from given statements and Identify the rule used

84
CHAPTER X. INFERENCE

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about INFERENCE

Pre-assessment 10 for LO1, LO2 and L03

APPLICATION
I. Fill-up the table Below

No. Interference Tautotology


1 P -> P v Q

2 P^Q->P^Q

3 (P ^ Q) -> P

4 P→Q
__P__
∴Q
5 P→Q
__¬Q__
∴ ¬P
6 ¬P
_P ∨ Q_
∴Q
7 P→Q
_Q → R_
∴P→R
8 ((P -> Q) ^ (R -> S))^(P v R) -> Q v S
9 (P → Q ) ∧ (R → S)
___¬Q ∨ ¬S___
∴P∨R

II. Give the Interference and the tautology of the given sentence.

No. Variable Sentence Inference Tautology


“If it is snowing, then I will study
Let p be “It is discrete math.”
snowing.” “It is snowing.”
1.. Let q be “I will study
discrete math.” “ Therefore , I will study discrete
math. ”

85
CHAPTER X. INFERENCE

Let p be “I will study “If I will study discrete math, then I


discrete math.” will study computer science.”
Let q be “I will study “If I will study protein structures,
computer science.” then I will study biochemistry.”
Let r be “I will study “I will not study computer science
2.
protein structures.” or I will not study biochemistry.”
Let s be “I will study
biochemistry.” “ Therefore, I will not study discrete
math or I will not study protein
structures. ”
Let p be “I will study “If I will study discrete math, then I
discrete math.” will study Computer Science.”
Let q be “I will study “If I will study databases, then I will
Computer Science.” study Computer Science.”
3. Let r be “I will study “I will study discrete math or I will
databases.” study databases.”

“ Therefore, I will study Computer


Science. ”

86
CHAPTER X. INFERENCE

INFORMATION SHEET

The Concept of inference


Every Theorem in Mathematics, or any subject for that matter,
is supported by underlying proofs. These proofs are nothing
but a set of arguments that are conclusive evidence of the
validity of the theory.
The arguments are chained together using Rules of Inferences
to deduce new statements and ultimately prove that the
theorem is valid.

Important Definitions :
1. Argument – A sequence of statements, premises, that end with a conclusion.
2. Validity – A deductive argument is said to be valid if and only if it takes a form that makes it
impossible for the premises to be true and the conclusion nevertheless to be false.
3. Fallacy – An incorrect reasoning or mistake which leads to invalid arguments.

Our Old Example:


 Suppose we have:
“All human beings are mortal”
“Catleen is a human being.”
 Does it follow that “ Catleen is mortal?”

Solution:
• Let H(x): “x is a human being.”
• Let M(x): “x is mortal.”
• The domain of discourse U is all human beings.
• “All human beings are mortal.” translates to Ɐx (H(x) → M(x))
“Catleen is a human being.” translates to H(Catleen)
• Therefore, for H(Catleen) → M(Catleen) to be true it must be the case that M(Catleen).

Arguments in Propositional Logic


 A argument in propositional logic is a sequence of propositions.
 All but the final proposition are called premises. The last statement is the conclusion.
 The argument is valid if the premises imply the conclusion.
 An argument form is an argument that is valid no matter what propositions are
substituted into its propositional variables.
 If the premises are p 1 , p 2, …, p n and the conclusion is q then (p1 ∧p2∧
… ∧ p n ) → q is a tautology.
 Inference rules are all argument simple argument forms that will be used to construct
more complex argument forms.

Simple arguments can be used as building blocks to construct more complicated valid arguments.
Certain simple arguments that have been established as valid are very important in terms of their
usage. These arguments are called Rules of Inference.

87
CHAPTER X. INFERENCE

Rules of inference
The most commonly used Rules of Inference are tabulated below –

 Modus Ponens or Law of Detachment (Modus Ponens = mode that affirms)


Corresponding Tautology: Truth Table
(p ^ (p→q)) →q
p q p→q
T T T
Example: T F F
Let p be “It is snowing.” F T T
Let q be “I will study discrete math.” F F T

“If it is snowing, then I will study discrete math.”


“It is snowing.”

“Therefore , I will study discrete math.”

88
CHAPTER X. INFERENCE

 Modus Tollens ( Denying the Consequent)

Corresponding Tautology: Truth Table


(¬ q ∧( p → q ))→¬ p
p q p→q
T T T
T F F
Example: F T T
Let p be “it is snowing.” F F T
Let q be “I will study discrete math.”

“If it is snowing, then I will study discrete math.”


“I will not study discrete math.”

“Therefore , it is not snowing.”

 Hypothetical Syllogism ( Transitivity of Implication or Chain Argument)

Corresponding Tautology: Example:


Let p be “it snows.”
((p → q ) ∧ (q→ r ))→( p → r ) Let q be “I will study discrete math.”
Let r be “I will get an A.”

“If it snows, then I will study discrete math.” “If I study


discrete math, I will get an A.”

“Therefore , If it snows, I will get an A.”

 Disjunctive Syllogism (Disjunction Elimination or OR Elimination)

Corresponding Tautology: Example:


Let p be “I will study discrete math.”
((p v q ) ∧ ¬p) →q
Let q be “I will study English literature.”

“I will study discrete math or I will study English literature.”

“I will not study discrete math.”

“Therefore , I will study English literature.”

89
CHAPTER X. INFERENCE

 Addition (Disjunction Introduction)

Example:
Corresponding Tautology: Let p be “I will study discrete math.”

p→ (p→ q) Let q be “I will visit Las Vegas.”

“I will study discrete math.”

“Therefore, I will study discrete math or I will visit Las


Vegas.”

 Simplification (Conjunction Elimination)

Corresponding Tautology: Example:


Let p be “I will study discrete math.”
( p^q )→ p
Let q be “I will study English literature.”

“I will study discrete math and English literature”

“Therefore, I will study discrete math.”

 Conjunction (Conjunction Introduction)

Example:
Corresponding Tautology:
Let p be “I will study discrete math.”
(( p )^(q)) →(p^q)) Let q be “I will study English literature.”

“I will study discrete math.”


∧ ( q )) →( p ∧ q
“I will study English literature.”

“Therefore, I will study discrete math and I will study English


literature.”

90
CHAPTER X. INFERENCE

 Resolution
Resolution plays an important role in Artificial Intelligence and is used in the programming
language Prolog.

Corresponding Tautology:

((pvq)^( ¬pvr)) →(qvr)

Example:
Let p be “I will study
∧ ( q discrete
)) →( p ∧math.”
q
Let q be “I will study databases.”
Let r be “I will study English literature.”

“I will study discrete math or I will study databases.”


“I will not study discrete math or I will study English
literature.”

“Therefore, I will study databases or I will English literature.”

 Proof by Cases (Disjunction Elimination)_

Corresponding Tautology:

((p→q)^(r→q)^(pvr)) →q

Example:
Let p be “I will study discrete math.”
Let q be “I will study Computer Science.”
Let r be “I will study databases.”

“If I will study discrete math, then I will study Computer


Science.”
“If I will study databases, then I will study Computer Science.”
“I will study discrete math or I will study databases.”

“Therefore, I will study Computer Science.”

 Constructive Dilemma ( Disjunction of modus ponens)


Corresponding Tautology:

((p→q)^(r→s)^(pvr)) →(qvs)

Example:
Let p be “I will study discrete math.”
Let q be “I will study computer science.”
Let r be “I will study protein structures.”
Let s be “I will study biochemistry.”

“If I will study discrete math, then I will study computer science.”
“If I will study protein structures, then I will study biochemistry.”
“I will study discrete math or I will study protein structures.” 91

“Therefore, I will study computer science or biochemistry.”


CHAPTER X. INFERENCE

 Destructive Dilemma ( Disjunction of modus tollens)


Corresponding Tautology:

((p→q)^(r→s)^( ¬qv¬s) → (¬pv¬r)

Example:
Let p be “I will study discrete math.”
Let q be “I will study computer science.”
Let r be “I will study protein structures.”
Let s be “I will study biochemistry.”

“If I will study discrete math, then I will study computer science.”
“If I will study protein structures, then I will study biochemistry.”
“I will not study computer science or I will not study
biochemistry.”

“Therefore, I will not study discrete math or I will not study


protein structures.”

 Absorptions
q is absorbed by p in the conclusion!
Corresponding Tautology:

(p→q)→ (p→ (p^q))

Example:
Let p be “I will study discrete math.”
Let q be “I will study computer science.”

“If I will study discrete math, then I will study computer science.”

“Therefore, if I will study discrete math, then I will study discrete


Building Valid Arguments
mathematics and I will study computer science.”

A valid argument is a sequence of statements where each statement is either a premise


or follows from previous statements (called premises) by rules of inference. The last statement is
called conclusion.
A valid argument takes the following form:

Example1 : From the single proposition

P ^ (p→q)

92
CHAPTER X. INFERENCE

Show that q is a conclusion

Solution

Example 2 : With these hypotheses:


“It is not sunny this afternoon and it is colder than yesterday.”
“We will go swimming only if it is sunny.”
“If we do not go swimming, then we will take a canoe trip.”
“If we take a canoe trip, then we will be home by sunset.”

• Using the inference rules, construct a valid argument for the conclusion:
“We will be home by sunset.”

Solution
1. Choose propositional variables: 2. Translation into propositional
logic:

p : “It is sunny this afternoon.”


q : “It is colder than yesterday.”
r : “We will go swimming.”
s : “We will take a canoe trip.”
t : “We will be home by sunset.”

93
CHAPTER X. INFERENCE

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about INFERENCE

Self Check 10 for LO1, LO2, and LO3

APPLICATION
III. Fill-up the table Below

No. Interference Tautotology


1 P -> P v Q

2 P^Q->P^Q

3 (P ^ Q) -> P

4 P→Q
__P__
∴Q
5 P→Q
__¬Q__
∴ ¬P
6 ¬P
_P ∨ Q_
∴Q
7 P→Q
_Q → R_
∴P→R
8 ((P -> Q) ^ (R -> S))^(P v R) -> Q v S
9 (P → Q ) ∧ (R → S)
___¬Q ∨ ¬S___
∴P∨R

IV. Give the Interference and the tautology of the given sentence.

No. Variable Sentence Inference Tautology


“If it is snowing, then I will study
Let p be “It is discrete math.”
snowing.” “It is snowing.”
1.. Let q be “I will study
discrete math.” “ Therefore , I will study discrete
math. ”

94
CHAPTER X. INFERENCE

Let p be “I will study “If I will study discrete math, then I


discrete math.” will study computer science.”
Let q be “I will study “If I will study protein structures,
computer science.” then I will study biochemistry.”
Let r be “I will study “I will not study computer science
2.
protein structures.” or I will not study biochemistry.”
Let s be “I will study
biochemistry.” “ Therefore, I will not study discrete
math or I will not study protein
structures. ”
Let p be “I will study “If I will study discrete math, then I
discrete math.” will study Computer Science.”
Let q be “I will study “If I will study databases, then I will
Computer Science.” study Computer Science.”
3. Let r be “I will study “I will study discrete math or I will
databases.” study databases.”

“ Therefore, I will study Computer


Science. ”

95
CHAPTER XI. Sorting Algorithm

CHAPTER XI
SORTING ALGORITHM
Learning Content:
 The concept of discrete structure sorting.
 Bubble Sorting
 Insertion Sorting
 Selection sorting
 Radix Sorting

Intended Learning Outcomes


At the end of the lesson, the student should be able to:
 Recall and describe sorting
 Identify and apply the rules of bubble sort, merge sort, selection sort and insertion sorting

98
CHAPTER XI. Sorting Algorithm

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about SORTING ALGORITHM

Pre-assessment 11 for LO1 and LO2

Sort the given set using the following sorting algorithm

1. Selection Sort: (5,9,12,3,2,5)


2. Bubble Sort: (5,9,8,3,2,6)
3. Insertion Sort: (7,4,9,23,3,5,7)
4. Radix Sort:( 1010,2017,78654,89,201,8)

1. Selection Sort: (5,9,12,3,2,5)

2. Bubble Sort: (5,9,8,3,2,6)

3. Insertion Sort: (7,4,9,23,3,5,7)

4. Radix:( 1010,2017,78654,89,201,8)

99
CHAPTER XI. Sorting Algorithm

INFORMATION SHEET
The concept of discrete structure sorting
A Sorting Algorithm is used to rearrange a given array or list elements according to a
comparison operator on the elements. The comparison operator is used to decide the new order
of element in the respective data structure.

Sorting refers to arranging data in a particular format. Sorting algorithm specifies the way
to arrange data in a particular order. Most common orders are in numerical or lexicographical
order.

The importance of sorting lies in the fact that data searching can be optimized to a very high
level, if data is stored in a sorted manner. Sorting is also used to represent data in more readable
formats. Following are some of the examples of sorting in real-life scenarios −

 Telephone Directory − The telephone directory stores the telephone numbers of people
sorted by their names, so that the names can be searched easily.
 Dictionary − The dictionary stores words in an alphabetical order so that searching of any
word becomes easy.

1. Bubble sort is a simple sorting algorithm. This sorting algorithm is comparison-based


algorithm in which each pair of adjacent elements is compared and the elements are swapped
if they are not in order. This algorithm is not suitable for large data sets as its average and
worst case complexity are of Ο(n2) where n is the number of items.

How Bubble Sort Works?


We take an unsorted array for our example. Bubble sort takes Ο(n2) time so we're keeping it short
and precise.

Bubble sort starts with very first two elements, comparing them to check which one
is greater.

In this case, value 33 is greater than 14, so it is already in sorted locations. Next,
we compare 33 with 27.

We find that 27 is smaller than 33 and these two values must be swapped.

The new array should look like this −

100
CHAPTER XI. Sorting Algorithm

Next we compare 33 and 35. We find that both are in already sorted positions.

Then we move to the next two values, 35 and 10.

We know then that 10 is smaller 35. Hence they are not sorted.

We swap these values. We find that we have reached the end of the array. After
one iteration, the array should look like this −

To be precise, we are now showing how an array should look like after each
iteration. After the second iteration, it should look like this −

Notice that after each iteration, at least one value moves at the end.

And when there's no swap required, bubble sorts learns that an array is completely
sorted.

Now we should look into some practical aspects of bubble sort.

101
CHAPTER XI. Sorting Algorithm

2. Insertion Sort
This is an in-place comparison-based sorting algorithm. Here, a sub-list is
maintained which is always sorted. For example, the lower part of an array is maintained to
be sorted. An element which is to be 'insert'ed in this sorted sub-list, has to find its
appropriate place and then it has to be inserted there. Hence the name, insertion sort.

The array is searched sequentially and unsorted items are moved and inserted into
the sorted sub-list (in the same array). This algorithm is not suitable for large data sets as
its average and worst case complexity are of Ο(n2), where n is the number of items.

How Insertion Sort Works?


We take an unsorted array for our example.

Insertion sort compares the first two elements.

It finds that both 14 and 33 are already in ascending order. For now, 14 is in sorted
sub-list.

Insertion sort moves ahead and compares 33 with 27.

And finds that 33 is not in the correct position.

102
CHAPTER XI. Sorting Algorithm

It swaps 33 with 27. It also checks with all the elements of sorted sub-list. Here we
see that the sorted sub-list has only one element 14, and 27 is greater than 14.
Hence, the sorted sub-list remains sorted after swapping.

By now we have 14 and 27 in the sorted sub-list. Next, it compares 33 with 10.

These values are not in a sorted order.

So we swap them.

However, swapping makes 27 and 10 unsorted.

Hence, we swap them too.

Again we find 14 and 10 in an unsorted order.

We swap them again. By the end of third iteration, we have a sorted sub-list of 4
items.

This process goes on until all the unsorted values are covered in a sorted sub-list.
Now we shall see some programming aspects of insertion sort.

103
CHAPTER XI. Sorting Algorithm

3. Selection Sort

Consider the following depicted array as an example.

For the first position in the sorted list, the whole list is scanned sequentially. The
first position where 14 is stored presently, we search the whole list and find that 10
is the lowest value.

So we replace 14 with 10. After one iteration 10, which happens to be the minimum
value in the list, appears in the first position of the sorted list.

For the second position, where 33 is residing, we start scanning the rest of the list
in a linear manner.

We find that 14 is the second lowest value in the list and it should appear at the
second place. We swap these values.

After two iterations, two least values are positioned at the beginning in a sorted
manner.

The same process is applied to the rest of the items in the array.
Following is a pictorial depiction of the entire sorting process −

104
CHAPTER XI. Sorting Algorithm

4. Radix sort

Radix sort is one of the sorting algorithms used to sort a list of integer numbers in order. In radix
sort algorithm, a list of integer numbers will be sorted based on the digits of individual numbers.
Sorting is performed from least significant digit to the most significant digit.
Radix sort algorithm requires the number of passes which are equal to the number of digits present
in the largest number among the list of numbers. For example, if the largest number is a 3 digit
number then that list is sorted with 3 passes.

Step by Step Process

105
CHAPTER XI. Sorting Algorithm

The Radix sort algorithm is performed using the following steps...

Step 1 - Define 10 queues each representing a bucket for each digit from 0 to 9.
Step 2 - Consider the least significant digit of each number in the list which is to be sorted.
Step 3 - Insert each number into their respective queue based on the least significant digit.
Step 4 - Group all the numbers from queue 0 to queue 9 in the order they have inserted into their
respective queues.
Step 5 - Repeat from step 3 based on the next least significant digit.
Step 6 - Repeat from step 2 until all the numbers are grouped based on the most significant digit.

106
CHAPTER XI. Sorting Algorithm

107
CHAPTER XI. Sorting Algorithm

Name : __________________________________________________ Date : ______________


Course/Year/Section : ______________________________________ Score: ______________

Let us determine how much you already know about SORTING ALGORITHM

Self-Check 11 for LO1 and LO4

Sort the given set using the following sorting algorithm

1. Selection Sort: (5,9,12,3,2,5)


2. Bubble Sort: (5,9,8,3,2,6)
3. Insertion Sort: (7,4,9,23,3,5,7)
4. Radix:( 1010,2017,78654,89,201,8)
5. Selection Sort: (5,9,12,3,2,5)

6. Bubble Sort: (5,9,8,3,2,6)

7. Insertion Sort: (7,4,9,23,3,5,7)

8. Radix:( 1010,2017,78654,89,201,8)

108
ACKNOWLEDGEMENT
This module wouldn’t have been possible without Isabela State University that allowed me to

develop and test insight-related ideas during the development period of this instructional material.

I owe an enormous debt of gratitude to Renalyn G. Tecson who gave me detailed and constructive

comments on one or more chapters. She gave freely of her time to discuss nuances of the text and pushed

me to clarify concepts, explore particular facets of insight work, and explain the content for specific

recommendations.

I’m also immensely grateful to the COLLEGE OF COMPUTING STUDIES, INFORMATION AND

COMMUNICATION TECHNOLOGY , who have allowed me to use the difefrent resurces of the college for

my personal learning laboratory. What an indescribable pleasure it is to meet those faculty and staff who

are genuinely interested in ideas, who render a constructive critique of any material, suggestion, or

practice that comes before them, and who are always eager to test new ideas, new ways of thinking, and

new practices.

I want to acknowledge Ricardo Q. Camungao, college dean of CCSICT, who have made my

professional life such a pleasure, has constantly encouraged me to “get that Instructional material done.”

I can’t thank him enough for being my unrelenting source of inspiration to challenge how things get done

in the corporate world.

Finally, I want to thank my husband, Notiffer Feliciano, for tolerating my incessant disappearances

into my home office. A lifelong partner makes both the journey and destination worthwhile. And above

all this to my only child Patrizia Feliciano that serve as my inspiration to finished this module.

132
ABOUT THE AUTHOR
Catleen Glo Feliciano is the present faculty of College of Computing Studies, Information and

Communication Technology(CCSICT) and designated as BSCS Program chair, She Discrete mathematics

and Discrete Structure from 2015 to present at CCSICT..She finished her master degree of Master of

Information Technoology at University of La Sallete and currently on-going taking up Doctor in Information

Technology at the University of the East, Manila.

133

You might also like