1 / 26

Searching

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:.

mercury
Download Presentation

Searching

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Searching

  2. 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

  3. 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.

  4. 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

  5. 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

  6. 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

  7. 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

  8. (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

  9. time: where n is #of elements. It is assumed that all elements are distinct. Otherwise, there may be write conflicts.

  10. 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.

  11. 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

  12. Time: N: #of processors. n: #of elements.

  13. EREW Searching(random sequence)

  14. Time: When N=n and q queries: Time: Can this be improved?

  15. 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.

  16. 1 query: time: O(log n) q queries: pipeline time: O(log n + q)

  17. Some Variations position count: #of elements = x closest element: is the smallest. rank: #of elements < x + 1

  18. 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#.

  19. 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).

  20. H-tree layout: time.

  21. Searching a random sequence on a mesh

  22. 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.

More Related