space-efficiency

Efficiently finding the ranks of elements in an array?

 ̄綄美尐妖づ 提交于 2019-12-04 04:22:41
问题 How does one find the rank of each element of an array, averaging in the case of ties, efficiently? For example: float[] rank(T)(T[] input) { // Implementation } auto foo = rank([3,6,4,2,2]); // foo == [3, 5, 4, 1.5, 1.5] The only way I can think of doing it requires allocating 3 arrays: A duplicate of the input array because it has to be sorted and we don't own it. An array to keep track of the order in which the input array was sorted. An array of ranks to return. Does anyone know how to do

Is Quicksort in-place or not? [duplicate]

Deadly 提交于 2019-12-03 03:37:54
问题 This question already has answers here : Is imperative Quicksort in situ (in-place) or not? (2 answers) Closed 5 years ago . So the space efficiency of Quicksort is O(log(n)). This is the space required to maintain the call stack. Now, according to the Wikipedia page on Quicksort, this qualifies as an in-place algorithm, as the algorithm is just swapping elements within the input data structure. According to this page however, the space Efficiency of O(log n) disqualifies Quicksort from being

Efficiently finding the ranks of elements in an array?

梦想的初衷 提交于 2019-12-01 21:18:15
How does one find the rank of each element of an array, averaging in the case of ties, efficiently? For example: float[] rank(T)(T[] input) { // Implementation } auto foo = rank([3,6,4,2,2]); // foo == [3, 5, 4, 1.5, 1.5] The only way I can think of doing it requires allocating 3 arrays: A duplicate of the input array because it has to be sorted and we don't own it. An array to keep track of the order in which the input array was sorted. An array of ranks to return. Does anyone know how to do this in O(N log N) time and O(1) auxiliary space (meaning the only array we have to allocate is the

Difference between passing array and array pointer into function in C

倾然丶 夕夏残阳落幕 提交于 2019-11-25 22:44:06
问题 What is the difference between the two functions in C? void f1(double a[]) { //... } void f2(double *a) { //... } If I were to call the functions on a substantially long array, would these two functions behave differently, would they take more space on the stack? 回答1: First, some standardese: 6.7.5.3 Function declarators (including prototypes) ... 7 A declaration of a parameter as ‘‘array of type ’’ shall be adjusted to ‘‘qualified pointer to type ’’, where the type qualifiers (if any) are