Domanda di colloquio di Microsoft

Sorting Algorithms Optimizations from 2 loops to just 1 loop

Risposte di colloquio

Anonimo

5 ott 2012

use quicksort. it has runtime of O(n.logn), or heapsort. they both use one for loop and a heap/stack

1

Anonimo

9 apr 2012

#include #include using namespace std; int main() { int list[10] = {5, 4, 3, 6, 7, 1, 2, 9, 8, 10}; for (int i=0; i= 0 && next list[next]) { int temp = list[i]; list[i] = list[next]; list[next] = temp; next--; } else next++; } } for (int i=0; i<10; i++) { cout << list[i] << " "; } return 0; }

Anonimo

19 apr 2012

you still have two loops #include #include using namespace std; int main() { int list[10] = {5, 4, 3, 6, 7, 1, 2, 9, 8, 10}; for (int i=0;j=i; i<10; i++;j++) { I can't remember, but you use two indices within one loop to sort using bubble sort } for (int i=0; i<10; i++) { cout << list[i] << " "; } return 0; }

Domande di colloquio di Microsoft: Sorting Algorithms Optimizations from 2 loops to just 1 loop | Glassdoor