All Questions
11 questions
8
votes
2
answers
6k
views
Is there a sensible way to sort coordinates?
Sorting is generally used to solve problems where distance between elements matters. A sorted list/array has the convenient property that the smaller the difference between the indices of any two ...
0
votes
1
answer
1k
views
Lower bound for finding a value in sorted array
Suppose we have a sorted array of unique elements, A[n]. I am trying to find the lower bound for finding a specific element x in the array. I suspect the lower bound to be log_2(n+1).
I tried to use ...
3
votes
4
answers
2k
views
Fastest algorithm of dividing array into positive and negative numbers
Given array of integers I am trying to design the fastest algorithm that swaps the elements such that at the end : all negative elements are on the left and then the positive elements, for example, ...
2
votes
1
answer
196
views
How to combine N non-comparable arrays up to an output limit in a fair way?
Given N non-comparable arrays of different sizes, what is the best method to combine them into one output array?
Since the input arrays are non-comparable, a metric is needed to represent how ...
2
votes
2
answers
5k
views
Merge sort and O(n log n) mystery
I read every explanation here but still not convinced. I think mergesort is n * n and I know I am wrong but not sure where. Here is what I think:
Suppose we are sorting 8 elements and this is the ...
44
votes
3
answers
23k
views
How to store ordered information in a Relational Database
I am trying to understand how to properly store ordered information in a relational database.
An example:
Say I have a Playlist, consisting of Songs. Inside my Relational Database, I have a table of ...
-1
votes
3
answers
621
views
Sorting an array when values are decreased by each swap [closed]
Recently in an interview I come across a question:
We have an unsorted array, we need to sort it with minimum number of swap. We have in sort a 'tax' of 1 is deducted from the number we are swapping....
1
vote
5
answers
6k
views
Reverse subarray of an array with O(1)
I have an idea how to implement sub array reverse with O(1), not including precalculation such as reading the input. I will have many reverse operations, and I can't use the trivial solution of O(N).
...
3
votes
1
answer
3k
views
Use ruby's array sort() method, or add items in correct place with a binary lookup?
If I am loading a whole load of items (un-ordered words from a file or something) would it be more efficient to load them all to a Ruby array, and then use the built in sort! method or to do a binary ...
1
vote
1
answer
1k
views
Sort rectangles in a grid based on a comparison of the center point of each
If I have a grid of rectangles and I move one of the rectangles, say above and to the left of another rectangle, how would I resort the rectangles?
Note the rectangles are in an array, so each ...
0
votes
1
answer
3k
views
Sorting an ArrayList by a Split Value [closed]
I am attempting to create an list which should be sorted by a particular field in a colon separated string. I have an array of strings with the following values:
name1:535
name2:697
After sorting ...