Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
53 Cards in this Set
- Front
- Back
Stack |
FILO O(1) |
|
Queue |
FIFO O(1) |
|
Vector |
array has rank circular? slow to change, fast to access |
|
List |
DLL or SLL awareness of "before" and "after" fast to manipulate, slow to access |
|
Sequences |
methods of List and vector, implementation can vary |
|
Tree implementation (vector) |
layers from top to bottom, children are 2xrank and + 1 for right child |
|
Euler tour |
general tour for traversing a tree |
|
priority queue |
sorted queue with rank or weight total order relation can return smallest key |
|
Heap |
parent < children always balanced -> O(logn) binary tree implementation or array bottom up construction takes O(n) because of maximum path |
|
Selection Sort (for PQ) |
retrieves the smallest item from a sequence.
Runs in O(n^2) |
|
Insertion Sort (for PQ) |
places each item sortedly in the sequence
runs in O(n^2) but not always |
|
Heapsort |
implementing the sequence as a heap.
each insertion is logn, and retrieving is also logn. For n items, becomes nlogn
in place in an array shifting the "barrier" between heap and unsorted sequence |
|
Dictionary |
umbrella for sorted search methods KEYS has methods for key before and key after
|
|
Lookup Table |
sorted array with binary search: logn access
|
|
Binary Search Trees |
left < parent < right search is O(h)
insertion: trivial removal: take left most node of right-subtree and replace (if has leaf node, just delete) |
|
AVL |
balanced tree
logn access |
|
AVL proof of height |
looking at number of nodes stored when balanced with respect to height.
n(h) > 2 * n(h-2) (always more nodes than this)
so logn |
|
AVL insertion |
insert in correct location find z if unbalanced, y and z are children determine abc, switch around constant time |
|
AVL deletion |
delete: basic if leaf node, otherwise left most node of right subtree becomes node
z is first unbalanced, y and x are children of subtree with LARGER HEIGHT
logn steps worst case |
|
Merge Sort |
splitting into two parts, recursively sorting, then merging
Merging: smallest object of each, proceed, merge takes O(n1+n2)
total nlogn |
|
Sets (merging) |
smallest element from the front of both sorted parts, when one runs out, just let the other one finish |
|
QuickSort |
3 parts: less than pivot, pivot, greater than pivot
recursively sort
random pivot selection: expected runtime nlogn worst is still n^2 |
|
in place quicksort |
pivot and flipping elements over the pivot if smaller |
|
Bucket sort |
O(n + N)!!!
place all elements into buckets then remove from buckets |
|
Radix Sort |
lexicographically sorting pairs
from back to front
runs O(d(n+N)) with d being the length or depth of sorting |
|
divide and conquer |
solving distinct sub-problems and then combining |
|
integer multiplication (D&C) |
splitting large and small orders
expanding the multiplication
using a substitution for the mixed part, then storing answers and O(n^1.585) |
|
Dynamic programming |
similar to DC bt more powerful
subproblems can overlap - store solutions
3 properties: - must be able to break problem down - optimal subproblems must give optimal solution - overlapping is GOOD |
|
DP example change of coins |
building network from the bottom up
storing solutions and using them later |
|
Graph |
vertices and edges
directed
cycles |
|
Spanning tree |
of a connected, undirected graph is a subgraph with all vertecies but no cycles and is fully connected |
|
Graph important methods |
isAdjacent(v,w), adjacentVertices(v)
deleteVertex(v)
these will be compared frequently
|
|
Structures |
Edge List Adjacency List Adjacency Matrix |
|
Edge List |
vertices are objects in list
edges are objects in container, link to vertices
runtime mostly O(E) |
|
Adjacency List |
builds on Edge list,
Vertex now contains container of edges to link to, and edges link to that container
runtime now dependent on deg(v) or minimum of deg(u),deg(v) |
|
Adjacency matrix |
builds on edge list,
edges are stored in a vertex matrix, each vertex has an index
null = no link, object = link present
areAdjacent no O(1), rest in n and space O(n^2) |
|
DFS BFS |
both take O(V + E) time |
|
DAG |
directed, acyclic graph
can find topological ordering |
|
topological ordering of DAG |
enqueue with in-degree 0
dequeue with 0, reduce all linked vertices in-degree and store its rank. Repeat with new vertices that are no 0
O(V+E) |
|
Strings algs |
Brute Force BM - Last occurence function KMP - Failure Function |
|
Boyer Moore |
scanning from back of pattern
last Occurence function for each letter in alphabet
jumpy by according m to align or entire length if not in pattern or 1 if neither
still O(mn) |
|
KMP |
Failure Function: - length of prefix that is suffix of current position
i and j counter, j updated by F(j-1) if j > 0 otherwise j = j + 1
O(m + n)
|
|
Trie |
standard -> compressed -> compact
use special character to deal with prefix |
|
standard trie |
O(n) space where n is the total length of all strings
height is longest string
finding string: O(dm) - note not dependent on n |
|
compact trie |
space is O(s) where s is the number of strings |
|
suffix trie |
all suffixes of a potential trie, compactable
pattern matching O(dm) with d being length of alphabet |
|
1D range tree |
findall in O(logn + s)
O(n) space |
|
2D range search |
auxiliary structures are subtrees root v sorted with y
Range search: O(log^2 n + s)
Space nlogn (getting worse) |
|
QuadTree |
region in quads, can be greatly impalanced
O(sqrt(n) + s) for 2D |
|
k-D tree |
point or region based. point is balanced, height logn
nearest neighbour is O(n) worst but O(logn) expected |
|
DFS / BFS running time |
O(V+E) |
|
DAG sorting |
O(V+E) |
|
k-D tree building time |
O(knlogn) |