View
46
Download
3
Category
Preview:
Citation preview
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 1 of 33
PARTY SUBMITTING SOLUTION REPORT:
_______________________________________________________
AGREEMENT NUMBER: ____________ PROGRAM ADDENDUM NUMBER: ____________
DATE OF SUBMISSION: ____________ PROGRAM ID (WHERE APPLICABLE): ____________
TITLE OF PROPOSED SOLUTION:
EXTRACTION OF THE ALGORITHM OF A CLASSICAL SOLUTION OF THE EIGHT COINS PROBLEM AND USE OF THE
ALGORITHM FOR COMPUTING SOLUTIONS FOR N COINS PROBLEM
(RFI NUMBER)
RESEARCHER(S):
RAJAT KUMAR PAL, PAPIYA SENMAJUMDAR, SRIJONI MAITRA
(ENTER THE NAME(S) OF THE RESEARCHER(S))
NOTE: To qualify as a researcher, a person must contribute to the conception of the proposed solution. The following examples are typically insufficient to qualify a person as a researcher: (a) simply coming up with a problem to be solved; or (b) carrying out routine tasks or experiments at someone else's instruction which implement details. Naming the researcher(s) correctly is extremely important. Naming the wrong researchers may result in the invalidity or unenforceability of the patent. It is important NOT to name someone as a researcher just because of the person's position or title – this issue must be determined only on the basis of specific contribution to this proposed solution.
ASIDE FROM YOUR EMPLOYER, DOES ANYONE ELSE (FOR EXAMPLE, A RESEARCH SPONSOR)HAVE ANY RIGHTS TO THE PROPOSED SOLUTION? IF ‘YES’ OR ‘NOT SURE’ PLEASE ATTACH BRIEF EXPLANATION.
YES ___ NO __ NOT SURE ___
DID YOU USE GOVERNMENT FUNDING FOR DEVELOPMENT OF THE PROPOSED SOLUTION? YES ___ NO __
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 2 of 33
NOTE : (CO) RESEARCHER 1 REFERS TO THE MAIN CONTACT PERSON IV LIAISES WITH AND HE/SHE SHARES EQUAL RIGHTS WITH THE CO-INVENTORS
UNLESS THE CONTRACT STATES OTHERWISE. IF A PATENT IS ISSUED, THIS NAME WILL APPEAR AS THE FIRST NAME ON THE CERTIFICATE.
(C0)RESEARCHER 1
RAJAT KUMAR PAL
(FULL LEGAL NAME)
9B, MIDDLE ROAD, PO: SANTOSHPUR
(GARFA)(HOME ADDRESS)
KOLKATA 700 075, WEST BENGAL, INDIA(HOME ADDRESS CONTINUED)
UNIVERSITY OF CALCUTTA
(EMPLOYER)
READER (ASSOCIATE PROFESSOR)(POSITION / TITLE)
DEPARTMENT OF COMPUTER SCIENCE &ENGINEERING
(WORK ADDRESS)
92, A. P. C. ROAD, KOLKATA 700 009,INDIA
(WORK ADDRESS CONTINUED)
RAJATKP@VSNL.NET +91-33-23501857(WORK EMAIL) (WORK PHONE)
RAJATKP@VSNL.NET +91-33-24185987(HOME EMAIL) (HOME PHONE)
(SIGNATURE)
(C0)RESEARCHER 2
PAPIYA SENMAJUMDAR
(FULL LEGAL NAME)
35/4, KANTI CHARAN PATH, PO:SHYAMNAGAR, 24 PGS(N)(HOME ADDRESS)
PIN 743 127, WEST BENGAL,INDIA(HOME ADDRESS CONTINUED)
UNIVERSITY OF CALCUTTA
(EMPLOYER)
STUDENT (M.SC.)(POSITION / TITLE)
DEPARTMENT OF COMPUTER SCIENCE &ENGINEERING
(WORK ADDRESS)
92, A. P. C. ROAD, KOLKATA 700 009,INDIA
(WORK ADDRESS CONTINUED)
PAPIYA.SENMAJUMDAR@GMAIL.COM
(WORK EMAIL) (WORK PHONE)
PAPIYA.SENMAJUMDAR@GMAIL.COM
+91-33-25956461/+91-9831875655(HOME EMAIL) (HOME PHONE)
(SIGNATURE)
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 3 of 33
(C0)RESEARCHER 3
SRIJONI MAITRA
(FULL LEGAL NAME)
108, MANICKTALA MAIN ROAD,SUPERWAY ESTATE FLAT-19(HOME ADDRESS)
KOLKATA 700 054, INDIA(HOME ADDRESS CONTINUED)
UNIVERSITY OF CALCUTTA
(EMPLOYER)
STUDENT (M.SC.)(POSITION / TITLE)
DEPARTMENT OF COMPUTER SCIENCE &ENGINEERING
(WORK ADDRESS)
92, A. P. C. ROAD, KOLKATA 700 009,INDIA
(WORK ADDRESS CONTINUED)
SRIJONI.MAITRA@GMAIL.COM
(WORK EMAIL) (WORK PHONE)
SRIJONI.MAITRA@GMAIL.COM
+91-33-23208485/+91-9830994880(HOME EMAIL) (HOME PHONE)
(SIGNATURE)
(C0)RESEARCHER 4
(FULL LEGAL NAME)
(HOME ADDRESS)
(HOME ADDRESS CONTINUED)
(EMPLOYER)
(POSITION / TITLE)
(WORK ADDRESS)
(WORK ADDRESS CONTINUED)
(WORK EMAIL) (WORK PHONE)
(HOME EMAIL) (HOME PHONE)
(SIGNATURE)
(Attach additional Co-Researcher information sheets as necessary)
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 4 of 33
1. MAIN PROBLEM BEING ADDRESSED
Our aim is to extract the algorithm behind the classical solution of the eight coins problem, and generalise the algorithm to solve any given n coins problem, where n=2P for p3. So, at first we need to describe the eight coins problem.
Eight coins problem is a well-known problem in Mathematics as well as in Computer Science. In this problem eight coins are given, say A, B, C, D, E, F, G, and H, and we are told that only one is counterfeit (or false), as it has a different weight than each of the others. We want to determine which coin it is, making use of an equal arm balance. At the same time we want to identify the counterfeit coin using a minimum number of comparisons and determine whether the false coin is heavier or lighter than each of the remaining.
Now, we extend the problem to n coins, where the n coins problem is defined in the same way, and n having the value same as 2P (where p3). This means that n is a power of two, greater than eight. Thus the various n coins problems can be 16 coins problem, 32 coins problem, 64 coins problem, and so on.
2. SUMMARY OF THE INVENTION (MAXIMUM OF 150 WORDS)
The invention discussed here is the algorithm developed to solve the n coins problem. The algorithm has been extracted and developed by viewing and realizing the beauty behind the classical solution existing for the eight coins problem. Utilising the algorithm behind the eight coins problem, we develop our own new algorithm, which is in fact a generalised algorithm of the eight coins problem. In other words, there is no algorithm in solving the eight coins problem in literature though a solution is there as a classical solution that is shown in Figure 1. This new algorithm is a true generalization as we can use the same in solving n coins problem for any n=2P, where p3 (which includes solving the well known eight coins problem, i.e. when p=3). Here in this algorithm a decision tree structure is computed based on the weight of the coins. Each time a decision is taken based on whether the weight of the coins in one pan of the equal arm balance is equal to or greater than or lesser than the weight of the coins in the other pan. Finally we reach to a decision in finding a definite coin as either heavier or lighter than each of the remaining coins as a leaf vertex of the decision tree.
The novelty of this algorithm is that it uses the minimum number of comparisons to find out the counterfeit coin, amongst the n number of coins. At each step, the algorithm explicitly tells which coins to be kept on which pan for comparison, using the equal arm balance. The algorithm can be applied to find out counterfeit objects, not only coins, but also jewellery and other antique objects, where the forgery can be detected by checking the weight against known correct objects.
3. HOW IS THIS INVENTION MADE AND USED
3.1 Introduction
At first we discuss about the existing classical solution of the eight coins problem; the solution of the problem is shown in Figure 1.
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 5 of 33
Figure 1:- The existing solution of the eight coins problem in the form of a decision tree.
In this section we describe the solution of the existing eight coins problem in literature [2, 4, 5]. The solution is shown in Figure 1, which is a decision tree. The tree in this figure represents a set of decisions by which we can get the solution(s) of our problem. This is why it is called a decision tree. We use upper-case H or L as suffix to represent the counterfeit (or false) coin as heavier or lighter, respectively. In the solution of the eight coins problem in the form of a decision tree in Figure 1, each internal vertex (other than leaf vertices) represents a comparison between a pair of sets of coins using an equal arm balance. Needless to mention that in this comparison both the sets contain equal number of coins.The tree starts with a vertex, where it considers three coins be kept on either side of the equal arm balance. Surely, if we consider all the eight coins at a time to distribute them into two sets of four coins each to be compared, then it is an useless comparison as one coin out of eight coins is given as counterfeit (or false). So we cannot start with all the coins at a time to be compared for finding out the false coin; rather it leads a redundant comparison.In the decision tree in Figure 1, we consider three coins on a side of the equal arm balance, which is the root of the tree. If the weight-sums are equal, then surely each of these coins is a true coin, and the false coin is either 7 or 8 with their possibilities either heavier or lighter. In this situation as 1 is a true coin, which we use in comparing separately with 7 and 8 after a comparison between 7 and 8themselves.If the weight-sum containing coin 1 is less than the weight-sum containing coin 4 (i.e., 1+2+3 < 4+5+6), then we can say that the false coin is either of these six coins only, where either 1 is lighter, or 2 is lighter, or 3 is lighter, or 4 is heavier, or 5 is heavier, or 6 is heavier. At the same time in this situation, both 7 and 8 are true coins. The next comparison is highly important in order to make the height of the tree as small as possible; we do three things as follows: (i) keep a pair of coins 1 and 5 on their own sides, (ii) another pair of
1+2+3 : 4+5+6
1+4 : 2+5
>=<
1+4 : 2+5 7 : 8
8 : 11 : 8 3 : 8 2 : 8 7 : 1 1 : 7 8 : 2 8 : 3
<
1L 5H
<
3L 6H
< <
7L
<
7H
<
4L
<
3H
<
6L
< < <= = >>>
2L 4H 8H 8L 2H 1H 5L
= = = = = = = =
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 6 of 33
coins 2 and 4 interchange their sides, and (iii) the remaining pair of coins 3 and 6 are removed from the comparison. So subsequently the weight-sum of 1 and 4 (i.e., 1+4) are compared with the weight-sum of 2 and 5 (i.e., 2+5). Three cases may arise.CASE 1. If weight-sums are equal, then either 3 or 6 is a false coin (as these coins are removed from this comparison), where either 3 is lighter or 6 is heavier (following the root of the tree). So, we compare 3 with 1 (a true coin). If the weight of 1 is more than the weight of 3, then 3 is lighter; otherwise, these two coins must have the same weight resulting 6 as heavier.CASE 2. If 1+4 < 2+5, then certainly either 1 or 5 is a false coin, as these coins are kept in their own sides and the logical relation (following the root of the tree) is unchanged. Here either 1 is lighter or 5is heavier. So, we compare 2 (a true coin) with 1. If the weight of 2 is more than the weight of 1, then 1 is lighter; otherwise, these two coins must have the same weight resulting 5 as heavier.CASE 3. In a similar way, if 1+4 > 2+5, then definitely either 2 or 4 is a false coin, as these coins have interchanged their sides and the logical relation (following the root of the tree) has also changed. Here, either 4 is heavier or 2 is lighter. So, we compare 2 with 1 (a true coin). If the weight of 1 is more than the weight of 2, then 2 is lighter; otherwise, these two coins must have the same weight resulting 4 as heavier. Similarly, we may consider the case of weight-sums following the remaining branch of the root of the tree, where 1+2+3 > 4+5+6. Here either 1 is heavier, or 2 is heavier, or 3 is heavier, or 4 is lighter, or 5 is lighter, or 6 is lighter. The remaining part of the subsequent comparisons is done in a similar way as it is explained above and shown in Figure 1.
Figure 2:- The existing solution in Figure 1 with some modification along the case of equality, following the root of the decision tree.
In developing our algorithm we minimally modify the classical solution in order to compute a better solution in terms of comparisons as shown in Figure 2. Now to minimize the number of comparisons, for the equality case at the root we do not compare the 7th and 8th coin. This is because one out of the 7th and 8th coin is counterfeit, and so they are of unequal weight. We remove this redundant
1+2+3 : 4+5+6
1+4 : 2+5
>=<
1+4 : 2+5 7 : 1
8 : 11 : 8 3 : 8 2 : 8 8:1 8 : 2 8 : 3
<
1L 5H
<
3L 6H
< <
7L
. >
7H
<
4L
<
3H
<
6L
< < <= = >>>
2L 4H 8L 8H 2H 1H 5L
= = =
=
= = =
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 7 of 33
comparison and compare the 7th coin with the 1st coin (which is a known correct coin). If they are of unequal weight it means that the 7th coin is faulty and we find out whether it is heavier or lighter from this comparison only. Otherwise it is understood that the 8th coin is faulty. In which case we compare the 8th coin with the known correct coin 1, and find out whether it is heavier or lighter.The extraction of the algorithm behind the eight coins problem is fully based on the decision tree structure drawn to solve the problem (in Figure 2).
3.2 Description of the Algorithm
The n coins problem is solved using the procedure n_coin_problem as described here in this section and the steps of the procedure are shown in Section 3.3. This procedure takes as inputs, the starting index of the n coins, and the number of coins. This procedure then calls the less_than function or the greater_than function depending on the weight of the pans. The function less_than is called when in the first comparison (that is done at the root of the decision tree) the weight of the left pan is less than that of the right pan. Similarly, the function greater_than is called when the left pan is heavier than the other. These functions are recursively called within each of the functions until only two suspect coins (of whom one is certainly a counterfeit coin) are left. As the tree structure goes down, each of these procedures eliminates some coins at each stage, until the number of suspect coins is two. At this stage these functions take the help of the check function. This check function helps to identify the counterfeit coin among those two suspect coins, with the help of a known correct coin. When the procedure n_coin_problem is being called recursively, and the number of remaining coins is only two or only four, then the procedure calls the 2_coin_problem or the 4_coin_problem, respectively (instead of calling the n_coin_problem again). Basically, these two procedures act as the base case when we are calling the n_coin_problem recursively. Now, let us look at the working of the algorithm.
Now we start with the problem under consideration.
INPUT: - Number of coins n (out of which only one coin is counterfeit, either heavier or lighter).
OUTPUT: - The index of the counterfeit coin, z (where z is an integer) and declaring whether it is heavier or lighter.
In developing the algorithm that actually solves the eight coins problem, as shown in Figure 2, we now consider each of the procedures as outlined above in isolation and explain how they work. We start with the main procedure, i.e., the n_coin_problem.
Procedure n_coin_problem in brief:
We have been given n coins, out of which one coin is counterfeit. To find the counterfeit coin (and also whether it’s heavier or lighter), we use the decision tree structure. We call the n_coin_problemwith start=1 and number of coins=n, i.e. in the following way: n_coin_problem(start,n). Here, start indicates the starting index of the coins to be considered or compared, and n is the size of the problem, i.e. the number of coins. The total number of possible outcomes in case n coins problem is equal to 2*n. We first determine the number of coins to be kept on each of the pans of the equal arm
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 8 of 33
balance. This is given by 3x, where x=n/8. Thus, 6x coins are compared initially. We can have three possible cases or outcomes –
1. Left pan is lighter than the right pan. This case is handled by the less_than function. Since the left pan is lighter, it means that any one of the 3x coins kept in the left pan is lighter, or any one of the 3xcoins kept in the right pan is heavier. From this condition we can reach 2*3x=6x number of possible outcomes as leaf nodes. The counterfeit coin exists between the coins indexed by start and 6x. The left pan contains the coins indexed from start through 3x, and the right pan contains the coins indexed from 3x+1 through 6x. The 1st coin on the left pan is indexed by S_left (i.e. at the beginning it is same as start). Similarly the 1st coin of the right pan is indexed by S_right, (i.e. at the beginning it is the coin same as 3x+1).
2. Left pan is heavier than the right pan. This case is handled by the greater_than function. Since the right pan is lighter, it means that any one of the 3x coins kept in the left pan is heavier, or any one of the 3x coins kept in the right pan is lighter. Likewise, from this condition we can reach 2*3x=6xnumber of possible outcomes as leaf nodes. The indexing is the same as in the previous case.
3. Both the pans are equal. Since the pans are equal, it means that the 6x coins compared at the root are correct. The counterfeit coin then lies in the 2x number of coins yet to be considered. In this case, i.e. the case of equality, the n coin problem gets reduced to 2x coins problem. To solve this 2x coins problem, we call the n_coin_ problem recursively, with the number of coins now equal to 2x. Since the first 6x coins are correct, now start=6x+1 and n=2x. From this case of equality, we can reach 2*2x= 4x number of possible outcomes as leaf nodes.
Procedure less_than function in brief:
We retain the 1st x coins in the left pan(starting from S_left) and interchange the next x number of coins with the 1st x coins in the right pan(starting from S_right), and retain the next x coins of the right pan as it is. Thus in this comparison the last x coins of both the pans are not considered. Rather, these coins are removed from comparison at this stage. Again in this case there are three possible outcomes – (i) The left pan is lighter: The counterfeit coin exists between 1st x number of coins in the left pan, or the middle x number of coins in the right pan. Thus we have to update the value of S_right. It now points to the 1st coin of the middle x number of coins of the right pan. Value of S_left remains as it is. (ii) The left pan is heavier: The counterfeit coin exists between middle x number of coins in the left pan, or the 1st x number of coins in the right pan. Thus we have to update the value of S_left. It now points to the 1st coin of the middle x number of coins of the left pan. Value of S_right remains as it is. (iii) Both pans are equal: The counterfeit coin exists between the last x number of coins of the left and the right pan. Thus the value of both S_left and S_right needs to be updated. S_left now points to the 1st coin of the last x coins of the left pan, and S_right now points to the 1st coin of the last x coins of the right pan.
Now, the value of x is halved as we move down one level in the decision tree structure. If value of x is equal to ½, only two coins are left undecided. At this point we call the check function with these two undecided coins, and a known correct coin. The check function takes the three coins as parameters, in the following order – lighter or correct coin (for less than condition it would be the coin indexed by S_left, and for greater than condition it would be the coin indexed by S_left+1), heavier or correct coin (for less than condition it would be the coin indexed by S_right+1, and for greater than condition
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 9 of 33
it would be the coin indexed by S_right), and known correct coin. This check function then finds out the counterfeit coin by comparing the three coins. If the value of x is more than ½, the less_than function is called recursively with the updated values of S_left and S_right. Case iii) will not occur more than once. This is due to the fact that all the undecided coins (among which there exists the counterfeit coin) are compared in the next levels.
Procedure greater _than function in brief:
This procedure is pretty much the mirror image of the above procedure. We retain the 1st x coins in the left pan(starting from S_left) and interchange the next x number of coins with the 1st x coins in the right pan(starting from S_right), and retain the next x coins of the right pan as it is. Thus in this comparison the last x coins of both the pans are not considered. Again in this case there are three possible outcomes – i) The left pan is heavier: The counterfeit coin exists between 1st x number of coins in the left pan, or the middle x number of coins in the right pan. Thus we have to update the value of S_right. It now points to the 1st coin of the middle x number of coins of the right pan. Value of S_left remains as it is. ii) The left pan is lighter: The counterfeit coin exists between middle x number of coins in the left pan, or the 1st x number of coins in the right pan. Thus we have to update the value of S_left. It now points to the 1st coin of the middle x number of coins of the left pan. Value of S_right remains as it is. iii) Both pans are equal: The counterfeit coin exists between the last x number of coins of the left and the right pan. Thus the value of both S_left and S_right needs to be updated. S_left now points to the 1st coin of the last x coins of the left pan, and S_right now points to the 1st coin of the last x coins of the right pan.
Now, the value of x is halved as we move down one level in the decision tree structure. If value of x isequal to ½, only two coins are left undecided. At this point we call the check function with these two undecided coins, and a known correct coin. The check function takes the three coins as parameters, in the following order – lighter or correct coin (for less than condition it would be the coin indexed by S_right, and for greater than condition it would be the coin indexed by S_right+1), heavier or correct coin (for less than condition it would be the coin indexed by S_left+1, and for greater than condition it would be the coin indexed by S_left), and known correct coin. This check function then finds out the counterfeit coin by comparing the three coins. If the value of x is more than ½, the less_than function is called recursively with the updated values of S_left and S_right. Case iii) will not occur more than once this is due to the fact that all the undecided coins (among which there exists the counterfeit coin) are compared in the next levels.
Procedure 4_coin_problem in brief:
This solves the n_coin_problem when the problem is reduced to n=4, i.e. there are four number of undecided or unchecked coins. The parameters passed to this function are start (i.e. the index of the coin from which four undecided coins occur) and the index of a correct coin. It compares the coins indexed by start and start+1. If they are equal then it means that these two coins are correct, and the problem reduces to two coins problem. The 2_coin_problem is called with start=start+2 and the index of the correct coin. Otherwise, if the weight of the two coins is unequal, then the check function is called with these two coins to find out the counterfeit coin.
Procedure 2_coin_problem in brief:
This solves the n_coin_problem when the problem is reduced to n=2, i.e. there are two number of undecided or unchecked coins. The parameters passed to this function are start (i.e. the index of the
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 10 of 33
coin from which two undecided coins occur) and the index of a correct coin. This gives the index of the counterfeit coin, and mentions whether it is heavier or lighter.
Procedure check in brief:
The check function takes three coins as parameters, in the following order – lighter or correct coin, heavier or correct coin, and a known correct coin. This tells whether the 1st coin passed (which may be the lighter coin or a correct coin) is lighter, or the 2nd coin passed is heavier (which maybe the heavier coin, or a correct coin). This is done by comparing the weights of the 1st and 2nd coin passed with the known correct coin passed.
3.3 Algorithm for the n coins problem
This is the main procedure that calls all the other associated procedures to reach the final result. This procedure is called recursively if at the beginning weights of both the pans are equal.
n_coin_problem Algorithm (start, n)
INPUT: Number of coins and their starting index
OUTPUT: The index of the counterfeit coin and declaring whether it is heavy or light.
STEP 1: Each time the no. of coins exchanged in the left and right most side of the root in a n coin problem is x
x= n/8
The starting index of the n coin problem for the next pass is s_loc needed only when all the coins considered at the root comparison (of the n coins problem under consideration following the case of equality) are correct coins.
S_loc = 6x + start
Let us assume initially that the 1st coin is not the counterfeit coin. If the index of the correct coin be ‘correct’ then
correct = 1
STEP 2: If the weight of the coins from the starting location to the coin with index (3x+start-1) are equal to the weight of the coin from index (3x+start) to the (6x+start-1)th coin then m coin problem with the start = s_loc will be called where m = 2x where m is an even number less than n and a power of 2.
[For example, if it is an 8-coin / 16-coin problem, then it would call 2-coin / 4-coin problem with start = 7 / 13.]
STEP 3: If the weight of the coins from the starting location to the coin with index ‘3x+start-1’ are less than to the weight of the coin from index (3x+start) to the (6x+start-1)th coin then
S_left=start
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 11 of 33
S_right=3x+start
correct=8x
Call less_than(S_left,S_right,x,correct);
[S_left and S_right are the index of the 1st coin in the left and right pan where the counterfeit coin can exist in the 1st comparison and Correct is the index of the correct coin. In our case it is the last coin as the counterfeit coin exist between start and (6x+start1)th coin.]
STEP 4: If the weight of the coins from the starting location to the coin with index ‘3x+start1’ are greater than the weight of the coin from index (3x+start) to the (6x+start1)th coin then
S_left=start
S_right=3x+start
correct=8x
Call greater_than(S_left,S_right,x,correct);
[S_left and S_right are the index of the 1st coin in the left and right pan where the counterfeit coin can exist in the 1st comparison and correct is the index of the correct coin. In our case it is the last coin as the counterfeit coin exists between start and (6x+start1)th coin.]
STEP 5: End
Algorithm less_than(S_left,S_right,x,correct)
This procedure deals with the left subtree (of the root) of the decision tree. This procedure is called if at the beginning the left pan is lighter than the right pan (or the left pan is heavier than the right pan). This means that the one of the coin placed at the left pan is lighter (or one of the coin placed at the right pan is heavier). STEP 1: If the weight of the coin from index S_left to (S_left+x-1) and S_right to (S_right+x-1) is less than the weight of the coin from index (S_left+x) to (S_left+2x-1) and (S_right+x) to (S_right+2x-1) then
x=x/2
As we are going down through the decision tree one level upper so divide the value of x by 2
If x=1/2 then it is time to take some decision so call the check function where the coin with index S_left can be lighter or the coin with index S_right+1 can be heavier. So we pass the parameters in the check function in that order that is the index of the lighter coin, then the index of the heavier coin, then the index of the correct coin.
Call check(S_left,S_right+1,correct)
Else (when x>1/2)
Assign the new values of S_left and S_right and call less_than function recursively
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 12 of 33
S_left=S_left
S_right=S_right+2x
[Counterfeit coin does not exist in S_right through (S_right+2x-1) and in (S_left+2x) through (S_left+4x-1)]
Call less_than(S_left,S_right,x,correct)
STEP 2: If the total weight of the coins from index S_left to (S_left+x-1) and S_right to (S_right+x-1)is greater than the total weight of the coins from index (S_left+x) to (S_left+2x-1) and (S_right+x) to (S_right+2x-1), then
x=x/2
As we are going down through the decision tree one level lower so divide the value of x by 2
If x=1/2 then it is time to take some decision so call the check function where the coin with index S_left+1 can be lighter or the coin with index S_right can be heavier. So we pass the parameters in the check function in that order that is the index of the lighter coin, then the index of the heavier coin, then the index of the correct coin.
Call check(S_left+1,S_right,correct)
Else (when x>1/2)
Assign the new values of S_left and S_right and call less_than function recursively
S_left=S_left+2x
[Counterfeit coin does not exist in S_left through S_left+2x1 and in S_right+2x through S_right+4x1]
S_right=S_right
Call less_than(S_left,S_right,x,correct)
STEP 3: If the weight of the coin from index S_left to (S_left+x1) and S_right to (S_right+x1)equal to the weight of the coin from index (S_left+x) to (S_left+2x1) and (S_right+x) to (S_right+2x1) then
x=x/2
As we are going down through the decision tree one level lower so divide the value of x by 2
If x=1/2 then it is time to take some decision so call the check function where the coin with index S_left+2 can be lighter or the coin with index S_right+2 can be heavier. So we pass the parameters in the check function in that order, that is the index of the lighter coin, then the index of the heavier coin, then the index of the correct coin.
Call check (S_left+2,S_right+2,correct)
Else
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 13 of 33
Assign the new values of S_left and S_right and call less_than function recursively
S_left=S_left+4x
S_right=S_right+4x
[Counterfeit coin does not exist in S_left through S_left+4x1 and in S_right through S_right+4x1]
Call less_than(S_left,S_right,x,correct)
STEP 4: End
Algorithm greater_than(S_left,S_right,x,correct)
This procedure deals with the right subtree (of the root) of the decision tree. This procedure is called if at the beginning the left pan is heavier than the right pan (or the left pan is lighter than the right pan). This means that the one of the coins placed at the left pan is heavier (or one of the coins placed at the right pan is lighter).
STEP 1: If the weight of the coin from index S_left to (S_left+x1) and S_right to (S_right+x1) is less than the weight of the coin from index (S_left+x) to (S_left+2x1) and (S_right+x) to (S_right+2x1) then
x=x/2
As we are going down through the decision tree one level upper so divide the value of x by 2
If x=1/2 then it is time to take some decision so we call the check function where the coin with index S_right can be lighter or the coin with index S_left+1 can be heavier. So we pass the parameters in the check function in that order, that is the index of the lighter coin, then the index of the heavier coin, then the index of the correct coin.
Call check(S_right,S_left+1,correct)
Else (when x>1/2)
Assign the new values of S_left and S_right and call less_than function recursively.
S_left=S_left+2x
[Counterfeit coin does not exist in S_left through S_left+2x1 and in S_right+2x through S_right+4x1]
S_right=S_right
Call greater_than(S_left,S_right,x,correct)
STEP 2: If the weight of the coin from index S_left to (S_left+x1) and S_right to (S_right+x1) is greater than the weight of the coin from index (S_left+x) to (S_left+2x1) and (S_right+x) to (S_right+2x1) then
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 14 of 33
x=x/2
As we are going down through the decision tree one level lower so divide the value of x by 2
If x=1/2 then it is time to take some decision so we call the check function where the coin with index S_right can be lighter or the coin with index S_left+1 can be heavier. So we pass the parameters in the check function in that order, that is the index of the lighter coin, then the index of the heavier coin, then the index of the correct coin.
Call check(S_right+1,S_left,correct)
Else (when x>1/2)
Assign the new values of S_left and S_right and call less_than function recursively.
S_left=S_left
S_right=S_right+2x
[Counterfeit coin does not exist in S_right through (S_right+2x1) and in (S_left+2x) through (S_left+4x1)]
Call greater_than(S_left,S_right,x,correct)
STEP 3: If the weight of the coin from index S_left to (S_left+x1) and S_right to (S_right+x1) is equal to the weight of the coin from index (S_left+x) to (S_left+2x1) and (S_right+x) to (S_right+2x1) then
x=x/2
As we are going down through the decision tree one level lower so divide the value of x by 2
If x=1/2 then it is time to take some decision so call the check function where the coin with index S_right+2 can be lighter or the coin with index S_left+2 can be heavier. So we pass the parameters in the check function in that order, that is the index of the lighter coin, then the index of the heavier coin, then the index of the correct coin.
Call check(S_right+2,S_left+2,correct)
Else
Assign the new values of S_left and S_right and call less_than function recursively
S_left=S_left+4x
S_right=S_right+4x
[Counterfeit coin does not exist in S_left through (S_left+4x1) and in S_right through (S_right+4x1)]
Call greater_than(S_left, S_right, x, correct)
STEP 4: End.
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 15 of 33
Algorithm check(Light_coin, Heavy_coin, Correct_coin)
This procedure is called when there is one coin on each pan and the weight of the pans are unequal. It is then certain that one of these two coins is counterfeit. This procedure compares both the coins with a known correct coin and gives the desired result, i.e. displays which coin is counterfeit.
INPUT: The index of 3 coins where the 1st coin must be either lighter or correct, 2nd coin must be heavier or correct and the 3rd coin is the index of a correct coin.
OUTPUT: The index of the counterfeit coin and declaring whether it is heavy or light.
STEP 1: If the weight of the coin with index Correct_coin is equal to the weight of the coin with index Light_coin then
HEAVY INDEX COIN IS HEAVIER
STEP 2: If the weight of the coin with index Correct_coin is greater than the weight of the coin with index Light_coin then
LIGHT INDEX COIN IS LIGHTER
STEP 3: End
Algorithm 4_coin_problem(start,correct)
This procedure is called by the n coin problem when the number of undecided or unchecked coins is equal to 4. This procedure takes the help of check and 2 coin procedure to get the desired output.
INPUT: The starting index of 4 coins among which a coin exist which is the counterfeit coin and an index of a correct coin.
OUTPUT: The index of the counterfeit coin and declaring whether it is heavy or light.
STEP 1: Take the index of the 4 coins from start in 4 variables
A=start
B=start+1
C=start+2
D=start+3
STEP 2: If weight of A index coin is less than weight of B index coin then
Call check(A,B,correct)
Else if weight of A index coin is greater than weight of B index coin then
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 16 of 33
Call check(B,A,correct)
Else of A index coin is equal to weight of B index coin then
Call 2_coin_problem(C,correct)
STEP 3: End.
Algorithm 2_coin_problem(start,correct)
This procedure is called by the n coin problem or 4 coins problem when the number of undecided or unchecked coin equal to 2. This procedure takes the help of check to get the desired output.
INPUT: The starting index of 2 coins among which a coin exist which is the counterfeit coin, and anindex of a correct coin.
OUTPUT: The index of the counterfeit coin and declaring whether it is heavy or light.
STEP 1: Take the index of the 4 coins from start in 2 variables
A=start
B=start+1
STEP 2: If the Weight of the coin with index A is greater than the weight of the coin with index Bthen
Call check(B,A,correct)
If the Weight of the coin with index A is less than the weight of the coin with index B then
Call check(A,B,correct)
STEP 3: End
3.4 Illustration of the working of the algorithm
Here, we illustrate the working of the n coins algorithm taking n=8. We show each of the three possible cases that may arise after the 1st comparison.
i) CASE: - less than
First we show the less than case, where the weight of the left pan is lighter than that of the right pan. In the following example we take the 2nd coin to be lighter.
INPUT:-
0 -1 0 0 0 0 0 0
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 17 of 33
Procedure followed during the processing of the Algorithm:-
Initially we call the n coin problem with start=1, n=8 [i.e. n_coin_problem(1,8)]
STEP 1:- x=8/8=1[as n=8]
Compare the weight of the coins 1+2+3 : 4+5+6 [We would keep 3x, (i.e. three) coins starting from the start coin in the two pan respectively. Thus 6x, (i.e. six) coins is compared initially.]
STEP 2:- As the left pan is lighter it would call the less_than function with S_left=1, S_right=4 [Index of the 1st coin in the left and right pan respectively in the above comparison] and the correct=8[Index of the correct coin i.e. the last coin in the n coin problem]
STEP 3:- 1st x (x=1) coins in the left pan (starting from S_left=1) and interchange the next x (i.e. 2nd
coin) number of coins with the 1st x coins (4th coin) in the right pan (starting from S_right=4), and retain the next x coins (5th coin) of the right pan as it is. Now we will compare the weight of the coins in the left and right pan again. Thus, 1+4 : 2+5
STEP 4:- As the weight of the left pan is heavier thus counterfeit coin exist between the coin index by 2nd and 4th coin.
STEP 5:- Divide the value of x by 2 i.e. x=1/2
STEP 6:- As x=1/2 it is time to take some decision where the counterfeit coin may be either 2nd coin which may be lighter or 4th coin that might be heavier.
Thus the check function is called in the following way, check(2,4,8)
The parameters passed in the check function are in the following order, i.e. the index of the lighter coin, index of the heavier coin, index of the correct coin.
STEP 7:- Compare the weight of the second and eight coin as and we can conclude that the 2nd coin is lighter. Thus, 2 : 8
OUTPUT: - 2nd coin is lighter.
Comparisons:-
1. 1+2+3 : 4+5+6
2. 1+4 : 2+5
3. 2 : 8
Number of comparisons required is 3.
ii) CASE:- greater than
Next, we show the greater than case, where the weight of the left pan is heavier than that of the right pan. In the following example we take the 3rd coin to be heavier.
INPUT:-
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 18 of 33
0 0 1 0 0 0 0 0
Procedure followed during the processing of the algorithm:
Initially we call the n coin problem with start=1, n=8 [i.e. n_coin_problem(1,8)]
STEP 1:- x=8/8=1 [as n=8]
Compare the weight of the coins 1+2+3 : 4+5+6 [We would keep 3x, (i.e. three) coins starting from the start coin in the two pan respectively. Thus 6x, (i.e. six) coins is compared initially.]
STEP 2:- As the left pan is heavier it would call the greater_than function with S_left=1, S_right=4 [Index of the 1st coin in the left and right pan respectively in the above comparison] and correct=8[Index of the correct coin i.e. the last coin in the n coin problem]
STEP 3:- Now we will compare the weight of the coins in the left and right pan again. 1st x (x=1) coins in the left pan (starting from S_left=1) and interchange the next x (i.e. 2nd coin) number of coins with the 1st x coins(4th coin) in the right pan(starting from S_right=4), and retain the next x coins (5th
coin) of the right pan as it is.
Thus, 1+4 : 2+5
STEP 4:- As the weight of the two arm balance are equal thus all the above coins, indexed by 1,2,4,5 are correct coins.
STEP 5:- S_left and S_right points to the index of the 1st coin in the left and right arm balance that is not compared in the above comparison, i.e. the last x coins in the 1st comparison.
S_left= 3 [S_left(previous)+2x, i.e., 1+2.1 =3],
S_right=6 [S_right(previous)+2x i.e. 4+2.1 =6], and
Divide the value of x by 2 i.e. x=1/2
STEP 6:- As x=1/2 it is time to take some decision where the counterfeit coin may be either 3rd coin which may be heavier or 6th coin that might be lighter.
Thus the check function is called in the following way, check(6,3,8)
The parameters passed in the check function are in the order the index of the lighter coin, index of the heavier coin, index of the correct coin.
STEP 7:- Compare the weight of the third and eighth coin, as they are equal we can conclude that the 3rd coin is heavier. Thus 8 : 3
OUTPUT: - 3rd coin is heavier.
Comparisons:-
1. 1+2+3 : 4+5+6
2. 1+4 : 2+5
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 19 of 33
3. 8 : 3
Number of comparisons required is 3.
iii) CASE:- equal to
Lastly, we show the equality case, where the weight of the left pan is equal to that of the right pan. In the following example we take the 7th coin to be heavier.
INPUT:-
0 0 0 0 0 0 1 0
Procedure followed during the processing of the algorithm :-
Initially we call the n coin problem with start=1, n=8 [i.e. n_coin_problem(1,8)]
STEP 1:- x=8/8=1[as n=8]
Compare the weight of the coins 1+2+3 : 4+5+6 [We would keep 3x, (i.e. three) coins starting from the start coin in the two pan respectively. Thus 6x, (i.e. six) coins is compared initially.]
STEP 2:- As the two arms are equal thus the counterfeit coin exists between the last 2x (as x=1) coins in the n=8 coin problem. Now the problem becomes a two coin problem, correct=1 and start = start + 6x [i.e. 1+6.1=7]. Thus the 2_coin_problem function is called in the following way, 2_coin_problem(2,4,8)
STEP 3:-Now we conclude that the weight of 7th coin(first coin in the two coin problem with the weight of the correct coin i.e. the 1st coin and conclude that the 7th coin is heavier. Thus, 1 : 7 is compared.
OUTPUT: - 7th coin is heavier.
Comparisons:-
1. 1+2+3 : 4+5+6
2. 1 : 7
Number of comparisons required is 2.
3.5 Implementation of the algorithm
We have implemented the n coins problem algorithm, using the programming language C. Here in section 3.5.1 we give the program listing. In the program we accept the number of coins (i.e. n), the index of the counterfeit coin, and also whether it is heavier or lighter. The program gives as its output, the total number of comparisons needed to find the counterfeit coin (from the decision tree structure), and also each comparison done (in order). In section 3.5.2 we give some experimental data. We give
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 20 of 33
the input-output set for n=8, 16, 32, 64, 128 and 256. The results indicate the path in the tree structure followed, for a particular counterfeit coin.
3.5.1 Program Listing
/*Solving the n-coins problem*/#include<stdio.h>#include<conio.h>
int start=1,n,x,correct,s_left,s_right,comp=0,flag=0,f=0,count=0; /*global declarations*/int w[2049];
void n_coin_problem(int start,int n); /*various function declarations*/void greater_than(int s_left,int s_right,int x,int correct);void less_than(int s_left,int s_right,int x,int correct);void check(int light_coin,int heavy_coin,int correct_coin);void coin_problem4(int start,int correct);void coin_problem2(int start,int correct);void input(void);
void main() /*main*/{ clrscr(); printf("\n********THE N COINS PROBLEM********\n"); printf("\nINPUT:\n"); input(); printf("\nOUTPUT:\n"); printf("\n\nThe following are the comparisons made to reach the result\n"); n_coin_problem(start,n); /*calling the n_coin_problem*/ getch(); }
void n_coin_problem(int start,int n){ int w_left=0,w_right=0,i;
x=n/8; correct=1;
printf("\n%d. %d->%d:%d->%d\n",++count,start,3*x+start-1,3*x+start,6*x+start-1); /*finding out the weight of each pan*/
for(i=start;i<=3*x+start-1;i++) w_left+=w[i]; for(i=3*x+start;i<=6*x+start-1;i++) w_right+=w[i]; comp++; if(w_left==w_right) /*comparing weights*/ {
start+=n-2*x;
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 21 of 33
if(x==1)coin_problem2(start,correct); /*call coin_problem2 if pan weights are
equal, &no. of coins=2*/else if(x==2)
coin_problem4(start,correct); /*call coin_problem4 if pan weights are equal, &no. of coins=4*/ else { /*otherwise call n_coin_problem recursively*/
n=2*x; f=1;
n_coin_problem(start,n);}
} else if(w_left<w_right) /*call less_than if left pan weight<right pan weight*/ { s_left=start; s_right=3*x+start; if(f==0) correct=8*x; flag=1; less_than(s_left,s_right,x,correct); } else if(w_left>w_right) /*call greater_than if left pan weight>right pan weight*/ { s_left=start; s_right=3*x+start; if(f==0) correct=8*x; flag=2; greater_than(s_left,s_right,x,correct); } }
void greater_than(int s_left,int s_right,int x,int correct) /*greater_than function*/ { int w_left=0,w_right=0,i;
/*calculate both pan weights*/for(i=s_left;i<=s_left+x-1;i++)
w_left+=w[i];for(i=s_right;i<=s_right+x-1;i++)
w_left+=w[i];for(i=s_left+x;i<=s_left+(2*x)-1;i++)
w_right+=w[i];for(i=s_right+x;i<=s_right+(2*x)-1;i++)
w_right+=w[i];
if(s_left==s_left+x-1 && s_right==s_right+x-1 && s_left+x==s_left+2*x-1 && s_right+x==s_right+2*x-1)
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 22 of 33
printf("\n%d. %d+%d:%d+%d\n",++count,s_left,s_right,s_left+x,s_right+x);else
printf("\n%d. %d->%d+%d->%d:%d->%d+%d->%d\n",++count,s_left,s_left+x-1,s_right,s_right+x-1,s_left+x,s_left+2*x-1,s_right+x,s_right+2*x-1);
comp++;
if(w_left==w_right) /*if weights are equal*/ { /*decrease value of x*/
x=x/2;if(x<1)check(s_right+2,s_left+2,correct); /*call check if no. of suspect coins=2*/else{
s_left+=(4*x); /*update values of s_left & s_right according to the result*/s_right+=(4*x);greater_than(s_left,s_right,x,correct); /*call greater_than recursively*/
}}else if(w_left<w_right) /*if weight of left pan<weight of right pan*/{
x=x/2; /*decrease value of x*/if(x<1)
check(s_right,s_left+1,correct); /*call check if no. of suspect coins=2*/else{
s_left+=(2*x); /*update s_left according to the weighing result*/ greater_than(s_left,s_right,x,correct); /*call greater_than recursively*/ }}else if(w_left>w_right){
x=x/2; /*decrease value of x*/if(x<1)
check(s_right+1,s_left,correct); /*call check if no. of suspect coins=2*/else{
s_right+=(2*x); /*update s_right according to the weighing result*/ greater_than(s_left,s_right,x,correct); /*call greater_than recursively*/ }}
}
void less_than(int s_left,int s_right,int x,int correct) /*less_than function*/ {
int w_left=0,w_right=0,i;
for(i=s_left;i<=s_left+x-1;i++) /*calculate both pan weights*/w_left+=w[i];
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 23 of 33
for(i=s_right;i<=s_right+x-1;i++)w_left+=w[i];
for(i=s_left+x;i<=s_left+(2*x)-1;i++)w_right+=w[i];
for(i=s_right+x;i<=s_right+(2*x)-1;i++)w_right+=w[i];
if(s_left==s_left+x-1 && s_right==s_right+x-1 && s_left+x==s_left+2*x-1 && s_right+x==s_right+2*x-1)
printf("\n%d. %d+%d:%d+%d\n",++count,s_left,s_right,s_left+x,s_right+x);else
printf("\n%d. %d->%d+%d->%d:%d->%d+%d->%d\n",++count,s_left,s_left+x-1,s_right,s_right+x-1,s_left+x,s_left+2*x-1,s_right+x,s_right+2*x-1);
comp++;
if(w_left==w_right) /*if weights are equal*/ {
x=x/2; /*decrease value of x*/if(x<1)
check(s_left+2,s_right+2,correct); /*call check if no. of suspect coins=2*/else{
s_left+=(4*x); /*update s_left & s_right according to the weighing result*/s_right+=(4*x);less_than(s_left,s_right,x,correct); /*call less_than recursively*/
} }
else if(w_left<w_right) /*if weight of left pan<weight of right pan*/{
x=x/2; /*decrease value of x*/ if(x<1)
check(s_left,s_right+1,correct); /*call check if no. of suspect coins=2*/ else
{ s_right+=(2*x); /*update s_right according to the weighing result*/ less_than(s_left,s_right,x,correct); /*call less_than recursively*/
} } else if(w_left>w_right) /*if weight of left pan>weight of right pan*/
{x=x/2; /*decrease value of x*/if(x<1)check(s_left+1,s_right,correct); /*call check if no. of suspect coins=2*/
else{ /*update value of s_left according to the
weighing result*/ s_left+=(2*x);
less_than(s_left,s_right,x,correct); /*call less_than recursively*/ }
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 24 of 33
} }
void check(int light_coin,int heavy_coin,int correct_coin) /*check function*/ {
comp++;if(flag==1)
printf("\n%d. %d:%d\n",++count,light_coin,correct_coin); else if(flag==2) printf("\n%d. %d:%d\n",++count,correct_coin,heavy_coin);
printf("\nRESULT\n");if(w[correct_coin]==w[light_coin]) /*comparing correct coin with light coin*/ printf("\n%d-th coin is heavier\n",heavy_coin); /*print the result*/else printf("\n%d-th coin is lighter\n",light_coin);printf("\nTotal number of comparisons made = %d",comp); /*number of comparisons made*/
return; }
void coin_problem4(int start,int correct) /*coin_problem4*/ { int a,b,c;
a=start; /*initialize coin indices*/ b=a+1; c=a+2; correct=1;
comp++; printf("\n%d. %d:%d\n",++count,a,b);
if(w[a]<w[b]) /*compare 1st two coins out of the 4 coins*/{
flag=1;check(a,b,correct); /*call check*/
} else if(w[a]>w[b]) { flag=2;
check(b,a,1); /*call check*/}else if(w[a]==w[b])
coin_problem2(c,correct); /*1st two coins are correct, so call coin_problem2*/ }
void coin_problem2(int start,int correct) /*coin_problem2*/ { int a,b; a=start; b=a+1;
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 25 of 33
comp++;printf("\n%d. %d:%d\n",++count,correct,a);
if(w[a]<w[correct]) /*compare 1st coin out of the 2 coins with the correct coin*/printf("\n%d-th coin is lighter\n",a);
else if(w[a]>w[correct]) printf("\n%d-th coin is heavier\n",a);if(w[a]==w[correct]) /*weight of 1st coin=weight of correct coin*/
{printf("\n%d. %d:%d\n",++count,correct,b);if(w[b]<w[correct]) /*compare 2nd coin out of the 2 coins with the correct coin*/
printf("\n%d-th coin is lighter\n",b);else if(w[b]>w[correct])
printf("\n%d-th coin is heavier\n",b); } }
void input(void) /*input function*/ { int index,choice,error=1; do {
printf("\nEnter the number of coins: "); /*accept the no. of coins,i.e. n*/ scanf("%d",&n); if(n==0 || n%8!=0) printf("\nThe input should be a multiple of 8"); else error=0; }while(error==1);
printf("\nWhich coin do you choose to be counterfeit? "); /*accept index of the counterfeit coin*/ scanf("%d",&index); printf("\nIf you wish it to be heavier press 1\nIf you wish it to be lighter press 2\n\nEnter choice(1/2): "); scanf("%d",&choice); /*accept whether its heavier or lighter*/ printf("\n"); if(choice==1) /*set weight of counterfeit coin=1, since it is heavier*/ w[index]=1; else if(choice==2) w[index]=-1; /*set weight of counterfeit coin=-1, since it is lighter*/ return; }
3.5.2 Experimental Results
********THE N COINS PROBLEM********
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 26 of 33
INPUT:
Enter the number of coins: 8
Which coin do you choose to be counterfeit? 1
If you wish it to be heavier press 1
If you wish it to be lighter press 2
Enter choice(1/2): 2
OUTPUT:
The following are the comparisons made to reach the result
1. 1->3:4->6
2. 1+4:2+5
3. 1:8
RESULT
1-th coin is lighter
Total number of comparisons made = 3
********THE N COINS PROBLEM********
INPUT:
Enter the number of coins: 16
Which coin do you choose to be counterfeit? 9
If you wish it to be heavier press 1
If you wish it to be lighter press 2
Enter choice(1/2): 2
OUTPUT:
The following are the comparisons made to reach the result
1. 1->6 : 7->12
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 27 of 33
2. 1->2+7->8 : 3->4+9->10
3. 1+9 : 2+10
4. 16 : 2
RESULT
9-th coin is lighter
Total number of comparisons made = 4
********THE N COINS PROBLEM********
INPUT:
Enter the number of coins: 32
Which coin do you choose to be counterfeit? 31
If you wish it to be heavier press 1
If you wish it to be lighter press 2
Enter choice(1/2): 2
OUTPUT:
The following are the comparisons made to reach the result
1. 1->12 : 13->24
2. 25->27 : 28->30
3. 1 : 31
RESULT
31-th coin is lighter
Total number of comparisons made
********THE N COINS PROBLEM********
INPUT:
Enter the number of coins: 64
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 28 of 33
Which coin do you choose to be counterfeit? 4
If you wish it to be heavier press 1
If you wish it to be lighter press 2
Enter choice(1/2): 1
OUTPUT:
The following are the comparisons made to reach the result
1. 1->24 : 25->48
2. 1->8+25->32 : 9->16+33->40
3. 1->4+33->36 : 5->8+37->40
4. 1->2+37->38 : 3->4+39->40
5. 3+37 : 4+38
6. 64 : 4
RESULT
4-th coin is heavier
Total number of comparisons made = 6
********THE N COINS PROBLEM********
INPUT:
Enter the number of coins: 128
Which coin do you choose to be counterfeit? 45
If you wish it to be heavier press 1
If you wish it to be lighter press 2
Enter choice(1/2): 2
OUTPUT:
The following are the comparisons made to reach the result
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 29 of 33
1. 1->48 : 49->96
2. 1->16+49->64 : 17->32+65->80
3. 33->40+81->88 : 41->48+89->96
4. 41->44+81->84 : 45->48+85->88
5. 45->46+81->82 : 47->48+83->84
6. 45+83 : 46+84
7. 45 : 128
RESULT
45-th coin is lighter
Total number of comparisons made = 7
********THE N COINS PROBLEM********
INPUT:
Enter the number of coins: 256
Which coin do you choose to be counterfeit? 243
If you wish it to be heavier press 1
If you wish it to be lighter press 2
Enter choice(1/2): 1
OUTPUT:
The following are the comparisons made to reach the result
1. 1->96 : 97->192
2. 193->216 : 217->240
3. 241->246 : 247->252
4. 241->242+247->248 : 243->244+249->250
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 30 of 33
5. 243+247 : 244+248
6. 1 : 243
RESULT
243-th coin is heavier
Total number of comparisons made = 6
3.6 Observations
1. Maximum number of comparisons needed to find the counterfeit coin is p, where p = log 2 n. Hence, the height of the tree is p.
2. Minimum number of comparisons needed to find the counterfeit coin is (p/2) + 1 if p is even, and (p+1)/2 if p is odd.
3. The left and right sub trees of the root of the n coin problem are mirror images of each other. So if we can solve one part, the other can be easily found out.
4. x=n/8, x gives 3 things, they are the following –
(i) Initially, 3x coins are kept in each pan for comparison, i.e. in total, 6x coins are compared.
(ii) If the weights of both the pans are equal, then the n_coin_ problem is called recursively with 2xnumber of coins (i.e., then the problem becomes a 2x coins problem).
(iii) If the weights of the pans are unequal, then x numbers of coins are exchanged on both sides of the pan.
5. For less_than or greater_than function the equality condition will not occur more than once, i.e.,for the initial comparison (except obviously when the check function finds out the counterfeit coin). Thus when the less_than or greater_than function is called recursively the equality condition will not occur. This is due to the fact that all the undecided coins (among which there exists the counterfeit coin) are compared in the next levels.
3.7 Computational Complexity
Time Complexity: In this solution report, we have developed a new algorithm to solve the n coins problem based on the decision tree, that finds out the index of the counterfeit coin using minimum number of comparisons and takes time (log n) in the worst-case, where n is the number of coins. The n coins algorithm developed in this solution report works for such n which is a power of two and greater than or equal to eight. The algorithm follows a path from the root of the tree to any of the 2*nnumber of leaves (which indicate that the decision has been reached). This means that the total number of comparisons never exceed the height of the tree. The decision tree that is being implicitly
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 31 of 33
used by our algorithm is a tree with minimum possible height for a given number of nodes, i.e. n. The height in the worst case is log n. Hence, the algorithm takes time (log n). Since n=2P, log n = p. This means that the number of comparisons needed in the worst case is p. This gives the upper bound for the computational complexity of our algorithm.
Space Complexity: The implementation of the algorithm has been achieved using the programming language C. The only data structure used is a one-dimensional array of size n for storing the weights of the n coins.
4. MARKETS ADDRESSED
Academicians may view the eight coins problem as fun, finding counterfeits can be treated as a form of a puzzle. We view this problem more from the theoretical computer science and/or applied mathematics points of view. More specifically, it is a problem in the domain of graph theory and its solution is in the form of a decision tree. A major use of such coin problems is in efficiently determining counterfeits.
A counterfeit is an imitation that is made usually with the intent to deceptively represent its content or true origin. Counterfeit antique coins are generally made to a very high standard so that they often fool collectors; this is not easy and many coins still stand out.Counterfeit coins made to be of face value and destined for general circulation amongst the public have been made by criminals for hundreds of years. For modern coins destined for general circulation the most common method of protection from forgeries is the use of bi-metallic coins that are made of two different metals that are a different colour which render counterfeiting very hard.Initially when the euro was introduced in Europe, the number of counterfeits was extremely low; however, the number has increased massively in recent years. The increasingly large number of fake euro coins in circulation in 2004 led to the creation of a Technical and Scientific Centre for the coordination of technical actions to protect euro coins against counterfeiting. Hence the n coins problem is still important from a research point of view, for any n ≥ 2 [1, 3].
The above presented solution for the n coins problem is fully based on the decision tree structure. Our algorithm provides a deterministic way for solving problems based on decision tree structures, which can then be solved in polynomial time using minimum number of comparisons. Thus, problems having a similar nature (i.e. problems solved by using decision tree structure) can be solved using the basic idea behind the algorithm being presented.
Our algorithm solves the n coins problem for certain values of n, i.e. n=2P for p3. This means that the algorithm developed in this paper, solves the n coins problem, for all n=2P for p3, including the eight coins problem that exists in literature. Previously, here existed a classical solution for the eight coins problem. But there was no definite algorithm to solve it. In our work being presented, we have extracted the algorithm existing behind the classical solution (after having modified it slightly to suit our needs). Then we have extended this algorithm to solve for other values of n greater than eight, provided it is a power of two.
5. COMPARATIVE BENEFITS / ADVANTAGES (Please try to explain why your invention is better than what currently may be available in the marketplace.)
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 32 of 33
The existing solution in the literature is limited to eight coins only. The solution uses the decision tree structure explicitly to find out the faulty coin. But since the solution is not generalized, it works for eight coins only. So our aim was to extract the algorithm used to solve the eight coins problem, and then generalise it to solve the problem for any n, where n is the number of coins. The restriction imposed is that n has to be a power of two, greater than or equal to eight, i.e. n=2P (where p>=3). Previously, there was no available algorithm to solve the counterfeit coin problem, where number of coins is higher than eight. So, our invention is completely new, and provides a way in which the ncoins problem can be solved, with the above mentioned restriction for n.
The algorithm has been developed with the help of the decision tree structure that is used in the classical solution of the eight coins problem. The solution gives a step by step process of which coins to keep in the pan (and on which side) for comparing, so that the counterfeit coin can be found out with the minimum number of comparisons. The algorithm gives the path of the tree that is followed to reach the conclusion. The algorithm takes as its input, the following things, the number of coins (i.e. n), and the weight of all the n coins, (needed for comparison); and the algorithm gives as its output the following things – each comparison made, and the final result (that of which coin is heavier or lighter).
6. RELATED BACKGROUND
There has been a huge amount of work done in this field of finding the counterfeit object (can be coins, ornaments, antiquities, etc). But most of the existing works solve the problem for a particular value of n. That is, none of the problem solving techniques, presented in the various works, gives a generalised method for finding the forged or counterfeit object. This is a major drawback, since the total number of objects (in our case coins) cannot be fixed from beforehand. A generalised problem solving technique is the need of the hour. Our algorithm thus paves the way for more generalised problem solving methods.
The algorithm developed by us solves the n coins problem where n is a power of two, greater than or equal to eight. This is not generalised in the true sense, since it cannot solve the problem for other values of n. This is the limitation of the above presented algorithm. What is needed is an algorithm which solves the problem for any given value of n. For achieving this, further study and related work is needed in this field.
7. REFERENCES
(The full technical detail of your invention may need to be described in documents that you incorporate by reference into this Detailed Disclosure Description. Please list below each of the documents are you are incorporating by reference.)
[1] Gagg C. R. and P. R. Lewis , Counterfeit Coin of the Realm – Review and Case Study Analysis, Second International Conference on Engineering Failure Analysis (ICEFA-II), Toronto, Canada, Sep. 2006, Engineering Failure Analysis, vol. 14, no. 6, pp. 1144 -1152, 2007.
SOLUTION REPORT
Version: 3.2 1 September 2009 Page 33 of 33
[2] Horowitz E. and, S. Sahni, Fundamentals of Data Structures in Pascal, Galgotia Booksource, New Delhi, 1984.
[3] Lewis P. R., C. R. Gagg and K. Reynolds, Forensic Materials Engineering: Case Studies, CRC Press, 2004.
[4] Reingold E. M., J. Nievergelt and N. Deo, Combinatorial Algorithms: Theory and Practice, Prentice-Hall, Inc., Englewood Cliffs, New Jersey, 1977.
[5] Rosen K. H., Discrete Mathematics and Its Applications (Fifth Edition), Tata McGraw-Hill Publishing Co. Ltd., New Delhi, 2003.
8. CONFIDENTIALITY OF THE INVENTION
This work on generalisation of the n coins problem has not been communicated or disclosed for publication in any form in a journal or conference proceedings or anywhere else by any of the researchers, and is unpublished. This is the first time the counterfeit coin problem has been generalised for larger values of n. This is, in fact, a fresh, new, original innovative work, and important in solving problems using the decision tree structure.
Recommended