1 / 8

Chapter 1 - Mathematical Review Functions

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

Télécharger la présentation

Chapter 1 - Mathematical Review Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. Logarithms • logby=xbx=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

  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<<ptr->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

More Related