Best sorting method to use

This is a discussion on Best sorting method to use within the C++ Programming forums, part of the General Programming Boards category; Hi - What is the best sorting method (speed wise) to use to sort roughly 40,000+ objects in ascending/desceding order? ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    8

    Question Best sorting method to use

    Hi -

    What is the best sorting method (speed wise) to use to sort roughly 40,000+ objects in ascending/desceding order? Selection sort only comes to mine. Are there any others?

    What I have to do is find any duplicate numbers in a 40,000+ list. My game plan to approach this problem is ...

    1) Sort the numbers in ascending/descending order first
    2) After a sorted list is created, take the first number and compare it to every other number in that list. If a match if found, record it.
    3) Move on the next number in the list and repeat step 2. Do this until you reach the bottom of the list.

    Are there any problems with my thinking or is there something I can do to make more algorihim more efficent?

    Thanks,
    Pelp

  2. #2
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Look up quick sort, it is arguably the best sort out there. Do a search on google or on this board and you'll find lots of examples on it.

    Once your items are sorted, you don't need to look at every item to see if there is a duplicate. You only need to look at the next item. If the next item doesn't match, then it is unique.
    Last edited by PJYelton; 03-11-2003 at 07:47 PM.

  3. #3
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    std::sort<>()

    my favorite thing thus found in the standard
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  4. #4
    Registered User Diamonds's Avatar
    Join Date
    Oct 2002
    Posts
    68
    quicksort, non-recursive I feel would help...

    if you use the recursive version on such a large pile, you might have speed problems.

    btw, the sort is in the standard library

    http://www.cplusplus.com/ref

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. best sorting method to sort half end of array
    By nitinmhetre in forum C Programming
    Replies: 2
    Last Post: 01-11-2007, 12:18 PM
  2. Name of sorting method
    By noodles in forum Tech Board
    Replies: 6
    Last Post: 10-07-2006, 02:54 AM
  3. Sorting Method
    By silicon in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2005, 11:06 PM
  4. change sorting method using polymorphism
    By Forever82 in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2003, 02:21 PM
  5. Sorting words with a fast, effincient sorting method
    By Unregistered in forum C++ Programming
    Replies: 19
    Last Post: 07-12-2002, 05:21 PM

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