Professional Documents
Culture Documents
For this tutorial assume that the following operations are defined on lists:
length(list): returns the length of the list
delete(index, list): deletes the item list[index].
join(list1, list2): returns the list where list1 is joined to the start of list2.
add(item, list): adds item to the end of the list.
insert(item, index, list): inserts item into the list so that it becomes the item list[index]
Task 2: Sorting
Describe the sequence of changes to the list [ A, L, G, O, R, I, T, H, M ]
as it is sorted alphabetically using insertion sort and selection sort. III
Task 3: Anagrams
Given a list of English words, describe an algorithm which can find
all the anagrams for a given word. For example, if you were given the
word post, you might return the list: [pots, spot, tops]. IV
III
IV
Task 4: Checkerboard
We use a square table with 1s and 0s to represent a checkerboard pattern. An element 1 represents a
black square, and 0 represents a white square. The element in row 0 and column 0 is assumed to be black.
Using pseudocode write an algorithm to produce a checkerboard pattern, taking as input any given square
matrix.
A magic square is a table with n rows and n columns, such that the numbers in each row, and in each
column, and the numbers in the main and secondary diagonals, all add up to the same number. Using
pseudocode write an algorithm to determine if a given table is a magic square.