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 7506279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:12:47+00:00 2026-05-29T22:12:47+00:00

I am getting some weird running times for my mergesort algorithm…I want to run

  • 0

I am getting some weird running times for my mergesort algorithm…I want to run the algorithm (say 1000 times) on the same permuted ArrayList. Right now, I just create an array of ArrayList of size 1000, then time how long it takes to sort each of these, then take the average of the times.

So my question is: am I sorting the same list over and over? If I change one instance of the ArrayList in the array say at index 0, will the other ArrayLists in the array stay the same? I would assume so, but I want to be certain that’s not happening? Thanks.

    for (int N = 1000; N <= 10000; N += 1000) {

      //copy the array
      @SuppressWarnings("unchecked")
      ArrayList<Integer>[] container = (ArrayList<Integer>[])new ArrayList[N];
      ArrayList<Integer> testArray1 = generatePermutedOrder(N);
      for(int j=0; j<timesToLoop; j++){
        container[j] = testArray1;
      }

      System.out.print(N + "\t");

      // let things stabilize
      startTime = System.nanoTime();
      while (System.nanoTime() - startTime < 1000000000)
        ;

      // time the routine
      startTime = System.nanoTime();
      for (int i = 0; i < timesToLoop; i++) {
          mergesort(container[i]);
      }
  • 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-05-29T22:12:50+00:00Added an answer on May 29, 2026 at 10:12 pm

    If I change one instance of the ArrayList in the array say at index 0, will the other ArrayLists in the array stay the same?

    Yes, modifying ArrayList at index 0 won’t effect the other indexes. (but make sure that other indexes don’t have reference to same ArrayList)

    Scenerio 1: (Modifying index 0 will effect index 1)

    ArrayList[] arr = new ArrayList[2];
    ArrayList aList = new ArrayList();
    
    arr[0] = aList;
    arr[1] = aList;
    

    Scenerio 2: (Modifying index 0 will NOT effect index 1)

    ArrayList[] arr = new ArrayList[2];
    ArrayList aList1 = new ArrayList();
    ArrayList aList2 = new ArrayList();
    
    arr[0] = aList1;
    arr[1] = aList2;
    

    So, make sure it’s Scenerio 2 in your code.

    EDIT:

    ArrayList<Integer> testArray1 = generatePermutedOrder(N);       
    for(int j=0; j<timesToLoop; j++)
    {         
        container[j] = testArray1; // same reference pointing to same ArrayList is added in each interation
    }
    

    You are adding same reference to each index. So, modifying at any index will effect remaining indexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting some weird output when running (seemingly simple) code. Here's what I have:
I'm getting some really weird issues with the Django admin application. I'm running everything
I'm getting some weird black spots with a custom map page (via the Google
I'm getting some very wierd errors. The compiler seems to want to call the
I'm struggling getting some unit tests running and wondering if anyone might have anything
I am getting some open/closed times as integers since midnight. For example: 1140 =
I'm just getting started developing for Android and I'm running into a weird problem.
I keep getting some weird error in Processing, using the following tiny piece of
I'm getting some weird behavior in asp.net MVC2 (at least it's not what I'm
I'm getting some weird behavior from IE when trying to change a session variable

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.