Learn all these terms:
\(\displaystyle\sum_{i=1}^n c = cn\) | \(\displaystyle\sum_{i=1}^n i = \displaystyle\frac{n(n+1)}{2}\) |
\(\displaystyle\sum_{i=1}^n i^2 = \displaystyle\frac{n(n+1)(2n+1)}{6}\) | \(\displaystyle\sum_{i=0}^n r^i = \displaystyle\frac{1 - r^{n+1}}{r - 1}\) |
In a linked list we store a reference to one node, all other nodes are reachable by following \(O(n)\) references.
In a binary tree we store a reference to one node, all other nodes were reachable by following \(O(\log_2 n)\) references.
Trace the following traversal method...
public static <E> void mystery(BinNode<E> rt) {
Queue<BinNode<E>> queue = new LQueue<>();
queue.enqueue(rt);
while (queue.length() > 0) {
BinNode<E> cur = queue.dequeue();
visit(cur);
if (cur.left() != null) {
queue.enqueue(cur.left());
}
if (cur.right() != null) {
queue.enqueue(cur.right());
}
}
}