80 likes | 105 Views
Learn about mathematical concepts like Factorial, Recursion, Summations alongside C++ topics including Constructors, Pointers, and Templates. Get ready to dive into the world of functions and programming in this comprehensive review.
E N D
Chapter 1 - Mathematical ReviewFunctions • 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
Logarithms • logby=xbx=y blogby=y • log mn = log m + log n • Let m=XA, n=XB, log(XAXB)=log(XA+B)=A+B=log m+ log b • log m/n = log m - log n • XA/XB=XA-B • log nr = r log n • (XA)B=XAB • logan=logbn/logba • 2n+2n=2*2n=2n+1
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.
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<<ptr->data<<endl; printLL(ptr->next); }}
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
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.
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