If you have a fixed size like 5, then you should be able to speed things up by keeping an updated list of all 4-cliques for each member, stored as the three friends connected to that member (obviously, no need to include the member himself/herself in the list). Then when two members become friends, see if the two people have a list element in common (maybe organize lexicographically and iterate through both lists in parallel). If and only if they share a common list element, their friendship will create a 5-clique. Of course, you can keep track of 4-cliques by keeping lists of 3-cliques, etc. The memory overhead of this could be quite a lot in practice.