Docsity

Parallel Sorting Algorithms, Study Guides, Projects, Research of Data Structures and Algorithms

Partial preview of the text

Download Parallel Sorting Algorithms and more Study Guides, Projects, Research Data Structures and Algorithms in PDF only on Docsity!

Sorting Algorithm

Algorithms & Parallel Processing

Informatics Engineering

Gunadarma University

Introduction to Sorting

  • Importance : Sorting is a fundamental computational task that has been extensively studied and is crucial for many applications.
  • Problem Definition : Given a sequence S = (s 1 , s 2 , ..., sn) of n items in random order, sort them into a sequence S′ = (s 1 ′, s 2 ′, ..., sn′) such that s′i≤s′i+1.
  • Sequential Sorting Lower Bound : Any sorting algorithm requires Ω(n logn) operations in the worst case. Sequential Sorting : Quicksort
  • Quicksort Algorithm :
  1. Base Case : If the sequence has one or two elements, sort directly.
  2. Recursive Case : ▪ Select the median element. ▪ Split the sequence into two subsequences: one with elements less than or equal to the median, and one with elements greater than or equal to the median. ▪ Recursively apply Quicksort to both subsequences.
  • Time Complexity : Optimal with O(n logn).

Merge-Split for Linear Array

  • Algorithm :
    1. Each processor sorts its subsequence using Quicksort.
    2. Odd-numbered processors merge their subsequences with their even-numbered neighbors and split the merged sequence.
    3. Repeat for ⌈ N /2⌉ iterations, where N is the number of processors.
  • Time Complexity : O((n logn)/ N ) + O( n ), aiming for cost-optimality. Example : Quicksort Problem : Sort the sequence S = (6, 5, 9, 2, 4, 3, 5, 1, 7, 5, 8). Step-by-Step Execution :
  1. Initial Call : S = (6, 5, 9, 2, 4, 3, 5, 1, 7, 5, 8) o Median : 5 o Split : S 1 = (2, 4, 3, 1, 5, 5), S2 = (6, 9, 7, 8, 5)
  2. First Recursive Call on S 1 : o Median : 3 o Split : S 11 = (2, 1 ), S 12 = (4, 5, 5)
  3. Recursive Calls on S 11 and S 12 : o S 11 : Sorted to (1, 2) o S 12 : Median 5, Split S 121 = (4), S 122 = (5, 5)
  1. Recursive Calls on S 121 and S 122 : o Both already sorted. o Combined : (1, 2, 3, 4, 5, 5)
  2. First Recursive Call on S 2 : o Median : 7 o Split: S 21 = (6, 5), S 22 = (9,8)
  3. Recursive Calls on S 21 and S 22 : o S 21 : Median 5, Split S 211 = (5), S 212 = (6) o S 22 : Median 8, Split S 221 = (8), S 222 = (9)
  4. Combining Sorted Subsequences : o S 1 and S 2 result in : (1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9) This results in the final sorted sequence : (1, 2, 3, 4, 5 , 5, 5, 6, 7, 8, 9). This study guide covers the essential concepts and algorithms related to sorting in parallel computing, providing both theoretical background and practical examples.