Discrete Math Flashcards
1
Q
Geometric Sequence
A
- a sequence of numbers where each number (after the first) is found by multiplying the previous number by some fixed value (common ratio)
2
Q
nth term
Geometric Sequence
A
- Defines the nth term in a geometric sequence
- In general, use formala starting at 1
Starting at 0
ar<span>n</span>
Starting at 1
arn-1
3
Q
Geometric Series
A
- Sum of the first n terms
- In general, use formala starting at 1
Starting at 0
a(1 - rn+1)
(1 - r)
Starting at 1
a(1 - rn)
(1 - r)
4
Q
Prime Number
A
A natural numbers that is:
- Greater than 1
- Only divisible by itself and 1
- cannot be negative
- must have exactly two factors
5
Q
Composite Number
A
- a natural, non-prime number
6
Q
Trial Division
A
- Used to find factors of a number N
Steps
- Create an output list
- Loop from 1 - √N (inclusive)
- Check if N%i == 0
- If so, add i, and its cofactor to output list
7
Q
cofactor
A
- factors always exist in pairs
- given factor a, the cofactor is the other factor b s.t. a*b=c
- cofactor may be same as factor (62 == 36)
8
Q
Sieve of Eratosthenes
A
- Ancient algorithm for finding all prmes less than some number
Steps
- Create a boolean array from 0 to N
- Set all entries to True (mark every number as prime)
- Set 0, 1 to false (they aren’t prime)
- Start looping from 2 to root N
- Find all multiples of i (starting at i^2), mark as false (they are composite)
- Use indices to get primality of a number
Complexity
Time
O( n log log n)
Space
O(n)
*Time complexity is based on fancy math
9
Q
Prime Factorization
A
- Writing the factors of a number with only primes
- Only one possible prime factorization of a number
- Often written with exponents
Steps
- Start looping from 2 to √N
- At each i, while n%i ==0
- Divide n by i
- Increase count (number of i’s in n)
- Return to outer loop
- If N != 1 after loop, N must be a prime number
- Add N (frequency 1) to the output
10
Q
GCD
Euclidean Algorithm
A
- gcd is the largest number that evenly divides two numbers
- euclidean algorithm fast technique for finding gcd of a numbers a and b
- usually implemented recursively
- generally assume (or position) a > b
- note: if two numbers (a, b) share a factor, then their difference (a-b) also shares a factor
- ergo, if two numbers (a, b) share a factor, then their remainder (a%b) also shares a factor
Steps
- Assuming a > b
- If b == 0, return a
- Otherwise, return gcd(b, a%b)
11
Q
cardinality
[set theory]
A
- The cardinality of a set is the number of elements in a set
- Syntax is the same as for absolute value
Syntax:
If set A has 5 elements, then:
|A| = cardinality of A = 5
12
Q
intersection
(set theory)
A
- A ∩ B are the elements in both A and B
13
Q
union
[set theory]
A
- A ∪ B is the elements in X or Y
- Combination of the two sets
14
Q
symmetric difference
[set theory]
A
- A ∆ B are the elements that A and B don’t share
- Everything other than the overlap in a venn diagram
15
Q
complement
[set theory]
A
- all the things that are not in A
2 definitions
- relative complement (difference)
- absolute complement