Download presentation
Presentation is loading. Please wait.
1
Mathematics Common Math Approaches
2
Math in Problems Many problems can be simplified with some analysis ahead of time Doing some analysis of the problem ahead of time can make a seemingly complex or long-running problem go much faster Not always a simplification, but sometimes need to think mathematically. Brute Force is sometimes the right approach, but avoid unnecessary work E.g. read lots of numbers, how many are < k? Answer: do O(n) loop and count. Do NOT sort the numbers.
3
Finding Patterns Often there will be a pattern, but not always obvious
Can try to generate several elements of a sequence, to try to ID the pattern Takes some experience to recognize patterns Generate by hand first, before getting computer to do it Generate the first few elements by brute force, so that you can try to discern a pattern. Look for solutions that could use Dynamic Programming Look for well-known sequences
4
Common Sequences Arithmetic: a+bi Geometric: a ri Other sequences:
Let an = a+(n-1)b Then the sum from a1 to an is n(a1+an)/2 e.g. n(n+1)/2 Geometric: a ri Sum from a1 to an is a(1-rn)/(1-r) if r<1. Other sequences: Fibonacci Factorial Catalan, etc.
5
Logarithms Can simplify many operations
Convert multiplication sequence to addition, or exponentiation to multiplication Solve the easier problem, then take exponent (if needed) Can use to convert from one base to another
6
Java BigInteger Provides arbitrary precision integer math
When an unsigned long long is not large enough to hold Operates much slower than HW-supported integer operations Unfortunately, only available in Java So, if it’s needed, you need to code in Java Has other features Convert to Bases GCD Modulo arithmetic Probabilistic Prime Testing See book, section 5.3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.