SlideShare a Scribd company logo
1 of 36
Download to read offline
An overview of lecture
• A parallel search algorithm
• A parallel merging algorithm
• A parallel sorting algorithm
A parallel search algorithm
• We discuss an algorithm for parallel
searching in a sorted array.
• n is the number of elements in a sorted
array S and we use p, p < n processors for
searching.
• The complexity of the parallel searching
algorithm is: .
log( 1)
log( 1)
n
O
p
A parallel search algorithm
Input:
(i) A sorted array S = x1,x2,…,xn with n
elements.
(ii) A query element y.
Output: Two elements xi, xi +1 in S such that
xi y xi +1.
A parallel search algorithm
• The algorithm consists of a series of iterations to
reduce the size of the array where the element y
is located.
• In each iteration, we divide the current array in
p + 1 equal parts and locate y in one of the parts.
• This is continued until the size of the array where
y is located is reduced to p.
• We then do a direct comparison to find two
elements xi, xi +1 such that xi y xi +1.
A parallel search algorithm
A parallel search algorithm
• For each of the p + 1 parts of the array, a
processor checks whether y < xl, where xl is the
last element of the part.
• If y < xl, the subarray to the right of xl can be
rejected. If y > xl, the subarray to the left of xl can
be rejected.
• In each iteration we identify only one subarray for
further search.
A parallel search algorithm
• When the size of the remaining array is the same
as the number of processors, we do the following.
• We allocate one processor for each element.
• The processor assigned to element xi checks
whether xi y xi +1.
• Hence it takes O(1) time to locate y once the size
of the array has been reduced to p.
Complexity
• We need to analyze what is the complexity of
reducing the size of the array to p.
• At the first iteration, we are reducing the size of
the array from n to n/p.
• Suppose, the size reduces to p after k iterations.
• Hence, , which implies n = pk +1.
• . We need the CREW PRAM model.
log
( )
log
n
k O
p
k
n
p
p
Merging
• We use the parallel search algorithm to design an
optimal O(loglog n) time merging algorithm.
• rank(x : X) is the number of elements of X that are
x.
• Ranking a sequence Y = (y1, y2, …, yn) in X is the
same as:
• Computing the integer array : (r1, r2, …, rm) where
ri = rank(yi, X).
Merging
• If rank(ai, A) = r1 and rank(ai, B) = r2
• rank(ai, A +B) = r1 + r2.
• Hence, ai should go to the entry number r1 + r2 in
the merged array.
Ranking a short sequence in a
sorted sequence
• X is a sorted sequence with n elements.
• Y is an arbitrary sorted sequence of size m such
that m = O(ns), where s is a constant and 0 < s < 1.
• If we use processors,
• Then we can rank each element of Y in X
in time.log
( ) (1)
log
n
O O
p
1
( )sn
p O n
m
A fast merging algorithm
• We now discuss a fast algorithm for merging two
sorted arrays A and B with n and m elements
each.
• Fast merging is an essential component in any
sorting algorithm based on divide-and-conquer.
• We will first design an O(loglog m) time and
O((m + n) loglog m) work algorithm.
• Then we will improve the work to O(m + n) which
is optimal.
A fast merging algorithm
Input: Two sorted sequences A and B of lengths
n and m respectively.
Output: rank(B : A) and rank(A : B).
•We use a strategy similar to the merging
algorithm we discussed earlier.
•We divide the array B into parts, each part
with elements.
•We start with ranking the last element from
each part of B into A.
m
m
Ranking a sample of elements
• We start with a sample of elements from B.
• We choose every –th element from B.
• These elements can be ranked in A in O(1)
time through binary search in parallel using m
processors.
m
m
m
A parallel search algorithm
Ranking elements in O(1) time
m m
m
m m m
m elements
m elements A
B
For every element in B, we allocate processors.m
In one step, we identify the block of elements in
A where an element of B will be ranked.
m
We find the rank in another step.
Ranking a sample of elements
• B is partitioned into blocks, each of size .
• After the ranking of the elements from B in A.
• A is also partitioned into blocks.
• We can now merge the blocks in A and B
pairwise recursively.
m m
m
m
Independent subproblems
• Consider the first element of B2 and the first element of B3,
the elements r and s.
• Now, r is ranked at u and s is ranked at v.
• Consider an element p such that r < p < s. p must be ranked
in between u and v.
• Hence, all the elements in B2 must be ranked in A2 and vice
verse.
Ranking a sample of elements
• Suppose at the current level of recursion, the size
of the two subproblems B’ and A’ are m’ and n’.
• If m’ > n’, then we divide B’ into parts and apply
the algorithm recursively.
• If n’ > m’, we divide A’ into parts and apply the
algorithm recursively.
'm
'n
An example
Recursion
Recursion
• The recursion between all pairs of blocks can
be solved in parallel.
• The recursion stops when the size of the
subproblems is small and we can merge the
very small blocks through a sequential
algorithm in O(1) time.
• At the end of the algorithm, we know rank(B :
A) and rank(A : B). Hence, we can move the
elements to another array in sorted order.
Complexity
• The recursion satisfies the recurrences
either :
or,
• The processor requirement is O(m + n).
• The total work done is O(m + n) loglog m.
( ) ( ) (1)T n T n O
( ) ( ) (1)T m T m O
An optimal merging algorithm
• The make the algorithm optimal, we need to reduce
the work to O(m + n).
• We use a different sampling strategy and use the fast
algorithm that we have designed. For simplicity, we
assume that each array has n elements.
• We divide the arrays A and B into blocks of size
loglog n.
• We choose the last element from each block as our
sample and form two arrays A’ and B’.
• Hence each of A’ and B’ has elements.loglog
n
n
Taking the samples
• Now we compute rank(A’ : B’) and rank(B’ : A’)
using the algorithm we have designed.
• This takes O(loglog n) time and
or O(n) work.
( loglog )
loglog
n
O n
n
Ranking the elements
• We now compute rank(A’ : B) in the following
ways.
• Suppose the elements in A’ are:
p1, p2,…, pn / loglog n.
Ranking the elements
• Consider pi A’. If rank(pi : B’) is the first element in
block Bk,
• Then rank(pi,B) must be some element in block Bk.
• We do a binary search using one processor to
locate rank(pi,B).
Ranking the elements
• We allocate one processor for pi. The processor
does a binary search in Bk.
• Since there are O(loglog n) elements in Bk, this
search takes O(logloglog n) time.
• The search for all the elements in A’ can be done
in parallel and requires processors.
• We can compute rank(B’ : A) in a similar way.
( )
loglog
n
O
n
Recursion again
• Consider Ai, a loglog n block in A.
• We know rank(p : B) and rank(q : B) for the two
boundary elements p and q of Ai.
• Now we can call our algorithm recursively with Ai and
all the elements in B in between rank(p : B) and
rank(q : B) .
Recursion again
• The problem is, there may be too many elements in
between rank(p : B) and rank(q : B).
• But then there are too many loglog n blocks in
between rank(p : B) and rank(q : B) .
Recursion again
• The boundaries of all these blocks must be ranked in Ai.
• Hence we get pairs of blocks, one loglog n block from B
and a smaller block from Ai.
Solving the subproblems
• Now each of the two blocks participating in a
subproblem has size at most loglog n.
• And there are such pairs.
• We assign one processor to each pair. This
processor merges the elements in the pair
sequentially in O(loglog n) time.
• All the mergings can be done in parallel since we
have processors.
( )
loglog
n
O
n
loglog
n
n
Complexity
• Computing rank(A’ : B’) and rank(B’ : A’) take
O(loglog n) time and O(n) work.
• Computing rank(A’ : B) and rank(B’ : A) take
O(loglog n) time and O(n) work.
• The final merging also takes the same time and
work.
• Hence, we can merge two sorted arrays of length
n each in O(n) work and O(loglog n) time on the
CREW PRAM.
An efficient sorting algorithm
• We can use this merging algorithm to design an
efficient sorting algorithm.
• Recall the sequential merge sort algorithm.
• Given an unsorted array, we go on dividing the
array into two parts recursively until there is one
element in each leaf.
• We then merge the sorted arrays pairwise up the
tree.
• At the end we get the sorted array at the root.
An efficient sorting algorithm
• We can use the optimal merging algorithm to
merge the sorted arrays at each level.
• There are n elements in each level of this binary
tree distributed among several arrays depending
upon the level.
• Hence we need O(loglog n) time and O(n) work
for all the pairwise mergings at each level.
• The binary tree has a depth of O(log n) .
• Hence we can sort n elements in total work
O(n log n) and time O(log n loglog n)
Better sorting algorithms?
• This sorting algorithm is work-optimal
since the sequential lower bound for
sorting is (n log n).
• However, it is not time optimal.
• Cole’s pipelined merge sort algorithm is
an optimal O(log n) time and O(n log n)
work sorting algorithm on the EREW
PRAM.

More Related Content

What's hot

Bitonic Sort in Shared SIMD Array Processor
Bitonic Sort in Shared SIMD Array ProcessorBitonic Sort in Shared SIMD Array Processor
Bitonic Sort in Shared SIMD Array ProcessorAsanka Dilruk
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAdelina Ahadova
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notationsjayavignesh86
 
Algorithem complexity in data sructure
Algorithem complexity in data sructureAlgorithem complexity in data sructure
Algorithem complexity in data sructureKumar
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data StructureMandeep Singh
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisAnindita Kundu
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysisjayavignesh86
 
02 order of growth
02 order of growth02 order of growth
02 order of growthHira Gul
 
Intro to Sorting + Insertion Sort
Intro to Sorting + Insertion SortIntro to Sorting + Insertion Sort
Intro to Sorting + Insertion SortNicholas Case
 
Bucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision AlgorithmBucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision AlgorithmKrupali Mistry
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysisDr. Rajdeep Chatterjee
 

What's hot (20)

Bitonic Sort in Shared SIMD Array Processor
Bitonic Sort in Shared SIMD Array ProcessorBitonic Sort in Shared SIMD Array Processor
Bitonic Sort in Shared SIMD Array Processor
 
Cs1311lecture23wdl
Cs1311lecture23wdlCs1311lecture23wdl
Cs1311lecture23wdl
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 
Lecture 4 asymptotic notations
Lecture 4   asymptotic notationsLecture 4   asymptotic notations
Lecture 4 asymptotic notations
 
Algorithem complexity in data sructure
Algorithem complexity in data sructureAlgorithem complexity in data sructure
Algorithem complexity in data sructure
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
Parallel algorithms
Parallel algorithms Parallel algorithms
Parallel algorithms
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
Lecture 3 insertion sort and complexity analysis
Lecture 3   insertion sort and complexity analysisLecture 3   insertion sort and complexity analysis
Lecture 3 insertion sort and complexity analysis
 
Graph 1
Graph 1Graph 1
Graph 1
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Graph 2
Graph 2Graph 2
Graph 2
 
Sorting network
Sorting networkSorting network
Sorting network
 
Intro to Sorting + Insertion Sort
Intro to Sorting + Insertion SortIntro to Sorting + Insertion Sort
Intro to Sorting + Insertion Sort
 
Bucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision AlgorithmBucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision Algorithm
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
 
Graph 3
Graph 3Graph 3
Graph 3
 
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
 
Computational Complexity
Computational ComplexityComputational Complexity
Computational Complexity
 

Similar to Lecture23

Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesSreedhar Chowdam
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptxDeepakM509554
 
Data analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxData analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxsgrishma559
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)eShikshak
 
2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptxRams715121
 
DAA - chapter 1.pdf
DAA - chapter 1.pdfDAA - chapter 1.pdf
DAA - chapter 1.pdfASMAALWADEE2
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Hossain Md Shakhawat
 
lecture 10
lecture 10lecture 10
lecture 10sajinsc
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................nourhandardeer3
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHISowmya Jyothi
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithmsJulie Iskander
 

Similar to Lecture23 (20)

sorting
sortingsorting
sorting
 
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Merge sort
Merge sortMerge sort
Merge sort
 
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
 
Chap9 slides
Chap9 slidesChap9 slides
Chap9 slides
 
Quick sort
Quick sortQuick sort
Quick sort
 
Data analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptxData analysis and algorithms - UNIT 2.pptx
Data analysis and algorithms - UNIT 2.pptx
 
Brute force method
Brute force methodBrute force method
Brute force method
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptx
 
2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx2. Asymptotic Notations and Complexity Analysis.pptx
2. Asymptotic Notations and Complexity Analysis.pptx
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
DAA - chapter 1.pdf
DAA - chapter 1.pdfDAA - chapter 1.pdf
DAA - chapter 1.pdf
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
 
Chap8 slides
Chap8 slidesChap8 slides
Chap8 slides
 
lecture 10
lecture 10lecture 10
lecture 10
 
chapter1.pdf ......................................
chapter1.pdf ......................................chapter1.pdf ......................................
chapter1.pdf ......................................
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHIBCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 

More from Dr Sandeep Kumar Poonia

An improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithmAn improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithmDr Sandeep Kumar Poonia
 
Modified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithmModified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithmDr Sandeep Kumar Poonia
 
Enhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithmEnhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithmDr Sandeep Kumar Poonia
 
Memetic search in differential evolution algorithm
Memetic search in differential evolution algorithmMemetic search in differential evolution algorithm
Memetic search in differential evolution algorithmDr Sandeep Kumar Poonia
 
Improved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithmImproved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithmDr Sandeep Kumar Poonia
 
Comparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithmComparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithmDr Sandeep Kumar Poonia
 
A novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithmA novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithmDr Sandeep Kumar Poonia
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsDr Sandeep Kumar Poonia
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmDr Sandeep Kumar Poonia
 
New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm Dr Sandeep Kumar Poonia
 
Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...Dr Sandeep Kumar Poonia
 
Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...Dr Sandeep Kumar Poonia
 

More from Dr Sandeep Kumar Poonia (20)

Soft computing
Soft computingSoft computing
Soft computing
 
An improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithmAn improved memetic search in artificial bee colony algorithm
An improved memetic search in artificial bee colony algorithm
 
Modified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithmModified position update in spider monkey optimization algorithm
Modified position update in spider monkey optimization algorithm
 
Enhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithmEnhanced local search in artificial bee colony algorithm
Enhanced local search in artificial bee colony algorithm
 
RMABC
RMABCRMABC
RMABC
 
Memetic search in differential evolution algorithm
Memetic search in differential evolution algorithmMemetic search in differential evolution algorithm
Memetic search in differential evolution algorithm
 
Improved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithmImproved onlooker bee phase in artificial bee colony algorithm
Improved onlooker bee phase in artificial bee colony algorithm
 
Comparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithmComparative study of_hybrids_of_artificial_bee_colony_algorithm
Comparative study of_hybrids_of_artificial_bee_colony_algorithm
 
A novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithmA novel hybrid crossover based abc algorithm
A novel hybrid crossover based abc algorithm
 
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked listsMultiplication of two 3 d sparse matrices using 1d arrays and linked lists
Multiplication of two 3 d sparse matrices using 1d arrays and linked lists
 
Sunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithmSunzip user tool for data reduction using huffman algorithm
Sunzip user tool for data reduction using huffman algorithm
 
New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm New Local Search Strategy in Artificial Bee Colony Algorithm
New Local Search Strategy in Artificial Bee Colony Algorithm
 
A new approach of program slicing
A new approach of program slicingA new approach of program slicing
A new approach of program slicing
 
Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...Performance evaluation of different routing protocols in wsn using different ...
Performance evaluation of different routing protocols in wsn using different ...
 
Enhanced abc algo for tsp
Enhanced abc algo for tspEnhanced abc algo for tsp
Enhanced abc algo for tsp
 
Database aggregation using metadata
Database aggregation using metadataDatabase aggregation using metadata
Database aggregation using metadata
 
Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...Performance evaluation of diff routing protocols in wsn using difft network p...
Performance evaluation of diff routing protocols in wsn using difft network p...
 
Lecture28 tsp
Lecture28 tspLecture28 tsp
Lecture28 tsp
 
Lecture27 linear programming
Lecture27 linear programmingLecture27 linear programming
Lecture27 linear programming
 
Lecture26
Lecture26Lecture26
Lecture26
 

Recently uploaded

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

Lecture23

  • 1. An overview of lecture • A parallel search algorithm • A parallel merging algorithm • A parallel sorting algorithm
  • 2. A parallel search algorithm • We discuss an algorithm for parallel searching in a sorted array. • n is the number of elements in a sorted array S and we use p, p < n processors for searching. • The complexity of the parallel searching algorithm is: . log( 1) log( 1) n O p
  • 3. A parallel search algorithm Input: (i) A sorted array S = x1,x2,…,xn with n elements. (ii) A query element y. Output: Two elements xi, xi +1 in S such that xi y xi +1.
  • 4. A parallel search algorithm • The algorithm consists of a series of iterations to reduce the size of the array where the element y is located. • In each iteration, we divide the current array in p + 1 equal parts and locate y in one of the parts. • This is continued until the size of the array where y is located is reduced to p. • We then do a direct comparison to find two elements xi, xi +1 such that xi y xi +1.
  • 5. A parallel search algorithm
  • 6. A parallel search algorithm • For each of the p + 1 parts of the array, a processor checks whether y < xl, where xl is the last element of the part. • If y < xl, the subarray to the right of xl can be rejected. If y > xl, the subarray to the left of xl can be rejected. • In each iteration we identify only one subarray for further search.
  • 7. A parallel search algorithm • When the size of the remaining array is the same as the number of processors, we do the following. • We allocate one processor for each element. • The processor assigned to element xi checks whether xi y xi +1. • Hence it takes O(1) time to locate y once the size of the array has been reduced to p.
  • 8. Complexity • We need to analyze what is the complexity of reducing the size of the array to p. • At the first iteration, we are reducing the size of the array from n to n/p. • Suppose, the size reduces to p after k iterations. • Hence, , which implies n = pk +1. • . We need the CREW PRAM model. log ( ) log n k O p k n p p
  • 9. Merging • We use the parallel search algorithm to design an optimal O(loglog n) time merging algorithm. • rank(x : X) is the number of elements of X that are x. • Ranking a sequence Y = (y1, y2, …, yn) in X is the same as: • Computing the integer array : (r1, r2, …, rm) where ri = rank(yi, X).
  • 10. Merging • If rank(ai, A) = r1 and rank(ai, B) = r2 • rank(ai, A +B) = r1 + r2. • Hence, ai should go to the entry number r1 + r2 in the merged array.
  • 11. Ranking a short sequence in a sorted sequence • X is a sorted sequence with n elements. • Y is an arbitrary sorted sequence of size m such that m = O(ns), where s is a constant and 0 < s < 1. • If we use processors, • Then we can rank each element of Y in X in time.log ( ) (1) log n O O p 1 ( )sn p O n m
  • 12. A fast merging algorithm • We now discuss a fast algorithm for merging two sorted arrays A and B with n and m elements each. • Fast merging is an essential component in any sorting algorithm based on divide-and-conquer. • We will first design an O(loglog m) time and O((m + n) loglog m) work algorithm. • Then we will improve the work to O(m + n) which is optimal.
  • 13. A fast merging algorithm Input: Two sorted sequences A and B of lengths n and m respectively. Output: rank(B : A) and rank(A : B). •We use a strategy similar to the merging algorithm we discussed earlier. •We divide the array B into parts, each part with elements. •We start with ranking the last element from each part of B into A. m m
  • 14. Ranking a sample of elements • We start with a sample of elements from B. • We choose every –th element from B. • These elements can be ranked in A in O(1) time through binary search in parallel using m processors. m m m
  • 15. A parallel search algorithm
  • 16. Ranking elements in O(1) time m m m m m m m elements m elements A B For every element in B, we allocate processors.m In one step, we identify the block of elements in A where an element of B will be ranked. m We find the rank in another step.
  • 17. Ranking a sample of elements • B is partitioned into blocks, each of size . • After the ranking of the elements from B in A. • A is also partitioned into blocks. • We can now merge the blocks in A and B pairwise recursively. m m m m
  • 18. Independent subproblems • Consider the first element of B2 and the first element of B3, the elements r and s. • Now, r is ranked at u and s is ranked at v. • Consider an element p such that r < p < s. p must be ranked in between u and v. • Hence, all the elements in B2 must be ranked in A2 and vice verse.
  • 19. Ranking a sample of elements • Suppose at the current level of recursion, the size of the two subproblems B’ and A’ are m’ and n’. • If m’ > n’, then we divide B’ into parts and apply the algorithm recursively. • If n’ > m’, we divide A’ into parts and apply the algorithm recursively. 'm 'n
  • 22. Recursion • The recursion between all pairs of blocks can be solved in parallel. • The recursion stops when the size of the subproblems is small and we can merge the very small blocks through a sequential algorithm in O(1) time. • At the end of the algorithm, we know rank(B : A) and rank(A : B). Hence, we can move the elements to another array in sorted order.
  • 23. Complexity • The recursion satisfies the recurrences either : or, • The processor requirement is O(m + n). • The total work done is O(m + n) loglog m. ( ) ( ) (1)T n T n O ( ) ( ) (1)T m T m O
  • 24. An optimal merging algorithm • The make the algorithm optimal, we need to reduce the work to O(m + n). • We use a different sampling strategy and use the fast algorithm that we have designed. For simplicity, we assume that each array has n elements. • We divide the arrays A and B into blocks of size loglog n. • We choose the last element from each block as our sample and form two arrays A’ and B’. • Hence each of A’ and B’ has elements.loglog n n
  • 25. Taking the samples • Now we compute rank(A’ : B’) and rank(B’ : A’) using the algorithm we have designed. • This takes O(loglog n) time and or O(n) work. ( loglog ) loglog n O n n
  • 26. Ranking the elements • We now compute rank(A’ : B) in the following ways. • Suppose the elements in A’ are: p1, p2,…, pn / loglog n.
  • 27. Ranking the elements • Consider pi A’. If rank(pi : B’) is the first element in block Bk, • Then rank(pi,B) must be some element in block Bk. • We do a binary search using one processor to locate rank(pi,B).
  • 28. Ranking the elements • We allocate one processor for pi. The processor does a binary search in Bk. • Since there are O(loglog n) elements in Bk, this search takes O(logloglog n) time. • The search for all the elements in A’ can be done in parallel and requires processors. • We can compute rank(B’ : A) in a similar way. ( ) loglog n O n
  • 29. Recursion again • Consider Ai, a loglog n block in A. • We know rank(p : B) and rank(q : B) for the two boundary elements p and q of Ai. • Now we can call our algorithm recursively with Ai and all the elements in B in between rank(p : B) and rank(q : B) .
  • 30. Recursion again • The problem is, there may be too many elements in between rank(p : B) and rank(q : B). • But then there are too many loglog n blocks in between rank(p : B) and rank(q : B) .
  • 31. Recursion again • The boundaries of all these blocks must be ranked in Ai. • Hence we get pairs of blocks, one loglog n block from B and a smaller block from Ai.
  • 32. Solving the subproblems • Now each of the two blocks participating in a subproblem has size at most loglog n. • And there are such pairs. • We assign one processor to each pair. This processor merges the elements in the pair sequentially in O(loglog n) time. • All the mergings can be done in parallel since we have processors. ( ) loglog n O n loglog n n
  • 33. Complexity • Computing rank(A’ : B’) and rank(B’ : A’) take O(loglog n) time and O(n) work. • Computing rank(A’ : B) and rank(B’ : A) take O(loglog n) time and O(n) work. • The final merging also takes the same time and work. • Hence, we can merge two sorted arrays of length n each in O(n) work and O(loglog n) time on the CREW PRAM.
  • 34. An efficient sorting algorithm • We can use this merging algorithm to design an efficient sorting algorithm. • Recall the sequential merge sort algorithm. • Given an unsorted array, we go on dividing the array into two parts recursively until there is one element in each leaf. • We then merge the sorted arrays pairwise up the tree. • At the end we get the sorted array at the root.
  • 35. An efficient sorting algorithm • We can use the optimal merging algorithm to merge the sorted arrays at each level. • There are n elements in each level of this binary tree distributed among several arrays depending upon the level. • Hence we need O(loglog n) time and O(n) work for all the pairwise mergings at each level. • The binary tree has a depth of O(log n) . • Hence we can sort n elements in total work O(n log n) and time O(log n loglog n)
  • 36. Better sorting algorithms? • This sorting algorithm is work-optimal since the sequential lower bound for sorting is (n log n). • However, it is not time optimal. • Cole’s pipelined merge sort algorithm is an optimal O(log n) time and O(n log n) work sorting algorithm on the EREW PRAM.