-
Essay / Data Structure and Algorithms: Sorting and Searching...
Sorting and Searching Techniques.INTRODUCTIONSorting is the process of rearranging given objects in a specific order. This is done in a way that serves the purpose of the research. Objects (data) stored everywhere, such as in libraries, hospitals, warehouses, institutes and in different databases, need to be searched and retrieved. So, for data to be retrieved easily and in a more understandable form, it is important that this data is sorted. There are many sorting techniques, three of which we will discuss: Shell Sort.Bucket Sort.Radix Sort. WORKINGShell SortThis sorting algorithm basically uses insertion sort to solve the problem. It breaks the problem into smaller pieces. Table 1: Index 0 1 2 3 4 5 6 7 8 9 Table 2: Table 40 80 35 75 60 57 34 90 70 45 There is this gap value in the shell sort which starts as: Gap value = (array length/2)= 10/2 = 5 Now we will select subarrays using the gap value. From index 0 and after the difference of 5 from this index we will be at index 5 and if we go back after the difference of 5 we will be at index 10 because there is no index number 10 we have two indices 0 and 5 so we will have a subarray [40, 57] and in the same way, we will now start with index number 1 and repeat the process. At the end we will have subarrays [40, 57], [34, 80], [35, 90], [75, 70] and [60, 45]. We will now need to use insertion sort on each subarray and if they are unsorted we will swap them in their indices. 40 34 35 70 45 57 80 90 75 60 Now we will further simplify the gap value so we can have smaller deviation values. So we will take the previous deviation value and divide it by 2. Deviation value = 5/2 = 2.5 = 2Now using this deviation value we will have subarrays [40... ... middle of paper ......algorithm is: O (kn) Where k = no. of digits in the longest entered number and n = no. of inputs.PROS & CONSShell SortPros:It is effective when the array list is of medium size.It is of better complexity than that of insertion sort.Relatively simple to implement.Disadvantages:It poses mathematical problems very difficult, many of which have not been resolved. It is not yet known which choice of increments gives the best results. This is a somewhat complex sorting algorithm.Bucket SortAdvantages: It's good for rough sorting.It's fast.It's easy to implement.Disadvantages: Doesn't sort in place.Radix SortPros: It does not perform comparisons on individual elements. It's fast. It is easy to implement. Disadvantages: Not a good choice for floating point numbers. Not good for arbitrary strings. Do not sort on site.