суббота, 4 июля 2009 г.

Sorting Algorithms

Sorting Algorithms

The problem of organizing data from a practical point of view:
advantages and disadvantages of five different methods of sorting.

Sorting is used in all the areas of programming, whether a database or math program.
Practically every sorting algorithm can be divided into three parts:
- A comparison that determines the order pairs of elements;
- Up, swap a couple of elements;
- Actual sorting algorithm that performs the comparison and transfer of elements until the juice of all the elements of the set will not be ordered.
Similar properties have those five sorting algorithms that
discussed below. They are selected from the set of algorithms, because
First, the most frequently used, and secondly, because most of the other algorithms is modified as described here.

The method of the bubble.

(Also called the method of sorting with the choice of exchange).
The idea of this method is reflected in its title. Most elements of the array light "appear" top most "severe" - drown. Algorithmic it could be implemented as follows. We will look through the array of bottom-up "and change the number of elements standing in there when the" bottom "element is less than the" ceiling ". Thus, we vytolknem top most "easy" part of the whole array. Now repeat the whole opera neotsortirovanymi for the remaining N-1 elements (ie, for those who are "below" the first one. As you can see, the algorithm is simple enough, but sometimes observed, it is unsurpassed in its inefficiency. Slightly better, but so vivid is the second method.

Sort choice

At this time, when viewing macciva we will look for the smallest element, comparing it with the first. If the element is found, it will change places with the first. Then repeat the operation, but did not begin with the first element, but with the second. And we will continue this way until rassortiruem entire array.

Shell Method

This method was proposed by Donald Lewis Shell in 1959 The main idea of this algorithm is that at the beginning of yctpanit mass disorder in the array, comparing the far-facing each other elements. As shown, the interval between compared elements (gap) is gradually reduced to one. This means that in the latter stages of the sorting is reduced simply to the transposition of neighboring elements (unless, of course, such changes are necessary).

Method Hoopa

This method, also called the quick sorting (QuickSort), was developed in 1962 (it has developed a Charles Antony Richard Hoare).
The essence of the method is to find such an element of the set to be sorted, which break it into two subsets: those elements that less fissile element, and those that do not lower it. This idea can be realized in many ways.

Комментариев нет:

Отправить комментарий