Can anyone help me to compute this complexity?
What i think is :
Line 1 is an O(nlogn) for the sort.
Then,I have to compute for every node (line 2, while (U!=0) ) two stars for the node.
Compute one star for all nodes its cost O(|E|), but my problem is the second star.
Can anyone help me?
Related
Given 𝑛 points on a line and 𝑚 intervals on the same line. Design a polynomial-time algorithm that will return the minimum number of intervals whose union covers all 𝑛 points. Prove the correctness of the algorithm.
I have to write a program in python to solve this problem.
Any idea ?
Thanks in advance
I came across this question in preparation for the final exam, and I could not find the recursive formula although I saw similar questions.
I will thank you for any help!
the problem is:
Suppose we are given a set L of n line segments in the plane, where the endpoints
of each segment lie on the unit circle x
2 + y
2 = 1, and all 2n endpoints are
distinct. Describe and analyze an algorithm to compute the largest subset of L in
which every pair of segments intersects
The solution needs to be an algorithm in dynamic programming approach (based on recursive formula)
I am assuming the question ("the largest subset of L...") is dealing with the subset size, and not that the subset cannot be extended. If the latter is true, the problem is trivial and the simple greedy algorithm works.
Now to your question. Following Matt Timmermans' hint (can you prove it?) this can be viewed as the longest common subsequence problem, except that we don't know what the 2 input strings are = where the splitting point between the 2 sequence occurences is.
Longest common subsequence problem can be solved in O(m*n) time and linear memory. By moving the splitting point along your 2n-length array you will create 2n instances of the LCS problem each of which can be solved in O(n^2) time, which yields the total time complexity of O(n^3).
Your problem is known as the maximum clique problem (with line segments corresponding to graph nodes, and line segments intersections corresponding to graph edges) of a circle graph and has been shown in 2010 to have a solution with O(n^2*log(n)) time complexity.
Please note that the maximum clique problem (the decision version) is NP-hard (NP-complete, to be exact) in the case of an arbitrary graph.
Suppose we have two sets of points, say A and B (both of size O(n)) in the plane. Can we find farthest pair of points each being in A & B in O(n) time?
No, you can not calculate the furthest point for each point in O(n). The best you can obtain is O(n log n) with a 2-d tree. You can do this with a technique, similar to finding a closest point.
Read a more detailed answer here where I show a couple of other approaches to solve a similar problem.
I need to get two points that have biggest distance between.
The easiest method is to compute distance between each of them, but that solution would have an quadratic complexity.
So i'm looking for any faster solution.
How about:
1 Determine the convex hull of the set of points.
2 Find the longest distance between points on the hull.
That should allow you to ignore all points not on the hull when checking for distance.
To elaborate on rossom's answer:
Find the convex hull of the points which can be found in O(n log n) time with an algorithm like Graham's Scan or O(n log h) time with other algorithm's which I assume are harder to implement
Start at a point, say A, and loop through the other points to find the one furthest from it, say B.
Advance A to the next point and advance B until it is furthest from A again. If this distance is larger than the one in part 2, store it as the largest. Repeat until you have looped through all points A in the set
Parts 2 and 3 take amortized O(n) time and therefore the overall algorithm takes O(n log n) or O(n log h) time depending on how much time you can be bothered spending on implementing convex hull.
This is great and all but if you only have a few thousand points (like you said), O(n^2) should work fine (unless you're executing it many times).
I have a graph in form of a rectangular grid, i.e. N nodes and 2N edges, all adjacent nodes are connected.
This means it is two-colourable, and hence it is possible to do bipartite matching on it.
Each (undirected) edge has a weight assigned to it - either -2, -1, 0, 1 or 2. No other values are allowed
How would I go about finding the matching on this graph that maximises the sum of the weighs in the matching? Pseudocode would be nice, don't bother with specific languages.
Ideally, I am looking for an algorithm that runs in quadratic time - maybe O(n^2 log n) at worst.
Before you propose a solution, I have tried doing a max match using edges of weight 2, then of weight 1 (without going over edges of weight 2). I have scored 98% with this implementation (the problem is from an informatics olympiad), and wondering what is the 100% solution.
Not sure why you are thinking of min cut. A cut is not guaranteed to give you matching in this case. What you need to do is solve assignment problem.Assignment Problem. The successive shortest math algorithm solves it in O(EV log V) which in your case is O(n^2 log n).