Sorting
Sorting is needed to speed up the process of searching a data. There are two kinds of sorting : ascending from the lowest to the highest. And descending from the highest to the lowest.
Type of sorting :
1. Bubble sort, compares the value of the current data with the immediate next data and swap the according to the requirement and goes till the last element.
2. Selection sort, a selection of an element position from the start with the other rest of the element. Element are compared and exchanged depending on the condition and then selection position is shifted to the next position till it reaches to the end
3. Insertion Sort, one element from the top is selected and is compares to the other rest of the elements down the line and inserted to another position and rest of the elements are shifted accordingly.
4. Quick shot, it picks an element as pivot and partitions the given array around the picked pivot.
5. Merge shot, This type of sorting follows the divide and rule policy. This algorithm divides the array of n elements into n separate arrays of size 1 (each array contains one element) and then rejoins the divided arrays one by one with each other to form the array of size n.
Searching
After we sort the data that we got, its easier to find the data that we want using searching. These are the types of searching :
1. Linear Search, compares each element of the array with the search key. If the array is not in any particular order, it might be longer to find it. On average, the program will have to compare the search key with half the element of the array.
2. Binary Search, the linear searching method works well for small or unsorted arrays. However, for large arrays linear searching is inefficient. If the array sorted, the binary search technique can be used and it's faster. The program set the first, middle and last data and see if the middle is the search key, if it is not, the the sequence is repeated until the search key is found.
3. Interpolation Search, Interpolation search technique is performed on the sorted data. This searching process is almost similar with binary search technique. Searching technique is done with the approximate location of the data
Comments
Post a Comment