Download presentation
Presentation is loading. Please wait.
Published byClaire May Modified over 9 years ago
1
Advance Data Structure and Algorithm COSC600 Dr. Yanggon Kim Chapter 1
2
Introduction In order to analyze a given algorithm, we need to have some mathematical background. Some of formulas that aid in analysis are as follows.
3
Exponents Definition The base X raised to power N is equal to product of X multiplied N many times. The power N in this case is exponent
4
Exponent Rules EXAMPLE: LAW:
5
Logarithms Definition if and only if THEROM 1.1: THEROM 1.2:
6
Series Let be a sequence then the sum of a sequence is called a series. This is denoted as: The easiest formula to remember is:
7
Series (Continued) The companion formula is:
8
Series (Continued) Important formulas used for analysis: 1) 2) 3) 4)
9
Series (Continued)
10
Rules
11
Rules ( Continued)
12
Induction Method Principle of Mathematical Induction Let P be a property of positive integers such that Base Case: P (1) is true, and Inductive Step: if P (n) is true, then P (n+1) is true. Then P (n) is true for all positive integers. The premise P (n) in the inductive step is called Induction Hypothesis.
13
Steps for proof by Induction Method Base condition: prove the theorem for base condition. For example N=1 Assume that the given theorem is true for N=k case Using assumption, prove the theorem is true for N=k+1 case step by step
14
Induction Method Example 1 For example, proof of for any positive integer N Proof: Base Condition: For N =1
15
Induction Method Example 1 Assume that For N = k + 1 case, Theorem is true for n =k+1 case Theorem is true for any positive integer N
16
Induction Method Example 2 For example, proof of Fibonacci number Let be Fibonacci number Prove
17
Induction Method Example 2 Proof Base Condition For i =1 case Assume that For i=k+1 case,
18
Counter Example Most theorems are counter example. They prove as “false.” Example: F1 is a Fibonacci number F k F k 2 is false F 0 =1 F 1 =1 F 2 =2 F 3 =3 F 4 =5 F 5 =8 So we try…… F 11 = 144 11 2 = 121 not true Given case is false!
19
Contradiction Proof by contradiction proceeds by assuming that the theorem is false and showing that this assumption implies that some known property is false, and hence the original assumption was erroneous. There is an infinite number of primes EX: 2,3,5,7,11,13,17,19 ASSUME that there is a finite number of primes Let P k be the largest prime Let N = P 1 * P 2 * P 3 * P 4 * ……….. P k +1 None of P 1, P 2 ……. P k Divides n exactly There will be a remainder of 1 N is a prime number
20
Contradiction (Continued) Contradiction (P k is not the largest prime) (N > P k ) Then theorem is true
21
Recursion A function that is defined in terms of itself is called “recursive.” Fundamental Rules of recursion: Base case – you must always have some base cases, which can be solved without recursion. Making progress – for the cases that are to be solved recursively, the recursive call must always be to a case that makes progress toward a base case. Design Rule – assume that all the recursive calls work. Compound interest rule – never duplicate work by solving the same instance of a problem in separate recursive calls. Divide & Conquer Example Just like merge sort for traversing an array – divide array in half, then divide both pieces in half until search item is found.
22
Recursion Example 2 – Hanoi Tower Problem No disk can be placed on a smaller disk. If n=1 move the disk source to destination Else T(n-1, A,C,B) Move n th disk from A to C T(n-1,B,A,C)
23
Recursion Example Public static int f (int n) { if (n == 0) return 0; else return f(n/3 +1) + n-1; } RESULT F(10) F(4) +9 F(2) +3 F(1) +2 F(1) + 0
24
References LERMA, M. (2003, February 8). MATHEMATICAL INDUCTION. Retrieved September 6, 2014, from http://www.math.northwestern.edu/~mlerma/problem_solving/resul ts/induction.pdf
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.