1
2 3
4
Handshake with 2-3 and 1-4 will cause cross. In how many ways these N people can make handshakes so that no two handshakes crosses each other. N would be even.
For example, in above diagram, there are two non-crossing ways to handshake {{1, 2}, {3, 4}} and {{1, 3}, {2, 4}}.
Or we can say :
There are 2n people sitting on a round table. In how many ways can they shake their hands, in pairs, without crossing the hands?
Lets collect data for n=1, n=2, n=3,.....
So, we got a sequence of numbers i.e 1, 2, 5, 14 .....
- Dyck Paths and Acceptable Sequences
- ( ) ( ) ( )
- ( ( ) ) ( )
- ( ) ( ( ) )
- ( ( ( ) ) )
- ( ( ) ( ) )
Clearly, each acceptable route is either above the diagonal or below the diagonal and both of these paths are symmetric. So we calculate the number of paths below the diagonal and multiply it by 2. Each route is a sequence of northerly blocks and westerly blocks. We identify west with and north with . Each route corresponds to a sequence of copies of 's and copies of 's. But in order for the route not to go above the diagonal, we must have
for . So the number of acceptable routes above the diagonal equals the Catalan number, and the total number of acceptable routes is
The above diagram shows the routes below the diagonal for . Notice that the number of such routes is equal to . So the answer is
3. Binary trees:
A rooted binary tree is a tree with one root node, where each node has either zero or two branches descending from it. A node is internal if it has two nodes coming from it. How many rooted binary trees are there with internal nodes?
be the number of rooted binary trees with internal nodes. Then as in the picture. Now for suppose there is a rooted binary tree with internal nodes. The root node is internal. There are internal nodes on the left and internal nodes on the right, for some Looking at the left and right sides gives two rooted binary trees with and internal nodes, respectively. So
which is the same recurrence relation as the Catalan numbers. So for all
4. Polygon triangulations:
How many ways are there to cut an -gon into triangles, by drawing non-crossing lines between vertices of the polygon?
Let be the number of such triangulations, and define . Consider , which counts triangulations of an -gon. The idea is to pick an edge of that -gon and classify triangulations by which triangle that edge ends up in.
Number the vertices . Suppose our edge is . If the triangle this edge ends up in is , then this triangle splits the polygon into two remaining polygons that must be triangulated.
- If , then what is left is an -gon. The number of triangulations like this is .
- If , there is a triangle on one side and an -gon on the other side. The number of triangulations like this is .
- If , there is a quadrilateral on one side and an -gon on the other side. The number of triangulations like this is .
Proceeding in this way,
Also . This is the same recurrence relation and initial condition that the Catalan numbers satisfy, so it must be the case that for all .
##########################################################################
Let's rewrite the main recursive equation of Catalan numbers and search for a pattern.
Equation is :
Cn+1 = C0Cn + C1Cn−1 + ⋯ + CnC0 = k=0∑nCk Cn−k
We can see that it has mirror image part of itself, for instance 'C0Cn
' have its mirror part 'CnC0' at the end, same follows for others, from this mirror part idea, we can actually find the nth Catalan number from previous values [ Insight of Dynamic programming ]
Let's suppose we already found, first three numbers of Catalan sequence :
1, 2, 5. Write them in vertical order and rewriting the same column again next to it.
1 1
2 2
5 5
Connect them in this fashion:
1 1
\ /
2--\--2
/ \
5 5
'1' is connected with '5'
'2' is connected with '2'
'5' is connected with '1'
for getting the 4th Catalan number we can multiply these pairs and further add them, i.e
C(4) = 1*5 + 2*2 + 5*1 = 14
Recursive approach :
Time complexity : Exponential
Further improving this,
Dynamic Programming solution :
Time Complexity : O(n^2)
Again further optimising and using
there we will find (n/2)th Catalan
As many companies like Amazon have asked questions based on this topic :
Handshake Problem
Comments
Post a Comment