Pregunta de entrevista de Microsoft

How would you sort an array if you had infinite RAM? Infinite memory?

Respuestas de entrevistas

Anónimo

30 sep 2012

I would probably use counting sort. This is not generally used outside of sorting a bunch of integer numbers that fall within a small range precisely because it uses a lot of memory. For e.g., to sort number in the range of 1 to 10,000, you will need an array C[1...10,000]. It can be extended to sort a set of any kind of stuff that has total ordering relationship between them, and is O(n) time. Only down side is that memory used will be insane depending on the range of values whatever you are sorting will take.

3

Anónimo

13 nov 2012

If no duplicates exist, create an infinite array, put each integer in the array by using the value of the integer as the index to put the value in the array, then read the array from left to right ignoring null values. N write + N read = O(n) time complexity.

1

Anónimo

28 ago 2013

counting sort!