== Helper Algorithm ==
Is_ith_Bit_Set(Num, i) :
if ( ( (2 ^ i) bitwise-AND (Num) ) > 0 ) : then return true
else : return false
== Main Algorithm ==
Get_Number_Of_Coins (V) :
1 :
Let n <- Number of coins available, so that coins of denominations (2 ^ 0), (2 ^ 1) ... (2 ^ (n-1)) are available.
2 :
Let N(V) <- floor(V / (2 ^ (n - 1)))
i.e. N(V) is the quotient (rounded to nearest lower integer if required) when V is divided by (2 ^ (n - 1))
3 :
Let R(V) <- V mod (2 ^ (n - 1))
i.e. R(V) is the remainder when V is divided by (2 ^ (n - 1))
4 :
Now, for the particular i'th bit set in the binary-representation for (2 ^ (n - 1)), coin of that particular denomination, multiplied by N(V), needs to be taken.
5:
Additionally, for every i'th bit set in the binary representation of R(V), 1 coin each for that particular denomination, needs to be taken.
Examples :
Let n = 5, so that coins of denominations (2 ^ 0), (2 ^ 1), (2 ^ 2), (2 ^ 3), (2 ^ 4) are available.
That is, coins of denominations, 1, 2, 4, 8, 16 are available.
Running-Time :
Since we are dealing only in binary, so the running time is O(lg V). In other words, O(number of bits for the integer word on a computer).
5. (3 points) Consider a hypothetical country Binary Land where they only use coins. There are...
Making Change: Given coins of denominations (value) 1 = v1 <
v2< … < vn, we wish to make change for an amount A using as
few coins as possible. Assume that vi’s and A are integers. Since
v1= 1 there will always be a solution.
Formally, an algorithm for this problem should take as input:
An array V where V[i] is the value of the coin of the ith
denomination.
A value A which is the amount...
The Hungarian algorithm: An example
We consider an example where four jobs (J1, J2, J3, and J4) need
to be executed by four workers (W1, W2, W3, and W4), one job per
worker. The matrix below shows the cost of assigning a certain
worker to a certain job. The objective is to minimize the total
cost of the assignment.
J1
J2
J3
J4
W1
82
83
69
92
W2
77
37
49
92
W3
11
69
5
86
W4
8...