Implementing Bron–Kerbosch algorithm in python

前端 未结 3 1559
旧巷少年郎
旧巷少年郎 2021-02-09 07:40

for a college project I\'m trying to implement the Bron–Kerbosch algorithm, that is, listing all maximal cliques in a given graph.

I\'m trying to implement the first alg

3条回答
  •  旧巷少年郎
    2021-02-09 08:07

    Python is getting confused because you are modifying the list that it is iterating over.

    Change

    for vertex in p:
    

    to

    for vertex in p[:]:
    

    this will cause it to iterate over a copy of p instead.

    You can read more about this at http://effbot.org/zone/python-list.htm.

提交回复
热议问题