Sie sind auf Seite 1von 2

Tutorial 2

FIT 1029 Algorithmic Problem Solving


12 March 2015 Prepared by Julian Garca
The objectives of this tutorial are:
To get familiar with bit strings.
To understand selection sort and insertion sort.
To get familiar with fundamental algorithms involving lists and tables.

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 1: Bit strings


Construct a list consisting of all the bit strings representing the
subsets of S = { a, b, c}. Order the list in a way such that every
string differs from its immediate successor by one single bit. I
Given a set S and two subsets of it, A S and B S; design an
algorithm to find the subset of S given by A B. II

Could it be useful to think about


graphs in this problem as well?
II

Assume that subsets are represented


as strings of bits.

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

Suggestion: write down the sorting


algorithms as well, and follow them
carefully with the suggested list as
input.

IV

A similar algorithm is probably


behind: http://www.wordsmith.org/
anagram/

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.

tutorial 2. fit 1029 algorithmic problem solving

Task 5 : Standard deviation


Using pseudocode write an algorithm to calculate the standard deviation of a list of n real numbers.V

Task 6 : Magic squares

The standard deviation of a list of


real numbers
x1 , x2 . . . xn is defined as
q
n
1
2
=
n i =1 ( xi ) , where is the
average value of the list.

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.

Das könnte Ihnen auch gefallen