


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Solutions to exam 1 of cos 126 fall 2006. It includes answers to short answer questions, corrections for errors in arrays, functions, loops, strings, i/o, and recursion. It also covers the toy (techniques for object-oriented yacc) no-ops.
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



(b) 2N^ (because the string length doubles at each iteration)
computes "n + 1" In general, Ack(1, n) = Ack(0, Ack(0, ........ Ack(1, 0))), with "n" Ack(0, ...) and one Ack(1, 0). Since Ack(1, 0) is 2, and the other "n" Acks add 1 onto the previous result, we get n + 2. (c) Ack(2, 0) = Ack(1, 1) = 3 Using the fact that Ack(1, n) = n + 2. Ack(2, 3) = Ack(1, Ack(2, 2)) = Ack(1, Ack(1, Ack(2, 1))) = Ack(1, Ack(1, Ack(1, Ack(2, 0)))) = 2 + 2 + 2 + 3 = 9 Using the facts that Ack(2, 0) is 3 and that Ack(1, n) computes "n + 2". Ack(2, 6) = Ack(1, Ack(2, 5)) = Ack(1, Ack(1, Ack(2, 4))) = Ack(1, Ack(1, Ack(1, Ack(2, 3)))) = 2 + 2 + 2 + 9 = 15 Using the fact that Ack(2, 3) is 9 and that Ack(1, n) computes "n + 2". In general, Ack(2, n) = Ack(1, Ack(1, .... Ack(2, 0))), with "n" Ack(1, ....) and one Ack(2, 0). Since Ack(2, 0) is 3 and the other "n" Acks add 2 onto the previous result, we get 2n + 3.