Algorithm, principles and misc concepts

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/28

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 6:15 PM on 7/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

29 Terms

1
New cards

Bitwise XOR (^)

Returns 1 if bits differ, 0 if same. Ex: 5^3=6 (101^011=110). Uses: Swapping variables, finding the unique element in a pair-heavy array, toggling bits.

2
New cards

Big O Notation

Describes asymptotic time/space complexity. O(1) < O(log n) < O(n) < O(n log n) < O(n²) < O(2ⁿ). Ignores constants and lower-order terms.

3
New cards

Amortized Analysis

The average time per operation over a worst-case sequence. Ex: Dynamic array append is O(1) amortized because O(n) resizing happens rarely.

4
New cards

Permutations (P)

Number of ways to arrange r items from n where order matters: $P(n,r) = \frac{n!}{(n-r)!}$. For all n items, it is simply n!.

5
New cards

Combinations (C)

Number of ways to choose r items from n where order doesn't matter: $C(n,r) = \frac{n!}{r!(n-r)!}$. Also called 'n choose r.'

6
New cards

Pigeonhole Principle

If n items are put into m containers and n > m, at least one container has >1 item. Used to prove collisions (e.g., hash overlaps).

7
New cards

Euclidean Algorithm

Efficient GCD method: gcd(a, b) = gcd(b, a mod b). Base case: gcd(a, 0) = a.

8
New cards

Modular Arithmetic

Math with 'wraparound' at modulus m. Property: (a + b) % m = ((a % m) + (b % m)) % m. Essential for preventing integer overflow.

9
New cards

Modular Exponentiation

Computing $(base^{exp}) \pmod m$ in O(log exp) time using repeated squaring. Prevents massive intermediate numbers.

10
New cards

Brian Kernighan's Algorithm

Counts set bits in an integer: while(n) { n &= (n-1); count++; }. Each step clears the least significant set bit.

11
New cards

Power of 2 Check (Bitwise)

A number n is a power of 2 if: (n > 0) && ((n & (n - 1)) == 0).

12
New cards

Bit Masks

Using bits to represent a set. Set: mask | (1 << i); Clear: mask & ~(1 << i); Toggle: mask ^ (1 << i); Check: mask & (1 << i).

13
New cards

Two's Complement

Standard for negative numbers: Flip all bits and add 1. Allows addition and subtraction to use the same CPU logic.

14
New cards

Prefix Sum Array

Precomputes cumulative sums. prefix[i] = arr[0...i]. Query range sum [L, R] in O(1) time via prefix[R] - prefix[L-1].

15
New cards

Sliding Window Maximum

Finds the maximum in all subarrays of size k. Solved in O(n) using a Deque to store indices in decreasing order of values.

16
New cards

Binary Search on Answer

Used when the search space is monotonic. Instead of calculating the result, guess a value and check if it's 'feasible.'

17
New cards

Monotonic Stack

A stack that keeps elements in increasing/decreasing order. Used for 'Next Greater Element' problems in O(n).

18
New cards

Sieve of Eratosthenes

Finds all primes up to n in O(n log log n). Iteratively marks multiples of each prime as composite.

19
New cards

Euler's Totient Function (phi)

$\phi(n)$ counts integers $\le n$ that are coprime to n. For prime p, $\phi(p) = p - 1$. Used in RSA encryption.

20
New cards

Matrix Exponentiation

Solves linear recurrences (like Fibonacci) in O(log n) by raising a transformation matrix to the power of n.

21
New cards

Catalan Numbers

$C_n = \frac{1}{n+1}\binom{2n}{n}$. Counts valid parentheses, binary search trees, and polygon triangulations.

22
New cards

Geometric Series Sum

The sum of $a + ar + ar^2...$ is $\frac{a(1-r^n)}{1-r}$. If $|r| < 1$, the infinite sum is $\frac{a}{1-r}$.

23
New cards

Expected Value E[X]

The average outcome of a random variable: $\sum (value \times probability)$. Linearity of Expectation: E[X+Y] = E[X] + E[Y].

24
New cards

Kadane's Algorithm

Finds the maximum sum contiguous subarray in O(n) time using one pass.

25
New cards

Union-Find (DSU)

Data structure for tracking disjoint sets. Optimized by 'Path Compression' and 'Union by Rank' to nearly O(1) per operation.

26
New cards

Fast Fourier Transform (FFT)

Reduces polynomial multiplication from $O(n^2)$ to $O(n \log n)$. Essential for signal processing and large integer math.

27
New cards

Difference Array

Allows O(1) range updates. To add x to [L, R]: diff[L] += x, diff[R+1] -= x. Recover original values via prefix sum.

28
New cards

Z-Algorithm

Finds all occurrences of a pattern P in string T in O(n+m) time by computing longest common prefixes with the start of the string.

29
New cards

Rolling Hash (Rabin-Karp)

Uses a polynomial hash to compare strings in O(1) after O(n) preprocessing. Great for pattern matching.