Write down the input values
A=4935,B=3050 Box 1 reads in the two positive integers.
Carry out the next 2 divisions
4935=1×3050+1885; 3050=1×1885+1165 Each time, A is replaced by B and B by the remainder.
Note when the flow chart stops
R=0⇒output B=5 The last non-zero remainder is the highest common factor.
List the remainders produced
1885, 1165, 720, 445, 275, 170, 105, 65, 40, 25, 15, 10, 5, 0 The remainders strictly decrease, so the flow chart must terminate.
Count the times Box 2 is carried out
divisions=14 One division is done for each pass round the loop.
Check that the output divides both inputs
4935=5×987,3050=5×610 The output is a common factor of the two inputs.
Check that no larger common factor exists
gcd(987,610)=1 The two quotients share no factor, so 5 is the highest common factor.
Note the order of the Euclidean algorithm
order log(min(A,B)) The Euclidean algorithm is extremely fast even for huge inputs.
Recall what a sorted list means
ascending order: a1≤a2≤⋯≤an Every item must be no larger than the item that follows it.
Recall the number of comparisons in one bubble-sort pass
pass k makes n−k comparisons Each pass leaves one more item in its final place, so it is one comparison shorter.
Recall the worst case for a bubble sort
21n(n−1) comparisons A reversed list forces every possible comparison to be made.
Note the order of a bubble sort
bubble sort has order n2 Doubling the length of the list roughly quadruples the running time.
Note the order of a binary search
binary search has order logn Each pass halves the number of items still under consideration.
Recall the lower bound for a bin-packing problem
bins≥⌈capacitytotal size⌉ No packing can use fewer bins than this, though the bound need not be attainable.
Note that bin-packing algorithms are heuristics
first-fit need not give the optimal packing A heuristic gives a good solution quickly but not necessarily the best one.
State the value output
output=5 The flow chart outputs the highest common factor of 4935 and 3050.