Problems with integer sorting algorithms? Sorting Algorithm Count sorting

Updated on technology 2024-02-09
10 answers
  1. Anonymous users2024-02-05

    Fast row (the most common and the easiest).

    The idea of algorithms is divide and conquer.

    The implementation process is as described in GIS19831203 above.

    Look for pivots (those to the left of the pivot are smaller than the pivot, and those to the right of the pivot are larger than the pivot), and this is done repeatedly, with recursion. ”

    Stacking (unstable, but an effective algorithm idea for solving a certain type of problem) is an algorithm with a time complexity of n*(log2 n).

    I don't know about faster algorithms!!

    The maximum amount of computation on your data is:

    Estimated ......Even such an algorithm takes tens of minutes to calculate!!

    Unless you use a supercomputer ...

    Bubbling, insert ......Equal n 2 algorithms.

    Don't think about it.

    Fast Row requires all data to be read in advance.

    It doesn't seem like there's a need to be able to read one by one to create a heap.

    Then proceed with the operation but the heap also needs to be fully documented.

    Given that your maximum data volume is 2 32!!

    It's not satisfying just from a spatial point of view

    Even though the algorithm is very efficient, fast, and awesome.

    It's also difficult for the average device to meet your maximum data requirements.

    The requirements for the operating system are also very demanding (linix is recommended), and c seems to come with a sorting function.

    I see.

    Speechless......In this case, use the fast sorting algorithm.

    500,000 is a second (it should be an instantaneous thing).

    The algorithm you're using is an algorithm of n 2, which is too slow.

    Generally speaking, the time required for this type of question should be in between.

    The knowledge point examined is the sorting algorithm with a time complexity of n*(log2 n).

    Your program can't test all the data in a time-bound manner.

    It is recommended to use the fast sequencing algorithm.

    Go online and search for an explanation of such algorithms.

    Find your own explanation and then learn ...

  2. Anonymous users2024-02-04

    You can try it with the bubbling method, which is to continuously discharge the size of two adjacent numbers.

  3. Anonymous users2024-02-03

    The sorting algorithms mentioned above are all achieved through comparison. Can sorting be achieved without comparison? Yes, that's how amazing it is to count and sort the grips.

    Create an array of counts, using the array subscript to represent the element, and the value corresponding to the array subscript to represent the number of times the element occurs. Then iterate over the count array. For example, if the subscript is 5 and the element value is 2, it means that 5 appears twice, and 5 can be written twice in a row.

    1.Case:

    Suppose the arr of the order to be sorted is as follows:

    The maximum element is 8, so create an array with a maximum subscript of 8:

    Traversing the sequence to be sorted, the first one is 5, so count[5]++ and the second one is 7, so count[7]++

    The final count array is:

    Finally, according to the count array, we can know that 3 appears once, 4 appears once, 5 appears twice, and ...... appearsYou can know that the sorting should look like this:

    This may seem perfect, but there are two problems.

    2.Question 1:

    The 5 above appears twice, and the 5 with the subscript 2 in the last ordered array is still the 5 with the subscript 0 in the original sequence? That is to say, when the values are the same, there is no way to ensure that the order in which the same elements appear after sorting is the same as before sorting, which is what we call unstable ordering. How to optimize it?

    Let's mark the two 5s in the previous array to make it easier to distinguish them:

    In this way, the count array becomes:

    3.Question 2:

    Suppose the existing to-be arr is as follows:

    As mentioned earlier, the maximum subscript of the count array is the maximum value of the arr array, i.e. if you want to sort these four numbers, you need to create an array of length 1001. Moreover, these spaces from 0 to 994 are not used, and they are wasted. Therefore, the length of the count array should be max(arr) -min(arr) +1, that is, the maximum value is subtracted from the minimum value and then added by 1.

    In this case, the length of the count is 1000 - 995 + 1 = 6, so which subscript should each element be placed on? Each element is subtracted from the smallest element, and the resulting value corresponds to the subscript of count. For example, if 999 - 995 = 4, then 999 should correspond to count[4].

    4.Disadvantages of counting sorting:

    From the above analysis, we can know that counting sorting is suitable for the data in the distribution of relatively concentrated data, that is, the maximum and minimum values are not much different, and if there is a lot of difference, it will be very space-consuming.

  4. Anonymous users2024-02-02

    Choice sorting is a simple, easy-to-implement algorithm for sorting data. Taking the integer array element as an example, there is the array a[10], that is, a[0], a[1] ,...a[8], a[9] (assuming that their elements are not the same as each other). Require that its elements be ordered in increments.

    Start scanning from one direction with an element as the reference, e.g. from left to right, with a[0] as the reference.

    Next, ,... from a[0].a[9] and swap it with a[0].

    Then move the datum position one place to the right and repeat the above action, e.g., using a[1] as the base, find the smallest of a[1] a[9] and exchange it with a[1].

    The sorting ends when the datum position is moved to the last element of the array (at this point, all the elements to the left of the datum are incrementally ordered, and the datum is the last element, so the sorting is complete).

    main()

    int array[10];

    Initialize the array!

    int i,j,k,temp;

    for(i=0;i<10-1;i++)="" }

  5. Anonymous users2024-02-01

    I think it's so difficult, it's like a permutation and combination problem when I was studying, but if I look closely, it's not, it's really a bit difficult for me who hasn't been very good at math grades, so I'll look at the book first.

  6. Anonymous users2024-01-31

    Let's start with the best sort case in quick sorting, in the best case, every time we partition, we will divide a sequence into two subsequences that are nearly equal, and in this case, we will also deal with half the size of the subsequence every time we call it recursively. This looks like a full binary tree with a depth of o(logn), so you need to make o(logn) nested calls. But in two program calls in the same hierarchy, the same part of the original sequence is not processed.

    As a result, each hierarchy of program calls takes a total of o(n) time. So the time complexity of this algorithm in the best case is o(nlogn).

    But calling the decrement data to quicksort for incrementing sort is the worst case in quicksort, you can imagine that after each partition there is a subsequence of 1 in length and n-1, which will cause our expression to become:

    t(n) =o(n) +t(1) +t(n-1) =o(n) +t(n-1)

    This is the time complexity, which is o(n).

  7. Anonymous users2024-01-30

    The most basic sorting algorithm for interviews.

  8. Anonymous users2024-01-29

    1. Background.

    In computer science and mathematics, a sorting algorithm is an algorithm that arranges a string of data in a specific sorting way.

    The most commonly used sorting methods are numeric order and dictionary order.

    Effective sorting algorithms are important in some algorithms (e.g., search algorithms and merging algorithms) so that these algorithms can be answered correctly.

    Sorting algorithms are also used to process textual data and produce human-readable outputs.

    Basically, the output of a sorting algorithm must adhere to the following two principles:

    1. The output result is an increment sequence (the increment is for the desired sort order);

    2. The output result is a permutation or reorganization of the original input;

    2. Knowledge analysis.

    The search and sort algorithm is an introduction to algorithms, and its classical ideas can be applied to many algorithms. Because of its shorter implementation, applications are more common. Therefore, in interviews, it is common to ask questions about the sorting algorithm and its related questions.

    However, as long as you are familiar with the ideas, it is not difficult to use them flexibly.

    Generally, the most common tests in interviews are quick sort and bubbling sorting, and there are often interviewers who ask them to write out these two kinds of sort on the spot. The ** of these two sorts must be at your fingertips. In addition to that, there are insert sorting, bubbling sorting, heap sorting, cardinality sorting, bucket sorting, etc.

    3. Common algorithms:

    Bubbling Algorithm, Selection Sort, Insert Sort, Hill Sort, Merge Sort, Quick Sort.

    Features of the algorithm:

    1. Finiteness: An algorithm must ensure that it ends after executing a finite step.

    2. Certainty: Each step of an algorithm must be precisely defined.

    3. Input: An algorithm has zero or more inputs to describe the initial situation of the operation object, and the so-called zero input means that the algorithm itself is given the initial conditions.

    4. Output: An algorithm has one or more outputs. An algorithm without output is meaningless.

    5. Feasibility: Any calculation step executed in the algorithm can be broken down into basic executable operation steps, that is, each calculation step can be completed in a limited time (also called effectiveness).

  9. Anonymous users2024-01-28

    Select d to select sorting, after the first trip is finished, it must be the smallest and the maximum value is in the front, so it is not eligible to quickly sort after the first trip is finished, and the left side is smaller than him, and the right side is larger than him (or vice versa).

    After the first trip of heap sorting, you need to see how the nodes numbered 1 are adjusted after the complete binary tree is established, and you can find that the answer does not match.

    The merge order is from small to large to merge sub-intervals, and it can be found that the sub-intervals [1,2], [3,4], [5,6], [7,8] are all ordered.

  10. Anonymous users2024-01-27

    These methods are all about the same, novices can take a look, mainly to learn the ideas of different methods.

    It's not really the method itself, it's the way you think about the problem.

Related questions
5 answers2024-02-09

There are no advantages or disadvantages, this algorithm is just a way to solve the problem of convergence. Advantages and disadvantages need to be compared, and there is no comparison object and the same comparison conditions, how to talk about advantages and disadvantages. There are many algorithms that can be solved for every problem, and it is not necessarily good or bad to iterate. >>>More

3 answers2024-02-09

==Uniform cubic b-spline interpolation **********=

Define variables: x: raw data, d: control vertices. >>>More

16 answers2024-02-09

Just o(n) scans it once, millions of arrays are not big, and c can be opened so big for global variables. >>>More

3 answers2024-02-09

With the increasing number of netizens and the continuous expansion of netizens' desire for a high-quality Internet ecological environment, the 360 search that was born out of thin air has seized more than 10% of the search share in half a year, which is really untenable. In the past year, algorithm updates have become more and more frequent, and they will be approved before each update, aiming to create a better user experience for webmasters, and also give some webmasters who have worked hard a chance to regret it. After the update of the algorithm to present better content to users, I will summarize where SEO will go after the update. >>>More

5 answers2024-02-09

Try my way:

Create a text on the form, and a command1 >>>More