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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:46:07+00:00 2026-05-23T18:46:07+00:00

I am currently studying quicksort and would like to know how it works when

  • 0

I am currently studying quicksort and would like to know how it works when the first (or last) element is chosen as the pivot point.

Say for example I have the following array:

{15, 19, 34, 41, 27, 13, 9, 11, 44}

This is what I think happens:

{15, 19, 34, 41, 27, 13, 9, 11, 44}
 ^
pivot

{15, 19, 34, 41, 27, 13, 9, 11, 44}
 ^                              ^
compare these two, they are good

{15, 19, 34, 41, 27, 13, 9, 11, 44}
 ^                          ^
compare these two and swap

{11, 19, 34, 41, 27, 13, 9, 15, 44}
 ^                       ^
compare these two and swap

{9, 19, 34, 41, 27, 13, 11, 15, 44}
 ^                  ^
compare these two, they are good

{9, 19, 34, 41, 27, 13, 11, 15, 44}
 ^              ^
 compare these two, they are good

{9, 19, 34, 41, 27, 13, 11, 15, 44}
 ^          ^
compare these two, they are good

{9, 19, 34, 41, 27, 13, 11, 15, 44}
 ^      ^
 compare these two, they are good

{9, 19, 34, 41, 27, 13, 11, 15, 44}
 ^  ^
 compare these two, they are good

{9, 19, 34, 41, 27, 13, 11, 15, 44}

End of first partition

Is this how it works? If so, would 19 be the new pivot point, or do you divide the array in half to find it (so that it would be 27/13), or does it depend on the implementation of the quicksort? Thanks for your time!

  • 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-23T18:46:07+00:00Added an answer on May 23, 2026 at 6:46 pm

    Check wikipedia, there is a little example with a bit smaller list of inplace quicksort http://en.wikipedia.org/wiki/Quicksort

    With your example the idea is to partition

    {15, 19, 34, 41, 27, 13, 9, 11, 44}
    

    into

    {13, 9, 11 -- 15 -- 19, 34, 41, 27, 44}
    

    So first we move pivot to the end

    Swap 44, and 15
    {44, 19, 34, 41, 27, 13, 9, 11, 15}
     ^                          ^
    
    Than check 44, its larger than pivot, so swap with one one before last...
    
    {11, 19, 34, 41, 27, 13, 9, 44, 15}
     ^                       ^
    
    than check element at some position as last one was larger than pivot.
    9 < 15, so proceed to the next, 19 > 15 => swap
    
    {11, 9, 34, 41, 27, 13, 19, 44, 15}
            ^            ^
    
    swap again
    {11, 9, 13, 41, 27, 34, 19, 44, 15}
            ^       ^
    
    next
    {11, 9, 13, 41, 27, 34, 19, 44, 15}
                ^   ^
    
    and second last swap
    
    {11, 9, 13, 27, 41, 34, 19, 44, 15}
                ^    
    
    Now as forward and backward indices reached each other,
    we swap pivot into right position
    
    {11, 9, 13, 15, 41, 34, 19, 44, 27}
    

    And we got partitioned set. Items less than 15 at the beginning, than pivot = 15, and then greater elements.

    EDIT: algorithm described in wikipedia article is a bit different:

    Legend:
    ^ = storeindex
    # = i
    
    {44, 19, 34, 41, 27, 13, 9, 11, 15}
     ^#
    
    {44, 19, 34, 41, 27, 13, 9, 11, 15}
     ^   #
    
    ... until ...   
    
    {44, 19, 34, 41, 27, 13, 9, 11, 15}
     ^                   #
    
    {13, 19, 34, 41, 27, 44, 9, 11, 15}
         ^                   #
    
    {13, 9, 34, 41, 27, 44, 19, 11, 15}
            ^                   #
    
    {13, 9, 11, 41, 27, 44, 19, 34, 15}
                ^                   #
    
    {13, 9, 11, 15, 27, 44, 19, 34, 41}
                ^- pivot
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently studying Fitch Format first order logic proofs. My lecturer follows closely
I am currently studying Perl programming and am running into statements like this: return
I am currently studying whether it would be suitable for me to use Ehcache
I'm studying C# right now and currently learning threading. Here is a simple example
am currently studying jquery, can someone tell me the things that javascript native can
I'm currently studying Ubuntu Server administration, and also HTML/CSS. When it comes to the
I am currently studying for an exam I'll have on x86 assembly. I didn't
I'm currently studying the Mockito framework and I've created several test cases using Mockito.
I am currently studying recursion in school, and I have trouble thinking about methods
I'm currently studying for a CS course's final exam and I've run into a

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.