the fastest algorthm to order?

This is a discussion on the fastest algorthm to order? within the C Programming forums, part of the General Programming Boards category; what is the fastest algorithm to order an large amount of numbers? Could someone write a simple example please? i've ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    21

    the fastest algorthm to order?

    what is the fastest algorithm to order an large amount of numbers?
    Could someone write a simple example please? i've already tried bubble sort but it's extremly slow!!!

  2. #2
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    lol

    too many edits on this

    yeah, have you looked into qsort? I was not sure if that was a good function for sorting numbers or not.
    Last edited by kermit; 03-16-2004 at 05:12 PM.

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    21
    sorry my mistake. is qsort ansi-c? it has to be Ansi-C!

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i've already tried bubble sort but it's extremly slow!!!
    Bubble sort is second only to Bogo sort in suckiness.

    >Could someone write a simple example please?
    Check the contest forum. A recent thread has an implementation of quicksort.

    >is qsort ansi-c?
    Yes.
    My best code is written with the delete key.

  5. #5
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    well you will find it in stdlib.h, if that helps - yeah it is standard C

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >>Bubble sort is second only to Bogo sort in suckiness.
    And what is this 'Bogo sort' you speak of?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >And what is this 'Bogo sort' you speak of?
    Take a deck of cards. Throw them in the air and let them fall to the floor. Check to see if they're sorted. Repeat until they are. That's the equivalent of Bogo sort.
    My best code is written with the delete key.

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Gah!

    Nothing like O(&#8734) efficiency!
    Last edited by XSquared; 03-16-2004 at 05:57 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,588
    I thought bogosort was O(N!)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Radix sort is pretty fast, look it up.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  11. #11
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Bucket sort is pretty much the fastest sort, with a complexity of O(N). It uses huge amount of memory though, and is in most cases not practical especially when having duplicates.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  12. #12
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Originally posted by Salem
    I thought bogosort was O(N!)
    I'm just going by Prelude's description, so in the worst case it would be O(&#8734).
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  13. #13
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,588
    Yeah, actually it doesn't have an O value as such.

    It is a probablility, that being 1 : N! of actually coming up with the right answer in any given trial.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  14. #14
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    I wonder how many monkeys it would take to implement the bogo sort?
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  15. #15
    Registered User Markallen85's Avatar
    Join Date
    Nov 2002
    Posts
    53
    depends how fast you want it one monkey could implement it just fine, except the monkey might die before completing the process.
    "never argue with an idiot, they will drag you down to their level and beat you with experience"

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laplace Expansion
    By Leojeen in forum C Programming
    Replies: 7
    Last Post: 10-28-2008, 11:26 PM
  2. Embedded SQL Order By
    By cjohnman in forum C Programming
    Replies: 12
    Last Post: 04-15-2008, 03:45 PM
  3. Memory Order in Classes
    By skewray in forum C++ Programming
    Replies: 13
    Last Post: 12-14-2006, 05:40 AM
  4. How do you order your game code?
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 02-05-2006, 05:26 PM
  5. what is the significance of low order and high order bits
    By Shadow12345 in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 10:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21