CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2007
    Posts
    491

    Why don't they use O(n) algorithms in order to sort arrays?

    The Bucket Sort, Count Sort & Radix Sort are algorithms which only take O(n) operations in order to sort an array. They require additional information, but it's not much of a problem because it's possible to find this information and the algorithms will stay O(n).

    Yet, usally when people want to sort arrays, they usally use Quick Sort, Heap Sort or Merge Sort.

    However, if the size of the array is big enough, the O(n) algorithms will be faster.

    So why do people rarely use these algorithms?
    Last edited by Talikag; June 27th, 2008 at 02:51 PM.

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Why don't they use O(n) algorithms in order to sort arrays?

    Bucket Count and Radix sorts all require constraints on the data that tend to make them not nearly as general.

    Also remember that performance should ALWAYS be driven by requirements, and that radable, maintainable, robust code is the "prime directive".

    Therefore it only makes sense to consider these sorts if an application has been written and it is MEASURED that the sorting time is causing it to not meet (or be dangerously close to) a performance specification.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Feb 2008
    Posts
    966

    Re: Why don't they use O(n) algorithms in order to sort arrays?

    Too add to that, what is the difference in a .456 second algorithm and a .569 second algorithm? Nothing that you would ever notice (unless you called this algorithm a lot, which is silly to sort something over and over again ).

    The reason people use quick sort is because it is quick and easy, and for most cases it works just fine. If your data set is HUGE and time is a large factor in your program, then of course you are going to need a faster algorithm. It all depends on the size of the problem. See gents, size does matter .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured