Comp 388-005 Week 5
Lewis Tower 415, 4:15-8:15
Welcome
Readings:
Traversing a Tree
Some ways to traverse a tree: traversers.cs
Alternative stack-based traverser
Queue-based traverser
Hash statistics
How many buckets can we expect to use?
If hashtable array size is M and there are N things
inserted, the fill ratio is λ = N/M
Poisson distribution: fraction of buckets with k items is
λke-λ/k!
k=0: e-λ
k=1: λe-λ
Suppose λ=2, so the average bucket has 2 items. Then we expect this:
k |
fraction |
0 |
13.5% |
1 |
27% |
2 |
27% |
3 |
18% |
4 |
9% |
5 |
3.6% |
6 |
1.2% |
Compiler
parsing: a, b, c, d, e are specific symbols, A, B, C are
higher-level constructs
A ::= a A | b B
B ::= c C { c e C }
C ::= d [ e C ]
We can parse this language with
parseA: if (token=A) {accept(a);
parseA();}
else {accept(b); parseB();}
parseB: accept(c); parseC(); while
(token==c) {accept(c); accept(e); parseC();}
parseC: accept(d); if (token==e)
{accept(e); parseC();}
machine code
recursive-descent compilation
expressions
if and while
global and local variables; stack
frames
recursion