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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:34:17+00:00 2026-05-22T17:34:17+00:00

Sort the following array a using quicksort, [6, 11, 4, 9, 8, 2, 5,

  • 0

Sort the following array a using quicksort,

[6, 11, 4, 9, 8, 2, 5, 8, 13, 7]

The pivot should be chosen as the arithmetic mean of the first and the last element, i.e., (a[0] + a[size - 1]) / 2 (rounded down).

Show all important steps such as partitioning and the recursive calls to the algorithm.


I understand how to sort the array using quicksort, however I’m not sure how to calculate the pivot.

Is the pivot calculated by 6 + 7 = 13 then 13 / 2 = 6.5 (rounded down is 6) so the pivot is 2 (i.e. the 6th element)?

I know the elements less than pivot appear on the left hand side, and elements greater than the pivot appear on the right hand side, and the partition repeats this step of sorting the sub-array.

Any help would be greatly appreciated.

  • 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-22T17:34:18+00:00Added an answer on May 22, 2026 at 5:34 pm

    For quicksort, the pivot can be whatever element you want.
    Check out Wikipedia.

    The problem was easily solved by choosing either a random index for the pivot, choosing the middle index of the partition or (especially for longer partitions) choosing the median of the first, middle and last element of the partition for the pivot

    Three choices thus :

    • First element
    • Middle element
    • Median of first, middle and last.

    And in you case using the mean of first and last element value would give you :

    6 + 7 = 13
    13 / 2 = 6.5
    6.5 rounded down = 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following ASM routine to bubble sort an array. I want
I'm trying to pre-sort an array of items are added into an array using
Let's say I'm trying to sort the following array. String[] array = { ABC12,
How might I sort the following using PHP? (where wed_2_open comes after wed_1_close) I
with reference of this question Sort json array I have the following JSON String
I would like to sort an array by the value in its first index,
I'm looking to use the results in an array and sort them using a
I've got the following objects using AJAX and stored them in an array: var
I am searching an array of custom items using the following NSPredicate : NSPredicate
I have an nsmutablearray named nsmarrMedicineInfo. I want to sort the element by using

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.