0% found this document useful (0 votes)
133 views178 pages

DM ppt2

This document provides an overview of propositional logic. Some key points: - A proposition is a statement that is either true or false. Propositional variables like p, q, r are used to represent propositions. - Propositional logic uses logical connectives like AND, OR, NOT to combine propositions. Common connectives include conjunction (∧), disjunction (∨), negation (¬), implication (→), biconditional (⇔). - Truth tables are used to determine the truth value of complex propositions formed by connecting simpler propositions with logical connectives. Concepts like tautology, contradiction, contingency can be defined based on the truth table.

Uploaded by

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

DM ppt2

This document provides an overview of propositional logic. Some key points: - A proposition is a statement that is either true or false. Propositional variables like p, q, r are used to represent propositions. - Propositional logic uses logical connectives like AND, OR, NOT to combine propositions. Common connectives include conjunction (∧), disjunction (∨), negation (¬), implication (→), biconditional (⇔). - Truth tables are used to determine the truth value of complex propositions formed by connecting simpler propositions with logical connectives. Concepts like tautology, contradiction, contingency can be defined based on the truth table.

Uploaded by

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

DISCRETE

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

• PROPOSITIONAL LOGIC:A proposition is the basic building block of logic. It is defined as a


declarative sentence that is either True or False, but not both.
• The Truth Value of a proposition is True(denoted as T) if it is a true statement, and
False(denoted as F) if it is a false statement.
• For Example,
1. The sun rises in the East and sets in the West.
2. 1 + 1 = 2
3. 'b' is a vowel.
Example of non-propositions:
2 + 3.
Solve the equation 2 + x = 3.
2 + x > 8.
Some sentences that do not have a truth value or may have more than one truth value are not
propositions.
For Example,
1. What time is it? 2. Go out and play. 3. x + 1 = 2.
The above sentences are not propositions as the first two do not have a truth value, and the third one
may be true or false.
• To represent propositions, propositional variables are used. By Convention, these variables are
represented by small alphabets such as p,q,r….
• The area of logic which deals with propositions is called propositional calculus or propositional logic.
• The propositions are combined together using Logical Connectives or Logical Operators.

In propositional logic generally we use five connectives which are −


• OR (∨)
• AND (∧)
• Negation/ NOT (¬)
• Implication / if-then (→)
• If and only if (⇔)
OR/Disjunction(∨) − The OR operation of two propositions A and B (written as A∨B) is true if at least
any of the propositional variable A or B is true.
AND/Conjuction (∧) − The AND operation of two propositions A and B (written as A∧B) is true if both the
propositional variable A and B is true.

Negation (¬) − The negation of a proposition A (written as ¬A) is false when A is true and is true when A is
false.
• Implication / if-then (→) − An implication A→B is the proposition “if A, then B”. It is false if A is true and
B is false. The rest cases are true. In the implication pq, p is called the hypothesis or antecedent or
premise and q is called the conclusion or consequence.
• The implication is p → q is also called a conditional statement.
• This situation is similar to the “Innocent until proven Guilty” stance, which means that the implication
p → q is considered true until proven false. Since we cannot call the implication p → q false when p is
false, our only alternative is to call it true.
1. "if p, then q"
2. "p is sufficient for q"
3. "q when p"
4. "a necessary condition for p is q"
5. "p only if q"
6. "q unless \neg p"
7. "q follows from p“
Example,
“If it is Friday then it is raining today” is a proposition which is of the form pq. The above
proposition is true if it is not Friday(premise is false) or if it is Friday and it is raining, and
it is false when it is Friday but it is not raining.
• If and only if/ Biconditional or Double Implication (⇔) − A⇔B is bi-conditional logical connective which is true
when p and q are same, i.e. both are false or both are true. The statement pq is also called a bi-implication.
• pq has the same truth value as (pq)(qp)

"p is necessary and sufficient for q"


"if p then q, and conversely"
"p iff q“
Example,
“It is raining today if and only if it is Friday today.” is a proposition which is of the form p q. The above proposition is
true if it is not Friday and it is not raining or if it is Friday and it is raining, and it is false when it is not Friday or it is not
raining.
Consider the following statements:
P: Good mobile phones are not cheap Q: Cheap mobile phones are not good
Let a and b be two proposition
a: Good Mobile phones. b: Cheap Mobile Phones.
P and Q can be written in logic as
P: a-->~b
Q: b-->~a.
Truth Table
a b ~a ~b P Q
T T F F F F
T F F T T T
F T T F T T
F F T T T T it clearly shows P and Q are equivalent.
• Exclusive Or operator
Truth table for Exclusive Or ⊕
pq p⊕q
TT F
TF T
FT T
FF F
Actually, this operator can be expressed by using other operators: p ⊕ q is the same as ¬ (p ↔
q).

Precedence of Operators
Operator Precedence
¬1
∧2
∨3
→4
↔5
Example:
¬ p ∧ q means (¬ p) ∧ q
p ∧ q → r means (p ∧ q) → r
Translating logical formulas to English sentences
Using the logic operators, we can construct more complicated logical formulas. (They are called
compound propositions.)
Proposition p: Alice is smart.
Proposition q: Alice is honest.
¬p ∧ q: Alice is not smart but honest.
p ∨ (¬p ∧ q): Either Alice is smart, or she is not smart but honest.
p → ¬q: If Alice is smart, then she is not honest.

We can also go in the other direction, translating English sentences to logical formulas:
Alice is either smart or honest, but Alice is not honest if she is smart:
(p ∨ q) ∧ (p → ¬ q).
That Alice is smart is necessary and sufficient for Alice to be honest:
(p → q) ∧ (q → p).
(This is often written as p ↔ q).
• Tautologies
A Tautology is a formula which is always true for every value of its propositional variables.
Example − Prove [(A→B)∧A]→B is a tautology
A B A→B (A → B) ∧ A [( A → B ) ∧ A] → B
True True True True True
True False False False True
False True True False True
False False True False True
As we can see every value of [(A→B)∧A]→B is "True", it is a tautology.

• Contradictions
A Contradiction is a formula which is always false for every value of its propositional variables.
Example − Prove (A∨B)∧[(¬A)∧(¬B)] is a contradiction
The truth table is as follows −
A B A∨B ¬A ¬B (¬ A) ∧ ( ¬ B) (A ∨ B) ∧ [( ¬ A) ∧ (¬ B)]
True True True False False False False
True False True False True False False
False True True True False False False
False False False True True True False
As we can see every value of (A∨B)∧[(¬A)∧(¬B)] is “False”, it is a contradiction.
• Contingency
A Contingency is a formula which has both some true and some false values for every value of its
propositional variables.
Example − Prove (A∨B)∧(¬A) a contingency
A B A∨B ¬A (A ∨ B) ∧ (¬ A)
True True True False False
True False True False False
False True True True True
False False False True False
As we can see every value of (A∨B)∧(¬A) has both “True” and “False”, it is a contingency.

Propositional Equivalences
Two statements X and Y are logically equivalent if any of the following two conditions hold −
• The truth tables of each statement have the same truth values.
• The bi-conditional statement X⇔Y is a tautology.
Example − Prove ¬(A∨B)and[(¬A)∧(¬B)] are equivalent
Testing by 1st method (Matching truth table)
A B A∨B ¬ (A ∨ B) ¬ A ¬B [(¬ A) ∧ (¬ B)]
True True True False False False False
True False True False False True False
False True True False True False False
False False False True True True True
Here, we can see the truth values of ¬(A∨B)and[(¬A)∧(¬B)] are same, hence the statements are
equivalent.
Testing by 2nd method (Bi-conditionality)
A B ¬ (A ∨ B ) [(¬ A) ∧ (¬ B)] [¬ (A ∨ B)] ⇔ [(¬ A ) ∧ (¬ B)]
True True False False True
True False False False True
False True False False True
False False True True True
As [¬(A∨B)]⇔[(¬A)∧(¬B)] is a tautology, the statements are equivalent.

Example:
Look at the following two compound propositions: p → q and q ∨ ¬p.
p q p→q
T T T
T F F
F T T
F F T
p q ¬p q¬p
T T F T
T F F F
F T T T
F F T T
The last column of the two truth tables are identical. Therefore
(p → q) and (q ∨ ¬p) are logically equivalent.
So (p → q) ↔ (q ∨ ¬p) is a tautology.
Thus: (p → q)≡ (q ∨ ¬p)
• Valid- A compound proposition is called valid if and only if it is a tautology. It contains only T (Truth)
in last column of its truth table.
• Invalid- A compound proposition is called invalid if and only if it is not a tautology. It contains either
only F (False) or both T (Truth) and F (False) in last column of its truth table.
• Falsifiable- A compound proposition is called falsifiable if and only if it can be made false for some
value of its propositional variables. It contains either only F (False) or both T (Truth) and F (False) in
last column of its truth table.
• Unfalsifiable-A compound proposition is called unfalsifiable if and only if it can never be made false
for any value of its propositional variables. It contains only T (Truth) in last column of its truth table.
• Satisfiable- A compound proposition is called satisfiable if and only if it can be made true for some
value of its propositional variables. It contains either only T (Truth) or both T (True) and F (False) in
last column of its truth table.
• Unsatisfiable- A compound proposition is called unsatisfiable if and only if it can not be made true
for any value of its propositional variables. It contains only F (False) in last column of its truth table.

1. All contingencies are invalid and falsifiable but not vice-versa.


2. All tautologies are valid and unfalsifiable and vice-versa.
3. All tautologies are satisfiable but not vice-versa.
4. All contingencies are satisfiable but not vice-versa.
5. All contradictions are unsatisfiable and vice-versa.
6. All contradictions are invalid and falsifiable but not vice-versa.
1. p ∧ ∼p
2. (p ∧ (p → q)) → ∼q
3. [ (p → q) ∧ (q → r) ] ∧ ( p ∧ ∼r)
4. ∼(p → q) ∨ (∼p ∨ (p ∧ q))
5. (p ↔ r) → (∼q → (p ∧ r))

1. Contradiction 2. Contingency 3. Contradiction 4. Tautology 5. Contingency


Invalid Invalid Invalid Valid Invalid
Falsifiable Falsifiable Falsifiable Unfalsifiable Falsifiable
Unsatisfiable Satisfiable Unsatisfiable Satisfiable Satisfiable
Example:
By using truth table, prove p ⊕ q ≡ ¬ (p ↔ q).
De Morgan law
We have a number of rules for logical equivalence. For example:
De Morgan Law:
¬(p ∧ q) ≡ ¬p ∨ ¬q (1)
¬(p ∨ q) ≡ ¬p ∧ ¬q (2)
The following is the truth table proof for (1).
p q p∧q ¬(p ∧ q)
T T T F
T F F T
F T F T
F F F T
-------------------------------------------------------------------------------------
p q ¬p ∨ ¬q
T T F
T F T
F T T
F F T

Distributivity
p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) (1)
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) (2)
Converse, Inverse and Contrapositive-
For a conditional statement p → q,
• The converse statement is q → p
• The inverse statement ∼p → ∼q
• The contrapositive statement is ∼q → ∼p
• Inverse of converse is contrapositive.
• Inverse of contrapositive is converse.
• Converse of inverse is contrapositive.
• Converse of contrapositive is inverse.
• Contrapositive of inverse is converse.
• Contrapositive of converse is inverse.

For a conditional statement p → q,


• Its converse statement (q → p) and inverse statement (∼p → ∼q) are equivalent to each other.
• p → q and its contrapositive statement (∼q → ∼p) are equivalent to each other.

• The given sentence is- “If today is Sunday, then it is a holiday.” This sentence is of the form- “If p then q”.
So, the symbolic form is p → q where-
p : Today is Sunday q : It is a holiday
• Converse Statement- If it is a holiday, then today is Sunday.
• Inverse Statement- If today is not Sunday, then it is not a holiday.
• Contrapositive Statement- If it is not a holiday, then today is not Sunday.
The given sentence is- “If 5x – 1 = 9, then x = 2.” This sentence is of the form- “If p then q”.
So, the symbolic form is p → q where-
p : 5x – 1 = 9 q:x=2
• Converse Statement- If x = 2, then 5x – 1 = 9.
• Inverse Statement- If 5x – 1 ≠ 9, then x ≠ 2.
• Contrapositive Statement- If x ≠ 2, then 5x – 1 ≠ 9.
Contrapositives
The proposition ¬q → ¬p is called the Contrapositive of the proposition
p → q. They are logically equivalent.
p → q ≡ ¬q → ¬p
p q p→q
T T T
T F F
F T T
F F T
-------------------------------------------------
p q ¬q → ¬p
T T T
T F F
F T T
F F T
Logic Equivalences
p ∧ T ≡ p, p ∨ F ≡ p Identity laws
p ∨ T ≡ T, p ∧ F ≡ F Domination laws
p ∨ p ≡ p, p ∧ p ≡ p Idempotent laws
¬(¬p) ≡ p Double negation law
p∨q≡q∨p
p∧q≡q∧p Commutative laws
(p ∨ q) ∨ r ≡ p ∨ (q ∨ r)
(p ∧ q) ∧ r ≡ p ∧ (q ∧ r) Associative laws
p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r)
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) Distributive laws
¬(p ∨ q) ≡ ¬p ∧ ¬q
¬(p ∧ q) ≡ ¬p ∨ ¬q De Morgan’s laws
p ∨ (p ∧ q) ≡ p
p ∧ (p ∨ q) ≡ p Absorption laws
p ∨ ¬p ≡ T, p ∧ ¬p ≡ F Negation laws
Logical Equivalences Involving Conditional Statements
p → q ≡ ¬p ∨ q
p → q ≡ ¬q → ¬p
p ∨ q ≡ ¬p → q
p ∧ q ≡ ¬(p → ¬q)
¬(p → q) ≡ p ∧ ¬q
(p → q) ∧ (p → r) ≡ p → (q ∧ r)
(p → r) ∧ (q → r) ≡ (p ∨ q) → r
(p → q) ∨ (p → r) ≡ p → (q ∨ r)
(p → r) ∨ (q → r) ≡ (p ∧ q) → r
Logical Equivalences Involving Biconditional Statements
p ↔ q ≡ (p → q) ∧ (q → p)
p ↔ q ≡ ¬p ↔ ¬q
p ↔ q ≡ (p ∧ q) ∨ (¬p ∧ ¬q)
¬(p ↔ q) ≡ p ↔ ¬q
By using these laws, we can prove two propositions are logical
equivalent.
Example 1: Prove ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬q.
¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) DeMorgan
≡ ¬p ∧ (p ∨ ¬q) DeMorgan
≡ (¬p ∧ p) ∨ (¬p ∧ ¬q) Distributivity
≡ F∨(¬p ∧ ¬q) Because ¬p ∧ p ≡ F
≡ ¬p ∧ ¬q Because F ∨r ≡ r for any r

Example 2: Prove (p ∧ q) → (p ∨ q) ≡ T.
(p ∧ q) → (p ∨ q) ≡ ¬(p ∧ q) ∨ (p ∨ q) Substitution for →p → q ≡ ¬p ∨ q
≡ (¬p ∨ ¬q) ∨ (p ∨ q) DeMorgan
≡ (¬p ∨ p) ∨ (¬q ∨ q) Commutativity and Associativity
≡ T∨T Because ¬p ∨ p ≡ T
≡T
• Prove that: [¬ p ∧ (p ∨ q)] → q is a tautology.
By using truth table.
By using logic equivalence laws.
• Prove that: [(p → q) ∧ (q → r)] → [p → r] is a tautology.
By using truth table.
By using logic equivalence laws
• Use the truth tables method to determine whether p → (q ∧ ¬q) and ¬p are logically equivalent.

• (p → p) → p
• p → (p → p)
• p∨q→p∧q
• p ∨ (q ∧ r) → (p ∧ r) ∨ q
• p → (q → p)
• (p ∧ ¬q) ∨ ¬(p ↔ q)
• If it rains, then I will stay at home.
This sentence is of the form- “If p then q”.
So, the symbolic form is p → q where-
p : It rains
q : I will stay at home
• If I will go to Australia, then I will earn more money.
So, the symbolic form is p → q where-
p : I will go to Australia
q : I will earn more money
• He is poor but honest. // replace but with “and”
So, the symbolic form is p ∧ q where-
p : He is poor
q : He is honest
• If a = b and b = c then a = c.
So, the symbolic form is (p ∧ q) → r where-
p:a=b
q:b=c
r:a=c
• Neither it is hot nor cold today.
So, the symbolic form is ∼p ∧ ∼q where-
p : It is hot today
q : It is cold today
• He goes to play a match if and only if it does not rain.
This sentence is of the form- “p if and only if q”.
So, the symbolic form is p ↔ q where-
p : He goes to play a match
q : It does not rain
• Birds fly if and only if sky is clear.
So, the symbolic form is p ↔ q where-
p : Birds fly
q : Sky is clear
• I will go only if he stays.
This sentence is of the form- “p only if q”.
So, the symbolic form is p → q where-
p : I will go
q : He stays
• It is false that he is poor but not honest.
Then, the sentence is- “It is false that he is poor and not honest.”
So, the symbolic form is ∼(p ∧ ∼q) where-
p : He is poor
q : He is honest
• It is false that he is poor or clever but not honest.
So, the symbolic form is ∼((p ∨ q) ∧ ∼r) where-
p : He is poor
q : He is clever
r : He is honest
• It is hot or else it is both cold and cloudy.
So, the symbolic form is p ∨ (q ∧ r) where-
p : It is hot
q : It is cold
r : It is cloudy
• “I will not go to class unless you come.” This sentence is of the form- “p unless q”.
So, the symbolic form is ∼ q → p where-
p : I will go to class
q : You come
• The given sentence is- “We will leave whenever he comes.”
We can replace “whenever” with “if”. Then, the sentence is- “We will leave if he comes.” This
sentence is of the form- “q if p”.
So, the symbolic form is p → q where-
p : He comes
q : We will leave

• Presence of cycle in a single instance RAG is a necessary and sufficient condition for deadlock.
This sentence is of the form- “p is necessary and sufficient for q”.
So, the symbolic form is p ↔ q where-
p : Presence of cycle in a single instance RAG
q : Presence of deadlock
• Presence of cycle in a multi instance RAG is a necessary but not sufficient condition for deadlock.
This sentence is of the form- “p is necessary but not sufficient for q”.
So, the symbolic form is (q → p) ∧ ∼(p → q) where-
p : Presence of cycle in a multi instance RAG
q : Presence of deadlock
Let’s consider a propositional language where
• p means “P is happy”,
• q means “P paints a picture”,
• r means “R is happy”.
Formalize the following sentences:
Propositional Formalization
1. “if P is happy and paints a picture then R isn’t happy”
2. “if P is happy, then she paints a picture”
3. “P is happy only if she paints a picture”
Solution.
1. p ∧ q → ¬r
2. p → q
3. ¬(p ∧ ¬q) ..which is equivalent to p → q
Let’s consider a propositional language where
• p means “x is a prime number”,
• q means “x is odd”.
Formalize the following sentences:
1. “x being prime is a sufficient condition for x being odd”
2. “x being odd is a necessary condition for x being prime”
Solution. 1. and 2. p → q
Let A =“Aldo is Italian” and B =“Bob is English”.
Formalize the following sentences:
1. “Aldo isn’t Italian”
2. “Aldo is Italian while Bob is English”
3. “If Aldo is Italian then Bob is not English”
4. “Aldo is Italian or if Aldo isn’t Italian then Bob is English”
5. “Either Aldo is Italian and Bob is English, or neither Aldo is Italian nor
Bob is English”
Solution.
1. ¬A
2. A ∧ B
3. A → ¬B
4. A ∨ (¬A → B) logically equivalent to A ∨ B
5. (A ∧ B) ∨ (¬A ∧ ¬B) logically equivalent to A ↔ B
Let’s consider a propositional language where
• A =“Angelo comes to the party”,
• B =“Bruno comes to the party”,
• C =“Carlo comes to the party”,
• D =“Davide comes to the party”.
Formalize the following sentences:
1. “If Davide comes to the party then Bruno and Carlo come too”
2. “Carlo comes to the party only if Angelo and Bruno do not come”
3. “Davide comes to the party if and only if Carlo comes and Angelo doesn’t come”
4. “If Davide comes to the party, then, if Carlo doesn’t come then Angelo comes”
5. “Carlo comes to the party provided that Davide doesn’t come, but, if Davide comes, then Bruno doesn’t come”
6. “A necessary condition for Angelo coming to the party, is that, if Bruno and Carlo aren’t coming, Davide
comes”
7. “Angelo, Bruno and Carlo come to the party if and only if Davide doesn’t come, but, if neither Angelo nor
Bruno come, then Davide comes only if Carlo comes”

Solution.
1. D → B ∧ C
2. C → ¬A ∧ ¬B
3. D ↔ (C ∧ ¬A)
4. D → (¬C → A)
5. (¬D → C) ∧ (D → ¬B)
6. A → (¬B ∧ ¬C → D)
7. (A ∧ B ∧ C ↔ ¬D) ∧ (¬A ∧ ¬B → (D ↔ C)
Predicates and Quantifier

Consider the following statements:


x > 3, x = y + 3, x + y = z
The truth value of these statements has no meaning without specifying the values of x, y, z.
A predicate is a property that is affirmed or denied about the subject (in logic, we say “variable” or
“argument”) of a statement.

subject predicate
The statement “x is greater than 3″ can be denoted by P(x) where P denotes the predicate “is greater than
3” and x is the variable. The predicate P can be considered as a function. It tells the truth value of the
statement P(x) at x. Once a value has been assigned to the variable x, the statement P(x) becomes a
proposition and has a truth or false(t|f) value.
• A predicate is an expression of one or more variables defined on some specific domain. A predicate
with variables can be made a proposition by either assigning a value to the variable or by
quantifying the variable.
The following are some examples of predicates −
Let E(x, y) denote "x = y"
Let X(a, b, c) denote "a + b + c = 0"
Let M(x, y) denote "x is married to y“
• Predicate logic is an extension of Propositional logic. It adds the concept of predicates and quantifiers
to better capture the meaning of statements that cannot be adequately expressed by propositional
logic.
• In general, a statement involving n variables x1, x2, x3,.. , xn can be denoted by P(x1, x2, x3,.. , xn).
Here P is also referred to as n-place predicate or a n-ary predicate.
Example 1: Let P(x) denote the statement “x > 10″. What are the truth values of P(11) and P(5)?
Solution: P(11) is equivalent to the statement 11 > 10, which is True.
P(5) is equivalent to the statement 5 > 10, which is False.
Example 2: Let R(x,y) denote the statement “x = y + 1“. What is the truth value of the propositions R(1,3)
and R(2,1)?
Solution: R(1,3) is the statement 1 = 3 + 1, which is False.
R(2,1) is the statement 2 = 1 + 1, which is True.

Well Formed Formula- It is a predicate holding any of the following −


• All propositional constants and propositional variables are wffs
• If x is a variable and Y is a wff, ∀xY and ∃xY are also wff
• Truth value and false values are wffs
• Each atomic formula is a wff
• All connectives connecting wffs are wffs
What are quantifiers?
In predicate logic, predicates are used alongside quantifiers to express the extent to which a predicate is
true over a range of elements. Using quantifiers to create such propositions is called quantification.
Quantifiers are phrases that refer to given quantities, such as "for some" or "for all" or "for every",
indicating how many objects have a certain property.
There are two types of quantifiers-
1. Universal Quantifier(∀) for all
2. Existential Quantifier(∃) there exists some
Universal Quantifier: represented by ∀, “for all”, “for every”, “for each”, or “for any”.
Existential Quantifier: represented by ∃, “for some”, “there exists”, “there is a”, or “for at least one”.
• Universal Quantifier- It states that the statements within its scope are true for every value of the
specific variable. It is denoted by the symbol ∀. Or Mathematical statements sometimes assert that a
property is true for all the values of a variable in a particular domain, called the domain of
discourse
∀xP(x) is read as for every value of x, P(x) is true.

Example − "Man is mortal" can be transformed into the propositional form ∀xP(x) where P(x) is the
predicate which denotes x is mortal and the universe of discourse is all men.

Example- Let P(x) be the statement “x + 2 > x“. What is the truth value of the statement ∀xP(x) ?
Solution: As x+2 is greater than x for any real number, so P(x)T for all x or ∀xP(x)T.

An element for which P(x) is false is called a counterexample of ∀x P(x).


P(x): x>3
P(2): 2>3 is a counterexample of ∀x P(x)
P(x): x2 > 0.
What is the truth value of ∀x P(x) in the domain of integers?
Solution: Find a counterexample for ∀ x P(x)
P(0): 0>0 is false; x=0 is a counterexample for ∀x P(x), so ∀ x P(x) is false.
• Existential Quantifier- It states that the statements within its scope are true for some
values of the specific variable. It is denoted by the symbol ∃.
∃xP(x) is read as for some values of x, P(x) is true.
∃xP(x) is read as "There is atleast one such x such that P(x)".
Example − "Some people are dishonest" can be transformed into the propositional form
∃xP(x) where P(x) is the predicate which denotes x is dishonest and the universe of
discourse is some people.

Example- Let P(x) be the statement “x > 5″. What is the truth value of the statement
∃xP(x) ?
Solution: P(x) is true for all real numbers greater than 5 and false for all real numbers less
than 5. So ∃xP(x)T.
∀xP(x)Q(x) \\ Here, P(x) is the statement "x is 18 years or older and, Q(x) is the statement "x is eligible to
vote".
If the universe of discourse is finite, say {n1, n2, . . . , nk}, then the universal quantifier is simply the
conjunction of all elements:
∀xP(x) ⇐⇒ P(n1) ∧ P(n2) ∧ · · · ∧ P(nk)
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”.
“Every computer science student must take a discrete mathematics course”.
∀x(Q(x) → P(x))
“Everybody must take a discrete mathematics course or be a computer science student”.
∀x(Q(x) ∨ P(x))
Again, if the universe of discourse is finite, {n1, n2, . . . , nk}, then the existential quantifier is simply the
disjunction of all elements:
∃xP(x) ⇐⇒ P(n1) ∨ P(n2) ∨ · · · ∨ P(nk)

In general, when are quantified statements true/false?


Mixing Quantifiers
Existential and universal quantifiers can be used together to quantify a predicate statement; for example,
∀x∃yP(x, y) is perfectly valid. However, you must be careful—it must be read left to right. For example,
∀x∃yP(x, y) is not equivalent to ∃y∀xP(x, y). Thus, ordering is important.
For example:
∀x∃yLoves(x, y): everybody loves somebody
∃y∀xLoves(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 converse
does not hold. However, you can commute similar quantifiers; ∃x∃yP(x, y) is equivalent to ∃y∃xP(x, y)
Examples of Predicate Logic:
1. Mary loves everyone. [assuming D contains only humans]
∀x love (Mary, x), ∀x (love (Mary, x)), (∀x love (Mary, x)), (∀x (love (Mary, x)))
2. No one talks. [assume D contains only humans unless specified otherwise.]
¬∃x talk(x) or equivalently, ∀x ¬talk(x)
3. Everyone loves himself.
∀x love (x, x)
4. Everyone loves everyone.
` ∀x∀y love (x, y)
5. Everyone loves everyone except himself. (= Everyone loves everyone else.)
∀x∀y(¬ x = y → love (x, y)) or ∀x∀y( x ≠ y → love (x, y))
6. Every student smiles.
∀x (student(x) → smile( x))
7. Every student except George smiles.
∀x ((student(x) & x ≠ George) → smile( x))
8. Everyone walks or talks.
∀x (walk (x) ∨ talk (x))
9. Every student who walks talks.
∀x ((student(x) & walk (x)) → talk (x))) or ∀x (student(x) → (walk (x) → talk (x)))
10. If anyone cheats, everyone suffers.
∀x (cheat(x) → ∀y suffer(y)) or ∀x∀y (cheat(x) → suffer(y))
Also equivalent: ∀y ∀x (cheat(x) → suffer(y))
Also equivalent: ∃x cheat(x) → ∀y suffer( y) (Each quantifier has narrow scope here.)
Also equivalent: ∀y( ∃x cheat(x) → suffer(y))
Express the following system specifications.
“Every mail message larger than one megabyte will be compressed.”
“If a user is active, at least one network link will be available.”
Determine individual predicates
• Mail message is larger than one megabyte.
• Mail message will be compressed.
• User is active.
• Network link will be available.
Mail message is larger than one megabyte. P(m,x): Mail message m is larger than x megabytes.
domain of m: all mail messages; domain of x: positive real numbers
Mail message will be compressed. Q(m): Mail message m will be compressed.
domain of m: all mail messages
User is active. R(u): User u is active.
domain of u: all users
Network link will be available. S(n): Network link n is available.
domain of n: all network links
“Every mail message larger than one megabyte will be compressed.”
P(m,x): Mail message m is larger than x megabytes.
Q(m): Mail message m will be compressed.
m (P(m,1)→Q(m))
“If a user is active, at least one network link will be available.”
R(u): User u is active.
S(n): Network link n is available.
∃uR(u)→∃n S(n)
Express the following sentences using predicates and quantifiers.
“All lions are fierce.”
“Some lions do not drink coffee.”
Assume
P(x): x is a lion.
Q(x): x is fierce.
R(x): x drinks coffee.
Solution:
1. “All lions are fierce.”
∀x (P(x)→Q(x))
2. “Some lions do not drink coffee.”
∃x(P(x)¬R(x))
PERMUTATION &
COMBINATIONS
Combinatorics (counting) deals with the question: “How many elements in a given set have desired
property?”
For instance, in how many ways can a panel of judges comprising of 6 men and 4 women be chosen
from among 50 men and 38 women?
How many different 10 lettered PAN numbers can be generated such that the first five letters are
capital alphabets, the next four are digits and the last is again a capital letter.
For solving these problems, mathematical theory of counting are used.
Counting mainly encompasses fundamental counting rule, the permutation rule, and the combination
rule.
The Rules of Sum and Product

• The Rule of Sum − If a sequence of tasks T1,T2,…,Tm can be done in w1,w2,…wm ways respectively
(the condition is that no tasks can be performed simultaneously), then the number of ways to do
one of these tasks is w1+w2+⋯+wm. If we consider two tasks A and B which are disjoint (i.e.
A∩B=∅), then mathematically |A∪B|=|A|+|B|. decomposes task into a set of alternatives

• The Rule of Product − If a sequence of tasks T1,T2,…,Tm can be done in w1,w2,…wm ways
respectively and every task arrives after the occurrence of the previous task, then there are
w1×w2×⋯×wm ways to perform the tasks. Mathematically, if a task B arrives after a task A, then |
A×B|=|A|×|B|. useful when task decomposes into a sequence of independent tasks
• Suppose a task A can be decomposed into a sequence of two independent tasks B and C
n1 ways of doing B
n2 ways of doing C
Product rule: Then, there are n1n2 ways of doing A
• Suppose a task A can be done either in way B or in way C
Suppose there are n1 ways to do B, and n2 ways to do C
Sum rule: There are n1 + n2 ways to do A.

Rule of Sum - Statement:

If there are n choices for one action, and m choices for another action and the two actions cannot be done
at the same time, then there are n+m ways to choose one of these actions.

Rule of Product - Statement:

If there are n ways of doing something, and m ways of doing another thing after that, then there are n×m
ways to perform both of these actions.

• Calvin wants to go to Milwaukee. He can choose from 3 bus services or 2 train services to head from
home to downtown Chicago. From there, he can choose from 2 bus services or 3 train services to head
to Milwaukee. How many ways are there for Calvin to get to Milwaukee?

He has 3 + 2=5 ways to get to downtown Chicago. (Rule of sum)


From there, he has 2+3=5 ways to get to Milwaukee. (Rule of sum)
Hence, he has 5*5=25ways to get to Milwaukee in total. (Rule of product)
There are 3 flights from California to France, and 2 flights from France to India. Sanjeet wants to fly from
California to France and then to India.
How many choices does he have for his flight plan?

How many choices does he have for his flight plan? =3*2=6
A restaurant offers 5 choices of appetizer, 10 choices of the main course and 4 choices of dessert. A
customer can choose to eat just one course, or two different courses, or all three courses. Assuming that
all food choices are available, how many different possible meals does the restaurant offer?
Note: When you eat a course, you only pick one of the choices.

A person who eats only an appetizer has 5 choices. A person who eats only a main meal has 10 choices. A
person who eats only a dessert has 4 choices.
A person who eats an appetizer and a main meal has 5 × 10 = 50 choices. A person who eats an appetizer
and a dessert has 5 × 4 = 20 choices. A person who eats a main meal and a dessert has 10 × 4 = 40 choices.
A person who eats all three courses has 5 × 10 × 4 = 200 choices
So the total number of possible meals = 5 + 10 + 4 + 50 + 20 + 40 + 200 = 329

A boy lives at X and wants to go to School at Z. From his home X he has to first reach Y and then Y to Z. He may
go X to Y by either 3 bus routes or 2 train routes. From there, he can either choose 4 bus routes or 5 train
routes to reach Z. How many ways are there to go from X to Z?

Solution − From X to Y, he can go in 3+2=5 ways (Rule of Sum). Thereafter, he can go Y to Z in 4+5=9 ways
(Rule of Sum). Hence from X to Z he can go in 5×9=45 ways (Rule of Product).
• How many bit strings of length seven are there?
Since each bit is either 0 or 1, applying the product rule,
the answer is = 128.
• How many different car license plates can be made if each plate contains a sequence of three
uppercase English letters followed by three digits?
26 · 26 · 26 · 10 · 10 · 10
• Suppose variable names in a programming language can be either a single uppercase letter or an
uppercase letter followed by a digit. Find the number of possible variable names.
Use the sum and product rules: 26 + 26 · 10 = 286.
• Each user on a computer system has a password which must be six to eight characters long.
1. Each character is an uppercase letter or digit.
2. Each password must contain at least one digit.
3. How many possible passwords are there?

think of the digits as no different from the uppercase alphabets. Then you have a set of 36 characters(26 :
A-Z + 10 : 0-9) to choose from. Each one may be present in the password at any of the 6 positions.
This gives you 36 choices for 6 positions. 36^6 combinations.
But then there is the added burden of removing those passwords which have no digits, as required in the
problem statement.
So forget the digits ever existed and construct the password out of uppercase alphabets only. 26 choices.
6 positions. 26^6 combinations.
Removing these invalid passwords, you are left with 36^6 - 26^6 correct ones.
Let P be the total number of passwords, and let P6, P7, and P8 be the passwords of
length 6, 7, and 8.
● By the sum rule P = P6 + P7 +P8.
● To find each of P6, P7, and P8 , we find the number of passwords of the specified length
composed of letters and digits and subtract the number composed only of letters. We find that:

P6 = 366 − 266 =2,176,782,336 − 308,915,776 =1,867,866,560.


P7 = 367 − 267 =
78,364,164,096 − 8,031,810,176 = 70,332,353,920.
P8 = 368 − 268 =
2,821,109,907,456 − 208,827,064,576 =2,612,282,842,880.
Consequently, P = P6 + P7 +P8 = 2,684,483,063,360.

An office building contains 27 floors and has 37 offices on each floor. How many offices are in
the building?
Solution. By the product rule there are 27 · 37 = 999 offices.

A particular brand of shirt comes in 12 colors, has a male version and a female version, and comes in three sizes
for each. How many different types of this shirt are made?
By the product rule there are 12 · 2 · 3 = 72 different types of shirt.
The North American numbering plan (NANP) specifies the format of telephone numbers in the U.S., Canada,
and many other parts of North America. A telephone number in this plan consists of 10 digits, which are split
into a three-digit area code, a three-digit office code, and a four-digit station code. Because of signaling
considerations, there are certain restrictions on some of these digits. To specify the allowable format, let X
denote a digit that can take any of the values 0 through 9, let N denote a digit that can take any of the values 2
through 9, and let Y denote a digit that must be a 0 or 1. Two numbering plans, which will be called the old
plan, and the new plan, will be discussed. (The old plan, in use in the 1960s, has been replaced by the new
plan, but the recent rapid growth in demand for new numbers for mobile phones and devices will eventually
make even this new plan obsolete. In this example, the letters used to represent digits follow the conventions
of the North American Numbering Plan.) As will be shown, the new plan allows the use of more numbers. In
the old plan, the formats of the area code, office code, and station code are NYX, NNX, and XXXX, respectively,
so that telephone numbers had the form NYX-NNX-XXXX. In the new plan, the formats of these codes are NXX,
NXX, and XXXX, respectively, so that telephone numbers have the form NXX-NXX-XXXX. How many different
North American telephone numbers are possible under the old plan and under the new plan?

By the product rule, there are 8 · 2 · 10 = 160 area codes with format NYX and 8 · 10 · 10 = 800 area codes
with format NXX. Similarly, by the product rule, there are 8 ·8·10 = 640 office codes with format NNX. The
product rule also shows that there are 10 · 10 · 10 · 10 = 10,000 station codes with format XXXX.
Consequently, applying the product rule again, it follows that under the old plan there are160 · 640 · 10,000 =
1,024,000,000 different numbers available in North America. Under the new plan, there are 800 · 800 ·
10,000 = 6,400,000,000 different numbers available
How many bit strings are there of length six or less, not counting the empty string?
We use the sum rule, adding the number of bit strings of each length up to 6. If we include the
empty string, then we get + + + + + + = − 1 = 127 (using the formula for the sum Of a geometric
progression).

Suppose either a CS faculty or CS student must be chosen as representative for a committee, There are 14
faculty, and 50 majors. How many ways are there to choose the representative?
By the sum rule, 50 + 14 = 64 ways
PERMUTATIONS
&
COMBINATIONS
What is Permutation?
Permutation relates to the act of arranging all the members of a set into some sequence or order. In other words, if the
set is already ordered, then the rearranging of its elements is called the process of permuting.
When the order does matter it is a Permutation. A Permutation is an ordered Combination.
"The combination to the safe is 472". Now we do care about the order. "724" won't work, nor will "247". It has to be
exactly 4-7-2.
There are basically two types of permutation:
1. Repetition is Allowed: such as the lock above. It could be "333".
2. No Repetition: for example the first three people in a running race. You can't be first and second.

Combination?
The combination is a way of selecting items from a collection, such that (unlike permutations) the order of selection
does not matter. In smaller cases, it is possible to count the number of combinations. Combination refers to the
combination of n things taken k at a time without repetition.
When the order doesn't matter, it is a Combination.
such as coins in your pocket (5,5,5,10,10), Picking a team of 3 people from a group of 10, Choosing 3 desserts from a
menu of 10
• Permutations with Repetition
These are the easiest to calculate.
When a thing has n different types ... we have n choices each time!
For example: choosing 3 of those things, the permutations are:
n × n × n (n multiplied 3 times)
More generally: choosing r of something that has n different types, the permutations are:
n × n × ... (r times) (In other words, there are n possibilities for the first choice, THEN there are n possibilities for the
second choice, and so on, multiplying each time.)
n × n × ... (r times) =
Example: in the lock above, there are 10 numbers to choose from (0,1,2,3,4,5,6,7,8,9) and we choose 3 of them:
10 × 10 × ... (3 times) = = 1,000 permutations
where n is the number of things to choose from, and we choose r of them, repetition is allowed, and order matters.
• Permutations without Repetition
In this case, we have to reduce the number of available choices each time.
Example: what order could 16 pool balls be in?
After choosing, say, number "14" we can't choose it again.
So, our first choice has 16 possibilities, and our next choice has 15 possibilities, then 14, 13, 12, 11, ... etc. And the total
permutations are:
16 × 15 × 14 × 13 × ... = 20,922,789,888,000
But maybe we don't want to choose them all, just 3 of them, and that is then:
16 × 15 × 14 = 3,360
In other words, there are 3,360 different ways that 3 pool balls could be arranged out of 16 balls.
Without repetition our choices get reduced each time.
But how do we write that mathematically? Answer: we use the "factorial function"
The factorial function (symbol: !) just means to multiply a series of descending natural numbers. Examples:
4! = 4 × 3 × 2 × 1 = 24
7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5,040
1! = 1
Note: it is generally agreed that 0! = 1. So, when we want to select all of the billiard balls the permutations are:
16! = 20,922,789,888,000
But when we want to select just 3 we don't want to multiply after 14. How do we do that? There is a neat trick: we divide by 13!
= 16 × 15 × 14

The formula is written:

where n is the number of things to choose from, and we choose r of them, no repetitions, order matters.
Example Our "order of 3 out of 16 pool balls example" is:
(which is just the same as: 16 × 15 × 14 = 3,360)
2. How many ways can first and second place be awarded to 10 people?
90=(which is just the same as: 10 × 9 = 90)

NOTE: permutation notation P(n,r) = =


Example: P(10,2) = 90
Going back to our pool ball example, let's say we just want to know which 3 pool balls are chosen, not the order.
We already know that 3 out of 16 gave us 3,360 permutations. But many of those are the same to us now, because we don't care what
order!
For example, let us say balls 1, 2 and 3 are chosen. These are the possibilites:
Order does matter Order doesn't matter
123
132
213
231
312
321 123
So, the permutations have 6 times as many possibilities.
In fact there is an easy way to work out how many ways "1 2 3" could be placed in order, and we have already talked about it. The
answer is: 3! = 3 × 2 × 1 = 6. (Another example: 4 things can be placed in 4! = 4 × 3 × 2 × 1 = 24 different ways)
So we adjust our permutations formula to reduce it by how many ways the objects could be in order (because we aren't interested in
their order any more):

where n is the number of things to choose from, and we choose r of them, no repetition, order doesn't matter.

So, our pool ball example (now without order) is:


= 560
• Find the number of permutations and combinations if n = 12 and r = 2.
Permutation:
= (n!) / (n-r)! =(12!) / (12-2)! = 12! / 10! = (12 x 11 x 10! )/ 10! = 132

Combination:
=n!/r!(n−r)! = 12!/2!(12−2)!=12!/2!(10)!=12×11×10!/2!(10)!=66

• In how many ways a committee consisting of 5 men and 3 women, can be chosen from 9 men and 12 women?
Choose 5 men out of 9 men = ways = 126 ways
Choose 3 women out of 12 women = ways = 220 ways
The committee can be chosen in 27720 ways.
• How many words can be formed by using 3 letters from the word “DELHI” ?
The word “DELHI” has 5 different letters. Therefore, required number of letters = = 5! / (5 – 3)!
Þ Required number of words = 5! / 2! = 120 / 2 = 60
• In how many ways, can we select a team of 4 students from a given choice of 15 ?
Number of possible ways of selection = = 15 ! / [(4 !) x (11 !)]
Þ Number of possible ways of selection = (15 x 14 x 13 x 12) / (4 x 3 x 2 x 1) = 1365
• Find the number of words, with or without meaning, that can be formed with the letters of the word ‘CHAIR’.
‘CHAIR’ contains 5 letters. Therefore, the number of words that can be formed with these 5 letters = 5! = 5*4*3*2*1 = 120.
• Find the number of words, with or without meaning, that can be formed with the letters of the word ‘INDIA’.
The word ‘INDIA’ contains 5 letters and ‘I’ comes twice. When a letter occurs more than once in a word, we divide the factorial of the
number of all letters in the word by the number of occurrences of each letter.
Therefore, the number of words formed by ‘INDIA’ = 5!/2! = 60.
• Find the number of words, with or without meaning, that can be formed with the letters of the word ‘SWIMMING?
The word ‘SWIMMING contains 8 letters. Of which, I occurs twice and M occurs twice.
Therefore, the number of words formed by this word = 8! / (2!*2!) = 10080.

• How many different words can be formed with the letters of the word ‘SUPER’ such that the vowels always come together?
The word ‘SUPER’ contains 5 letters. In order to find the number of permutations that can be formed where the two vowels U and E
come together. In these cases, we group the letters that should come together and consider that group as one letter.
So, the letters are S,P,R, (UE). Now the number of words are 4. Therefore, the number of ways in which 4 letters can be arranged is 4!.
In U and E, the number of ways in which U and E can be arranged is 2!. Hence, the total number of ways in which the letters of the
‘SUPER’ can be arranged such that vowels are always together are 4! * 2! = 48 ways.

• Find the number of different words that can be formed with the letters of the word ‘BUTTER’ so that the vowels are always
together.
The word ‘BUTTER’ contains 6 letters. The letters U and E should always come together. So the letters are B, T, T, R, (UE).
Number of ways in which the letters above can be arranged = 5!/2! = 60 (since the letter ‘T’ is repeated twice).
Number of ways in which U and E can be arranged = 2! = 2 ways
Therefore, total number of permutations possible = 60*2 = 120 ways.

• Find the number of permutations of the letters of the word ‘REMAINS’ such that the vowels always occur in odd places.

The word ‘REMAINS’ has 7 letters. There are 4 consonants and 3 vowels in it.
(1) (2) (3) (4) (5) (6) (7)
No. of ways 3 vowels can occur in 4 different places = 4P3 = 24 ways.
After 3 vowels take 3 places, no. of ways 4 consonants can take 4 places = 4P4 = 4! = 24 ways.
Therefore, total number of permutations possible = 24*24 = 576 ways.
• How many unique ways are there to arrange the letters in the word CANNON?
= 6! / 3! =120
• How many different possible permutations can be made from the word ‘BULLET’ such that the vowels are never together?
The word ‘BULLET’ contains 6 letters of which 1 letter occurs twice = 6! / 2! = 360
No. of permutations possible with vowels always together = 5! * 2! / 2! = 120
No. of permutations possible with vowels never together = 360-120 = 240.
• In how many ways can a selection of 3 men and 2 women can be made from a group of 5 men and 5 women ?
5C3 * 5C2 = 100
• Using all the letters of the word GIFT how many distinct words can be formed?
4!=24
• In how many different ways can five friends sit for a photograph of five chairs in a row?
5*4*3*2*1=120
• From 2010, Alberta assigns license plates with 7 characters (ABC-1234), replacing the old 6-character plates (ABC-123). All 26
letters (A to Z) and 10 digits (0 to 9) may be used more than once.
a) How many license plates were possible with the old plate?
b) How many license plates are possible with the new plate?
SOLUTION
a) For each letter, there are 26 choices.
For each digit there are 10 choices.
So, the number of possible plates is this product:
26 26 26 10 10 10 = 17 576 000 letter letter letter digit digit digit
So, 17 576 000 license plates were possible with the old plate.
b) Adding another digit increases the number of plates by a factor of 10:
17 576 000 10 = 175 760 000
So, 175 760 000 license plates are possible with the new plate
• In a group of 6 boys and 4 girls, four children are to be selected. In how many different ways can they be selected such that at least
one boy should be there?
Sol: We may have (1 boy and 3 girls) or (2 boys and 2 girls) or (3 boys and 1 girl) or (4 boys).
Required number
of ways = (6C1 x 4C3) + (6C2 x 4C2) + (6C3 x 4C1) + (6C4)
= (6C1 x 4C1) + (6C2 x 4C2) + (6C3 x 4C1) + (6C2)
= (24 + 90 + 80 + 15)
= 209.
• How many 3-digit numbers can be formed from the digits 2, 3, 5, 6, 7 and 9, which are divisible by 5 and none of the digits is
repeated?
Since each desired number is divisible by 5, so we must have 5 at the unit place. So, there is 1 way of doing it.
The tens place can now be filled by any of the remaining 5 digits (2, 3, 6, 7, 9). So, there are 5 ways of filling the tens place.
The hundreds place can now be filled by any of the remaining 4 digits. So, there are 4 ways of filling it.
Required number of numbers = (1 x 5 x 4) = 20.
• A box contains 2 white balls, 3 black balls and 4 red balls. In how many ways can 3 balls be drawn from the box, if at least one
black ball is to be included in the draw?
We may have(1 black and 2 non-black) or (2 black and 1 non-black) or (3 black).

Required number of ways = (3C1 x 6C2) + (3C2 x 6C1) + (3C3)


= (45 + 18 + 1)
= 64.
• In how many different ways can the letters of the word 'DETAIL' be arranged in such a way that the vowels occupy only the odd
positions?
There are 6 letters in the given word, out of which there are 3 vowels and 3 consonants.
Let us mark these positions as under: (1) (2) (3) (4) (5) (6)
Now, 3 vowels can be placed at any of the three places out 4, marked 1, 3, 5.
Number of ways of arranging the vowels = 3P3 = 3! = 6.
Also, the 3 consonants can be arranged at the remaining 3 positions.
Number of ways of these arrangements = 3P3 = 3! = 6.
Total number of ways = (6 x 6) = 36.
• How many 4-letter words with or without meaning, can be formed out of the letters of the word, 'LOGARITHMS', if repetition of
letters is not allowed?
'LOGARITHMS' contains 10 different letters.
Required number of words = Number of arrangements of 10 letters, taking 4 at a time.
= 10P4
= (10 x 9 x 8 x 7)
= 5040.
• In how many different ways can the letters of the word 'MATHEMATICS' be arranged so that the vowels always come together?
In the word 'MATHEMATICS', we treat the vowels AEAI as one letter.
Now, we have to arrange 8 letters, out of which M occurs twice, T occurs twice and the rest are different.
Number of ways of arranging these letters =8!/(2!)(2!) = 10080.
Now, AEAI has 4 letters in which A occurs 2 times and the rest are different.
Number of ways of arranging these letters =4!/2! = 12.
Required number of words = (10080 x 12) = 120960.
FUNCTIONS
Let X and Y be sets. A function f from X to Y is a rule that assigns every element x of X to a unique y in Y . We write f : X → Y and f(x) = y.
Then X is called the domain of f, and Y is called the codomain of f. The element y is the image of x under f, while x is the pre-image of y
under f.
**There may be some elements of set Y which are not associated to any element of the set X.
(∀𝑥 ∈ 𝑋 ∃𝑦 ∈ 𝑌, 𝑦 = 𝑓(𝑥)) ∧(∀𝑥1, 𝑥2 ∈ 𝑋, 𝑓 𝑥1 ≠ 𝑓(𝑥2) → 𝑥1 ≠ 𝑥2)
X = domain, Y = codomain
y = image of x under f,
x = preimage of y under f
range = subset of Y with preimages

Eg:1 Domain X={a,b,c},


Co-domain Y={1,2,3,4}
f={(a,2),(b,4),(c,2)},
preimage of 2 is{a,c}
Range={2,4}

Sample functions:
f : R->R, f(x) =
f : Z->Z, f(x) = x + 1
f : Q->Z, f(x) = 2
Graphical Representations

• Functions can be represented graphically in several ways:

A B
f
• •
f • •
• • • y
a b •



x
A
B Graph
Plot
Like Venn diagrams
Functions vs. Non-functions
(∀𝑥 ∈ 𝑋 ∃𝑦 ∈ 𝑌, 𝑦 = 𝑓(𝑥)) ∧(∀𝑥1, 𝑥2 ∈ 𝑋, 𝑓 𝑥1 ≠ 𝑓(𝑥2) → 𝑥1 ≠ 𝑥2)
X = {a,b,c} to Y = {1,2,3,4}
One-To-One Function(Injective)
A function f is one-to-one (or injective), if and only if f(x) = f (y) implies x = y for all x and y in the domain of f
In words: “All elements in the domain of f have different images” or “ if each element in codomain has a unique pre-
image” or “for f:A->B no element in B is the image of more than 1 element in A”
A function in which one element of Domain Set is connected to one element of Co-Domain Set.
Mathematical Description:
f:A →B is one-to-one ⟺∀x1, x2∊A (f(x1)=f(x2)→x1 = x2 )
or
f:A → B is one-to-one ⟺ ∀x1, x2 ∊ A (x1≠x2 → f(x1)≠f(x2))
f : R->R, f(x) =4x-1 f:N→N,f(x)=5x but f(x)= is not 1:1 or f(x)=|x| is not 1:1 and g(x)=|x-2| as (4,2) and (0,2)exists
Surjective / Onto function
A function f:A→B is surjective (onto) if each element in the codomain is an image of some preimage or if image of f= its
range. Equivalently, for every b∈B, there exists some a∈A such that f(a)=b. This means that for any y in B, there exists
some x in A such that y=f(x).
Consider, A = {1, 2, 3, 4}, B = {a, b, c} and f = {(1, b), (2, a), (3, c), (4, c)}. In an Onto Function, Range is equal to Co-
Domain.
Eg: h:{1,2,3}→{1,2,3}, h is surjective. Every element of the codomain is also in the range. Nothing in the codomain is
missed.
• Bijective (One-to-One Onto) Functions: A function which is both injective (one to - one) and surjective (onto) is called
bijective (One-to-One Onto) Function. Bijection also called one-to-one correspondence or invertible function

• Consider P = {x, y, z} Q = {a, b, c} and f: P → Q such that


f = {(x, a), (y, b), (z, c)}
• f(x)=2x-3, f(x)=
• The function f(x)=x+1 from the set of integers to itself is onto. Is it True or False?
• True, For every integer “y” there is an integer “x ” such that f(x) = y.
• Into Functions: A function in which there must be an element of co-domain Y does not have a pre-image in domain X.
Example: Consider, A = {a, b, c} B = {1, 2, 3, 4} and f: A → B such that f = {(a, 1), (b, 2), (c, 3)}
In the function f, the range i.e., {1, 2, 3} ≠ co-domain of Y i.e., {1, 2, 3, 4}

• One-One Into Functions: Let f: X → Y. The function f is called one-one into function if different elements of X have different unique
images of Y.
Example: Consider, X = {k, l, m} Y = {1, 2, 3, 4} and f: X → Y such that f = {(k, 1), (l, 3), (m, 4)}
• Many-One Functions: Let f: X → Y. The function f is said to be many-one functions if there exist two or more than two different
elements in X having the same image in Y.
Example: Consider X = {1, 2, 3, 4, 5} Y = {x, y, z} and f: X → Y such that f = {(1, x), (2, x), (3, x), (4, y), (5, z)}

• Many-One Into Functions: Let f: X → Y. The function f is called the many-one function if and only if is both many one and into
function.
Example: Consider X = {a, b, c} Y = {1, 2} and f: X → Y such that f = {(a, 1), (b, 1), (c, 1)}
As the function f is a many-one and into, so it is a many-one into function.
Many-One Onto Functions: Let f: X → Y. The function f is called many-one onto function if and only if is both many one and onto.
Example: Consider X = {1, 2, 3, 4} Y = {k, l} and f: X → Y such that f = {(1, k), (2, k), (3, l), (4, l)}
The function f is a many-one (as the two elements have the same image in Y) and it is onto (as every element of Y is the image of
some element X). So, it is many-one onto function

Identity Functions-The function f is called the identity function if each element of set A has an image on itself i.e. f (a) = a ∀ a ∈ A. It
is denoted by I.
Example: Consider, A = {1, 2, 3, 4, 5} and f: A → A such that f = {(1, 1), (2, 2), (3, 3), (4, 4), (5, 5)}. The function f is an identity
function as each element of A is mapped onto itself. The function f is a one-one and onto
Invertible (Inverse) Functions
A function f: X → Y is invertible if and only if it is a bijective function.
Consider the bijective (one to one onto) function f: X → Y. As f is a one to one, therefore, each element of X corresponds to a distinct
element of Y. As f is onto, there is no element of Y which is not the image of any element of X, i.e., range = co-domain Y.
The inverse function for f exists if is a function from Y to X.
Example: Consider, X = {1, 2, 3} Y = {k, l, m} and f: X→Y such that f = {(1, k), (2, m), (3, l)

The inverse function of f is shown in fig:


If |A|=m elements and |B|=n elements then number of functions possible from A to B=
2*2*2=8 options

A:
B:
a
1
b
2
c

• Suppose X and Y are sets |X| and |Y| are their respective cardinalities. It is given that there are exactly 97 functions
from X to Y then find their cardinalitites?
A. |X|=1 and |Y|=97 =
B. |X|=97 and |Y|=97
C. |X|=97 and |Y|=1
D. None
• Let X, Y, Z be sets of sizes x, y and z respectively. Let W = X x Y. Let E be the set of all subsets of W. The number of functions from Z
to E is:
(A)z2xy
(B)zx2xy
(C)z2x+y
(D) 2xyz

Sol: |X|=x |Y|=y |Z|=z


W=X*Y. Since E E be the set of all subsets of W=> E=P(W)
Z->E elements???
If any set |A|=n elements the P(W)=
So W=X*Y=x*y then E has
Now Z->E if Z has z elements and E has then no. of functions = =
• Let S denote the set of all functions f: -> {0,1}. Denote by N the number of functions from S to the set {0,1}. The value of is ______.
=strings of length 2(00,01,10,11)……….
f: -> {0,1}.

16 2 S=
Denote by N the number of functions from S to the set {0,1}.
S->{0,1} = =N
is ______ compared with =16
Function Composition
Let f and g be two relations such that rng f ⊆ dom g. Then, the composition of f and g, denoted by gof, is defined as gof = {(x, z) : (x, y)
∈ f and (y, z) ∈ g for some y ∈ rng f ⊆ dom g
• function composition is an operation that takes two functions f and g and produces a function h such that h(x) = g(f(x)). In this
operation, the function g is applied to the result of applying the function f to x. That is, the functions f : X → Y and g : Y → Z are
composed to yield a function that maps x in X to g(f(x)) in Z.

• f(x)=y and g(y)=z => g(f(x))=z => gof(x)=z


• fog(x)=f(g(x))
• gof(x)=g(f(x))
Composition of functions on a finite set: If f = {(1, 1), (2, 3), (3, 1), (4, 2)}, and g = {(1, 2), (2, 3), (3, 1), (4, 2)}, then g ∘ f = {(1, 2), (2, 1),
(3, 2), (4, 3)}
• Composition of functions on an infinite set: If f: ℝ → ℝ (where ℝ is the set of all real numbers) is given by f(x) = 2x + 4 and g: ℝ →
ℝ is given by g(x) =, then:
(f ∘ g)(x) = f(g(x)) = f(x3) = 2 + 4, and
(g ∘ f)(x) = g(f(x)) = g(2x + 4) =

g(x)=1-x and h(x)=

= 1-=

==
===

• Let f and g be the functions from the set of integers defined by f(x)=2x+3 and g(x)=3x+2. Then the composition of f and g and g and
f is given as
1. 6x+7, 6x+11
2. 6x+11, 6x+7
3. 5x+5, 5x+5
4. None of the above
Let f and g be the functions from the set of integers defined by f(x)=2x+3 and g(x)=3x+2. Then the composition of f and g
f(g(x))=2(3x+2)+3= 6x+4+3=6x+7
g(f(x))=3(2x+3)+2=6x+9+2=6x+11
Mathematical Functions
1. Floor Functions: The floor function for any real number x is defined as f (x) is the greatest integer 1 less than or equal to x. It is
denoted by [x].
Example: Determine the value of (i)[3. 5] (ii)[-2.4] (iii)[3. 143].
(i)[3 . 5] = 3
(ii) [-2 .4] = -3
(iii) [3. 143] = 3
2. Ceiling Functions: The ceiling function for any real number x is defined as h (x) is the smallest integer greater than or equal to x. It is
denoted by [x].
Example: Determine the value of (i)[3. 5] (ii) [-2.4] (iii) [3. 143].
(i)[3. 5] = 4
(ii) [-2 .4] = -2
(iii) [3. 143] = 4.
3. Remainder Functions: The integer remainder is obtained when some a is divided by m. It is denoted by a (MOD m). We can also define
it as, a (MOD m) is the unique integer t such that a = Mq + t. Here q is quotient 0 ≤ r < M.
Example: Determine the value of the following:
(i) 35 (MOD 7) (ii) 20 (MOD 3) (iii) 4 (MOD 9)
(i) 35 (MOD 7) = 0
(ii) 20 (MOD 3) = 2
(iii) 4 (MOD 9) = 4
4. Exponential Functions: Consider two sets A and B. Let A = B = I+ and also let f: A → B be defined by f (n) =. Here n is a +ve integer. The
function f is called the base k exponential function.
Example: Determine the value of the following: (i) 103 (ii) 51/2 (iii) 3-5
= 10. 10. 10 = 1000
=2.23607
==
Logarithmic Functions: Consider two sets A and B. Let A = B = R (the set of real numbers and also let f_n:A→B be defined for each
positive integer n > 1 as (x)=(x) the base n of x.

Note1: k = (x) and are equivalent.


2. For any base n, 1=0 as =1.
3. For any base n, n=1 as =n.
Example: Determine the value of the following: (i)16 (ii) 100 (iii) 0.001.
(i) 16 = 4 as =16.
(100 = 6 as = 64 but =128 which is greater
(iii) 0.001.=-9 as =but =which is greater.
Probability
The word 'Probability' means the chance of occurring of a particular event. It is generally possible to predict the future of an event
quantitatively with a certain probability of being correct. The probability is used in such cases where the outcome of the trial is
uncertain.
Probability Definition:
The probability of happening of an event A, denoted by P(A), is defined as

Thus, if an event can happen in m ways and fails to occur in n ways and m+n ways is equally likely to occur then the probability of
happening of the event A is given by

And the probability of non-happening of A is

Note:
The probability of an event which is certain to occur is one.
The probability of an event which is impossible to zero.
If the probability of happening of an event P(A) and that of not happening is P(A), then
P(A)+ P() = 1, 0 ≤ P(A) ≤ 1,0≤ P()≤1.
What is the probability of throwing a 5 with a dice?
The number of favorable outcomes = 1 (there is only one 5 on a dice)
The number of possible outcomes = 6 (a dice has 6 sides)
P(5)=≈0.167
Important Terms related to Probability:
1. Trial and Event: The performance of an experiment is called a trial, and the set of its outcomes is termed an event. Example: Tossing
a coin and getting head is a trial. Then the event is {HT, TH, HH}.
2. Random Experiment: It is an experiment in which all the possible outcomes of the experiment are known in advance. But the exact
outcomes of any specific performance are not known in advance.
Example:
Tossing a Coin, Rolling a die, Drawing a card from a pack of 52 cards, Drawing a ball from a bag.
3. Outcome: The result of a random experiment is called an Outcome.
Example: 1. Tossing a coin is an experiment and getting head is called an outcome.
2. Rolling a die and getting 6 is an outcome.
4. Sample Space: The set of all possible outcomes of an experiment is called sample space and is denoted by S.
Example: When a die is thrown, sample space is S = {1, 2, 3, 4, 5, 6}
It consists of six outcomes 1, 2, 3, 4, 5, 6
Note1: If a die is rolled n times the total number of outcomes will be
5. Impossible Events: An event which will never be happened.
Example1: Tossing double-headed coins and getting tails in an impossible event.
Example2: Rolling a die and getting number > 10 in an impossible outcome. P (impossible outcome) =0
• Sure Outcome/Certain Outcome: An Outcome which will definitely be happen
Example1: Tossing double-headed coins and getting heads only.
Example2: Rolling a die and getting number < 7
P (sure outcome) = 1
{1, 2, 3, 4, 5 6} is called sure event
• Possible Outcome: An outcome which is possible to occur is called Possible Outcome.
Example1: Tossing a fair coin and getting a head on it.
Example2: Rolling a die and getting an odd number.
• Equally Likely Events: Events are said to be equally likely if one of them cannot be expected to occur in preference to others. In other
words, it means each outcome is as likely to occur as any other outcome.
Example: When a die is thrown, all the six faces, i.e., 1, 2, 3, 4, 5 and 6 are equally likely to occur.
• Mutually Exclusive or Disjoint Events: Events are called mutually exclusive if they cannot occur simultaneously.
Example: Suppose a card is drawn from a pack of cards, then the events getting a jack and getting a king are mutually exclusive because
they cannot occur simultaneously.
• Independent Events: Events A and B are said to be independent if the occurrence of any one event does not affect the occurrence of
any other event. P (A ∩ B) = P (A) P (B).
Example: A coin is tossed thrice, and all 8 outcomes are equally likely
A: "The first throw results in heads."
B: "The last throw results in Tails.“ Prove that event A and B are independent.
Theorem1: If A and B are two mutually exclusive events, then
P(A ∪B)=P(A)+P(B)
Proof: Let the n=total number of exhaustive cases
n1= number of cases favorable to A.
n2= number of cases favorable to B.
Now, we have A and B two mutually exclusive events. Therefore, n1+n2 is the number of cases favorable to A or B.

Example: Two dice are tossed once. Find the probability of getting an even number on first dice or a total of 8.
An even number can be got on a die in 3 ways because any one of 2, 4, 6, can come. The other die can have any number. This can happen
in 6 ways.
∴ P (an even number on Ist die and any number on other is) = 3*6/36=18/36=1/2
A total of 8 can be obtained in the following cases:
{(2,6),(3,5),(4,4),(5,3),(6,2)}
∴ P (a total of 8) =5/36
Total Probability= 1/2+5/36=23/36
If one has two dice, what is the probability of throwing a 5 with the first dice and a 6 with the other dice?
P(5)=1/6
P(6)=1/6
P(5and6)=P(5)⋅P(6)=1/6⋅1/6=1/36

We toss a coin, either heads or tails might turn up, but not heads and tails at the same time.
If A and B are mutually exclusive events then we determine the probability of A happening or the probability of B happening with the
following formula:
P(AorB)=P(A)+P(B)
If the events are inclusive, e.g. both can happen but not at the same time, then we use the following formula to determine the
probability that either A or B occurs:
P(AorB)=P(A)+P(B)−P(AandB)

• A coin is thrown 3 times .what is the probability that atleast one head is obtained?
Sample space = [HHH, HHT, HTH, THH, TTH, THT, HTT, TTT]
Total number of ways = 2 × 2 × 2 = 8. Fav. Cases = 7
P (A) = 7/8
OR
P (of getting at least one head) = 1 – P (no head)⇒ 1 – (1/8) = 7/8
Find the probability of getting a numbered card when a card is drawn from the pack of 52 cards.
Sol: Total Cards = 52. Numbered Cards = (2, 3, 4, 5, 6, 7, 8, 9, 10) 9 from each suit 4 × 9 = 36
P (E) = 36/52 = 9/13
• There are 5 green 7 red balls. Two balls are selected one by one without replacement. Find the probability that first is green and
second is red.
Sol: P (G) × P (R) = (5/12) x (7/11) = 35/132
• What is the probability of getting a sum of 7 when two dice are thrown?
Sol: Probability math - Total number of ways = 6 × 6 = 36 ways. Favorable cases = (1, 6) (6, 1) (2, 5) (5, 2) (3, 4) (4, 3) --- 6 ways.
P (A) = 6/36 = 1/6
• 1 card is drawn at random from the pack of 52 cards.
(i) Find the Probability that it is an honor card.
(ii) It is a face card.
Sol: (i) honor cards = (A, J, Q, K) 4 cards from each suits = 4 × 4 = 16
P (honor card) = 16/52 = 4/13
(ii) face cards = (J,Q,K) 3 cards from each suit = 3 × 4 = 12 Cards.
P (face Card) = 12/52 = 3/13
• Two cards are drawn from the pack of 52 cards. Find the probability that both are diamonds or both are kings.
Sol: Total no. of ways = 52C2
Case I: Both are diamonds = 13C2
Case II: Both are kings = 4C2
P (both are diamonds or both are kings) = (13C2 + 4C2 ) / 52C2
• Three dice are rolled together. What is the probability as getting at least one '4'?
Sol: Total number of ways = 6 × 6 × 6 = 216. Probability of getting number ‘4’ at least one time
= 1 – (Probability of getting no number 4) = 1 – (5/6) x (5/6) x (5/6) = 91/216
• A vessel contains 4 blue balls, 5 red balls and 11 white balls. If three balls are drawn from the vessel at random, what is the
probability that the first ball is red, the second ball is blue, and the third ball is white?
Solution: The probability to get the first ball is red or the first event is 5/20.
Now, since we have drawn a ball for the first event to occur, then the number of possibilities left for the second event to occur is 20
– 1 = 19.
Hence, the probability of getting the second ball as blue or the second event is 4/19.
Again with the first and second event occurred, the number of possibilities left for the third event to occur is 19 – 1 = 18.
And the probability of the third ball is white or third event is 11/18.
Therefore, the probability is 5/20 x 4/19 x 11/18 = 44/1368 = 0.032.
Or we can express it as P = 3.2%.
• Two dice are rolled, find the probability that the sum is:
equal to 1
equal to 4
less than 13
1) To find the probability that the sum is equal to 1 we have to first determine the sample space S of two dice as shown below.
S={(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(2,1),(2,2),(2,3),(2,4),(2,5),(2,6),(3,1),(3,2),(3,3),(3,4),(3,5),(3,6),(4,1),(4,2),(4,3),(4,4),(4,5),
(4,6),(5,1),(5,2),(5,3),(5,4),(5,5),(5,6), (6,1),(6,2),(6,3),(6,4),(6,5),(6,6) }
1) Let E be the event “sum equal to 1”. Since, there are no outcomes which where a sum is equal to 1, hence,
P(E) = n(E) / n(S) = 0 / 36 = 0
2) Three possible outcomes give a sum equal to 4 they are:
E = {(1,3),(2,2),(3,1)}
Hence, P(E) = n(E) / n(S) = 3 / 36 = 1 / 12
3) From the sample space, we can see all possible outcomes for the evenr E, which give a sum less than 13. Like:
(1,1) or (1,6) or (2,6) or (6,6).
So you can see the limit of an event to occur is when both dies have number 6, i.e. (6,6).
P(E) = n(E) / n(S) = 36 / 36 = 1
• Probability of an Event
Assume an event E can occur in r ways out of a sum of n probable or possible equally likely ways. Then the probability
of happening of the event or its success is expressed as;
P(E) = r/n
The probability that the event will not occur or known as its failure is expressed as:
P(E’) = (n-r)/n = 1-(r/n)
E’ represents that the event will not occur.
Therefore, now we can say;
P(E) + P(E’) = 1
This means that the total of all the probabilities in any random test or experiment is equal to 1.
• What are Equally Likely Events?
When the events have the same theoretical probability of happening, then they are called equally likely events. The
results of a sample space are called equally likely if all of them have the same probability of occurring. For example, if
you throw a die, then the probability of getting 1 is 1/6. Similarly, the probability of getting all the numbers from
2,3,4,5 and 6, one at a time is 1/6. Hence, the following are some examples of equally likely events when throwing a
die:
Getting 3 and 5 on throwing a dice
Getting an even number and an odd number on a dice
are equally likely events, since the probabilities of each event are equal.
Find the mean and mode of the following data: 2, 3, 5, 6, 10, 6, 12, 6, 3, 4.
Sol: Total Count: 10
Sum of all the numbers: 2+3+5+6+10+6+12+6+3+7=60
Mean = (sum of all the numbers)/(Total number of items)
Mean = 60/10 = 6
Again, Number 6 is occurring for 3 times, therefore Mode = 6. Answer
• A bucket contains 5 blue, 4 green and 5 red balls. X is asked to pick 2 balls randomly from the bucket without
replacement and then one more ball is to be picked. What is the probability he picked 2 green balls and 1 blue ball?
Solution: Total number of balls = 14
Probability of drawing
1 green ball = 4/14
another green ball = 3/13
1 blue ball = 5/12
Probability of picking 2 green balls and 1 blue ball = 4/14 * 3/13 * 5/12 = 5/182.
• What is the probability that Ram will choose a marble at random and that it is not black if the bowl contains 3 red, 2
black and 5 green marbles.
Solution: Total number of marble = 10
Red and Green marbles = 8
Find the number of marbles that are not black and divide by the total number of marbles.
So P(not black) = (number of red or green marbles)/(total number of marbles)
= 8 /10
= 4/5
• Find the mean of the following data:
55, 36, 95, 73, 60, 42, 25, 78, 75, 62
Solution: Sum of observations = 55 + 36 + 95 + 73 + 60 + 42 + 25 + 78 + 75 + 62 = 601
Number of observations = 10
Mean = 601/10 = 60.1
• Find the median and mode of the following marks (out of 10) obtained by 20 students:
4, 6, 5, 9, 3, 2, 7, 7, 6, 5, 4, 9, 10, 10, 3, 4, 7, 6, 9, 9
Solution Ascending order: 2, 3, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 9, 9, 9, 9, 10, 10
Number of observations = n = 20
Median = (10th + 11th observation)/2
= (6 + 6)/2
=6
Most frequent observations = 9
Hence, the mode is 9.
• What is the probability that a card taken from a standard deck, is an Ace?
Total number of cards a standard pack contains = 52
Number of Ace cards in a deck of cards = 4
So, the number of favorable outcomes = 4
Probability of selecting an ace from a deck is,
P(Ace) = (Number of favorable outcomes) / (Total number of favorable outcomes)
P(Ace) = 4/52
= 1/13
So we can say that the probability of getting an ace is 1/13.
• Calculate the probability of getting an odd number if a dice is rolled.
Sample space (S) = {1, 2, 3, 4, 5, 6} n(S) = 6
Let “E” be the event of getting an odd number, E = {1, 3, 5} n(E) = 3
So, the Probability of getting an odd number is:
P(E) = (Number of outcomes favorable)/(Total number of outcomes)
= n(E)/n(S)
= 3/6

• Compute the probability of the occurrence of an event if the probability the event not occurring is 0.56.
Solution: Given, P(not E) = 0.56
We know that, P(E) + P(not E) = 1
So, P(E) = 1 – P(not E)
P(E) = 1 – 0.56
Or, P(E) = 0.44
• Compute the probability of the occurrence of an event if the probability the event not occurring is 0.56.
Given, P(not E) = 0.56
We know that, P(E) + P(not E) = 1
So, P(E) = 1 – P(not E)
P(E) = 1 – 0.56 Or, P(E) = 0.44
• From a deck of cards, 10 cards are picked at random and shuffled. The cards are as follows:
6, 5, 3, 9, 7, 6, 4, 2, 8, 2 Find the probability of picking a card having value more than 5 and find the probability of
picking a card with an even number on it.
Solution: Total number of cards = 10
Total cards having value more than 5 = 5 i.e. {6, 9, 7, 6, 8}
Total cards having an even number = 6 i.e. {6, 6, 4, 2, 8, 2}
So, the probability of picking a card having value more than 5 = 5/10 = 0.5
And, the probability of picking a card with an even number on it = 6/10 = 0.6
GRAPH THEORY
• Graph Theory is a relatively new area of mathematics, first studied by the super famous mathematician Leonhard Euler in 1735.
• A graph is a set of points, called nodes or vertices, which are interconnected by a set of lines called edges.
• Definition − A graph (denoted as G=(V,E)) consists of a non-empty set of vertices or nodes V and a set of edges E.
Example − Let us consider, a Graph is G=(V,E) where V={a,b,c,d} and E={{a,b},{a,c},{b,c},{c,d}}

Characteristics of graphs:
1. Adjacent node: A node ‘v’ is said to be adjacent node of node ‘u’ if and only if there exists an edge between ‘u’ and ‘v’.
2. Degree of a node/vertex: In an undirected graph the number of nodes incident on a node is the degree of the node.’
3. Vertex Degree Even / Odd
a 2 even
b 2 even
c 3 odd
d 1 odd
Even and Odd Vertex − If the degree of a vertex is even, the vertex is called an even vertex and if the degree of a vertex is odd, the
vertex is called an odd vertex.
4. Degree of a Graph − The degree of a graph is the largest vertex degree of that graph. For the above graph the degree of the
graph is 3.
• Undirected graph(unordered pair ) An undirected graph is graph, i.e., a set of objects (called vertices or nodes) that are connected
together, where all the edges are bidirectional. An undirected graph is sometimes called an undirected network.
• In contrast, a graph where the edges point in a direction is called a Directed Graph(ordered pair).

In a directed graph direction matters. i.e. edge V2->V3 means that edge is directed. There is only an edge from V2 to V3 and no edge
from V3 to V2. Therefore you can go from vertex V2 to vertex V3 but not from V3 to V2.
In undirected graph V2-V3 means the edge has no direction, i.e. V2-V3 means you can go both from V2 to V3 and V3 to V2.
• Cyclic & acyclic graphs
Before going over the what cyclic and acyclic graphs are, there are two key terms to cover: path and cycle. A path is a sequence of
vertices connected by edges and a cycle a path whose first and last vertices are the same.
A cyclic graph means that there contains a least one cycle within the graph.
An acyclic graph has no cycles within it.
A commonly used phrase when referring to graphs is a directed acylic graph (DAG), which is a directed graph in which there are no
cycles. In a DAG, these two terms are commonly used to denote nodes with special properties:

Sink nodes have no outgoing edges, only incoming edges


Source nodes only have outgoing edges, no incoming edges
• Adjacent Vertex- If two vertex are joined by the same edge( example- a and b are adjacent, a & c, c&d, b &d)
• Adjacent Edge- If two edges are incident on same vertex. (ac and ab are adjacent edges, ab & bd,…)

• Self Loop: Edge having same vertex(Vi,Vi) as its end vertices


• Parallel Edges: More than one edges are associated with same pair of vertices
• Path: A path of length ‘n’ from node ‘u’ to node ‘v’ is defined as sequence of n+1 nodes.
P(u,v)=(v0,v1,v2,v3…….vn)
• A path is simple if all the nodes are distinct, exception is source and destination are same.
• Isolated node/vertex : A node with degree 0 is known as isolated node. Isolated node can be found by Breadth first
search(BFS).
• In undirected graphs, edge (u, v) same as (v, u)
• A directed edge (arc) is an ordered pair (u, v) (i.e., (u, v) not same as (v, u))
• A directed graph is a graph with directed edges. Directed graph is also known as digraphs.
• The in-degree of a vertex v, written deg−(v), is the number of edges going into v deg−(a) =1
• The out-degree of a vertex v, written deg+(v), is the number of edges leaving v deg+(a) =1
• The Handshaking Lemma − In a graph, the sum of all the degrees of all the vertices is equal to twice the number of
edges.
• In case of directed graph ,In degree of the node is the number of arriving edges to a node.
• Out degree of the node is the number of departing edges to a node.
Handshaking Lemma/Sum-of-degree
• The Handshaking Lemma − In a graph, the sum of all the degrees of all the vertices is equal to twice the
number of edges
• +
• A graph contains 21 edges and 3 vertices of degree 4 and all other vertices of degree 2. find total
number of vertices.
|E|=21

1
3*4+(n-3)*2=42
12+2n-6=42
2n=36
n=18
• A simple graph G has 24 edges and degree of each vertex is 4. Find the number of vertices.
Number of edges = 24
Degree of each vertex = 4
Let number of vertices in the graph = n.
Sum of degree of all vertices = 2 x Number of edges
Substituting the values, we get-
n x 4 = 2 x 24
n=2x6
∴ n = 12
• A graph contains 21 edges, 3 vertices of degree 4 and all other vertices of degree 2. Find total number of vertices.
Number of edges = 21
Number of degree 4 vertices = 3
All other vertices are of degree 2
Let number of vertices in the graph = n.
Sum of degree of all vertices = 2 x Number of edges
Substituting the values, we get-
3 x 4 + (n-3) x 2 = 2 x 21
12 + 2n – 6 = 42
2n = 42 – 6
2n = 36
∴ n = 18
• A simple graph contains 35 edges, four vertices of degree 5, five vertices of degree 4 and four vertices of degree 3. Find the number
of vertices with degree 2.
Number of edges = 35
Number of degree 5 vertices = 4
Number of degree 4 vertices = 5
Number of degree 3 vertices = 4
Let number of degree 2 vertices in the graph = n.
Sum of degree of all vertices = 2 x Number of edges
Substituting the values, we get-
4 x 5 + 5 x 4 + 4 x 3 + n x 2 = 2 x 35
20 + 20 + 12 + 2n = 70
52 + 2n = 70
2n = 70 – 52
2n = 18
∴n=9
Thus, Number of degree 2 vertices in the graph = 9.
• A graph has 24 edges and degree of each vertex is k, then which of the following is possible number of vertices?
20 15 10 8
Number of edges = 24
Degree of each vertex = k
Let number of vertices in the graph = n.
Using Handshaking Theorem, we have-
Sum of degree of all vertices = 2 x Number of edges
Substituting the values, we get-
n x k = 2 x 24
k = 48 / n
Now,
It is obvious that the degree of any vertex must be a whole number.
So in the above equation, only those values of ‘n’ are permissible which gives the whole value of ‘k’.
Now, let us check all the options one by one-
For n = 20, k = 2.4 which is not allowed.
For n = 15, k = 3.2 which is not allowed.
For n = 10, k = 4.8 which is not allowed.
For n = 8, k = 6 which is allowed.
Thus, Option (D) is correct.

The following conclusions may be drawn from the Handshaking Theorem.

In any graph,

The sum of degree of all the vertices is always even.


The sum of degree of all the vertices with odd degree is always even.
The number of vertices with odd degree are always even.
1. The two vertices u and v are end vertices of the edge (u, v).
2. Edges that have the same end vertices are parallel.
3. An edge of the form (v, v) is a loop.
4. A graph is simple if it has no parallel edges or loops.
5. A graph with no edges (i.e. E is empty) is empty.
6. A graph with no vertices (i.e. V and E are empty) is a null graph.
7. A graph with only one vertex is trivial.
8. Edges are adjacent if they share a common end vertex.
9. Two vertices u and v are adjacent if they are connected by an edge, in other words, (u, v) is an edge.
10. The degree of the vertex v, written as d(v), is the number of edges with v as an end vertex.
By convention, we count a loop twice and parallel edges contribute separately.
11. A pendant vertex is a vertex whose degree is 1.
12. An edge that has a pendant vertex as an end vertex is a pendant edge.
13. An isolated vertex is a vertex whose degree is 0.
• v4 and v5 are end vertices of e5.
• e4 and e5 are parallel.
• e3 is a loop.
• The graph is not simple.
• e1 and e2 are adjacent.
• v1 and v2 are adjacent.
• The degree of v1 is 1 so it is a pendant vertex.
• e1 is a pendant edge.
• The degree of v5 is 5.
• The degree of v4 is 2.
• The degree of v3 is 0 so it is an isolated vertex
The minimum degree of the vertices in a graph G is denoted δ(G) (= 0 if there is an isolated vertex in G). Similarly, we
write ∆(G) as the maximum degree of vertices in G.
Example: δ(G) = 0 and ∆(G) = 5.
Types of Graph
1. Null Graph- A null graph has no edges. In this vertex set is non-empty but edge set is empty. The null graph of n vertices is
denoted by 𝑁_𝑛

2. Trivial Graph- A trivial graph is the graph which has only one vertex and edge set is empty. It is the smallest possible graph.
Example- there is only one vertex 'v' without any edge. Therefore, it is a trivial graph

3. Non-Directed Graph-
A graph in which all the edges are undirected is called as a non-directed graph. In other words, edges of an undirected graph do not
contain any direction.
• Directed Graph- A graph in which all the edges are directed is called as a directed graph. In other words, all the edges of a
directed graph contain some direction. Directed graphs are also called as digraphs.

• Connected Graph- A graph in which we can visit from any one vertex to any other vertex is called as a connected graph. In
connected graph, at least one path exists between every pair of vertices.

• Disconnected Graph- A graph in which there does not exist any path between at least one pair of vertices is called as a
disconnected graph.
• Regular Graph- A graph in which degree of all the vertices is same is called as a regular graph. If all the vertices in a
graph are of degree ‘k’, then it is called as a “k-regular graph“. Every null graph is a regular graph of degree zero and
a complete graph Kn is a regular graph of degree n-1.

• Complete Graph- A graph in which exactly one edge is present between every pair of vertices is called as a complete
graph. A complete graph of ‘n’ vertices contains exactly nC2 edges. A complete graph of ‘n’ vertices is represented as
An undirected complete graph G=(V,E) of n vertices is a graph in which each vertex is connected to every other
vertex i.e., and edge exist between every pair of distinct vertices. It is denoted by 𝑘_ 𝑛. A complete graph with n
vertices will (𝑛(𝑛−1))⁄(2 )edges. A graph is called complete graph if every two vertices pair are joined by exactly
one edge. Every vertex is connected to n-1 vertices.
• Cyclic Graph- A simple graph of ‘n’ vertices (n>=3) and n edges forming a cycle of length ‘n’ is called as a cycle graph. In a cycle
graph, all the vertices are of degree 2.

• Acyclic Graph- A graph not containing any cycle in it is called as an acyclic graph

• Bipartite Graph- A bipartite graph is a graph where-


 Vertices can be divided into two sets X and Y.
 The vertices of set X only join with the vertices of set Y.
 None of the vertices belonging to the same set join each other.
Here,
The vertices of the graph can be decomposed into two sets. The two sets are X = {A, C} and Y = {B, D}. The vertices of set X join only
with the vertices of set Y and vice-versa. The vertices within the same set do not join. Therefore, it is a bipartite graph.
• A graph G=(V,E) is bipartite if the vertex set V can be partitioned into two subsets V1 and V2 such that every edge in E connects a
vertex in V1 and a vertex in V2 ( no edge in G connects either two vertices in V1 or two vertices in V2) is called a bipartite graph.
A bipartite graph can have no loop.
• Complete Bipartite Graph- A complete bipartite graph may be defined as follows-
A bipartite graph where every vertex of set X is joined to every vertex of set Y is called as complete bipartite graph.
OR
Complete bipartite graph is a bipartite graph which is complete.
OR
Complete bipartite graph is a graph which is bipartite as well as complete.

Here,

This graph is a bipartite graph as well as a complete graph.


Therefore, it is a complete bipartite graph.
This graph is called as K4,3.
• Planar Graph- A planar graph is a graph that we can draw in a plane such that no two edges of it cross each other.

• Regions of Plane- The planar representation of the graph splits the plane into connected areas called as Regions of the plane.
Each region has some degree associated with it given as-
• Degree of Interior region = Number of edges enclosing that region
• Degree of Exterior region = Number of edges exposed to that region
Here, this planar graph splits the plane into 4 regions- R1, R2, R3 and R4 where-

Degree (R1) = 3
Degree (R2) = 3
Degree (R3) = 3
Degree (R4) = 5
• Simple Graph- A graph is called simple graph/strict graph if the graph is undirected and does not contain any loops or parallel
edges. A simple graph which has n vertices, the degree of every vertex is at most n -1.

• Multigraph: If in a graph multiple edges between the same set of vertices are allowed, it is known as Multigraph. In other words, it
is a graph having at least one loop or multiple edges.

• Pseudo Graph- A graph having no parallel edges but having self loop(s) in it is called as a pseudo graph.
• Euler Graph- Euler Graph is a connected graph in which all the vertices are even degree.

• Hamiltonian Graph- If there exists a closed walk in the connected graph that visits every vertex of the graph exactly once (except
starting vertex) without repeating the edges, then such a graph is called as a Hamiltonian graph.

This graph contains a closed walk ABCDEFG that visits all the vertices (except starting vertex) exactly once. All the vertices are visited
without repeating the edges. Therefore, it is a Hamiltonian Graph.
Types of Graphs
• Null Graph- A null graph has no edges.
• In this vertex set is non-empty but edge set is empty.
• The null graph of n vertices is denoted by
• Simple Graph- A graph is called simple graph/strict graph if the graph is undirected and does not contain any loops or parallel
edges. A simple graph which has n vertices, the degree of every vertex is at most n -1.

• Trivial Graph- A trivial graph is the graph which has only one vertex and edge set is empty.
Example- In the above graph, there is only one vertex 'v' without any edge. Therefore, it is a trivial graph.
• Multigraph: If in a graph multiple edges between the same set of vertices are allowed, it is known as Multigraph. In other words, it
is a graph having at least one loop or multiple edges.
Self Loop Parallel Edge
Multigraph N Y
Pseudo graph Y N
Simple graph N N
Graph Y Y

Important Points-

Edge set of a graph can be empty but vertex set of a graph can not be empty.
Every polygon is a 2-Regular Graph.
Every complete graph of ‘n’ vertices is a (n-1)-regular graph.
Every regular graph need not be a complete graph.
Planar Graph- Planar graph is a graph that can be drawn in a plane such that none of its edges cross each other.
Planar Graph Properties-
Property-01: In any planar graph, Sum of degrees of all the vertices = 2 x Total number of edges in the graph

Property-02: In any planar graph, Sum of degrees of all the regions = 2 x Total number of edges in the graph

Special Cases

Case-01: In any planar graph, if degree of each region is K, then-


K x |R| = 2 x |E|
Case-02: In any planar graph, if degree of each region is at least K (>=K), then-
K x |R| <= 2 x |E|
Case-03: In any planar graph, if degree of each region is at most K (<=K), then-
K x |R| >= 2 x |E|
If G is a connected planar simple graph with ‘e’ edges, ‘v’ vertices and ‘r’ number of regions in the planar representation of G, then-
r = e – v + 2. This is known as Euler’s Formula.
If G is a planar graph with k components, then-
r = e – v + (k + 1)
PRACTICE PROBLEMS BASED ON PLANAR GRAPH IN GRAPH THEORY-
Problem-01: Let G be a connected planar simple graph with 25 vertices and 60 edges. Find the number of regions in G.
Number of vertices (v) = 25
Number of edges (e) = 60
By Euler’s formula, we know r = e – v + 2.
Substituting the values, we get-
Number of regions (r)
= 60 – 25 + 2
= 37
Thus, Total number of regions in G = 37.
Problem-02: Let G be a planar graph with 10 vertices, 3 components and 9 edges. Find the number of regions in G.
Number of vertices (v) = 10
Number of edges (e) = 9
Number of components (k) = 3
By Euler’s formula, we know r = e – v + (k+1)
Substituting the values, we get- Number of regions (r)
= 9 – 10 + (3+1)
= -1 + 4
=3
Thus, Total number of regions in G = 3.
Problem-03: Let G be a connected planar simple graph with 20 vertices and degree of each vertex is 3. Find the
number of regions in G.
Number of vertices (v) = 20
Degree of each vertex (d) = 3
Calculating Total Number Of Edges (e)-
By sum of degrees of vertices theorem, we have-
Sum of degrees of all the vertices = 2 x Total number of edges
Number of vertices x Degree of each vertex = 2 x Total number of edges
20 x 3 = 2 x e
∴ e = 30
Thus, Total number of edges in G = 30.
Calculating Total Number Of Regions (r)-
By Euler’s formula, we know r = e – v + 2.
Substituting the values, we get
Number of regions (r)
= 30 – 20 + 2
= 12
Thus, Total number of regions in G = 12.
Problem-04: Let G be a connected planar simple graph with 35 regions, degree of each region is 6. Find the number
of vertices in G.
Number of regions (n) = 35
Degree of each region (d) = 6
Calculating Total Number Of Edges (e)-
By sum of degrees of regions theorem, we have-
Sum of degrees of all the regions = 2 x Total number of edges
Number of regions x Degree of each region = 2 x Total number of edges
35 x 6 = 2 x e
∴ e = 105
Thus, Total number of edges in G = 105.
Calculating Total Number Of Vertices (v)-
By Euler’s formula, we know r = e – v + 2.
Substituting the values, we get-
35 = 105 – v + 2
∴ v = 72
Problem-05: Let G be a connected planar graph with 12 vertices, 30 edges and degree of each region is k. Find the value
of k.
Number of vertices (v) = 12
Number of edges (e) = 30
Degree of each region (d) = k
Calculating Total Number Of Regions (r)-
By Euler’s formula, we know r = e – v + 2.
Substituting the values, we get-
Number of regions (r)
= 30 – 12 + 2
= 20
Thus, Total number of regions in G = 20.
Calculating Value Of k- By sum of degrees of regions theorem, we have-
Sum of degrees of all the regions = 2 x Total number of edges
Number of regions x Degree of each region = 2 x Total number of edges
20 x k = 2 x 30
∴k=3
Thus, Degree of each region in G = 3.
Problem-06: What is the maximum number of regions possible in a simple planar graph with 10 edges?
In a simple planar graph, degree of each region is >= 3. So, we have 3 x |R| <= 2 x |E|.
Substituting the value |E| = 10, we get-
3 x |R| <= 2 x 10
|R| <= 6.67
|R| <= 6
Thus, Maximum number of regions in G = 6.
Problem-07: What is the minimum number of edges necessary in a simple planar graph with 15 regions?
In a simple planar graph, degree of each region is >= 3.
So, we have 3 x |R| <= 2 x |E|.
Substituting the value |R| = 15, we get-
3 x 15 <= 2 x |E|
|E| >= 22.5
|E| >= 23
Thus, Minimum number of edges required in G = 23.
Walk in Graph Theory | Path | Trail | Cycle | Circuit
• A walk is defined as a finite length alternating sequence of vertices and edges.
• The total number of edges covered in a walk is called as Length of the Walk.
• Walk can repeat anything (edges or vertices).

In this graph, few examples of walk are-


a,b,c,e,d (Length = 4)
d , b , a , c , e , d , e , c (Length = 7)
e,c,b,a,c,e,d (Length = 6)

Open Walk in Graph Theory- In graph theory, a walk is called as an Open walk if-
• Length of the walk is greater than zero
• And the vertices at which the walk starts and ends are different.
Closed Walk in Graph Theory- In graph theory, a walk is called as a Closed walk if-
• Length of the walk is greater than zero
• And the vertices at which the walk starts and ends are same.
1->2->3->4->5->3-> is an open walk.
1->2->3->4->5->3->1-> is a closed walk.
NOTE
It is important to note the following points-
If length of the walk = 0, then it is called as a Trivial Walk.
Both vertices and edges can repeat in a walk whether it is an open walk or a closed walk.
2. Trail –
Trail is an open walk in which no edge is repeated.
Vertex can be repeated
Here 1->3->8->6->3->2 is trail
Also 1->3->8->6->3->2->1 will be a closed trail

3. Circuit –
Traversing a graph such that not an edge is repeated but vertex can be repeated and it is closed also i.e. it is a closed
trail.
Vertex can be repeated
Edge not repeated
Here 1->2->4->3->6->8->3->1 is a circuit

Circuit is a closed trail.


These can have repeated vertices only.
4. Path –
It is a trail in which neither vertices nor edges are repeated i.e. if we traverse a graph such that we do not repeat a
vertex and nor we repeat an edge. As path is also a trail, thus it is also an open walk.
Vertex not repeated
Edge not repeated
Here 6->8->3->1->2->4 is a Path

5. Cycle –
Traversing a graph such that we do not repeat a vertex nor we repeat a edge but the starting and ending vertex must
be same i.e. we can repeat starting and ending vertex only then we get a cycle.
Vertex not repeated
Edge not repeated
Here 1->2->4->3->1 is a cycle.

Cycle is a closed path.


These can not have repeat anything (neither edges nor vertices).
PRACTICE PROBLEMS BASED ON WALK IN GRAPH THEORY-Decide which of the following sequences of vertices
determine walks.

For those that are walks, decide whether it is a circuit, a path, a cycle or a trail.
1. a , b , g , f , c , b
2. b , g , f , c , b , g , a
3. c , e , f , c
4. c , e , f , c , e
5. a , b , f , a
6. f , d , e , c , b

1. Trail
2. Walk
3. Cycle
4. Walk
5. Not a walk
6. Path
Consider the following sequences of vertices and answer the questions that follow-
a) x , v , y , w , v
b) x , u , x , u , x
c) x , u , v , y , x
d) x , v , y , w , v , u , x
Which of the above given sequences are directed walks?
What are the lengths of directed walks?
Which directed walks are also directed paths?
Which directed walks are also directed cycles?
Part-01:
Only (A) and (B) are the directed walks.
(C) is not a directed walk since there exists no arc from vertex u to vertex v.
(D) is not a directed walk since there exists no arc from vertex v to vertex u.
Part-02:
Both the directed walks (A) and (B) have length = 4.
Part-03:
Neither (A) nor (B) are directed paths.
This is because vertices repeat in both of them.
Vertex v repeats in Walk (A) and vertex u repeats in walk (B).
Part-04:
Neither of them are directed cycles.
Walk (A) does not represent a directed cycle because its starting and ending vertices are not same.
Walk (B) does not represent a directed cycle because it repeats vertices/edges.
Observe the given sequences and predict the nature of walk in each case-
1. v1e1v2e2v3e2v2
2. v4e7v1e1v2e2v3e3v4e4v5
3. v1e1v2e2v3e3v4e4v5
4. v1e1v2e2v3e3v4e7v1
5. V6e5v5e4v4e3v3e2v2e1v1e7v4e6v6

Solution-
6. Open walk
7. Trail (Not a path because vertex v4 is repeated)
8. Path
9. Cycle
10. Circuit (Not a cycle because vertex v4 is repeated)
Euler Graph | Euler Path | Euler Circuit
Any connected graph is called as an Euler Graph if and only if all its vertices are of even degree.
OR
An Euler Graph is a connected graph that contains an Euler Circuit.
Euler Graph Example-

Euler Path-Euler path is also known as Euler Trail or Euler Walk.


If there exists a Trail in the connected graph that contains all the edges of the graph, then that trail is called as an Euler
trail.
OR
If there exists a walk in the connected graph that visits every edge of the graph exactly once with or without repeating
the vertices, then such a walk is called as an Euler walk.
NOTE
A graph will contain an Euler path if and only if it contains at most two vertices of odd degree.
Euler Circuit- Euler circuit is also known as Euler Cycle or Euler
Tour.
If there exists a Circuit in the connected graph that contains all the
edges of the graph, then that circuit is called as an Euler circuit.
OR
If there exists a walk in the connected graph that starts and ends
at the same vertex and visits every edge of the graph exactly once
with or without repeating the vertices, then such a walk is called
as an Euler circuit.
OR
An Euler trail that starts and ends at the same vertex is called as
an Euler circuit.
OR
A closed Euler trail is called as an Euler circuit.

NOTE
A graph will contain an Euler circuit if and only if all its vertices
are of even degree.
Semi-Euler Graph-
If a connected graph contains an Euler trail but does not
contain an Euler circuit, then such a graph is called as a
semi-Euler graph.
Thus, for a graph to be a semi-Euler graph, following two
conditions must be satisfied-
Graph must be connected.
Graph must contain an Euler trail.

This graph contains an Euler trail BCDBAD.


But it does not contain an Euler circuit.
Therefore, it is a semi-Euler graph.
Note-01: To check whether any graph is an Euler graph or not, any one of the following two ways may be used-
If the graph is connected and contains an Euler circuit, then it is an Euler graph.
If all the vertices of the graph are of even degree, then it is an Euler graph.

Note-02: To check whether any graph contains an Euler circuit or not,


Just make sure that all its vertices are of even degree.
If all its vertices are of even degree, then graph contains an Euler circuit otherwise not.

Note-03: To check whether any graph is a semi-Euler graph or not,


Just make sure that it is connected and contains an Euler trail.
If the graph is connected and contains an Euler trail, then graph is a semi-Euler graph otherwise not.

Note-04: To check whether any graph contains an Euler trail or not,


Just make sure that the number of vertices in the graph with odd degree are not more than 2.
If the number of vertices with odd degree are at most 2, then graph contains an Euler trail otherwise not.

Note-05: A graph will definitely contain an Euler trail if it contains an Euler circuit.
A graph may or may not contain an Euler circuit if it contains an Euler trail.
Which of the following is / are Euler Graphs?

A) It is an Euler graph.

B) It is not an Euler graph.

C) It is not an Euler graph.

D) It is not an Euler graph.

E) It is an Euler graph.

F) It is not an Euler graph.


Hamiltonian Graph | Hamiltonian Path | Hamiltonian Circuit
A Hamiltonian graph may be defined as-
If there exists a closed walk in the connected graph that visits every vertex of the graph exactly once (except starting
vertex) without repeating the edges, then such a graph is called as a Hamiltonian graph.
OR
Any connected graph that contains a Hamiltonian circuit is called as a Hamiltonian Graph.
The following graph is an example of a Hamiltonian graph-

Here,

This graph contains a closed walk ABCDEFA.


It visits every vertex of the graph exactly once except starting vertex.
The edges are not repeated during the walk.
Therefore, it is a Hamiltonian graph.
Alternatively, there exists a Hamiltonian circuit ABCDEFA in the above graph, therefore it is a Hamiltonian graph.
Hamiltonian Path- If there exists a walk in the connected graph that visits every vertex of the graph exactly once without repeating the
edges, then such a walk is called as a Hamiltonian path.
OR
If there exists a Path in the connected graph that contains all the vertices of the graph, then such a path is called as a Hamiltonian path.
NOTE: In Hamiltonian path, all the edges may or may not be covered but edges must not repeat.
Hamiltonian Circuit- Hamiltonian circuit is also known as Hamiltonian Cycle.
If there exists a walk in the connected graph that visits every vertex of the graph exactly once (except starting vertex) without
repeating the edges and returns to the starting vertex, then such a walk is called as a Hamiltonian circuit.
OR
If there exists a Cycle in the connected graph that contains all the vertices
of the graph, then that cycle is called as a Hamiltonian circuit.
OR
A Hamiltonian path which starts and ends at the same vertex is
called as a Hamiltonian circuit.
OR
A closed Hamiltonian path is called as a Hamiltonian circuit.
Important Notes-
Any Hamiltonian circuit can be converted to a Hamiltonian path by removing one of its edges.
Every graph that contains a Hamiltonian circuit also contains a Hamiltonian path but vice versa is not true.
There may exist more than one Hamiltonian paths and Hamiltonian circuits in a graph.
Which of the following is / are Hamiltonian graphs?
A) The graph neither contains a Hamiltonian path nor it contains a
Hamiltonian circuit, therefore It is not a Hamiltonian Graph.

B) The graph neither contains a Hamiltonian path nor it contains a


Hamiltonian circuit, therefore It is not a Hamiltonian Graph.

C) The graph contains both a Hamiltonian path (ABCDHGFE) and a


Hamiltonian circuit (ABCDHGFEA), therefore It is a Hamiltonian
Graph.

D) The graph contains both a Hamiltonian path (ABCDEFG) and a


Hamiltonian circuit (ABCDEFGA). Since graph contains a
Hamiltonian circuit, therefore It is a Hamiltonian Graph.

E) The graph neither contains a Hamiltonian path nor it contains a


Hamiltonian circuit , therefore It is not a Hamiltonian Graph.

F) The graph contains both a Hamiltonian path (ABCDEFGHI) and a


Hamiltonian circuit (ABCDEFGHIA). Since graph contains a
Hamiltonian circuit, therefore It is a Hamiltonian Graph.
Bipartite Graph | Bipartite Graph Example | Properties
A bipartite graph is a special kind of graph with the following properties-
1. It consists of two sets of vertices X and Y.
2. The vertices of set X join only with the vertices of set Y.
3. The vertices within the same set do not join.

Here,
The vertices of the graph can be decomposed into two sets.
The two sets are X = {A, C} and Y = {B, D}.
The vertices of set X join only with the vertices of set Y and vice-versa.
The vertices within the same set do not join.
Therefore, it is a bipartite graph.
Complete Bipartite Graph- A bipartite graph where every vertex of set X is joined to every vertex of set Y is called as
complete bipartite graph.
OR
Complete bipartite graph is a bipartite graph which is complete.
OR
Complete bipartite graph is a graph which is bipartite as well as complete.
Here,
• This graph is a bipartite graph as well as a complete graph.
• Therefore, it is a complete bipartite graph.
• This graph is called as K4,3.
Bipartite Graph Chromatic Number- To properly color any bipartite graph, Minimum 2 colors are required. This
ensures that the end vertices of every edge are colored with different colors. Thus, bipartite graphs are 2-colorable. If
graph is bipartite with no edges, then it is 1-colorable.
Bipartite Graph Properties-
1. Bipartite graphs are 2-colorable.
2. Bipartite graphs contain no odd cycles.
3. Every sub graph of a bipartite graph is itself bipartite.
4. In any bipartite graph with bipartition X and Y,
Sum of degree of vertices of set X = Sum of degree of vertices of set Y
Maximum Number Of Edges-
Any bipartite graph consisting of ‘n’ vertices can have at most edges.

Problem-01:Is the following graph a bipartite graph?

Here,

This graph consists of two sets of vertices.


The two sets are X = {1, 4, 6, 7} and Y = {2, 3, 5, 8}.
The vertices of set X are joined only with the vertices of set Y and
vice-versa.
Also, any two vertices within the same set are not joined.
This satisfies the definition of a bipartite graph.
Therefore, Given graph is a bipartite graph.
Problem-02: The maximum number of edges in a bipartite graph on 12 vertices is _________?
Solution- We know, Maximum possible number of edges in a bipartite graph on ‘n’ vertices =
Substituting n = 12, we get-
Maximum number of edges in a bipartite graph on 12 vertices
= (1/4) x = (1/4) x 12 x 12 = 36
Therefore, Maximum number of edges in a bipartite graph on 12 vertices = 36.

Konigsberg Bridge Problem in Graph Theory


Konigsberg is the former name of a German city that is now in Russia.
The following picture shows the inner city of Konigsberg with the river Pregel.
The river Pregel divides the city into four land areas A, B, C and D.
In order to travel from one part of the city to another, there exists seven bridges.
Konigsberg Bridge Problem may be stated as-
“Starting from any of the four land areas A, B, C, D, is it possible to cross each of the seven bridges exactly once
and come back to the starting point without swimming across the river?”
Konigsberg Bridge Problem Solution-In 1735, A Swiss Mathematician Leon hard Euler solved this problem. He provided
a solution to the problem and finally concluded that such a walk is not possible.
Euler represented the given situation using a graph as shown below-

In this graph,
Vertices represent the landmasses.
Edges represent the bridges.
Start from any vertex, without repeating edges, end at the same vertex.
Euler observed that when a vertex is visited during the process of tracing a graph,
There must be one edge that enters into the vertex.
There must be another edge that leaves the vertex.
Therefore, order of the vertex must be an even number.
Based on this observation, Euler discovered that it depends on the number of odd vertices present in the network
whether any network is traversable or not.
Euler found that only those networks are traversable that have either-
No odd vertices (then any vertex may be the beginning and the same vertex will also be the ending point)
Or exactly two odd vertices (then one odd vertex will be the starting point and other odd vertex will be the ending point)
Now,
Since the Konigsberg network has four odd vertices, therefore the network is not traversable. Thus, It was finally
concluded that the desired walking tour of Konigsberg is not possible.
NOTE- If the citizens of Konigsberg decides to build an eighth bridge from A to C, then-
It would be possible to walk without traversing any bridge twice.
This is because then there will be exactly two odd vertices.
However, adding a ninth bridge will again make the walking tour once again impossible.

Complement Of Graph-Complement of a simple graph G is a simple graph G’ having-


All the vertices of G.
An edge between two vertices v and w iff there exists no edge between v and w in the original graph G.
Relationship Between G & G’-
1. Number of vertices in G = Number of vertices in G’.
|V(G)| = |V(G’)|
2. The sum of total number of edges in G and G’ is equal to the total number of edges in a complete graph.
|E(G)| + |E(G’)|
= C(n,2)
= n(n-1) / 2
where n = total number of vertices in the graph
Important Terms-
Order of graph = Total number of vertices in the graph
Size of graph = Total number of edges in the graph

Problem-01: A simple graph G has 10 vertices and 21 edges. Find total number of edges in its complement graph G’.
Solution-
Number of edges in graph G, |E(G)| = 21
Number of vertices in graph G, n = 10
We know |E(G)| + |E(G’)| = n(n-1) / 2.
Substituting the values, we get-
21 + |E(G’)| = 10 x (10-1) / 2
|E(G’)| = 45 – 21
∴ |E(G’)| = 24
Thus, Number of edges in complement graph G’ = 24.
• A simple graph G has 30 edges and its complement graph G’ has 36 edges. Find number of vertices in G.
Solution-
Number of edges in graph G, |E(G)| = 30 Number of edges in graph G’, |E(G’)| = 36
We know |E(G)| + |E(G’)| = n(n-1) / 2.
Substituting the values, we get-
30 + 36 = n(n-1) / 2
n(n-1) = 132
n2 – n – 132 = 0
Solving this quadratic equation, we get n = 12.
Thus, Number of vertices in graph G = 12.
• Let G be a simple graph of order n. If the size of G is 56 and the size of G’ is 80. What is n?
Size of a graph = Number of edges in the graph.
Number of edges in graph G, |E(G)| = 56
Number of edges in graph G’, |E(G’)| = 80
We know |E(G)| + |E(G’)| = n(n-1) / 2.
Substituting the values, we get-
56 + 80 = n(n-1) / 2
n(n-1) = 272
n2 – n – 272 = 0
Solving this quadratic equation, we get n = 17.
Thus, Number of vertices in graph G = 17. In other words, Order of graph G = 17.
Graph Coloring-Graph Coloring is a process of assigning colors to the vertices of a graph such that no two adjacent
vertices of it are assigned the same color.
Graph Coloring is also called as Vertex Coloring.
It ensures that there exists no edge in the graph whose end vertices are colored with the same color.
Such a graph is called as a Properly colored graph.
Graph Coloring Applications-
1. Map Coloring
2. Scheduling the tasks
3. Preparing Time Table
4. Sudoku
Chromatic Number- Chromatic Number is the minimum number of colors required to properly color any graph.
OR
Chromatic Number is the minimum number of colors required to color any graph such that no two adjacent vertices of it
are assigned the same color.
Chromatic Number Example-
5. No two adjacent vertices are colored with the same color.
6. Minimum number of colors required to properly color the vertices = 3.
7. Therefore, Chromatic number of this graph = 3.
8. We can not properly color this graph with less than 3 colors.
Chromatic Number Of Graphs-
1. Cycle Graph- A simple graph of ‘n’ vertices (n>=3) and ‘n’ edges forming a cycle of length ‘n’ is called as a cycle
graph. In a cycle graph, all the vertices are of degree 2.
Chromatic Number
If number of vertices in cycle graph is even, then its chromatic number = 2.
If number of vertices in cycle graph is odd, then its chromatic number = 3.
2. Planar Graphs- A Planar Graph is a graph that can be drawn in a plane such that none of its edges cross each other.
Chromatic Number of any Planar Graph = Less than or equal to 4
3. Complete Graphs- A complete graph is a graph in which every two distinct vertices are joined by exactly one edge. In a
complete graph, each vertex is connected with every other vertex. So to properly it, as many different colors are needed
as there are number of vertices in the given graph.
Chromatic Number of any Complete Graph = Number of vertices in that Complete Graph
4. Bipartite Graphs- A Bipartite Graph consists of two sets of vertices X and Y. The edges only join vertices in X to
vertices in Y, not vertices within a set.
Chromatic Number of any Bipartite Graph = 2
5. Trees- A Tree is a special type of connected graph in which there are no circuits.
Every tree is a bipartite graph. So, chromatic number of a tree with any number of vertices = 2.
Chromatic Number of any tree = 2
How to Find Chromatic Number | Graph Coloring Algorithm
•Graph Coloring is a process of assigning colors to the vertices of a graph.
•It ensures that no two adjacent vertices of the graph are colored with the same color.
•Chromatic Number is the minimum number of colors required to properly color any graph.
Graph Coloring Algorithm-
There exists no efficient algorithm for coloring a graph with minimum number of colors. Graph Coloring is a NP
complete problem. However, a following greedy algorithm is known for finding the chromatic number of any given
graph.
Greedy Algorithm-
Step-01: Color first vertex with the first color.
Step-02: Now, consider the remaining (V-1) vertices one by one and do the following-
• Color the currently picked vertex with the lowest numbered color if it has not been used to color any of its adjacent
vertices.
• If it has been used, then choose the next least numbered color.
• If all the previously used colors have been used, then assign a new color to the currently picked vertex.
Drawbacks of Greedy Algorithm-
There are following drawbacks of the above Greedy Algorithm-
•The above algorithm does not always use minimum number of colors.
•The number of colors used sometimes depend on the order in which the vertices are processed.
Problem-01: Find chromatic number of the following graph-

Applying Greedy Algorithm, we have-


Vertex a b c d e f
Color C1 C2 C1 C2 C1 C2
From here,
Minimum number of colors used to color the given graph are 2.
Therefore, Chromatic Number of the given graph = 2.
Find chromatic number of the following graph-

Applying Greedy Algorithm, we have-


Vertex a b c d e f
Color C1 C2 C2 C3 C3 C1
From here,
• Minimum number of colors used to color the given graph are 3.
• Therefore, Chromatic Number of the given graph = 3.
Solution-
Applying Greedy Algorithm, we have-
Vertex a b c d e f g
Color C1 C2 C1 C3 C2 C3 C4
From here,
• Minimum number of colors used to color the given graph are 4.
• Therefore, Chromatic Number of the given graph = 4.
Graph Isomorphism- Graph Isomorphism is a phenomenon of existing the same graph in more than one forms. Such
graphs are called as Isomorphic graphs.
Graph Isomorphism Conditions-
For any two graphs to be isomorphic, following 4 conditions must
be satisfied-
Number of vertices in both the graphs must be same.
Number of edges in both the graphs must be same.
Degree sequence of both the graphs must be same.
If a cycle of length k is formed by the vertices { v1 , v2 , ….. , vk } in
one graph, then a cycle of same length k must be formed by the
vertices { f(v1) , f(v2) , ….. , f(vk) } in the other graph as well.
• Degree Sequence
Degree sequence of a graph is defined as a sequence of the degree
of all the vertices in ascending order.
Important Points-
The above 4 conditions are just the necessary conditions for any
two graphs to be isomorphic.
They are not at all sufficient to prove that the two graphs are
isomorphic.
If all the 4 conditions satisfy, even then it can’t be said that the
graphs are surely isomorphic.
However, if any condition violates, then it can be said that the
graphs are surely not isomorphic.
Applying Greedy Algorithm,

Minimum number of colors required to color the given graph are 3.


Therefore, Chromatic Number of the given graph = 3.
Sufficient Conditions-
The following conditions are the sufficient conditions to prove any two graphs isomorphic. If any one of these
conditions satisfy, then it can be said that the graphs are surely isomorphic.
1. Two graphs are isomorphic if and only if their complement graphs are isomorphic.
2. Two graphs are isomorphic if their adjacency matrices are same.
3. Two graphs are isomorphic if their corresponding sub-graphs obtained by deleting some vertices of one graph and
their corresponding images in the other graph are isomorphic.

Are the following two graphs isomorphic?


Checking Necessary Conditions
Condition-01:
Number of vertices in graph G1 = 4
Number of vertices in graph G2 = 4
Here,
Both the graphs G1 and G2 have same number of vertices.
So, Condition-01 satisfies.
Condition-02:
Number of edges in graph G1 = 5
Number of edges in graph G2 = 6
Here,
Both the graphs G1 and G2 have different number of edges. So, Condition-02 violates.
Since Condition-02 violates, so given graphs can not be isomorphic.
∴ G1 and G2 are not isomorphic graphs.
Which of the following graphs are isomorphic?

Condition-01:
Number of vertices in graph G1 = 4 Number of vertices in graph G2 = 4 Number of vertices in graph G3 = 4
Here, All the graphs G1, G2 and G3 have same number of vertices. So, Condition-01 satisfies.
Condition-02:
Number of edges in graph G1 = 5 Number of edges in graph G2 = 5 Number of edges in graph G3 = 4
Here, The graphs G1 and G2 have same number of edges. So, Condition-02 satisfies for the graphs G1 and G2.
However, the graphs (G1, G2) and G3 have different number of edges. So, Condition-02 violates for the graphs (G1, G2)
and G3.
Since Condition-02 violates for the graphs (G1, G2) and G3, so they can not be isomorphic. ∴ G3 is neither isomorphic
to G1 nor G2.
Since Condition-02 satisfies for the graphs G1 and G2, so they may be isomorphic.
∴ G1 may be isomorphic to G2.
Now, let us continue to check for the graphs G1 and G2.
Condition-03:
Degree Sequence of graph G1 = { 2 , 2 , 3 , 3 } Degree Sequence of graph G2 = { 2 , 2 , 3 , 3 }
Here, Both the graphs G1 and G2 have same degree sequence. So, Condition-03 satisfies.
Condition-04:
Both the graphs contain two cycles each of length 3 formed by the vertices having degrees { 2 , 3 , 3 }.It means both the
graphs G1 and G2 have same cycles in them. So, Condition-04 satisfies.
Thus,
All the 4 necessary conditions are satisfied.
So, graphs G1 and G2 may be isomorphic.
Now, let us check the sufficient condition.
Checking Sufficient Condition-
We know that two graphs are surely isomorphic if and only if their complement graphs are isomorphic. So, let us draw
the complement graphs of G1 and G2.

Clearly, Complement graphs of G1 and G2 are isomorphic.


∴ Graphs G1 and G2 are isomorphic graphs.
Graph Representation
By Graph representation, we simply mean the technique which is to be used in order to store some graph into the
computer's memory.
1. Sequential Representation
In sequential representation, we use adjacency matrix to store the mapping represented by vertices and edges. In
adjacency matrix, the rows and columns are represented by the graph vertices. A graph having n vertices, will have a
dimension n x n.
An entry Mij in the adjacency matrix representation of an undirected graph G will be 1 if there exists an edge between Vi
and Vj. An undirected graph and its adjacency matrix representation is shown in the following figure.

in the above figure, we can see the mapping among the vertices (A, B, C, D, E) is represented by using the adjacency
matrix which is also shown in the figure.
There exists different adjacency matrices for the directed and undirected graph. In directed graph, an entry Aij will be 1
only when there is an edge directed from Vi to Vj.
A directed graph and its adjacency matrix representation is shown in the following figure.

Representation of weighted directed graph is different. Instead of filling the entry by 1, the Non- zero entries of the
adjacency matrix are represented by the weight of respective edges.
The weighted directed graph along with the adjacency matrix representation is shown in the following figure.
Linked Representation
In the linked representation, an adjacency list is used to store the Graph into the computer's memory.
Consider the undirected graph shown in the following figure and check the adjacency list representation.

An adjacency list is maintained for each node present in the graph which stores the node value and a pointer to the next
adjacent node to the respective node. If all the adjacent nodes are traversed then store the NULL in the pointer field of
last node of the list. The sum of the lengths of adjacency lists is equal to the twice of the number of edges present in an
undirected graph.
In a directed graph, the sum of lengths of all the adjacency lists is equal to the number of edges present in the graph.
In the case of weighted directed graph, each node contains an extra field that is called the weight of the node. The
adjacency list representation of a directed graph is shown in the following figure.
Graph Traversal Algorithm- Traversing the graph means examining all the nodes and vertices of the graph. There are two
standard methods by using which, we can traverse the graphs. Lets discuss each one of them in detail.
• Breadth First Search
• Depth First Search
Breadth First Search (BFS) Algorithm
Breadth first search is a graph traversal algorithm that starts traversing the graph from root node and explores all the
neighboring nodes. Then, it selects the nearest node and explore all the unexplored nodes. The algorithm follows the same
process for each of the nearest node until it finds the goal.
The algorithm starts with examining the node A and all of its neighbors. In the next step, the neighbors of the nearest node of
A are explored and process continues in the further steps. The algorithm explores all neighbors of all the nodes and ensures
that each node is visited exactly once and no node is visited twice.
Step 1: SET STATUS = 1 (ready state)
for each node in G
Step 2: Enqueue the starting node A
and set its STATUS = 2 (waiting state)
Step 3: Repeat Steps 4 and 5 until
QUEUE is empty
Step 4: Dequeue a node N. Process it
and set its STATUS = 3 (processed state).
Step 5: Enqueue all the neighbors of
N that are in the ready state
(whose STATUS = 1) and set
their STATUS = 2 (waiting state)
[END OF LOOP]
Step 6: EXIT
Consider the graph G shown in the following image, calculate the minimum path p from node A to node E. Given that each
edge has a length of 1.

Minimum Path P can be found by applying breadth first search algorithm that will begin at node A and will end at E. the
algorithm uses two queues, namely QUEUE1 and QUEUE2. QUEUE1 holds all the nodes that are to be processed while
QUEUE2 holds all the nodes that are processed and deleted from QUEUE1.
Lets start examining the graph from Node A.
1. Add A to QUEUE1 and NULL to QUEUE2.
QUEUE1 = {A} QUEUE2 = {NULL}
2. Delete the Node A from QUEUE1 and insert all its neighbors. Insert Node A into QUEUE2
QUEUE1 = {B, D} QUEUE2 = {A}
3. Delete the node B from QUEUE1 and insert all its neighbors. Insert node B into QUEUE2.
QUEUE1 = {D, C, F} QUEUE2 = {A, B}
4. Delete the node D from QUEUE1 and insert all its neighbors. Since F is the only neighbor of it which has been
inserted, we will not insert it again. Insert node D into QUEUE2.
QUEUE1 = {C, F} QUEUE2 = { A, B, D}
5. Delete the node C from QUEUE1 and insert all its neighbors. Add node C to QUEUE2.
QUEUE1 = {F, E, G} QUEUE2 = {A, B, D, C}
6. Remove F from QUEUE1 and add all its neighbors. Since all of its neighbors has already been added, we will not add
them again. Add node F to QUEUE2.
QUEUE1 = {E, G} QUEUE2 = {A, B, D, C, F}
7. Remove E from QUEUE1, all of E's neighbours has already been added to QUEUE1 therefore we will not add them
again. All the nodes are visited and the target node i.e. E is encountered into QUEUE2.
QUEUE1 = {G} QUEUE2 = {A, B, D, C, F, E}
Now, backtrack from E to A, using the nodes available in QUEUE2.
The minimum path will be A → B → C → E.
Depth First Search (DFS) Algorithm
Depth first search (DFS) algorithm starts with the initial node of the graph G, and then goes to deeper and deeper until
we find the goal node or the node which has no children. The algorithm, then backtracks from the dead end towards the
most recent node that is yet to be completely unexplored.
The data structure which is being used in DFS is stack. The process is similar to BFS algorithm. In DFS, the edges that
leads to an unvisited node are called discovery edges while the edges that leads to an already visited node are called
block edges.
Algorithm
Step 1: SET STATUS = 1 (ready state) for each node in G
Step 2: Push the starting node A on the stack and set its STATUS = 2 (waiting state)
Step 3: Repeat Steps 4 and 5 until STACK is empty
Step 4: Pop the top node N. Process it and set its STATUS = 3 (processed state)
Step 5: Push on the stack all the neighbors of N that are in the ready state (whose STATUS = 1) and set their
STATUS = 2 (waiting state)
[END OF LOOP]
Step 6: EXIT
Consider the graph G along with its adjacency list, given in the figure below. Calculate the order to print all the nodes of
the graph starting from node H, by using depth first search (DFS) algorithm.
Push H onto the stack STACK : H
POP the top element of the stack i.e. H, print it and push all the neighbors of H onto the stack that are is ready state. Print H
STACK : A
Pop the top element of the stack i.e. A, print it and push all the neighbors of A onto the stack that are in ready state. Print A
Stack : B, D
Pop the top element of the stack i.e. D, print it and push all the neighbors of D onto the stack that are in ready state. Print D
Stack : B, F
Pop the top element of the stack i.e. F, print it and push all the neighbors of F onto the stack that are in ready state. Print F
Stack : B
Pop the top of the stack i.e. B and push all the neighbors Print B
Stack : C
Pop the top of the stack i.e. C and push all the neighbors. Print C
Stack : E, G
Pop the top of the stack i.e. G and push all its neighbors. Print G
Stack : E
Pop the top of the stack i.e. E and push all its neighbors. Print E
Stack :
Hence, the stack now becomes empty and all the nodes of the graph have been traversed.
The printing sequence of the graph will be :
H→A→D→F→B→C→G→E
Travelling Salesman Problem-
You are given-
• A set of some cities
• Distance between every pair of cities
Travelling Salesman Problem states-
• A salesman has to visit every city exactly once.
• He has to come back to the city from where he starts his journey.
• What is the shortest possible route that the salesman must follow to complete his tour?
If salesman starting city is A, then a TSP tour in the graph is-
A→B→D→C→A
Cost of the tour
= 10 + 25 + 30 + 15
= 80 units
PRACTICE PROBLEM BASED ON TRAVELLING SALESMAN PROBLEM USING BRANCH AND BOUND APPROACH
Step-01: Write the initial cost matrix and reduce it-
Rules
To reduce a matrix, perform the row reduction and column reduction of the matrix separately.
A row or a column is said to be reduced if it contains at least one entry ‘0’ in it.
Row Reduction-
Consider the rows of above matrix one by one.
If the row already contains an entry ‘0’, then-
There is no need to reduce that row.
If the row does not contains an entry ‘0’, then-
Reduce that particular row.
Select the least value element from that row.
Subtract that element from each element of that row.
This will create an entry ‘0’ in that row, thus reducing that row.
Following this, we have-
Reduce the elements of row-1 by 4.
Reduce the elements of row-2 by 5.
Reduce the elements of row-3 by 6.
Reduce the elements of row-4 by 2.
Column Reduction- Consider the columns of above row-reduced matrix one by one.
If the column already contains an entry ‘0’, then-
There is no need to reduce that column.
If the column does not contains an entry ‘0’, then-
Reduce that particular column.
Select the least value element from that column.
Subtract that element from each element of that column.
This will create an entry ‘0’ in that column, thus reducing that column.
Following this, we have-
There is no need to reduce column-1.
There is no need to reduce column-2.
Reduce the elements of column-3 by 1.
There is no need to reduce column-4.

Finally, the initial distance matrix is completely reduced.


Now, we calculate the cost of node-1 by adding all the reduction elements.
Cost(1-vertex A)
= Sum of all reduction elements
=4+5+6+2+1
= 18
Step-02: We consider all other vertices one by one.
We select the best vertex where we can land upon to minimize the tour cost.
Choosing To Go To Vertex-B: Node-2 (Path A → B)
• From the reduced matrix of step-01, M[A,B] = 0(note A,B entry from reduce matrix)
• Set row-A and column-B to ∞
• Set M[B,A] = ∞
Now, resulting cost matrix is-
Now,
We reduce this matrix.
Then, we find out the cost of node-02.
Row Reduction-
We can not reduce row-1 as all its elements are ∞.
Reduce all the elements of row-2 by 13.
There is no need to reduce row-3.
There is no need to reduce row-4.
Performing this, we obtain the following row-reduced matrix-

Column Reduction-
Reduce the elements of column-1 by 5.
We can not reduce column-2 as all its elements are ∞.
There is no need to reduce column-3.
There is no need to reduce column-4.
Performing this, we obtain the following column-reduced matrix-
Finally, the matrix is completely reduced.
Now, we calculate the cost of node-2.
Cost(2)
= Cost(1) + Sum of reduction elements + M[A,B]
= 18 + (13 + 5) + 0
= 36
Choosing To Go To Vertex-C: Node-3 (Path A → C)
From the reduced matrix of step-01, M[A,C] = 7
Set row-A and column-C to ∞
Set M[C,A] = ∞
Now, resulting cost matrix is-

Now,
We reduce this matrix.
Then, we find out the cost of node-03.
Row Reduction-
We can not reduce row-1 as all its elements are ∞.
There is no need to reduce row-2.
There is no need to reduce row-3.
There is no need to reduce row-4.
Thus, the matrix is already row-reduced.
Column Reduction-
There is no need to reduce column-1.
There is no need to reduce column-2.
We can not reduce column-3 as all its elements are ∞.
There is no need to reduce column-4.
Thus, the matrix is already column reduced.
Finally, the matrix is completely reduced.
Now, we calculate the cost of node-3.
Cost(3)
= Cost(1) + Sum of reduction elements + M[A,C]
= 18 + 0 + 7
= 25
Choosing To Go To Vertex-D: Node-4 (Path A → D)
From the reduced matrix of step-01, M[A,D] = 3
Set row-A and column-D to ∞
Set M[D,A] = ∞
Now, resulting cost matrix is-

Row Reduction-
We can not reduce row-1 as all its elements are ∞.
There is no need to reduce row-2.
Reduce all the elements of row-3 by 5.
There is no need to reduce row-4.
Performing this, we obtain the following row-reduced matrix-
Column Reduction-
There is no need to reduce column-1.
There is no need to reduce column-2.
There is no need to reduce column-3.
We can not reduce column-4 as all its elements are ∞.
Thus, the matrix is already column-reduced.
Finally, the matrix is completely reduced.
Now, we calculate the cost of node-4.
Cost(4)
= Cost(1) + Sum of reduction elements + M[A,D]
= 18 + 5 + 3
= 26
Thus, we have-
Cost(2) = 36 (for Path A → B)
Cost(3) = 25 (for Path A → C)
Cost(4) = 26 (for Path A → D)
We choose the node with the lowest cost.
Since cost for node-3 is lowest, so we prefer to visit node-3.
Thus, we choose node-3 i.e. path A → C.
Step-03:
We explore the vertices B and D from node-3.
We now start from the cost matrix at node-3 which is-
Choosing To Go To Vertex-B: Node-5 (Path A → C → B)
From the reduced matrix of step-02, M[C,B] = ∞
Set row-C and column-B to ∞
Set M[B,A] = ∞
Now, resulting cost matrix is-

Now,
We reduce this matrix.
Then, we find out the cost of node-5.
Row Reduction-
We can not reduce row-1 as all its elements are ∞.
Reduce all the elements of row-2 by 13.
We can not reduce row-3 as all its elements are ∞.
Reduce all the elements of row-4 by 8.
Column Reduction-
There is no need to reduce column-1.
We can not reduce column-2 as all its elements are ∞.
We can not reduce column-3 as all its elements are ∞.
There is no need to reduce column-4.
Thus, the matrix is already column reduced.
Finally, the matrix is completely reduced.
Now, we calculate the cost of node-5.
Cost(5)
= cost(3) + Sum of reduction elements + M[C,B]
= 25 + (13 + 8) + ∞
=∞
Choosing To Go To Vertex-D: Node-6 (Path A → C → D)
From the reduced matrix of step-02, M[C,D] = ∞
Set row-C and column-D to ∞
Set M[D,A] = ∞
Now, resulting cost matrix is-
Now, We reduce this matrix. Then, we find out the cost of node-6.
Row Reduction-
We can not reduce row-1 as all its elements are ∞.
There is no need to reduce row-2.
We can not reduce row-3 as all its elements are ∞.
We can not reduce row-4 as all its elements are ∞.
Thus, the matrix is already row reduced.
Column Reduction-
There is no need to reduce column-1.
We can not reduce column-2 as all its elements are ∞.
We can not reduce column-3 as all its elements are ∞.
We can not reduce column-4 as all its elements are ∞.
Thus, the matrix is already column reduced.
Finally, the matrix is completely reduced.
Now, we calculate the cost of node-6.
Cost(6)
= cost(3) + Sum of reduction elements + M[C,D]
= 25 + 0 + 0
= 25
Thus, we have-
Cost(5) = ∞ (for Path A → C → B)
Cost(6) = 25 (for Path A → C → D)
We choose the node with the lowest cost.
Since cost for node-6 is lowest, so we prefer to visit node-6.
Thus, we choose node-6 i.e. path C → D.
Step-04: We explore vertex B from node-6. We start with the cost matrix at node-6 which is-

Choosing To Go To Vertex-B: Node-7 (Path A → C → D → B)


From the reduced matrix of step-03, M[D,B] = 0
Set row-D and column-B to ∞
Set M[B,A] = ∞
Now, resulting cost matrix is-
Now,
We reduce this matrix.
Then, we find out the cost of node-7.
Row Reduction-
We can not reduce row-1 as all its elements are ∞.
We can not reduce row-2 as all its elements are ∞.
We can not reduce row-3 as all its elements are ∞.
We can not reduce row-4 as all its elements are ∞.
Column Reduction-
We can not reduce column-1 as all its elements are ∞.
We can not reduce column-2 as all its elements are ∞.
We can not reduce column-3 as all its elements are ∞.
We can not reduce column-4 as all its elements are ∞.
Thus, the matrix is already column reduced.
Finally, the matrix is completely reduced.
All the entries have become ∞.
Now, we calculate the cost of node-7.
Cost(7)
= cost(6) + Sum of reduction elements + M[D,B]
= 25 + 0 + 0
= 25
Thus,
Optimal path is: A → C → D → B → A
Cost of Optimal path = 25 units
Cost Matrix

𝑅𝑜𝑤 𝑟𝑒𝑑𝑢𝑐𝑒 𝑣 1 𝑣 2
𝑣 1(− 4) ∞ 1
𝑣 2(−2) 3 ∞
¿ ¿ ¿
Dijkstra's Algorithm:
This algorithm maintains a set of vertices whose shortest paths from source is already known. The graph is represented
by its cost adjacency matrix, where cost is the weight of the edge. In the cost adjacency matrix of the graph, all the
diagonal values are zero. If there is no path from source vertex Vs to any other vertex Vi then it is represented by +∞.In
this algorithm, we have assumed all weights are positive.
• Initially, there is no vertex in sets.
• Include the source vertex Vs in S. Determine all the paths from Vs to all other vertices without going through any other
vertex.
• Now, include that vertex in S which is nearest to Vs and find the shortest paths to all the vertices through this vertex
and update the values.
• Repeat the step until n-1 vertices are not included in S if there are n vertices in the graph.
• After completion of the process, we got the shortest paths to all the vertices from the source vertex.
Find the shortest paths between K and L in the graph shown in fig using Dijkstra's Algorithm.
Step1: Include the vertex K is S and determine all the direct paths from K to all other vertices
without going through any other vertex.
Distance to all other vertices
S K a b c d L
K 0 4(K) ∞ 2(K) ∞ 20(K)
Step2: Include the vertex in S which is nearest to K and determine shortest paths to all
vertices through this vertex and update the values. The closest vertex is c.
Distance to all other vertices
S K a b c d L
K 0 3(K, c) 7(K, c) 2(K) 8(K, c) 18(K, c)
Step3: The vertex which is 2nd nearest to K is 9, included in S.
Distance to all other vertices
S K a b c d L
K 0 3(K, c) 7(K, c) 2(K) 7(K, c, a) 18(K, c)
Step4: The vertex which is 3rd nearest to K is b, included in S.
Distance to all other vertices
S K a b c d L
K 0 3(K, c) 7(K, c) 2(K) 7(K, c, a) 8(K, c, b)
Step5: The vertex which is next nearest to K is d, is included in S.
Distance to all other vertices
S K a b c d L
K(c, a, b, d) 0 3(K, c) 7(K, c) 2(K) 7(K, c, a) 8(K, c, b)
Since, n-1 vertices included in S. Hence we have found the shortest distance from K to all
other vertices. Thus, the shortest distance between K and L is 8 and the shortest path is K, c,
b, L.
Dijkstra Algorithm-
• Dijkstra Algorithm is a very famous greedy algorithm.
• It is used for solving the single source shortest path problem.
• It computes the shortest path from one particular source node to all other remaining nodes of the graph.
Conditions-
• Dijkstra algorithm works only for connected graphs.
• Dijkstra algorithm works only for those graphs that do not contain any negative weight edge.
• It only provides the value or cost of the shortest paths.
• By making minor modifications in the actual algorithm, the shortest paths can be easily obtained.
• Dijkstra algorithm works for directed as well as undirected graphs.

V A B C D E F G H
A 0 8,A 2,A 5,A
C - 8,A () 2,A 4,C 7,C
D - 6,D - 4,C 5,D 10,D 7,D
E - 6,D - - 5,D 10,D 6,E
B - 6,D - - - 10,D 6,E
G - - - - - 8,G 6,E 12,G
F - - - - - 8,G - 11,F
- - - - - - - 11,F

You might also like