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

  • SEARCH
  • Home
  • 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 3310428
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:45:33+00:00 2026-05-17T21:45:33+00:00

Am suppose to return the number of character comparisons. In the while() loop i

  • 0

Am suppose to return the number of character comparisons. In the while() loop i compare the index of the characters and update the counter. My question is, is it right to do it that way or i have to compare the characters themselves. I think comparing the index and updating the counter is the same as comparing the characters themselves. Any idea?

Need help.

The following is the code of the algorithm.

    // Sort an array of strings using quick sort
   // Always pivot on the first element
   // Return the number of CHARACTER comparisons

  public int stringQuickSort(ComparableByte[][] strings) {
      Counter nCompares = new Counter();
      sortStringQuickSort(strings, 0, strings.length-1, 0, nCompares, false);
    return nCompares.value;
  }

  public void sortStringQuickSort(ComparableByte[][] strings, int lo, int hi, int d, Counter nCompares, boolean switchToOtherAlgorithm){
      if(!switchToOtherAlgorithm){
      if(hi <= lo)
          return;
      }else if(hi <= lo+10){

              stringInsertionSort(strings);
          return;
      }
      int lt = lo, gt = hi;
      int v = characterAt(ComparableByte.toString(strings[lo]), d);
      int i = lo+1;

      while(i <= gt){
          int t = characterAt(ComparableByte.toString(strings[i]), d);
          nCompares.value++;
          if (t < v){
              swapTwoComparableByteElements(strings, lt++, i++);
              nCompares.value++;
          }
          else if(t > v){
              swapTwoComparableByteElements(strings, i, gt--);
          }
          else 
              i++;
      }

      sortStringQuickSort(strings, lo, lt-1, d, nCompares, switchToOtherAlgorithm);
      if(v >= 0){
          sortStringQuickSort(strings, lt, gt, d+1, nCompares, switchToOtherAlgorithm);
      }
      sortStringQuickSort(strings, gt+1, hi, d, nCompares, switchToOtherAlgorithm);
  }

Thanks for your help

  • 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-17T21:45:33+00:00Added an answer on May 17, 2026 at 9:45 pm

    Usually these things are used to provide an empirical estimate of comparisons needed by algoritms to study if the expected behaviour is correct.

    So, yes, it doesn’t matter exactly what you count if you take care to count the correct operations. You don’t care if they are characters of indices as long as you are actually counting whenever you program needs to compute a < > <= >= = operation related to the input and the current implementation.

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

Sidebar

Related Questions

Suppose I have a method that must return an object (say from a database
Suppose I have a list that I wish not to return but to yield
suppose that,we have following code auto_ptr<T> source() { return auto_ptr<T>( new T(1) ); }
def count_chars(s): '''Return a dict that contains each character in str s as a
Suppose we want to return a value from a function based on a condition.
Suppose I've the following function: function mul() { return array_reduce(func_get_args(), '*'); } Is is
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
There's no strongly typed View() method to return an ActionResult. So, suppose I have
I have an sql statement that is supposed to return 2 rows. the first
I am using java language,I have a method that is supposed to return an

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.