Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel algorithm to check if a sequence is sorted

I need a parallel algorithm (cost optimal) to check if a given sequence of n numbers is sorted .

like image 847
woodstok Avatar asked May 03 '26 04:05

woodstok


1 Answers

For m threads, give each thread a chunk of n/m consecutive numbers with an overlap of 1 number. In each thread, check that that the sequence it is assigned is in sorted order. If all subsequences are sorted, then the entire sequence is sorted.

Examples:

[1, 4, 5, 6, 11, 42] => [1, 4, 5, 6*] and [6, 11, 42] with 2 threads
[1, 4, 5, 6, 11, 42] => [1, 4, 5*], [5, 6, 11*] and [11, 42] with 3 threads

* this is the overlap of 1.

This solution has complexity O(n/m).

like image 72
moinudin Avatar answered May 05 '26 17:05

moinudin