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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:03:20+00:00 2026-05-31T17:03:20+00:00

I made an algorithm for sorting but I then I thought perhaps I had

  • 0

I made an algorithm for sorting but I then I thought perhaps I had just reinvented quicksort.

However I heard quicksort is O(N^2) worst case; I think my algorithm should be only O(NLogN) worst case.

Is this the same as quicksort?

The algorithm works by swapping values so that all values smaller than the median are moved to the left of the array. It then works recursively on each side.

The algorithm starts with i=0, j = n-1

i and j move towards each other with list[i] and list[j] being swapped if necessary.

Here is some code for the first iteration before the recursion:

_list = [1,-4,2,-5,3,-6]

def in_place(_list,i,j,median):
    while i<j:
        a,b = _list[i],_list[j]
        if (a<median and b>=median):
            i+=1
            j-=1
        elif (a>=median and b<median):
            _list[i],_list[j]=b,a
            i+=1
            j-=1
        elif a<median:
            i+=1
        else:
            j-=1
    print "changed to ", _list



def get_median(_list):
    #approximate median in O(N) with O(1) space
    return -4

median = get_median(_list)
in_place(_list,0,len(_list)-1,median)

"""
changed1 to  [-6, -5, 2, -4, 3, 1]
"""
  • 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-31T17:03:21+00:00Added an answer on May 31, 2026 at 5:03 pm

    http://en.wikipedia.org/wiki/Quicksort#Selection-based_pivoting

    Conversely, once we know a worst-case O(n) selection algorithm is
    available, we can use it to find the ideal pivot (the median) at every
    step of quicksort, producing a variant with worst-case O(n log n)
    running time. In practical implementations, however, this variant is
    considerably slower on average.

    Another variant is to choose the Median of Medians as the pivot
    element instead of the median itself for partitioning the elements.
    While maintaining the asymptotically optimal run time complexity of
    O(n log n) (by preventing worst case partitions), it is also
    considerably faster than the variant that chooses the median as pivot.

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

Sidebar

Related Questions

I have already made an algorithm for the problem but it still got a
I made a quicksort algorithm out of the visual presentation of the algorithm in
I made a memetic algorithm in Python for traveling salesman problem . However, all
I made an algorithm to generate sudokus, but it was terribly inefficient. Each puzzle
I made this simple algorithm, but Chrome is acting weird, almost like functions called
I made this bubble sort algorithm in C. Its working well in DM, but
I made a discovery some time back. Just follow these steps: Create a .doc/.xls/.ppt
Based on what I read, I've made an algorithm for FM sound synthesis. I'm
I have made a videochat, but as usual, a lot of men like to
Using the Smith-Waterman algorithm for a book homework assignment, I made up a table

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.