Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When Would You Implement Your Own Sorting Algorithm?

Forgive me if this is a silly question....but I think back to my Comp. Sci. classes and I distinctly remember learning/being quizzed on several sorting algorithms and the corresponding 'Big O' notation.

Outside of the classroom though, I've never actually written code to sort.

When I get results from a database, I use 'Order By'. Otherwise, I use a collection class that implements a sort. I have implemented IComparable to allow sorting; but I've never gone beyond that.

Was sorting always just an academic pursuit for those of us who don't implement languages/frameworks? Or is it just that modern languages running on modern hardware make it a trivial detail to worry about?

Finally, when I call .Sort on a List(Of String), for example, what sort algorithm is being used under the hood?

like image 516
Rob P. Avatar asked Apr 29 '11 22:04

Rob P.


People also ask

Where we can use sorting algorithm?

A Sorting Algorithm is used to rearrange a given array or list of elements according to a comparison operator on the elements. The comparison operator is used to decide the new order of elements in the respective data structure.

Why we are using sorting algorithm?

A sorting algorithm will put items in a list into an order, such as alphabetical or numerical order. For example, a list of customer names could be sorted into alphabetical order by surname, or a list of people could be put into numerical order by age.

What is the use of sorting in real life?

For example: The contact list in your phone is sorted, which means you can easily access your desired contact from your phone since the data is arranged in that manner for you. In other words, “it is sorted”.

Do you need to know how do you implement sorting algorithms?

There are a ton of sorting algorithms in the world which could take you forever to memorize, but you don't need to know them all. There are a few key elements to each algorithm: conceptually how it works. code implementation.


1 Answers

While you rarely might need to implement a sorting algorithm yourself understanding the different algorithms and their complexity might help you in solving more complex problems.

Finally, when I call .Sort on a List(Of String), for example, what sort algorithm is being used under the hood?

Quick Sort

like image 67
Darin Dimitrov Avatar answered Oct 13 '22 01:10

Darin Dimitrov