You are on page 1of 189

discrete structure

E-BOOK

Page 1 of 189
Page 2 of 189
UNIT - 1
Sets theory and functions

Page 3 of 189
Sets theory and functions
8/20/2015 scorm content

 
Sets

A set is a distinct collection of objects. The objects are called elements.

We will develop more fully

The definitions of sets,

The properties of sets,

The operations on sets

Sets are fundamental discrete structures.

Definition

The  objects  in  a  set  are  called  elements  or  members  of  a  set.  A  set  is  said  to  contain  its
elements.

Terminology

Page 4 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/2.html 1/4
Sets theory and functions
8/20/2015 scorm content

Multi­set

A multi­set is a set where you specify the number of occurrences of each element.

Page 5 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/2.html 2/4
Sets theory and functions
8/20/2015 scorm content

Set­build

Page 6 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/2.html 3/4
Sets theory and functions
8/20/2015 scorm content

Venn diagram

A set can be represented graphically using a Venn diagram.

A Venn diagram or Set Diagram is a diagram that shows all possible logical relations between a
finite collections of sets.

Page 7 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/2.html 4/4
Sets theory and functions
8/20/2015 scorm content

 
Terminology and Notation

A set that has no elements is called the empty set or null set and is denoted Ø.

A set that has one element is called a singleton set.

For example: {a}, with brackets, is a singleton set. a, without brackets, is an element of the set
{a}.

Definition

Set Operations

Intersection: The common elements of two sets:

Page 8 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/3.html 1/3
Sets theory and functions
8/20/2015 scorm content

Union: The set of elements that belong to either of two sets:

Complement: The set of elements (in the universal set) that do not belong to a given set:

Difference or Relative Complement

The set of elements that belong to a set but not to another.

Page 9 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/3.html 2/3
Sets theory and functions
8/20/2015 scorm content

Symmetric Difference

Given two sets, their symmetric difference is the set of elements that belong to either one or the
other set but not both.

Page 10 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/3.html 3/3
Sets theory and functions
8/20/2015 scorm content

 
Properties of Sets

Associative Laws

Commutative Laws

Distributive Laws

Identity Laws

Complement Laws

The  analogy  between  unions  and  intersections  of  sets,  and  addition  and  multiplication  of
numbers, is quite striking.

Like  addition  and  multiplication,  the  operations  of  union  and  intersection  are  commutative  and
associative, and intersection distributes over unions.

Page 11 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/4.html 1/3
Sets theory and functions
8/20/2015 scorm content

However, unlike addition and multiplication, union also distributes over intersection.

Two additional pairs of laws involve the special sets called the empty set Ø and the universal set
U; together with the complement operator.

The empty set has no members, and the universal set has all possible members (in a particular
context).

As  noted  above,  each  of  the  laws  stated  in  proposition  3  can  be  derived  from  the  five
fundamental pairs of laws stated above.

As an illustration, a proof is given below for the idempotent law for union.

Proof

The following proof illustrates that the dual of the above proof is the proof of the dual.

Of the idempotent law for union, namely the idempotent law for intersection.

Page 12 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/4.html 2/3
Sets theory and functions
8/20/2015 scorm content

Page 13 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/4.html 3/3
Sets theory and functions
8/20/2015 scorm content

 
Properties of relations

Let A and B be sets.

A binary relation from A to B is a subset of A x B.

Let R be a relation. If (a, b) R, we write a R b.

Example

Let us be a set of students.

Let C be a set of courses.

Let R = {(s, c) | student s is taking course c}.

Many students may take the same course.

A single student may take many courses.

Functions as Relations

Functions are a kind of relation.

Let function f : A → B.

If f (a) = b, we could write (a,b) f A x B.

P(A x B) = the set of all relations from A to B.

Let F = the set of all functions from A to B.

F is a proper subset of A x B.

Relations on a Set

A relation on a set A is a relation from A to A.

Examples of relations on R:

R1 = { (a, b) | a ≤ b }

R2 = { (a, b) | b = +sort( a ) }

A relation R on A is:

Page 14 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/5.html 1/2
Sets theory and functions
8/20/2015 scorm content

Let S be a set of people.

Let R & T be relations on S.

Antisymmetric

Example:

L = { ( a, b ) | a ≤ b }

Transitive:

Page 15 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/5.html 2/2
Sets theory and functions
8/20/2015 scorm content

 
Composition

Let R be a relation from A to B.

Let S be a relation from B to C.

The composition is

Let R be a relation on A.

R1 = RRn = Rn­1°R

Let R = { (1, 1), (2, 1), (3, 2), (4, 3) }

Relations on a Set

The word graph above is used as a verb.

Let A = {1, 2, 3} and B = {2, 3, 4}.

Let R be a relation from A to B where {(a, b) | a divides b}.

Representing Relations Using Matrices

Let A = {a1, a2… an} be a finite set. Then we can represent a relation R over the set A using an
n by n matrix: Where entry

Example

Is the 3 by 3 zero­one matrix that represents the relation R.?

This representation can be generalized in the obvious way to represent a relation R from A to B
where both A and B are finite sets with m and n elements respectively.

Page 16 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/6.html 1/2
Sets theory and functions
8/20/2015 scorm content

Then an m by n zero­one matrix can be used to represent the relation R.

We  can  use  the  matrix  representation  to  store  relations  in  a  computer  and  efficiently  perform
certain operations on relations using matrix operations.

Representing Relations Using Digraphs

While the matrix representation is convenient for working with relations in a computer, a digraph
representation is a more visually appealing way to represent a relation on a finite set.

Let A = { a1, a2, …, a3 } and let R be a relation on A.

For the digraph representation of R, we use a labeled dot to represent each element of A.

Then for each pair (aj, ak) that is in R, we draw an arrow coming out of dot aj and that points to
dot ak.

Example: Let A = {1, 2, 3, 4} and

R = { (1, 2), (2, 1), (2, 2), (3, 4) }

Reflexive: The relation represented by a digraph is reflexive if and only if there is a loop at every
vertex.

I reflexive: The relation represented by a digraph is irreflexive if and only if there is not a loop at
any vertex.

Symmetric:  The  relation  represented  by  a  digraph  is  symmetric  if  and  only  if  all  arrows  (other
than loops) come in pairs with reverse direction.

Antisymmetric: The relation represented by a digraph is antisymmetric if and only if there are no
pairs of arrows with reverse direction.

Transitive: The relation represented by a digraph is transitive if and only if there is an edge from
a to b whenever there is a path from a to b for all nodes a and b.

Page 17 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/6.html 2/2
Sets theory and functions
8/20/2015 scorm content

 
Equivalence relation

An equivalence relation on a set S, is a relation on S which is reflexive, symmetric and transitive.

In general an equivalence relation results when we wish to “identify” two elements of a set that
share a common attribute.

The  definition  is  motivated  by  observing  that  any  process  of  “identification”  must  behave
somewhat like the equality relation, and the equality relation satisfies the

Reflexive ( x = x for all x ),

Symmetric ( x = y implies y = x ), and

Transitive (x = y and y = x implies x = z) properties.

Example

Let R be the relation on the set R real numbers defined by x R y if f x – y is an integer.Prove that
R is an equivalence relation on R.

Thus, R is an equivalence relation on R.

Example

Let R be the relation on the set of real numbers R in Example. Prove that if x R x′ and y Y′, then
(x + y) R (x′ + y′).

Proof:

Suppose x R x′ and y R y′.

In order to show that (x + y) R ( x′ + y′ ),

Page 18 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/7.html 1/3
Sets theory and functions
8/20/2015 scorm content

we must show that (x + y) – ( x′ + y′ ) is an integer.

since, (x + y) – ( x′ + y′ ) = ( x – x′ ) + ( y – y′ )

and since each of x – x′ and y – y′ is an integer (by definition of R),

( x – x′ ) + ( y – y′ ) is an integer.

Thus, (x + y) R ( x′ + y′ ).

Equivalence Classes

Given  an  equivalence  relation  R  on  a  set  S,  we  define  the  equivalence  class  containing  an
element x of S by :

Let  R  be  an  equivalence  relation  on  A  and  let  a A.  The  set  [a]  =  {  x|aRx  }  is  called  the
equivalence class of a.

The element in the bracket in the above notation is called the Representative of the equivalence
class.

Equivalence Theorem

Let R be an equivalence relation on a set A. Then the following are equivalent:

Page 19 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/7.html 2/3
Sets theory and functions
8/20/2015 scorm content

The purpose of any identification process is to break a set up into subsets consisting of mutually
identified elements. An equivalence relation on a set A does precisely this: it decomposes A into
special subsets, called equivalence classes.

These ideas are summed up in Theorem.

When we say several statements, such as P1, P2, and P3 are equivalent, we mean P1 ↔ P2 ↔
P3 is true. N

otice that in order to prove that the statements are mutually equivalent, it is sufficient to prove a
circle of implications, such as P1 → P2 → P3 → P1. This is how we set up the proof of Theorem.

Page 20 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/7.html 3/3
Sets theory and functions
8/20/2015 scorm content

 
Partition

A collection S of nonempty subsets of a set A is a partition of A if

If S is a set with an equivalence relation R, then it is easy to see that the equivalence classes of
R form a partition of the set S. More interesting is the fact that the converse of this statement is
true.

Partition Theorem

The equivalence classes of an equivalence relation on A form a partition of A.

Conversely, given a partition on A, there is an equivalence relation with equivalence classes that
are exactly the partition given.

Such decomposition is called a partition.

For example, if we wish to identify two integers if they are either both even or both odd, then we
end up with a partition of the integers into two sets, the set of even integers and the set of odd
integers.

The  converse  of  Theorem  allows  us  to  create  or  define  an  equivalence  relation  by  merely
partitioning a set into mutually exclusive subsets.

The  common  “attribute”  then  might  just  be  that  elements  belong  to  the  same  subset  in  the
partition.

If R is an equivalence relation on a set A, the set of equivalence classes of R is denoted A/R.

Proof

Page 21 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/8.html 1/2
Sets theory and functions
8/20/2015 scorm content

Page 22 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit1/assets/8.html 2/2
UNIT - 2
Mathematical logic

Page 23 of 189
Mathematical logic
8/20/2015 scorm content

 
Mathematical Logic ­ Definition

Perhaps  the  most  distinguishing  characteristic  of  mathematics  is  its  reliance  on  logic.  Explicit
training in mathematical logic is essential to a mature understanding of mathematics.

Familiarity with the concepts of logic is also a prerequisite to studying a number of central areas
of computer science, including databases, compilers, and complexity theory.

Formal Language & Arguments

Within that formal language: Knowledge can be stated concisely and precisely.

The process of reasoning from that knowledge can be made rigorous.

Symbols and strings of symbols, Well­formed formulas, Theorems, Arguments Specific Case(s),
General Rules or Principles, Inductive, Deductive.

Examples in Arguments

Deductive argument: “Alexandria is a port or a holiday resort. Alexandria is not a port. Therefore,
Alexandria is a holiday resort”.

Inductive argument: “Most students who did not do the tutorial questions will fail the exam. John
did not do the tutorial questions. Therefore John will fail the exam”.

Page 24 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/2.html 1/2
Mathematical logic
8/20/2015 scorm content

Page 25 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/2.html 2/2
Mathematical logic
8/20/2015 scorm content

 
Propositional logic

A proposition is a sentence that is either true or false but not both. (In particular, it cannot be a
question.)

Simple types of statements, called propositions, are treated as atomic building blocks for more
complex statements.

Introduction

The  rules  of  logic  give  precise  meaning  to  mathematical  statements.  These  rules  are  used  to
distinguish between valid and invalid mathematical arguments.

Besides  the  importance  of  logic  in  understanding  mathematical  reasoning,  logic  has  numerous
applications to computer science.

These rules are used in the design of computer circuits, the construction of computer programs,
the verification of the correctness of programs, and in many other ways.

Furthermore, software systems have been developed for constructing some, but not all, types of
proofs automatically.

Propositions

Our  discussion  begins  with  an  introduction  to  the  basic  building  blocks  of  logic  propositions.  A
proposition is a declarative sentence (that is, a sentence that declares a fact) that is either true
or false, but not both.

Consider the following sentences.

Sentences 1 and 2 are not propositions because they are not declarative sentences.

Page 26 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/3.html 1/5
Mathematical logic
8/20/2015 scorm content

Sentences 3and 4 are not propositions because they are neither true nor false.

Note that each of sentences 3 and 4 can be turned into a proposition if we assign values to the
variables.

The area of logic that deals with propositions is called the propositional calculus or propositional
logic.

Many  mathematical  statements  are  constructed  by  combining  one  or  more  propositions.  New
propositions, called compound propositions, are formed from existing propositions using logical
operators.

EXAMPLE

Find the negation of the proposition “Vandana’s smartphone has at least 32GB of memory” and
express this in simple English.

Solution

The negation is “It is not the case that Vandana’s smartphone has at least 32GB of memory.”

This negation can also be expressed as “Vandana’s smartphone does not have at least 32GB of
memory” or even more simply as “Vandana’s smartphone has less than 32GB of memory.”

Table displays the truth table for the negation of a proposition p. This table has a row for each of
the  two  possible  truth  values  of  a  proposition  p.  Each  row  shows  the  truth  value  of  ¬ p
corresponding to the truth value of p for this row.

Conjunction

Let p and q be propositions. The conjunction of p and q, denoted by p Λ q, is the proposition“p
and q.” The conjunction p Λ q is true when both p and q are true and is false otherwise.

Page 27 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/3.html 2/5
Mathematical logic
8/20/2015 scorm content

The four rows correspond to the pairs of truth values TT, TF, FT, and FF, where the first truth
value in the pair is the truth value of p and the second truth value is the truth value of q.

Note  that  in  logic  the  word  “but”  sometimes  is  used  instead  of  “and”  in  a  conjunction.  For
example, the statement “The sun is shining, but it is raining” is another way of saying “The sun is
shining and it is raining.”

Disjunction

Let p and q be propositions. The disjunction of p and q, denoted by p V q, is the proposition“p or
q.”

The disjunction p V q is false when both p and q are false and is true otherwise.

Conditional Statements

Let p and q be propositions.

The conditional statement p → q is the proposition “if p, then q.” The conditional statement p →
q is false when p is true and q is false, and true otherwise.
Page 28 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/3.html 3/5
Mathematical logic
8/20/2015 scorm content

In the conditional statement p → q, p is called the hypothesis (or antecedent or premise) and q
is called the conclusion (or consequence).

The statement p → q is called a conditional statement because p → q asserts that q is true on
the condition that p holds. A conditional statement is also called an implication.

The truth table for the conditional statement p → q is shown in Table. Note that the statement p
→ q is true when both p and q are true and when p is false (no matter what truth value q has).

Because conditional statements play such an essential role in mathematical reasoning, a variety
of terminology is used to express p → q. You will encounter most if not all of the following ways
to express this conditional statement:

Biconditionals

Let p and q be propositions.

The biconditional statement p ↔ q is the proposition “p if and only if q.”

The biconditional statement p ↔ q is true when p and q have the same truth values, and is false
otherwise.

Biconditional statements are also called bi­implications.

Page 29 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/3.html 4/5
Mathematical logic
8/20/2015 scorm content

That  is  why  we  use  the  words  “if  and  only  if”  to  express  this  logical  connective  and  why  it  is
symbolically written by combining the symbols → and ←.

There are some other common ways to express p ↔ q: p is necessary and sufficient for q” “if p
then q, and conversely” “p iff q.”

The  last  way  of  expressing  the  biconditional  statement  p  ↔  q  uses  the  abbreviation  “iff”  for  “if
and only if.” Note that p ↔ q has exactly the same truth value as (p → q) ∧ (q → p).

Page 30 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/3.html 5/5
Mathematical logic
8/20/2015 scorm content

 
Precedence of logical operators

Generally  we  use  parentheses  to  specify  the  order  in  which  logical  operators  in  a  compound
proposition are to be applied. For instance, (p ∨ q) ∧ (¬r) is the conjunction of p ∨ q and ¬r.

General  rule  of  precedence  is  that  the  conjunction  operator  takes  precedence  over  the
disjunction operator, so that p ∧ q ∨ r means (p ∧ q) ∨ r rather than p ∧ (q ∨ r).

It  is  an  accepted  rule  that  the  conditional  and  biconditional  operators  →  and  ↔  have  lower
precedence than the conjunction and disjunction operators, ∨ and ∧.

Consequently, p ∨ q → r is the same as (p ∨ q) → r.

We will use parentheses when the order of the conditional operator and biconditional operator is
at issue, although the conditional operator has precedence over the biconditional operator.

Table displays the precedence levels of the logical operators, ¬, ∧, ∨, →, and↔.

Predicate calculus

A  predicate  is  a  sentence  that  contains  variables,  and  when  the  variables  are  substituted  by
numbers or actual objects, it becomes a proposition.

Predicate  calculus  on  the  other  hand  is  analogous  to  Algebra,  which  is  more  complex  than
arithmetic but it requires the knowledge of arithmetic.

Predicates define relationships between any number of entities using qualifiers:

Page 31 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/4.html 1/4
Mathematical logic
8/20/2015 scorm content

Examples

Predicates

A  predicate  is  a  statement  that  contains  a  variable,  such  that  for  any  specific  value  of  the
variable the statement is a proposition.

Usually  the  allowed  values  for  the  variable  will  come  from  a  specific  set,  sometimes  called  the
universe of the variable.

Page 32 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/4.html 2/4
Mathematical logic
8/20/2015 scorm content

This will be either explicitly mentioned or clear from context.

A simple example of a predicate is x _ 2 for x 2 R.

Clearly, for any real value of x, this statement is either true or false.

A  predicate  may  have  more  than  one  variable,  in  which  case  we  speak  of  predicates  in  two
variables, three variables, and so on, denoted as Q(x, y), S(x, y, z), etc.

Propositional Functions

A statement of the form P(x1, x2. . . xn) is the value of the propositional function P.

Here, (x1, x2. . . xn) is an n­tuple and P is a predicate.

Evaluates to true or false.

Takes one or more arguments.

Expresses a predicate involving the argument(s).

Becomes a proposition when values are assigned to the arguments.

Example

Let Q(x, y, z) denote the statement “x2 + y2 = z2”. What is The truth value of Q(3, 4, 5)? What is
the truth value of Q (2, 2, 3)? How many values of (x, y, z) make the predicate true?

There are infinitely many values for (x, y, z) that make this propositional function true.

Universe of Discourse

Universe of discourse is the set of all things we wish to talk about; that is, the set of all objects
that we can sensibly assign to a variable in a propositional function.

Consider the example,

Let Q(x, y, z) denote the statement “x2 + y2 = z2”.

What is the truth value of Q (3, 4, 5)?

What is the truth value of Q (2, 2, 3)?

How many values of (x, y, z) make the predicate true?

Does it make sense to assign to x the value “blue”?

Page 33 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/4.html 3/4
Mathematical logic
8/20/2015 scorm content

What would be the universe of discourse for the propositional function P(x) = “The test will be on
x the 23rd” be?

Moreover, each variable in an n­tuple may have a different universe of discourse.

Let P(r, g, b, c) = “The rgb­value of the color c is (r, g, b)”.

For example, P(255, 0, 0, red) is true, while P(0, 0, 255, green) is false.

What are the universes of discourse for (r, g, b, c)?

Page 34 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/4.html 4/4
Mathematical logic
8/20/2015 scorm content

 
Quantifiers

A  predicate  becomes  a  proposition  when  we  assign  it  fixed  values.  However,  another  way  to
make a predicate into a proposition is to quantify it.

That is, the predicate is true (or false) for all possible values in the universe of discourse or for
some value(s) in the universe of discourse.

We form propositions from predicates by assigning values to the variables or by quantification.

Such  quantification  can  be  done  with  two  quantifiers.  The  universal  quantifier,  the  existential
quantifier and uniqueness quantifier.

Universal quantifier: 8, read, “for all,” or “for every;”

Existential quantifier: 9, read, “there exists;”

Uniqueness quantifier: !, read, “unique.”

Given a predicate in more than one variable we can quantify each (or some) of the variables.

Universal Quantifiers

The universal quantification of a predicate P(x) is the proposition “P(x) is true for all values of x in
the universe of discourse”

If the universe of discourse is finite, say {n1, n2. . . nk}, then the universal quantifier is simply the
conjunction of all elements.

Let  P(x)  be  the  predicate  “x  must  take  a  discrete  mathematics  course”  and  let  Q(x)  be  the
predicate “x is a computer science student”.

The  universe  of  discourse  for  both  P(x)  and  Q(x)  is  all  UNL  students.  Express  the  statement
“Every computer science student must take a discrete mathematics course”.

Express the statement “Everybody must take a discrete mathematics course or be a computer
science student”.

Page 35 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/5.html 1/6
Mathematical logic
8/20/2015 scorm content

Given a proposition P, the negation of P is the proposition “P is false”. It is true if P is false, and
false if P is true. The negation of P is denoted by ¬P, read as “not P.”

If we know the meaning of P, such as when P stands for “It will rain tomorrow,” the proposition
¬P can be stated more naturally than “not P,” as in “It will not rain tomorrow.”

If the universe of discourse is finite, say {n1, n2. . . nk}, then the universal quantifier is simply the
conjunction of all elements.

Negations

A truth table simply lists the truth values of particular statements in all possible cases.

Something  interesting  can  be  observed  in  we  consider  the  truth  values  of  ¬¬Q,  which  can  be
obtained by using the above table once with P = Q and once with P = ¬Q.

We see that the statements Q and ¬¬Q have the same truth values. In this case we say that the
two statements are equivalent, and write Q , ¬¬Q.

If A , B we can freely use B in the place of A, or A instead of B in our logical derivations. Negation
gets really interesting when the negated proposition is quantified. Then we can assert that

These can be interpreted as the claim that if P(x) is not true for all x E A then it is false for some
x E A and vice versa, and the claim that if P(x) is not false for any x E A then it is true for all x E A
and vice versa.

What this means, in particular, is that if we want to disprove a statement that asserts something
for all x E A, it is sufficient to demonstrate one such x for which the statement does not hold.

On the other hand, if we need to disprove a statement that asserts the existence of an x E A with
a certain property, we actually need to show that for all such x this property does not hold.

Page 36 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/5.html 2/6
Mathematical logic
8/20/2015 scorm content

Nested Quantifier

Two quantifiers are nested if one is within the scope of the other.

Existential Quantifier
Page 37 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/5.html 3/6
Mathematical logic
8/20/2015 scorm content

The  existential  quantification  of  a  predicate  P(x)  is  the  proposition  “There  exists  an  x  in  the
universe of discourse such that P(x) is true.” It is denoted by

Mean?

What universe(s) of discourse make it true?

Express the statement “there exists a real solution to ax2 + bx − c = 0”

Let P(x) be the statement x = (−b± p (b2−4ac))/2a where the universe of discourse for x is the
set of reals. Note here that a, b, c are all fixed constants.

Question: what is the truth value of ∃xP(x)?

Answer: it is false. For any real numbers such that b2 < 4ac, there will only be complex solutions,
for these cases no such real number x can satisfy the predicate.

Mixing Quantifier

Existential and universal quantifiers can be used together to quantify a predicate statement.

For Example

is perfectly valid. However, you must be careful—it must be read left to right.

For Example

is not equivalent to ∃y∀xP(x, y).Thus, ordering is important.

For Example

∀x∃y Loves (x, y): everybody loves somebody

∃y∀x Loves(x, y): There is someone loved by everyone

Those  expressions  do  not  mean  the  same  thing!  Note  that  ∃y∀xP(x,  y)  !  ∀x∃yP(x,  y),  but  the
Page 38 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/5.html 4/6
Mathematical logic
8/20/2015 scorm content

converse  does  not  hold.  However,  you  can  commute  similar  quantifiers;  ∃x∃yP(x,  y)  is
equivalent to ∃y∃xP(x, y) (which is why our shorthand was valid).

Express, in predicate logic, the statement that there are an infinite number of integers.

Express, in predicate logic, the statement that there are an infinite number of integers. Let P(x,
y) be the statement that x < y. Let the universe of discourse be the integers, Z.

Example

Express the statement “there is a number x such that when it is added to any number, the result
is that number, and if it is multiplied by any number, the result is x” as a logical expression.

Solution

Example

Is there a multiplicative inverse law over the nonzero integers? That is, for every integer x does
there exists a y such that xy = 1?

This is false, since we can find a counter example.

Take any integer, say 5 and multiply it with another integer, y.

Page 39 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/5.html 5/6
Mathematical logic
8/20/2015 scorm content

Example

Express the statement “there is a number x such that when it is added to any number, the result
is that number, and if it is multiplied by any number, the result is x” as a logical expression.

Solution

Let P(x, y) be the expression “x + y = y”.

Let Q(x, y) be the expression “xy = x”.

Page 40 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/5.html 6/6
Mathematical logic
8/20/2015 scorm content

 
Proposition Equivalence

Binding Variables

When a quantifier is used on a variable x, we say that x is bound. If no quantifier is used on a
variable in a predicate statement, it is called free.

A statement is called a well­formed formula, when all variables are properly quantified.

In the expression ∃x, y∀zP(x, y, z, c) the scope of the existential quantifier is {x, y}, the scope of
the universal quantifier is just z and c has no scope since it is free.

Let P(x) be a predicate. Then the following hold.

This is essentially a quantified version of De Morgan’s Law (in fact if the universe of discourse is
finite, it is exactly De Morgan’s law).

Proposition Equivalence

Proposition  equivalence  feature  three  terminologies,  they  are  Contradiction,  tautology,


contingency.

A compound proposition that is always true, no matter what the truth values of the propositions
that occur in it, is called a Tautology.

A compound proposition that is always false, no matter what the truth values of the propositions
that occur in it, is called a contradiction.

A compound proposition that is neither a tautology nor a contradiction is called a contingency.

Boolean operators

Boolean operators were unary and binary. Some of the Boolean operators are tabulated.

Negation operator is a unary operator.

Operators  like  Conjunction,  Disjunction,  Exclusive­  OR,  Implication,  Bi­conditional  were  binary
operators.

Page 41 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 1/8
Mathematical logic
8/20/2015 scorm content

Tautology

A tautology is a proposition that is always true.

Tautology  is  one  of  the  important  techniques  used  in  proving  theorems  is  to  replace,  or
substitute, one proposition by another one that is equivalent to it.

Contradiction

A contradiction is a proposition that is always false.

Contradiction  is  one  of  the  important  techniques  used  in  proving  theorems  is  to  replace,  or
substitute, one proposition by another one that is equivalent to it.

Contingency
Page 42 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 2/8
Mathematical logic
8/20/2015 scorm content

A contingency is a proposition that is neither a tautology nor a contradiction.

Contradiction  is  one  of  the  important  techniques  used  in  proving  theorems  is  to  replace,  or
substitute, one proposition by another one that is equivalent to it.

Bi­conditionals

Let p and q be propositions. The bi­conditional statement p⇔q is the proposition “p if and only if
q." These are also called” bi­implications".

Two propositions are called equivalent when they have the same truth table.

The contrapositive is equivalent to the original implication.

The converse and inverse are equivalent to each other.

The inverse is not equivalent to the original.

Law of excluded middle

Tautology is called the law of excluded middle, is a direct consequence of our basic assumption
that a proposition is a statement that is either true or false.

Aristotelian logic, might be described as a “2­valued” logic, and it is the logical basis for most of
the theory of modern mathematics, at least as it has developed in western culture.

There  is,  however,  a  consistent  logical  system,  known  as  constructivist,  or  intuitionistic,  logic
which does not assume the law of excluded middle.

This results in a 3­valued logic in which one allows for a third possibility, namely, other.

In this system proving that a statement is “not true" is not the same as proving that it is “false,"
so that indirect proofs, which we shall soon discuss, would not be valid.

Logically Equivalent

Propositions r and s are logically equivalent if the statement r ⇔ s is a tautology. If r and s are
logically equivalent, we write

Page 43 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 3/8
Mathematical logic
8/20/2015 scorm content

A second notation often used to mean statements r and s are logically equivalent is r ⇔ s.

You can determine whether compound propositions r and s are logically equivalent by building a
single truth table for both propositions and checking to see that they have exactly the same truth
values.

Notice  the  new  symbol  r  ⇔  s,  which  is  used  to  denote  that  r  and  s  are  logically  equivalent,  is
denoted to mean the statement r ⇔ s is a tautology.

In a sense the symbols <­>$ and ⇔convey similar information when used in a sentence.

However,

r ⇔ s is generally used to assert that the statement.

r ⇔ s is, in fact, true while the statement.

r ⇔ s alone does not imply any particular truth value.

The symbol is the preferred shorthand for “equivalent to."

Example

(p → q) ^ (q → p) is logically equivalent to p ⇔ q.

The truth values of both propositions are identical.

Examine every possible case in which the statement (p → q) ^ (q → p) may not have the same
truth value as p ⇔ q.

Case1

Suppose (p → q) ^ (q → p) is false and p ⇔ q is true. There are two possible cases where (p →
q) ^ (q → p) is false.

Namely, p → q is false or q → p is false (note that this covers the possibility both are false since
we use the inclusive “or" on logic).

Page 44 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 4/8
Mathematical logic
8/20/2015 scorm content

Case2

If the latter is false, the p and q do not have the same truth value and the there are two possible
ways this may occur that we address below.

Logical Equivalences

Some of the important logical equivalences were

Page 45 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 5/8
Mathematical logic
8/20/2015 scorm content

Implication

The proposition r implies the proposition s and write r ⇒ s.

If r → s is a tautology.

We say the proposition r implies the proposition s and write r ⇒ s. if r → s is a tautology.

This is very similar to the ideas previously discussed regarding the ↔ verses ⇔

We use r ⇒ s to imply that the statement r → s is true, while that statement r → s alone does not
imply any particular truth value.

The symbol → is often used in proofs as a shorthand for “implies".

Well­formed Formula (WFF)

A well­formed formula (Syntax of compound proposition)

1. Any statement variable is a WFF.

2. For any WFF α, ¬α is a WFF.

3. If α and β are WFFs, then (α Ù β), (α Ú β), (α → β) and (α⇔β) are WFFs.

4. A finite string of symbols is a WFF only when it is constructed by steps 1, 2, and 3.

Substitution instance

A  WFF  A  is  a  substitution  instance  of  another  formula  B  if  A  is  formed  from  B  by  substituting
formulas  for  variables  in  B  under  condition  that  the  same  formula  is  substituted  for  the  same
variable each time that variable is occurred.

A substitution instance of a tautology is a tautology.

Page 46 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 6/8
Mathematical logic
8/20/2015 scorm content

Every compound proposition in the propositional variables p, q, r, ..., is uniquely equivalent to a
proposition  that  is  formed  by  taking  the  disjunction  of  conjunctions  of  some  combination  of  the
variables p; q; r; … or their negations. This is called the disjunctive normal form of a proposition.

The  disjunctive  normal  form  of  a  compound  proposition  is  a  natural  and  useful  choice  for
representing  the  proposition  from  among  all  equivalent  forms,  although  it  may  not  be  the
simplest representative.

We will find this concept useful when we arrive at the module on Boolean algebra.

Example

p is true and q is false

Solution

p is true and q is false or when p is true and q is true

Solution

Constructing Disjunctive Normal Forms

Page 47 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 7/8
Mathematical logic
8/20/2015 scorm content

The conjunctive normal form of a proposition is another “canonical form" that may occasionally
be useful, but not to the same degree as the disjunctive normal form.

The  conjunctive  normal  form  of  a  proposition  is  the  equivalent  form  that  consists  of  a
“conjunction of disjunctions.

It is easily constructed indirectly using disjunctive normal forms by observing that if you negate a
disjunctive normal form you get a conjunctive normal form.

For example, three applications of De Morgan′s Laws gives.

Page 48 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit2/assets/6.html 8/8
UNIT - 3
Boolean Algebra

Page 49 of 189
Boolean Algebra
8/20/2015 scorm content

 
Boolean Algebra

Boolean algebra provides the operations and the rules for working with the set {0, 1}.

These  are  the  rules  that  underlie  electronic  circuits,  and  the  methods  we  will  discuss  are
fundamental to VLSI design.

Boolean algebras are defined over sets

Two­valued Boolean algebra defined over {0,1} or {TRUE, FALSE}

Boolean algebras can be much more general and can be defined over much larger sets

We will soon define Boolean algebras over sets of functions

Definition

A lattice is a poset (A, €) in which any two elements have both a meet and a join.

Lattice: A poset with both meet and join for every pair of elements of the carrier set.

Boolean  Algebra:  A  distributed  and  complemented  lattice.  Every  lattice  has  a  unique  minimum
element and a unique maximum element.

Meet, Join, Unique maximum (1), minimum (0) element are always defined.

Idempotent: x +x =x x. x= x

Commutative: x +y= y+ x x. y= y. x

Associative: x +(y +z)=( x+ y)+ z x. (y. z)=(x. y). z

Absorptive: x .(x+ y)= x x+( x. y)= x

Absorptive properties are fundamental to optimization.

Complementation

If x+y=1 and x.y=0 then x is the complement of y and vice versa.

A lattice is complemented if all elements have a complement.

Definition: Given x,y which are elements of a lattice (A, ≤), x is a complement of y (written y’) if
x+y  =  1  and  x.y  =  0.  A  lattice  is  said  to  be  complemented  if  all  elements  have  a  complement.
Complements within a lattice are not necessarily unique.

As  an  example,  the  left  lattice  below  is  not  complemented  because,  although  c  and  b  are
complements,  d  has  no  complement.  The  right  lattice  below  is  complemented  and  e  has  two
complements, namely f and g.

Distributive Lattice

Let  [L;  V,  Λ]  be  a  lattice  (under  ≤).  .[L;  V,  Λ]is  called  a  distributive  lattice  if  and  only  if  the
Page 50 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/2.html 1/2
Boolean Algebra
8/20/2015 scorm content

distributive laws hold; that is, for all a, b, c € L, we have:

a V(bΛc) = (a V b)Λ(a V c) and

a Λ(b V c) = (a Λb)V (a Λc).

Since a lattice L is an algebraic system with binary operations Vand Λ, it is denoted by [L; V, Λ]

Page 51 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/2.html 2/2
Boolean Algebra
8/20/2015 scorm content

 
Duality

Every lattice identity is transformed into another identity by interchanging:

+ and ­

≤ and ≥

0 and 1

Example

x .(x + y) = x → x + (x .y) = x

The  principle  of  duality  states  that  every  lattice  identity  can  be  transformed  into  another  by
interchanging:

+ with ×, and vice­versa.

≤ with ≥, and vice­versa.

0 with 1, and vice­versa.

As an example, each of the lattice properties P0 through P4 has a dual.

Another example, a dual to the theorem exists that states that in any lattice (A, €), (x+y).(x+z) ≥
x+(y.z).

Principle of Duality

In  the  axioms  of  Boolean  algebra  (1)­(10),  in  an  equation  that  contains  V,  .,0,  or  1,  if  we
interchange V with ., and/or 0 with 1, then the another equation holds.

In general, this is true. In other words, given an equation in a Boolean algebra, the equation that
is obtained from the equation by interchanging Vwith ., and/or 0 with 1 also holds.

This property is the principle of duality.

Dual Boolean Expressions

Let A be a Boolean expression. The dual AD is defined recursively as follows:

O D = l.

I D = O.

If Xi is a variable, then Xi D = x ii = 1, ... , n).

If A, B, and C are Boolean expressions, and A = B V C, then A D =B D·C D.

If A, B, and C are Boolean expressions, and A = B . C, then A D =B D VC D.

If A and B’ are Boolean expressions, and A = B, then A D = (B D)’.


Page 52 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/3.html 1/2
Boolean Algebra
8/20/2015 scorm content

Page 53 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/3.html 2/2
Boolean Algebra
8/20/2015 scorm content

 
Algebraic Systems

The pair (V,≤) is called an algebraic system

V is a set, called the carrier of the system

≤ is a relation onV. V = V 2

(,⇒are similar to ≤)

This algebraic system is called a partially ordered set,or poset for short.

An algebraic system is a mathematical system consisting of a set called the domain and one or
more operations on the domain. If V is the domain and *1 , *2 , …, *n are the operations, [V;*1,
*2 , …, *n ] denotes the mathematical system. If the context is clear, this notation is abbreviated
to V.

Partially Ordered Sets

A poset has two operations, . and + called meet and join (like AND and OR).

Sometimes written (V,≤,.,+) or (V 2 ,≤,.,+) even((V,.,+) since ≤ is implied.

Boolean algebra provides the operations and the rules for working with the set {0, 1}.

Electronic and optical switches can be studied using this set and the rules of Boolean algebra.
The  three  operations  in  Boolean  algebra  that  we  will  use  most  are  complementation,  the
Boolean sum, and the Boolean product.

The complement of an element, denoted with a bar, is defined by 0 = 1and 1 = 0.

The Boolean sum, denoted by + or by OR, has the following values: 1 + 1 = 1, 1 + 0 = 1, 0 + 1 =
1, 0 + 0 = 0.

The Boolean product, denoted by · or by AND, has the following values: 1 · 1 = 1, 1 · 0 = 0, 0 · 1
= 0, 0 · 0 = 0.

Boolean Expressions and Boolean Functions

Let B = {0, 1}. Then B n  = {(x 1 , x 2 , . . . , x n ) | x i € B for 1 ≤ i ≤ n} is the set of all possible n­tuples


of 0s and 1s.

The  variable  x  is  called  a  Boolean  variable  if  it  assumes  values  only  from  B,  that  is,  if  its  only
possible values are 0 and 1.

A function from B n  to B is called a Boolean function of degree n.

EXAMPLE

The function F(x, y) = xy from the set of ordered pairs of Boolean variables to the set {0, 1} is a
Boolean function of degree 2 with F(1, 1) = 0, F(1, 0) = 1, F(0, 1) = 0, and F(0, 0) = 0.

Page 54 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/4.html 1/3
Boolean Algebra
8/20/2015 scorm content

Let B = {0, 1}. The variable x is called a Boolean variable if it assumes values only from B.

A  function  from  B n ,  the  set  {(x 1 ,  x 2 ,  …,  x n )  |xi  B,  1  i  n},  to  B  is  called  a  Boolean  function  of
degree n.

Definition: Let (B,) be a Boolean algebra and let x 1 , x 2 ,  ...,  xn  be  variables  taking  values  on  B.


Then the set of Boolean functions on x 1 , x 2 , ..., x n  consist of:

The constant functions f(x 1 , x 2 , ..., x n )=b for any element b€ B.

The projection functions f(x 1 , x 2 , ..., x n )=xi for any i=1,2,...,n.

If g and h are Boolean functions on x 1 , x 2 , ..., x n , then so are.

(g+h)(x 1 , x 2 , ..., x n ) = g(x 1 , x 2 , ..., x n )+h(x 1 , x 2 , ..., x n )

(g. h)(x 1 , x 2 , ..., x n )=g(x 1 , x 2 , ..., x n ). h(x 1 , x 2 , ..., x n )

(g’)(x 1 , x 2 , ..., x n )=(g(x 1 , x 2 , ..., x n ))’

A  function  is  a  Boolean  function  on  x 1 ,  x 2 ,  ...,  x n   if  and  only  if  it  can  be  derived  by  finite
application of the previous rules.

Definition: The set of Boolean functions f:{0,1}n ! {0,1} are called switching functions.

Minterm

There  is  a  simple  method  for  deriving  a  Boolean  expression  for  a  function  that  is  defined  by  a
table. This method is based on minterms.

Definition: A literal is a Boolean variable or its complement. A minterm of the Boolean variables
x 1 , x 2 , …, x n  is a Boolean product y 1 y 2 …y n , where y i = x i or y i = ­x i.

Hence, a minterm is a product of n literals, with one literal for each variable.

Example

Consider F(x,y,z)

F(x, y, z) = 1 if and only if:

x = y = z = 0 or

x = y = 0, z = 1 or

x = 1, y = z = 0

Therefore, F(x,y,z)=(­x)(­y)(­z)+(­x)(­y)z+x(­y)(­z)

Equivalent

Definition: The Boolean functions F and G of n variables are equal if and only if F(b 1 , b 2 , …, b n )

Page 55 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/4.html 2/3
Boolean Algebra
8/20/2015 scorm content

= G(b 1 , b 2 , …, b n ) whenever b 1 , b 2 , …, b n  belong to B.

Two different Boolean expressions that represent the same function are called equivalent.

For example, the Boolean expressions xy, xy + 0, and xy1 are equivalent.

The complement of the Boolean function F is the function F, where F(x 1 , . . . , x n ) = F(x 1 , . . . ,


x n ).

Let F and G be Boolean functions of degree n.

The Boolean sum F + G and the Boolean product FG are defined by

(F + G)(x 1 , . . . , x n ) = F(x 1 , . . . , x n ) + G(x 1 , . . . , x n ),

(F G)(x 1 , . . . , x n ) = F(x 1 , . . . , x n )G(x 1 , . . . , x n ).

Representing Boolean Functions

Any  Boolean  function  can  be  represented  by  a  Boolean  sum  of  Boolean  products  of  the
variables and their complements.

Every Boolean function can be represented using the three Boolean operators ·,+, and ..

The  disjunctive  normal  form  (DNF)  or  sum­of­products  expansion  of  a  degree­n.  Boolean
function f is the unique sum of minterms of the variables x1,…,xn that represents f.

A literal is a Boolean variable or its complement.

A maxterm is a sum of literals.

Conjunctive  Normal  Form  (CNF)  or  product­of­sums  expansion  is  a  product­of  maxterms
representation.

To find the CNF representation for f, take the DNF representation for complement ¬f,

Page 56 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/4.html 3/3
Boolean Algebra
8/20/2015 scorm content

 
Logic Gates

Boolean algebra is used to model the circuitry of electronic devices.

Each input and each output of such a device can be thought of as a member of the set {0, 1}.

A computer, or other electronic device, is made up of a number of circuits.

Each circuit can be designed using the rules of Boolean algebra.

The circuits that give output that depends only on the input, and not on the current state of the
circuit.

In other words, these circuits have no memory capabilities.

Such circuits are called combinational circuits or gating networks.

We construct combinational circuits using three types of elements.

The first is an inverter, which accepts the value of one Boolean variable as input and produces
the complement of this value as its output.

The next type of element we will use is the OR gate. The inputs to this gate are the values of two
or more Boolean variables. The output is the Boolean sum of their values.

The third type of element we will use is the AND gate. The inputs to this gate are the values of
two or more Boolean variables. The output is the Boolean product of their values.

Combinations of Gates

Combinational circuits can be constructed using a combination of inverters, OR gates, and AND
gates.

When combinations of circuits are formed, some gates may share inputs.

This is shown in one of two ways in depictions of circuits.

One  method  is  to  use  branchings  that  indicate  all  the  gates  that  use  a  given  input.  The  other
method is to indicate this input separately for each gate.

These are circuits composed of Boolean gates whose outputs depend only on their most recent
inputs, not on earlier inputs.

Thus these circuits have no useful memory.

Their state persists while the inputs are constant, but is irreversibly lost when the input signals
change.

Combinational Circuit Examples

Majority voting circuit.

Page 57 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/5.html 1/2
Boolean Algebra
8/20/2015 scorm content

XOR using OR / AND / NOT.

3­input XOR using OR / AND / NOT.

Half adder using OR/AND/NOT.

Full adder from half­adders.

Ripple­carry adders.

Adders

To design a circuit that carries out addition of two positive integers from their binary expansions.

The output will consist of two bits, namely s and c,where s is the sum bit and c is the carry bit.
This circuit is called a multiple output circuit.

We will build a circuit that can be used to find x + y, where x and yare two bits. The input to our
circuit will be x and y, because these each have the value 0 or the value 1.

The output will consist of two bits, namely, s and c, where s is the sum bit and c is the carry bit.
This circuit is called a multiple output circuit because it has more than one output.

Half adder

It adds two bits, without considering a carry from the previous addition.

TABLE Input and Output for the Half Adder.

Full adder

It computes the sum of bit and the carry bit when two bits and carry are added The input are the
bits x and y and the carry ci. The outputs are the sum bit s and the new carry ci+1.

TABLE Input and Output for the Full Adder.

Page 58 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/5.html 2/2
Boolean Algebra
8/20/2015 scorm content

 
Minimization of Circuits

The efficiency of a combinational circuit depends on the number and arrangement of its gates.

The process of designing a combinational circuit begins with the table specifying the output for
each combination of input values.

We can always use the sum­of­products expansion of a circuit to find a set of logic gates that will
implement this circuit.

Terms  in  a  sum­of­products  expansion  that  differ  in  just  one  variable,  so  that  in  one  term  this
variable occurs and in the other term the complement of this variable occurs, can be combined.

For instance, consider the circuit that has output 1 if and only if x = y = z = 1 or x = z = 1 and y =
0.

The sum­of­products expansion of this circuit is xyz + xyz.

The  two  products  in  this  expansion  differ  in  exactly  one  variable,  namely,  y.  They  can  be
combined as xyz + xyz = (y + y)(xz) = 1 · (xz)= xz.

Hence, xz is a Boolean expression with fewer operators that represents the circuit.

The second circuit uses only one gate, whereas the first circuit uses three gates and an inverter.

We will describe two procedures that simplify sum­of­products expansions.

The goal of both procedures is to produce Boolean sums of Boolean products that represent a
Boolean function with the fewest products of literals such that these products contain the fewest
literals possible among all sums of products that represent a Boolean function.

Finding such a sum of products is called minimization of the Boolean function.

Minimizing a Boolean function makes it possible to construct a circuit for this function that uses
the  fewest  gates  and  fewest  inputs  to  the  AND  gates  and  OR  gates  in  the  circuit,  among  all
circuits for the Boolean expression we are minimizing.

Minimisation with NAND gates

When designing combinational circuits, efficient is sought by minimizing the number of gates (or
switches) in a circuit.

Many computer circuits make use of another gate called a NAND gate which is used to replace
NOT AND, thereby reducing the number of gates.

The NAND gate receives inputs a and b and the output is denoted by a↑b.

The NAND Gate as a Universal Logic Element:

The NAND gate is a universal gate because it can be used to produce the NOT, the AND, the
OR, and the NOR functions.

Page 59 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/6.html 1/2
Boolean Algebra
8/20/2015 scorm content

An  inverter  can  be  made  from  a  NAND  gate  by  connecting  all  of  the  inputs  together  and
creating, in effect, a single input, for a 2­input gate.

An  AND  function  can  be  generated  by  the  use  of  NAND  gates  alone.  An  OR  function  can  be
produced with only NAND gates. Finally, a NOR function is produced as shown in fig.

The NOR Gate as a Universal Logic Element

Like  the  NAND  gate,  the  NOR  gate  can  be  used  to  produce  the  NOT,  AND.  OR  and  NAND
functions.

A NOT circuit, or inverter, can be made from a NOR gate by connecting all of the inputs together
to  effectively  create  a  single  input,  with  a  2­input  example.  Also,  an  OR  gate  can  be  produced
from NOR gates. An AND gate can be constructed by the use of NOR gates.

In this case the NOR gates G 1 and G 2 are used as inverters, and the final output is as follows:
X=A+B=AB

Fig. shows how NOR gates are used to form a NAND function.

Page 60 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/6.html 2/2
Boolean Algebra
8/20/2015 scorm content

 
2 Parallel Binary Adders

A single full­adder is capable of adding two 1­bit numbers and an input carry.

To add binary numbers with more than one bit, you must use additional full­adders.

When one binary number is added to another, each column generates a sum bit and a 1 or 0
carry bit to the next column to the left, as illustrated here with 2­bit numbers.

To add two binary numbers, a full­adder is required for each bit in the numbers.

So, for 2­bit numbers, two adders are needed; for 4­bit numbers, four adders are used; and so
on.

The carry output of each adder is connected to the carry input of the next higher­order adder for
a 2­bit adder.

Notice that either a half­adder can be used for the least significant position or the carry input of a
full adder can be made 0 (grounded) because there is no carry input to the least significant bit
position.

Four­Bit Parallel Adders

A group of four bits is called a nibble. A basic 4­bit parallel adder is implemented with four full­
adder stages.

The LSBs (A1 and B1) in each number being added go into the right­most full­adder: the higher­
order bits are applied as shown to the successively higher­order added, with the MSBs (A and B)
in each number being applied to the left­most full­adder.

The Carry output of each adder is connected to the carry input of the next higher­order adder as
indicated. These are called internal carries.

Switching Circuits

A network of switches can be used to represent a Boolean expression and an associated truth
table.

Generally the switches are used to control the flow of an electrical current but you might find it
easier  to  consider  switching  circuits  as  a  series  of  water  pipes  with  taps  or  valves  at  certain
points.

One of the reasons for using switching circuits rather than logic gates is that designers need to
movee  from  a  combinational  circuit  towards  a  design  which  the  manufacturer  can  use  for  the
construction of the electronic circuits.

This diagram shows switches A, B, and C which can be open or closed.

If a switch is closed it is shown as 1 in the following table whilst 0 shows that the switch is open.
The switching table for this circuit is as follows:

Page 61 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/7.html 1/2
Boolean Algebra
8/20/2015 scorm content

A series circuit, often called an AND gate, A V B.

A parallel circuit, often called an AND gate, A Λ B.

Page 62 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/7.html 2/2
Boolean Algebra
8/20/2015 scorm content

 
Karnaugh Map:

To reduce the number of terms in a Boolean expression representing a circuit, it is necessary o
find terms to combine.

There is a graphical method, called a Karnaugh map or K­map,for finding terms to combine for
Boolean functions involving a relatively small number of variables.

A  Karnaugh  map  provides  a  systematic  method  for  simplifying  Boolean  expressions  and,  if
properly  used,  will  produce  the  simplest  SOP  or  POS  expression  possible,  known  as  the
minimum expression.

A Karnaugh map is similar to a truth table because it presents all of the possible values of input
variables and the resulting output for each value.

Karnaugh maps can be used for expressions with two, three, and four and five variables.

2­Variable Karnaugh Map

There are four possible minterms in the sum­of­products expansion of a Boolean function in the
two variables x and y.

A K­map for a Boolean function in these two variables consists of four cells, where a 1 is placed
in the cell representing a minterm if this minterm is present in the expansion.

Cells are said to be adjacent if the minterms that they represent differ inexactly one literal. For
instance, the cell representing xy is adjacent to the cells representing xy and x y. The four cells
and the terms that they represent are shown in Figure.

If there are 1s in two adjacent cells in the K­map, the minterm represented by these cells can be
combined into a product involving just one of the variables. e. g. x y+x y=(x+x)y.

If 1s are in all four cells, the four minterms can be combined into one term, i.e. 1 involving none
of the variables.

To  circle  the  blocks  of  cells  that  can  be  combined.  The  goal  is  to  identify  the  largest  possible
blocks,  and  to  cover  all  the  1’s  with  the  fewest  blocks  using  the  largest  blocks  first  and  always
using the largest possible blocks.

The 3­Variable Karnaugh Map

A  K­map  in  three  variables  is  a  rectangle  divided  into  eight  cells.  The  cells  represent  the  eight
possible minterms in three variables.

Two cells are said to be adjacent if the minterms that they represent differ in exactly one literal.
One of the ways to form a K­map in three variables is shown in Figure.

The 3­variable Karnaugh map is an array of eight cells as shown in Fig. In this case, A, B, and C
are used for the variables although other letters could be used.

Binary values of A and B are along the left side (notice the sequence) and the values of C are
Page 63 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/8.html 1/4
Boolean Algebra
8/20/2015 scorm content

across the top. The value of a given cell is the binary values of A and B at the left in the same
row combined with the value of C at the top in the same column.

For example, the cell in the upper left corner has a binary value of 000 and the cell in the lower
right  corner  has  a  binary  value  of  101  Fig.(  shows  the  standard  product  terms  that  are
represented by each cell in the Karnaugh map.

The 4­Variable Karnaugh Map

A  K­map  in  four  variables  is  a  square  that  is  divided  into  16  cells.  The  cells  represent  the  16
possible minterms in four variables.

The  4­variable  Karnaugh  map  is  an  array  of  sixteen  cells,  as  shown  in  Fig.  Binary  values  of  A
and B are along the left side and the values of C and D are across the top. The value of a given
cell is the binary values of A and B at the left in the same row combined with the binary values of
C and D at the top in the same column.

For  example,  the  cell  in  the  upper  right  corner  has  a  binary  value  of  0010  and  the  cell  in  the
lower  right  corner  has  a  binary  value  of  1010.  Fig.  shows  the  standard  product  terms  that  is
represented by each cell in the 4­variable Karnaugh map.

Karnaugh map SOP Minimization

For an SOP expression in standard form, a 1 is placed on the Karnaugh map for each product
term in the expression.

Each  1  is  placed  in  a  cell  corresponding  to  the  value  of  a  product  term.  For  example,  for  the
product term ABC, a 1 goes in the 10l cell on a 3­variable map.

Example: Map the following standard SOP expression on a Karnaugh map:

Karnaugh Map Simplification of SOP Expressions

Grouping  the  1s,  you  can  group  1s  on  the  Karnaugh  map  according  to  the  following  rules  by
enclosing those adjacent cells containing 1s. The goal isto maximize the size of the groups and
to minimize the number of groups.

A group must contain either 1, 2, 4, 8, or 16 cells, which are all powers of two. In the case of a 3­
variable map, 23 = 8 a cell is the maximum group.

Each cell in a group must be adjacent to one or more cells in that same group.

Always include the largest possible number of 1s in a group in accordance with rule 1.

Each  1  on  the  map  must  be  included  in  at  least  one  group.  The  1s  already  in  a  group  can  be
included in another group as long as the overlapping groups include non­common 1s.

Karnaugh map POS Minimization

Page 64 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/8.html 2/4
Boolean Algebra
8/20/2015 scorm content

The  approaches  are  much  the  same  except  that  with  POS  expressions,  0s  representing  the
standard sum terms are placed on the Karnaugh map instead of 1s.

For a POS expression in standard form, a 0 is placed on the Karnaugh mapfor each sum term in
the  expression.  Each  0  is  placed  in  a  cell  corresponding  to  the  value  of  a  sum  term.  For
example, for the sum term A + B + C, a 0goes in the 0 1 0 cell on a 3­variable map.

When  a  POS  expression  is  completely  mapped,  there  will  be  a  number  of  0son  the  Karnaugh
map equal to the number of sum terms in the standard POSexpression.

The cells that do not have a 0 are the cells for which the expression is 1. Usually, when working
with POS expressions, the 1s are left off. The following steps and the illustration in Fig. show the
mapping process.

Step 1. Determine the binary value of each sum term in the standard POSexpression. This is the
binary value that makes the term equal to 0.

Step  2.  As  each  sum  term  is  evaluated,  place  a  0  on  the  Karnaugh  map  in  the  corresponding
cell.

Karnaugh Map Simplification of POS Expressions

The  process  for  minimizing  a  POS  expression  is  basically  the  same  as  for  an  SOP  expression
except  that  you  group  0s  to  produce  minimum  sum  terms  instead  of  grouping  1s  to  produce
minimum product terms.

The rules for grouping the 0s are the same as those for grouping the 1s that you learned before.

Example: Use a Karnaugh map to minimize the following standard POS expression:

Five­Variable Karnaugh maps

Boolean  functions  with  five  variables  can  be  simplified  using  a  32­cell  Karnaugh  map.  Actually,
two 4­variable maps (16 cells each) are used to construct a 5­variable map.

A Karnaugh map for five variables (ABCDE) can be constructed using two4­variable maps with
which you are already familiar. Each map contains 16cells with all combinations of variables B,
C, D, and E. One map is for A = 0 and the other is for A = 1, as shown in fig..

The best way to visualize cell adjacencies between the two 16­cel1maps is to imagine that the A
= 0 map is placed on top of the A = 1 map.

Each cell in the A = 0 map is adjacent to the cell directly below it in the A =1 map.

"Don′t Care" Conditions

In some circuits we care only about the output for some combinations of input values, because
other combinations of input values are not possible or never occur.

This gives us freedom in producing a simple circuit with the desired output because the output
values for all those combinations that never occur can be arbitrarily chosen.

Page 65 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/8.html 3/4
Boolean Algebra
8/20/2015 scorm content

The values of the function for these combinations are called don′t care conditions.

For example, recall that in the BCD code there are six invalid combinations: 1010, 1011, 1100,
1101, 1110, and 1111. Since these unallowed states will never occur in an application involving
the BCD code,they can be treated as "don′t care" terms with respect to their effect on the output.

That  is,  for  these  "don′t  care"  terms  either  a  1  or  a  0  may  be  assigned  to  the  output:  it  really
does not matter since they will never occur.

The  "don′t  care"  terms  can  be  used  to  advantage  on  the  Karnaugh  map.  Fig.  shows  that  for
each "don′t care" term, an X is placed in the cell.

When grouping the 1 s, the Xs can be treated as 1s to make a larger grouping or as 0s if they
cannot be used to advantage. The larger a group, the simpler the resulting term will be.

The truth table in Fig.describes a logic function that has a 1 output only when the BCD code for
7,8, or 9 is present on the inputs. If the "don′t cares" are used as 1s, the resulting expression for
the  function  is  A  +  BCD,as  indicated  in  part  (b).  If  the  "don′t  cares"  are  not  used  as  1s,  the
resulting expression is ABC + ABCD: so you can see the advantage of using "don′t care" terms
to get the simplest expression.

Page 66 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit3/assets/8.html 4/4
UNIT - 4
Number Theory

Page 67 of 189
Number Theory
8/20/2015 scorm content

 
The principle of Induction

More generally, we may apply the principle of induction whenever the universe of discourse is a
set of integers of the form f{k, k + 1, k + 2…} where k is some fixed integer.

Let P(n) be a predicate over f{k, k + 1, k + 2…}, where k belongs to Z. If

(1) P(k), and

P(n) v P(n + 1) then vnP(n).

In this context the “for all n", of course, means for all n >= k.

While  the  principle  of  induction  is  a  very  useful  technique  for  proving  propositions  about  the
natural numbers, it isn′t always necessary.

Why  does  the  principle  of  induction  work?  This  is  essentially  the  domino  effect.  Assume  you
have shown the premises. In other words you know P(0) is true and you know that P(n) implies
P(n + 1) for any integer n >=0.

Using Mathematical Induction. Steps

Prove the basis step.

Prove the inductive step.

Assume P(n) for arbitrary n in the universe. This is called the induction hypothesis.

Prove P(n + 1) follows from the previous steps.

The First Principle of Mathematical Induction

If a set of positive integers has the property that, if it contains the integer k, then it also contains
k + 1, and if this set contains 1 then it must be the set of all positive integers.

More generally, a property concerning the positive integers that is true for n = 1, and that is true
for the integer n + 1 whenever it is true for the integer n, must be true for all positive integers.

We use the well ordering principle to prove the first principle of mathematical induction.

Proof:

Let S be the set of positive integers containing the integer 1, and the integer k + 1 whenever
it contains k.

Assume also that S is not the set of all positive integers.

As a result, there are some integers that are not contained in S and thus those integers must
have a least element α by the well ordering principle.

Notice that α =! 1 since 1 ϵ S. But α ­ 1 ϵ S and thus using the property of S, α ϵ S.

Page 68 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/2.html 1/2
Number Theory
8/20/2015 scorm content

Example ­ 1

Example ­ 2

Page 69 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/2.html 2/2
Number Theory
8/20/2015 scorm content

 
The Second Principle of Mathematical Induction

A  set  of  positive  integers  that  has  the  property  that  for  every  integer  k,  if  it  contains  all  the
integers  1  through  k  then  it  contains  k  +  1  and  if  it  contains  1  then  it  must  be  the  set  of  all
positive integers.

More generally, a property concerning the positive integers that is true for n = 1, and that is true
for all integers up to n + 1 whenever it is true for all integers up to n, must be true for all positive
integers.

The second principle of induction is also known as the principle of strong induction. Also, the first
principle of induction is known as the principle of Weak induction.

To prove the second principle of induction, we use the first principle of induction.

Proof.  Let  T  be  a  set  of  integers  containing  1  and  such  that  for  every  positive  integer  k,  if  it
contains 1, 2, … k, then it contains k + 1.

Let S be the set of all positive integers k such that all the positive integers less than or equal to k
are in T. Then 1 is in S, and we also see that k + 1 is in S.

Thus  S  must  be  the  set  of  all  positive  integers.  Thus  T  must  be  the  set  of  all  positive  integers
since S is a subset of T.

Example ­ 1

Prove:  Every  integer  n≥2  can  be  expressed  as  a  product  of  one  or  more  prime  numbers.  A
prime number is defined to be an integer greater than one that is only divisible by itself and one.

Proof.  Recall  that  a  prime  number  is  an  integer  ≥  2  that  is  only  divisible  by  itself  and  1.  (The
number 1 is not considered to be prime.)

Let P(n) be the predicate “n can be expressed as a product of prime numbers."

Basis Step, n = 2: Since 2 is prime, 2 can be expressed as a product of prime numbers in a
trivial way (just one factor). Thus, P(2) is true.

Induction Step: Let n be an integer with n ≥ 2. Suppose that every integer j, 2 ≤ j ≤ n, can be
expressed as a product of prime numbers.

The integer n + 1 is either a prime number or it is not.

Example ­ 2

In  this  example,  the  first  principle  of  induction  would  be  virtually  impossible  to  apply,  since  the
integer n is not a factor of n + 1 when n ≥ 2.

That is, knowing the factors of n doesn′t tell us anything about the factors of n + 1.

Case 1. If n + 1 is a prime number, then it is a product of prime numbers in a trivial way.

Page 70 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/3.html 1/3
Number Theory
8/20/2015 scorm content

Case 2. If n + 1 is not a prime number, then n + 1 = a . b where a and b are positive integers,
both different from n + 1 and 1.

Thus, 2 ≤ a ≤ n and 2 ≤ b ≤ n. By the induction hypothesis, a and b can each be expressed as a
product of prime numbers, say a = p1p2… pr and b = q1q2… qs.

Since  n  +  1  =  a  .b  =  p1p2…pr  q1q2  …qs,  n  +  1  can  also  be  expressed  as  a  product  of  prime
numbers, namely, the product of primes that multiply to give a times the product of primes that
multiply to give b.

By the second principle of mathematical induction, every n ≥ 2 can be expressed as a product of
prime numbers.

Example ­ 3

Example ­ 4

In  Example  2,  the  predicate,  P(n),  is  5n+5  ≤  n 2 ,  and  the  universe  of  discourse  is  the  set  of
integers n >= 6. Notice that the basis step is to prove P(6).

Page 71 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/3.html 2/3
Number Theory
8/20/2015 scorm content

You might also observe that the statement P(5) is false, so that we can′t start the induction any
sooner.

In this example we are proving an inequality instead of equality.

This actually allows you more “fudge room", but sometimes that extra freedom can make it a bit
more difficult to see what to do next.

In this example, the hardest part, conceptually, is recognize that we need another inequality, 5 ≤
2n+1, which holds whenever n >= 2.

A good approach to showing f(n+1) ≤ g(n+1) is to start with f(n+1), think of a way express f(n +
1) in terms of f(n) so that you can use the induction hypothesis, Then find ways to get to g(n + 1)
using further equities or inequalities (that go in the right direction!).

In the induction step we use the fact that if you know a ≤ b, then a + 5 ≤ b + 5. The induction
hypothesis gives us an inequality. Then we add 5 to both sides of that inequality prove P(n + 1).

Example ­ 5

Prove: A set with n elements, n _ 0, has exactly 2 n  subsets.

Proof. Let P(n) be the statement “A set with n elements has 2n subsets."

Basis Step, n = 0: The only set with 0 elements is the empty set Ø , which has exactly one
subset,  namely  Ø.  We  also  have  2 0   =  1,  therefore  a  set  with  0  elements  has  exactly  20
subsets. Thus P(0).

Induction Step: Let n belongs to N. Assume P(n): every set with n elements has 2n subsets.

Use the induction hypothesis to prove a set with n + 1 elements has 2n+1 subsets.

Suppose A is a set with n + 1 elements, say, A = {a1, a2,… an, an+1}.

Let B be the subset {a1,a2,…,an} of A.

Since B has n elements, we can apply the induction hypothesis to B, which says that B has
exactly 2n subsets.

Each subset S of B corresponds to exactly two subsets of A, namely, S and S U {a n+1 }.

But  every  subset  of  A  is  of  one  of  these  two  forms;  hence,  A  has  exactly  twice  as  many
subsets as B. Thus, A has exactly 2 _ 2n = 2n+1 subsets.

By  the  principle  of  mathematical  induction  it  follows  that  a  set  with  n  elements  has  exactly  2n
subsets for all n >= 0.

Page 72 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/3.html 3/3
Number Theory
8/20/2015 scorm content

 
The Greatest Common Divisor

The greatest common divisor of two integers a and b is the greatest integer that divides both a
and b.

Two integers a and b, not both 0, can have only finitely many divisors, and thus can have only
finitely many common divisors.

In  this  section,  we  are  interested  in  the  greatest  common  divisor  of  a  and  b.  Note  that  the
divisors of a and that of | a | are the same.

We denote the greatest common divisor of two integers a and b by (a, b). We also define (0, 0) =
0.

The Greatest Common Divisor : Example

The greatest common divisor of 24 and 18 is 6. In other words (24, 18) = 6.

The greatest common divisor of 9 and 16 is 1, thus they are relatively prime.

There  are  couples  of  integers  (e.g.  3  and  4,  etc...)  whose  greatest  common  divisor  is  1  so  we
call such integers relatively prime integers.

Note that every integer has positive and negative divisors. If a is a positive divisor of m, then ­a
is also a divisor of m.

Therefore by our definition of the greatest common divisor, we can see that (a, b) = (| a |, | b |).

The Greatest Common Divisor : Theorem 1

The  theorem  states  that  if  we  divide  two  integers  by  their  greatest  common  divisor,  then  the
outcome is a couple of integers that are relatively prime.

If (a, b) = d then (a/d, b/d) = 1.

Proof. We will show that a=d and b=d have no common positive divisors other than

Assume that k is a positive common divisor such that k | a/d and k | b/d. As a result, there are
two positive integers m and n such that a/d = km and b/d = kn

Thus we get that a = kmd and b = knd

Hence  kd  is  a  common  divisor  of  both  a  and  b.  Also,  kd  >=  d.  However,  d  is  the  greatest
common divisor of a and b. As a result, we get that k = 1.

The Greatest Common Divisor : Theorem 2

The greatest common divisor of two integers does not change when we add a multiple of one of
the two integers to the other.

Let a; b and c be integers. Then (a, b) = (a + cb, b)

Page 73 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/4.html 1/3
Number Theory
8/20/2015 scorm content

Proof. We will show that every divisor of a and b is also a divisor of a + cb and b and vise versa.
Hence they have exactly the same divisors. So we get that the greatest common divisor of a and
b will also be the greatest common divisor of a + cb and b.

Let  k  be  a  common  divisor  of  a  and  b.  By  Theorem  1,  k  |  (a  +  cb)  and  hence  k  is  a  divisor  of
a+cb.

Now assume that l is a common divisor of a+cb and b. Also by Theorem 1 we have , l | ((a + cb)
­ cb) = a

As a result, l is a common divisor of a and b and the result follows.

The Greatest Common Divisor : Definition

Let  a1,  a2,…,an  be  integers,  not  all  0.  The  greatest  common  divisor  of  these  integers  is  the
largest integer that divides all of the integers in the set. The greatest common divisor of a1, a2,
…, an is denoted by (a1, a2,…, an).

The integers a1, a2,…,an are said to be mutually relatively prime if (a1, a2,…,an) = 1.

Example. The integers 3, 6, 7 are mutually relatively prime since (3, 6, 7) = 1 although (3, 6) = 3.

The integers a1, a2,…,an, are called pairwise prime if for each i != j, we have (ai, aj) = 1.

Example The integers 3, 14, 25 are pairwise relatively prime. Notice also that these integers are
mutually relatively prime.

Notice that if a1, a2,…,an are pairwise relatively prime then they are mutually relatively prime.

The Greatest Common Divisor : Theorem 3

This theorem proves that the greatest common divisor of two integers can be written as a linear
combination of the two integers.

The  greatest  common  divisor  of  two  integers  a  and  b,  not  both  0  is  the  least  positive  integer
such that ma + nb = d for some integers m and n.

Proof. Assume without loss of generality that a and b are positive integers. Consider the set of all
positive integer linear combinations of a and b. This set is non empty since a = 1 . a + 0 . b and b
= 0 . a + 1 . b are both in this set.

Thus this set has a least element d by the well­ordering principle.

Thus d = ma + nb for some integers m and n. We have to prove that d divides both a and b and
that it is the greatest divisor of a and b. By the division algorithm, we have a = dq + r, 0 . r < d

Thus we have r = a ­ dq = a ­ q(ma + nb) = (1 ­ qm)a ­ qnb

We then have that r is a linear combination of a and b. Since 0 _ r < d and d is the least positive
integer which is a linear combination of a and b, then r = 0 and a = dq.

As a result, we conclude that if (a, b) = 1 then there exist integers m and n such that ma + nb =

Page 74 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/4.html 2/3
Number Theory
8/20/2015 scorm content

1.

Page 75 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/4.html 3/3
Number Theory
8/20/2015 scorm content

 
The Euclidean Algorithm

A systematic method that determines the greatest common divisor of two integers. This method
is called the Euclidean algorithm.

If a and b are two integers and a = bq + r where also q and r are integers, then (a, b) = (r, b). we
have (bq + r, b) = (b, r)

The  above  lemma  will  lead  to  a  more  general  version  of  it.  We  now  present  the  Euclidean
algorithm in its general form. It states that the greatest common divisor of two integers is the last
non zero remainder of the successive division.

Let  a  =  r 0  and b = r 1   be  two  positive  integers  where  a  >=  b.  If  we  apply  the  division  algorithm
successively to obtain that

Notice that, we will have a remainder of 0 eventually since all the remainders are integers and
every remainder in the next step is less than the remainder in the previous one. we see that

Note that

Page 76 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/5.html 1/3
Number Theory
8/20/2015 scorm content

Hence (4147, 10672) = 29:

We  now  use  the  steps  in  the  Euclidean  algorithm  to  write  the  greatest  common  divisor  of  two
integers as a linear combination of the two integers.

The  following  example  will  actually  determine  the  variables  m  and  The  following  algorithm  can
be described by a general form but for the sake of simplicity of expressions we will present an
example  that  shows  the  steps  forobtaining  the  greatest  common  divisor  of  two  integers  as  a
linear combination of the two integers.

Example: 1

Example 2

Euclidean algorithm to find the greatest common divisor of two positive integers has number of
divisions  less  than  or  equal  five  times  the  number  of  decimal  digits  in  the  minimum  of  the  two
Page 77 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/5.html 2/3
Number Theory
8/20/2015 scorm content

integers.

Let  a  and  b  be  two  positive  integers  where  a  >  b.  Applying  the  Euclidean  algorithm  to  find  the
greatest common divisor of two integers with a = r0 and

Example 3

Notice that each of the quotients q1, q2,…, qn­1 are all greater than 1 and qn >= 2 and this is
because rn < rn­1. Thus we have

Page 78 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/5.html 3/3
Number Theory
8/20/2015 scorm content

 
Equivalence relation

An equivalence relation on a set S, is a relation on S which is reflexive, symmetric and transitive.

In general an equivalence relation results when we wish to “identify” two elements of a set that
share a common attribute.

The  definition  is  motivated  by  observing  that  any  process  of  “identification”  must  behave
somewhat like the equality relation, and the equality relation satisfies the reflexive (x = x for all
x), symmetric (x = y implies y = x), and transitive (x = y and y = z implies x = z) properties.

Example ­ 1

Example ­ 2

Equivalence Classes

Given  an  equivalence  relation  R  on  a  set  S,  we  define  the  equivalence  class  containing  an
element x of S by:

Page 79 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/6.html 1/3
Number Theory
8/20/2015 scorm content

Let  R  be  an  equivalence  relation  on  A  and  let  a  ϵ  A.  The  set  [a]  =  {x|aRx}  is  called  the
equivalence class of a.

The  element  in  the  bracket  in  the  above  notation  is  called  the  Representative  of  the
equivalence class.

Equivalence Theorem

Equivalence Theorem Explanation

Let R be an equivalence relation on a set A. Then the following are equivalent:

Page 80 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/6.html 2/3
Number Theory
8/20/2015 scorm content

The purpose of any identification process is to break a set up into subsets consisting of mutually
identified elements.

An  equivalence  relation  on  a  set  A  does  precisely  this:  it  decomposes  A  into  special  subsets,
called equivalence classes.

Looking back at the example given, we see the following equivalence classes:

These ideas are summed up in Theorem. When we say several statements, such as P1, P2, and
P3 are equivalent, we mean P1 P2 P3 is true.

Notice that in order to prove that the statements are mutually equivalent, it is sufficient to prove a
circle of implications, such as P1 ! P2 ­> P3 ­> P1. This is how we set up the proof of Theorem.

Page 81 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/6.html 3/3
Number Theory
8/20/2015 scorm content

 
Partition

A collection S of nonempty subsets of a set A is a partition of A if

If S is a set with an equivalence relation R, then it is easy to see that the equivalence classes of
R form a partition of the set S. More interesting is the fact that the converse of this statement is
true.

Partition Theorem

The equivalence classes of an equivalence relation on A form a partition of A.

Conversely, given a partition on A, there is an equivalence relation with equivalence classes that
are exactly the partition given.

The  definition  along  with  theorem  describes  formally  the  properties  of  an  equivalence  relation
that motivates the definition. Such decomposition is called a partition.

For example, if we wish to identify two integers if they are either both even or both odd, then we
end up with a partition of the integers into two sets, the set of even integers and the set of odd
integers.

The  converse  of  Theorem  allows  us  to  create  or  define  an  equivalence  relation  by  merely
partitioning a set into mutually exclusive subsets.

The  common  “attribute”  then  might  just  be  that  elements  belong  to  the  same  subset  in  the
partition.

If R is an equivalence relation on a set A, the set of equivalence classes of R is denoted A/R.

Suppose R is an equivalence relation on A and S is the set of equivalence classes of R.

If S is an equivalence class, then S = [a], for some a ϵ A; hence, S is nonempty, since aRa by the
reflexive property of R.

By partition Theorem 1, if S = [a] and S0 = [b] are in S, then [a] = [b] iff [a] ∩ [b] ≠ Ø.

Since this is a biconditional, this statement is equivalent to [a] ≠ [b] iff [a] ∩ [b] = Ø.

Since  each  equivalence  class  is  contained  in  A,  S  {S|S  ϵ  S}  C  A.  But,  as  we  just  saw,  every
element in A is in the equivalence class it represents, so A,U S{S|S ϵ S}. This shows S{S|S ϵ S} =
A.

Page 82 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/7.html 1/1
Number Theory
8/20/2015 scorm content

 
Intersection of Equivalence Relations

If R1 and R2 are equivalence relations on a set A then R1 ∩ R2 is also an equivalence relation
on A.

To prove this, it suffices to show the intersection of

Reflexive relations is reflexive,

Symmetric relations is symmetric, and

Transitive relations is transitive.

Example

Let m be a positive integer. The relation a ≡ b (mod m), is an equivalence relation on the set of
integers.

Proof. Reflexive. If a is an arbitrary integer, then a − a = 0 = 0 · m. Thus a ≡ a (mod m).

Symmetric. If a ≡ b (mod m), then a − b = k · m for some integer k. Thus, b − a = (−k) · m is also
divisible by m, and so b ≡ a (mod m).

Transitive. Suppose a ≡ b (mod m) and b ≡ c (mod m). Then a − b = k · m and b − c = l · m for
some integers k and l. Then a − c = (a − b) + (b − c) = k · m + l · m = (k + l) m is also divisible by
m. That is, a ≡ c (mod m).

Infimum

If a ϵA is a lower bound for B if for every b ϵB, a R b. Also, a is called a greatest lower bound (or
infimum) for B if

a is a lower bound for B, and

x R a for every lower bound x for B.

In  the  example  (Hasse  diagram),  consider  B  =  {2,3}.  Both  6  and  12  are  upper  bounds  of  this
subset and 6 is the sup(B).

The only lower bound of B is 1 and inf(B) = 1.

Now let B = {4,6}. Sup{B) = 12 and Inf(B) = 2. Consider the set C = {2,3,5}. There is no upper
bound for C, and 1 is a lower bound and also inf(C).

Page 83 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/8.html 1/1
Number Theory
8/20/2015 scorm content

 
Fibonacci numbers

Fibonacci  numbers,  the  mathematics  associated  with  them  is  interesting  and  because
(surprisingly) they are intimately related with the complexity analysis of the Euclidean algorithm.

Here are the first 16 Fibonacci numbers:

The convention is to start numbering at zero, so that we have listed the Oth, the 1st, ..., and the
15th Fibonacci number.

We denote the nth Fibonacci number by Fn for each non negative integer n.

There is an easy method for obtaining the Fibonacci numbers. First, F. = O, F1 = 1, and then for
all n >=2, Fn=Fn­1+Fn­2

Fibonacci numbers and Mathematical Induction

Since the nth Fibonacci number is defined in terms of smaller Fibonacci numbers, it is natural to
try to build proofs about these numbers using induction.

However, the nth Fibonacci number is not defined solely in terms of its immediate predecessor,
but rather in terms of two predecessors. Consequently, we need a strengthening of our induction
machine.

Algorithm INDUCTION

STEP 1. Verify the base case.

STEP 2. Assume that Pk is true for an arbitrary value of k.

STEP 3. Verify that Pk + 1 is true, using the assumption that Pk is true.

Fibonacci numbers and Complete Induction

Sometimes  the  truth  of  Pk+1  depends  on  the  truth  of  more  than  one  of  the  preceding  Pj’s  or
depends on the truth of Pj, where j < k. There is still hope for the method of induction if we use
the following principle, which is known as Complete Induction.

Suppose that Pn is a proposition that depends upon the positive integer n. Then Pn is true for all
n >= N, (where N is some fixed integer) provided that

PN is true, and

if PN, PN+1,. ... and PN are all true, then so is PN+1.

There are two changes here. First we’ve introduced an unspecified constant N.

In the original version of induction we always mentioned the base case P1 although we admitted
Page 84 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/9.html 1/4
Number Theory
8/20/2015 scorm content

that the base case might start off at Po.

Fibonacci numbers and Complete Induction

The second difference between induction and complete induction is in the inductive hypothesis.
In  this  second  version  we  assume  that  PN,  PN  +1,.  .  .,  and  PN  are  all  true.  Since  we  assume
more, it should be easier to use this form. The algorithmic version of complete induction.

Algorithm INDUCTION

STEP 1. (The base cases). Verify that PN, PN+1,. . . . l PN +jj are valid for some constants N
and j (depending upon the problem).

STEP 2. (The inductive hypothesis). Assume that PN, PN+1,. . . . and PN are all true for an
arbitrary value of k.

STEP 3. (The inductive step). Verify that PN+1 is true, using the inductive hypothesis.

There is one more change, introduced in this algorithm, namely the constant j in Step 1. At times
we shall need to check more than one base case, depending on the proof we construct, to show
that pk + 1 is true. The value of j depends upon the number of Pk,Pk+1,. . . . Pk that we refer
back to in our verification of Pk + 1.

Fibonacci numbers: Theorem

Every integer n >1 has a prime divisor.

The statement gives the starting point of the proposition N = 2. This statement is true for n = 2,
since 2 is a prime number and divides itself. Similarly, the statement is valid for n = 3, since 3 is
a prime.

We check that it is also true fern =4=2.2. The inductive hypothesis tells us to assume the truth of
the statement for n = 2,3, ..., k, for some arbitrary value of k.

To accomplish the inductive step, we must prove the result that the integer (k + 1) has a prime
divisor. Now either (k + 1) is a prime or it isn’t. If (k + 1) is a prime, then it has itself as a prime
divisor.

If (k + 1) is not a prime, then k + 1 = bc, where b and c satisfy 1< b < (k + 1) and 1 < c < (k + 1).
Consider b. By the inductive hypothesis, since 1< b < (k + 1), we may assume that b has a prime
divisor, say p. Then k+l

Every integer n >1 has a prime divisor.

We see that (k + 1)/p is an integer, since it is expressed as the product of two integers.

This means that p is a divisor of (k + 1) and so (k + 1) has a prime divisor, namely p. q Note that

Page 85 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/9.html 2/4
Number Theory
8/20/2015 scorm content

we could not have used the standard form of induction in this problem because the truth of the
assertion Pk+1 depends not on the truth of Pk, but on the truth of Pb, where b is less than k.

Since  our  proof  depends  upon  only  one  earlier  case,  P~  with  1  <  b  <  (k  +  1),  our  base  case
needed  only  one  value,  namely  N  =  2  and  j  =  O,  although  to  get  a  feel  for  the  problem  we
checked  three  base  cases.  We  now  use  complete  induction  to  establish  some  facts  about  the
Fibonacci numbers.

Fibonacci numbers: Rabbit­out­of­the­hat tricks

Find an integer N such that FN> (3/2)N. Prove by induction that

Which is rabbit­out­of­the­hat tricks with the Fibonacci numbers.

A pair of rabbits requires one month to mature to the age when it can reproduce. Suppose that
the rabbits then mate and produce another pair in every subsequent month, and that the pair of
offspring is always conveniently one male and one female, who then form a new breeding pair.

If in the first month we have one pair of rabbits, how many pairs do we have at the beginning of
the  nth  month?  For  simplicity,  we  assume  no  death  or  loss  of  fertility.  We  call  the  resulting
number R. At the beginning of the first month we have one pair, so RI = 1.

At the beginning of the second month we still have one pair, but during the second month they
produce  a  pair  of  bunnies.  Thus  Rz  =  1  and  R3  =  2.  During  the  third  month  the  original  pair
produces another pair of bunnies, but the new pair of bunnies doesn’t reproduce yet. So R4 = 3.
Then R5 = 5.

We might as well argue the general case That is, let’s determine R. in terms of previous values
of R. At the beginning of the nth month we have all the rabbit pairs that we had at the beginning
of the (n – l)st month, R.­~, plus some new bunny pairs.

The  number  of  new  bunny  pairs  is  the  number  of  rabbit  pairs  that  are  at  least  one  month  old.
The  rabbit  pairs  that  are  this  old  are  precisely  those  that  were  around  in  the  (n  –  2)nd  month,
Rn­2.. In symbols then Rn=Rn­1 + Rn­2

Now we see that the R. are exactly the same as the Fibonacci numbers and that R. = F. for all
positive n. Fibonacci numbers arise in other natural settings.

For example, the spacing of leaves on some plants and some arrangements of flower petals and
seeds are closely related to the Fibonacci numbers. Mollusk shells spiral in curves derived from
Fibonacci numbers.

Ratios  of  successive  Fibonacci  numbers,  like  5/3,  3/8,  and  &  are  considered  aesthetically
pleasing.  The  squares  in  Figure  4.1  each  have  sides  equal  to  a  Fibonacci  number.  They
combine to make rectangles with sides in ratios of 34 to 21, 21 to 13, 13 to 8, 8 to 5, 5 to 3, 3 to
2, and 2 to 1. In fact, for large values of n, Fn/Fn ­1 gets arbitrarily close to a constant.

Fibonacci Squares

Page 86 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/9.html 3/4
Number Theory
8/20/2015 scorm content

The Fibonacci numbers are even thought to be useful in predicting highs and lows on the stock
market.  These  numbers  have  so  many  interesting  and  varied  properties  that  there  is  a
mathematics  research  journal,  the  Fibonacci  Quarterly,  dedicated  to  results  about  Fibonacci
numbers.

The  defining  property  is  useful  for  proving  results  about  Fibonacci  numbers  by  induction.  But
one  thing  seems  missing  from  our  knowledge.  Is  there  a  formula  for  Fn?  Or  to  calculate,  say,
F17 must we determine all the smaller Fibonacci numbers? Yes and maybe no, respectively. We
shall write down a formula for F., but we stress that in most situations the inductive definition that
Fn = Fn­1 + Fn­2 is the most helpful fact to know.

Fibonacci Numbers Contradictions

To calculate F. by adding as shown above appears to require that we store all of FO, Fl . . . Fn­
1.  Is  it  possible  to  calculate  F.  by  addition  without  storing  all  the  previous  values  in  n  different
memory locations? What is the minimum number of memory locations that you need to calculate
F. in this way.

The second way we now have to calculate Fn is using the formula in previous stated theorem.
This requires two exponentiation, one division and one subtraction as well as an approximation
of the square root of 5.

There are a variety of additional methods known for calculating F., including an addition method
that is analogous to the FASTEXP algorithm, that is, one that does not require the determination
of ail intermediate Fibonacci numbers.

Page 87 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit4/assets/9.html 4/4
UNIT - 5
Algebraic Methods

Page 88 of 189
Algebraic Methods
8/20/2015 scorm content

 
Groups

Abstract algebra is the study of algebraic structures. Such a structure consists of a set together
with one or more binary operations, which are required to satisfy certain axioms.

A group is a set with an associated binary operation satisfying certain mathematical properties.
This simple algebraic structure has very rich applications because the elements of the set need
not  be  just  numbers  –  they  can  be  matrices,  planes,  translations,  rotations,  reflections,  in  fact
functions or operations of any kind.

Group  theory  has  been  applied  in  field  as  diverse  as  crystallography  and  game  theory  In
crystallography  and  in  quantum  mechanics,  Groups  serve  as  the  natural  language  to  describe
the arrangement of molecules and the behaviour of particles.

A striking example is the discovery of the Ω­baryon, an elementary particle belonging to a family
of  ten  particles.  It  was  the  last  member  to  be  discovered.  After  the  first  nine  members  were
discovered and their behaviour was modelled using group theory, it was thought there should be
another particle in the family.

This  in  turn  lead  to  a  search  and  the  Ω­baryon  was  discovered  in  1964.  It  was  like  someone
telling you there is a gold coin in your pocket; you are unaware of its existence but when you put
your hand in the pocket, you find it there, as if by magic.

A group G is a finite or infinite set together with a binary operation or composition that satisfies
the  four  fundamental  properties  of  closure,  associativity,  the  identity  property,  and  the  inverse
property.

Basics of Counting

The operation with respect to which a group is defined is often called the "group operation," and
a set is said to be a group "under" this operation if the following four properties are satisfied.

Closure: If a and b are two elements in G, then the product a×b is also in G.

Associativity: The defined operation is associative, i.e., for all a, b, c in G, (a × b) × c = a × (b
× c).

Existence of Identity: There is an identity element, often denoted by e, such that e × a = a ×e
= a for all a belonging to G.

Existence  of  Inverse:  Each  element  must  have  an  inverse,  that  is  for  each  element  a  in  G,
there must exist an element b in G such that a×b =b

The number of elements in the set is called the order of the group. If the set is infinite, the group
is called an infinite group.

CARD SHUFFLING

A  perfect  shuffle  is  one  in  which  the  deck  is  cut  precisely  in  two  equal  parts  and  cards  are
interleaved. Example: if these cards are 1, 2 ...52, then two halves are 1, 2... 26 and 27, 28 ...52.

Page 89 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/2.html 1/2
Algebraic Methods
8/20/2015 scorm content

After  a  perfect  shuffle  the  order  of  the  cards  is  either  1,  27,  2,  28...  26,  52  or  27,1,  28,
2,......,52,26. Eight perfect shuffles restore a deck of 52 cards to the original order.

Group theorists have studied generalisation of shuffles on decks of arbitrary number of cards in
detail. (Magic Tricks, Card Shuffling and Computer Memories by S. Brent Morris) In addition to
their use in designing many card tricks, the group theoretic results from studying shuffles have
been  used  to  designing  dynamic  RAM  and  also  in  algorithms  for  shuffling  tasks  in  parallel
computers with multiple processors.

In  the  Rubik’s  cube,  the  cube  is  formed  of  27  small  cubes.  Each  face  consists  of  9  small
squares,  which  we  may  call  facets.  Since  a  cube  has  6  faces,  we  have  54  facets  in  all.  Each
facet is coloured with one of six different colours, there being exactly nine facets of each colour.
The  facets  can  be  moved  into  different  positions  by  various  rotations.  The  problem  consists  of
applying suitable rotations so that each of the six faces has all the nine facets of one colour.

It  is  possible  to  ′solve′  the  Rubik  cube  without  knowledge  of  groups.  But  the  fast  algorithms,
which solve a cube from any initial position in 20 moves or less use group theory. A well known
book  on  solving  the  Rubik’s  cube  is  Rubik’s  Cubic  Compendium  by  Erno  Rubik,  Tamas  Varga,
Gerzson  Keri,  Gyorgy  Marx  and  Tamas  Vekerdy;  and  another  one  is  Notes  on  Rubik’s  Magic
Cube  by  David  Singmaster.  The  more  recent  Adventures  in  Group  Theory:  Rubik’s  Cube,
Merlin’s  Machine  and  Other  Mathematical  Toys  by  David  Joyner  has  a  description  of  many
puzzles, their solving strategies and the underlying group theoretic framework.

Groups  are  a  particularly  simple  algebraic  structure,  having  only  one  operation  and  three
axioms. Most algebraic structures have more than one operation, and are required to satisfy a
long list of axioms.

Other algebraic structures

Field is an algebraic structure with addition and multiplication, which obey all of the usual rules of
elementary algebra. Examples of fields include the rational numbers Q, the real numbers R, and
the complex numbers C.

A ring is a more general algebraic structure with addition and multiplication. A good example of a
ring  is  the  set  of  all  nXn  matrices  under  the  operations  of  matrix  addition  and  matrix
multiplication.

A vector space is an algebraic structure with operations of addition and multiplication by scalars.
The  scalars  are  required  to  be  elements  of  a  field,  such  as  the  real  numbers  R.  The  basic
example of a vector space is the set Rn of all vectors with n entries.

A module is similar to a vector space, except that the scalars are only required to be elements of
a  ring.  For  example,  the  set  Zn  of  n­dimensional  vectors  with  integer  entries  forms  a  module,
where “scalar multiplication" refers to multiplication by integer scalars.

Page 90 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/2.html 2/2
Algebraic Methods
8/20/2015 scorm content

 
Properties of groups

Uniqueness of identity element

The identity element of a group is unique. For suppose that there are two identity elements, say
e1 and e2. (This means that g ◦ e1 = e1 ◦ g = g for all g, and also g ◦ e2 = e2 ◦ g = g for all g.)
Then e1 = e1 ◦ e2 = e2.

Uniqueness of inverse

The inverse of a group element g is unique. For suppose that h and k are both additive inverses
of g. (This means that g◦h = h◦g = e and g◦ k = k ◦ g = e – we know now that there is a unique
identity  element  e).  Then  h  =  h  ◦   e  =  h  ◦   (g  ◦   k)  =  (h  ◦   g)  ◦   k  =  e  ◦   k  =  k,  where  we  use  the
associative law in the third step.We denote the inverse of g by g­1.

Composing more than two elements

As  long  as  the  associative  law  holds,  the  result  of  composing  any  number  of  elements  is
independent of the way that the product is bracketed: for example, a ◦ ((b ◦ c) ◦ d) = (a ◦ b) ◦ (c ◦
d).

Since the associative law holds in a group, we have:

Proposition Let  g1,...,gn  be  elements  of  a  group  G.  Then  the  composition  g1  ◦  g2  ◦  ···  ◦  gn  is
well­defined, independent of the way it is bracketed.

Cancellation laws

Page 91 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/3.html 1/2
Algebraic Methods
8/20/2015 scorm content

Page 92 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/3.html 2/2
Algebraic Methods
8/20/2015 scorm content

 
Order

The order of an element g in a group is defined as follows:

If gn = 1 for some positive integer n, then the smallest such n is called the order of g.

If no such n exists, we say that g has infinite order.

The implies g = g −1  by the Cancellation Law.)

Consider  the  additive  group  of  the  ring  Z.  The  element  1  has  infinite  order,  since  there  is  no
positive  integer  n  such  that  n  ·  1  =  0  identity  element  always  has  order  1.  If  an  element  g  has
order 2, then it is equal to its inverse (for g2 = 1 = gg−1.

Assume that the equation xyz = 1 holds in a group G. Does it follow that yzx = 1? That yxz = 1?
Justify your answer.

Solution: xyz = 1 implies that x(yz) = 1. Let yz = a . Then we have xa = 1 and so ax = 1 since a is
invertible and a−1 = x. It follows that (yz)x = 1. Hence yzx = 1.

On the other hand, if xyz = 1, it is not always true that yxz = 1. To see this, let G be the group of
2×2 real matrices and let

Let G be a nonempty set closed under an associative product, which in addition satisfies:

There exists an e ∈ G such that ae = a for all a ∈ G.

Given a ∈ G, there exists an element y (a) ∈ G such that ay (a) =e.

Prove that G must be a group under this product.

Solution: Given a ∈ G. Since right inverse exists, there exists y(a) ∈ G such that ay(a) = e.

Page 93 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/4.html 1/2
Algebraic Methods
8/20/2015 scorm content

Then,  y(a)  =  y(a)e  =  y(a)(ay(a))  =(y(a)a)y(a).  Also,  there  exists  t  ∈  G  such  that  y(a)t  =  e.  This
implies that (y(a)a)y(a)t = e then (y(a)a)e = e Hence y(a)a = e. So every right inverse is also a
left inverse. Now for any a ∈ G we have ea = (ay(a))a = a(y(a)a) = ae = a as e is a right identity.
Hence e is a left identity.

If G is a group of even order, prove that it has an element a ≠ e satisfying a 2  = e.

Solution: Define a relation on G by g ∼ h if and only if g = h or g = h −1  for all g, h ∈ G.

It  is  easy  to  see  that  this  is  an  equivalence  relation.  The  equivalence  class  containing  g  is  {g,
gsup>−1}  and  contains  exactly  2  elements  if  and  only  if  g 2   ≠  e.  Let  C1,  C2,  ·  ·  ·  ,  Ck  be  the
equivalence classes of G with respect to ∼ . Then |G| = |C1| + |C2| + · · · + |Ck| Since each |Ci |
∈ {1, 2} and |G| is even the number of equivalence classes Ci , with |Ci | = 1 is even. Since the
equivalence  class  containing  {e}  has  just  one  element,  there  must  exist  another  equivalence
class with exactly one element say {a}. Then e≠a and asup>−1 = a. i.e. a 2  = e.

Prove that in any group the orders of ab and of ba are equal.

Solution: Let (ab) k = 1. Then abab · · · ab = 1 This implies a(ba)(ba)· · ·(ba)b = 1

We have a(ba) k−1 b = 1 ⇒ (ba)k−1 = a−1b−1 =(ba)−1

We  obtain  (ba) k−1 (ba)  =  1  which  implies  (ba)k  =  1.  Similarly  if  (ba) l  =  1,  then  (ab) l  =  1.  Hence
orders of ab and ba are the same.

Page 94 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/4.html 2/2
Algebraic Methods
8/20/2015 scorm content

 
Sub groups

Page 95 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/5.html 1/1
Algebraic Methods
8/20/2015 scorm content

 
Cosets

We  have  introduced  the  product,  sum,  and  subtraction  rules  for  counting.  You  may  wonder
whether  there  is  also  a  Cosets  for  counting.  In  fact,  there  is  such  a  rule,  which  can  be  Useful
when solving certain types of enumeration problems.

THE COSETS There are n/d ways to do a task if it can be done using a procedure that can be
carried out in n ways, and for every way w, exactly d of the n ways correspond to way w.

Page 96 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/6.html 1/3
Algebraic Methods
8/20/2015 scorm content

Page 97 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/6.html 2/3
Algebraic Methods
8/20/2015 scorm content

Page 98 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/6.html 3/3
Algebraic Methods
8/20/2015 scorm content

 
Lagrange’s theorem

The number of elements in a group G is called the order of G and denoted o(G).

Given  a  subgroup  H  of  G,  the  number  of  cosets  of  H  in  G  is  called  the  index  of  H  in  G  and
denoted [G : H].

Page 99 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/7.html 1/2
Algebraic Methods
8/20/2015 scorm content

Page 100 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/7.html 2/2
Algebraic Methods
8/20/2015 scorm content

 
Recap – Problems

If  a  ∈  G  define  CG(a)  =  {  x  ∈  G  |  xa  =  ax  }.  Show  that  CG(a)  is  a  subgroup  of  G.  The  group
CG(a) is called the centralizer of a in G.

Solution: Let x, y ∈ CG(a). If ya = ay, then ay−1 = y−1a hence y−1 ∈ CG(a) and moreover (xy)a
= x(ya) = x(ay) = a(xy). Hence xy ∈ CG(a). (Observe that CG(a) = CG({a})

Show that the intersection of two normal subgroups of G is a normal subgroup of G.

Solution: It is clear that the intersection of two subgroups of G is a subgroup of G.

Let N and M be normal subgroups of G.

Then for any g ∈ G and any n ∈ N and any m ∈ M we have gng−1 ∈ N and gmg−1 ∈ M.

Let w ∈ N ∩M. Since w ∈ N we have gwg−1 ∈ N and since w ∈ M we have gwg−1 ∈ M. Hence
gwg−1 ∈ N ∩ M for any g ∈ G i.e. N ∩ M is a normal subgroup of G.

If H is a subgroup of G such that the product of any two right cosets of H in G is again a right
coset of H in G, prove that H is normal in G.

Solution: Let Ha and Hb be two right cosets of H in G. By assumption HaHb is a right coset of H
in G. The set Ha Hb contains the element ab. So the right coset should contain ab. Since there is
only one right coset of H in G containing ab, which is Hab, we have HaHb = Hab for all a, b ∈ G.
Hence HaH = Ha for all a ∈ G. i.e.

If H is a subgroup of G such that the product of any two right cosets of H in G is again a right
coset of H in G, prove that H is normal in G.

Solution: Let Ha and Hb be two right cosets of H in G. By assumption HaHb is a right coset of H
in G. The set Ha Hb contains the element ab. So the right coset should contain ab. Since there is
only one right coset of H in G containing ab, which is Hab, we have HaHb = Hab for all a, b ∈ G.
Hence  HaH  =  Ha  for  all  a  ∈  G.  i.e.  h1ah2  is  equal  to  h3a  for  some  h3  ∈  H.  But  h1ah2  =  h3a
implies  ah2a−1  =  h1−1h3.  So  for  any  h2  ∈  H  and  any  a  ∈  G  ah2a−1  =  h1−1h3  ∈  H  i.e.  H  is
normal in G and So on..

Page 101 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit5/assets/8.html 1/1
UNIT - 6
Combination

Page 102 of 189


Combination
8/20/2015 scorm content

 
Combinations

Combinatorics,  the  study  of  arrangements  of  objects,  is  an  important  part  of  discrete
mathematics.  This  subject  was  studied  as  long  ago  as  the  seventeenth  century,  when
combinatorial questions arose in the study of gambling games.

Combinations have been applied in all facets of computing from web technology to mathematical
biology.

What is combinatorics?

Combinatorics  is  a  branch  of  mathematics  concerning  the  study  of  finite  or  countable  discrete
structure

Question:  Suppose  that  a  password  on  a  computer  system  consists  of  six,  seven,  or  eight
characters. Each of these characters must be a digit or a letter of the alphabet. Each password
must contain at least one digit. How many such passwords are there?

The techniques needed to answer this question forms what we call as the counting problem. We
will show you how this is done later on in the module.

Combination is the number of ways of picking k unordered outcomes from n possibilities.`

There are two techniques used in counting

Sum rule

Product rule

The product rule applies when a procedure is made up of separate tasks.

The product rule: Suppose that a procedure can be broken down into a sequence of two tasks. If
there are n1 ways to do the first task and for each of these ways of doing the first task, there are
n2 ways to do the second task, then there are n1n2 ways to do the procedure.

Another definition: Let m be the number of ways to do task 1 and n the number of ways to do
task 2 (with each number independent of how the other task is done), and assume that no way
to do task 1 simultaneously also accomplishes task 2.

The product rule: The task “do both” task 1 and task 2 can be done in mn ways.

A new company with just two employees, Sanchez and Patel, rents a floor of a building with 12
offices. How many ways are there to assign different offices to these two employees?

The  procedure  of  assigning  offices  to  these  two  employees  consists  of  assigning  an  office  to
Sanchez,  which  can  be  done  in  12  ways,  then  assigning  an  office  to  Patel  different  from  the
office assigned to Sanchez, which can be done in 11 ways. By the product rule, there are 12 · 11
= 132 ways to assign offices to these two employees.

The  chairs  of  an  auditorium  are  to  be  labeled  with  an  uppercase  English  letter  followed  by  a
positive  integer  not  exceeding  100.  What  is  the  largest  number  of  chairs  that  can  be  labeled

Page 103 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/2.html 1/4
Combination
8/20/2015 scorm content

differently?

The procedure of labeling a chair consists of two tasks, namely, assigning to the seat one of the
26  uppercase  English  letters,  and  then  assigning  to  it  one  of  the  100  possible  integers.  The
product  rule  shows  that  there  are  26  ·  100  =  2600  different  ways  that  a  chair  can  be  labeled.
Therefore, the largest number of chairs that can be labeled differently is 2600.

There  are  32  microcomputers  in  a  computer  center.  Each  microcomputer  has  24  ports.  How
many different ports to a microcomputer in the center are there?

The procedure of choosing a port consists of two tasks, first picking a microcomputer and then
picking a port on this microcomputer. Because there are 32 ways to choose the microcomputer
and 24 ways to choose the port no matter which microcomputer has been selected, the product
rule shows that there are 32 · 24 = 768 ports.

How many different bit strings of length seven are there?

Solution: Each of the seven bits can be chosen in two ways, because each bit is either 0 or 1.
Therefore,  the  product  rule  shows  there  are  a  total  of  27  =  128  different  bit  strings  of  length
seven.

What is the value of k after the following code, where n1, n2, . . . , nm are positive integers, has
been executed?

Solution: The initial value of k is zero. Each time the nested loop is traversed, 1 is added to k. Let
Ti  be  the  task  of  traversing  the  ith  loop.  Then  the  number  of  times  the  loop  is  traversed  is  the
number of ways to do the tasks T1, T2,... , Tm. The number of ways to carry out the task Tj, j =
1, 2,..., m, is nj, because the j th loop is traversed once for each integer ij with 1 ≤ ij ≤ nj . By the
product  rule,  it  follows  that  the  nested  loop  is  traversed  n1n2  ·  ·  ·  nm  times.  Hence,  the  final
value of k is n1n2 · · · nm.

THE SUM RULE If a task can be done either in one of n1 ways or in one of n2 ways, where none
of the set of n1 ways is the same as any of the set of n2 ways, then there are n1 + n2 ways to do
the task.

Suppose  that  either  a  member  of  the  mathematics  faculty  or  a  student  who  is  a  mathematics
major is chosen as a representative to a university committee. How many different choices are

Page 104 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/2.html 2/4
Combination
8/20/2015 scorm content

there  for  this  representative  if  there  are  37  members  of  the  mathematics  faculty  and  83
mathematics majors and no one is both a faculty member and a student? Solution: There are 37
ways  to  choose  a  member  of  the  mathematics  faculty  and  there  are  83  ways  to  choose  a
student  who  is  a  mathematics  major.  Choosing  a  member  of  the  mathematics  faculty  is  never
the same as choosing a student who is a mathematics major because no one is both a faculty
member and a student. By the sum rule it follows that there are 37 + 83 = 120 possible ways to
pick this representative.

A student can choose a computer project from one of three lists. The three lists contain 23, 15,
and 19 possible projects, respectively. No project is on more than one list. How many possible
projects are there to choose from?

Solution: The student can choose a project by selecting a project from the first list, the second
list, or the third list. Because no project is on more than one list, by the sum rule there are 23 +
15 + 19 = 57 ways to choose a project.

Each user on a computer system has a password, which is six to eight characters long, where
each character is an uppercase letter or a digit. Each password must contain at least one digit.
How many possible passwords are there?

Let P be the total number of possible passwords, and let P6, P7, and P8 denote the number of
possible passwords of length 6, 7, and 8, respectively. By the sum rule, P = P6 + P7 + P8.We will
now find P6, P7, and P8. Finding P6 directly is difficult. To find P6 it is easier to find the number
of  strings  of  uppercase  letters  and  digits  that  are  six  characters  long,including  those  with  no
digits,  and  subtract  from  this  the  number  of  strings  with  no  digits.  By  the  product  rule,  the
number  of  strings  of  six  characters  is  366,  and  the  number  of  strings  with  no  digits  is  266.
Hence,

Some facts about IPv4

Valid computer addresses are in one of 3 types:

A class A IP address contains a 7­bit .netid. 6= 17, and a 24­bit .hostid.

A class B address has a 14­bit netid and a 16­bit hostid.

Page 105 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/2.html 3/4
Combination
8/20/2015 scorm content

A class C addr. has 21­bit netid and an 8­bit hostid.

The 3 classes have distinct headers (0, 10, 110)

Hostids that are all 0s or all 1s are not allowed. How many valid computer addresses are there?

(# addrs) = (# class A) + (# class B) + (# class C)

(# class A) = (# valid netids) . (# valid host IDs)

(# valid class A netids) = 27 ­ 1 = 127.

(# valid class A hostids) = 224 ­ 2 = 16, 777, 214.

Continuing in this fashion we find the answer is: 3, 737, 091, 842 (3.7 billion IP addresses)

Page 106 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/2.html 4/4
Combination
8/20/2015 scorm content

 
Principle of Subtraction

Suppose that a task can be done in one of two ways, but some of the ways to do it are common
to both ways. In this situation, we cannot use the sum rule to count the number of ways to do the
task.

If  we  add  the  number  of  ways  to  do  the  tasks  in  these  two  ways,  we  get  an  over  count  of  the
total number of ways to do it, because the ways to do the task that are common to the two ways
are counted twice. To correctly count the number of ways to do the two tasks, we must subtract
the number of ways that are counted twice.

The  Subtraction  Rule  If  a  task  can  be  done  in  either  n1  ways  or  n2  ways,  then  the  number  of
ways to do the task is n1 + n2 minus the number of ways to do the task that are common to the
two different ways.

The  subtraction  rule  is  also  known  as  the  principle  of  inclusion–exclusion,  especially  when  it  is
used  to  count  the  number  of  elements  in  the  union  of  two  sets.  Suppose  that  A1  and  A2  are
sets. Then, there are |A1| ways to select an element from A1 and |A2| ways to select an element
from A2.

The  number  of  ways  to  select  an  element  from  A1  or  from  A2,  that  is,  the  number  of  ways  to
select an element from their union, is the sum of the number of ways to select an element from
A1 and the number of ways to select an element from A2, minus the number of ways to select
an element that is in bothA1 and A2. Because there are |A1 ∪ A2| ways to select an element in
either A1 or in A2, and |A1 ∩ A2| ways to select an element common to both sets, we have |A1
∪ A2| = |A1| + |A2| − |A1 ∩ A2|.

Hypothetical rules for passwords

Passwords must be 2 characters long. Each password must be a letter a ­ z, a digit 0 ­ 9, or one
of the 10 punctuation characters!@#$%^& _ (). Each password must contain at least 1 digit or
punctuation character.

Solution

A  legal  password  has  a  digit  or  punctuation  character  in  position  1  or  position  2.  These  cases
overlap, so the principle applies.

(# of passwords w. OK symbol in position 1) = (10 + 10) . (10 + 10 + 26)

(# of passwords w. OK symbol in position 2) = 20 . 46

(# of passwords w. OK symbol in both places) = 20 . 20

Ans: 920 + 920 ­ 400 = 1, 440

A  computer  company  receives  350  applications  from  computer  graduates  for  a  job  planning  a
line  of  new  Web  servers.  Suppose  that  220  of  these  applicants  majored  in  computer  science,
147 majored in business, and 51 majored both in computer science and in business. How many
of these applicants majored neither in computer science nor in business?

Page 107 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/3.html 1/2
Combination
8/20/2015 scorm content

Solution: To find the number of these applicants who majored neither in computer science nor in
business, we can subtract the number of students who majored either in computer science or in
business (or both) from the total number of applicants.

Let A1 be the set of students who majored in computer science and A2 the set of students who
majored in business. Then A1 ∪ A2 is the set of students who majored in computer science or
business  (or  both),  and  A1  ∩  A2  is  the  set  of  students  who  majored  both  in  computer  science
and in business. By the subtraction rule the number of students who majored either in computer
science or in business (or both) equals |A1 ∪ A2| = |A1| + |A2| − |A1 ∩ A2| = 220 + 147 − 51 =
316.

We conclude that 350 − 316 = 34 of the applicants majored neither in computer science nor in
business.

Page 108 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/3.html 2/2
Combination
8/20/2015 scorm content

 
The Division Rule

We  have  introduced  the  product,  sum,  and  subtraction  rules  for  counting.  You  may  wonder
whether  there  is  also  a  division  rule  for  counting.  In  fact,  there  is  such  a  rule,  which  can  be
Useful when solving certain types of enumeration problems.

There are n/d ways to do a task if it can be done using a procedure that can be carried out in n
ways, and for every way w, exactly d of the n ways correspond to way w.

Division rule in terms of sets and functions

“If the finite set A is the union of n pairwise disjoint subsets each with d elements, then n = |A|/d.”

“If f is a function from A to B where A and B are finite sets, and that for every value y ∈ B there
are exactly d values x ∈ A such that f (x) = y (in which case, we say that f is d­to­one), then |B| =
|A|/d.”

How  many  different  ways  are  there  to  seat  four  people  around  a  circular  table,  where  two
seating’s are considered the same when each person has the same left neighbor and the same
right neighbor?

We arbitrarily select a seat at the table and label it seat 1. We number the rest of the seats in
numerical  order,  proceeding  clockwise  around  the  table.  Note  that  are  four  ways  to  select  the
person for seat 1, three ways to select the person for seat 2, two ways to select the person for
seat 3, and one way to select the person for seat 4. Thus, there are 4! = 24 ways to order the
given four people for these seats.

However, each of the four choices for seat 1 leads to the same arrangement, as we distinguish
two arrangements only when one of the people has a different immediate left or immediate right
neighbor. Because there are four ways to choose the person for seat 1, by the division rule there
are 24/4 = 6 different seating arrangements of four people around the circular table.

Page 109 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/4.html 1/1
Combination
8/20/2015 scorm content

 
THE PIGEONHOLE PRINCIPLE

Suppose that a flock of 20 pigeons flies into a set of 19 pigeonholes to roost. Because there are
20 pigeons but only 19 pigeonholes, a least one of these 19 pigeonholes must have at least two
pigeons in it. To see why this is true, note that if each pigeonhole had at most one pigeon in it, at
most 19 pigeons, one per hole, could be accommodated.

This illustrates a general principle called the pigeonhole principle, which states that if there are
more  pigeons  than  pigeonholes,  then  there  must  be  at  least  one  pigeonhole  with  at  least  two
pigeons in it (see Figure). Of course, this principle applies to other objects besides pigeons and
pigeonholes.

THE  PIGEONHOLE  PRINCIPLE  If  k  is  a  positive  integer  and  k  +  1  or  more  objects  are  placed
into k boxes, then there is at least one box containing two or more of the objects.

Proof: We prove the pigeonhole principle using a proof by contraposition.

Suppose  that  none  of  the  k  boxes  contains  more  than  one  object.  Then  the  total  number  of
objects would be at most k. This is a contradiction, because there are at least k + 1 objects.

Theorem: A function f from a set with k + 1 or more elements to a set with k elements is not one­
to­one.

Proof:  Suppose  that  for  each  element  y  in  the  codomain  of  f  we  have  a  box  that  contains  all
elements  x  of  the  domain  of  f  such  that  f  (x)  =  y.  Because  the  domain  contains  k  +  1  or  more
elements and the codomain contains only k elements, the pigeonhole principle tells us that one
of  these  boxes  contains  two  or  more  elements  x  of  the  domain.  This  means  that  f  cannot  be
one­to­one.

There  are  280  students  in  the  class.  Without  knowing  anybody’s  birthday,  what  is  the  largest
value  of  n  for  which  we  can  prove  that  at  least  n  students  must  have  been  born  in  the  same
month? Ans |280/12| = |23.3| = 24

Show  that  for  every  integer  n  there  is  a  multiple  of  n  that  has  only  0s  and  1s  in  its  decimal
expansion.

Solution: Let n be a positive integer. Consider the n + 1 integers 1, 11, 111, . . . , 11 . . . 1 (where

The last integer in this list is the integer with n + 1 1s in its decimal expansion). Note that there

Are n possible remainders when an integer is divided by n? Because there are n + 1 integers in
this list, by the pigeonhole principle there must be two with the same remainder when divided by
n. The larger of these integers less the smaller one is a multiple of n, which has a decimal

Expansion consisting entirely of 0s and 1s.

Page 110 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/5.html 1/1
Combination
8/20/2015 scorm content

 
The generalized pigeonhole principle

If  N  objects  are  placed  into  k  Boxes,  then  there  is  at  least  one  box  containing  at  least  [N/k]
objects.

Proof:  We  will  use  a  proof  by  contraposition.  Suppose  that  none  of  the  boxes  contains  more
Than [N/k] − 1 objects. Then, the total number of objects is at most

Where the inequality [N/k] < (N/k) + 1 has been used. This is a contradiction because there Are a
total of N objects?

What  is  the  minimum  number  of  students  required  in  a  discrete  mathematics  class  to  be  sure
that at least six will receive the same grade, if there are five possible grades, A, B, C, D, and F?

Solution: The minimum number of students needed to ensure that at least six students receive
the same grade is the smallest integer N such that [N/5] = 6. The smallest such integer is N = 5 ·
5  +  1  =  26.  If  you  have  only  25  students,  it  is  possible  for  there  to  be  five  who  have  received
each  grade  so  that  no  six  students  have  received  the  same  grade.  Thus,  26  is  the  minimum
number of students needed to ensure that at least six students will receive the same grade.

What  is  the  least  number  of  area  codes  needed  to  guarantee  that  the  25  million  phones  in  a
state  can  be  assigned  distinct  10­digit  telephone  numbers?  (Assume  that  telephone  numbers
are of the form NXX­NXX­XXXX, where the first three digits form the area code, N represents a
digit from 2 to 9 inclusive, and X represents any digit.)

Solution:  There  are  eight  million  different  phone  numbers  of  the  form  NXX­XXXX  (as  shown  In
Example  8  of  Section  6.1).  Hence,  by  the  generalized  pigeonhole  principle,  among  25  million
Telephones,  at  least  [25,000,000/8,000,000]  =  4  of  them  must  have  identical  phone  numbers.
Hence, at least four area codes are required to ensure that all 10­digit numbers are different.

During a month with 30 days, a baseball team plays at least one game a day, but no more than
45 games. Show that there must be a period of some number of consecutive days during which
the team must play exactly 14 games.

Solution: Let aj be the number of games played on or before the j th day of the month. Then a1,
a2, . . . , a30 is an increasing sequence of distinct positive integers, with 1 ≤ aj ≤ 45. Moreover,
a1 + 14, a2 + 14, . . . , a30 + 14 is also an increasing sequence of distinct positive integers, with
15 ≤ aj + 14 ≤ 59. The 60 positive integers a1, a2, . . . , a30, a1 + 14, a2 + 14, . . . , a30 + 14 are
all less than or equal to 59. Hence, by the pigeonhole principle two of these integers are equal.
Because the integers aj , j = 1, 2, . . . , 30 are all distinct and the integers aj + 14, j = 1, 2, . . . ,
30  are  all  distinct,  there  must  be  indices  i  and  j  with  ai  =  aj  +  14.  This  means  that  exactly  14
games were played from day j + 1 to day i

Assume  that  in  a  group  of  six  people,  each  pair  of  individuals  consists  of  two  friends  or  two
Page 111 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/6.html 1/5
Combination
8/20/2015 scorm content

enemies. Show that there are either three mutual friends or three mutual enemies in the group.

Solution: Let A be one of the six people. Of the five other people in the group, there are either
three or more who are friends of A, or three or more who are enemies of A. This follows from the
generalized pigeonhole principle, because when five objects are divided into two sets, one of the
sets has at least [5/2] = 3 elements. In the former case, suppose that B, C, and D are friends of
A. If any two of these three individuals are friends, then these two and A form a group of three
mutual  friends.  Otherwise,  B,  C,  and  D  form  a  set  of  three  mutual  enemies.  The  proof  in  the
latter case, when there are three or more enemies of A, proceeds in a similar manner.

The Ramsey number R(m, n), where m and n are positive integers greater than or equal to 2,
denotes the minimum number of people at a party such that there are either mutual friends or n
mutual  enemies,  assuming  that  every  pair  of  people  at  the  party  are  friends  or  enemies.  The
Example shows that R(3, 3) ≤ 6. We conclude that R(3, 3) = 6 because in a group of five

Many  counting  problems  can  be  solved  by  finding  the  number  of  ways  to  arrange  a  specified
number  of  distinct  elements  of  a  set  of  a  particular  size,  where  the  order  of  these  elements
matters. Many other counting problems can be solved by finding the number of ways to select a
particular  number  of  elements  from  a  set  of  a  particular  size,  where  the  order  of  the  elements
Selected does not matter.

For example, in how many ways can we select three students from a group of five students to
stand in line for a picture? How many different committees of three students can be formed from
a  group  of  four  students?  Permutations  and  combinations  offer  methods  to  answer  questions
such as these.

A  permutation  of  a  set  S  of  objects  is  a  sequence  containing  each  object  once.  An  ordered
arrangement of r distinct elements of S is called an r ­permutation.

In how many ways can we select three students from a group of five students to stand in line for
a picture? In how many ways can we arrange all five of these students in a line for a picture?

Solution: First, note that the order in which we select the students matters. There are five ways
to select the first student to stand at the start of the line. Once this student has been selected,
there are four ways to select the second student in the line. After the first and second students
have been selected, there are three ways to select the third student in the line. By the product
rule, there are 5 · 4 · 3 = 60 ways to select three students from a group of five students to stand
in line for a picture.

To  arrange  all  five  students  in  a  line  for  a  picture,  we  select  the  first  student  in  five  ways,  the
second  in  four  ways,  the  third  in  three  ways,  the  fourth  in  two  ways,  and  the  fifth  in  one  way.
Consequently, there are 5 · 4 · 3 · 2 · 1 = 120 ways to arrange all five students in a line for a
picture.

The  number  of  r­permutations  of  a  set  with  n  elements  is  denoted  by  P(n,  r).  If  n  is  a  positive
integer and r is an integer with 1 ≤ r ≤ n, then there are P(n, r) = n(n − 1)(n − 2) · · · (n − r + 1) r­
permutations of a set with n distinct elements.

Proof: We will use the product rule to prove that this formula is correct. The first element of the
permutation can be chosen in n ways because there are n elements in the set. There are n – 1
Page 112 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/6.html 2/5
Combination
8/20/2015 scorm content

ways to choose the second element of the permutation, because there are n – 1 elements left in
the  set  after  using  the  element  picked  for  the  first  position.  Similarly,  there  are  n  −  2  ways  to
choose the third element, and so on, until there are exactly n − (r − 1) = n − r + 1 ways to choose
the rth element. Consequently, by the product rule, there are n(n − 1)(n − 2) · · · (n − r + 1) r­
permutations of the set.

Note that P(n, 0) = 1 whenever n is a nonnegative integer because there is exactly one Way to
order zero elements. That is, there is exactly one list with no elements in it, namely the Empty
list.

How many ways are there to select a first­prize winner, a second­prize winner, and a third­prize
winner from 100 different people who have entered a contest?

Solution: Because it matters which person wins which prize, the number of ways to pick the three
prize winners is the number of ordered selections of three elements from a set of 100 elements,
that  is,  the  number  of  3­permutations  of  a  set  of  100  elements.  Consequently,  the  answer  is
P(100, 3) = 100 · 99 · 98 = 970,200.

Suppose that there are eight runners in a race. The winner receives a gold medal, the second
place finisher receives a silver medal, and the third­place finisher receives a bronze medal. How
many different ways are there to award these medals, if all possible outcomes of the race can
occur and there are no ties?

Solution: The number of different ways to award the medals is the number of 3­permutations of
a set with eight elements. Hence, there are P(8, 3) = 8 · 7 · 6 = 336 possible ways to award the
medals.

Suppose  that  a  saleswoman  has  to  visit  eight  different  cities.  She  must  begin  her  trip  in  a
specified  city,  but  she  can  visit  the  other  seven  cities  in  any  order  she  wishes.  How  many
possible orders can the saleswoman use when visiting these cities?

Solution:  The  number  of  possible  paths  between  the  cities  is  the  number  of  permutations  of
seven  elements,  because  the  first  city  is  determined,  but  the  remaining  seven  can  be  ordered
arbitrarily. Consequently, there are 7! = 7 · 6 · 5 · 4 · 3 · 2 · 1 = 5040 ways for the saleswoman
to  choose  her  tour.  If,  for  instance,  the  saleswoman  wishes  to  find  the  path  between  the  cities
with  minimum  distance,  and  she  computes  the  total  distance  for  each  possible  path,  she  must
consider a total of 5040 paths!

How many permutations of the letters ABCDEFGH contain the string ABC?

Solution: Because the letters ABC must occur as a block, we can find the answer by finding the
number of permutations of six objects, namely, the block ABC and the individual letters D, E, F,
G, and H. Because these six objects can occur in any order, there are 6! = 720 permutations of
the letters ABCDEFGH in which ABC occurs as a block.

An  r­combination  of  elements  of  a  set  is  an  unordered  selection  of  r  elements  from  the  set.
Thus, an r­combination is simply a subset of the set with r elements.

The number of r­combinations of a set with n distinct elements is denoted by C(n, r). C(n,  r)  is
called  a  binomial  coefficient.  The  number  of  r­combinations  of  a  set  with  n  distinct  elements  is

Page 113 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/6.html 3/5
Combination
8/20/2015 scorm content

denoted  by  C(n,  r).  The  number  of  r­combinations  of  a  set  with  n  elements,  where  n  is  a
nonnegative integer and r is an integer with 0 ≤ r ≤ n, equals C(n, r) =n!/(r! (n − r)!)

The  number  of  r­combinations  of  a  set  with  n  distinct  elements  is  denoted  by  C(n,  r).  The
number of r­combinations of a set with n elements, where n is a nonnegative integer and r is an
integer with 0 ≤ r ≤ n, equals C(n, r) =n!/(r! (n − r)!)

The  P(n,  r)  r­permutations  of  the  set  can  be  obtained  by  forming  the  C(n,  r)  r­combinations  of
the  set,  and  then  ordering  the  elements  in  each  r­combination,  which  can  be  done  in  P(r,  r)
ways. Consequently, by the product rule, P(n, r) = C(n, r) · P(r, r).

This implies that C(n, r) = P(n, r)/P(r, r) = n!/(n − r)! divided by r!/(r − r)! =n!/(r! (n − r)!)

How many poker hands of five cards can be dealt from a standard deck of 52 cards? Also, how
many ways are there to select 47 cards from a standard deck of 52 cards?

Solution: Because the order in which the five cards are dealt from a deck of 52 cards does not
matter,  there  are  C(52,  5)  =  52!/  5!47!  Different  hands  of  five  cards  that  can  be  dealt.  To
compute the value of C(52, 5), first divide the numerator and denominator by 47! to obtain C(52,
5) =(52 · 51 · 50 · 49 · 48)/(5 · 4 · 3 · 2 · 1)

Let n and r be nonnegative integers with r ≤ n. Then C(n, r) = C(n, n − r).

How many ways are there to select five players from a 10­member tennis team to make a trip to
a match at another school?

Solution:  The  answer  is  given  by  the  number  of  5­combinations  of  a  set  with  10  elements.  By
Theorem 2, the number of such combinations is C(10, 5) = 10! / 5! 5! = 252.

A group of 30 people have been trained as astronauts to go on the first mission to Mars. How
many ways are there to select a crew of six people to go on this mission (assuming that all crew
members have the same job)?

Solution: The number of ways to select a crew of six from the pool of 30 people is the number of
6­combinations of a set with 30 elements, because the order in which these people are chosen
does not matter. By Theorem 2, the number of such combinations is C(30, 6) =30!/6! 24! = (30 ·
29 · 28 · 27 · 26 · 25)/( 6 · 5 · 4 · 3 · 2 · 1) = 593,775

How many strings of length r can be formed from the uppercase letters of the English alphabet?

Solution:  By  the  product  rule,  because  there  are  26  uppercase  English  letters,  and  because
each  letter  can  be  used  repeatedly,  we  see  that  there  are  26r  strings  of  uppercase  English
letters of Length r.

Suppose that a cookie shop has four different kinds of cookies. How many different ways can six
cookies be chosen? Assume that only the type of cookie, and not the individual cookies or the
order in which they are chosen, matters.

Solution:  The  number  of  ways  to  choose  six  cookies  is  the  number  of  6­combinations  of  a  set
with  four  elements.  From  Theorem  2  this  equals  C(4  +  6  −  1,  6)  =  C(9,  6).  Because  C(9,  6)  =
C(9, 3) = 9 · 8 · 7 1 · 2 · 3 = 84, There are 84 different ways to choose the six cookies.

Page 114 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/6.html 4/5
Combination
8/20/2015 scorm content

Page 115 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/6.html 5/5
Combination
8/20/2015 scorm content

 
Permutations with Indistinguishable Objects

Some elements may be indistinguishable in counting problems. When this is the case, care must
be taken to avoid counting things more than once

How many different strings can be made by reordering the letters of the word SUCCESS?

Solution: Because some of the letters of SUCCESS are the same, the answer is not given by the
number of permutations of seven letters. This word contains three Ss, two Cs, one U, and one E.

To  determine  the  number  of  different  strings  that  can  be  made  by  reordering  the  letters,  first
note  that  the  three  Ss  can  be  placed  among  the  seven  positions  in  C(7,  3)  different  ways,
leaving  four  positions  free.  Then  the  two  Cs  can  be  placed  in  C(4,  2)  ways,  leaving  two  free
positions.

The U can be placed in C(2, 1) ways, leaving just one position free. Hence E can be placed in
C(1, 1) way.

Consequently,  from  the  product  rule,  the  number  of  different  strings  that  can  be  made  is  C(7,
3)C(4, 2)C(2, 1)C(1, 1) = 7!/(3! 4!) · 4!/(2! 2!) · 2!/ (1! 1!) ·1!/ (1! 0!) = 7!/ (3! 2! 1! 1!) = 420

The number of different permutations of n objects, where there are n1 indistinguishable objects
of type 1, n2 indistinguishable objects of type 2, . . . , and nk indistinguishable objects of type k,
is n! / (n1! n2! · · · nk!)

Proof: To determine the number of permutations, first note that the n1 objects of type one can
be placed among the n positions in C(n, n1) ways, leaving n − n1 positions free.

Then the objects of type two can be placed in C(n − n1, n2) ways, leaving n − n1 − n2 positions
free. Continue placing the objects of type three, . . . , type k − 1, until at the last stage, nk objects
of type k can be placed in C(n − n1 − n2 −· · ·−nk−1, nk) ways. Hence, by the product rule, the
total number of different permutations is C(n, n1)C(n − n1, n2) · · · C(n − n1 −· · ·−nk−1, nk) =
n!/ (n1! (n − n1)!). (n − n1)!/ (n2! (n − n1­ n2)!) · · ·(n − n1 −· · ·−nk−1)!/(nk! 0!) = n!/ (n1! n2! · · ·
nk!)

Combinatorics  and  probability  theory  share  common  origins.  The  theory  of  probability  was  first
developed more than 300 years ago, when certain gambling games were analyzed.

Although  probability  theory  was  originally  invented  to  study  gambling,  it  now  plays  an  essential
role in a wide variety of disciplines. For example, probability theory is extensively applied in the
study of genetics, where it can be used to help understand the inheritance of traits. Of course,
probability still remains an extremely popular part of mathematics because of its applicability to
gambling, which continues to be an extremely popular human endeavor.

An experiment is a procedure that yields one of a given set of possible outcomes. The sample
space  of  the  experiment  is  the  set  of  possible  outcomes.  An  event  is  a  subset  of  the  sample
space. Laplace’s definition of the probability of an event with finitely many possible outcomes will
now be stated.

DEFINITION  1  If  S  is  a  finite  nonempty  sample  space  of  equally  likely  outcomes,  and  E  is  an
Page 116 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/7.html 1/5
Combination
8/20/2015 scorm content

event, that is, a subset of S, then the probability of E is p(E) = |E|/|S|. The probability of an event
can never be negative or more than one! According to Laplace’s definition, the probability of an
event is between 0 and 1. To see this, note that if E is an event from a finite sample space S,
then 0 ≤ |E| ≤ |S|, because E ⊆ S. Thus, 0 ≤ p(E) = |E|/|S| ≤ 1.

An  urn  contains  four  blue  balls  and  five  red  balls.  What  is  the  probability  that  a  ball  chosen  at
random from the urn is blue?

Solution:  To  calculate  the  probability,  note  that  there  are  nine  possible  outcomes,  and  four  of
these possible outcomes produce a blue ball. Hence, the probability that a blue ball is chosen is
4/9.

In a lottery, players win a large prize when they pick four digits that match, in the correct order,
four  digits  selected  by  a  random  mechanical  process.A  smaller  prize  is  won  if  only  three  digits
are  matched.  What  is  the  probability  that  a  player  wins  the  large  prize?  What  is  the  probability
that a player wins the small prize?

Solution: There is only one way to choose all four digits correctly. By the product rule, there are
104 = 10,000 ways to choose four digits. Hence, the probability that a player wins the large prize
is 1/10,000 = 0.0001.

Players win the smaller prize when they correctly choose exactly three of the four digits. Exactly
one digit must be wrong to get three digits correct, but not all four correct. By the sum rule, to
find the number of ways to choose exactly three digits correctly, we add the number of ways to
choose four digits matching the digits picked in all but the ith position, for i = 1, 2, 3, 4.

To count the number of successes with the first digit incorrect, note that there are nine possible
choices for the first digit (all but the one correct digit), and one choice for each of the other digits,
namely, the correct digits for these slots. Hence, there are nine ways to choose four digits where
the first digit is incorrect, but the last three are correct.

Similarly, there are nine ways to choose four digits where the second digit is incorrect, nine with
the third digit incorrect, and nine with the fourth digit incorrect. Hence, there is a total of 36 ways
to  choose  four  digits  with  exactly  three  of  the  four  digits  correct.  Thus,  the  probability  that  a
player wins the smaller prize is 36/10,000 = 9/2500 = 0.0036.

There are many lotteries now that award enormous prizes to people who correctly choose a set
of six numbers out of the first n positive integers, where n is usually between 30 and 60. What is
the probability that a person picks the correct six numbers out of 40?

Solution:  There  is  only  one  winning  combination.  The  total  number  of  ways  to  choose  six
numbers out of 40 is C(40, 6) = 40!/(34! 6!) = 3,838,380. Consequently, the probability of picking
a winning combination is 1/3,838,380 ≈ 0.00000026. (Here the symbol ≈ means approximately
equal to.

What is the probability that the numbers 11, 4, 17, 39, and 23 are drawn in that order from a bin
containing 50 balls labeled with the numbers 1, 2, . . . , 50 if (a) the ball selected is not returned
to the bin before the next ball is selected and (b) the ball selected is returned to the bin before
the next ball is selected?

Page 117 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/7.html 2/5
Combination
8/20/2015 scorm content

Solution: (a) By the product rule, there are 50 · 49 · 48 · 47 · 46 = 254,251,200 ways to select
the  balls  because  each  time  a  ball  is  drawn  there  is  one  fewer  ball  to  choose  from.
Consequently, the probability that 11, 4, 17, 39, and 23 are drawn in that order is 1/254,251,200.
This  is  an  example  of  sampling  without  replacement.  (b)  By  the  product  rule,  there  are  505  =
312,500,000 ways to select the balls because there are 50 possible balls to choose from each
time a ball is drawn. Consequently, the probability that 11, 4, 17, 39, and 23 are drawn in that
order is 1/312,500,000. This is an example of sampling with replacement.

A sequence of 10 bits is randomly generated. What is the probability that at least one of these
bits is 0?

Solution: Let E be the event that at least one of the 10 bits is 0. Then E is the event that all the
bits are 1s. Because the sample space S is the set of all bit strings of length 10, it follows that
p(E) = 1 − p(E) = 1 −1/1024 =1023/1024 Hence, the probability that the bit string will contain at
least one 0 bit is 1023/1024.

The  Monty  Hall  Three­Door  Puzzle  Suppose  you  are  a  game  show  contestant.  You  have  a
Chance to win a large prize. You are asked to select one of three doors to open; the large prize
is behind one of the three doors and the other two doors are losers. Once you select a door, the
Game show host, who knows what is behind each door, does the following. First, whether or not
You selected the winning door, he opens one of the other two doors that he knows is a losing
Door (selecting at random if both are losing doors). Then he asks you whether you would like to
Switch doors. Which strategy should you use? Should you change doors or keep your original

Selection, or does it not matter?

Solution: The probability you select the correct door (before the host opens a door and asks you
Whether you want to change) is 1/3, because the three doors are equally likely to be the correct
Door. The probability this is the correct door does not change once the game show host opens
One of the other doors, because he will always open a door that the prize is not behind.

The probability that you selected incorrectly is the probability the prize is behind one of the Two
doors you did not select. Consequently, the probability that you selected incorrectly is 2/3. If you
selected incorrectly, when the game show host opens a door to show you that the prize is Not
behind  it,  the  prize  is  behind  the  other  door.  You  will  always  win  if  your  initial  choice  was
Incorrect and you change doors.

So, by changing doors, the probability you win is 2/3. In other Words, you should always change
doors when given the chance to do so by the game show host. This doubles the probability that
you will win.

To understand recurrence relations let us start from the basics.

A sequence is a discrete structure used to represent an ordered list. For example, 1, 2, 3, 5, 8 is
a sequence with five terms and 1, 3, 9, 27, 81 , . . . , 3n, . . . is an infinite sequence. DEFINITION
1 A sequence is a function from a subset of the set of integers (usually either the set {0, 1, 2, . .
.} or the set {1, 2, 3, . . .}) to a set S. We use the notation an to denote the image of the integer
n. We call an a term of the sequence.

A recurrence relation for the sequence {an} is an equation that expresses an in terms of one or
Page 118 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/7.html 3/5
Combination
8/20/2015 scorm content

more of the previous terms of the sequence, namely, a0, a1, . . . , an−1, for all integers n with n
≥ n0, where n0 is a nonnegative integer. A sequence is called a solution of a recurrence relation
if its terms satisfy the recurrence relation b.

Let {an} be a sequence that satisfies the recurrence relation an = an−1 + 3 for n = 1, 2, 3, . . . ,
and suppose that a0 = 2. What are a1, a2, and a3?

Solution: We see from the recurrence relation that a1 = a0 + 3 = 2 + 3 = 5. It then follows that a2
= 5 + 3 = 8 and a3 = 8 + 3 = 11.

The initial conditions for a recursively defined sequence specify the terms that precede the first
term where the recurrence relation takes effect. For instance, the initial condition in Example 5 is
a0 = 2,

The Fibonacci sequence, f0, f1, f2, . . . , is defined by the initial conditions f0 = 0, f1 = 1, And the
recurrence relation fn = fn−1 + fn−2 For n = 2, 3, 4 . . .

Compound Interest

Suppose that a person deposits $10,000 in a savings account at a bank yielding 11% per year
with interest compounded annually. How much will be in the account after 30 years?

Solution: To solve this problem, let Pn denote the amount in the account after n years. Because
the amount in the account after n years equals the amount in the account after n−1 years plus
interest for the nth year, we see that the sequence {Pn} satisfies the recurrence relation Pn = Pn
−1 + 0.11Pn−1 = (1.11)Pn−1.

The initial condition is P0 = 10,000. We can use an iterative approach to find a formula for Pn.
Note that

When  we  insert  the  initial  condition  P0  =  10,000,  the  formula  Pn  =  (1.11)n10,000  is  obtained.
Inserting  n  =  30  into  the  formula  Pn  =  (1.11)n10,000  shows  that  after  30  years  the  account
Contains P30 = (1.11)3010,000 = $228,922.97

A common problem in discrete mathematics is finding a closed formula, a recurrence relation, or
some other type of general rule for constructing the terms of a sequence. Sometimes only a few
terms of a sequence solving a problem are known; the goal is to identify the sequence.

Find formulae for the sequences with the following first five terms: (a) 1, 1/2, 1/4, 1/8, 1/16 (b) 1,

Page 119 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/7.html 4/5
Combination
8/20/2015 scorm content

3, 5, 7, 9 (c) 1, −1, 1, −1, 1.

Solution: (a) We recognize that the denominators are powers of 2. The sequence with an = 1/2n,
n = 0, 1, 2, . . . is a possible match. This proposed sequence is a geometric progression with a =
1  and  r  =  1/2.  (b)  We  note  that  each  term  is  obtained  by  adding  2  to  the  previous  term.  The
sequence with an = 2n + 1, n = 0, 1, 2, . . . is a possible match. This proposed sequence is an
arithmetic  progression  with  a  =  1  and  d  =  2.  (c)  The  terms  alternate  between  1  and  −1.  The
sequence  with  an  =  (−1)n,  n  =  0,  1,  2  .  .  .  is  a  possible  match.  This  proposed  sequence  is  a
geometric progression with a = 1 and r = −1.

How can we produce the terms of a sequence if the first 10 terms are 1, 2, 2, 3, 3, 3, 4, 4, 4, 4?

Solution: In this sequence, the integer 1 appears once, the integer 2 appears twice, the integer 3
appears three times, and the integer 4 appears four times. A reasonable rule for generating this
sequence is that the integer n appears exactly n times, so the next five terms of the sequence
would all be 5, the following six terms would all be 6, and so on. The sequence generated this
way is a possible match.

Page 120 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/7.html 5/5
Combination
8/20/2015 scorm content

 
Recursively Defined Functions

We use two steps to define a function with the set of nonnegative integers as its domain:

BASIS STEP: Specify the value of the function at zero.

RECURSIVE  STEP:  Give  a  rule  for  finding  its  value  at  an  integer  from  its  values  at  smaller
integers.

Such a definition is called a recursive or inductive definition. Note that a function f (n) from the
set of nonnegative integers to the set of a real numbers is the same as a sequence a0, a1, . . .
where ai is a real number for every nonnegative integer i. So, defining a real­valued sequence
a0, a1, . . . using a recurrence relation, as was done in Section 2.4, is the same as defining a
function from the set of nonnegative integers to the set of real numbers.

Suppose that f is defined recursively by

Recursively defined functions are well defined. That is, for every positive integer, the value of the
function at this integer is determined in an unambiguous way. This means that given any positive
integer, we can use the two parts of the definition to find the value of the function at that integer,
and that we obtain the same value no matter how we apply the two parts of the definition. This is
a consequence of the principle of mathematical induction.

Consider this problem, which was originally posed by Fibonacci, in the thirteenth century in his
book  Liber  abaci.  A  young  pair  of  rabbits  (one  of  each  sex)  is  placed  on  an  island.  A  pair  of
rabbits  does  not  breed  until  they  are  2  months  old.  After  they  are  2  months  old,  each  pair  of
rabbits produces another pair each month, as shown in Figure 1. Find a recurrence relation for
the number of pairs of rabbits on the island after n months, assuming that no rabbits ever die

Solution: Denote by fn the number of pairs of rabbits after n months. We will show that fn, n = 1,
2, 3, . . . , are the terms of the Fibonacci sequence. The rabbit population can be modeled using
a recurrence relation. At the end of the first month, the number of pairs of rabbits on the island is
Page 121 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/8.html 1/2
Combination
8/20/2015 scorm content

f1  =  1.  Because  this  pair  does  not  breed  during  the  second  month,  f2  =  1  also.  To  find  the
number of pairs after n months, add

The Fibonacci numbers appear in many other places in nature, including the number of petals
on  flowers  and  the  number  of  spirals  on  seedheads.  the  number  on  the  island  the  previous
month, fn−1, and the number of newborn pairs, which equals fn−2, because each newborn pair
comes from a pair at least 2 months old.

Consequently,  the  sequence  {fn}  satisfies  the  recurrence  relation  fn  =  fn−1  +  fn−2  for  n  ≥  3
together  with  the  initial  conditions  f1  =  1  and  f2  =  1.  Because  this  recurrence  relation  and  the
initial conditions uniquely determine this sequence, the number of pairs of rabbits on the island
after n months is given by the nth Fibonacci number.

A popular puzzle of the late nineteenth century invented by the French Mathematician Edouard
Lucas, called the Tower of Hanoi, consists of three pegs mounted on Aboard together with disks
of different sizes. Initially these disks are placed on the first peg In order of size, with the largest
on the bottom (as shown in Figure). The rules of the puzzle Allow disks to be moved one at a
time  from  one  peg  to  another  as  long  as  a  disk  is  never  placed  On  top  of  a  smaller  disk.  The
goal of the puzzle is to have all the disks on the second peg in Order of size, with the largest on
the bottom.

Solution: Begin with n disks on peg 1.We can transfer the top n − 1 disks, following the rules of
the puzzle, to peg 3 using Hn−1 moves (see Figure for an illustration of the pegs and disks at
this  point).  We  keep  the  largest  disk  fixed  during  these  moves.  Then,  we  use  one  move  to
transfer the largest disk to the second peg. We can transfer the n − 1 disks on peg 3 to peg 2
using Hn−1 additional moves, placing them on top of the largest disk, which always stays fixed
on the bottom of peg 2.

Moreover, it is easy to see that the puzzle cannot be solved using fewer Schemes for efficiently
backing  up  computer  files  on  multiple  tapes  or  other  media  are  based  on  the  moves  used  to
solve the Tower of Hanoi puzzle. steps. This shows that Hn = 2Hn−1 + 1. The initial condition is
H1 = 1, because one disk can be transferred from peg 1 to peg 2, according to the rules of the
puzzle, in one move

Page 122 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/8.html 2/2
Combination
8/20/2015 scorm content

 
Code word Enumeration

A computer system considers a string of decimal digits a valid Code word if it contains an even
number of 0 digits. For instance, 1230407869 is valid, Whereas 120987045608 is not valid. Let
an be the number of valid n­digit code words. Find a recurrence relation for an.

Solution:  Note  that  a1  =  9  because  there  are  10  one­digit  strings,  and  only  one,  namely,  the
string 0, is not valid.A recurrence relation can be derived for this sequence by considering how a
valid  n­digit  string  can  be  obtained  from  strings  of  n  −  1  digits.  There  are  two  ways  to  form  a
valid string with n digits from a string with one fewer digit.

First, a valid string of n digits can be obtained by appending a valid string of n − 1 digits With a
digit other than 0. This appending can be done in nine ways. Hence, a valid string With n digits
can be formed in this manner in 9an−1 ways.

Second, a valid string of n digits can be obtained by appending a 0 to a string of length N − 1
that  is  not  valid.  (This  produces  a  string  with  an  even  number  of  0  digits  because  the  Invalid
string of length n − 1 has an odd number of 0 digits.) The number of ways that this can Be done
equals the number of invalid (n − 1)­digit strings. Because there are 10n−1 strings of Length n −
1,  and  an−1  are  valid,  there  are  10n−1  −  an−1  valid  n­digit  strings  obtained  by  Appending  an
invalid string of length n − 1 with a 0.

Because all valid strings of length n are produced in one of these two ways, it follows that There
are An = 9an−1 + (10n−1 − an−1) = 8an−1 + 10n−1 Valid strings of length n.

Many  recursive  algorithms  take  a  problem  with  a  given  input  and  divide  it  into  one  or  more
Smaller  problems.  This  reduction  is  successively  applied  until  the  solutions  of  the  smaller
problems Can be found quickly.

These  procedures  follow  an  important  algorithmic  paradigm  known  “Divide  et  impera”
(translation: “Divide and conquer” ­ Julius Caesar

As  divide­and­conquer,  and  are  called  divide­and­conquer  algorithms,  because  they  divide  a
problem into one or more instances of the same problem of smaller size and they conquer The
problem by using the solutions of the smaller problems to find a solution of the original Problem,
perhaps with some additional work.

Divide and Conquer examples

For instance, we perform a binary search by reducing the search for an element in a list to the
search  for  this  element  in  a  list  half  as  long.  We  successively  apply  this  reduction  until  one
element is left.

When we sort a list of integers using the merge sort, we split the list into two halves of equal size
and  sort  each  half  separately.We  then  merge  the  two  sorted  halves.  Another  example  of  this
type  of  recursive  algorithm  is  a  procedure  for  multiplying  integers  that  reduces  the  problem  of
the  multiplication  of  two  integers  to  three  multiplications  of  pairs  of  integers  with  half  as  many
bits. This reduction is successively applied until integers with one bit are obtained.

Page 123 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/9.html 1/2
Combination
8/20/2015 scorm content

Divide­and­Conquer Recurrence Relations

Suppose that a recursive algorithm divides a problem of size n into a subproblems, where each
subproblem is of size n/b (for simplicity, assume that n is a multiple of b; in reality, the smaller
problems are often of size equal to the nearest integers either less than or equal to, or greater
than or equal to, n/b).

Also,  suppose  that  a  total  of  g(n)  extra  operations  are  required  in  the  conquer  step  of  the
algorithm  to  combine  the  solutions  of  the  subproblems  into  a  solution  of  the  original  problem.
Then,  if  f  (n)  represents  the  number  of  operations  required  to  solve  the  problem  of  size  n,  it
follows that f satisfies the recurrence relation f (n) = af (n/b) + g(n). This is called a divide­and­
conquer recurrence relation.

Page 124 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/9.html 2/2
Combination
8/20/2015 scorm content

 
Finding the Maximum and Minimum of a Sequence

Consider  the  following  algorithm  for  locating  the  maximum  and  minimum  elements  of  a
sequence a1, a2, . . . , an. If n = 1, then a1 is the maximum and the minimum. If n > 1, split the
sequence into two sequences, either where both have the same number of elements or where
one of the sequences has one more element than the other. The problem is reduced to finding
the maximum and minimum of each of the two smaller sequences. The solution to the original
problem  results  from  the  comparison  of  the  separate  maxima  and  minima  of  the  two  smaller
sequences to obtain the overall maximum and minimum.

Let  f  (n)  be  the  total  number  of  comparisons  needed  to  find  the  maximum  and  minimum
elements  of  the  sequence  with  n  elements.  We  have  shown  that  a  problem  of  size  n  can  be
reduced into two problems of size n/2, when n is even, using two comparisons, one to compare
the maxima of the two sequences and the other to compare the minima of the two sequences.
This gives the recurrence relation f (n) = 2f (n/2) + 2 when n is even.

Merge Sort

The merge sort algorithm splits a list to be sorted with n items, where n is even, into two lists with
n/2  elements  each,  and  uses  fewer  than  n  comparisons  to  merge  the  two  sorted  lists  of  n/2
items each into one sorted list.

Consequently, the number of comparisons used by the merge sort to sort a list of n elements is
less thanM(n), where the function M(n) satisfies the divide­and­conquer recurrence relation M(n)
= 2M(n/2) + n.

Generating  functions  are  used  to  represent  sequences  efficiently  by  coding  the  terms  of  a
sequence as coefficients of powers of a variable x in a formal power series. Generating functions
can be used to solve many types of counting problems, such as the number of ways to select or
distribute objects of different kinds, subject to a variety of constraints, and the number of ways to
make  change  for  a  dollar  using  coins  of  different  denominations.  Generating  functions  can  be
used  to  solve  recurrence  relations  by  translating  a  recurrence  relation  for  the  terms  of  a
sequence into an equation involving a generating function.

The  generating  function  for  the  sequence  a0,  a1,  .  .  .  ,  ak,  .  .  .  of  real  numbers  is  the  infinite
Series

What is the generating function for the sequence 1, 1, 1, 1, 1, 1?

Solution: The generating function of 1, 1, 1, 1, 1, 1 is 1 + x + x2 + x3 + x4 + x5. By Theorem we
have (x6 − 1)/(x − 1) = 1 + x + x2 + x3 + x4 + x5 when x ≠ 1. Consequently, G(x) = (x6 − 1)/(x −
1) is the generating function of the sequence 1, 1, 1, 1, 1, 1. [Because the powers of x are only
place holders for the terms of the sequence in a generating function, we do not need to worry

Page 125 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/10.html 1/2
Combination
8/20/2015 scorm content

that G(1) is undefined.

Let  m  be  a  positive  integer.  Let  ak  =  C(m,  k),  for  k  =  0,  1,  2,  .  .  .  ,  m.  What  is  the  generating
function for the sequence a0, a1, . . . , am?

Solution: The generating function for this sequence is G(x) = C(m, 0) + C(m, 1)x + C(m, 2)x2 +· ·
·+C(m, m)xm. The binomial theorem shows that G(x) = (1 + x)m.

Generating  functions  can  be  used  to  solve  a  wide  variety  of  counting  problems.  In  particular,
they  can  be  used  to  count  the  number  of  combinations  of  various  types.  Find  the  number  of
solutions of e1 + e2 + e3 = 17, where e1, e2, and e3 are nonnegative integers with 2 ≤ e1 ≤ 5, 3
≤ e2 ≤ 6, and 4 ≤ e3 ≤ 7.

Solution:  The  number  of  solutions  with  the  indicated  constraints  is  the  coefficient  of  x17  in  the
expansion of (x2 + x3 + x4 + x5)(x3 + x4 + x5 + x6)(x4 + x5 + x6 + x7). This follows because we
obtain a term equal to x17 in the product by picking a term in the first sum xe1 , a term in the
second sum xe2 , and a term in the third sum xe3 , where the exponents e1, e2, and e3 satisfy
the equation e1 + e2 + e3 = 17 and the given constraints.

It  is  not  hard  to  see  that  the  coefficient  of  x17  in  this  product  is  3.  Hence,  there  are  three
solutions.  (Note  that  the  calculating  of  this  coefficient  involves  about  as  much  work  as
enumerating  all  the  solutions  of  the  equation  with  the  given  constraints.  However,  the  method
that  this  illustrates  often  can  be  used  to  solve  wide  classes  of  counting  problems  with  special
formulae,  as  we  will  see.  Furthermore,  a  computer  algebra  system  can  be  used  to  do  such
computations.)

Generating  functions  can  be  used  to  solve  a  wide  variety  of  counting  problems.  In  particular,
they  can  be  used  to  count  the  number  of  combinations  of  various  types.  Find  the  number  of
solutions of e1 + e2 + e3 = 17, Where e1, e2, and e3 are nonnegative integers with 2 ≤ e1 ≤ 5, 3
≤ e2 ≤ 6, and 4 ≤ e3 ≤ 7.

In  how  many  different  ways  can  eight  identical  cookies  be  distributed  among  three  distinct
Children if each child receives at least two cookies and no more than four cookies?

Solution: Because each child receives at least two but no more than four cookies, for each child
There is a factor equal to (x2 + x3 + x4) in the generating function for the sequence {cn}, where
cn  is  the  number  of  ways  to  distribute  n  Cookies.  Because  there  are  three  children,  this
generating function is (x2 + x3 + x4)3.

We need the coefficient of x8 in this product. The reason is that the x8 terms in the expansion
Correspond to the ways that three terms can be selected, with one from each factor, that have
Exponents  adding  up  to  8.  Furthermore,  the  exponents  of  the  term  from  the  first,  second,  and
Third  factors  are  the  numbers  of  cookies  the  first,  second,  and  third  children  receive,
respectively.  Computation  shows  that  this  coefficient  equals  6.  Hence,  there  are  six  ways  to
distribute the Cookies so that each child receives at least two, but no more than four, cookies.

Page 126 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/10.html 2/2
Combination
8/20/2015 scorm content

 
THE PRINCIPLE OF INCLUSION–EXCLUSION

Let A1,A2, . . . , An be finite sets. Then

Proof: We will prove the formula by showing that an element in the union is counted exactly once
by  the  right­hand  side  of  the  equation.  Suppose  that  a  is  a  member  of  exactly  r  of  the  sets
A1,A2, . . . , An where 1 ≤ r ≤ n. This element is counted C(r, 1) times by _|Ai |. It is Counted C(r,
2) times by _|Ai ∩ Aj |. In general, it is counted C(r,m) times by the summation Involving m of the
sets  Ai  .  Thus,  this  element  is  counted  exactly  C(r,  1)  −  C(r,  2)  +  C(r,  3)−·  ·  ·+(−1)r+1C(r,  r)
Times by the expression on the right­hand side of this equation. We have C(r, 0) − C(r, 1) + C(r,
2)−· · ·+(−1)rC(r, r) = 0.

Hence, 1 = C(r, 0) = C(r, 1) − C(r, 2)+· · ·+(−1)r+1C(r, r). Therefore, each element in the union is
counted exactly once by the expression on the right­hand side of the equation. This proves the
principle of inclusion–exclusion.

The  inclusion–exclusion  principle  gives  a  formula  for  the  number  of  elements  in  the  union  of  n
sets for every positive integer n. There are terms in this formula for the number of elements in
the intersection of every nonempty subset of the collection of the n sets. Hence, there are 2n − 1
terms in this formula.

Give a formula for the number of elements in the union of four sets.

Solution: The inclusion–exclusion principle shows that

Note  that  this  formula  contains  15  different  terms,  one  for  each  nonempty  subset  of
{A1,A2,A3,A4}.

A  total  of  1232  students  have  taken  a  course  in  Spanish,  879  have  taken  a  course  in  French,
and 114 have taken a course in Russian. Further, 103 have taken courses in both Spanish and
French, 23 have taken courses in both Spanish and Russian, and 14 have taken courses in both
French and Russian.

If 2092 students have taken at least one of Spanish, French, and Russian, how many students
have taken a course in all three languages?

Solution: Let S be the set of students who have taken a course in Spanish, F the set of students who have

Page 127 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/11.html 1/2
Combination
8/20/2015 scorm content

taken a course in French, and R the set of students who have taken a course in Russian. Then

Suppose  that  there  are  1807  freshmen  at  your  school.  Of  these,  453  are  taking  a  course  in
Computer science, 567 are taking a course in mathematics, and 299 are taking courses in both
Computer  science  and  mathematics.  How  many  are  not  taking  a  course  either  in  computer
science Or in mathematics?

Solution: To find the number of freshmen who are not taking a course in either mathematics Or
computer science, subtract the number that are taking a course in either of these subjects From
the  total  number  of  freshmen.  Let  A  be  the  set  of  all  freshmen  taking  a  course  in  computer
Science, and let B be the set of all freshmen taking a course in mathematics. It follows That |A| =
453, |B| = 567, and |A ∩ B| = 299. The number of freshmen taking a course in Either computer
science or mathematics is |A ∪ B| = |A| + |B| − |A ∩ B| = 453 + 567 − 299 = 721. Consequently,
there  are  1807  −  721  =  1086  freshmen  who  are  not  taking  a  course  in  computer  Science  or
mathematics.

Page 128 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit6/assets/11.html 2/2
UNIT - 7
Graph Theory

Page 129 of 189


Graph Theory
8/20/2015 scorm content

 
Graph Theory

Graph theory is a branch of mathematics concerned about how networks can be encoded and
their properties measured. It has been enriched in the last decades by growing influences from
studies of social and complex networks.

History of Graph Theory

Königsberg bridge problem

The history of graph theory may be specifically traced to 1735, when the Swiss mathematician
Leonhard Euler solved the Königsberg bridge problem.

The  Königsberg  bridge  problem  was  an  old  puzzle  concerning  the  possibility  of  finding  a  path
over  every  one  of  seven  bridges  that  span  a  forked  river  flowing  past  an  island  but  without
crossing any bridge twice (see the diagram).

Euler  argued  that  no  such  path  exists;  his  proof  involved  only  references  to  the  physical
arrangement of the bridges, but essentially he proved the first theorem in graph theory.

What is Graph Theory?

Branch  of  mathematics  concerned  with  networks  of  points  connected  by  lines.  The  subject  of
graph  theory  had  its  beginnings  in  recreational  math  problems  (see  number  game),  but  it  has
grown into a significant area of mathematical research with applications in chemistry, operations
research, social sciences, and computer science.

Undirected Graphs

Perhaps  the  most  distinguishing  characteristic  of  mathematics  is  its  reliance  on  logic.  Explicit
training in mathematical logic is essential to a mature understanding of mathematics.

Adjacency

Adjacency: Two vertices u and v are adjacent if there exists an edge (u,v) that connects them.

Incidence: An edge (u,v) is said to be incident upon nodes u and v

Loops: An edge e = (u,u) that links a vertex to itself is known as a self­loop or reflexive tie.

Example

As  an  example,  the  graph  undirected  depicted  in  Figure  5  has  vertex  set  V={a,b,c,d,e.f}  and
edge set E = {{a,b},{b,c},{c,d},{c,e},{d,e},{e,f}}

Formal definition of graph

A graph G = (V ,E) consists of V , a nonempty set of vertices (or nodes) and E, a set of edges.
Each edge has either one or two vertices associated with it, called its endpoints. An edge is said
to connect its endpoints.

Page 130 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/2.html 1/5
Graph Theory
8/20/2015 scorm content

The set of vertices V of a graph G may be infinite. A graph with an infinite vertex set or an infinite
number of edges is called an infinite graph, and in comparison, a graph with a finite vertex set
and a finite edge set is called a finite graph.

Multigraphs

Graphs  that  may  have  multiple  edges  connecting  the  same  vertices  are  called  multigraphs.
When there are m different edges associated to the same unordered pair of vertices {u, v}, we
also say that {u, v} is an edge of multiplicity m.

That is, we can think of this set of edges as m different copies of an edge {u, v}.

Example Subgraph

A graph G1 is a subgraph of another graph G if and only if the vertex and edge sets of G1 are,
respectively, subsets of the vertex and edge sets of G.

EXAMPLE Each of the three graphs G1, G2 and G3 shown on the right of Figure is a subgraph
of the graph G on the left in this figure. (The subgraphs do not have to be drawn the same way
they appear in the presentation of G.

Subgraph

Figure depicts a graph g and two subgraphs G1 and G2 . The last graph in this figure, G3, is not
a subgraph of G because the two vertices of degree 3 in G are not adjacent.

Directed graph

A  directed  graph  (or  digraph)  (V  ,E)  consists  of  a  nonempty  set  of  vertices  V  and  a  set  of
directed  edges  (or  arcs)  E.  Each  directed  edge  is  associated  with  an  ordered  pair  of  vertices.
The directed edge associated with the ordered pair (u, v) is said to start at u and end at v.

Path graph

Informally,  a  path  is  a  sequence  of  edges  that  begins  at  a  vertex  of  a  graph  and  travels  from
vertex  to  vertex  along  edges  of  the  graph.  As  the  path  travels  along  its  edges,  it  visits  the
vertices along this path, that is, the endpoints of these edges.

Paths and circuits

Let n be a non­negative integer and G an undirected graph. A path of length n from u to v in G is
a sequence of n edges e 1 , · · · , en of G such that e 1  is associated with {x 0 , x 1 }, e 2  is associated
with {x 1 , x 2 }, and so on, with enassociated with {x n−1 , x n }, where x 0  = u and x n  = v.

When the graph is simple, we denote this path by its vertex sequence x 0 , x 1 , · · · , x n . Because


listing these vertices uniquely determines the path. The path is a circuit if it begins and ends at
the same vertex and has length greater than zero. The path or circuit is said to pass through the
vertices x 1 , x 2 , · · · , x n  or traverse the edges e 1 , e 2 , · · · , en. A path or circuit is simple if it dose
not contain the same edge more than once.

Path graph
Page 131 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/2.html 2/5
Graph Theory
8/20/2015 scorm content

In the simple graph shown in Figure, a, d, c, f , e is a simple path of length 4, because {a, d}, {d,
c},  {c,  f  },  and  {f,  e}  are  all  edges.  {a,  d},  {d,  c},  {c,  f  },  {f,  e}.However,  d,  e,  c,  a  is  not  a  path,
because {e, c} is not an edge. Note that b, c, f , e, b is a circuit of length 4 because {b, c}, {c, f },
{f, e}, and {e, b} are edges, and this path begins and ends at b. The path a, b, e, d, a, b, which is
of

length 5, is not simple because it contains the edge {a, b} twice.

Paths and circuits

Let n be a nonnegative integer and G a directed graph. A path of length n from u to v in G is a
sequence  of  edges  e 1 ,  e 2 ,  ·  ·  ·  ,  en  of  G  such  that.  e 1   is  associated  with  (x 0 ,  x 1 ),  e 2   is
associated with (x 1 , x 2 ), and son on, with en associated with (x n−1 , x n ), where x 0  = u and x n  = v.
When  there  are  no  multiple  edges  in  the  directed  graph.  this  path  is  denoted  by  its  vertex
sequence x 0 , x 1 , x 2 ,  ·  ·  ·  ,  x n .  A  path  of  length  greater  than  zero  that  begins  and  ends  at  the
same vertex is called a circuit or cycle. A path or circuit is called simple if. it does not contain the
same edge more than once.

Simple Graphs

Graphs in which there is no more than one edge between any two vertices and in which no edge
goes from vertex to the same vertex are called simple.

Degree of a vertex

Degree  of  a  vertex  in  an  undirected  graph  is  the  number  of  edges  incident  on  it.  In  a  directed
graph,  the  out  degree  of  a  vertex  is  the  number  of  edges  leaving  it  and  the  in  degree  is  the
number of edges entering it.

Degree of vertex 2 is 3.

Degree  of  a  vertex  in  an  undirected  graph  is  the  number  of  edges  incident  on  it.  In  a  directed
graph,  the  out  degree  of  a  vertex  is  the  number  of  edges  leaving  it  and  the  in  degree  is  the
number of edges entering it.

The degree of vertex 2 is 2 and the in degree of vertex 4 is 1

Find the degree of the following graphs.

A has degree 0, B has degree 1, C has degree 2 and D has degree 3.

In any graph, the sum of the degrees of the vertices equals twice the number of edges.

Find the Degree of A, B, C, and D

Degree

A graph has exactly four vertices, each of degree 3. How many edges does this graph have?

The sum of degrees of the vertices is 12.

By the theorem, this number is twice the number of edges,
Page 132 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/2.html 3/5
Graph Theory
8/20/2015 scorm content

So The number of edges is = 12/2 = 6

Weighted Graph

A weighted graph is a graph for which each edge has an associated weight, usually given by a
weight function w: E → R

Walk, Path and Cycle Weighted Graph

A walk is an sequence of nodes (V 1 , V 2 ,..., vL) such that {(V 1 , V 2 ), (V 1 , V 2 ),..., (V 1 , V 2 )} E, e.g.


(V 2 , V 3 ,V 6 , V 5 ,V 3 ).

A simple path is a walk with no repeated nodes, e.g. (V 1 , V 4 ,V 5 , V 2 ,V 3 ).

A cycle is an walk (V 1 , V 2 ,..., v L ) where V 1 =v L  with no other nodes repeated and L>3, e.g. (V 1 ,


V 2 ,V 5 , V 4 ,V 1 ).

A graph is called cyclic if it contains a cycle; otherwise it is called acyclic.

The relation between walk path and cycle is shown.

Complete graph

Degree  of  a  vertex  in  an  undirected  graph  is  the  number  of  edges  incident  on  it.  In  a  directed
graph,  the  out  degree  of  a  vertex  is  the  number  of  edges  leaving  it  and  the  in  degree  is  the
number of edges entering it.

A complete graph is an undirected/directed graph in which every pair of vertices is adjacent.

If (u, v ) is an edge in a graph G, we say that vertex v is adjacent to vertex u.

4 nodes and (4*3)/2 edges

V nodes and V*(V–1)/2 edges

Draw a complete graph with four vertices.

A complete graph is an undirected/directed graph in which every pair of vertices is adjacent.

If (u, v) is an edge in a graph G, we say that vertex v is adjacent to vertex u.

Connected graph

An  undirected  graph  is  connected  if  you  can  get  from  any  node  to  any  other  by  following  a
sequence of edges OR any two nodes are connected by a path.

Strongly connected

A  directed  graph  is  strongly  connected  if  there  is  a  directed  path  from  any  node  to  any  other
node.

Bipartite graph

Page 133 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/2.html 4/5
Graph Theory
8/20/2015 scorm content

A bipartite graph is an undirected graph G = (V,E) in which V can be partitioned into 2 sets V 1
and V 2  such that ( u,v) ∈ E implies either u ∈ V 1  and v ∈ V 2  OR v ∈ V 1  and u ∈ V 2 .

Map and Coloring

A map is a partition of the plane into connected regions.

A  coloring  of  a  simple  graph  is  the  assignment  of  a  color  to  each  vertex  of  the  graph.  Can  we
color  the  regions  of  every  map  using  at  most  four  colors  so  that  neighboring  regions  have
different colors?

Map Coloring → graph coloring. A region → A vertex. Adjacency → An edge

Strongly connected

Scheduling and Coloring

Two  committees  cannot  hold  meetings  at  the  same  time  if  two  committees  have  common
member.

Model:

One committee being represented by a vertex.

An edge between two vertices if two corresponding committees have common member.

Two adjacent vertices cannot receive the same color.

Map and Coloring

Scheduling problem is equivalent to graph coloring problem.

Incidence and adjacency

Two vertices u and v in an undirected graph G are called adjacent (or neighbors) in G if u and v
are endpoints of an edge e of G. Such an edge e is called incident with the vertices u and v and
e is said to connect u and v.

The vertices u and v are called endpoints of the edge {u, v}.

Strongly connected

Complete  Graphs  A  complete  graph  on  n  vertices,  denoted  by  Kn,  is  a  simple  graph  that
contains exactly one edge between each pair of distinct vertices. The graphs Kn, for n = 1, 2, 3,
4, 5, 6, are displayed.

A simple graph for which there is at least one pair of distinct vertex not connected by an edge is
called noncomplete.

Page 134 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/2.html 5/5
Graph Theory
8/20/2015 scorm content

 
Graph representation

Carrying  out  graph  algorithms  using  the  representation  of  graphs  by  lists  of  edges,  or  by
adjacency lists, can be cumbersome if there are many edges in the graph

To simplify computation, graphs can be represented using matrices.

Two types of matrices commonly used to represent graphs will be presented here.

One is based on the adjacency of vertices, and the other is based on incidence of vertices and
edges.

Adjacency matrix

Suppose that G = (V ,E) is a simple graph where |V| = n.

Suppose that the vertices of G are listed arbitrarily as V 1 , V 2 , . . . , vn.

The adjacency matrix A (or AG) of G, with respect to this listing of the vertices, is the n x n zero–
one matrix with 1 as its (i, j)th entry when vi and vj are adjacent, and 0 as its (i, j)th entry when
they are not adjacent In other words, if its adjacency matrix is A = [aij], then aij = 1 if{vi , vj } is an
edge of G, aij = 0 otherwise.

Use an adjacency matrix to represent the pseudograph shown.

Draw a graph with the adjacency matrix.

The  adjacency  matrix  of  a  simple  graph  is  symmetric,  that  is,  aij  =  aji  ,  because  both  of  these
entries are 1 when vi and vj are adjacent, and both are 0 otherwise.

Furthermore, because a simple graph has no loops, each entry aii, i = 1, 2, 3, . . . , n, is 0.

Adjacency  matrices  can  also  be  used  to  represent  undirected  graphs  with  loops  and  with
multiple edges.

A loop at the vertex vi is represented by a 1 at the (i, i)th position of the adjacency matrix.

When  multiple  edges  connecting  the  same  pair  of  vertices  vi  and  vj,  or  multiple  loops  at  the
same vertex, are present, the adjacency matrix is no longer a zero–one matrix, because the (i, j
) the entry of this matrix equals the number of edges that are associated to {vi , vj }.

All  undirected  graphs,  including  multigraphs  and  pseudographs,  have  symmetric  adjacency
matrices.

Use an adjacency matrix to represent the pseudograph shown.

Another  way  to  represent  a  graph  is  to  use  adjacency  lists,  which  specify  the  vertices  that  are
adjacent to each vertex of the graph.

Page 135 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/3.html 1/5
Graph Theory
8/20/2015 scorm content

Use adjacency lists to describe the simple graph given.

Use adjacency lists to describe the simple graph given.

Page 136 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/3.html 2/5
Graph Theory
8/20/2015 scorm content

Page 137 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/3.html 3/5
Graph Theory
8/20/2015 scorm content

Incidence matrix

Another common way to represent graphs is to use incidence matrices.

Let G = (V ,E) be an undirected graph.

Suppose that V 1 , V 2 , . . . , vn are the vertices and e 1 , e 2 , . . . , em are the edges of G.

Where mij = 1 when edge ej is incident with vi, mij = 0 otherwise.

Represent the graph shown in Figure below with an incidence matrix.

Page 138 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/3.html 4/5
Graph Theory
8/20/2015 scorm content

Page 139 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/3.html 5/5
Graph Theory
8/20/2015 scorm content

 
Euler path

The town of Königsberg, Prussia (now called Kaliningrad and part of the Russian republic),was
divided into four sections by the branches of the Pregel River.

These four sections included the two regions on the banks of the Pregel, Kneiphof Island, and
the  region  between  the  twobranches  of  the  Pregel.  In  the  eighteenth  century  seven  bridges
connected these regions.

The  townspeople  took  long  walks  through  town  on  Sundays.  They  wondered  whether  it
waspossible  to  start  at  some  location  in  the  town,  travel  across  all  the  bridges  once  without
crossing any bridge twice, and return to the starting point.

Euler path and circuit

Euler studied this problem using the multigraph obtained when the four regions are represented
by vertices and the bridges by edges. This multigraph is also shown.

First,  Euler  pointed  out  that  the  choice  of  route  inside  each  land  mass  is  irrelevant.  The  only
important feature of a route is the sequence of bridges crossed.

This allowed him to reformulate the problem in abstract terms (laying the foundations of graph
theory), eliminating all features except the list of land masses and the bridges connecting them.

In  modern  terms,  one  replaces  each  land  mass  with  an  abstract  "vertex"  or  node,  and  each
bridge with an abstract connection, an "edge", which only serves to record which pair of vertices
(land  masses)  is  connected  by  that  bridge.  The  resulting  mathematical  structure  is  called  a
graph.

Next, Euler observed that (except at the endpoints of the walk), whenever one enters a vertex by
a bridge, one leaves the vertex by a bridge.

In  other  words,  during  any  walk  in  the  graph,  the  number  of  times  one  enters  a  non­terminal
vertex equals the number of times one leaves it.

Now, if every bridge has been traversed exactly once, it follows that, for each land mass (except
for the ones chosen for the start and finish), the number of bridges touching that land mass must
be  even  (half  of  them,  in  the  particular  traversal,  will  be  traversed  "toward"  the  landmass;  the
other half, "away" from it).

However, all four of the land masses in the original problem are touched by an odd number of
bridges (one is touched by 5 bridges, and each of the other three are touched by 3).

Since, at most, two land masses can serve as the endpoints of a putative walk, the proposition of
a walk traversing each bridge once leads to a contradiction.

An Euler circuit in a graph G is a simple circuit containing every edge of G. An Euler path in G is
a  simple  path  containing  every  edge  of  G.  The  figure  shows  the  concept  of  Euler  paths  and
circuits.

Page 140 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/4.html 1/3
Graph Theory
8/20/2015 scorm content

Which of the undirected graphs in Figure have an Euler circuit? Of those that do not, which have
an Euler path?

Solution:

The graph G 1  has an Euler circuit, for example, a, e, c, d, e, b, a.

Neither of the graphs G 2  or G 3  has an Euler circuit (the reader should verify this).

However, G 3  has an Euler path, namely, a, c, d, e, b, d, a, b.

G 2  does not have an Euler path.

Which of the directed graphs in Figure have an Euler circuit? Of those that do not, which have
an Euler path?

Solution:

The graph H 2  has an Euler circuit, for example, a, g, c, b, g, e, d, f, a.

Neither H 1  nor H 3  has an Euler circuit (as the reader should verify).

H 3  has an Euler path, namely, c, a, b, c, d, b. but H 1  does not

A connected multigraph with at least two vertices has an Euler circuit if and only if each of
its vertices has even degree.

An Euler circuit in a graph G is a simple circuit containing every edge of G. An Euler path
in G is a simple path containing every edge of G. The figure shows the concept of Euler
paths and circuits.

Many puzzles ask you to draw a picture in a continuous motion without lifting a pencil so
that no part of the picture is retraced. We can solve such puzzles using Euler circuits and
paths.

For  example,  can  Mohammed’s  scimitars,  shown  in  Figure,  be  drawn  in  this  way,  where  the
drawing begins and ends at the same point?

Solution:

We can solve this problem because the graph G shown in Figure has an Euler circuit.

It has such a circuit because all its vertices have even degree.

First, we form the circuit a, b, d, c, b, e, i, f, e, a.

We obtain the subgraph H by deleting the edges in this circuit and all vertices that become
isolated when these edges are removed.

Then we form the circuit d, g, h, j, i, h, k, g, f, d in H.

After forming this circuit we have used all edges in G.

Page 141 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/4.html 2/3
Graph Theory
8/20/2015 scorm content

Splicing  this  new  circuit  into  the  first  circuit  at  the  appropriate  place  produces  the  Euler
circuit a, b, d, g, h, j, i, h, k, g, f, d, c, b, e, i, f, e, a.

This circuit gives a way to draw the scimitars without lifting the pencil or retracing part of
the picture.

A  connected  multigraph  has  an  Euler  path  but  not  an  Euler  circuit  if  and  only  if  it  has
exactly two vertices of odd degree.

Which graphs shown in Figure have an Euler path?

Solution:

G 1  contains exactly two vertices of odd degree, namely, b and d.

Hence, it has an Euler path that must have b and d as its endpoints.

One such Euler path is d, a, b, c, d, b.

Similarly:

G 2  has exactly two vertices of odd degree, namely, b and d.

So it has an Euler path that must have b and d as endpoints.

One such Euler path is b, a, g, f, e, d, c, g, b, c, f, d.

G 3  has no Euler path because it has six vertices of odd degree.

Euler paths and circuits can be used to solve many practical problems.

For  example,  many  applications  ask  for  a  path  or  circuit  that  traverses  each  street  in  a
neighborhood,  each  road  in  a  transportation  network,  each  connection  in  a  utility  grid,  or  each
link in a communications network exactly once.

Finding an Euler path or circuit in the appropriate graph model can solve such problems.

For  example,  if  a  postman  can  find  an  Euler  path  in  the  graph  that  represents  the  streets  the
postman  needs  to  cover,  this  path  produces  a  route  that  traverses  each  street  of  the  route
exactly once.

If no Euler path exists, some streets will have to be traversed more than once.

The  problem  of  finding  a  circuit  in  a  graph  with  the  fewest  edges  that  traverses  every  edge  at
least once is known as the Chinese postman problem in honor of Guan Meigu, who posed it in
1962.

Page 142 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/4.html 3/3
Graph Theory
8/20/2015 scorm content

 
Hamilton paths and circuits

A simple path in a graph G that passes through every vertex exactly once is called a Hamilton
path, and a simple circuit in a graph G that passes through every vertex exactly once is called a
Hamilton circuit.

That is, the simple path x 0 , x 1 , . . . , x n−1 , x n  in the graph G = (V ,E) is a Hamilton path

if V = {x 0 , x 1 , . . . , x n−1 , x n } and

xi = xj for 0 ≤ i < j ≤ n, and the simple circuit.

x 0 , x 1 , . . . , x n−1 , x n , x 0

(with n > 0) is a Hamilton circuit

if x 0 , x 1 , . . . , x n−1 , x n  is a Hamilton path.

Which of the simple graphs in Figure have a Hamilton circuit or, if not, a Hamilton path?

Solution:

G 1  has a Hamilton circuit: a, b, c, d, e, a.

There is no Hamilton circuit in G 2   (this  can  be  seen  by  noting  that  any  circuit  containing
every  vertex  must  contain  the  edge  {a,  b}  twice),  but  G 2   does  have  a  Hamilton  path,
namely, a, b, c, d.

G 3   has  neither  a  Hamilton  circuit  nor  a  Hamilton  path,  because  any  path  containing  all
vertices must contain one of the edges {a, b}, {e, f}, and {c, d} more than once.

Show that neither graph displayed in Figure has a Hamilton circuit.

Solution:

There is no Hamilton circuit in G because G has a vertex of degree one, namely, e.

Now consider H

Because  the  degrees  of  the  vertices  a,  b,  d,  and  e  are  all  two,  every  edge  incident  with
these vertices must be part of any Hamilton circuit.

It is now easy to see that no Hamilton circuit can exist in H, for any Hamilton circuit would
have to contain four edges incident with c, which is impossible.

Applications of Hamilton Circuits

Hamilton paths and circuits can be used to solve practical problems.

For  example,  many  applications  ask  for  a  path  or  circuit  that  visits  each  road  intersection  in  a
city,  each  place  pipelines  intersect  in  a  utility  grid,  or  each  node  in  a  communications  network
exactly once.
Page 143 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/5.html 1/2
Graph Theory
8/20/2015 scorm content

Finding a Hamilton path or circuit in the appropriate graph model can solve such problems.

The famous traveling salesperson problem or TSP (also known in older literature as the traveling
salesman problem) asks for the shortest route a traveling salesperson should take to visit a set
of cities.

This problem reduces to finding a Hamilton circuit in a complete graph such that the total weight
of its edges is as small as possible.

Page 144 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/5.html 2/2
Graph Theory
8/20/2015 scorm content

 
Travelling salesman problem

An  important  problem  involving  weighted  graphs  asks  for  a  circuit  of  shortest  total  length  that
visits every vertex of a complete graph exactly once.

This  is  the  famous  traveling  salesperson  problem,  which  asks  for  an  order  in  which  a
salesperson  should  visit  each  of  the  cities  on  his  route  exactly  once  so  that  he  travels  the
minimum total distance.

Consider a four city TSP for which The cost between the city pairs are as shown in the figure.

Find the tour of the salesman so that the cost of travel is minimal.

The  traveling  salesperson  problem  asks  for  the  circuit  of  minimum  total  weight  in  a  weighted,
complete, undirected graph that visits each vertex exactly once and returns to its starting point.

This  is  equivalent  to  asking  for  a  Hamilton  circuit  with  minimum  total  weight  in  the  complete
graph, because each vertex is visited exactly once in the circuit.

The  most  straightforward  way  to  solve  an  instance  of  the  traveling  salesperson  problem  is  to
examine all possible Hamilton circuits and select one of minimum total length.

How  many  circuits  do  we  have  to  examine  to  solve  the  problem  if  there  are  n  vertices  in  the
graph?

Once  a  starting  point  is  chosen,  there  are  (n  −  1)!  Different  Hamilton  circuits  to  examine,
because there are n − 1 choices for the second vertex, n − 2 choices for the third vertex, and so
on.

Because  a  Hamilton  circuit  can  be  traveled  in  reverse  order,  we  need  only  examine  (n  −  1)!/2
circuits to find our answer. Note that (n − 1)!/2 grows extremely rapidly.

Trying  to  solve  a  traveling  salesperson  problem  in  this  way  when  there  are  only  a  few  dozen
vertices is impractical.

For  example,  with  25  vertices,  a  total  of  24!/2  (approximately  3.1  ×  1023)  different  Hamilton
circuits would have to be considered.

(Approximately 3.1 × 1023) different Hamilton circuits would have to be considered.

If  it  took  just  one  nanosecond  (10−9  second)  to  examine  each  Hamilton  circuit,  a  total  of
approximately  ten  million  years  would  be  required  to  find  a  minimum­length  Hamilton  circuit  in

Page 145 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/6.html 1/3
Graph Theory
8/20/2015 scorm content

this graph by exhaustive search techniques.

Because  the  traveling  salesperson  problem  has  both  practical  and  theoretical  importance,  a
great deal of effort has been devoted to devising efficient algorithms that solve it.

However,  no  algorithm  with  polynomial  worst­case  time  complexity  is  known  for  solving  this
problem.

Furthermore,  if  a  polynomial  worst­case  time  complexity  algorithm  were  discovered  for  the
traveling  salesperson  problem,  many  other  difficult  problems  would  also  be  solvable  using
polynomial worst­case time complexity algorithms.

A practical approach to the traveling salesperson problem when there are many vertices to visit
is to use an approximation algorithm.

These  are  algorithms  that  do  not  necessarily  produce  the  exact  solution  to  the  problembut
instead are guaranteed to produce a solution that is close to an exact solution.

Brute force approach

List all of the possible Hamilton circuits

Calculate the total weights for each of the possible Hamilton circuit

Choose an optimal circuit (cheapest, shortest, or fastest…)

Therefore: optimal circuits are C,B,A,D,C or C,D,A,B,C

If the problem asks to start at A then the optimal circuits are D,C,B,A or A,B,C,D,A

Nearest neighbor problem

From the starting vertex, go to its nearest neighbor (the edge has the smallest weight)

Repeating step 1 with the next vertex and the next vertex until there is no more vertex to visit.

From the last vertex, return to the starting point

Start at C, pick CB = 15

From B, pick BD = 10

Page 146 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/6.html 2/3
Graph Theory
8/20/2015 scorm content

From D, pick DA = 30

No more vertex left, so connect A and C, with AC = 70

Therefore, the route is C,B,D,A,C = 125

The Brute­Force Algorithm: optimal but inefficient algorithm

The  Nearest­Neighbor  Algorithm  and  Repetitive  Nearest­Neighbor:  Efficient  but  not  optimal
algorithms

The Repetitive Nearest­Neighbor Algorithm

Apply the Nearest Neighbor Algorithm to each of the vertices to calculate the total weights.

Choose the best circuit.

If there is a designated starting vertex, rewrite the circuit using that vertex as the reference point.

The Repetitive Nearest­Neighbor Algorithm

Apply the Nearest Neighbor Algorithm to each of the vertices to calculate the total weights.

Choose  the  best  circuit.  If  there  is  a  designated  starting  vertex,  rewrite  the  circuit  using  that
vertex as the reference point.

One of the best routes is C,B,D,A,C = 125

Or if re­write with starting point A: A,C,B,D,A.

Planar Graphs

Consider  the  problem  of  joining  three  houses  to  each  of  three  separate  utilities,  as  shown  in
Figure. Is it possible to join these houses and utilities so that none of the connections cross?

This problem can be modeled using the complete bipartite graph K3.3. The original question can
be rephrased as: Can K3.3 be drawn in the plane so that no two of its edges cross?

A  graph  is  called  planar  if  it  can  be  drawn  in  the  plane  without  any  edges  crossing  (where  a
crossing of edges is the intersection of the lines or arcs representing them at a point other than
their common endpoint).Such a drawing is called a planar representation of the graph.

Is the graph (shown in Figure with two edges crossing) planar?

The graph is planar because it can be redrawn without crossings, as shown.

Is the graph, shown in Figure, planar?

The graph is planar, because it can be drawn without any edges crossing, as shown

Page 147 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/6.html 3/3
Graph Theory
8/20/2015 scorm content

 
Trees

A connected graph that contains no simple circuits is called a tree. Trees were used as long ago
as  1857,  when  the  English  mathematician  Arthur  Cayley  used  them  to  count  certain  types  of
chemical compounds.

Since that time, trees have been employed to solve problems in a wide variety of disciplines.

Trees are particularly useful in computer science, where they are employed in a wide range of
algorithms.

For instance, trees are used to construct efficient algorithms for locating items in a list.

They can be used in algorithms, such as Huffman coding, that construct efficient codes saving
costs in data transmission and storage.

Trees can be used to study games such as checkers and chess and can help determine winning
strategies for playing these games.

Trees can be used to model procedures carried out using a sequence of decisions.

Constructing  these  models  can  help  determine  the  computational  complexity  of  algorithms
based on a sequence of decisions, such as sorting algorithms.

A  tree  is  a  connected  undirected  graph  with  no  simple  circuits.  Because  a  tree  cannot  have  a
simple  circuit,  a  tree  cannot  contain  multiple  edges  or  loops.  Therefore  any  tree  must  be  a
simple graph.

An undirected graph is a tree if and only if there is a unique simple path between any two of its
vertices.

A rooted tree is a tree in which one vertex has been designated as the root and every edge is
directed away from the root.

Spanning Trees
Page 148 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/7.html 1/4
Graph Theory
8/20/2015 scorm content

Let G be a simple graph. A spanning tree of G is a subgraph of G that is a tree containing every
vertex of G. Find a spanning tree of the simple graph G shown. Solution:

Finally, remove edge {c, g} to produce a simple graph with no simple circuits. This subgraph is a
spanning  tree,  because  it  is  a  tree  that  contains  every  vertex  of  G.  The  sequence  of  edge
removals used to produce the spanning tree is illustrated in Figure.

Cut set

A  cut  set  is  a  minimal  set  of  edges  that,  when  broken,  breaks  the  graph  into  two  completely
separate  parts  (two  groups  of  nodes.  Minimal  means  that  a  cut  set  cannot  contain  another
smaller cut set that would break the graph into the same two parts.

Suppose I am given a tree. A fundamental cut set w.r.t. that tree is a cut set that only contains
one branch of the tree. There may be many fundamental cut sets w.r.t. a given tree.

Spanning Trees

Finding fundamental cut sets

Redraw the graph with the tree in a straight line.

For each tree edge, form its fundamental cut set as follows:

That tree edge is a member of this fundamental cut set

Cut that edge…what two groups of nodes are separated?

The fundamental cut set also contains all edges in the co­tree that connect these two groups.

Cut sets

Minimum cut problems arise in many context:

Study of network reliability (smallest number of edges that can fail).

Study of network optimization (find a maximum flow).

Clustering problems (edges like association’s rules).

Matching problems.

The Minimal Spanning Tree Problem

Consider the undirected network as shown in the figure.

The graph consists of nodes and edges, and each edge has an associated length.

An edge is the line segment connecting two nodes and has the same length in either direction.

The Minimal Spanning Tree problem is to select a set of edges so that there is a path between
each node.

The sum of the edge lengths is to be minimized.
Page 149 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/7.html 2/4
Graph Theory
8/20/2015 scorm content

Minimum spanning

sort the edges of G in increasing order by length

keep a subgraph S of G, initially empty

for each edge e in sorted order.

if the endpoints of e are disconnected in S.

add e to S

return S

Prim’s Algorithm

Page 150 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/7.html 3/4
Graph Theory
8/20/2015 scorm content

Page 151 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit7/assets/7.html 4/4
UNIT - 8
First state machines & languages

Page 152 of 189


First state machines & languages
8/20/2015 scorm content

 
Introduction

Words in the English language can be combined in various ways.

The grammar of English tells us whether a combination of words is a valid sentence.

An alphabet is a set of symbols

{ a, b }

Sentences are strings of symbols

a, b, aa, ab, ba, a......

A language is a set of sentences

L = (aaa, abaa, aaba, bbb )

For instance, the frog writes neatly is a valid sentence, because it is formed from a noun phrase,
the frog, made up of the article the and the noun frog, followed by a verb phrase, writes neatly,
made up of the verb writes and the adverb neatly.

We  do  not  care  that  this  is  a  nonsensical  statement,  because  we  are  concerned  only  with  the
syntax, or form, of the sentence, and not its semantics, or meaning.

We
also
note  that
the

combination  of  words  swims  quickly  mathematics  is  not  a  valid  sentence  because  it  does  not
follow the rules of English grammar.

The  sentences  of  a  formal  language  using  a  grammar.  The  use  of  grammars  helps  when  we
consider the two classes of problems that arise most frequently in applications to programming
languages:

How  can  we  determine  whether  a  combination  of  words  is  a  valid  sentence  in  a  formal
language?

How can we generate the valid sentences of a formal language?

Before giving a technical definition of a grammar, we will describe an example of a grammar that
generates a subset of English.

This subset of English is defined using a list of rules that describe how a valid sentence can be
produced.
Page 153 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/2.html 1/2
First state machines & languages
8/20/2015 scorm content

Page 154 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/2.html 2/2
First state machines & languages
8/20/2015 scorm content

 
Definition

A  vocabulary  (or  alphabet)  V  is  a  finite,  nonempty  set  of  elements  called  symbols.  A  word  (or
sentence)  over  V  is  a  string  of  finite  length  of  elements  of  V  .  The  empty  string  or  null  string,
denoted by λ, is the string containing no symbols.

The set of all words over V is denoted by V A language over V is a subset of V*.

A  phrase­structure  grammar  G  =  (V,  T,  S,  P)  consists  of  a  vocabulary  V  ,  a  subset  T  of  V
consisting of terminal symbols, a start symbol S from V , and a finite set of productions P. The
set V − T is denoted by N. Elements of N are called nonterminal symbols.

Every production in P must contain at least one non terminal on its left side.

Page 155 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/3.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Types of Phrase­Structure Grammars

Phrase­structure  grammars  can  be  classified  according  to  the  types  of  productions  that  are
allowed.

We will describe the classification scheme introduced by Noam Chomsky.

we  will  see  that  the  different  types  of  languages  defined  in  this  scheme  correspond  to  the
classes of languages that can be recognized using different models of computing machines.

A type 0 grammar has no restrictions on its productions.

A  type  1  grammar  can  have  productions  of  the  form  w 1   →  w 2 ,  where  w 1   =  lAr  and  w 2   =  lwr,
where  A  is  a  nonterminal  symbol,  l  and  r  are  strings  of  zero  or  more  terminal  or  nonterminal
symbols, and w is a nonempty string of terminal or nonterminal symbols.

It can also have the production S → λ as long as S does not appear on the right­hand side of
any other production.

A type 2 grammar can have productions only of the form w 1  → w 2 , where w 1  is a single symbol


that is not a terminal symbol.

A type 3 grammar can have productions only of the form w 1  → w 2  with w 1  = A and either w 2  =


aB or w 2  = a, where A and B are nonterminal symbols and a is a terminal symbol, or with w 1  = S
and w 2  = λ.

Context ­ Free Grammar Example

Type  2  grammars  are  called  context­free  grammars  because  a  nonterminal  symbol  that  is  the
left side of a production can be replaced in a string whenever it occurs, no matter what else is in
the string.

Page 156 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/4.html 1/2
First state machines & languages
8/20/2015 scorm content

A language generated by a type 2 grammar is called a context­free language.

When there is a production of the form lw1r → lw2r (but not of the form w1 → w2), the grammar
is  called  type  1  or  context­sensitive  because  w1  can  be  replaced  by  w2  only  when  it  is
surrounded by the strings l and r.

A  language  generated  by  a  type  1  grammar  is  called  a  context­sensitive  language.  Type  3
grammars  are  also  called  regular  grammars.  A  language  generated  by  a  regular  grammar  is
called regular. The relationship between regular languages and finite­state machines.

Page 157 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/4.html 2/2
First state machines & languages
8/20/2015 scorm content

 
Derivation Trees

A  derivation  in  the  language  generated  by  a  context­free  grammar  can  be  represented
graphically using an ordered rooted tree, called a derivation, or parse tree. The root of this tree
represents the starting symbol.

The internal vertices of the tree represent the nonterminal symbols that arise in the derivation.

The leaves of the tree represent the terminal symbols that arise. If the production A → w arises
in  the  derivation,  where  w  is  a  word,  the  vertex  that  represents  A  has  as  children  vertices  that
represent each symbol in w, in order from left to right.

Backus–Naur Form

There  is  another  notation  that  is  sometimes  used  to  specify  a  type  2  grammar,  called  the
Backus–Naur form (BNF) The specification of the programming language ALGOL.

The productions in a type 2 grammar have a single nonterminal symbol as their left­hand side.
Instead of listing all the productions separately, The same nonterminal symbol on the left­hand
side into one statement. Instead of using the symbol→in a production.

Page 158 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/5.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Strings and Languages

Vocabulary (V):

a finite set of symbols, e.g., V = {0, 1}

String (w): a finite sequence of symbols from V , e.g., w 1  = 010 and w 2

Empty String (λ): The string of length 0.

Conactenation (VW):

vw is string v, then string w.

w n : string w repeated n times,

e.g., 0 3  = 000

V*: all possible strings using V.

Language (L): A subset of all possible strings V*

Example: L = {1 m0 n  | m ∈N ∧ n ∈ N}

Phrase­Structure Grammars

A phrase­structure grammar G consists of:

vocabulary V , divided into two subsets:

Terminal symbols T and Nonterminal symbols N

Start symbol S ∈N a finite set of productions P

Each production has the form x → y,

where x ∈ V + and y ∈ V*.

This means we can derive string uyv from string uxz.

A string w is an element of the language generated by G if w can be derived from S by applying
a sequence of productions.

Page 159 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/6.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Alphabets and Languages

Definition:

A vocabulary (or alphabet) V is a finite, nonempty set of symbols.

A word or sentence over V is a finite string of symbols from V.

The empty string or null string, denoted by l, is the string containing no symbols.

The set of all words over V is denoted by V*.

A language over V is a subset of V*.

Language Examples

Let V={0,1}

00110, 11111, 00, and 11 are words over V

012, a234, and 222 are not words over V

V* = {0,1,00,01,10,11,000,…}

V* = {0,1,00,01,10,11,000,…}

In other words, V* is the set of all binary strings

The set of strings consisting of only 0s is a language over V*

{1,10,100,1000,10000,…} is a language over V*

Page 160 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/7.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Concatenation

Definition:

Let V be a vocabulary, and A and B be subsets of V*.

The concatenation of A and B, denoted by AB, is the set of all strings of the form xy, where x ∈A
and y∈B.

Example:

Let A = {0, 10}, and B = {1,12}.

Then
AB = {01, 012, 101, 1012} 
BA = {10, 110, 120, 1210}
AA = {00, 010, 100, 1010}
AAA = A(AA) = {000, 0010, 0100, 01010, 1000, 10010, 10100, 101010}

Concatenation: An

Let V be a vocabulary, and A a subset of V*. Then A0 = {l} , and for n>0, we can define

Example:

Let A = {0, 10}.

Then
A 0  = { l }
A 1  = A0A = {l} A = A = {0,10}
A 2  = A1A = {00, 010, 100, 1010}
A 3  = A2A = {000, 0010, 0100, 01010, 1000, 10010, 10100, 101010}

Page 161 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/8.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Kleene Closure

Definition:

Let V be a vocabulary, and A a subset of V*.

The  Kleene  closure  of  A,  denoted  by  A*,  is  the  set  consisting  of  concatenations  of  an  arbitrary
number of strings from A. That is,

A+ is the set of nonempty strings over A. In other words,

Example:

Let A={0, 1}.

Then
A 0  = {l}
A 1  = {0,1}
A 2  = {00, 01, 10, 11}
A 3  = {000, 001, 010, 011, 100, 101, 110, 111}
A* = {0,1}* = {All binary strings}

Let B={111}.

Then
B 0  = {l}
B 1  = {111}
B 2  = {111111111}
B* is the set of strings with 3n 1s, for every n≥0.

Page 162 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/9.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Regular Sets

Definition:

A regular set is a set that can be generated starting from the empty set, empty string, and single
elements  from  the  vocabulary,  using  concatenations,  unions,  and  Kleene  closures  in  arbitrary
order.

We will give a more precise definition after we define a regular expression.

Properties of Regular Sets

Pumping Lemma for Regular Sets

Applying Pumping Lemma

Closure Properties of Regular Sets

Emptiness of L(M)

Finiteness of L(M)

Equivalence of two FAs

Properties of Regular Sets Example

Closed under union, concatenation, and Kleene closure.

Closed under complementation: If L is regular,

Then

Intersection:

Page 163 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/10.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Regular Expressions:

Definition:

The regular expressions over a set I are defined recursively by:

∅ (the empty set) is a regular expression,

λ(the set containing the empty string) is a regular expression,

x is a regular expression for all x∈I,

(AB) , (A ∪ B) , and A* are regular expressions if A and B are regular expressions

A regular set is a set represented by a regular expression.

Examples: 001*, 1(0 ∪ 1)0, (0 ∪ 1)*11, and AB*C are regular expressions

The  regular  set  defined  by  the  regular  expression  01*  is  the  set  of  strings  starting  with  a  0
followed by 0 or more 1s.

The regular set defined by (10)* is the set of strings containing 0 or more copies of 10.

The regular set defined by 0(0 ∪ 1)*1 is the set of all binary strings beginning with 0 and ending
with 1.

The regular set defined by (0 ∪ 1)1(0 ∪ 1) is the set of strings {010, 011, 110, 111}.

Regular Expression Applications

Regular expressions are actually used quite often in computer science.

For instance, if you are editing a file with vi, and want to see if it contains the string blah followed
by  a  number  followed  by  any  character  followed  by  the  letter  Q,  you  can  use  the  regular
expression

This works because vi uses regular expressions for searching.

Page 164 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/11.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Finite State of Machines

Many kinds of machines, including components in computers, can be modeled using a structure
called a finite­state machine.

Several types of finite­state machines are commonly used in models.

All these versions of finite­state machines include a finite set of states, with a designated starting
state,  an  input  alphabet,  and  a  transition  function  that  assigns  a  next  state  to  every  state  and
input pair.

Finite­state  machines  are  used  extensively  in  applications  in  computer  science  and  data
networking.

For  example,  finite­state  machines  are  the  basis  for  programs  for  spell  checking,  grammar
checking, indexing or searching large bodies of text, recognizing speech.

A vending machine accepts nickels (5 cents), dimes (10 cents), and quarters (25 cents).

When  a  total  of  30  cents  or  more  has  been  deposited,  the  machine  immediately  returns  the
amount in excess of 30 cents.

When 30 cents has been deposited and any excess refunded, the customer can push an orange
button and receive an orange juice or push a red button and receive an apple juice.

We  can  describe  how  the  machine  works  by  specifying  its  states,  how  it  changes  states  when
input  is  received,  and  the  output  that  is  produced  for  every  combination  of  input  and  current
state.

The machine can be in any of seven different states s i, i = 0, 1, 2, . . . , 6, where s i is the state


where the machine has collected 5i cents. The machine starts in state s0, with 0 cents received.

The possible inputs are 5 cents, 10 cents, 25 cents, the orange button (O), and the red button
(R).  The  possible  outputs  are  nothing  (n),  5  cents,  10  cents,  15  cents,  20  cents,  25  cents,  an
orange juice, and an apple juice.

Page 165 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/12.html 1/4
First state machines & languages
8/20/2015 scorm content

Suppose  that  a  student  puts  in  a  dime  followed  by  a  quarter,  receives  5  cents  back,  and  then
pushes the orange button for an orange juice.

The  machine  starts  in  state  s0.  The  first  input  is  10  cents,  which  changes  the  state  of  the
machine to s2 and gives no output.

The second input is 25 cents. This changes the state from s 2  to s 6 , and gives 5 cents as output.

The next input is the orange button, which changes the state from s 6   back  to  s 0   (because  the


machine returns to the start state) and gives an orange juice as its output.

Finite­State Machines with Outputs

A  finite­state  machine  M  =  (S,  I,  O,  f,  g,  s 0 )  consists  of  a  finite  set  S  of  states,  a  finite  input
alphabet I, a finite output alphabet O, a transition function f that assigns to each state and input
pair a new state, an output function g that assigns to each state and input pair an output, and an
initial state s 0 .

Let  M  =  (S,  I,  O,  f,  g,  s 0 )  be  a  finite­state  machine.  We  can  use  a  state  table  to  represent  the
values of the transition function f and the output function g for all pairs of states and input.

We previously constructed a state table for the vending machine discussed in the introduction to
this section.

Phrase­Structure Grammars

Example:

The state table describes a finite­state machine with S = {s 0 , s 1 , s 2 , s 3 }, I = {0, 1}, and O = {0, 1}.

The  values  of  the  transition  function  f  are  displayed  in  the  first  two  columns,  and  the  values  of
the output function g are displayed in the last two columns.

Another  way  to  represent  a  finite­  state  machine  is  to  use  a  state  diagram,  which  is  a  directed
graph with labeled edges.

In this diagram, each state is represented by a circle. Arrows labeled with the input and output
pair are shown for each transition.

Let  M  =  (S,  I,  O,  f,  g,  s 0 )  be  a  finite­state  machine  and  L  ⊆  I  *.We  say  that  M  recognizes  (or
accepts) L if an input string x belongs to L if and only if the last output bit produced by M when
given x as input is a 1.

Example:  Find  the  output  string  generated  by  the  finite­state  machine  in  Figure  3  if  the  input
string is 101011.

Solution:The output obtained is 001000. The successive states and outputs are shown in Table

Page 166 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/12.html 2/4
First state machines & languages
8/20/2015 scorm content

Example:

Produce a finite­state machine that adds two positive integers using their binary expansions.

Solution:

When (x n  . . . x 1 x 0 )2 and (y n  . . . y 1 y 0 )2 are added, the following procedure is followed.

First, the bits x 0  and y 0  are added, producing a sum bit z 0  and a carry bit c 0 .]

This carry bit is either 0 or 1. Then, the bits x 1  and y 1  are added, together with the carry c 0 .

This gives a sum bit z 1  and a carry bit c 1 .

This  procedure  is  continued  until  the  nth  stage,  where  x n , y n ,  and  the  previous  carry  c n­1   are
added to produce the sum bit z n  and the carry bit c n , which is equal to thesum bit z n+1 .

In a certain coding scheme, when three consecutive 1s appear in a message, the receiver of the
message knows that there has been a transmission error.

Construct a finite­state machine that gives a 1 as its current output bit if and only if the last three
bits received are all 1s.

The state s 1  remembers that the previous input was a 1, but the input before the previous input,
if it exists, was not a 1.

The  state  s 2   remembers  that  the  previous  two  inputs  were  1s.  An  input  of  1  takes  s 0   to  s 1 ,
because now a1, and not two consecutive 1s, has been read; it takes s 1  to s 2 , because now two
consecutive  1s  have  been  read;  and  it  takes  s 2   to  itself,  because  at  least  two  consecutive  1s
have been read.

An input of 0 takes every state to s 0 , because this breaks up any string of consecutive 1s. The
output for the transition from s2 to itself when a 1.

One of the most important applications of finite­state machines is in language recognition.

This  application  plays  a  fundamental  role  in  the  design  and  construction  of  compilers  for

Page 167 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/12.html 3/4
First state machines & languages
8/20/2015 scorm content

programming languages.

A finite­state machine with output can be used to recognize a language, by giving an output of 1
when a string from the language has been read and a 0 otherwise.

However,  there  are  other  types  of  finite­state  machines  that  are  specially  designed  for
recognizing languages.

Instead of producing output, these machines have final states.

A string is recognized if and only if it takes the starting state to one of these final states.

Page 168 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/12.html 4/4
First state machines & languages
8/20/2015 scorm content

 
Set of Strings

The operations that will be defined here will be used extensively in our discussion of language
recognition by finite­state machines.

Suppose that A and B are subsets of V *, where V is a vocabulary.

The concatenation of A and B, denoted by AB, is the set of all strings of the form xy, Where x is
a string in A and y is a string in B.

Finite­State Machines with No Output

Example:

Let A = {0, 11} and B = {1, 10, 110}. Find AB and BA.

Solution:

The set AB contains every concatenation of a string in A and a string in B.

Hence,

AB = {01, 010, 0110, 111, 1110, 11110}.

The set BA contains every concatenation of a string in B and a string in A.

Hence,

BA = {10, 111, 100, 1011, 1100, 11011}.

Note that it is not necessarily the case that AB = BA when A and B are subsets of V.

where V is an alphabet, as Example 1 illustrates.

From the definition of the concatenation of two sets of strings, we can define An, for n = 0, 1, 2, .
. . .

This is done recursively by specifying that 
A 0  = {λ}
A n+1  = A n  A for n = 0, 1, 2, . . . .

Example:

Let A = {1,00}. Find A n  for n = 0, 1, 2, and 3.

Solution:

We have A 0  = {λ} and A 1  = A0A = {λ} A = {1, 00}.

To find A 2  we take concatenations of pairs of elements of A.

This gives A 2  = {11, 100, 001, 0000}.

Page 169 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/13.html 1/3
First state machines & languages
8/20/2015 scorm content

To find A 3  we take concatenations of elements in A 2  and A;

This gives A 3  = {111, 1100, 1001, 10000, 0011, 00100, 00001, 000000}.

Suppose that A is a subset of V *.

Then  the  Kleene  closure  of  A,  denoted  by  A  *,  is  the  set  consisting  of  concatenations  of
arbitrarily many strings from A.

Example:

What are the Kleene closures of the sets A = {0}, B = {0, 1}, and C = {11}?.

Solution:

The Kleene closure of A is the concatenation of the string 0 with itself an arbitrary finite number
of times.

Hence, A* = {0 n  | n = 0, 1, 2, . . . }.

The  Kleene  closure  of  B  is  the  concatenation  of  an  arbitrary  number  of  strings,  where  each
string is either 0 or 1.

This is the set of all strings over the alphabet V = {0, 1}.

That is, B* = V*

Finally, the Kleene closure break of C is the concatenation of the string 11 with itself an arbitrary
number of times.

Hence, C * is the set of strings consisting of an even number of 1s.

That is, C* = {1 2n  | n = 0, 1, 2, . . . }.

A finite­state machine with no output.

Such machines are also called finite­state automata, and that is the terminology we will use for
them here. (Note: The singular of automata is automaton.)

These machines differ from the finite­state machines studied in that they do not produce output,
but they do have a set of final states.

Recognize strings that take the starting state to a final state.

A  finite­state  automaton  M  =  (S,  I,  f,  s 0 ,  F)  consists  of  a  finite  set  S  of  states,  a  finite  input

Page 170 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/13.html 2/3
First state machines & languages
8/20/2015 scorm content

alphabet I, a transition function f that assigns a next state to every pair of state and input (so that
f  :  S  ×  I  →  S),  an  initial  or  start  state  s 0 ,  and  a  subset  F  of  S  consisting  of  final  (or  accepting
states).

A string x is said to be recognized or accepted by the machine M = (S, I, f, s 0 , F) if it takes the
initial state s 0  to a final state, that is, f (s 0 , x) is a state in F.

The  language  recognized  or  accepted  by  the  machine  M,  denoted  by  L(M),  is  the  set  of  all
strings that are recognized by M.

Two finite­state automata are called equivalent if they recognize the same language.

Nondeterministic Finite­State Automata

A nondeterministic finite­state automaton M = (S, I, f, s 0 , F) consists of a set S of states, an input
alphabet I, a transition function f that assigns a set of states to each pair of state and input (so
that f : S × I → P(S)), a starting state s 0 , and a subset F of S consisting of the final states.

Page 171 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/13.html 3/3
First state machines & languages
8/20/2015 scorm content

 
Language Recognition

Finite­state automata can be used as language recognizers.

What sets can be recognized by these machines?

Although this seems like an extremely difficult problem, there is a simple characterization of the
sets that can be recognized by finite state automata.

This problem was first solved in 1956 by the American mathematician Stephen Kleene.

A finite­state automaton that recognizes a set if and only if this set can be built up from the null
set.

The empty string, and singleton strings by taking concatenations, unions, and Kleene closures,
in arbitrary order.

Sets that can be built up in this way are called regular sets.

The regular expressions over a set I are defined recursively by:

The symbol ∅ is a regular expression;

The symbol λ is a regular expression;

The symbol x is a regular expression whenever x ∈ I;

The  symbols  (AB),  (A  ∪  B),  and  A*  are  regular  expressions  whenever  A  and  B  are  regular
expressions.

Each regular expression represents a set specified by these rules:

∅ represents the empty set, that is, the set with no strings;

λ represents the set {λ}, which is the set containing the empty string;

x represents the set {x} containing the string with one symbol x;

(AB) represents the concatenation of the sets represented by A and by B;

(A ∪ B) represents the union of the sets represented by A and by B;

A* represents the Kleene closure of the set represented by A.

Page 172 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/14.html 1/1
First state machines & languages
8/20/2015 scorm content

 
KLEENE’S THEOREM

A set is regular if and only if it is recognized by a finite­state automaton.

Kleene’s theorem is one of the central results in automata theory.

We will prove the only if part of this theorem, namely, that every regular set is recognized by a
finite­state automaton.

The proof of the if part, that a set recognized by a finite­state automaton is regular, is left as an
exercise for the reader.

Recall  that  a  regular  set  is  defined  in  terms  of  regular  expressions,  which  are  defined
recursively.

We can prove that every regular set is recognized by a finite­state automaton if we can do the
following things.

1. Show that ∅ is recognized by a finite­state automaton.

2. Show that {λ} is recognized by a finite­state automaton.

3. Show that {a} is recognized by a finite­state automaton whenever a is a symbol in I .

4. Show that AB is recognized by a finite­state automaton whenever both A and B are.

5. Show that A ∪ B is recognized by a finite­state automaton whenever both A and B are.

6. Show that A * is recognized by a finite­state automaton whenever A is.

We now consider each of these tasks.

First, we show that ∅ is recognized by a nondeterministic finite­state automation.

To do this, all we need is an automation with no final states.

The finite­state automata cannot be used as general models of computation.

They are limited in what they can do.

For  example,  finite­state  automata  are  able  to  recognize  regular  sets,  but  are  not  able  to
recognize  many  easy­to­describe  sets,  including  {0n1n  |  n  ≥  0},  which  computers  recognize
using memory.

We can use finite­state automata to compute relatively simple functions such as the sum of two
numbers, but we cannot use them to compute functions that computers can, such as the product
of two numbers.

To overcome these deficiencies we can use a more powerful type of machine known as a Turing
machine, after AlanTuring, the famous mathematician and computer scientist who invented them
in the 1930s.

Page 173 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/15.html 1/1
First state machines & languages
8/20/2015 scorm content

 
Turing Machines

A Turing machine consists of a control unit, which at any step is in one of finitely many different
states, together with a tape divided into cells, which is infinite in both directions.

Turing machines have read and write capabilities on the tape as the control unit moves back and
forth along this tape, changing states depending on the tape symbol read.

Turing  machines  are  more  powerful  than  finite­state  machines  because  they  include  memory
capabilities that finite state machines lack.

We  will  show  how  to  use  Turing  machines  to  recognize  sets,  including  sets  that  cannot  be
recognized by finite­state machines.

Definition of Turing Machines

A Turing machine T = (S, I, f, s 0 ) consists of a finite set S of states, an alphabet I containing the
blank symbol B, a partial function f from S × I to S × I × {R,L}, and a starting state s0.

The  action  of  the  Turing  machine  at  each  step  of  its  operation  depends  on  the  value  of  the
partial function f for the current state and tape symbol.

At each step, the control unit reads the current tape symbol x.

If the control unit is in state s and if the partial function f is defined for the pair (s, x) with f (s,x) =
(s‘ , x‘ , d) the control unit:

Enters the state s‘

Write the symbol x1 in the current cell. Erasing x, and

Moving right one cell if d = R or moves left one cell if d = L.

At each step, the control unit reads the current tape symbol x.

If the control unit is in state s and if the partial function f is defined for the pair (s, x) with f (s,x) =
(s‘ , x‘ , d) the control unit:

Enters the state s‘

Moving right one cell if d = R or moves left one cell if d = L.

Using Turing Machines to Recognize Sets

Page 174 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/16.html 1/3
First state machines & languages
8/20/2015 scorm content

Machine halts

We can now define what it means for a Turing machine to recognize a string.

Given a string, we write consecutive symbols in this string in consecutive cells.

Definition:

Let V be a subset of an alphabet T .

A Turing machine T = (S, I, f, s 0 ) recognizes a string x in V * if and only if T, starting in the initial
position when x is written on the tape, halts in a final state.

T is said to recognize a subset A of V * if x is recognized by T if and only if x belongs to A.

Find a Turing machine that recognizes the set of bit strings that have a 1 as their second bit, that
is, the regular set (0 ∪ 1)1(0 ∪ 1) *.

Different Types of Turing Machines

There are many variations on the definition of a Turing machine. We can expand the capabilities
of a Turing machine in a wide variety of ways.

For example, we can allow a Turing machine to move right, left, or not at all at each step.

We can allow multiple tape heads that read different cells simultaneously.

Furthermore, we can allow a Turing machine to be nondeterministic, by allowing a (state, tape
Page 175 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/16.html 2/3
First state machines & languages
8/20/2015 scorm content

symbol)  pair  to  possibly  appear  as  the  first  elements  in  more  than  one  five­tuple  of  the  Turing
Machines.

Turing Machines and its variants

Example:

Recognize the language 01* + 10*. The machine “remembers” the first symbol read in its state.

Shifting Symbols Problem:

Solution:

“Remember” the last k symbols in finite control.

Page 176 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit8/assets/16.html 3/3
UNIT - 9
Analysis of Algorithm

Page 177 of 189


Analysis of Algorithm
8/20/2015 scorm content

 
Introduction

One  of  the  major  goals  of  computer  science  is  to  understand  how  to  solve  problems  with
computers.

Developing a solution to some problem typically involves at least four steps:

Designing an algorithm or step­by­step procedure for solving the problem.

Analyzing the correctness and efficiency of the procedure.

Implementing  the  procedure  in  some  programming  language,  and  Testing  the
implementation.

The absolute execution time of an algorithm depends on many factors:

The  size  of  the  input  (searching  through  a  list  of  length  1,000  takes  longer  than  searching
through a list of length 10),

The algorithm used to solve the problem (Unordered­Linear­Search is inherently slower than
Binary­Search),

The programming language used to implement the algorithm (interpreted languages such as
Basic are typically slower than compiled languages such as C++),

The  quality  of  the  actual  implementation  (good,  tight  code  can  be  much  faster  than  poor,
sloppy code), and

The machine on which the code is run (a supercomputer is faster than a laptop).

Page 178 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/2.html 1/1
Analysis of Algorithm
8/20/2015 scorm content

 
Algorithm

In analyzing the efficiency of an algorithm, one typically focuses on the first two of these factors.

“speed" of the algorithm as a function of the size of the input on which it is run.

one  typically  determines  the  number  of  program  steps  (or  some  count  of  other  interesting
computer operations) as a function.

Input  time  will  depend  on  the  programming  language  used,  the  quality  of  the  code  produced,
and the machine on which the code is run.

Introduction

An  algorithm  is  a  finite  sequence  of  precise  instructions  for  performing  a  computation  or  for
solving a problem.

Set  the  temporary  maximum  equal  to  the  first  integer  in  the  sequence.  (The  temporary
maximum will be the largest integer examined at any stage of the procedure.)

Compare the next integer in the sequence to the temporary maximum, and if it is larger than
the temporary maximum, set the temporary maximum equal to this integer.

Repeat the previous step if there are more integers in the sequence.

Stop when there are no integers left in the sequence. The temporary maximum at this point is
the largest integer in the sequence.

Properties Of Algorithms

There  are  several  properties  that  algorithms  generally  share.  They  are  useful  to  keep  in  mind
when algorithms are described. These properties are:

Input. An algorithm has input values from a specified set.

Output. From each set of input values an algorithm produces output values from a specified
set. The output values are the solution to the problem.

Definiteness. The steps of an algorithm must be defined precisely.

Correctness.  An  algorithm  should  produce  the  correct  output  values  for  each  set  of  input
values.

Finiteness. An algorithm should produce the desired output after a finite (but perhaps large)
number of steps for any input in the set.

Linear Search

Prose: Locate an item in a list by examining the sequence of list elements one at a time, starting
at the beginning.

Page 179 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/3.html 1/2
Analysis of Algorithm
8/20/2015 scorm content

More formal prose: Find item x in the list [a 1 ; a 2 ; : : : ; a n ].

First compare x with a1. If they are equal, return the position 1.

If not, try a 2 . If x = a 2 , return the position 2.

Keep going, and if no match is found when the entire list is scanned, return 0.

Binary Search

Prose description:

Assume the input is a list of items in increasing order, and the target element to be found.

The algorithm begins by comparing the target with the middle element.

If the middle element is strictly lower than the target, then the search proceeds with the upper
half of the list.

Otherwise, the search proceeds with the lower half of the list (including the middle).

Repeat this process until we have a list of size 1.

If target is equal to the single element in the list, then the position is returned.

Otherwise, 0 is returned to indicate that the element was not found.

Greedy Algorithms

Optimization problems minimize or maximize some parameter over all possible inputs. Examples
of optimization problems:

Finding a route between two cities with the smallest total mileage.

Determining how to encode messages using the fewest possible bits.

Finding the fiber links between network nodes using the least amount of fiber.

Optimization problems can often be solved using a greedy algorithm, which makes the “best”
(by  a  local  criterion)  choice  at  each  step.  This  does  not  necessarily  produce  an  optimal
solution to the overall problem, but in many instances, it does.

Page 180 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/3.html 2/2
Analysis of Algorithm
8/20/2015 scorm content

 
Efficiency of Algorithms

Efficiency: Amount of resources used by an algorithm

Space (number of variables)

Time (number of instructions)

When designing an algorithm must be aware of its use of resources

If there is a choice, pick the more efficient algorithm!

How to measure time efficiency?

Running time: let it run and see how long it takes

On what machine?

On what inputs?

Time efficiency depends on input

Example: the sequential search algorithm

In the best case, how fast can the algorithm halt?

In the worst case, how fast can the algorithm halt?

Time Efficiency

Worst case efficiency is the maximum number of steps that an algorithm can take for any input
data values.

Best  case  efficiency  is  the  minimum  number  of  steps  that  an  algorithm  can  take  for  any  input
data values.

Average case efficiency the efficiency averaged on all possible inputs must assume a distribution
of the input we normally assume uniform distribution (all keys are equally probable). If the input
has size n, efficiency will be a function of n

Analysis of Sequential Search

Best­case : 1 comparison

Target is found immediately

Worst­case: 3n + 5 comparisons

Target is not found

Average­case: 3n/2+4 comparisons

Target is found in the middle

Page 181 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/4.html 1/2
Analysis of Algorithm
8/20/2015 scorm content

Space efficiency

How much space is used in addition to the input?

Efficiency of Copy­Over

Best case: all values are zero: no copying, no extra space

Worst­case: No zero value: n elements copied, n extra space

Time: (n)

Extra space: n

Efficiency of Shuffle­Left

Space: no extra space (except few variables)

Time

Best­case

No zero value

no copying ==> order of n = Θ(n)

Worst case

All zero values: every element thus requires copying n­1 values one to the left

on x (n­1) = n 2  ­ n = order of n 2  = Θ(n 2 ) (why?)

Average case

Half of the values are zero

n/2 x (n­1) = (n 2  ­ n)/2 = order of n 2  = Θ(n 2 )

Page 182 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/4.html 2/2
Analysis of Algorithm
8/20/2015 scorm content

 
Big­O Notation

The History Of Big­O Notation

Big­O notation has been used in mathematics for more than a century.

In computer science it is widely used in the analysis of algorithms.

The  German  mathematician  Paul  Bachmann  first  introduced  big­O  notation  in  1892  in  an
important book on number theory.

The  big­O  symbol  is  sometimes  called  a  Landau  symbol  after  the  German  mathematician
Edmund Landau, who used this notation throughout his work.

The  use  of  big­O  notation  in  computer  science  was  popularized  by  Donald  Knuth,  who  also
introduced the big­​ and big­​ notations defined later in this section.

Working with the Definition Of Big­O Notation : A useful approach for finding a pair of witnesses
is to first select a value of k for which the size of |f (x)| can be readily estimated when x > k and
to see whether we can use this estimate to find a value of C for which |f (x)| ≤ C|g(x)| for x > k.

Big­O Estimates for Some Important Functions

Polynomials can often be used to estimate the growth of functions.

Instead of analyzing the growth of polynomials each time they occur,

We would like a result that can always be used to estimate the growth of a polynomial. Theorem
1 does this.

It  shows  that  the  leading  term  of  a  polynomial  dominates  its  growth  by  asserting  that  a
polynomial of degree n or less is O(xn).

THEOREM 1

THEOREM 2

Properties of Big­O Notation

If f is O(g) and g is O(f ) then one says that f and g are of the same order.

If f is O(g) and h(x) ​
 g(x) for all positive real numbers x then f is O(h).

The O­notation describes upper bounds on how fast functions grow. E.g., f (x) = x 2  + 3x is O(x 2 )
but also O(x 3 ), etc.

Often one looks for a simple function g that is as small as possible such that still f is O(g).(The
word ‘simple’ is important, since trivially f is O(f ).)

Useful Big­O Estimates

If d > c > 1, then nc is O(n d ), but n d  is not O(n c).


Page 183 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/5.html 1/2
Analysis of Algorithm
8/20/2015 scorm content

If b > 1 and c and d are positive, then (log b  n) c is O(n d  ), but n d  is not O((log b  n) c).

If b > 1 and d is positive, then n d  is O(b n ), but b n  is not O(n d  ).

If c > b > 1, then bn is O(c n ), but c n  is not O(b n ).

If f 1 (x) is O(g 1 (x)) and f 2 (x) is O(g 2 (x)) then (f 1  + f 2 )(x) is O(max(jg 1 (x)j; jg 2 (x)j)).

If f 1  is O(g 1 ) and f 2  is O(g 2 ) then (f 1  ο f 2 ) is O(g 1  ο g 2 ).

Note: These estimates are very important for analyzing algorithms. Suppose that g(n) = 5n 2  +7n
­  3  and  f  is  a  very  complex  function  that  you  cannot  determine  exactly,  but  you  know  that  f  is
O(n 3 ). Then you can still derive that n.f (n) is O(n 4 ) and g(f (n)) is O(n 6 ).

Big­Omega Notation

Definition: Let f ; g : R ! R. We say that f is (g) if there are constants C and k such that 8x > k: jf
(x)j ​
 Cjg(x)j

This  is  read  as  “f  is  big­Omega  of  g”.  The  constants  C  and  k  are  called  witnesses  to  the
relationship between f and g.

Big­O gives an upper bound on the growth of a function, while

Big­Omega  gives  a  lower  bound.  Big­Omega  tells  us  that  a  function  grows  at  least  as  fast  as
another.

Similar abuse of notation as for big­O.

f is Ω(g) if and only if g is O(f ).

Big­Theta Notation

Definition: Let f ; g : R ! R. We say that f is (g) if there are constants C and k such that 8x > k: jf
(x)j ​
 Cjg(x)j.

We say that “f is big­Theta of g” and also that “f is of order g” and also that “f and g are of the
same order”.

f is Θ(g) if and only if there exists constants C 1 , C 2  and k such that C 1 g(x) < f (x) < C 2 g(x) if x >


k. This follows from the definitions of big­O and big­Omega.

Page 184 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/5.html 2/2
Analysis of Algorithm
8/20/2015 scorm content

 
Comparison of Algorithm

Unordered Linear Search

Suppose that the given array was not necessarily sorted.

This  might  correspond,  for  example,  to  collection  exams  which  have  not  yet  been  sorted
alphabetically.

If a student wanted to obtain her exam score, how could she do so? She would have to search
through the entire collection of exams, one­by­one, until her exam was found.

This corresponds to the unordered linear search algorithm.

Note  that  in  order  to  determine  that  an  object  does  not  exist  in  the  collection,  one  needs  to
search through the entire collection.

Consider executing the Unordered­Linear­Search algorithm on this array while searching for the
number 11.

The rst four elements would need to be examined until the fourth element containing the value
11 is found.

In analyzing the performance of search algorithms, we will consider these \examination counts"
as a measure of the performance of such algorithms.

Now  consider  executing  the  Unordered­Linear­Search  on  this  array  while  searching  for  the
number 13.

Since 13 does not exist in the array, one must examine all eight of the array elements until one
could denitively return \13 not found."

Ordered Linear Search

Now  suppose  that  the  given  array  is  sorted.  In  this  case,  one  need  not  necessarily  search
through the entire list to nd a particular object or determine that it does not exist in the collection.

For example, if the collection of exams were sorted by name, one need not search beyond the
\P"s to determine that the exam for \Peterson" does or does not exist in the collection.

A simple modification of the above algorithm yields the ordered linear search algorithm.

Note  that  while  scanning  the  array  from  left­to­right  (smallest­to­largest  values),  a  search  can
now be terminated early if and when it is determined that the number being sought (and as yet
not found) is less than the element currently being examined.

Consider executing the Ordered­Linear­Search on this array while searching for the number 11.

In  this  case,  the  rst  two  elements  would  need  to  be  examined  until  the  second  element
containing the value 11 is found.

Now consider executing the Ordered­Linear­Search on this array while searching for the number
Page 185 of 189
file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/6.html 1/3
Analysis of Algorithm
8/20/2015 scorm content

13.

Note that only the rst four elements need be examined until the value 16 is encountered and one
can denitively return \13 not found."

Chunk Search

Given  an  ordered  list,  one  need  not  (and  one  typically  does  not)  search  through  the  entire
collection one­by­one.

Consider searching for a name in a phone book or looking for a particular exam in a sorted pile:
one might naturally grab 50 or more pages at a time from the phone book or 10 or more exams
at  a  time  from  the  pile  to  quickly  determine  the  50  page  (or  10  exam)  \chunk"  in  which  the
desired data lies.

One could then carefully search through this chunk using an ordered linear search. Let c be the
chunk  size  used  (e.g.,  50  pages  or  10  exams).  We  shall  refer  to  the  algorithm  encoding  the
above ideas as chunk search.

Consider  executing  the  Chunk­Search  on  the  above  array  while  searching  for  the  number  34
and using c = 3 (i.e., chunks of size 3).

To determine if 34 is in the rst chunk, the third element (at the end of the rst \chunk") with value
12  must  be  examined.  Since  34  >  12,  we  next  examine  the  sixth  element  (at  the  end  of  the
second \chunk") with value 37.

Since 34 < 37, we conclude that the value 34, if it exists in the array, must be contained in the
second chunk.

We then simply execute Ordered­Linear­ earch on the subarray A[4 : : 6] consisting of the three
elements in the second chunk, eventually nding 34 in the fth position.

Now  consider  executing  Chunk­Search  on  the  above  array  while  searching  for  the  number  33.
Chunk­Search would behave exactly as described above, except that the call to Ordered­Linear­
Search would return \33 not found" when searching the subarray A[4 : : 6].

Binary Search

Now consider the following idea for a search algorithm using our phone book example.

Select a page roughly in the middle of the phone book. If the name being sought is on this page,
you′re done.

If the name being sought is occurs alphabetically before this page, repeat the process on the \rst
half" of the phone book; otherwise, repeat the process on the \second half" of the phone book.

Note that in each iteration, the size of the remaining portion of the phone book to be searched is
divided in half; the algorithm applying such a strategy is referred to as binary search.

While this many not seem like the most \natural" algorithm for searching a phone book.

Page 186 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/6.html 2/3
Analysis of Algorithm
8/20/2015 scorm content

Consider executing the Binary­Search on this array while searching for the number 34.

Two determine if 34 is in the rst or second half of the array,

We split the array in half, considering the fourth element (at the end of the \rst half") whose value
is 16. Since 34 > 16,

We conclude that the number 34, if it exists in the array, must be contained in the second half,
i.e., the subarray A[5 : : 8].

We  then  repeat  on  the  second  half  of  the  array,  splitting  it  in  half  and  considering  the  sixth
element whose value is 37.

Since 34 < 37, we continue with the subarray A[5 : : 6], nding the element whose value is 34 in
the next iteration.

Now consider executing Binary­Search on this array while searching for the number 33.

Binary­Search will behave exactly as described above until the last subarray of size 1 containing
only the element whose value is 34 is considered.

At  this  point,  one  can  denatively  return  \33  not  found"  since  there  are  no  subarrays  yet  to  be
searched which could possibly contain the number 34.

Page 187 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/6.html 3/3
Analysis of Algorithm
8/20/2015 scorm content

 
Sorting Algorithm

Introduction

Ordered­Linear­Search,  Chunk­Search,  and  Binary­Search  each  assume  that  the  underlying


array or list which is being searched is already in sorted order.

How can one take an unordered array or list and sort it?

Algorithms for sorting are fundamental to computer science and dozens have been developed.

In this section, we shall consider three such algorithms:

Insertion­Sort

Selection­Sort

Merge­Sort.

Insertion Sort

Insertion­Sort corresponds to the method that many people use to sort cards as they are being
dealt to them.

The rst card is placed in one′s hand, the second card is compared to the first and placed either
before or after it, and so on.

In  general,  one  has  some  i  cards,  in  sorted  order,  in  one′s  hand,  and  the  i  +  1st  card  is
compared to successive cards (starting from the left or right) until the proper location to \insert"
the card is found.

Let us consider how to sort this array using Insertion­Sort.

Imagine the numbers 34, 16, 12, . . . , being \dealt" to you, in this order, like cards.

You would start with the number 34, a trivially sorted list.

Then the number 16 would be inserted into this list, producing the sorted list \16 34."

The number 12 would then be inserted into this list, producing \12 16 34," and so on. In general,
in  phase  k  of  the  algorithm,  the  kth  element  of  the  array  is  inserted  into  the  sorted  list  formed
from the rst k ­ 1 elements of the array.

The  process  of  insertion  sort  is  shown  below,  where  a  diamond  3  is  used  to  separate  the
processed and sorted array elements from the as yet unprocessed array elements.

Analysis: What is the running time of Insertion­Sort on an array containing n elements?

In phase 1 of the algorithm, the rst array element must be examined.

In  phase  2  of  the  algorithm,  the  second  element  must  be  examined  and  compared  to  the  rst
(which  must  therefore  be  examined).  In  general,  in  the  kth  phase  of  Insertion­Sort,  the  kth

Page 188 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/7.html 1/2
Analysis of Algorithm
8/20/2015 scorm content

element must be examined, and in the worst case, it may be compared to each of the previously
processed k ­ 1 elements, resulting in k total elements being examined.

Thus, the total number of elements examined (in the worst case) is given by 1 + 2 + 3 + _ _ _ +
(n ­ 2) + (n ­ 1) + n:

Selection Sort

While  Insertion­Sort  can  be  used  to  process  cards  on­line,  as  they  are  being  dealt,  the  next
algorithm we shall consider cannot proceed until all the cards have been dealt.

However, in sorting a list or array of elements that are all given in advance, both algorithms are
equally applicable.

Selection­Sort  begins  by  examining  the  list  of  elements,  \selecting"  the  smallest  one,  and
\swapping" it with the rst element of the list.

In phase 2, Selection­Sort selects the smallest element from the remaining n ­ 1 elements and
swaps it with the element in position 2.

In general, in the kth phase, Selection­Sort selects the smallest element from the remaining n ­ k
+ 1 elements and swaps it with the element in position k.

Analysis: What is the running time of Selection­Sort on an array containing n elements?

In  phase  1  of  the  algorithm,  all  n  elements  must  be  examined  in  order  to  nd  the  smallest
element.

In  phase  2  of  the  algorithm,  the  n  ­  1  remaining  elements  must  all  be  examined  to  find  the
second smallest element.

In general, in phase k of the algorithm, the remaining n­k+1 elements must all be examined to
determine the kth smallest element.

Thus, the total number of elements examined is given by n + (n ­ 1) + (n ­ 2) + _ _ _ + 3 + 2 + 1:

Merge Sort

We shall consider a third algorithm for sorting, Merge­Sort,

Whose implementation is inherently recursive and whose analysis depends on the mathematical
technique of recurrences.

Merge­Sort is provably faster than either Insertion­Sort or Selection­Sort, in the worst case.

Page 189 of 189


file:///D:/NIELIT%20PROJECT/Final%20Product/Discrete%20Structure/unit9/assets/7.html 2/2

You might also like