IT 123 Discrete Mathematics Module
IT 123 Discrete Mathematics Module
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
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
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
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)
1
CHAPTER I. DISCRETE MATHEMATICS
Let us determine how much you already know about the INTRODUCTION TO DISCRETE STRUTURES
Identification:
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
3
CHAPTER I. DISCRETE MATHEMATICS
4
CHAPTER I. DISCRETE MATHEMATICS
Let us determine how much you already know about the INTRODUCTION TO DISCRETE STRUTURES
Identification:
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
7
CHAPTER II. GRAPH THEORY
Let us determine how much you already know about the GRAPH THEORY
IDENTIFICATION
APPLICATION
Identify the indegree and outdegree of the graph
8
CHAPTER II. GRAPH THEORY
INFORMATION SHEET
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}
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
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.
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).
14
CHAPTER II. GRAPH THEORY
15
CHAPTER II. GRAPH THEORY
Let us determine how much you already know about the GRAPH THEORY
IDENTIFICATION
APPLICATION
Identify the indegree and outdegree of the graph
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
18
CHAPTER III. PROBLEM FORMULATION
Let us determine how much you already know about PROBLEM FORMULATION
APPLICATION
B D
* %
A F
& #
C E
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
21
CHAPTER III. PROBLEM FORMULATION
Let us determine how much you already know about PROBLEM FORMULATION
APPLICATION
B D
* %
A F
& #
C E
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
24
CHAPTER IV SETS
IDENTIFICATION
17. _____________
18. _____________
25
CHAPTER IV SETS
19. . _____________
APPLICATION
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)’
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}
26
CHAPTER IV SETS
INFORMATION SHEET
The objects of a set are all distinct, i.e., no two objects are the same.
(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
For example,
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
Descriptive form
The description must allow a concise determination of which elements belong to the set and
which elements do not.
For example,
28
CHAPTER IV SETS
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 }
Reading notation :
We read it as
For example,
29
CHAPTER IV SETS
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 ∞.
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.
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}.
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}.
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.
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).
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
IDENTIFICATION
17. _____________
18. _____________
35
CHAPTER IV SETS
19. . _____________
APPLICATION
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)’
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}
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
40
CHAPTER V. TREES
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
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
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
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
46
CHAPTER VI. TREE TRAVERSAL
Let us determine how much you already know about TREE TRAVERSAL
APPLICATION
Give the tree traversal of the tree below
B C
D E F
H I
G
47
CHAPTER VI. TREE TRAVERSAL
INFORMATION SHEET
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"
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
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
Let us determine how much you already know about TREE TRAVERSAL
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
52
CHAPTER VII. HUFFMAN CODE
Let us determine how much you already know about HUFFMAN CODE
1. ISABELA
2. STATE
3. UNIVERSITY
53
CHAPTER VII. HUFFMAN CODE
INFORMATION SHEET
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
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
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
56
CHAPTER VII. HUFFMAN CODE
Let us determine how much you already know about 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
59
CHAPTER VIII PROPOSITIONS
IDENTIFICATION:
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
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.
Logical Operators
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.
Connectives
In propositional logic generally we use five connectives which are
• OR (∨)
• AND (∧)
• Negation/ NOT (¬)
• Implication / if-then (→)
• If and only if (⇔).
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
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.
64
CHAPTER VIII PROPOSITIONS
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 −
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:
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.
67
CHAPTER VIII PROPOSITIONS
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.
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.
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
72
CHAPTER VIII PROPOSITIONS
IDENTIFICATION:
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
77
CHAPTER IX. PREDICATE LOGIC
Let us determine how much you already know about PREDICATE LOGIC
78
CHAPTER IX. PREDICATE LOGIC
INFORMATION SHEET
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
The proposition
“The dog is sleeping”
Propositional Functions
A predicate is modeled as a function P(·) from objects to propositions.
P(x) = “x is sleeping” (where x is any object).
Note: The predicate P itself (e.g. P=“is sleeping”) is not a proposition (not a complete sentence).
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
Quantifier Expressions
Quantifiers allow us to quantify (count) how many objects in the universe of discourse satisfy a
given predicate:
- “” is the FORLL 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.
80
CHAPTER IX. PREDICATE LOGIC
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.”
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
Let us determine how much you already know about PREDICATE LOGIC
82
CHAPTER X. INFERENCE
CHAPTER 10
CHAPTER X
INFERENCE.docx
INFERENCE
Learning Content:
Concept of inference
Rules of inference
84
CHAPTER X. INFERENCE
APPLICATION
I. Fill-up the table Below
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.
85
CHAPTER X. INFERENCE
86
CHAPTER X. INFERENCE
INFORMATION SHEET
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.
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).
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 –
88
CHAPTER X. INFERENCE
89
CHAPTER X. INFERENCE
Example:
Corresponding Tautology: Let p be “I will study discrete math.”
Example:
Corresponding Tautology:
Let p be “I will study discrete math.”
(( p )^(q)) →(p^q)) Let q be “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:
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.”
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.”
((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
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.”
Absorptions
q is absorbed by p in the conclusion!
Corresponding Tautology:
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.”
P ^ (p→q)
92
CHAPTER X. INFERENCE
Solution
• 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:
93
CHAPTER X. INFERENCE
APPLICATION
III. Fill-up the table Below
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.
94
CHAPTER X. INFERENCE
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
98
CHAPTER XI. Sorting Algorithm
Let us determine how much you already know about SORTING ALGORITHM
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.
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.
100
CHAPTER XI. Sorting Algorithm
Next we compare 33 and 35. We find that both are in already sorted positions.
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.
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.
It finds that both 14 and 33 are already in ascending order. For now, 14 is in sorted
sub-list.
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.
So we swap them.
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
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.
105
CHAPTER XI. Sorting Algorithm
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
Let us determine how much you already know about SORTING ALGORITHM
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
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
133