Selection Sort on 1 Million Elements: Is It Feasible?

  • Thread starter Thread starter rsala004
  • Start date Start date
  • Tags Tags
    Elements Sort
Click For Summary
SUMMARY

Selection sort is not feasible for sorting an array of 1 million elements on an everyday laptop due to its inefficient time complexity of O(n²). Instead, utilizing more efficient algorithms like quicksort is recommended. A rough estimate indicates that executing a selection sort on such a large dataset could take between 100 to 1000 seconds, factoring in memory access times. For practical applications, leveraging standard library sorting algorithms is essential for optimal performance.

PREREQUISITES
  • Understanding of sorting algorithms, specifically time complexity.
  • Familiarity with quicksort and its advantages over selection sort.
  • Basic knowledge of computer performance metrics, such as instructions per second.
  • Experience with programming languages that provide standard library sorting functions.
NEXT STEPS
  • Research the implementation and performance of quicksort in Python or C++.
  • Learn about the time complexity of various sorting algorithms, including merge sort and heapsort.
  • Explore the impact of memory access patterns on algorithm performance.
  • Investigate the use of built-in sorting functions in programming languages like Java and JavaScript.
USEFUL FOR

Software developers, computer science students, and anyone interested in optimizing sorting algorithms for large datasets will benefit from this discussion.

rsala004
Messages
23
Reaction score
0
if you have an array with size 1000000, would selection sort be feasible on a everyday laptop computer, or just too large?

I imagine it would take (1Million)2/2 loops to complete the sort
 
Technology news on Phys.org
No, use your standard library sorting algo or google sorting and you will find many better ones, like quicksort, for example.
 
I think what's he's asking is how long would it take to execute a small loop 1 trillion times on a modern lap top.

From wiki

http://en.wikipedia.org/wiki/Instructions_per_second

Probably between 10 and 20 billion instructions per second, so 50 to 100 seconds per trillion instructions, assuming the condiitions mentioned in the wiki article. So ballpark about 100 seconds per instruction in that selective sort loop. This is a crude estimate, it could be 1000 seconds per trillion instructions when you take memory accesses into account.

Here's a link to a prior thread about sorting which includes some links to source code of various sort programs:

https://www.physicsforums.com/showthread.php?t=218369
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 31 ·
2
Replies
31
Views
3K
Replies
4
Views
2K
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
9K