Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced Algorithms Analysis and Design

Similar presentations


Presentation on theme: "Advanced Algorithms Analysis and Design"— Presentation transcript:

1 Advanced Algorithms Analysis and Design
By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

2 Lecture No 3 Logic and Proving Techniques
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

3 Today Covered Tools used for proving algorithms Propositional Logic
Predicate Logic Proofs using Truth Tables Logical Equivalences Counter Example Contradiction Rule of Inference Probability as Analysis Tool Series and Summation etc. Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

4 Propositional and Predicate Logic
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

5 Logical Connectives Proposition: Simplest statements also called atomic formula Propositions may be connected based on atomic formula. Logical connectives, in descending order of operator precedence Symbol Name Pronunciation negation not conjunction and disjunction or implication implies equivalence if and only if Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

6 Negation, Conjunction and Disjunction
The conjunction p  q is true only if p and q both are true otherwise false The conjunction follows the commutative property, i.e. p  q = q  p Disjunction The disjunction p  q is false if both p and q are false otherwise true The disjunction follows the commutative property as well, i.e. p  q = q  p Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

7 Implication The p is antecedent and q is consequent
The antecedent is stronger than consequent. Commutative property does not hold, i.e. (p  q)  (q  p) p q p  q q  p  p  q t f Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

8 Bi-implication The equivalence p  q means p  q & q  p
Commutative property does hold, i.e. (p  q) = (q  p) p q p  q q  p p  q & q  p t f Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

9 Predicates and Quantifiers
Predicate: P(x)  x < 5 Example:  x : N | x2 = x  x < 2 For all quantifier  x, P(x) is true  P(x) is true for all x. Existential Quantifier  x, P(x) is true  P(x) is true for some value of x. Logical Equivalences  x, P(x) is logically equivalent to  ( x, P(x))  x, P(x) is logically equivalent to ( x, P(x))  x, (P(x)  Q(x)) means x, P(x)  Q(x) Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

10 Proving Techniques Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

11 Proof using Truth Table: (p  q  r)  (p  (q  r))
t t t t t t f t f t f f t f t t t t t f t t t f t Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

12 De Morgan’s Laws (p  q) =  p   q p q p  q (p  q) p q p  q
t f Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

13 De Morgan’s Laws 2. (p  q) =  p   q p q p  q (p  q) p q
t f Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

14 Proof using Counter Example, Contraposition
Counter Example To prove  x (A(x)  B(x)) is false, we show some object x for which A(x) is true and B(x) is false. Proof  ( x (A(x)  B(x)))  x, (A(x)  B(x)))   x, (A(x)  B(x))   x, A(x)  B(x)) Contraposition To prove A  B, we show ( B)  ( A) x is divisible by 4  x is divisible by 2  x is not divisible by 2  x is not divisible by 4  Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

15 Proof by Contradiction
Contradiction To prove A  B, Steps in Proof We assume A and to prove that B On contrary suppose that  B and Then prove B, it will be contradiction Further analysis A  B  (A  B)  B Contradiction A  B  (A  B) is false Assuming (A  B) is true, and discover a contradiction (such as A  A), then conclude (A  B) is false, and so A  B. Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

16 Problem: Proof by Contradiction
Prove: [B  (B  C)]  C, by contradiction Proof: Suppose [B  (B  C)], to prove C On contrary, assume C C  [B  (B  C)] must be true  C  [B  ( B  C)]  C  [(B   B)  (B  C)]  C  [f  (B  C)]  C  B  C = C  C  B = f  B = f  False, Contradiction  C Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

17 Rules of Inference A rule of inference is a general pattern that allows us to draw some new conclusion from a set of given statements. If we know P then we can conclude Q. Modus ponens If {B  (B  C)} then {C}, example in last slide Proof: Suppose B  (B  C) then B B  C Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

18 Rules of Inference Syllogism If {A  B  B  C} then {A  C} Proof
Suppose A  B  B  C, To prove A  C B C Rule of cases If {B  C  B  C} then {C} B, true, implies C true  B, true, implies C true Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

19 Two Valued Boolean Logic
Boolean values = B = {0, 1}, there are two binary operations: + = or =  · = and =  2. Closure properties:  x, y  B, x + y  B  x, y  B, x . y  B 3. Identity element: x + 0 = 0 + x = x x · 1 = 1 . x = x Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

20 Two Valued Boolean Logic
4. Commutative: x + y = y + x x · y = y · x 5. Distributive: x · (y + z) = (x · y) + (x · z) x + (y · z) = (x + y) · (x + z) 6. Complement:  x  B,  x’  B such that x + x’ = 1, x · x’ = 0 Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

21 Tautologies and Truth Table
Tautology: Any statement which is always true is called a tautology Example Show [B  (B  C)]  C is a tautology: Proof B C (B  C) (B  (B  C)) (B  (B  C))  C For every assignment for B and C, the statement is True, hence the above statement is a tautology. Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

22 Probability as Analysis Tool
Elementary events Suppose that in a given situation an event, or an experiment, may have any one, and only one, of k outcomes, s1, s2, …, sk. Assume that all these outcomes are mutually exclusive. Universe The set of all elementary events is called the universe of discourse and is denoted U = {s1, s2, …, sk}. Probability of an outcome si Associate a real number Pr(si), such that 0  Pr(si)  1 for 1  i  k; Pr(s1) + Pr(s2) + … + Pr(sk) = 1 Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

23 Event Event Let S  U. Then S is called an event, and Sure event
U = {s1, s2, …, sk}, if S = U Impossible event S = , Pr() = 0 Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

24 Arithmetic and Geometric Series
Dr Nazir A. Zafar Advanced Algorithms Analysis and Design

25 Conclusion Propositional Logic Predicate Logic
We have discussed various techniques of proving Truth Tables Logical Equivalence Counter Example Contraposition Contradiction Rule of Inference Probability can be used for average cost analysis Series and summation are very helpful in simplification Dr Nazir A. Zafar Advanced Algorithms Analysis and Design


Download ppt "Advanced Algorithms Analysis and Design"

Similar presentations


Ads by Google