answersLogoWhite

0


Best Answer

There are a great many sorts, Mergesort and Quicksort being among the most popular. These both have on the order of n*log n expected case runtime, and while Quicksort can get as bad as n^2, this is unlikely due to most implementations using a random pivot.

If you can make the assumption that ONLY NUMBERS will be sorted, you can use RadixSort, which is the fastest known sort for numbers.

As for how to sort in particular programming languages, consult your local API (in C++ it is in the STL's "algorithm" include file).

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

10y ago

The algorithm for selection sort is to treat the array as two subsets, with the sorted subset to the left and the unsorted subset to the right. Initially, the sorted subset is empty, but we repeatedly scan the unsorted subset for the smallest element and swap it with the first element in the unsorted subset, thus reducing the unsorted subset by one element each time. When there is only one element left in the unsorted subset we are done; we have already sorted every element that is less than or equal to the final element.

To implement this algorithm in C++, we can use the following template function:

template<class T>

void selection_sort(T a[], size_t size)

{

// an array of 0 or 1 elements can always be regarded as being sorted

if( size<2 )

return;

// traverse from left to right, stopping at the penultimate element

// (by the time we sort the penultimate element, the final element

// is guaranteed to be greater than or equal to it).

size_t last = size-1;

for( size_t index=0; index<last; ++index )

{

// assume the currently indexed element is the smallest element.

size_t smallest=index;

// locate an element that is smaller in the remainder of the array

for( size_t select=index+1; select<size; ++select )

if( a[select]<a[smallest] )

smallest=select;

// if we found a smaller element, swap it with the indexed element.

if( index!=smallest )

{

T temp=a[index];

a[index]=a[smallest];

a[smallest]=temp;

}

}

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

A sorting algorithm's efficiency is measured in the number of comparisons required to completely sort the elements in the array given a worse case scenario. The best sorting algorithms are rated at O(n), where n is the number of elements, and the worst algorithms are O(n2), with most algorithms falling in the O(n log n) range.

A best case algorithm, for example, takes about 20 comparisons when there are 20 elements, while a worst case algorithm would take about 400 comparisons for 20 elements.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Qucik sort or merge sort with time complexity O(n log n). In terms of both time and space Qucik sort is efficient.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Quick Sort

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which one is the best and efficient sort?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the best design for a waterwheel?

An overshot was the olderst most efficient one.


Which algorithm is more efficient- insertion sort algorithm or merge sort algorithm?

On average merge sort is more efficient however insertion sort could potentially be faster. As a result it depends how close to reverse order the data is. If it is likely to be mostly sorted, insertion sort is faster, if not, merge sort is faster.


Which term refers to the most efficient route from one node on a network to another?

Best Path


What are the advantages and disadvantages of radix sort?

Advantages:Easy to implementIn-place sort (requires no additional storage space)Disadvantages:Doesn't scale well: O(n2)


Which is the best webpage?

It depends entirely upon what sort of website you're looking for. There is on one "best" webpage out there.


What is the best fuel efficient truck brand?

According to my research the 2011 Dodge Ram 1500 Pickup 2W appears to be one of the best fuel efficient trucks that has come out this year, based on an article in Popular Mechanics.


What are the best free mac downloadable games?

Sauerbraten (Best one) Cube (same as the one above, sort of) That's about it, but Sauerbraten is the best game I have ever played.


What are advantages and disadvantages of merging?

merge sort is the most efficient way of sorting the list of array.


What are the best energy efficient cars?

If you are looking for more information on What are the best energy efficient cars, the best place to find the information is on www.consumerreports.org Best & worst cars review.


Where is FAT best efficient?

Stomach


Which is the best sorting methad?

There is no one best sorting method. The qsort() function is a good all rounder. The best sorting method depends on what you want to sort and how many items you need to sort and can only be determined by actual testing.


Which cassette deck is best for recording from one cassette to another?

The Nakamichi is the best tape deck for any sort of recording.