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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:47:16+00:00 2026-06-02T00:47:16+00:00

I am implementing a quicksort algorithm and have succesfully partitioned the input array around

  • 0

I am implementing a quicksort algorithm and have succesfully partitioned the input array around a pivot. The problem is, I am confused in how to recursively sort the 1st part and 2nd part of the array (i.e specifying the range) using the same input array.
Below is my implementation

class QuickSort {

    int i; 
    int l = 0;

    public void quicksort(int A[], int n) {

        if (n == 1) {
            return;
        } else {
            partition(A, 0, n);
//----Confused as from this point
            quicksort(A, A[i]);

            //Recursively sort both parts of the array
        }
    }

    public int partition(int A[], int l, int r) {
        int p = A[l];//Choose pivot
        i = l + 1;
        //Partition around A through P
        for (int j = i; j < r; j++) {
            if (A[j] < p) {
                swap(A, i, j);
                ++i;
            }
        }
        swap(A, l, i - 1 );
        return i;
    }

    public void swap(int A[], int i, int j) {
        int temp = A[i];
        A[i] = A[j];
        A[j] = temp;
    }
    public void display(int A[]){
        for (int i = 0; i < A.length; i ++){
            System.out.print(A[i] + " ");
        }
    }
}
class QuickSortApp{
    public static void main(String args[]){
        QuickSort quick = new QuickSort();
        int A[] = {6,2,7,8,4,3,5};
        quick.quicksort(A,  A.length);
        quick.display(A);
    }
}

Please, I would also appreciate being corrected on any other inefficencies in my algorithm. Thanks

  • 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-02T00:47:18+00:00Added an answer on June 2, 2026 at 12:47 am

    Change your quicksort() signature to quicksort(int[] A, int begin, int end)

    Since, you actually did the sorting inside partition(). What I would do is this:

    if (end-begin <= 1) {
        return;
    } else {
        int pivot = partition(A, begin, end);
        quicksort(A, begin, pivot);
        quicksort(A, pivot, end);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have been working on properly implementing a quicksort algorithm for a homework
Implementing the basic algorithm using last array as a pivot in Java, is it
I am having issues implementing a quicksort to sort an array of strings. I
I spend some time implementing a quicksort algorithm in C#. After finishing I compared
I have an input file that I want to sort based on timestamp which
When implementing Quicksort, one of the things you have to do is to choose
implementing publishActivity in PHP using the REST API using this code: $activity = array(
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
Implementing Document-View pattern I faced the problem: standard generic collections and dictionaries ( List<T>
As a learning experience I recently tried implementing Quicksort with 3 way partitioning in

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.