Mathematical Fundamentals Sets Factorials, Logarithms Recursion Summations, Recurrences Proof Techniques: By Contradiction, Induction Estimation Techniques Data Structures 1 Mathematical Fundamentals
Sets A collection of distinguishable members or elements, drawn from a base type. Each member is a primitive element or a set itself. Membership: Either in the set or not in the set. Data Structures Mathematical Fundamentals
Set Notation In the following A and B are sets. A = {1, 4, 7, } {x x is a positive integer} x A x A A A B, B A A B A B A B Data Structures 3 Mathematical Fundamentals
Sets (contd) Linear Ordering Any pair of set elements have a unique order, one of <, >, or =. Transitivity: a < b and b < c implies a < c. Finite Sequence Sequence of length n drawn from (0, 1,, n 1), and have an ordering. May contain duplicates. Data Structures 4 Mathematical Fundamentals
Other Notation KB ( 10 = 104 bytes), MB ( 0 = 1048576 bytes) Kb, Mb: Kilo or Mega bits. Factorial of n is defined as n! = n.(n 1).(n ).1, with 0! = 1 Permutation: Members of a sequence arranged in some order. Boolean variable Floor of x, x, returns the greatest integer less than x. Ceiling of x, x, returns smallest integer greater than x. Modulus returns remainder of integer division. Data Structures 5 Mathematical Fundamentals
Some Important Functions Constant f(n) = c where c is a constant. Linear f(n) = n Quadratic f(n) = n n log n f(n) = n log n Data Structures 6 Mathematical Fundamentals
Logarithms A logarithm of base b for value y is the power to which y must must raise b to get y Applications log b y = x b x = y b log by = y Algorithm analysis (binary search, tree structures) Encoding values. Properties: For positive values m, n log nm = log n + log m log n/m = log n log m log n r = r log n log a n = log b n log b a Data Structures 7 Mathematical Fundamentals
Recursion An algorithm is recursive if it calls itself to do part of its work. Requirements Needs a Base case - simple input that can be solved without recursion. Recursive part - which leads towards the base case. Examples Factorial(n) Fibonacci Sequence Towers of Hanoi Data Structures 8 Mathematical Fundamentals
Summations, Recurrences Summations are useful in adding up algorithm costs, and are represented as f(i) = f(1) + f() + + f(n) Some Summations in Closed Form: i = i = n(n + 1) 1 = 1 1 i i n(n + 1)(n + 1) 6 i = n+1 1 Data Structures 9 Mathematical Fundamentals
Recurrence Relations Useful in analyzing recursive algorithms. Recurrence relations defines a function by including smaller instances of the problem, such as n! = n.(n 1)!, 1! = 0! = 1 F ib(n) = F ib(n 1) + F ib(n ), F ib(1) = F ib() = 1 Towers of Hanoi recurrence: T (n) = T (n 1) + 1 Data Structures 10 Mathematical Fundamentals
Mathematical Proof Techniques Proof by Contradiction Assume the theorem is false. Find a logical contradiction from this assumption. If the logic used is correct, then the original assumption is wrong and the theorem is correct. Example There is no largest integer. Data Structures 11 Mathematical Fundamentals
Example Problems (proof by contradiction) 1. Let a Z. If a is even, then a is even.. Let n Z. If n is odd, then n is odd. 3. There is no largest integer. 4. is irrrational (not of the form a/b, where a, b Z) 5. if a, b Z, a 4b 3 0. 6. if a, b Z, a 4b 0. 7. if a a + 7 is even, then a is odd. Data Structures 1 Mathematical Fundamentals
Proof by Induction To prove a theorem T is true, express T in terms of positive integer n, and then proceed similar to recursion: Base case: T holds for n = c Induction Step: If T holds for n 1, then T holds for n. Data Structures 13 Mathematical Fundamentals
Example: Proof by Induction Base Step: n = 1 1 i = 1 = 1(1 + 1)/ i=n i = n(n + 1) Induction Hypothesis: Let result be true for some k, where 1 < k < n i=k i = k(k + 1) Data Structures 14 Mathematical Fundamentals
General Case. Example: Proof by Induction We need to prove the case for n = k + 1, i.e. i=k+1 = (k + 1)(k + ) Proof. i=k+1 i = [1 + + 3 +... + (k 1) + k + (k + 1)] = [1 + + 3 +... + (k 1) + k] + (k + 1) [ i=k ] = i + (k + 1) = k(k + 1) + (k + 1) // by Induction Hyp. = k + k + (k + 1) = k + 3k + (k + 1)(k + ) = Data Structures 15 Mathematical Fundamentals
Sample Problems (Proof by Induction) i = n(n + 1) n (i 1) = n. i n(n + 1)(n + 1) = 6 i 3 = n (n + 1) 4 i (i + 1) = n (n + 1) 4 i (i + ) = n (n + 1) 4 Data Structures 16 Mathematical Fundamentals
Sample Problems (Proof by Induction) i=0 1 n(n + 1)(n + 7) = i 6 a i = an+1 1 a 1 i = n+1 1 i=0 n 1 i 1 = (n 1) for a > 1 If n N(whole numbers, 0, 1,,..), n n+1 k 1 1 c and 5c stamps can be used to create any denomination greater than or equal to 4. Data Structures 17 Mathematical Fundamentals