CSC 403 - Data Structures II FINAL REVIEW
left-leaning red-black BSTs
1. represent 2-3 tree as a BST 2. use "internal" left-leaning links as "glue" for 3-nodes
2-3 Tree
2-node: 1 key, 2 children 3-node: 2 keys, 3 children perfect balance, symmetric recursive
LSD (Least Significant Digit)
LSD sorts fixed-length strings in ascending order.
BST - Binary Search Tree
a binary tree in symmetric order. each node has a key and every node's key is either: 1. larger than all keys in it's left subtree or 2. smaller than all keys in its right subtree
java definition of BST
a reference to a root Node
Keys
assume they're comparable (compareTo()); use equals(); use hashCode() to scramble key
adjacency list
based on iterating over vertices adjacent to v
potential issue with hashing?
collision - two keys w/ the same index
Node
comprised of 4 fields: a Key & Value, reference to left & right subtree
Dijkstra's algorithm
consider vertices in increasing order of distance from s. add vertex to tree and relax all edges pointing from that vertex. optimal for dense graphs.
symbol table applications
dictionary, book index, web search, compiler, DNS, file system. use immutable types for symbol tables: string, integer, double, java.io.File
topological sort
directed graph - linear ordering of its vertices
Binary Search
examine the middle key, if it matches, return it's index. otherwise, search either the left or right half.
how do you find the shortest path of BFS
find path from s to t that uses the fewest # of edges
rank
how many keys < k
m.find() returns true when?
if the pattern matches any part of the text string, false otherwise
m.lookingAt(); returns true when?
if the pattern matches at the beginning of the text string, false otherwise
m.matches() returns true when?
if the pattern matches the entire text string, false otherwise
regular expression package & implementation
import java.util.regrex.*; Pattern p = Pattern.compile("[a-z]+"); Matcher m = p.matcher("Now is the time");
symbol table
insert a value with a specified key. i.e. insert URL w/ specified IP address.
floor
largest key <= to a given key
which way do red nodes lean?
left
what do 2-3 trees have a 1-1 correspondence with?
left-leaning red-black BSTs
operations of strings
length(); charAt(); substring(); concat();
BST tree shape depends on what?
order of insertion
put()
overwrites old value w/ new value (symbol table) public boolean contains(Key key) { return get(key) != null; }
cycle
path whose first and last vertices are the same
MSD (most significant digit)
recursively sort all strings that are sorted according to first char; too slow for small subarrays; cache inefficient
m.replaceAll(replacement)
returns new string where every substring matched by the pattern is replaced
m.replaceFirst(replacement)
returns new string where the first substring matched by the pattern has been replaced
rotateLeft()
returns root of resulting binary tree so parent pointer can be updated
Hashing
save items in a key-indexed table. method for computing array index from key.
path
sequence of vertices connected by edges
why left-leaning red-black BSTs?
simplest balances BSTs to implement & among the fastest
ceiling
smallest key >= to a given key
steps of inorder traversal
traverse left subtree enqueue key traverse right subtree - yields keys in ascending order
collisions (hashing)
two distinct keys hashing to same index
hashCode()
use to scramble key. built in to java
==
use when field is a primitive type
equals()
use when field is an object
adj
vertices adjacent to v
is BFS FIFO or LIFO?
vertices in a queue, FIFO
is DFS FIFO or LIFO?
vertices on a stack, LIFO
does topological sort work with negative edge weights?
yes
is the StringBuilder Data type mutable?
yes; resizing char[] array and length