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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:21:09+00:00 2026-05-27T05:21:09+00:00

I have a quicksort that works, and a selection sort that also works- I

  • 0

I have a quicksort that works, and a selection sort that also works- I want to sort an int[] of random ints with quicksort up until the array.length = 1 and then for that last element call selection sort. I know I need to have a conditional that checks the array.length and when length = 1 then, return selectionSort() Im not sure how to structure it in the recursive calls within quickSort(). Here are my two sorting methods:

QuickSort:

public void quickSort(int array[], int start, int end) {
    int i = start; // index val of left-to-right scan
    int k = end; // index val of right-to-left scan

    if (end - start >= 1){
        PIVOT = array[start]; 
        while (k > i){
            while (array[i] <= PIVOT && i <= end && k > i)
                i++; 
            while (array[k] > PIVOT && k >= start && k >= i)
                k--;
            if (k > i) 
                swap(array, i, k); 
        }
        swap(array, start, k); 
        quickSort(array, start, k - 1); 
        System.out.println(k);
        quickSort(array, k + 1, end); 

    }
    return;
}

Selection Sort:

public void selectionSort(int[] nums) {
    //nums[0] = array[0];
    System.out.println(nums.length);
    for (int i = 0; i < (nums.length - 1); i++) {
        for (int j = i + 1; j < nums.length; j++) {
            if (nums[i] > nums[j]) {
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
            }
        }
    }
}
  • 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-27T05:21:10+00:00Added an answer on May 27, 2026 at 5:21 am

    You’re already almost doing it. With this line, end - start you’re getting the length. If that length is less than your SelectionSortThreshold, run insertion sort only on the current length. This means modifying your selectionSort routine to accept a start and end parameter so that you can selection sort only a small portion of the array.

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

Sidebar

Related Questions

I have been reading about Quicksort and found that sometimes it' s referred to
I have this quick sort implementation to sort the characters. int main(){ char val[]
I have an array of 1000-2000 elements which are pointers to objects. I want
I have implemented a working quickSort algorithm using the first element in the array
I have read that recursive implementation of QuickSort will require O(log n) of additional
I have a quick sort algorithm and a counter that I increment every time
Currently, I have a barebones implementation of the quicksort algorithm to sort some randomly
I have realized that in order for quicksort to work, all the infinities need
I finally finished a home-grown version of quicksort to sort an array of structures
I have to find SHA256 hashes of 2^25 random strings. And then look for

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.