Answer the question
In order to leave comments, you need to log in
Why learn sorting algorithms if there are ready-made sorting methods?
And also why learn and why, in principle, there are many linear sorting algorithms, if they all have O(n ^ 2) execution time (such as BubbleSort, InsertionSort etc ), that is, in fact, why do the same thing, in different ways, for me so this is stupid???
What's the catch?
Thanks in advance for your ANSWER!
Answer the question
In order to leave comments, you need to log in
1) For the development of thinking. Working with sorting algorithms is a good practice for developing programming skills. Plus, it is conveniently checked by the teacher, it is convenient to give feedback during training.
2) To later remember that they are different and find and use a ready-made solution not the first one that comes to hand, but take into account the pros and cons of this or that algorithm and choose exactly what is best suited for a specific task.
For more than 20 years of programming, indeed, I rarely sorted myself, more and more I used ready-made algorithms.
I do not regret at all that I once studied sorting algorithms. This greatly expands the professional horizons.
Sorting algorithms are standard material for teaching students about the complexity of algorithms. It's like a dictation - there are words without you, but you still need to learn how to write them.
To imagine what's going on there.
To understand what you are doing, and not mindlessly monkey around.
To implement the algorithm in case there is no ready-made library.
To train algorithmic thinking.
As for the time - different algorithms are optimal for different sets and data types.
Sometimes it is necessary to sort for a reason, but with some kind of bells and whistles, such as in some special way, or at the same time do something else, such, for example, is often found at the Olympiad programming, here are some ready-made methods they won't give a ride
More like for educational purposes. This is a good example of an algorithm that needs to be understood. In practice, you certainly won't write it yourself. Well, it is useful to know about different methods, since they are slightly different.
By the way, linear complexity is O(n). O(n^2) is called quadratic.
Standard sorts run in O(n * log(n)). But often this estimate is not exact but averaged.
There are sorts that can work with data in chunks without loading everything into memory.
There are linear sorts, but for this you need to know something more about the data. For example, counting sort works well on limited sets (for example, on arrays of numbers 0-9).
There are other important properties such as stability. This is when you sort files first by date and then by type, and as a result, all files of the same type remain ordered by date.
If you drive the same route every day for 12 kilometers of paved roads in a Ford Focus, then it is not necessary to have an understanding of the Carnot cycle or the kinematics of gearboxes. But if you want to win the Dakar Rally...
I’ll say an unpopular opinion here, but most average programmers don’t need to know this at all. Although no, it’s still good to know, it will come in handy for an interview.
Briefly:
If your code uses sorting of any type, you are a bad programmer!
This means that the data should be accessed by their relationships (ID+OOP) in the store, and not by an unsorted list that needs to be sorted and then selected from it.
Sorting (more precisely, position selection) should be ONLY at the stage of creating / adding a new object instance to the list / queue / tree / etc (ie, to any storage structure)!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question