Parallel Algorithm Examples - PowerPoint PPT Presentation

About This Presentation
Title:

Parallel Algorithm Examples

Description:

Application of BST to Geometric Computation We will show how to use the BST to solve a problem involving axis-parallel rectangles. We want a data structure that ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 14
Provided by: Ravikumar
Category:

less

Transcript and Presenter's Notes

Title: Parallel Algorithm Examples


1
Application of BST to Geometric Computation We
will show how to use the BST to solve a problem
involving axis-parallel rectangles. We want a
data structure that allows insertion and deletion
of rectangles and report all intersections, and
compute the area covered. We will see how
binary search tree can be used to achieve this
goal.
2
Given a collection of rectangles (with sides
parallel to X and Y axes), find the total area
covered by them. Obviously, overlapping parts
should be counted only once. Complexity should be
O((kn) log n) where n is the number of
rectangles and k is the number of intersections.
3
Each rectangle is specified by the (x,y) values
of the upper left corner, its height and width as
shown in the figure below
(350, 175)
100
130
We are interested in determining all the points
of intersections and the area covered by the
rectangles.
4
Inefficient, but simple solution for
(every rectangle R) for (every rectangle S)
if (R ! S) return the
points of intersections of R and S
This solution is inefficient. (complexity
O(n2)). We will present a better solution based
on a balanced binary search tree. The basic
algorithm is called a sweep-line algorithm. Our
goal is to reduce the complexity, An algorithm of
complexity O(n log nk) exists for this problem.
But our algorithm will be slightly less
efficient. Its complexity is O((kn) log n). But
area and contour computation seem tricky!

5
  • Major Steps of sweepline algorithm
  • Y-tree
  • Build a tree called Y-tree that consists of
    y-values of various rectangles. Each node will
    use Y-value as the main key by which the BST will
    be organized. It will also have other
    information the label of the rectangle, the
    X-values etc. There will also information about
    whether it is low-y or high-y.
  • Y-tree is built from the input data as follows
    Each rectangle info is read, and two y-nodes are
    created and inserted into Y-tree. If there are n
    rectangles, there will be 2n nodes in the Y-tree.

6
Example Suppose the input consists of the
following two rectangles 1, 50, 50, 40, 30
2, 60, 40, 50, 60
T
The resulting tree T will look as follows
Lchild Rchild
yvalue 50
Label 1
xlow xhigh Low 50 90
T
yvalue 40
Label 2
nil
nil
yvalue 80
Label 1
nil
xlow xhigh Low 60 110
T
xlow xhigh Low 50 90
F
yvalue 60
Label 2
nil
nil
xlow xhigh Low 60 110
F
7
  • Y-tree can be built in O(n log n) time if we can
    keep the tree balanced.
  • Each insertion will take O(log n) time, and
    there will be 2n insertions.
  • Overall idea
  • perform a series of deleteMin operations on the
    Y-tree, process the node and perform some
    operation on the X-tree.
  • When this process ends, we would have computed
    all the intersections, the contour and the area.

8
X-Tree
  • Nodes are selected in increasing order from the
    Y-tree.
  • For each selected node, the following steps are
    carried out
  • Step 1 obtain the low-X and high-X from the
    node. Perform RangeSearch(low-X, high-X) in
    X-tree and report the intersections.
  • Step 2 If the selected node is a High-Y, then
    Insert low-X and high-X into X-tree else delete
    them from X-tree.
  • Step 3 Finally, delete the selected node from
    Y-tree.
  • When Y-tree is empty, the algorithm ends.

9
  • BST Extensions Required
  • We need to extend the node structure of the
    tree to make it a XtreeNode or YtreeNode.
  • We need a function to perform RangeSearch.
  • Successor(myKey) is a useful function It
    returns the smallest key (strictly) larger than
    myKey. With it, we will be able to write a
    method for RangeSearch.
  • Our library for AVL tree will provide a method
    for Successor. You are to write RangeSearch in
    the derived class.
  • Outline of successor is provided below.

10
static TreeNode Successor(TreeNode T,
int myKey) / returns reference to successor in
the tree rooted at T, if it exists. Else it
returns a null reference. / if (T null)
return null else if (T.key lt myKey)
return Successor(T.right,myKey)
else if (T.key myKey) return
FindMin(T.right) else TreeNode
tempSuccessor(T.left,myKey) if (tempnull)
return T else return temp
11
Computing the total area covered First we
consider the one-dimensional version of the
problem. Given a collection of intervals, compute
the total length covered by them.
2 5 7 11
12 15
In this case, the total length is 12. We will now
describe an O(n log n) algorithm for this
problem.
12
Length covered by a set of intervals Input
Array A of starting points, array B of end
points. Step 1. Sort all the 2n points and store
them in a single array. Also, for each point, a
single bit information is stored that indicates
if it is start. 1 2 3 4 5
6 2 5 7 11 12 15 1
1 0 0 1 0 Step 2 count 1 length
0 for i from 2 to 2n if (count !
0) length length Ci-Ci-1 if
(Di 1) count else count-- Step 3
output(length). How do you prove the
correctness?
13
Two dimensional version of the problem Input a
collection of rectangles. Output Total area
covered by them. Step 1. Build Y-tree using the
y-values. There will be two y-nodes for each
rectangle. Step 2. prevy currenty 0 area
0 Initialize X-tree to be empty. while (Ytree
not empty) n deleteMin from Ytree m
length of intervals covered by X-tree area
m (currenty prevy) prevy currenty
currenty n.yvalue Update X-tree using node
n Output(area)
Write a Comment
User Comments (0)
About PowerShow.com