🍁
Data Structures and Algorithms
  • Introduction
  • Introduction to Algorithms Analysis
    • Growth Rates
    • Big-O, Little-o, Theta, Omega
    • Analysis of Linear Search
    • Analysis of Binary Search
  • Recursion
    • The runtime stack
    • How to Write a Recursive Function
      • Example: the Factorial Function
    • Drawbacks of Recursion and Caution
  • Lists
    • Implementation
    • Linked List
      • Nodes
      • Iterator
      • Template Singly Linked List
      • Doubly Linked List
      • Circular Linked List
  • Stacks
    • Stack Operations
    • Stack Implementations
    • Stack Applications
  • Queue
    • Queue Operations
    • Queue Implementations
    • Queue Applications
  • Tables
    • Simple Table
    • Hash Table
      • Bucketing
      • Chaining
      • Linear Probing
      • Quadratic Probing and Double Hashing
  • Sorting
    • Simple Sorts
      • Bubble Sort
      • Insertion Sort
      • Selection Sort
    • Merge Sort
      • Merge Sort Implementation
    • Quick Sort
    • Heap Sort
      • Binary heap
      • Binary heap basics
      • Insertion into a binary heap
      • Delete from a binary heap
      • Implementation
      • Sorting
  • Introduction to Trees, Binary Search Trees
    • Definitions
    • Tree Implementations
    • Binary Trees
    • Binary Search Trees
      • Insertion
      • Removal
      • Traversals
  • AVL Trees
    • Height Balance
    • Insertion
    • Why it works
  • Red Black Trees
    • Insertion Example
  • 2-3 Trees
  • Graphs
    • Representation
  • Complexity Theory
  • Appendix: Mathematics Review
Powered by GitBook
On this page
  • Mathematical Notations and Shorthands
  • Shorthands
  • Variables
  • Functions
  • Sigma Notation
  • Mathematical Definitions and Identities
  • Exponents
  • Logarithms
  • Series

Was this helpful?

Appendix: Mathematics Review

A certain familiarity with certain mathematical concepts will help you when trying to analyze algorithms. This section is meant as a review for some commonly used mathematical concepts, notation, and methodology

Mathematical Notations and Shorthands

Shorthands

shorthand

meaning

iff

if and only if

therefore

approximately

$$

a

$$

Variables

In math, like programming, we use variables. Variables can take on some numeric value and we use it as a short hand in a mathematical expression. Before using a variable, you should define what it means (like declaring a variable in a program)

For example:

"Let n represent the size of an array"

This means that the variable n is a shorthand for the size of an array in later statements.

Functions

Similar to functions in programming, mathematics have a notation for functions. Mathematically speaking, a function has a single result for a given set of arguments. When writing out mathematical proof, we need to use the language of math which has its own syntax

As a function works with some argument, we first define what the arguments mean then what the function represents.

For example:

Summary

n can take on any value (unless there are stated limitations) and result of a function given a specific value is calculated simply by replacing n with the value

Note that when we talk about big-O notation (and related little-o, theta and omega notation) those are not functions (though it kind of looks like it)

Sigma Notation

Sigma notation is a shorthand for showing a sum. It is similar in nature to a for loop in programming.

General summation notation.

The above notation means that there are n terms and the summation notation adds each of them together.

Example:

Mathematical Definitions and Identities

Mathematical identities are expressions that are equivalent to each other. Thus, if you have a particular term, you can replace it with its mathematical identity.

Exponents

definition

identities

Logarithms

definition

identities

Series

A series is the sum of a sequence of values. We usually express this using sigma notation (see above).

identities

PreviousComplexity Theory

Last updated 5 years ago

Was this helpful?

*

*

absolute value of

ceiling, round up to next biggest whole number. Example:

floor, round down to the next smallest whole number. Example:

Let nnn represent the size of the array (n is the name of the argument) Let T(n)T(n)T(n) represent the number of operations needed to sort the array

We pronounce T(n)T(n)T(n) as "T at n". Later we will assoicate T(n)T(n)T(n) with a mathematical expression that we can use to make some calculation. The expression will be a mathematical statement that can be used to calculate the number of operations needed to sort the array. If we supply the number 5, then T(5)T(5)T(5) would be the number of operations needed to sort an array of size 5

T(n)T(n)T(n) - read it as T at n, we call the function T.

T(n)=n2+n+2T(n) = {n^2} + n + 2T(n)=n2+n+2 means that T(n)T(n)T(n) is the same as the mathematical expression n2+n+2{n^2} + n + 2n2+n+2

T(5)=52+5+2=32T(5) = {5^2} + 5 + 2 = 32T(5)=52+5+2=32 ( we pronounce T(5)T(5)T(5) as "T at 5")

∑i=1nti=t1+t2+...+tn\sum\limits_{i=1}^{n} t_i = t_1 + t_2+ ... + t_ni=1∑n​ti​=t1​+t2​+...+tn​

Typically the terms tit_iti​ is some sort of mathetmatical expression in terms of i (think of it as a calculation you make with the loop counter). the i is replaced with every value from the initial value of i (at the bottom of the ∑\sum∑) going up by 1 to n (the value at the top of the ∑\sum∑)

∑i=15i=1+2+3+4+5\sum\limits_{i=1}^{5} i = 1 + 2 + 3 + 4 + 5i=1∑5​i=1+2+3+4+5

xn{x^n}xn means (x)(x)(x)...(x)(x)(x)(x)...(x)(x)(x)(x)...(x) (nnn xxx's multiplied together)

xaxb=xa+b{x^ax^b}={x^{a+b}}xaxb=xa+b

xaxb=xa−b\frac{x^a}{x^b} = {x^{a-b}}xbxa​=xa−b

(xa)b=xab{({x^a})^b} = {x^{ab}}(xa)b=xab

xa+xa=2xa≠x2a{x^a}+{x^a} = 2{x^a} \neq {x^{2a}}xa+xa=2xa=x2a

2a+2a=2(2a)=2a+1{2^a}+{2^a} = 2({2^a}) = {2^{a+1}}2a+2a=2(2a)=2a+1

In computer text books, unless otherwise stated logloglog means log2log_2log2​ as opposed to log10log_{10}log10​ like math text books

bn=a{b^n} = abn=a iff logba=nlog_ba = nlogb​a=n In otherwords logbalog_balogb​a is the exponent you need to raise b by in order to get a.

log⁡ba=log⁡calog⁡cb\log_ba = \frac{\log_ca}{\log_cb}logb​a=logc​blogc​a​, where c>0c > 0c>0

log⁡ab=log⁡a+log⁡b\log {ab} = \log a + \log blogab=loga+logb

log⁡(ab)=log⁡a−log⁡b\log (\frac{a}{b}) = \log a - \log blog(ba​)=loga−logb

log⁡ab=blog⁡a\log {a^b} = {b}{\log a}logab=bloga

log⁡x<x\log x < xlogx<x for all x>0x > 0x>0

log⁡1=0\log 1 = 0log1=0

log⁡2=1\log 2 = 1log2=1

∑i=0nc(f(i))=c∑i=0nf(i)\sum\limits_{i=0}^{n} c(f(i)) = c \sum\limits_{i=0}^{n}f(i)i=0∑n​c(f(i))=ci=0∑n​f(i), where ccc is a constant

∑i=0n2i=2n+1−1\sum\limits_{i=0}^{n} {2^i} = {2^{n+1}} - 1i=0∑n​2i=2n+1−1

∑i=0nai=an+1−1a−1\sum\limits_{i=0}^{n} {a^i} = \frac{a^{n+1}- 1}{ a - 1}i=0∑n​ai=a−1an+1−1​

∑i=0nai≤1a−1\sum\limits_{i=0}^{n} {a^i} \leq \frac{1}{a-1}i=0∑n​ai≤a−11​ if 0<a<10 < a < 10<a<1

∑i=1ni=n(n+1)2\sum\limits_{i=1}^{n} {i} = \frac{n(n+1)}{2}i=1∑n​i=2n(n+1)​

∑i=1ni2=n(n+1)(2n+1)6\sum\limits_{i=1}^{n}{i^2} = \frac{n(n+1)(2n+1)}{6}i=1∑n​i2=6n(n+1)(2n+1)​

∑i=1nf(n)=nf(n)\sum\limits_{i=1}^{n}{f(n)} = nf(n)i=1∑n​f(n)=nf(n)

∑i=n0nf(i)=∑i=1nf(i)−∑i=1n0−1f(i)\sum\limits_{i=n_0}^{n} f(i) = \sum\limits_{i=1}^{n} f(i) - \sum\limits_{i=1}^{n_0 - 1} f(i)i=n0​∑n​f(i)=i=1∑n​f(i)−i=1∑n0​−1​f(i)

∴\therefore∴
≈\approx≈
ababab
aaa
bbb
a(b)a(b)a(b)
aaa
bbb
aaa
⌈a⌉\lceil{a}\rceil⌈a⌉
aaa
⌈2.3⌉=3\lceil{2.3}\rceil = 3⌈2.3⌉=3
⌊a⌋\lfloor{a}\rfloor⌊a⌋
aaa
⌊2.9⌋=2\lfloor{2.9}\rfloor = 2⌊2.9⌋=2