0% found this document useful (0 votes)
14 views

4 Pram Algorithms

Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

4 Pram Algorithms

Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Department of CSE

DESIGN AND ANALYSIS OF


ALGORITHMS
23CS2205R
Topic:

PRAM Algorithms

Session
Session- -44
AIM OF THE SESSION

To familiarize students with the concept of PRAM Algorithms.

INSTRUCTIONAL OBJECTIVES

This Session is designed to:


1.Demonstrate :- PRAM Algorithm.
2.Describe :- Odd-Even merge.

LEARNING OUTCOMES

At the end of this session, you should be able to:


1.Define :- PRAM Algorithm.
2.Describe :- Odd-Even Merge
3.Summarize:-Use of PRAM algorithms
PRAM Algorithms

Introduction:
•So far we have discussed algorithms for single processor
•In this session, we introduce parallel machines
•Example: weather forecasting
•If you start today to forecast tomorrow's weather using single
processor you may get result after few days (since its a Compute-
intensive problem)
PRAM Model
• So we need multiple machines/processors to solve such type of
problems.
• Parallel machines offer the potential of decreasing the solution time
enormously.
• The idea of parallel computing is very similar.
• Given a problem to solve, we partition the problem into many
subproblems; let each processor work on a subproblem; and when all the
processors are done, the partial solutions are combined to arrive at the
final answer.
• Any algorithm designed for a single-processor machine as a sequential
algorithm
• Any designed for a multiprocessor machine as a parallel algorithm.
Merging

Given two sorted sequences, the problem of merging is to


combine two sorted sequences into a single sorted sequence.
Odd-Even Merge
PRAM(Parallel Random Access Machines):
MERGING:
ODD-EVEN Merge algorithm:

Step 0: if m=1, merge the sequence with one comparison.

Step 1: Partition X1 nad X2 into their odd and even parts. That is,
partition X1 into X1odd = k1,k3….km-1 and X1even = k2,k4,….km. Similarly,
partition X2 into X2odd and X2even.
Step 2: Recursively merge X1odd with X2odd using m processors. Let L1 = l1,l2,l3,
….lm be the result. Note that X1odd, X1even,X2odd, and X2even are in sorted order.
At the same time merge X1even with X2even using the other m processors to get L2
= lm+1, lm+2,…..l2m.
Step 3: Shuffle L1 and L2; that is form the sequence L = l1, lm+1,l2, lm+2, … lm,l2m.
Compare every pair (lm+i,li+1) interchange them if they are out of order. That is,
compare lm+1 with l2 and interchange them if need be, compare lm+2 with l3 and
interchange them if need be, and so on. Output the result sequence.
Example

• Sort the following two lists using odd-even merge algorithm


X1={ 2,8,11,13,14,18,21,29} and X2={ 3,6,11,15,16,20,23,31}
SUMMARY

• The Parallel Random Access Machine (PRAM)


is an abstract model for parallel computation
which assumes that all the processors
operate synchronously under a single clock
and are able to randomly access a large
shared memory.
SELF-ASSESSMENT QUESTIONS

• The algorithm designed for multi-processor machine is referred as _____ algorithm.


• The algorithm designed for multi-processor machine is referred as _____ algorithm.

• • Odd-Even Merge is based on __________ technique


Odd-Even Merge is based on __________ technique

A. Greedy
B. Divide and Conquer
C. Dynamic
D. Backtracking
TERMINAL QUESTIONS

1. Give an example for PRAM algorithm

2. What is the advantage of using PRAM algorithms?


REFERENCES FOR FURTHER LEARNING OF THE SESSION

Text Books :
1. Ellis Horowitz, Sartaj Sahni and Sanguthevar Rajasekaran, “Fundamentals of
ComputerAlgorithms”, 2nd Edition, University Press, 2008.
2. Cormen, Leizerson &Rivest, “Introduction toalgorithms”, 3rd Edition, Prentice-Hall, 2002.
3. Jon Kleinberg and Eva Tardos, “Algorithm Design”,Pearson Education, 2006.

Reference Books :
1. Robert Sedgewick and Kevin wayne , “Algorithms”, 4th edition, Addison WesleyProf.,(2011).
2. Anny Levitin, “Introduction to Design and Analysis of Algorithms”, 2rd Edition,
PersonEducation Press. (2007).
3. Michael T.Goodrich and Roberto Tamassia, Algorithm Design: Foundations,Analysis and
Internet Examples, Second Edition, Wiley-India, (2006).
4. Steven S. Skiena, “The AlgorithmDesign Manual”, Second Edition, Springer, (2008)

MOOCS :
1. https://www.coursera.org/specializations/algorithms?=
2.https://www.coursera.org/learn/dynamic-programming-greedy-algorithms#modules
THANK YOU

You might also like