SlideShare a Scribd company logo
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 Processor
Asanka 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 notations
jayavignesh86
 
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 Structure
Mandeep Singh
 
Parallel algorithms
Parallel algorithms Parallel algorithms
Parallel algorithms
Dr Shashikant Athawale
 
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 analysis
jayavignesh86
 
Graph 1
Graph 1Graph 1
02 order of growth
02 order of growth02 order of growth
02 order of growth
Hira Gul
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
Daffodil International University
 
Graph 2
Graph 2Graph 2
Sorting network
Sorting networkSorting network
Sorting network
BBAU Lucknow University
 
Intro to Sorting + Insertion Sort
Intro to Sorting + Insertion SortIntro to Sorting + Insertion Sort
Intro to Sorting + Insertion Sort
Nicholas Case
 
Bucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision AlgorithmBucket sort- A Noncomparision Algorithm
Bucket sort- A Noncomparision Algorithm
Krupali Mistry
 
Data Structure: Algorithm and analysis
Data Structure: Algorithm and analysisData Structure: Algorithm and analysis
Data Structure: Algorithm and analysis
Dr. Rajdeep Chatterjee
 
Graph 3
Graph 3Graph 3
Merge sort and quick sort
Merge sort and quick sortMerge sort and quick sort
Merge sort and quick sort
Shakila Mahjabin
 

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

sorting
sortingsorting
sorting-160810203705.pptx
sorting-160810203705.pptxsorting-160810203705.pptx
sorting-160810203705.pptx
VarchasvaTiwari2
 
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
Sreedhar Chowdam
 
Merge sort
Merge sortMerge sort
quick sort by deepak.pptx
quick sort by deepak.pptxquick sort by deepak.pptx
quick sort by deepak.pptx
DeepakM509554
 
Chap9 slides
Chap9 slidesChap9 slides
Chap9 slides
BaliThorat1
 
Quick sort
Quick sortQuick 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
sgrishma559
 
Brute force method
Brute force methodBrute force method
Brute force method
priyankabhansali217
 
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
 
Lec 03 - Sorting.pptx
Lec 03 - Sorting.pptxLec 03 - Sorting.pptx
Lec 03 - Sorting.pptx
Dr. Shaukat Wasi
 
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
Rams715121
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
DAA - chapter 1.pdf
DAA - chapter 1.pdfDAA - chapter 1.pdf
DAA - chapter 1.pdf
ASMAALWADEE2
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
Hossain Md Shakhawat
 
Chap8 slides
Chap8 slidesChap8 slides
Chap8 slides
BaliThorat1
 
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 JYOTHI
Sowmya Jyothi
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie 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

Soft computing
Soft computingSoft computing
Soft computing
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 algorithm
Dr 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 algorithm
Dr 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 algorithm
Dr Sandeep Kumar Poonia
 
RMABC
RMABCRMABC
Memetic search in differential evolution algorithm
Memetic search in differential evolution algorithmMemetic search in differential evolution algorithm
Memetic search in differential evolution algorithm
Dr 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 algorithm
Dr 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_algorithm
Dr 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 algorithm
Dr 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 lists
Dr 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 algorithm
Dr 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
 
A new approach of program slicing
A new approach of program slicingA new approach of program slicing
A new approach of program slicing
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
 
Enhanced abc algo for tsp
Enhanced abc algo for tspEnhanced abc algo for tsp
Enhanced abc algo for tsp
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

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 

Recently uploaded (20)

Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 

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.