TESTSHEET2 - #L.0 #L(d, , )=l. #L.1 #L(d,t1,t2)= #L(t1)+...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Different sets —types— of lists (sequences or strings) are distinguished by their base types . For example, The set of String (Lists) of Integers: 1. λ Z* 2. if x Z and w Z* then w x Z* Examples— a few useful functions defined on lists: 1. length (#) :: Z* N . # λ = 0 # ( w x) = 1 + # w …i.e. suc(#x) 2. concatenation (^) :: (Z*, Z*) Z* w ^ λ = w w 1 ^ w 2 x = ( w 1 ^ w 2 )x 3. reverse :: Z* Z* reverse ( λ ) = λ reverse ( w x) = xreverse ( w) An inductive definition of trees: 1. (d, , ) is a binary tree. 2. If t1 and t2 are binary trees, then (d,t1,t2) is a binary tree. The tree’s height, h:: t →Ν h.0 h(d, , )=0. h.1 h (d,t1,t2)= Max(h(t1), h(t2)) +1 The number of nodes of a binary tree, #N:: t →Ν #N.0 #N(d, , )=1. #N.1 #N(d,t1,t2)= #N(t1)+ #N(t2) +1 The number of leaves of a binary tree, #L:: t
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: #L.0 #L(d, , )=l. #L.1 #L(d,t1,t2)= #L(t1)+ #L(t2)) The number of internal nodes of a binary tree, #I:: t #I.0 #I(d, , )=0. #I.1 #I(d,t1,t2)= #I(t1)+ #I(t2) +1 DEFINITIONS Let f and g be functions from N to R. Then f is asymptotically dominated by g (we say that f is O(g)) iff ( C,k|: ( x| x>k: |f(x)| C|g(x)|)) Let f and g be functions from N to R. Then f asymptotically dominates g (we say that f is (g)) iff ( C,k|: ( x| x>k: |f(x)| C|g(x)|)) Let f and g be functions from N to R. If f is O(g)) and f is (g)) then f is of order of g and we say f is (g). ( i| 1 i n:i) = n(n+1)/2 ( i| 0 i n:a i ) = (a n+1-1)/(a-1)...
View Full Document

Ask a homework question - tutors are online