CS
exam2topics(1)

# Hanoin moven left center right move0 x y z moven x y

• Notes
• 3

This preview shows pages 2–3. Sign up to view the full content.

hanoi(N) :- move(N, left, center, right). move(0, X, Y, Z). move(N, X, Y, Z) :- N > 0, M is N - 1, move(M, X, Z, Y), display([X,Y]), move(M, Z, Y, X). Trace the above program using the query hanoi(3) . Show all queries which are generated by the execution and all moves which are printed. You may wish to draw a tree to show this clearly.

This preview has intentionally blurred sections. Sign up to view the full version.

5. Consider the denotational semantics below: S [[ S 1 ; S 2 ]] store = S [[ S 2 ]] ( S [[ S 1 ]] store ) S [[ V := E ]] store = store [ E [[ E ]] store / V ] S [[ while C loop S end loop ]] store = if C [[ C ]] store then S [[ while C loop S end loop ]] ( S [[ S ]] store ) else store C [[ E 1 > E 2 ]] store = if E [[ E 1 ]] store > E [[ E 2 ]] store then true else false E [[ E 1 + E 2 ]] store = E [[ E 1 ]] store + E [[ E 2 ]] store E [[ E 1 E 2 ]] store = E [[ E 1 ]] store E [[ E 2 ]] store E [[ I ]] store = N [[ I ]] E [[ V ]] store = if store [[ V ]] = then else store [[ V ]] Assume that N returns the integer value of its argument. Given the initial store ( λ V . ) [1/u] [5/y] [5/z], compute the store which results from evaluating S on the program below, showing all steps used in the evaluation. while (u > 0) loop u := u - 1; z := z + y end loop
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern