elementary pram algorithms (step by step trace)
TRANSCRIPT
![Page 1: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/1.jpg)
( step by step trace)
![Page 2: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/2.jpg)
P2
P2 P4
P3 P4 P5 P6 P7
P0
P0 P1
P6
P0
P4
1
02
4
3
6
5 7
P0
1
![Page 3: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/3.jpg)
P2
P2 P4
P3 P4 P5 P6 P7
P0
P0 P1
P6
P0
P0 P4
P0
P1
P2
P3
P4
P5
P6
P7
2
![Page 4: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/4.jpg)
3Parallel reduction = EREW PRAM algorithm to SUM n elements using n/2 processors
P2 P3P4P0 P1
4 3 8 2 9 1 0 5 6 3
P2P0
P0
P0
j = 0
j = 1
j = 2
j = 3
7 10 10 5 917 15 932 941
O ( Log n )
![Page 5: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/5.jpg)
4CREW PRAM algorithm to find prefix sums of an n-elements list using n-1 processors
P3 P4P1 P2
4 3 8 2 9
[0] [1] [2] [3] [4]
P4P2
P4
j = 0
j = 1
j = 2
4 3 7 8 11 2 10 9 11
[0] [1] [2] [3] [4]
P3
4 3 78
11 152
10 179
11 22
[0] [1] [2] [3] [4]
4 3 78
11 152
10 179 1122 26
[0] [1] [2] [3] [4]
O ( Log n )
![Page 6: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/6.jpg)
5
4 7 15 17 26
4 3 8 2 9
4 7 11 10 11
4 7 15 17 22
Trace مثال قبل از نگاهی دیگر:
![Page 7: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/7.jpg)
List Ranking
![Page 8: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/8.jpg)
CREW PRAMپردازندهp = nبوسیله )nبه طول (محاسبه فاصله هر نود تا انتهای لیست پیوندی 6 algorithm -
01 1 1
j = 1
P2 P3P0 P1
j = 2
02 2 13
O ( Log n )
![Page 9: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/9.jpg)
7
مثالی دیگر
![Page 10: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/10.jpg)
Tree Traversal
![Page 11: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/11.jpg)
8
Pre-Order Traverse : ABDEGHCF
![Page 12: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/12.jpg)
9
(پایینبهالبااز)رفتهنگامدریکبارمیشودپیمایشباردولبههرمیکنیدمشاهده،سری بصورتباینری درختper-orderپیمایشبررس یبا
.(باالبهپاییناز)برگشتهنگامدریکبارو
).نمودتبدیلپیوندیلیستپیمایشبهراpre-orderپیمایشمسالهودادتغییررامسالهبهنگاهمیتوان،باالوپایینلبه2بهلبههرتبدیلبا
(.داردوجودمناسبیموازی الگوریتمآنبرایکه
درخترویازشدهساختهپیوندیلیستنمایش:c–شکل
:d–شکل
سپس،(استشدهدادهتخصیص0مقدارباالهایلبهبهو1مقدارپایینهایلبهبه)پیوندیلیستنودهایبه1یا0وزناختصاص
.میشودمحاسبهلیستانتهایبهنسبتعنصرهرجایگاه،List-Rankingالگوریتماعمالبا
نشانپررنگd–شکلدرهانوداین.میرسیمآنهابهپایینهایلبهدرکهمیشوندمالقاتزمانی،سری pre-orderپیمایشدرنودها
طبقنتیجهدر.استpre-orderپیمایشلیستانتهایازگرهامینG،4گرهیعنیاست4وزندارای(E,G)لبهمثال.اندشدهداده
(e–شکل).بودخواهدpre-orderپیمایشدرگرهامینG،5گره،n-k+1رابطه
![Page 13: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/13.jpg)
10
![Page 14: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/14.jpg)
11
:آرایه نیاز است3برای نمایش درخت به
Parent=نگهداری والد هر گرهsibling=نگهداری نزدیکترین همسایه سمت راستchild=نگهداری سمت چپ ترین فرزند
![Page 15: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/15.jpg)
12
List-Ranking
![Page 16: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/16.jpg)
![Page 17: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/17.jpg)
13
ا با انجام تعداد عملیات بیشتر ، پیچیدگی زمانی کمتری در مقایسه بPRAMدر اغلب موارد ، الگوریتم های .بدست می آورندoptimal RAMالگوریتم های
. مقایسه انجام میشودn-1، حد اکثر با n/2دو لیست مرتب با اندازه mergeبهینه برای RAMمثال الگوریتم . محقق میشودO( log n )در زمان PRAMهمین کار در الگوریتم
:PRAMتوضیح روش
.به هر عنصر در هر کدام از دو لیست ، یک پردازنده اختصاص می یابد
چراکه اندیس ) . بیابدbinary-searchهر پردازنده سعی می کند اندیس عنصرش را در لیست دیگر بوسیله ی . (عنصرش را در لیست خودش می داند
.فرض شده است که عناصر هر دو لیست کامال متمایز اند و تکراری نیستند
![Page 18: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/18.jpg)
14
Binary-search
![Page 19: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/19.jpg)
15
[1] [2] [3] [4] [5] [6] [7] [8]
11 12 13 14 15 16 17 18
آرایه مرتب
[5] [6] [7] [8]
12 14 15 17
[1] [2] [3] [4]
11 13 16 18
P3Low High Mid
5 8 6
P2 P3 P4 P5 P6 P7 P8P1
7 78 87
Low > High
A [High+ i – n/2] x
A [ 7 + 3 – 4 ] = A [6] 16
![Page 20: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/20.jpg)
16
• a graph with n vertices, represented by an n*n adjacency matrix,and a
constant c.
![Page 21: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/21.jpg)
17
![Page 22: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/22.jpg)
18
![Page 23: Elementary PRAM Algorithms (step by step trace)](https://reader031.vdocuments.us/reader031/viewer/2022032616/55a6c9681a28ab4e1d8b471a/html5/thumbnails/23.jpg)
19
Reference:
[1] E. Horowitz, S. Sahni - Computer Algorithms - New York: computer science
press 1998
[2] Books.google.com and other sources on Internet