Learn all these terms:
n∑i=1c=cn | n∑i=1i=n(n+1)2 |
n∑i=1i2=n(n+1)(2n+1)6 | n∑i=0ri=1−rn+1r−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(log2n) 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());
}
}
}