SlideShare a Scribd company logo
1 of 32
Sorting Algorithms
Topic Overview
• Issues in Sorting on Parallel Computers
• Sorting Networks
• Bubble Sort and its Variants
• Quicksort
• Bucket and Sample Sort
• Other Sorting Algorithms
Sorting: Overview
• One of the most commonly used and well-studied kernels.
• Sorting can be comparison-based or noncomparison-based.
• The fundamental operation of comparison-based sorting is
compare-exchange.
• The lower bound on any comparison-based sort of n
numbers is Θ(nlog n) .
• We focus here on comparison-based sorting algorithms.
Sorting: Basics
What is a parallel sorted sequence? Where are the input and
output lists stored?
• We assume that the input and output lists are distributed.
• The sorted list is partitioned with the property that each
partitioned list is sorted and each element in processor Pi's
list is less than that in Pj's list if i < j.
Sorting: Parallel Compare Exchange Operation
A parallel compare-exchange operation. Processes Pi and Pj
send their elements to each other. Process Pi keeps
min{ai,aj}, and Pj keeps max{ai, aj}.
Sorting: Basics
What is the parallel counterpart to a sequential comparator?
• If each processor has one element, the compare exchange
operation stores the smaller element at the processor with
smaller id. This can be done in ts + tw time.
• If we have more than one element per processor, we call
this operation a compare split. Assume each of two
processors have n/p elements.
• After the compare-split operation, the smaller n/p
elements are at processor Pi and the larger n/p elements
at Pj, where i < j.
• The time for a compare-split operation is (ts+ twn/p),
assuming that the two partial lists were initially sorted.
Sorting: Parallel Compare Split Operation
A compare-split operation. Each process sends its block of size
n/p to the other process. Each process merges the received
block with its own block and retains only the appropriate half of
the merged block. In this example, process Pi retains the
smaller elements and process Pi retains the larger elements.
Sorting Networks
• Networks of comparators designed specifically for sorting.
• A comparator is a device with two inputs x and y and two
outputs x' and y'. For an increasing comparator, x' = min{x,y}
and y' = min{x,y}; and vice-versa.
• We denote an increasing comparator by ⊕ and a decreasing
comparator by Ө.
• The speed of the network is proportional to its depth.
Sorting Networks: Comparators
A schematic representation of comparators: (a) an increasing
comparator, and (b) a decreasing comparator.
Sorting Networks
A typical sorting network. Every sorting network is made up of
a series of columns, and each column contains a number
of comparators connected in parallel.
Sorting Networks: Bitonic Sort
• A bitonic sorting network sorts n elements in Θ(log2
n) time.
• A bitonic sequence has two tones - increasing and
decreasing, or vice versa. Any cyclic rotation of such
networks is also considered bitonic.
∀ 〈1,2,4,7,6,0〉 is a bitonic sequence, because it first
increases and then decreases. 〈8,9,2,1,0,4〉 is another
bitonic sequence, because it is a cyclic shift of
〈0,4,8,9,2,1〉.
• The kernel of the network is the rearrangement of a bitonic
sequence into a sorted sequence.
Sorting Networks: Bitonic Sort
• Let s = 〈a0,a1,…,an-1〉 be a bitonic sequence such that a0 ≤
a1 ≤ ··· ≤ an/2-1 and an/2 ≥ an/2+1 ≥ ··· ≥ an-1.
• Consider the following subsequences of s:
s1 = 〈min{a0,an/2},min{a1,an/2+1},…,min{an/2-1,an-1}〉
s2 = 〈max{a0,an/2},max{a1,an/2+1},…,max{an/2-1,an-1}〉
(1)
• Note that s1 and s2 are both bitonic and each element of s1
is less than every element in s2.
• We can apply the procedure recursively on s1 and s2 to get
the sorted sequence.
Sorting Networks: Bitonic Sort
Merging a 16-element bitonic sequence through a series of log 16
bitonic splits.
Sorting Networks: Bitonic Sort
• We can easily build a sorting network to implement this
bitonic merge algorithm.
• Such a network is called a bitonic merging network.
• The network contains log n columns. Each column
contains n/2 comparators and performs one step of the
bitonic merge.
• We denote a bitonic merging network with n inputs by
⊕BM[n].
• Replacing the ⊕ comparators by Ө comparators results
in a decreasing output sequence; such a network is
denoted by ӨBM[n].
Sorting Networks: Bitonic Sort
A bitonic merging network for n = 16. The input wires are numbered 0,1,
…, n - 1, and the binary representation of these numbers is shown.
Each column of comparators is drawn separately; the entire figure
represents a ⊕BM[16] bitonic merging network. The network takes a
bitonic sequence and outputs it in sorted order.
Sorting Networks: Bitonic Sort
How do we sort an unsorted sequence using a bitonic merge?
• We must first build a single bitonic sequence from the given
sequence.
• A sequence of length 2 is a bitonic sequence.
• A bitonic sequence of length 4 can be built by sorting the
first two elements using ⊕BM[2] and next two, using ӨBM[2].
• This process can be repeated to generate larger bitonic
sequences.
Sorting Networks: Bitonic Sort
A schematic representation of a network that converts an input
sequence into a bitonic sequence. In this example, ⊕BM[k]
and ӨBM[k] denote bitonic merging networks of input size k
that use ⊕ and Ө comparators, respectively. The last merging
network (⊕BM[16]) sorts the input. In this example, n = 16.
Sorting Networks: Bitonic Sort
The comparator network that transforms an input sequence
of 16 unordered numbers into a bitonic sequence.
Sorting Networks: Bitonic Sort
• The depth of the network is Θ(log2
n).
• Each stage of the network contains n/2 comparators. A
serial implementation of the network would have
complexity Θ(nlog2
n).
Bubble Sort and its Variants
The sequential bubble sort algorithm compares and exchanges
adjacent elements in the sequence to be sorted:
Sequential bubble sort algorithm.
Bubble Sort and its Variants
• The complexity of bubble sort is Θ(n2
).
• Bubble sort is difficult to parallelize since the algorithm
has no concurrency.
• A simple variant, though, uncovers the concurrency.
Odd-Even Transposition
Sequential odd-even transposition sort algorithm.
Odd-Even Transposition
Sorting n = 8 elements, using the odd-even transposition sort
algorithm. During each phase, n = 8 elements are compared.
Odd-Even Transposition
• After n phases of odd-even exchanges, the sequence is
sorted.
• Each phase of the algorithm (either odd or even)
requires Θ(n) comparisons.
• Serial complexity is Θ(n2
).
Parallel Odd-Even Transposition
• Consider the one item per processor case.
• There are n iterations, in each iteration, each processor
does one compare-exchange.
• The parallel run time of this formulation is Θ(n).
• This is cost optimal with respect to the base serial
algorithm but not the optimal one.
Parallel Odd-Even Transposition
Parallel formulation of odd-even transposition.
Parallel Odd-Even Transposition
• Consider a block of n/p elements per processor.
• The first step is a local sort.
• In each subsequent step, the compare exchange
operation is replaced by the compare split operation.
• The parallel run time of the formulation is
Parallel Odd-Even Transposition
• The parallel formulation is cost-optimal for p = O(log n).
• The isoefficiency function of this parallel formulation
is Θ(p2p
).
Shellsort
• Let n be the number of elements to be sorted and p be
the number of processes.
• During the first phase, processes that are far away from
each other in the array compare-split their elements.
• During the second phase, the algorithm switches to an
odd-even transposition sort.
Parallel Shellsort
• Initially, each process sorts its block of n/p elements
internally.
• Each process is now paired with its corresponding
process in the reverse order of the array. That is,
process Pi, where i < p/2, is paired with process Pp-i-1.
• A compare-split operation is performed.
• The processes are split into two groups of size p/2 each
and the process repeated in each group.
Parallel Shellsort
An example of the first phase of parallel shellsort on an
eight-process array.
Parallel Shellsort
• Each process performs d = log p compare-split
operations.
• With O(p) bisection width, each communication can be
performed in time Θ(n/p) for a total time of Θ((nlog p)/p).
• In the second phase, l odd and even phases are
performed, each requiring time Θ(n/p).
• The parallel run time of the algorithm is:

More Related Content

What's hot

Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplicationKumar
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and boundAbhishek Singh
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingArvind Kumar
 
Unit 3
Unit 3Unit 3
Unit 3ypnrao
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and LexemeA. S. M. Shafi
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventionssaranyatdr
 
MACs based on Hash Functions, MACs based on Block Ciphers
MACs based on Hash Functions, MACs based on Block CiphersMACs based on Hash Functions, MACs based on Block Ciphers
MACs based on Hash Functions, MACs based on Block CiphersMaitree Patel
 
Turing Machine
Turing MachineTuring Machine
Turing MachineRajendran
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniquesMani Kanth
 
Polygon filling
Polygon fillingPolygon filling
Polygon fillingAnkit Garg
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of AlgorithmsBulbul Agrawal
 
Lecture 6.1
Lecture  6.1Lecture  6.1
Lecture 6.1Mr SMAK
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clippingMohd Arif
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptarunsingh660
 
Curve and text clipping
Curve and text clippingCurve and text clipping
Curve and text clippingArvind Kumar
 

What's hot (20)

visible surface detection
visible surface detectionvisible surface detection
visible surface detection
 
Geometric algorithms
Geometric algorithmsGeometric algorithms
Geometric algorithms
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
15 puzzle problem using branch and bound
15 puzzle problem using branch and bound15 puzzle problem using branch and bound
15 puzzle problem using branch and bound
 
sutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clippingsutherland- Hodgeman Polygon clipping
sutherland- Hodgeman Polygon clipping
 
convex hull
convex hullconvex hull
convex hull
 
Unit 3
Unit 3Unit 3
Unit 3
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
 
Algorithm and pseudocode conventions
Algorithm and pseudocode conventionsAlgorithm and pseudocode conventions
Algorithm and pseudocode conventions
 
MACs based on Hash Functions, MACs based on Block Ciphers
MACs based on Hash Functions, MACs based on Block CiphersMACs based on Hash Functions, MACs based on Block Ciphers
MACs based on Hash Functions, MACs based on Block Ciphers
 
Turing Machine
Turing MachineTuring Machine
Turing Machine
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniques
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Analysis and Design of Algorithms
Analysis and Design of AlgorithmsAnalysis and Design of Algorithms
Analysis and Design of Algorithms
 
Lecture 6.1
Lecture  6.1Lecture  6.1
Lecture 6.1
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
 
Curve and text clipping
Curve and text clippingCurve and text clipping
Curve and text clipping
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Linear time sorting algorithms
Linear time sorting algorithmsLinear time sorting algorithms
Linear time sorting algorithms
 

Similar to Sorting algorithms

Similar to Sorting algorithms (20)

Chap9 slides
Chap9 slidesChap9 slides
Chap9 slides
 
Parallel sorting Algorithms
Parallel  sorting AlgorithmsParallel  sorting Algorithms
Parallel sorting Algorithms
 
Bitonic sort97
Bitonic sort97Bitonic sort97
Bitonic sort97
 
Chap8 slides
Chap8 slidesChap8 slides
Chap8 slides
 
Sorting network
Sorting networkSorting network
Sorting network
 
densematrix.ppt
densematrix.pptdensematrix.ppt
densematrix.ppt
 
Lecture23
Lecture23Lecture23
Lecture23
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Cerebellar Model Articulation Controller
Cerebellar Model Articulation ControllerCerebellar Model Articulation Controller
Cerebellar Model Articulation Controller
 
Aa sort-v4
Aa sort-v4Aa sort-v4
Aa sort-v4
 
Distributed Coordination
Distributed CoordinationDistributed Coordination
Distributed Coordination
 
Digital Electronics-Unit II.pdf
Digital Electronics-Unit II.pdfDigital Electronics-Unit II.pdf
Digital Electronics-Unit II.pdf
 
Unit - 5 Pipelining.pptx
Unit - 5 Pipelining.pptxUnit - 5 Pipelining.pptx
Unit - 5 Pipelining.pptx
 
Principles of soft computing-Associative memory networks
Principles of soft computing-Associative memory networksPrinciples of soft computing-Associative memory networks
Principles of soft computing-Associative memory networks
 
Chap5 slides
Chap5 slidesChap5 slides
Chap5 slides
 
I/O-Efficient Techniques for Computing Pagerank
I/O-Efficient Techniques for Computing PagerankI/O-Efficient Techniques for Computing Pagerank
I/O-Efficient Techniques for Computing Pagerank
 
Routing Protocols
Routing ProtocolsRouting Protocols
Routing Protocols
 
Streams in Java 8
Streams in Java 8Streams in Java 8
Streams in Java 8
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
Class13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdfClass13_Quicksort_Algorithm.pdf
Class13_Quicksort_Algorithm.pdf
 

More from Syed Zaid Irshad

More from Syed Zaid Irshad (20)

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_Solution
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in Computing
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xi
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
C Language
C LanguageC Language
C Language
 
Flowchart
FlowchartFlowchart
Flowchart
 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the Law
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Data Communication
Data CommunicationData Communication
Data Communication
 
Information Networks
Information NetworksInformation Networks
Information Networks
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information Technology
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year Book
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

Recently uploaded

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 

Sorting algorithms

  • 2. Topic Overview • Issues in Sorting on Parallel Computers • Sorting Networks • Bubble Sort and its Variants • Quicksort • Bucket and Sample Sort • Other Sorting Algorithms
  • 3. Sorting: Overview • One of the most commonly used and well-studied kernels. • Sorting can be comparison-based or noncomparison-based. • The fundamental operation of comparison-based sorting is compare-exchange. • The lower bound on any comparison-based sort of n numbers is Θ(nlog n) . • We focus here on comparison-based sorting algorithms.
  • 4. Sorting: Basics What is a parallel sorted sequence? Where are the input and output lists stored? • We assume that the input and output lists are distributed. • The sorted list is partitioned with the property that each partitioned list is sorted and each element in processor Pi's list is less than that in Pj's list if i < j.
  • 5. Sorting: Parallel Compare Exchange Operation A parallel compare-exchange operation. Processes Pi and Pj send their elements to each other. Process Pi keeps min{ai,aj}, and Pj keeps max{ai, aj}.
  • 6. Sorting: Basics What is the parallel counterpart to a sequential comparator? • If each processor has one element, the compare exchange operation stores the smaller element at the processor with smaller id. This can be done in ts + tw time. • If we have more than one element per processor, we call this operation a compare split. Assume each of two processors have n/p elements. • After the compare-split operation, the smaller n/p elements are at processor Pi and the larger n/p elements at Pj, where i < j. • The time for a compare-split operation is (ts+ twn/p), assuming that the two partial lists were initially sorted.
  • 7. Sorting: Parallel Compare Split Operation A compare-split operation. Each process sends its block of size n/p to the other process. Each process merges the received block with its own block and retains only the appropriate half of the merged block. In this example, process Pi retains the smaller elements and process Pi retains the larger elements.
  • 8. Sorting Networks • Networks of comparators designed specifically for sorting. • A comparator is a device with two inputs x and y and two outputs x' and y'. For an increasing comparator, x' = min{x,y} and y' = min{x,y}; and vice-versa. • We denote an increasing comparator by ⊕ and a decreasing comparator by Ө. • The speed of the network is proportional to its depth.
  • 9. Sorting Networks: Comparators A schematic representation of comparators: (a) an increasing comparator, and (b) a decreasing comparator.
  • 10. Sorting Networks A typical sorting network. Every sorting network is made up of a series of columns, and each column contains a number of comparators connected in parallel.
  • 11. Sorting Networks: Bitonic Sort • A bitonic sorting network sorts n elements in Θ(log2 n) time. • A bitonic sequence has two tones - increasing and decreasing, or vice versa. Any cyclic rotation of such networks is also considered bitonic. ∀ 〈1,2,4,7,6,0〉 is a bitonic sequence, because it first increases and then decreases. 〈8,9,2,1,0,4〉 is another bitonic sequence, because it is a cyclic shift of 〈0,4,8,9,2,1〉. • The kernel of the network is the rearrangement of a bitonic sequence into a sorted sequence.
  • 12. Sorting Networks: Bitonic Sort • Let s = 〈a0,a1,…,an-1〉 be a bitonic sequence such that a0 ≤ a1 ≤ ··· ≤ an/2-1 and an/2 ≥ an/2+1 ≥ ··· ≥ an-1. • Consider the following subsequences of s: s1 = 〈min{a0,an/2},min{a1,an/2+1},…,min{an/2-1,an-1}〉 s2 = 〈max{a0,an/2},max{a1,an/2+1},…,max{an/2-1,an-1}〉 (1) • Note that s1 and s2 are both bitonic and each element of s1 is less than every element in s2. • We can apply the procedure recursively on s1 and s2 to get the sorted sequence.
  • 13. Sorting Networks: Bitonic Sort Merging a 16-element bitonic sequence through a series of log 16 bitonic splits.
  • 14. Sorting Networks: Bitonic Sort • We can easily build a sorting network to implement this bitonic merge algorithm. • Such a network is called a bitonic merging network. • The network contains log n columns. Each column contains n/2 comparators and performs one step of the bitonic merge. • We denote a bitonic merging network with n inputs by ⊕BM[n]. • Replacing the ⊕ comparators by Ө comparators results in a decreasing output sequence; such a network is denoted by ӨBM[n].
  • 15. Sorting Networks: Bitonic Sort A bitonic merging network for n = 16. The input wires are numbered 0,1, …, n - 1, and the binary representation of these numbers is shown. Each column of comparators is drawn separately; the entire figure represents a ⊕BM[16] bitonic merging network. The network takes a bitonic sequence and outputs it in sorted order.
  • 16. Sorting Networks: Bitonic Sort How do we sort an unsorted sequence using a bitonic merge? • We must first build a single bitonic sequence from the given sequence. • A sequence of length 2 is a bitonic sequence. • A bitonic sequence of length 4 can be built by sorting the first two elements using ⊕BM[2] and next two, using ӨBM[2]. • This process can be repeated to generate larger bitonic sequences.
  • 17. Sorting Networks: Bitonic Sort A schematic representation of a network that converts an input sequence into a bitonic sequence. In this example, ⊕BM[k] and ӨBM[k] denote bitonic merging networks of input size k that use ⊕ and Ө comparators, respectively. The last merging network (⊕BM[16]) sorts the input. In this example, n = 16.
  • 18. Sorting Networks: Bitonic Sort The comparator network that transforms an input sequence of 16 unordered numbers into a bitonic sequence.
  • 19. Sorting Networks: Bitonic Sort • The depth of the network is Θ(log2 n). • Each stage of the network contains n/2 comparators. A serial implementation of the network would have complexity Θ(nlog2 n).
  • 20. Bubble Sort and its Variants The sequential bubble sort algorithm compares and exchanges adjacent elements in the sequence to be sorted: Sequential bubble sort algorithm.
  • 21. Bubble Sort and its Variants • The complexity of bubble sort is Θ(n2 ). • Bubble sort is difficult to parallelize since the algorithm has no concurrency. • A simple variant, though, uncovers the concurrency.
  • 22. Odd-Even Transposition Sequential odd-even transposition sort algorithm.
  • 23. Odd-Even Transposition Sorting n = 8 elements, using the odd-even transposition sort algorithm. During each phase, n = 8 elements are compared.
  • 24. Odd-Even Transposition • After n phases of odd-even exchanges, the sequence is sorted. • Each phase of the algorithm (either odd or even) requires Θ(n) comparisons. • Serial complexity is Θ(n2 ).
  • 25. Parallel Odd-Even Transposition • Consider the one item per processor case. • There are n iterations, in each iteration, each processor does one compare-exchange. • The parallel run time of this formulation is Θ(n). • This is cost optimal with respect to the base serial algorithm but not the optimal one.
  • 26. Parallel Odd-Even Transposition Parallel formulation of odd-even transposition.
  • 27. Parallel Odd-Even Transposition • Consider a block of n/p elements per processor. • The first step is a local sort. • In each subsequent step, the compare exchange operation is replaced by the compare split operation. • The parallel run time of the formulation is
  • 28. Parallel Odd-Even Transposition • The parallel formulation is cost-optimal for p = O(log n). • The isoefficiency function of this parallel formulation is Θ(p2p ).
  • 29. Shellsort • Let n be the number of elements to be sorted and p be the number of processes. • During the first phase, processes that are far away from each other in the array compare-split their elements. • During the second phase, the algorithm switches to an odd-even transposition sort.
  • 30. Parallel Shellsort • Initially, each process sorts its block of n/p elements internally. • Each process is now paired with its corresponding process in the reverse order of the array. That is, process Pi, where i < p/2, is paired with process Pp-i-1. • A compare-split operation is performed. • The processes are split into two groups of size p/2 each and the process repeated in each group.
  • 31. Parallel Shellsort An example of the first phase of parallel shellsort on an eight-process array.
  • 32. Parallel Shellsort • Each process performs d = log p compare-split operations. • With O(p) bisection width, each communication can be performed in time Θ(n/p) for a total time of Θ((nlog p)/p). • In the second phase, l odd and even phases are performed, each requiring time Θ(n/p). • The parallel run time of the algorithm is: