Proving Theorems - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Proving Theorems

Description:

Algorithm - A finite set of precise instructions for performing a computation or ... Method: Analyze the pseudocode and determine the number of steps required, f(n) ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 22
Provided by: dson
Category:

less

Transcript and Presenter's Notes

Title: Proving Theorems


1
Proving Theorems
  • Direct proof
  • An implication p?q can be proved by showing that
    if p is true, then q is also true.
  • Example Give a direct proof of the theorem If
    n is odd, then n2 is odd.
  • Idea Assume that the hypothesis of this
    implication is true (n is odd). Then use rules of
    inference and known theorems to show that q must
    also be true (n2 is odd).

2
Proving Theorems
  • n is odd.
  • Then n 2k 1, where k is an integer.
  • Consequently, n2 (2k 1)2.
  • 4k2 4k 1
  • 2(2k2 2k) 1
  • Since n2 can be written in this form, it is odd.

3
Proving Theorems
  • Indirect proof
  • An implication p?q is equivalent to its
    contra-positive ?q ? ?p. Therefore, we can prove
    p?q by showing that whenever q is false, then p
    is also false.
  • Example Give an indirect proof of the theorem
    If 3n 2 is odd, then n is odd.
  • Idea Assume that the conclusion of this
    implication is false (n is even). Then use rules
    of inference and known theorems to show that p
    must also be false (3n 2 is even).

4
Proving Theorems
  • n is even.
  • Then n 2k, where k is an integer.
  • It follows that 3n 2 3(2k) 2
  • 6k 2
  • 2(3k 1)
  • Therefore, 3n 2 is even.
  • We have shown that the contrapositive of the
    implication is true, so the implication itself is
    also true (If 2n 3 is odd, then n is odd).

5
Induction
  • The principle of mathematical induction is a
    useful tool for proving that a certain predicate
    is true for all natural numbers.
  • It cannot be used to discover theorems, but only
    to prove them.

6
Induction
  • If we have a propositional function P(n), and we
    want to prove that P(n) is true for any natural
    number n, we do the following
  • Show that P(0) is true. (basis step)
  • Show that if P(n) then P(n 1) for any n?N.
    (inductive step)
  • Then P(n) must be true for any n?N.
    (conclusion)

7
Induction
  • Example
  • Show that n lt 2n for all positive integers n.
  • Let P(n) be the proposition n lt 2n.
  • 1. Show that P(1) is true.(basis step)
  • P(1) is true, because 1 lt 21 2.

8
Induction
  • 2. Show that if P(n) is true, then P(n 1) is
    true.(inductive step)
  • Assume that k lt 2k is true.
  • We need to show that P(k 1) is true, i.e.
  • k 1 lt 2k1
  • We start from k lt 2k
  • k 1 lt 2k 1 2k 2k 2k1
  • Therefore, if n lt 2n then n 1 lt 2n1

9
Induction
  • Then P(n) must be true for any positive
    integer.(conclusion)
  • n lt 2n is true for any positive integer.
  • End of proof.

10
Induction
  • Another Example (Gauss)
  • 1 2 n n (n 1)/2
  • Show that P(0) is true.(basis step)
  • For n 0 we get 0 0. True.

11
Induction
  • Show that if P(n) then P(n 1) for any n?N.
    (inductive step)
  • 1 2 n n (n 1)/2
  • 1 2 n (n 1) n (n 1)/2 (n 1)
  • (2n 2 n (n 1))/2
  • (2n 2 n2 n)/2
  • (2 3n n2 )/2
  • (n 1) (n 2)/2
  • (n 1) ((n 1) 1)/2

12
Induction
  • Then P(n) must be true for any n?N. (conclusion)
  • 1 2 n n (n 1)/2 is true for all n?N.
  • End of proof.

13
Complexity of Algorithms
  • Algorithm - A finite set of precise instructions
    for performing a computation or for solving a
    problem. Examples
  • - Find the largest integer in a set
  • - Locate a particular element in a set
  • - Sort a list of elements
  • Pseudocode - Intermediate steps between an
    English language description of the procedure and
    an actual specification using a programming
    language.
  • Method Analyze the pseudocode and determine the
    number of steps required, f(n), as a function of
    the problem size n

14
Time Complexity
  • Consider
  • a 7
  • x 3
  • for i 1 to n
  • y ax
  • Complexity?

15
Time Complexity
  • Consider
  • a 7
  • b 2
  • c 1
  • x 3
  • for i 1 to n
  • for j 1 to n
  • y abbc(abc)/(ab) 4
  • Complexity?

16
Time Complexity
  • Assume an algorithm takes
  • 3n 3 steps Then it is a O(n) Algorithm
  • 5n2 5n 105 steps Then it is a O(n2)
    Algorithm
  • 2n3 2n 10 steps Then it is a O(n3)
    Algorithm
  • f(n) is O(g(n)) iff positive constants c and n0
    exist such that f(n) lt cg(n) for all n, n gt k.
  • 3n 3 lt 4n for all n, n gt 3
  • 5n2 5n 105 lt 10n2 for all n, n gt
    6
  • 2n3 2n 10 lt 3n3 for all n, n gt 3

17
Time Complexity
Typical Complexities O(1) O(log n) O(n) O(n
log n) O(n2) O(n3) NP
  • cg(n)

f(n)
n
k
f(n) is O(g(n)) iff positive constants c and k
exist such that f(n) lt cg(n) for all n, n gt k.
18
Example Find the Maximum Element in a Finite
Sequence
  • Procedure max(a1, a2,..., an integers)
  • max a1
  • for i 2 to n
  • if max lt ai then max ai
  • max is the largest element

a
6
5
7
1
10
8
1 2 3 4 5 6
19
ExampleBinary Search Algorithm
  • Procedure binary search(x integer, a1,...,an
    increasing integers)
  • i 1 left endpoint of search interval
  • j n right endpoint of search interval
  • while (i lt j )
  • m ?(i j )/2?
  • if x gt am then i m 1
  • else j m
  • end
  • if x ai then location i
  • else location 0
  • location is the subscript of the term that
    equals x location is 0 of x is not found

19
25
27
31
35
38
3
5
7
9
10
18
47
51
60
68
20
Homework
  • Weiss p. 35-38 2.1, 2.2, 2.18
  • Levitin P. 51-52 3, 8, 9
  • P. 59-60 1, 2, 3

21
Programming Assignment 1
  • Weiss p. 35-36 2.6
  • Instructions
  • Implement each routine in C
  • Turn in with a report stating clearly for each
    algorithm what the running time is
  • Provide a bar chart showing the number of
    iterations (or the running time) for various
    values of n
Write a Comment
User Comments (0)
About PowerShow.com