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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:21:10+00:00 2026-05-26T10:21:10+00:00

Below is an LSD Radix sort implementation in Java from a textbook to sort

  • 0

Below is an LSD Radix sort implementation in Java from a textbook to sort an array of strings where each string contains exactly W characters.

I want to count the number of array accesses during runtime. I’ve read that LSD sort is supposed to require n * c array accesses where n is the number of strings and c the amount of characters in each string. However, the algorithm below accesses more than one array several times. If I increment a counter at each of these I’ll end up with a significant factor of nc.

So what exactly constitutes ‘array access’ in the context of algorithms? Is there only one instance of array access that is considered more significant that I should count here, or is this example in fact an inefficient implementation that uses more array access than necessary?

 public int lsdSort(String[] array, int W) {
  int access = 0;
  // Sort a[] on leading W characters.
  int N = array.length;
  String[] aux = new String[N];
  for (int d = W-1; d >= 0; d--)
  { // Sort by key-indexed counting on dth char.
    int[] count = new int[R+1]; // Compute frequency counts.
    for (int i = 0; i < N; i++) {
        count[array[i].charAt(d) + 1]++;
    }
    for (int r = 0; r < R; r++) {
        // Transform counts to indices.
        count[r+1] += count[r];
    }
    for (int i = 0; i < N; i++) {
        // Distribute.
        aux[count[array[i].charAt(d)]++] = array[i];

    }  
    for (int i = 0; i < N; i++) // Copy back.
        array[i] = aux[i];
  }

  return access;
  }
  • 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-26T10:21:10+00:00Added an answer on May 26, 2026 at 10:21 am

    I’ve read that LSD sort is supposed to require n times c array accesses where n is the number of strings and c the amount of characters in each string.

    Are you sure you haven’t read that it’s O(nc)? That’s not the same thing at all. It’s big-O notation. The point isn’t to determine the exact number of array accesses – it’s to talk about how it grows (or rather, the limit of how it can grow) as n or c increase. In this case it increases linearly – if you increase n by a factor of 1000, you would only expect the total cost to grow by a factor of 1000 too… whereas if it were an O(n2c) algorithm instead, it might grow by a factor of 1,000,000. (Strictly speaking any O(nc) algorithm is also O(n2c) due to it only being a limit, but let’s not get into that.)

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

Sidebar

Related Questions

Below is my current char* to hex string function. I wrote it as an
Below are lines from the c++ programming language template<class T > T sqrt(T );
Below is an example that is producing an exception in Java (and not matching
below is something I am trying to do with JavaScript. If I have string
Below query is resulting NO rows lstResults.RowSource = select EmpId from tblTesting where Empid
Below is a snippet from my build.xml file. I want to modify the file
Below function working ok but I want to make it simple. if (list.Exists(delegate(string s)
Below, in CreateTest, uponsuccessful, I want to redirect to Tests from CreateTest. I want
Below creates an image from hbitmap: IntPtr hbitmap = IntPtr.Zero; ... ... Image img
Below is my script that updates my characters position in my database: <script language=javascript

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.