Note that there are some explanatory texts on larger screens.

plurals
  1. PODivide and conquer on sorted input with Haskell
    primarykey
    data
    text
    <p>For a part of a divide and conquer algorithm, I have the following question where the data structure is not fixed, so <em>set</em> is not to be taken literally: </p> <p>Given a set X sorted wrt. some ordering of elements and subsets A and B together consisting of all elements in X, can sorted versions A' and B' of A and B be constructed in time linear in the number of elements in X ?</p> <p>At the moment I am doing a standard sort at each recursive step giving the recursion </p> <pre><code>T(n) = 2*T(n/2) + O(n*log n) </code></pre> <p>for the complexity rather than</p> <pre><code>T(n) = 2*T(n/2) + O(n) </code></pre> <p>like in the procedural version, where one can utilize a structure with constant-time lookup on A and B to form A' and B' in linear time. </p> <p>The added <code>log n</code> factor carries over to the overall complexity, giving <code>O(n* (log n)^2)</code> instead of <br> <code>O(n* log n)</code>.</p> <p>EDIT: Perhaps I am understanding the term lookup incorrectly. The creation of A' and B' in linear time is easy to do if membership of A and B can be checked in constant time. <hr> I didn't succeed in my attempt at making things clearer by abstracting away the specifics, so here is the actual problem:</p> <p>I am implementing the algorithm for the <a href="http://en.wikipedia.org/wiki/Closest_pair_of_points_problem" rel="nofollow">closest pair problem</a>. Given a finite collection P of points in the plane it finds a pair of points in P with the minimal distance. It works roughly as follows: </p> <p>If P has at least 4 points, form Px and Py, the points in P sorted by x- and y-coordinate. By splitting Px form L and R, the left- and right-most halves of points. Recursively compute the closest pair distance in L and R, let d be the minimum of the two. Now the minimum distance in P is either d or the distance from a point in L to a point in R. If the minimal distance is between points from separate halves, it will appear between a pair of points lying in the strip of width 2*d centered around the line x = x0, where x0 is the x-coordinate of a right-most point in L. It turns out that to find a potential minimal distance pair in the strip, it is enough to compute for every point in the the strip its distance to the seven following points if the strip points are in a collection sorted by y-coordinate. </p> <p>It is in the steps with forming the sorted collections to pass into the recursion and sorting the strip points by y-coordinate where I don't see how to, in Haskell, utilize having sorted P at the beginning of the recursion. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload