Question:
I want to know the order of different sortings used in C language?
2007-01-03 23:29:57 UTC
Which type of sorting is fastest in terms of speed and which sorting is efficient in using memory space.
Five answers:
RIA
2007-01-03 23:40:43 UTC
Sorting in C language:



Bubble Sort

Radix Sort

Heap Sort

Merge Sort

Insertion Sort

Quick Sort

Shell Sort

Radix Exchange Sort

Selection Sort



Searching:

Linear Search

Binary Search



I think Radix Sort is the fastest in terms of speed!!!
its_ramzi
2007-01-03 23:35:07 UTC
Sorting algorithms are measured in terms of Big O, which is a measurement of the worst case running time. Under that measurement, many sorting algorithms are equivalent. Specifically, though, which one executes fastest depends on the data provided.



The best any comparison based sort can be is O(n*log(n)). Some of these are quicksort, mergesort, and selection sort.



There are some O(n) sorts, including radix sort, and bin sort. These are used when the data being sorted are numbers.
2007-01-04 19:44:21 UTC
Sorting Algorithms Compared



Sorting algorithms are an important part of managing data. At Cprogramming.com, they offer tutorials for understanding the most important and common sorting techniques. Each algorithm has particular strengths and weaknesses and in many cases the best thing to do is just use the built-in sorting function qsort. For times when this isn't an option or you just need a quick and dirty sorting algorithm, there are a variety of choices.



Most sorting algorithms work by comparing the data being sorted. In some cases, it may be desirable to sort a large chunk of data (for instance, a struct containing a name and address) based on only a portion of that data. The piece of data actually used to determine the sorted order is called the key.



Sorting algorithms are usually judged by their efficiency. In this case, efficiency refers to the algorithmic efficiency as the size of the input grows large and is generally based on the number of elements to sort. Most of the algorithms in use have an algorithmic efficiency of either O(n^2) or O(n*log(n)). A few special case algorithms (one example is mentioned in Programming Pearls) can sort certain data sets faster than O(n*log(n)). These algorithms are not based on comparing the items being sorted and rely on tricks. It has been shown that no key-comparison algorithm can perform better than O(n*log(n)).



Many algorithms that have the same efficiency do not have the same speed on the same input. First, algorithms must be judged based on their average case, best case, and worst case efficiency. Some algorithms, such as quick sort, perform exceptionally well for some inputs, but horribly for others. Other algorithms, such as merge sort, are unaffected by the order of input data. Even a modified version of bubble sort can finish in O(n) for the most favorable inputs.



A second factor is the "constant term". As big-O notation abstracts away many of the details of a process, it is quite useful for looking at the big picture. But one thing that gets dropped out is the constant in front of the expression: for instance, O(c*n) is just O(n). In the real world, the constant, c, will vary across different algorithms. A well-implemented quicksort should have a much smaller constant multiplier than heap sort.



A second criterion for judging algorithms is their space requirement -- do they require scratch space or can the array be sorted in place (without additional memory beyond a few variables)? Some algorithms never require extra space, whereas some are most easily understood when implemented with extra space (heap sort, for instance, can be done in place, but conceptually it is much easier to think of a separate heap). Space requirements may even depend on the data structure used (merge sort on arrays versus merge sort on linked lists, for instance).



A third criterion is stability -- does the sort preserve the order of keys with equal values? Most simple sorts do just this, but some sorts, such as heap sort, do not.



For more information see the following link:



http://www.cprogramming.com/tutorial/computersciencetheory/sortcomp.html

.

.

.
nurav
2007-01-03 23:56:20 UTC
you can measure the running times of various sorting algorithms asymptotically

so the better ones wud be Counting Sort, Bucket Sort and Order sort.

Next Comes heapsort

then randomized quicksort

then merge sort because it requires more space for sorting
bhumika c
2007-01-04 00:04:29 UTC
List of sorting:

Fastest sort : Insertion sort

Then: Merge sort

Quick sort

Heap sort

Selection sort

Bubble sort

Efficient is: Insertion sort


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...