Download presentation
Presentation is loading. Please wait.
Published byAubrie Stevenson Modified over 8 years ago
1
Chapter 1 - Mathematical Review Functions Factorial - x!=1*2*3*…..*x Permutation - a rearrangement of a sequence Boolean variable - takes on 2 values – TRUE, FALSE – 0, 1 Floor - round down x Ceiling - round up x Modulus - mod - Remainder – x mod y - remainder when divide x by y – 10 mod 3 is 1
2
Logarithms log b y=x b x =y b log b y =y log mn = log m + log n – Let m=X A, n=X B, log(X A X B )=log(X A+B )=A+B=log m+ log b log m/n = log m - log n – X A /X B =X A-B log n r = r log n – (X A ) B =X AB log a n=log b n/log b a 2 n +2 n =2*2 n =2 n+1
3
Recursion A recursive algorithm calls itself. Must have a base case to stop recursion Calls must pass a “smaller problem” to the function. This will cause the recursion to eventually stop. Assume the recursive calls work. Factorial example: int fact(int n) { if (n<=1) return 1; else return n*fact(n-1) } Looks a bit like induction Better to use for’s and while’s when appropriate.
4
Non-Math Recursion Print out a linked list – A linked list is either An empty list (null pointer) or A head node followed by a linked list – Base case -> linked list is empty printLL(ptr) {if (ptr==NULL) return; else { cout data<<endl; printLL(ptr->next); }}
5
Summations
6
Proof Techniques Proof by Contradiction – Assume the opposite of the conclusion is true. Use steps to prove a contradiction (for example 1=2), then the original theorem must be true. Proof by induction – Show the theorem holds for a base case (n=0 or n=1) – Assume the theorem holds for n=k-1 – Prove the theorem is true for n=k – Example: show 1+2+3+…+n=n(n+1)/2 for n=1 1=1(2)/2=1 assume 1+2+3+…+n-1=(n-1)(n)/2; show 1+2+…+n=n(n+1)/2 (n-1)(n)/2+n=[(n-1)(n)+2n]/2=[n(n-1+2)]/2=n(n+1)/2
7
C++ Review Review the C++ material in Chapter 1 and ask necessary questions next time. I know there are several topics that you did not cover in 208, but you may be able to understand them with your current background. – If you don’t ask about them, I will assume you know how to use them and they will be fair game on the tests.
8
C++ topics Constructors – Default – Initializer list – Explicit – Copy constructor Preprocessor – #ifndef, etc. Pointers/Dynamic object creation Parameter Passing Return Passing Reference Variables Destructor, Operator = C arrays and strings Templates Stop at P. 32
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.