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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:53:19+00:00 2026-05-20T04:53:19+00:00

So I am given an (unsorted) array A of N distinct integers, I am

  • 0

So I am given an (unsorted) array A of N distinct integers, I am trying to implement a divide-and-conquer algorithm to find the Kth smallest element (K ≤ N) in the array (i.e. it would be the overall smallest if K=1). The algorithm returns the value of the Kth smallest element in the array. I need it to run in O(N) time in the average case. Could anyone give me some hints?

  • 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-20T04:53:20+00:00Added an answer on May 20, 2026 at 4:53 am

    Sephy, I’m going to walk this through very carefully. You always have to be careful when helping people with algorithms, because, and I cannot stress this enough, solving algorithm problems are to programmers what weight-lifting is to professional athletes. Knowing how to put yourself into the mode of thinking like a computer is what you will get paid to do in a few years. So if the solutions are just given to you, you’re going to be the guy that bounces from job to job every 6 months instead of the guy who becomes the lead developer, or goes out on his own with a successful company.

    Now that that rant is out of the way…

    Traditionally, we think of algorithms that loop through the array once, and loop through it differently based on the first result, and repeat until we met some condition, to be O(n^2). Things that meet this criteria are selection sort, insertion sort, and bubble sort.

    But it doesn’t have to be. If we can properly divide the array into segments and prove the size of those segments, we can keep it on a low order.

    And, with most divide and conquer algorithms, we can start in the middle.

    Let A be an array of size N with N distinct elements in it.
    
    Let M be the element that resides at A[N/2]
    
    Let A-large be an array of all elements greater than M.
    Let A-small be an array of all elements less than M.
    

    What do we know about A-small and A large? Are they the same size? Maybe, but probably not.

    Is size(A-small) > k? or is it < k?

    If size(A-small) == k - 1, wouldn’t that make M the kth smallest element?

    Is there something we can do to create a new value for k and do some recurrsion here?

    I’m not going to finish this for you, because there should be plenty to chew on. These are the questions you need to ask yourself. @templatetypedef is 100% on the right track, this is just expanding on it.

    If you have some more questions, ask them, but there should be enough here to allow you to solve it without robbing you of your mental exercise.

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

Sidebar

Related Questions

Question: Given an unsorted array of positive integers, is it possible to find a
Given a list of unsorted numbers, I want to find the smallest number larger
I had this question: Given an unsorted array of positive integers and an integer
Suppose you are given an array of unsorted integers as A = {3,4,5,1,4,2} Input
You are given as input an unsorted array of n distinct numbers, where n
I'm currently trying to verify whether or not, given an unsorted array A of
Given an unsorted integer array, and without making any assumptions on the numbers in
We want to search for a given element in a circular sorted array in
Given an unsorted sequence of integers that flows into your program as a stream.
What is the best approach to find if a given set(unsorted) is a perfect

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.