Efficient way to sort large set of numbers

Posted by 7Aces on Programmers See other posts from Programmers or by 7Aces
Published on 2012-11-02T06:35:49Z Indexed on 2012/11/02 11:16 UTC
Read the original article Hit count: 400

Filed under:

I have to sort a set of 100000 integers as a part of a programming Q. The time limit is pretty restrictive, so I have to use the most time-efficient approach possible.

My current code -

#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
    int n,d[100000],i;
    for(i=0;i<n;++i) {
                     scanf("%d",&d[i]);
    }
    sort(d,d+n);
    ....
}

Would this approach be more efiicient?

int main() {
    int n,d[100000],i;
    for(i=0;i<n;++i) {
                     scanf("%d",&d[i]);
                     sort(d,d+i+1);
    }
    ....
}

What is the most efficient way to sort a large dataset?

Note - Not homework...

© Programmers or respective owner

Related posts about sorting