| 1810 | |

| 1811 | def KneserGraph(self,n,k): |

| 1812 | r""" |

| 1813 | Returns the Kneser Graph of parameters `n, k`. |

| 1814 | |

| 1815 | The Kneser Graph of parameters `n,k` is the graph |

| 1816 | whose vertices are the `k`-subsets of `[0,1,\dots,n-1]`, and such |

| 1817 | that two vertices are linked if their corresponding sets |

| 1818 | are disjoint. |

| 1819 | |

| 1820 | For example, the Petersen Graph can be defined |

| 1821 | as the Kneser Graph of parameters `5,2`. |

| 1822 | |

| 1823 | EXAMPLE:: |

| 1824 | |

| 1825 | sage: KG=graphs.KneserGraph(5,2) |

| 1826 | sage: P=graphs.PetersenGraph() |

| 1827 | sage: P.is_isomorphic(KG) |

| 1828 | True |

| 1829 | """ |

| 1830 | |

| 1831 | g=graph.Graph() |

| 1832 | from sage.combinat.subset import Subsets |

| 1833 | |

| 1834 | if k>n/2: |

| 1835 | g.add_vertices(Subsets(n,k).list()) |

| 1836 | |

| 1837 | S=Subsets(Subsets(n,k),2) |

| 1838 | l=lambda x:list(x) |

| 1839 | [g.add_edge(s,t) for [s,t] in map(l,S) if s.intersection(t).cardinality() ==0 ] |

| 1840 | return g |