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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:37:29+00:00 2026-05-30T18:37:29+00:00

Okay I have an assignment to find the Kth smallest element in the list

  • 0

Okay I have an assignment to find the Kth smallest element in the list using several different methods….

first method is to sort the list, then return the Kth smallest element. easy, my mentality is say the list = 10 elements, sort the list in ascending order, then return the element in the 10th position

next method uses the Partition from Quicksort:

“The second algorithm is to apply the procedure Partition used in Quicksort. The procedure partitions an array so that all elements smaller than some pivot item come before it in the array and all elements larger than that pivot item come after it. The slot at which the pivot item is located is called the pivotposition. We can solve the Selection Problem by partitioning until the pivot item is at the kth slot. We do this by recursively partitioning the left subarray if k is less than pivotposition, and by recursively partitioning the right subarray if k is greater than pivotposition. When k = pivotposition, we’re done.”

Say I have a list of 10 items:

3 8 9 2 4 5 1 7 10 6, with 5 being the pivot.. I know I would normally would have 2 arrays

3 2 4 1 and 8 9 7 10 6

but what I don’t understand is: “We can solve the Selection Problem by partitioning until the pivot item is at the kth slot.”

what is the kth slot? to me i keep thinking kth = the length of the array, so in this case 10. which would have the 6 value in it, which is obviously not the lowest… and isn’t correct.

can someone use this sample array and kinda just show me what this algorithm means and how it finds the kth/smallest element? 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-05-30T18:37:30+00:00Added an answer on May 30, 2026 at 6:37 pm

    I think you have looking at the solution in a complicated way.

    This is how you find the kth smallest element using QuickSort (well not entirely quicksort, I will tell why).

    In quicksort you choose a random pivot element and divide the entire array into two and recursively sort the left and the right subarrays to form the entire sorted array.

    In this problem you don’t have to do that. All you are doing is,

    1. Choose a random pivot element.
    2. Divide the array with [Sub-array 1 ] Pivot [Sub-array2] where Subarray 1 has elements less than pivot and sub-array2 has elements
      greater than pivot.
    3. Check size of sub-array1.
       If it is,
            a.Greater than 'k' then your kth element lies in the first sub-array. Go recursively. Start sorting the sub-array1 alone and you can entirely discard the sub-array2 as you can be sure that 'kth' element cannot occur at a position greater than k! Repeat step-1 for the right sub-array
            b.Lesser than 'k' then your kth element lies in the second sub-array. Again do as said above. Repeat step-1 for left subarray.
            c.If the size of sub-array1 is k-1 then your pivot element must be the kth largest element in your array.Bingo! you have your 'kth' largest element in the array
    

    So to address your doubt,

    Here you are not sorting the entire array but only a portion of
    it.(even that is not true entirely. You will get it if you entirely
    understand my above explanation.)

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

Sidebar

Related Questions

Okay, so I have an assignment to code (using Java,but I don't think that
Okay I have two classes for two links and two divs with different information.
Okay I have searched and can't seem to come up with where to find
Okay, so I have a little assignment to do which needs some array of
okay have a this list: object[] test; test[0]=null; .... test[8700]=null; test[8701]= object[] .... test[9431]=
Okay I have spent the last 2 days trying to sort this one out.
Okay I have a project that is using the android-rss library (org.mcsoxford.rss). I created
Okay so this is for a school assignment. I have had no problems doing
Okay I have a list of devices where i can select which to edit.
Okay so I have an assignment where I have to create a class with

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.