Beruflich Dokumente
Kultur Dokumente
o
o
Rotate to rebalance
to search
keep track of current discriminator, during range search you
may need to split and go down both branches, PR- quad tree has
exactly four children or is a leaf,
Tries: rooted, branches are labeled with letters, child nodes may
be null or have content, suffix trees
Suffix tree is a compressed trie with suffixes as keys and
positions in text as values, extremely efficient for finding
all distinct subsequences,
GRAPHS
A tree is an acyclic connected graph, cardinality of graph
is the number of vertices |G| = 6,
A path is simple if all vertices are distinct, a cycle is a
path with the same vertices starting and ending,
connected or not connected, directed or undirected,
weighted or unweighted paths, undirected, directed, or
directed acyclic graph (DAG)
Queue-based:
Shortest Path:
Source-target: given a weighted digraph, find the
shortest directed path from s to t (cost of path is
minimized), weights are arbitrary, worst case: go
through every vertex. Distance is inf if not
connected
Single source: from source to every other vertex
find all shortest paths. Unweighted graphs can use
BFS.
o Dijkstras (greedy)
All pairs shortest path:
Floyds (dynamic)
MST:
Prims: start with any source, add edge with
smallest weight, greedy, add edges that connect
vertices not yet in tree
Kruskals: sort edges in ascending order, add next
edge unless it creates a cycle. Greedily cluster objects
in increasing order of distance; stop when there are k
clusters
Algorithm Paradigms:
Designing algorithms: no recipe for designing
algorithms, know the problem, use existing
algorithms
Greedy: build up a solution incrementally, optimize
locally. Doesnt always find optimal solution
o Greedy choice property: global optimal is
reached from local greedy
o Optimal solution contains optimal solutions
to sub problems, optimal can be efficiently
reached
o Huffman tree, cashiers, activity selection,
knapsack,
Divide and Conquer: non-overlapping sub problems,
combine
o Quicksort, recursion kind of for computing
fibonacci
Dynamic Programming: series of overlapping subproblems, build up solution to larger problem
o Calculating nth Fibonacci, knapsack, edit
distance, shortest path