=========================================================================== CSC 236 Tutorial Exercises for Week 10 Fall 2007 =========================================================================== A. This is the example in section 2.5 of the textbook, rephrased to use the same notation I use in lecture. Show that the following algorithm terminates: # Pre: x, y in N while x != 0 or y != 0: if x != 0: x -= 1 else: x = 16 y -= 1 B. Show that the following algorithm terminates: # Pre: x in N, x >= 1 while x != 1: if x % 2 == 0: x /= 2 else: x = 3 * x + 1 WARNING: This is not as easy as it looks! Trace it for some values of x (or code it up to display the sequence of values generated) to get a feeling for what's going on. C. (a) List the elements of {a,ab}*. Find a way to describe strings in this language, i.e., find a predicate P(s) such that P(s) is true iff s in {a,ab}*, for all strings s over alphabet {a,b,c}. (b) Find three different examples of a language L over alphabet {a,b,c} such that L = L.L (c) Find three different examples of a language L over alphabet {a,b,c} such that L = L* (d) Find three different examples of languages L_1, L_2 over alphabet {a,b,c} such that L_1.L_2 = L_2.L_1