370 likes | 640 Views
Searching. data record:. sequential search ( linear search): O(n) binary search: used for sorted sequence O(log n). Example: 3, 11, 2, 9, 8, 5, 4, 6, 7. O(log N). O(1). O(log n/N). O(1). time:. EREW Searching(Sorted Sequence). N processors. n data records method:.
E N D
data record: sequential search ( linear search): O(n) binary search: used for sorted sequence O(log n). Example: 3, 11, 2, 9, 8, 5, 4, 6, 7
O(log N) O(1) O(log n/N) O(1) time: EREW Searching(Sorted Sequence) N processors n data records method: Step 1. Broadcast the searched element x and N. Step 2. Each processor stores records. Step 3. Each processor performs binary search. Step 4. The processor which finds x reports the key index.
EREW Searching(Sorted Sequence) N = 1, n =8, x = 15 1, 3, 4, 6, 9, 10, 11, 15 9, 10, 11, 15 11, 15 15 共有O(logN+1(n+1))個stages
EREW Searching Example: 2, 3, 4, 5, 6, 7, 8, 9, 11 N = 3, x= 5 Step 2. P1: 2, 3, 4 P2: 5, 6, 7 P3: 8, 9, 11 Step 1. P1: N = 3, x= 5 P2: N = 3, x= 5 P3: N = 3, x= 5 Step 3. P1: i = 0 P2: i = 4 P3: i = 0 Step 4. i = 4
CREW Searching(Sorted Sequence) N processors (N+1)-ary search P1 : 1*(3+1)2-1 = 4 P2 : 2*(3+1)2-1 = 8 P3 : 3*(3+1)2-1 = 12 N = 3, n =15 g = log16/log 4 = 4/2 = 2
N = 1, n =8, x = 15 1, 3, 4, 6, 9, 10, 11, 15 9, 10, 11, 15 11, 15 15 共有O(logN+1(n+1))個stages
(N+1)g n+1 g = [log(n+1)/log(N+1)] P1 : 1*(N+1)g-1 P2 : 2*(N+1)g-1 … PN : N*(N+1)g-1
time: where n is #of elements. It is assumed that all elements are distinct. Otherwise, there may be write conflicts.
Searching a random sequence on EREW Step 1: Broadcast the searched element. Step 2: Each processor performs a sequential search. Step 3: Report the index of the found element.
EREW Searching(random sequence) Example: 3, 11, 2, 9, 8, 5, 4, 6, 7 N = 3, x= 5 Step 2. P1: 3, 11, 2 P2: 9, 8, 5 P3: 4, 6, 7 Step 1. P1: N = 3, x= 5 P2: N = 3, x= 5 P3: N = 3, x= 5 Step 3. P1: i = 0 P2: i = 6 P3: i = 0 Step 4. i = 6
Time: N: #of processors. n: #of elements.
Time: When N=n and q queries: Time: Can this be improved?
Searching a random sequence on a tree Each intermediate node can receive one input from its parent, and send it to its two children; and receive two inputs from its children, combine them, and pass the result to its parent.
1 query: time: O(log n) q queries: pipeline time: O(log n + q)
Some Variations position count: #of elements = x closest element: is the smallest. rank: #of elements < x + 1
Maintenance Each intermediate node and the root store #unoccupied leaves in its left subtree #unoccupied leaves in its right subtree insertion: arbitrarily choose an unoccupied leaf. then, update the#. deletion: delete it, and update the#.
Usually the wire delay between two nodes is assumed to be a constant. In a hardware implementation of a tree, the wire delay is proprotional to the wire length. The maximum wire length is O(n). time for one query: O(n).
H-tree layout: time.
Searching a random sequence on a mesh
Row propagation and column propagation are performed alternately. 1 query: time: more than one query: pipeline The result has to be propagated to the lowest row and the rightmost column with the searched element. The period is constant.