CTK Exchange
Front Page
Movie shortcuts
Personal info
Awards
Reciprocal links
Terms of use
Privacy Policy

Interactive Activities

Cut The Knot!
MSET99 Talk
Games & Puzzles
Arithmetic/Algebra
Geometry
Probability
Eye Opener
Analog Gadgets
Inventor's Paradox
Did you know?...
Proofs
Math as Language
Things Impossible
My Logo
Math Poll
Other Math sit's
Guest book
News sit's

Recommend this site

Manifesto: what CTK is about Search CTK Buying a book is a commitment to learning Table of content |Store| Things you can find on CTK Chronology of updates Email to Cut The Knot Recommend this page

CTK Exchange

Subject: "marriage algorithm"     Previous Topic | Next Topic
Printer-friendly copy     Email this topic to a friend    
Conferences The CTK Exchange This and that Topic #653
Reading Topic #653
brac37
guest
Nov-16-05, 10:46 PM (EST)
 
"marriage algorithm"
 
   Dear Alexander Bogomolny,

When I searched for an algorithm to determine marriagability, google brought me to your page. But I do not understand the last step in it. You want to remove the rows and columns of E. This results in a square matrix if E is square. But what if E is not square? The case that E is higher than its width is trivial, so assume E is lower than its with. Now removing the rows and columns of E results in a matrix that can be made square by adding zero columns, but then the new matrix is surely not marriagable.

Despite that, I found a solution in that direction. I replaced the labeled phase by the following. The greedy phase gives us the matrix


-1---------|-G-
---1-------|===
-----\-----|-0-
-------\---|=== = M1
---------1-|-0-
===========|===
-0-|-0-|-E-|-0-

The problem we are going to solve is improving this matrix, i.e. getting a 1 on the diagonal in the B part without affecting the 1's on the diagonal we already have. For this purpose, we make a new matrix by setting all columns with E to zero (except in the trivial case that E has width zero).

-1-----|-0-|-G-
---\---|===|===
-----1-|-0-|-0-
-------|===|=== = M2
-------|-0-|-0-
=======|===|===
-0-|-0-|-0-|-0-

Now an E-column can be missed in M1 (and hence used in the rightmost part of the original matrix to get a zero on the diagonal in the B part), if and only if M2 can be improved. This can be checked recursively, but since M1 was the result of a greedy phase, we must apply the greedy phase on M2 first as well. If the greedy phase does not improve M2, then we check recursively whether M2 can be improved.

If M2 can be improved, then we get


-1-----|-------
---\---|-------
-----1-|-------
-------|======= = M3
-------|-F-|---
=======|===|===
-0-|-0-|-0-|-0-

with F having at least one 1 on the diagonal. Next, the E-columns must be put back. For that purpose we do the following algorithm (in which M1 and M3 become matrix variables).

1. Exchange all F-columns of M3 without a 1 on the diagonal with their corresponding E-column of M1,

2. Put the E-columns of M1 on zero columns of M3,

3. Apply the greedy phase on M3.

Now M3 is an improvement of M1. If M3 does not have an all-1 diagonal, then try to improve M1 further, etc.

Notice that only the greedy phase uses exchanges of rows. Since I used machine words for the columns (32 of 64 bits at most), I adapted the algorithm such that there are only exchanges of columns.

With the most friendly regards,

Michiel


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top

  Subject     Author     Message Date     ID  
marriage algorithm brac37 Nov-16-05 TOP
  RE: marriage algorithm McWorter Nov-17-05 1
     RE: marriage algorithm brac37 Nov-18-05 2
         RE: marriage algorithm alexb Nov-20-05 3
     RE: marriage algorithm brac37 Nov-20-05 4
         RE: marriage algorithm alexb Nov-20-05 5
                 RE: marriage algorithm brac37 Nov-24-05 7
                     RE: marriage algorithm McWorter Nov-24-05 8
                         RE: marriage algorithm brac37 Nov-29-05 9

Conferences | Forums | Topics | Previous Topic | Next Topic
McWorter
guest
Nov-17-05, 11:52 PM (EST)
 
1. "RE: marriage algorithm"
In response to message #0
 
   Prof. Bogomolny asked me to provide an interim reply. He plans to update the page.

You are right to find a problem with the last step of the proof. That last step is in error, partly because the proof does not assume that the original matrix A is square, even though the statement of the theorem misstakenly makes that assumption.

The last step also commits a second error. Without further argument (which will appear in an update) the algorithm could cycle between B HAS ONLY ZEROS and the LABEL PHASE forever.

You may find it easier to correct the last step of the proof by dropping the assumption that the matrix A is square. Who knows, maybe we will prefer your proof to ours!

Thanks for pointing out the error,
William


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
brac37
guest
Nov-18-05, 09:52 PM (EST)
 
2. "RE: marriage algorithm"
In response to message #1
 
   Mistakes are easily made, but I am quite sure my algorithm works. This is because I made a few tests:

1) Whether a matrix is a column permutation of another matrix. Recall that I only use column interchanges.

2) Whether a matrix has an all-one diagonal.

3) Whether a zero block, say of dimension r x s, is a zero block of a matrix, say with dimension n x n, and whether r + s > n. Yes, my implementation specifies such a zero block if no all-one diagonal can be attained.

The algorithm appeared correct for millions of matrices.

Remark that the first part of your labeled phase corresponds to the "B has only zero's"-part of the greedy phase on M2 (now I think of it, the greedy phase can be reduced to the "B has only zero's"-part at this point). Maybe, both algorithms only differ in their formulation. Your inductional B, which may be higher than its width, corresponds to the B-part of M2.

I formulated the greedy part differently as well. I interchange pairs of columns if that improves the diagonal (by one or two extra 1's). This way, both parts of the greedy phase are unified.

Last night, someone pointed me coincidentally that he had read a test for determining whether a number is a power of 2. I formulated
!(a & (a - 1))
which seemed even more efficient than the test he read:
(a & -a) == a
Yes, both tests have a bug that 0 is seen as a power of 2. If we look at my test, we see that a & (a-1) removes the least significant bit of a. So a - (a & (a-1)) selects the least significant bit'set. But I do not see how to get the index (exponent) of that bit fast. An idea is to loop on bytes rather that bits and use table lookup for the bytes. On an Intel 386 or better, you can get this index with the BSF instruction (bit scan forward). 1 << BSF(a) is also a way to get the least significant bit. With BSF, there is no need to make the matrix smaller in the inductional steps in order to gain efficiency. Unfortunately, I implemented my algorithm on a Sparc. But probably, these machine level considerations are not very interesting to you; at least they do not belong on your web page.

In case you prefer my algorithm, my surname is "De Bondt". "de" has no capital when preceded by a first name or initials; it means "the".

Michiel


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
alexb
Charter Member
1696 posts
Nov-20-05, 00:38 AM (EST)
Click to EMail alexb Click to send private message to alexb Click to view user profileClick to add this user to your buddy list  
3. "RE: marriage algorithm"
In response to message #2
 
   > In case you prefer my algorithm,
> my surname is "De Bondt". "de" has
> no capital when preceded by a first
> name or initials; it means "the".

Dear Michiel:

It's not a question of choosing preferences. Prof. McWorter amended his proof in two ways. He expanded the last paragraph of the proof but also added a remark before the proof to the effect that the case when the number of girls equals the number of boys may be equal without loss of generality. Indeed, if there are more girls than boys, the marriage condition is violated. If there are more boys than girls, a few girls can be added to equate the quantities. Such an operation will not affect the marriage condition provided the add-on girls agree to marry any boy.

Following the path of least resistance, I accept William's modifications.

I applaud your involvement and ingenuity.

Alex


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
brac37
guest
Nov-20-05, 06:40 PM (EST)
 
4. "RE: marriage algorithm"
In response to message #1
 
   > You may find it easier to correct the last step of the proof
> by dropping the assumption that the matrix A is square. Who
> knows, maybe we will prefer your proof to ours!

> In case you prefer my algorithm,
> my surname is "De Bondt". "de" has
> no capital when preceded by a first
> name or initials; it means "the".

The "you" in the second paragraph refers to the "we" in the first. So you do not need to choose, Mr. Bogomolny. I sent another reply with a discussion on the presentation of the algorithm, but I can not find in back on the forum. I think it is important that the algorithm is presented clearly; any name associated with it does not interest me at all.

Michiel


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
alexb
Charter Member
1696 posts
Nov-20-05, 06:43 PM (EST)
Click to EMail alexb Click to send private message to alexb Click to view user profileClick to add this user to your buddy list  
5. "RE: marriage algorithm"
In response to message #4
 
   >I sent
>another reply with a discussion on the presentation of the
>algorithm, but I can not find in back on the forum.

You mean it got misplaced. I apologize if it did. Please check the thread.

>I think
>it is important that the algorithm is presented clearly;

Absolutely.


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
brac37
Member since Nov-24-05
Nov-24-05, 05:27 PM (EST)
Click to EMail brac37 Click to send private message to brac37 Click to view user profileClick to add this user to your buddy list  
7. "RE: marriage algorithm"
In response to message #6
 
   Dear Alex B.

I sent you the above reply three times, but I think the second time got lost again. In the last attempt, I had [code]d the figures to get them correct. So it would be nice if you replace the above by it. I have registered myself in order to be able to attach files, which I tried, but it did not work. So I put it below, but now with all layout details, I hope.

Michiel


GREEDY PHASE:


| 1         |       |
|   1       |       |
|     .     |   D   |
|       .   |       |
|         1 |       |
|-----------|-------|
|           |       |
|     C     |   B   |
|           |       |
A                  

If block B is empty (0 by 0), then we are done, the family has a SDR. If B contains a 1, interchange rows through C and columns through D of A to put a 1 in the upper left corner of B. Next, replace B with the matrix obtained by using all but the first row and first column of B, replace C and D accordingly, and resume the greedy phase.

So we finally arrive at an empty B or a B with only zero entries.

B HAS ONLY ZEROS:


| 1         |       |
|   1       |       |
|     .     |   D   |
|       .   |       |
|         1 |       |
|-----------|-------|
|           |       |
|     C     |   0   |
|           |       |
A                  

If block C has only zeros, we are done; the family has no SDR because the sets associated with the columns through C together with a set associated with a column through D violate the marriage condition; that is, the union of these sets contains one fewer elements than the number of sets.

So assume that C has at least one 1. Let E be the columns of C that contain a 1. Interchange corresponding pairs of rows and columns of A to reach the following figure:


| 1     |       |       |
|   .   |       |   H   |
|     1 |       |       |
|-------|-------|-------|
|       | 1     |       |
|       |   .   |   G   |
|       |     1 |       |
|-------|-------|-------|
|       |       |       |
|   0   |   E   |   0   |
|       |       |       |
A                      

If aij = 1 in block E and ajk = 1 in block G, then interchange columns j and k of A and resume the greedy phase with B the lower right corner block which now contains a 1.

Otherwise, G has only zeros. If H has only zeros as well, then the set corresponding to any column through G violates the marriage condition.

LABELED PHASE:


| 1     |       |       |
|   .   |       |   H   |
|     1 |       |       |
|-------|-------|-------|
|       | 1     |       |
|   F   |   .   |   0   |
|       |     1 |       |
|-------|-------|-------|
|       |       |       |
|   0   |   E   |   0   |
|       |       |       |
A                      

Having reached here, every column of E contains a 1 and H does not only contain zeros. If the block F contains only zeros, then we are done; the family has no SDR because the sets corresponding to the columns through F and one column through H violates the marriage condition.

If for every nonzero column of F, the corresponding row of H has only zeros, then let E1 be the nonzero columns of F and let G1 be the rows of H corresponding to the columns of E1. Interchange corresponding pairs of rows and columns to get


| 1     |       |           |           |
|   .   |       |           |     H1    |
|     1 |       |           |           |
|-------|-------|-----------|-----------|
|       | 1     |           |           |
|   F1  |   .   |           |     G1    |
|       |     1 |           |           |
|---------------|-----------|-----------|
|       |       | 1         |           |
|       |       |   1       |           |
|   0   |   E1  |     .     |     0     |
|       |       |       .   |           |
|       |       |         1 |           |
|---------------|-----------|-----------|
|               |           |           |
|               |           |           |
|       0       |     E     |     0     |
|               |           |           |
|               |           |           |
A                                      

If G1 has a 1, then we can interchange a column through G1 with a column through E1 to put a 1 in the zero block G just below G1, whence we can do another column interchange to put a 1 into the lower right block B of A and resume the GREEDY PHASE.

Otherwise, G1 has only zero entries. If F1 has only zeros, then, as with F, the sets corresponding to the columns of F1 and one set corresponding to a column of G1 violate the marriage condition. Otherwise, let E2 be the nonzero columns of F1. Interchange corresponding pairs of rows and columns to reach


| 1 |   |       |           |     H2    |
|---|---|-------|-----------|-----------|
| F2| 1 |       |           |     G2    |
|-------|-------|-----------|-----------|
|   |   | 1     |           |           |
| 0 | E2|   .   |           |     0     |
|   |   |     1 |           |           |
|---------------|-----------|-----------|
|       |       | 1         |           |
|       |       |   1       |           |
|   0   |   E1  |     .     |     0     |
|       |       |       .   |           |
|       |       |         1 |           |
|---------------|-----------|-----------|
|               |           |           |
|               |           |           |
|       0       |     E     |     0     |
|               |           |           |
|               |           |           |
A                                      

If G2 contains a 1, we can do a series of column swaps to put a 1 to the right of E and resume the GREEDY PHASE. Otherwise, if F2 contains only zero entries, then the sets corresponding to the columns through F2 and one set corresponding to a column through G2 violate the marriage condition.

Otherwise, we continue the construction of Ei's, Fi's, Gi's and Hi's until some Gi has a nonzero entry (in which case we do a series of swaps that puts a 1 to the right of E and resume the GREEDY PHASE) or some Fi has only zero's (in which case the marriage condition is violated). Since H has at least one 1, this process stops before we reach a Hi with zero rows.

[Example:


          1 0 0 0 1
          1 1 0 0 0
          0 1 1 0 0
          0 0 1 1 0
          0 0 0 1 0

A series of 4 swaps needed to put a 1 in the lower right corner.]


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
McWorter
guest
Nov-24-05, 06:16 PM (EST)
 
8. "RE: marriage algorithm"
In response to message #7
 
   Looks good, and contains more detail. However, since your proof and the published proof are essentially the same, Prof. Bogomolny may choose not to modify his page any further.

Thanks again for your help in clarifying things.
William


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top
brac37
Member since Nov-24-05
Nov-29-05, 05:32 PM (EST)
Click to EMail brac37 Click to send private message to brac37 Click to view user profileClick to add this user to your buddy list  
9. "RE: marriage algorithm"
In response to message #8
 
   Dear Professor McWorter.

My last reply IS your algorithm. MY algorithm can be found in the first message of this thread, but has already been rejected, essentially by yourself when you updated the page on the marriage algorithm. Both algorithms are not that much different and I do not prefer one over the other.

What I think is more important is that the algorithm is presented clearly. That is why I tried to clarify your proof, which resulted in my previous reply. Since you still recognize your own algorithm and think my clarifications look good, it'seems a good idea to apply them. However, with your name above the algorithm, your approval is required.

Michiel


  Alert | IP Printer-friendly page | Reply | Reply With Quote | Top

Conferences | Forums | Topics | Previous Topic | Next Topic

You may be curious to have a look at the old CTK Exchange archive.
Please do not post there.

|Front page| |Contents|

Copyright © 1996-2018 Alexander Bogomolny

Search:
Keywords:

Google
Web CTK