Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lowest n Numbers in an Array

How can I assemble a set of the lowest or greatest numbers in an array? For instance, if I wanted to find the lowest 10 numbers in an array of size 1000.

I'm working in C but I don't need a language specific answer. I'm just trying to figure out a way to deal with this sort of task because it's been coming up a lot lately.

like image 491
piper1935 Avatar asked Dec 06 '25 19:12

piper1935


1 Answers

QuickSelect algorithm allows to separate predefined number of the lowest and greatest numbers (without full sorting). It uses partition procedure like Quicksort algo, but stops when pivot finds needed position.

like image 146
MBo Avatar answered Dec 09 '25 17:12

MBo