Parallel quicksort
Sylwia Dzikiewicz
Marta Leniewska
Mikołaj Olszewski
Marcin Woch
Michał Żelazowski
Sequential quicksort
 Quicksort

(Array, start, end)

If (start < end)
middle = partition (Array, start, end)
quicksort(A...
Sequential quicksort
 Partition

(Array, start, end)

X = Array [start]
I = start - 1
J = end + 1
while TRUE
repeat J = J...
Sequential quicksort – complexity
analysis
 Pessimistic
–

O (n2)

 Average
–

complexity

complexity

O (n log n)
Parallel quicksort
P a r a lle l q u ic k s o rt
Q s o rt
Q s o rt
Q s o rt

Q s o rt

Q s o rt

Q s o rt

Q s o rt

Q s o...
Parallel quicksort


How a single processor makes QuickSort (Array, start,
end)
–
–
–
–
–

J = Partition (Array, start, e...
Parallel quicksort
 OR
–
–
–
–
–

:

J = Partition (Array, start, end)
Start a new thread on another processor :
QuickSor...
Parallel quicksort
 In

case no processor can take thread, the
thread is put into a queue for later processing.
 After a...
Parallel quicksort
 Methods
–
–
–

of choosing the split key

First element
Average of : first, last and medium element
M...
Parallel quicksort
A

new thread is created only if the length of the
array to sort is no less than MIN_ARRAY_SIZE
consta...
Upcoming SlideShare
Loading in …5
×

Parallel quicksort cz. 1

357 views

Published on

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
357
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Parallel quicksort cz. 1

  1. 1. Parallel quicksort Sylwia Dzikiewicz Marta Leniewska Mikołaj Olszewski Marcin Woch Michał Żelazowski
  2. 2. Sequential quicksort  Quicksort (Array, start, end) If (start < end) middle = partition (Array, start, end) quicksort(Array, start, middle) quicksort(Array, middle+1, end)
  3. 3. Sequential quicksort  Partition (Array, start, end) X = Array [start] I = start - 1 J = end + 1 while TRUE repeat J = J –1 until Array [ J ] <= X repeat I = I +1 until Array [ I ] >=X if I < J swap (Array [ I ], Array [ J ] ) else return J
  4. 4. Sequential quicksort – complexity analysis  Pessimistic – O (n2)  Average – complexity complexity O (n log n)
  5. 5. Parallel quicksort P a r a lle l q u ic k s o rt Q s o rt Q s o rt Q s o rt Q s o rt Q s o rt Q s o rt Q s o rt Q s o rt Q s o rt Q s o rt Q s o rt
  6. 6. Parallel quicksort  How a single processor makes QuickSort (Array, start, end) – – – – – J = Partition (Array, start, end) Start a new thread on another processor : QuickSort(Array, start, J) Start a new thread on another processor : QuickSort(Array, J+1, end) Wait for both threads to complete Notice your parent that your task is finished
  7. 7. Parallel quicksort  OR – – – – – : J = Partition (Array, start, end) Start a new thread on another processor : QuickSort(Array, start, J) Execute QuickSort(Array, J+1, end) Wait for the thread to complete Notice your parent that your task is finished
  8. 8. Parallel quicksort  In case no processor can take thread, the thread is put into a queue for later processing.  After a processor has done its task, it checks whether the queue contains any waiting threads. If so, it removes the first task from the queue and processes it.
  9. 9. Parallel quicksort  Methods – – – of choosing the split key First element Average of : first, last and medium element Median (the median of a sample is expected to be the median of the whole array)
  10. 10. Parallel quicksort A new thread is created only if the length of the array to sort is no less than MIN_ARRAY_SIZE constant  If the length of the array to sort is less than MIN_QUICKSORT_SIZE, the array is sorted using a simple algorithm (eg. Insertionsort or Selectionsort), which require no new threads.  MIN_QUICKSORT_SIZE <= MIN_ARRAY_SIZE

×