Show worked solution
Worked solution
Write down the input values
Box 1 reads in the two positive integers.
Carry out the next 2 divisions
Each time, A is replaced by B and B by the remainder.
Note when the flow chart stops
The last non-zero remainder is the highest common factor.
List the remainders produced
The remainders strictly decrease, so the flow chart must terminate.
Count the times Box 2 is carried out
One division is done for each pass round the loop.
Check that the output divides both inputs
The output is a common factor of the two inputs.
Check that no larger common factor exists
The two quotients share no factor, so 5 is the highest common factor.
Note the order of the Euclidean algorithm
The Euclidean algorithm is extremely fast even for huge inputs.
Recall what a sorted list means
Every item must be no larger than the item that follows it.
Recall the number of comparisons in one bubble-sort pass
Each pass leaves one more item in its final place, so it is one comparison shorter.
Recall the worst case for a bubble sort
A reversed list forces every possible comparison to be made.
Note the order of a bubble sort
Doubling the length of the list roughly quadruples the running time.
Note the order of a binary search
Each pass halves the number of items still under consideration.
Recall the lower bound for a bin-packing problem
No packing can use fewer bins than this, though the bound need not be attainable.
Note that bin-packing algorithms are heuristics
A heuristic gives a good solution quickly but not necessarily the best one.
State the value output
The flow chart outputs the highest common factor of 4935 and 3050.