Notes+10.21

Computing factorials: it runs over too quickly to care how fast.

Triangular numbers: triangle(N) = 1 + 2 + 3 ... + N = N(N+1)/2 {Thanx, Laura} But if computed recursively, as shown in class code rsmoody@ctec:~/puzzles$ m a8.c
 * 1) include 

int f1(int nn) { if (nn <= 1) return (1); return (nn + f1(nn -1)); }

main { int kk; printf("Triangular numbers:\n"); for(kk=1; kk < 55; kk++) { printf("f1(%i)= %lu\n", kk, f1(kk)); } }

code it does a LOT more work. Tri(10002) = 10,025,003 which takes about 3 or 4 operations to compute by Laura's formula, at least 40,000 to compute recursively. Tiny numbers, even on a slow (1 Ghz) computer. The recursive solution would be ready in 40 micro-seconds. Doesn't feel compelling, does it? A factor of over 10,000 in efficiency did not get your attention?

We will practice **memoize**-ing = **cacheing** = remembering values which were expensive to compute. Web browsers make a page cache so they need not go out to the web to re-display recently visited pages.

Trees: know some terms.
 * node
 * leaf node, or just leaf
 * depth
 * height
 * level
 * balanced
 * binary
 * parent
 * child
 * size of a tree
 * sub-tree

Quick practice: in a tree defined on nodes which have //{left child, aString, right child}// where for now the only data carried by the tree is the collection of strings, inserted the first few words of the Gettysburg Address in aplhabetical order.

Airing a brain fart: I wasn't sure if there is "standard" terminology for "nearly balanced tree". I don't think there is. "Almost balanced tree" or "Almost well-balanced tree" Ref: [] "Perfect binary tree" is one with 2^n leaves. all on the same level (Wikipedia) A **complete binary tree** is a binary tree in which every level, //except possibly the last//, is completely filled, and all nodes are as far left as possible. A function for generating nearly balanced binary search trees from sets of non-random keys. R. A. Frost1, M. M. Peterson2 Article first published online: 27 OCT 2006 [] You can Goggle "nearly balanced tree" for more of the 36 million hits.