Tutorial 4: FIT 1029 - Algorithmic Problem Solving
Tutorial 4: FIT 1029 - Algorithmic Problem Solving
k .
Also, we will say that a directed integer is mobile in the list, if it is
greater than its immediate neighbour in the direction it is pointing.
For example, in the list [
3 ,
1 ,
2 ] only 2 is mobile.
tutorial 4. fit 1029 algorithmic problem solving 2
Consider the following algorithm and determine what is printed
2
.
2
Remember the Johnson-Trotter Algo-
rithm, used to generate permutations
and briey discussed in the lecture.
L [
3 ,
1 ,
2 ]
index index of the largest mobile integer in L
print L
while(index = 1) do
{
Swap L[index]with the immediate neighbour it is poiting at.
Reverse the direction on all integers larger than L[index]
print L
index index of the largest mobile integer in L
}
Write down an algorithm to perform the step
3
:
3
Remember the idea of module?
Reverse the direction on all integers larger than L[index]
Task 5
Consider the following types of items:
Type 1 2 3
Value $4 $13 $11
Weight 3kg 4kg 7kg
Suppose you have a knapsack of capacity 7kg. Write down all the
possible sets of items you could carry, together with their total
value.
Write down an algorithm to print out all possible sets of items and
their total value, for any given knapsack problem
4
.
4
A instance of the knapsack problem
is given by a list of values, a list of
weights, and a maximum knapsack
capacity
Task 6
In tutorial 2 we had the following problem:
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.
Describe an algorithm that provides the answer for any set S.