Start your revision by going through the lecture notes and the supervision problems.
This sheet breaks down past exam questions by topic. Try to answer around one from each topic. For the “lists” topic do as many as you can. Take note of the questions you had trouble with, so we can go through them during the revision class. As you gain more experience restrict yourself to examination conditions.
For the revision class, the only requirement is to attempt the 2014-2016 past papers.
Exercise [Check if a list is a permutation of another]: Write an OCaml function which given two lists determines if one is a permutation of the other. (This is 2009p1q1(d))
Exercise [Generalised permutation]: 2009p1q1 (e)
Exercise [Generate all possible permutations]: 2006p1q5 (b)
Exercise [Lazy permutation generation]: Modify your code about to lazily generate all permutations of a list.
Exercise [Generate all possible derangements]: Modify your code from the previous exercise to generate all possible derangements. A derangement is a permutation such that none of its elements maps back to its original position.
Exercise [Find the next permutation]: (+) Write an OCaml function which given a permutation computes the lexicographically next permutation. For example, given \([2; 3; 1; 4]\) it returns \([2; 3; 4; 1]\).
Exercise [Generate all combinations]: Given \(n\) and \(k\), write an OCaml function to generate all combinations. (Can you make it generate the combinations lazily?)
Exercise [Check if parentheses are balanced]: You are given a list containing (
and )
. Write a program in OCaml to check if a sequence of parentheses are balanced. A sequence of open and closed parentheses being balanced is defined recursively:
s
is balanced, then (s)
is balanced.s
and t
are balanced, then st
are balanced.
How efficient is your algorithm?Exercise [Generate all balanced parentheses]: Write a program in OCaml to generate all balanced parentheses.
Exercise [Lazy generation]: Modify your code from the previous exercise to lazily generate all balanced parentheses.
The lecture notes contain no mention of games, but these have appeared in past exam questions. If you want to gain a basic background, read pages 1 to 10 from Ferguson’s book.
In this exercise, you will solve the Lights Out puzzle using BFS, DFS and iterative deepening DFS. You are provided with Board.java
(Java class that represents the Lights out board) and DfsSolution.java
(Java class that implements a DFS solution for Lights Out).
DfsSolution.java
. Explain how/why it works.