Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a problem to solve for which I did not find any usable algorithms after an internet search and I have not been able to come up with a satisfying solution myself yet.
Problem definition:
I am given a set of N-many points, defined by their X- and Y-coordinates, and I am supposed to give each point a unique index between 0 and N. There are a few conditions though:
1) if the geometric distance between two points is small, the difference between their indices should be small too.
2) if point A has a higher X-coordinate as point B it should have a higher index value too.
3) if point A has a higher Y-coordinate as point B it should have a higher index value too.
Other:
The algorithm does not need to be particularly fast or efficient as the data is fairly small (50 ~ 100 points).
I need this algorithm for a user interface with only 2 buttons for navigation through a data set. With one button the user selects the next point and with the other the user selects the previous point.
All suggestions are welcome. Thanks in advance.
Example Image:
This is an example of what a result could look like. Please note how the conditions are not fulfilled for all points (as that would be impossible) but how the indices are still nicely distributed among the clusters.
Sort the points by the Morton curve aka Z-order (Wikipedia).
Then assign numbers.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 11 hours ago.
Improve this question
Winning Team # Previous
There is a scientific competition held every year in which students participate in the form of teams. the team that solves all the problems wins. We know that every student has power Pi in a subject Si.
This Question JPEG Links - https://i.stack.imgur.com/qzF5p.jpg
It is given that quiz questions will demand powers of Qpj in subject j (where j is from 1 to k). If there are two students with power X and Y in subject Z, the power of the team in that subject will be X + Y.
You have N students and want to choose from them a team that can solve all the problems of the competition and be composed of as few students as possible. It is mandatory that you choose a successive subgroup while selecting a team
Your task is to find the smallest number of students in the team to be able to win. If it is not possible to determine the answer print -1.
Note- Actually in this question time complexity issues is coming. so please make and provide us solutions.
I want solution of this question we can't run this question time complexity issue in execution. we wrote program against this questions. but stuck in middle after 3 seconds remaining execution parts.
We Wrote Java Code
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've been aksed to write a program that finds the largest area of equal neighbour elements in a rectangular matrix and prints its size. I tried to construct a 2d array with some numbers but I think that I should switch to using a tree or something in order to solve this problem. Chould somebody suggest a possible way of solving it?
For example:
"Hint: use the algorithm Depth-first search or Breadth-first search."
Sounds like a standard maze search problem. I suggest you use recursion to find all the elements which you haven't been to before which have the same number as the one you have found. You can either update the matrix as you go or create a copy to keep track of the cells you have visited. So you don't need a tree or even an additional complex data structure.
use the algorithm Depth-first search or Breadth-first search
These are two types of recursive searches. I suspect you could implement both of these to see how they behave.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need som help understanding how this works! how do I go about calculating the complexity of 'Computing the first half of an array of n items' or 'displaying the third element in a linked list' ? I need someone to explain how this works, theses are just examples, so be free to use your own if it helps explaining! thank you.
You should look at how the processing time of the algorithm grows as the size of the input grows. I'll take your two concrete examples:
Computing the first half of an array of n items
We need to process n/2 items. If n doubles, then the processing time should also double. Consequently, this is a linear operation (i.e. O(n)).
displaying the third element in a linked list
We always want to display the third element, so the size of the list doesn't actually matter. If it doubles, we don't care; the processing time is not affected. Consequently, this is a constant-time operation (i.e. O(1)), it doesn't depend on the size of the input.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
There's one question posted about Fibonacci Series, which I am much familiar with it. But there are multiple answers and linked questions to it. As I was digging through it with some interest, there's a solution which is linked to here
This algorithm solves the problem by O(log(n)) quite impressive. But I couldn't understand the logic and so called Matrix exponentiation [looked wiki, but unable to relate to it].
So kindly anyone can explain exactly how they achieved with more details and better explanation [if you can explain with code, prefer in Java, much helpful].
Thanks :)
What you need to understand is the algorithm, not the implementation.
The first thing you need to understand is that this algorithm will not give you all the fibonacci numbers, only those with with a n that is a power of 2.
The second thing is that a multiplication of constantly sized matrices of course takes constant ( O(1) ) time.
The trick now is to correctly note that the n'th fibonacci number can be formed by n-times multiplication of the matrix described in your link, which i will call M.
You get the log complexity by now "reordering" the matrix operations from, for example M*(M*(M*M)) to (M*M)*(M*M). With each matrix squaring, you go to M^2n instead of M^n+1.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I cannot figure out what data structure will be the best for this type of the problem:
I have a circle. It can have cuts at different positions(angle). Segments between cuts have color(say red or black). If there are no cuts all circle has one color.
What operations do I need on it?
[1] Change color of the segment.
[2] Add cut at some angle.
[3] For a given angle tell which segment it belongs.
[4] Join consecutive segments of the same color.
Right now I have class for a Segment storing angles of its ends and color.
And ArrayList to work with it.
Problems that I have:
[1]I want something faster than ArrayList. (TreeSet? something else?)
[2]I am treating circle without cuts as a special case. (two fake cuts at 0 and 0)
[3]I am treating Segments containing 0 angle as special case. Say Segments (7pi/8, pi/8) and (pi/8, 7pi/8) require different approach and enormous amount of if conditions.
The idiomatic way to do this in Java is not to use a data structure, but to create your own class. EG: a SegmentedCircle class. Give it the API you wish it had and then implement that as behavior. It'll probably delegate to other classes named Segment or Cut and may have a list of these.
It's usually a safe bet to get your API right/convenient first, then worry about performance second (and only if it's actually needed). In other words, don't pre-optimize.
Since you've told me that you need faster Adds and Removes, the right tool for the job may be a HashSet. From its documentation:
This class offers constant time performance for the basic operations (add, remove, contains and size)
Note: You need to make sure you implement equals and hashcode correctly on your classes for this to work propertly.