A
algorithms
running times of, growth rates of 11 – 13
run-time analysis, worst-case run time 15
approximate solution 205
approximation algorithms 197
arrays
linked lists and 24 – 25
terminology 27
ASCII (American Standard Code for Information Interchange) 134
asymmetric key encryption 259
average case 70
quicksort, vs. worst case 75
AVL trees 151
B
balanced trees 141 , 150 , 164
AVL trees 151
B-trees 162 – 164
improving insertion speed with 143
rotation 151
splay trees 159
balance factor 154
base case, in recursion 44 – 45
Bellman-Ford algorithm 180
BFS (breadth-first search) 101 , 120
graphs, overview of 102 – 104
implementing BFS algorithm 113 – 117
implementing graph 111 – 112
overview of 106 , 109
shortest path problem, using breadth-first search 108 – 109
Big O notation 10 , 75
average case vs. worst case 72 – 75
establishing worst-case run time 15
merge sort vs. quicksort 71 – 72
run times 15 – 17 , 70
traveling salesperson problem 17 – 19
visualizing run times 13
binary search 3 , 142
running time of 10
binary_search function 8
binary search trees (BSTs) 143
binary trees 131 , 139
Bloom filters 253
breadth-first search. See BFS (breadth-first search)
brute-force algorithms, knapsack problem 204
BSTs. See binary search trees
B-trees 161
advantages of 162 – 164
bye function 48
C
cache, using hash tables as 88
call stack 46 , 47 – 49 , 49
character encoding 134
collisions 91 – 93
connected, acyclic graph 130
constant 71
constant time 94
countdown example, base case and recursive case 44 – 45
D
data structures
arrays
linked lists and 24 – 25
overview of 26
selection sort and 24
terminology 27
AVL trees 151
balanced trees 147 – 150 , 164
binary search trees (BSTs) 143
binary trees 131 , 139
B-trees 161
graphs
BFS, implementing 111 – 112
Dijkstra’s algorithm, implementation of 181 – 189
overview of 102 – 105 , 122
terminology 170 – 172
weighted 165
data structures ( continued )
hash tables 77 , 84 , 91 , 99 , 111
heaps 261 – 263
linked lists 24
probabilistic algorithms, HyperLogLog 255
queues, overview of 109
recommendation systems 231
splay trees 159
stacks
call stack 47 – 49
call stack with recursion 49 – 53
trees, depth-first search 126 – 129
D&C. See divide and conquer (D&C)
decision problems 268
deletions 30
depth-first search (DFS) 126 – 129
deque function 113
dictionaries 83
diff command 227
Diffie-Hellman key exchange 255
ephemeral Diffie-Hellman key exchange 259
Dijkstra’s algorithm 165 , 190
implementation of 181 – 189
terminology 170 – 172
working with 166 – 170
directed graph 112
distributed algorithms 252
divide and conquer (D&C) 56 – 63
quicksort 64 – 76
DNS cache 86
DNS resolution 86
duplicates, preventing 86 – 88
dynamic programming 228
knapsack problem 203 , 216
brute-force solution 204
dynamic programming solution for 205
FAQ 213 , 216 , 217
filling in grid 216
filling knapsack completely 220
items that depend on each other 219
overview of 206 – 208
stealing fractions of items 217
longest common substring problem 220
filling in grid 222 – 223
longest common subsequence 225
solution 224 – 225
E
edges, negative-weight 178 – 180
enqueue 113
Euclids algorithm 58
F
factorial function 49
feature extraction 233 – 237 , 243 , 246
Feynman algorithm 222
FIFO (first in, first out) 110 , 263
file directories 123 – 125
find_lowest_cost_node algorithm 184
Fourier transform 250
fruit classification example 229
G
golden ratio 266
graphs
BFS, implementing 111 – 112
Dijkstra’s algorithm, implementation of 181 – 189
overview of 102 – 105 , 122
terminology 170 – 172
weighted 165
greedy algorithms 191 , 202
knapsack problem 194 – 196
set-covering problem 196 – 197 , 201 – 202
calculating answer 199
code for setup 198
sets 201
greet2 function 48
greet function 48 , 49
growth rates of algorithms 11 – 13
guitar row 206 – 208
H
hash functions 97
hash tables 77 , 84 , 91 , 99 , 111
collisions 91 – 93
lookups 84 – 86
performance 93 – 95
hash functions 97
load factor 96 – 97
preventing duplicate entries 86 – 88
use cases, lookups 84 – 86
using as cache 88
heapsort algorithm 262
Huffman coding 136 , 133 – 139
HyperLogLog 253 , 255
I
inductive proofs 69
injective function 83
in-neighbors 105
ISO-8859-1 code 133
K
knapsack problem 194 – 196 , 203
adding items to 213 – 215
adding smaller item 216
changing order of rows 216
dynamic programming solution for 205
FAQ 213
filling in grid row-wise 216
filling knapsack completely 220
items that depend on each other 219
optimizing travel itinerary 217
overview of dynamic programming 206 – 208
revisited, brute-force solution 204
stealing fractions of items 217
k-nearest neighbors (KNN) 229
building spam filters, Naive Bayes classifier 243
overview of machine learning 241
recommendation system
feature extraction 233 – 237
features for 240
regression 238 – 240
stock market, predicting 244
training models, high-level overview of 224 – 228 , 229 – 246
L
Levenshtein distance 227
LIFO (last in, first out) 110 , 263
linear programming 263
linear regression 247
linear time 15
linked lists 24
deletions 30
selection sort 25 , 31 – 34
terminology 27
load factor 96 – 97
logarithmic time. See log time
logarithms 7
log time 10 , 15
longest common substring problem 220
filling in grid 222 – 223
longest common subsequence 225
making grid 221 – 222
solution 224 – 225
LSH (locality-sensitive hashing) 260 – 261
M
machine learning, overview of 241
map function 252
map/reduce 252
merge sort 70
vs. quicksort 71 – 72
min heaps 261 – 263
ML (machine learning)
stock market, predicting 244
training models, high-level overview of 244 – 246
N
Naive Bayes classifier 243
negative-weight edges 178 – 180
nondeterministic polynomial time (NP) 267
NP-complete problems 267 , 268 , 275 – 276
NP-hard problems 267 , 274 – 275
hard to solve, quick to verify 272
overview of 274 – 275
reductions 273
satisfiability problem 269 – 271
NP (nondeterministic polynomial time) 267
O
optical character recognition (OCR) 242
out-neighbors 105
P
parallel algorithms 251
partitioning 65
perfect hash function 83
performance 2
pivot 64
pointers 30
pop 113
power set 196
print function 47
priority queues 261 – 263
probabilistic algorithms, HyperLogLog 255
probabilistic data structures 254
push 113
P vs. NP problem 273
Q
queue data structure 109
quicksort 64 – 76
average case vs. worst case 72 – 75
Big O notation 75
divide and conquer 56 – 63
merge sort vs. 71 – 72
run times for 70
R
<i>Real-World Cryptography</i> (Wong) 260
recommendation systems 231
feature extraction 233 – 237
recursion 41 , 44 , 54
base case and recursive case 44
call stack 47 – 49
overview of 42
stacks, call stack with recursion 49 – 53
reduce function 252
reductions 273
regression 239
regression analysis, linear 247
regression, KNN (k-nearest neighbors) 238 – 240
rotation, in AVL trees 151 , 154
run-time analysis, worst-case run time 15
run times 15 – 17
visualizing 13
S
SAT (satisfiability) problem 269 – 271
search, binary search 5 – 9
selection sort 21 , 34 , 38 , 39
arrays and linked lists 24 , 31
terminology 27
arrays, overview of 26
deletions 30
insertion sort, inserting into middle of list 29
memory 22 – 23
selection sort, code listing 38
set-covering problem 196 , 267
calculating answer 199
code for setup 198
greedy algorithms for
approximation algorithms 197
shortest path 178
shortest-path algorithms, Dijkstra’s algorithm 165
shortest-path problem 104
terminology 170 – 172
using breadth-first search 108 – 109
simple search 5
spam filters, building with KNN 243
splay trees 159
stack data structure 46
stacks
call stack 47 – 49
call stack with recursion 49 – 53
stat command 133
subproblem 215
sum function 61 , 63
symmetric key encryption 259
T
tail recursion 53
topological sort 118
training 243
traveling salesperson problem 17 – 19 , 267
travel itinerary, optimizing 217
tree algorithms, file directories 123 – 125
tree insertion, improving speed with 143
trees 119 , 121 , 140
depth-first search 126 – 129
Huffman coding 133 – 139
overview of 122
U
unweighted graphs 170
UTF-8 (Unicode Transformation Format 8) 134
V
vectors 236
W
weighted graphs 170
weights 170
Wong, David, <i>Real-World Cryptography</i> 260
worst case 70