Final Exam Flashcards
double memory
8
simple cycle
a cycle w/ no repeated edges or vertices
preorder ordering
if we save the vertex given as an argument to the recursive dsf() in a data structure, then iterate through it, we see all the graph vertices, in order determined by the nature of the data structure and whether we do the save before or after the recursive calls
order in which dfs() is called.
linear probing
method of open addressing for hashing When a new key collides, find next empty slot, and put it there. Simplest approach is Linear Probing (when we hash to a table index that is already occupied with a key different from the search key), then we just check the next entry in the table (by incrementing the index). Linear probing is characterized by identifying three possible outcomes: ■ Key equal to search key: search hit ■ Empty position (null key at indexed position): search miss ■ Key not equal to search key: try next entry
NFA
nondeterministic finite-state automata
A DFA changes from state to state by looking at a character from the text string based on the content of that character. A NFA can handle the or operation that makes a DFA unable to determine whether or not the pattern could occur at a given point.
Like DFA, starts at state zero, reading the first char of a text and then changing. Differently, however, - characters appear in the nodes, not the edges, in the diagrams (???) - nfa recognizes a text string only after reading all its characters;
DFA can end prematurely ways a NFA can move from one state to another:
- if the current state corresponds to a character in the alphabet AND the current character in the text string matches the character, the automaton can scan past the character in the text string and take the (black) transition to the next state. This is a match transition.
- The automaton can follow any red edge to another state w/o scanning any text character. That’s a E-transition, referring to the idea that it corresponds to matching the empty string E. Since an NFA may have multiple edges leaving a given site, the transition from such a state is not determinisitc
- it might take one transition at one point in time, and a different transition at another.
byte memory
1
simple path in a graph
serquence w/ no repeated vertices
cycle or path length
the number of edges in a cycle/path
cut property
given any cut in an edge-weighted graph, the crossing edge of minimum weight is in the MST (minimum spanning tree) of the graph
st-cut
a cut that places a vertex s in one of its sets and vertex t in the other
weighted quick union
UF implementation(enables union(p, q), find(p) connected(p, q) and count()) organized thusly: a site indexed id[] array organized such that the id[] entry for each site is the name of another site in the same component (possibly itself) find() follows until a root is reached; connected is find(a) == find(b). In this case, find requires 1 + 2 * depth of node corresponding to given site. From 1 to 2N + 1 array accesses. (2 array accesses for every miss; one to test if there’s a hit; another to change to next possible hit - usually just N + 1). union finds the roots of a and b, then makes one root point to another. Always linear. *** Weighted quick union improves on this by checking and always connecting the smaller with the larger tree. This ensures that the depth of any node is at most lg N. It uses an extra array sz[] to hold the node counts and slightly more code. The array starts w/ 1 for each id and then increments by the count of the root that’s being added to the larger tree. Worst case order of growth for find(), connected() and union() becomes log N. Path compression - making all find()-examined nodes point directly to the root makes this nearly constant time amortized. (an extra loop in the find() operation that sets the id[] entry corresponding to each node encountered along the way to link directly to the root).
acyclic graph
a graph with no cycles, ie no a path w/ at least one edge whose first and last vertices are the same
3-way radix quicksort
a hybrid of quicksort and msd
use three-way partitioning on the leading character of the keys, moving to the next character on only the middle subarray (keys w/ leading char equal to the partitioning character);
insertion sort w/ small subarrays restrict alphabet; shuffle the array to protect against worst case performance; for strings, since compareTo[] accesses chars in left-to-right order, all sorts are already MSD sorts uses 2NlnN compares on average good for general-purpose, and strings w/ long prefix matches.
lsd radix sort
good for short fixed-length stringsf least-significant digit string sort - Consider characters from right to left. - Stably sort using dth character as the key (using key-indexed counting). sort is stable linear time sorting for typical applications: no matter how large the value of N, it makes W passes through the data uses ~7WN + 3WR array accesses and extra space proportional to N + R to sort N items whose keys are W-character strings taken from a R-character alphabet
escape sequences
\ separating metacharacters from characters in the alphabet; otherwise escape sequences may signify special characters and whitespace
negative cycle detection
the digraph has a negative cycle reachable from the source if and only if the bellmanford queue is nonempty moreover the subgraph of edges in our edgeTo[] must contain a negative cycle So any vertex v is updated in pass V, there exists a negative cycle (and can trace back edgeTo[v] entries to find it)
inorder traversal
print all the keys in the left subtree, then the key at the root, and then t key in the right subtree, etc.
int memory
4
graph density
proportion of possible pairs of vertices that are connected by edges sparse graph graph has relatively few of the possible edges present dense graph has relatively few of the possible edges missing graph is sparse if its number of diff edges is within a small constant factor of V (# of vertices)
regular expression formal definition
either - empty (representing the empty set of strings, w/ 0 elements) - a single character (the set of strings w/ 1 element, itself) - a regular expression enclosed in parentheses (the same set of strings as the RE w/o the parentheses) - two or more concatenated regular expressions (the cross product of the sets of strings represented by the individual components - all possible strings that can be formed by taking one string from each and concatenating them in the same order as the REs) - two or more regular expressions separated by the or operator (|) (the union of the sets represented by the individual components) - a regulation expression followed by the closure operator (the empty string or the union of the sets represented by the concatenation of any number of copies of the RE)
graph connectedness
connected if there’s a path from every vertex to every other vertex in teh graph a graph that is not connected consists of a set of connected components, or maximal connected subgraphs
huffman compression steps
- read input 2. tabulate the freq of occurence of each char value in teh input 3. build the huffman encoding trie corresponding to those frequencies 4. build teh corresponding codeword table, to associate a bitstring w/ each char value in the input 5. write the trie, encoded as a bitstring. 6. write the count of chars in the input, encoded as a bitstring 7. use the codeword table to write the codeword for each input char.
reverse postorder
if we save the vertex given as an argument to the recursive dsf() in a data structure, then iterate through it, we see all the graph vertices, in order determined by the nature of the data structure and whether we do the save before or after the recursive calls reverse order in which dfs() returns.
put the vertex on a stack after the recursive calls reverse postorder in a DAG is a topological sort
adjacent vertices
when two vertices are connected by an edge