110 likes | 260 Views
MA/CSSE 473 Day 05. More induction Factors and Primes Recursive division algorithm. MA/CSSE 473 Day 05. HW 2 due tonight, 3 is due Monday Student Questions Two more induction examples Asymptotic Analysis example: summation Continue Algorithm Overview/Review
E N D
MA/CSSE 473 Day 05 More induction Factors and Primes Recursive division algorithm
MA/CSSE 473 Day 05 • HW 2 due tonight, 3 is due Monday • Student Questions • Two more induction examples • Asymptotic Analysis example: summation • Continue Algorithm Overview/Review • Integer Primality Testing and Factoring • Modular Arithmetic intro
Another Induction Example Tiling with Trominoes • We saw that a 2n2n checkerboard can be tiled with dominoes. • What about trominoes? • Clearly, we can't tile an entire board! • Definition: A deficient rectangular grid of squares is one that has one square missing. • It's easy to see that we can tile a 22 deficient rectangle! (We can rotate the tromino) Note: HW 4 will mainly be about tiling with trominoes. Q1
Trominoes Continued • What about a 4 x 4 deficient rectangle? • Can we tile this? • Fun with Tromino tiling:http://www3.amherst.edu/~nstarr/trom/puzzle-8by8/
Trominoes Continued • Prove by induction that we can tile any 2n2n deficient rectangle with trominoes • Base case: n=1 Done • Assume that we can do it for n=k • Show that we can do it for n=k+1 • Assume WLOG that the missing square is in the lower right quadrant of the rectangle • If it is somewhere else, we could simply rotate the board. • Can we place one tromino in a way that allows us to use the induction assumption?
Another Induction ExampleExtended Binary Tree (EBT) • An Extended Binary tree is either • an external node, or • an (internal) root node and two EBTs TL and TR. • We draw internal nodes as circles and external nodes as squares. • Generic picture and detailed picture. • This is simply an alternative way of viewing binary trees, in which we view the null pointers as “places” where a search can end or an element can be inserted.
A property of EBTs • Property P(N): For any N>=0, any EBT with N internal nodes has _______ external nodes. • Proof by strong induction, based on the recursive definition. • A notation for this problem: IN(T), EN(T) • Note that, like some other simple examples, this one can be done without induction. • But the purpose of this exercise is practice with strong induction, especially on binary trees. • What is the crux of any induction proof? • Finding a way to relate the properties for larger values (in this case larger trees) to the property for smaller values (smaller trees). Do the proof now. Q2-3
Asymptotic Analysis Example • Find a simple big-Theta expression (as a function of n) for the following sum • when 0 < c < 1 • when c = 1 • when c > 1 • f(n) = 1 + c + c2 + c3 + … + cn Q4
FACTORING and PRIMALITY • Two important problems • FACTORING: Given a number N, express it as a product of its prime factors • PRIMALITY: Given a number N, determine whether it is prime • Conclusions • Factoring is hard • The best algorithms so far require time that is exponential in the number of bits of N • Primality testing is relatively easy • A strange disparity for these closely related problems • Exploited by cryptographic algorithms • More on these problems later Q5
Recap: Arithmetic Run-times • For operations on two n-bit numbers: • Addition: Ѳ(n) • Multiplication: • Standard algorithm: Ѳ(n2) • "Gauss-enhanced": Ѳ(n1.59), but with a lot of overhead. • Division (We won't ponder it in detail, but see next slide): Ѳ(n2)
Algorithm for Integer Division Let's work through divide(19, 4). Analysis? Q6