- Chapter 3, #4
problem: first = last on full AND empty
Solution(s): don't let it get full (store N-1 max)
or keep full/empty bit and first and last
or keep front and length
- Chapter 3, #12
a. A single header cell H, with Next(H) = Prev(H) = h.
b. Two header cells H1 and H2, with Link(H1) = Link(H2) = 0.
If P and Q are set up to point at two successive list elements,
they should point to H1 and H2.
- Chapter 3, #13
|-- --| |-- --|
| | | |
| Link(Link(P)xor Q)| <---- | Link(Link(P)xor Q) xor P xor Q |
| Link(Q) | | Link(Q) xor P xor Link(P) xor Q|
| | | |
|-- --| |-- --|
- Chapter 4, #2
height + depth
- Chapter 4, #4
fan-out = f, height = h
max # nodes is 1 + f^1 + f^2 + ... + f^h = (f^(h+1) -1)/(f-1)
if tree has n nodes, then n <= (f^(h+1) -1)/(f-1)
h >= log_f (n * (f-1) +1) - 1
- Chapter 4, #6
n nodes: 1 root, n-1 edges
every leaf connected to exactly one edge
if L leaves, and we eliminate leaves and their edges, we
have a tree with (n - L) nodes
n - 1 = 2 (n-L)
n = 2L -1
nonleaves = n - L = L-1
- Chapter 4, #8
B(1) = 1, B(2) = 2, B(3) = 5, B(4) = 14
Idea: with n+1 nodes, 1 is the root, the remaining nodes are
divided into two subtrees, one of size i, the other of size (n-i).
B(n+1) = Sum(i=0, n, B(i) * B (n-i)), where B(0) = 1
- Chapter 4, #9
a. H(1) = 3, H(2) = 21, H(3) = 651, H(4) = 457653
A binary tree of height h+1 has either two subtrees of height h
or a left subtree of height h and a right subtree of height less
than h, or a left subtree of height less than h and a right
subtree of height h. So:
H(h+1) = H(h^2) + 2H(h)Sum(i=-1,h-1)H(i), with the base cases
H(-1) = H(0) = 1.
- Chapter 4, #13
A prefix expression is a number or the concatenation, in order,
of an operator and two prefix expressions.
See: Chapter 4, #13
- Chapter 5, #4
It suffices to swap the contents of the cells storing M[i,j] and
M[j,i] for each i and j. That is:
procedure SquareRMtoCM(table T, integer n):
//Table T represents an n by n array in row-major order
for (i=0 to n-1) do
for (j=0 to n-1) do
T[in+j] = T[jn+i]
- Chapter 5, #20
- Chapter 5, #32