Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8253815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:00:14+00:00 2026-06-08T01:00:14+00:00

I try to implement the karger Minimum Cut algorithm ( Karger wiki page )

  • 0

I try to implement the karger Minimum Cut algorithm (Karger wiki page)

So far, I have tried my algorithm on small examples (input of size 10) and it seems to work. But when I try to have a bigger input, let’s say 200. It just crashes.

To store the minimum cut data, I create a 2D array: GraphCut[SIZE_ARRAY][SIZE_ARRAY_2]
SIZE_ARRAY = 200 in this case, but I can’t find a good length for SIZE_ARRAY_2.

Issue is, SIZE_ARRAY_2 has to be big as I modify the initial array to merge the different vertices.

If I declare SIZE_ARRAY_2 = 200, the size won’t be enough, but if i put SIZE_ARRAY_2 = 1000, the program just crashes.

The thing is, I have to execute the algorithm 100000 times.

Here is parts of the code:

#define ARRAY_SIZE 200
#define ARRAY_SIZE_2 200

int main()
{
    int minCut,minMinCut;

    for (int k = 0; k < ARRAY_SIZE * ARRAY_SIZE * 4;k++) {
        minCut = kargerMinCut(k);
        if (k == 0)
            minMinCut = minCut;
        else if (minMinCut > minCut)
            minMinCut = minCut;
    }
    printf("\n minMinCut = %d\n", minMinCut);

    return 0;
}

int kargerMinCut(int k) {
// 1st dimension: each different node
// 2nd dimension: vertices
    long graphCut[ARRAY_SIZE + 1][ARRAY_SIZE_2] = {0};
    populateIntegerArray(graphCut); // import data from a file

    int nodeToMain[ARRAY_SIZE + 1];
    int sizeOfMainNode, indexToMerge,initialRand,i,j,m,nodeToMerge,nodeRemaining = ARRAY_SIZE;
    for (m = 0;m<ARRAY_SIZE + 1;m++) // initialization of nodeToMain
        nodeToMain[m] = m;

    while (nodeRemaining > 2) {
i = 0;
        j = 0;
        srand(time(NULL) + nodeRemaining);// initialise rand
        initialRand = nodeToMain[rand()%(ARRAY_SIZE) + 1]; // pick a random initial node, but not a merged one
        sizeOfMainNode = sizeOfArray(graphCut[initialRand]); // size of the initial node

        srand(time(NULL) + k); // initialise rand
        indexToMerge = rand()%sizeOfMainNode;// pick another random node in the linked nodes (its index to be precise)
        nodeToMerge = nodeToMain[graphCut[initialRand][indexToMerge]];

        for (m = 0;m<ARRAY_SIZE + 1;m++)  // update the nodeToMain array, initialRand is now the main node for nodeToMerge
            if (nodeToMain[m] == nodeToMerge)
                nodeToMain[m] = initialRand;

        // remove the nodeToMerge numbers from the graphCut[initialRand] (as they are going to be merged)
        while(graphCut[initialRand][j] > 0 && j < sizeOfMainNode) {
            if (initialRand == nodeToMain[graphCut[initialRand][j]]) {
                // if this is the last element, do nothing
                while(nodeToMain[graphCut[initialRand][sizeOfMainNode - 1]] == initialRand && j < sizeOfMainNode - 1) {
                    graphCut[initialRand][sizeOfMainNode - 1] = 0;
                    sizeOfMainNode--;
                }
                graphCut[initialRand][j] = nodeToMain[graphCut[initialRand][sizeOfMainNode - 1]];
                graphCut[initialRand][sizeOfMainNode - 1] = 0;
                sizeOfMainNode--;
            }
            j++;
        }

        i = 0;
        while (graphCut[nodeToMerge][i] > 0 && sizeOfMainNode < ARRAY_SIZE_2 && i < ARRAY_SIZE_2) { // add each vextex of the nodeTomerge to the merged nodes
            if (nodeToMain[graphCut[nodeToMerge][i]] != initialRand) {
                graphCut[initialRand][sizeOfMainNode] = nodeToMain[graphCut[nodeToMerge][i]];
                sizeOfMainNode++;
            }
            i++;
        }

        nodeRemaining--;
    }

    return sizeOfArray(graphCut[nodeToMain[1]]);
}

I’m sure that the code is not really clean, maybe even really bad (beginner in C). So i Welcome any other advice.

The errors I get with the debugger seems really random.
Error is:

Impossible to divide by 0

it stops in time64.c at line 62

tim = (__time64_t)((nt_time.ft_scalar - EPOCH_BIAS) / 10000000i64);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:00:17+00:00Added an answer on June 8, 2026 at 1:00 am

    The change in array size is probably causing a stack overflow. A common default size for the stack is 1MB (1048576 bytes). If you have:

    long graphCut[200][1000];
    

    and 4 == sizeof(long) the graphCut array is taking up 200 * 1000 * 4 = 800000 bytes, which leaves 248576 bytes which may not be enough for the stack variables in populateIntegerArray() function (I don’t see that function). If 8 == sizeof(long) then the array would require 1600000 bytes, which is greater than 1MB.

    If an array of that size is required then allocate (all or part) on the heap instead of the stack. For example:

    long* graphCut[ARRAY_SIZE_1];
    int i;
    for (i = 0; i < sizeof(graphCut)/sizeof(graphCut[0]); i++)
    {
        graphCut[i] = malloc(ARRAY_SIZE_2 * sizeof(graphCut[0][0]));
        memset(graphCut[i], 0, ARRAY_SIZE_2 * sizeof(graphCut[0][0]));
    }
    
    for (i = 0; i < sizeof(graphCut)/sizeof(graphCut[0]); i++)
    {
        free(graphCut[i]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to implement the following code: <div class=clearid=usernameline>username:<input type=text name=username id=username style=border:1px solid
I try to implement an RSA algorithm in a Java program. I am facing
I try to implement Hash join in Hadoop. However, Hadoop seems to have already
I try to implement callback interface with COM techonlogy and have IDL like that:
I try to implement Incognito k-anonymization algorithm in Java. A part of this algorithm
I try to implement a TypedActor in Java following the examples on Typed Actors
I try to implement a build pipeline using TFS. We already have TFS building
I try to implement the following code, this page will display when survey is
I try to implement the following code: <input type=radio name=yesno2 value=yes style=outline:0;/>Yes <input type=radio
I try to implement input user mask via that lesson and can't run it.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.