Returning the size of the largest clique in a graph This function is to return the size of the largest clique in a graph. When I run this code, I am running out of space at runtime. Also, it is insanely slow, so any speed tips would be appreciated.

int cliqueSize(graph &amp;g, std::vector&lt;VertexID&gt; nodes, std::vector&lt;EdgeID&gt; edges)
{
    std::vector&lt;std::vector&lt;VertexID&gt; &gt; previous_cliques;

    // start with all the singular nodes...
    for (unsigned i = 0; i &lt; nodes.size(); i++)
    {
        std::vector&lt;VertexID&gt; tmp;
        tmp.push_back(nodes[i]);
        previous_cliques.push_back(tmp);
    }

    for (unsigned clique_size = 1; clique_size &lt; nodes.size(); clique_size++)
    {
        std::vector&lt;std::vector&lt;VertexID&gt; &gt; new_cliques;
        // go through all the nodes to try to add to the clique.
        for (unsigned i = 0; i &lt; nodes.size(); i++)
        {
            // try to add node i to clique j.
            for (unsigned j = 0; j &lt; previous_cliques.size(); j++)
            {
                // make sure node j is not already in the clique.
                if (std::find(previous_cliques[j].begin(), previous_cliques[j].end(), nodes[i]) == previous_cliques[j].end()) 
                {
                    std::vector&lt;VertexID&gt; potential_clique(previous_cliques[j]);
                    potential_clique.push_back(nodes[i]);

                    // isClique has no issues, just checks if the given graph is a clique...   
                    if (isClique(g, potential_clique, edges))
                    {
                        new_cliques.push_back(potential_clique);
                    }
                }
            }
        }
        // no new cliques? 
        if (new_cliques.size() == 0) { return clique_size; }
        else { previous_cliques = new_cliques; }
    }
    return nodes.size();
}
First of all, start passing things by const reference more.  You're passing both nodes and edges by value, which will make a copy.
Instead of looping through the containers by index, you should use iterators.
Pushing tmp into previous_cliques will make a copy.


The following may be faster:

std::vector&lt;VertexID&gt; tmp(1);
for (...) {
    tmp[0] = nodes[i];
    previous_cliques.push_back(tmp);
}


(If you're worried about scope, just wrap it in braces.)


Checking for emptiness with size() may be less efficient than with empty(); unlikely in the case of a vector, though (I think size() must be O(1)).
You're not showing us isClique, so it's hard to comment on that.  Make sure you're passing be const reference there.  Also consider not copying previous_cliques until you know you want to push it into new_cliques and instead handling nodes[i] as a special case (may be faster, may be slower).
If you're using C++11, the emplace functions are your friend.