401 kms

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/107

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

108 Terms

1
New cards
2
New cards

What is Dynamic Programming?

Breaking problem into subproblems and reusing their solutions

3
New cards
4
New cards

What are the 3 parts of ANY DP problem?

  1. Subproblem definition 2. Choices 3. Bellman equation
5
New cards
6
New cards

What is a Bellman equation?

Recurrence relation that builds the DP solution from subproblems

7
New cards
8
New cards

Template for solving DP problem?

  1. Define subproblem DP[…] 2. Identify choices 3. Write Bellman eq 4. Set base case 5. Fill table
9
New cards
10
New cards

What is the DP subproblem in Knapsack?

Max value using first i items and budget w → DP[i][w]

11
New cards
12
New cards

Bellman equation for Knapsack?

If cost > w → DP[i

13
New cards
14
New cards

DP subproblem in Word Segmentation?

Max goodness of first i letters → DP[i]

15
New cards
16
New cards

Bellman equation for Word Segmentation?

DP[i] = max over j < i of DP[j] + goodness(j+1 to i)

17
New cards
18
New cards

Base case in DP?

Usually DP[0] = 0 or DP[0][0] = 0

19
New cards
20
New cards

Exam strategy for DP problems?

  1. Define DP subproblem 2. Write Bellman eq 3. Set base case 4. Fill table step
21
New cards
22
New cards

Time complexity of Knapsack DP?

O(nC)

23
New cards
24
New cards

Time complexity of Bellman

Ford?

25
New cards
26
New cards
27
New cards

Algorithm to compute shortest paths to target node t in graph with negative edges

Reverse all edges. Run Bellman

28
New cards
29
New cards

How to store path info in Bellman

Ford?

30
New cards
31
New cards

How to print path from s to t?

Start at s, follow pred[] to t, print nodes on path

32
New cards
33
New cards
34
New cards

How do I find time complexity easily?

Count # of loops and how many things they touch. Multiply together.

35
New cards
36
New cards

Dynamic Programming (DP) problem meaning:

We solve small problems, store the answers, and build up to solve the big problem.

37
New cards
38
New cards

bellman equation for DP[i]?

DP[i] = max over j of (DP[j

39
New cards
40
New cards

BFS

A way to explore a graph by checking all neighbors first before going deeper (like ripples in water)

41
New cards

DFS

A way to explore a graph by going deep along one path before backtracking

42
New cards

Topological Sort

For tasks with dependencies, this puts tasks in order so each comes after its prerequisites

43
New cards

DAG Shortest Path

If tasks have no cycles, you can sort them and find shortest path super fast

44
New cards

Bipartite Graph

A graph where you can split nodes into 2 groups and edges only go between groups (not inside)

45
New cards

Check Bipartiteness

Color nodes with 2 colors. If it works without conflicts, graph is bipartite

46
New cards

Strongly Connected Components

A chunk where every node can reach every other node (in both directions)

47
New cards

Minimum Spanning Tree (MST)

Connects all dots with the least total wire (no loops, covers everything)

48
New cards

Kruskal’s Algorithm

Start with cheapest wires and keep adding until everything is connected

49
New cards

Prim’s Algorithm

Start from one dot and always add the cheapest wire going out

50
New cards

Interval Scheduling

Pick as many non

51
New cards

Interval Partitioning

Find out how many rooms you need to host all events (based on overlapping)

52
New cards

Scheduling to Minimize Lateness

Do the tasks with the earliest deadlines first to avoid being late

53
New cards

Huffman Coding

Compress text by giving short codes to common letters and long codes to rare ones

54
New cards

Coin Change Greedy

Keep taking biggest coins that fit the amount (works well with US coins, not always in weird coin systems)

55
New cards

Clustering (Greedy)

Group dots into k blobs by cutting the longest wires in MST

56
New cards

Optimal Caching

When your memory is full, throw out the item you won’t need for the longest time

57
New cards

Weighted Interval Scheduling DP

Choose best set of non

58
New cards

Knapsack DP

Pick items to fit in a backpack to get most value without going over weight limit

59
New cards

Sequence Alignment DP

Line up two sequences (like DNA or words) in the best matching way

60
New cards

Segmented Least Squares DP

Split data into chunks and fit best lines to balance accuracy + simplicity

61
New cards

RNA Secondary Structure DP

Find best way to match base pairs in RNA (A

62
New cards

Bellman

Ford DP

63
New cards

Distance Vector Protocol

Every computer updates its map of network distances by talking to neighbors

64
New cards

Merge Sort

Split list into halves, sort them, and merge back together

65
New cards

Count Inversions

Count pairs that are out of order by modifying merge sort

66
New cards

Master Theorem

Shortcut to solve problems where you split things into smaller chunks repeatedly

67
New cards

Closest Pair of Points

Split dots into halves, solve each, and check if closer pairs cross middle

68
New cards

Integer Multiplication (Karatsuba)

A faster trick to multiply big numbers by splitting into pieces

69
New cards

Matrix Multiplication

Split big grids into smaller grids and multiply faster

70
New cards

Convolution and FFT

Super fast way to multiply polynomials (used in signal processing too)

71
New cards

P

Problems computers can solve quickly (like sorting a list)

72
New cards

NP

Problems where if someone shows you a solution, you can check it quickly (like Sudoku)

73
New cards

EXP

Problems that take crazy long time to solve (exponential time)

74
New cards

NP

Complete

75
New cards

SAT

Can you set true/false values to make a big AND/OR puzzle true? (The first NP

76
New cards

3

SAT

77
New cards

Vertex Cover

Can you pick a small set of dots that touches all lines?

78
New cards

Clique

Can you find a group of dots where every pair is connected?

79
New cards

Subset Sum

Can you pick numbers from a list that exactly add up to target?

80
New cards

Reduction

A way to turn one problem into another to compare difficulty

81
New cards

co

NP

82
New cards

PSPACE

Problems that may take a long time but only need a little memory

83
New cards

Ford

Fulkerson Algorithm

84
New cards

Max

Flow Min

85
New cards

Bipartite Matching via Flow

Use flow tricks to match pairs (like students to projects)

86
New cards

Disjoint Paths via Flow

See if you can find k separate paths from point A to B without overlap

87
New cards

Project Selection

Choose set of projects to do that gives highest reward (use flow tricks)

88
New cards

Baseball Elimination

Check if a baseball team can still win based on remaining games (uses flow)

89
New cards

Asymptotic Notation (Big O)

Describes how fast an algorithm grows when input gets big (ignores small details)

90
New cards

Big O

Upper bound ("at worst, it’s this slow")

91
New cards

Big Omega

Lower bound ("it’s at least this fast")

92
New cards

Big Theta

Tight bound ("it’s exactly this speed")

93
New cards

O(1)

Instant, constant time

94
New cards

O(log n)

Tiny increase as input grows (like binary search)

95
New cards

O(n)

Linear, doubles if input doubles

96
New cards

O(n log n)

Fast

97
New cards

O(n²)

Slow for big data (like bubble sort)

98
New cards

O(2ⁿ)

Bad! Explodes fast (like brute force subsets)

99
New cards

Polynomial Time

Reasonably fast (n², n³ etc. is still manageable)

100
New cards

Exponential Time

Too slow to be useful for big inputs