Found 1900 Articles for Data Structure

Radix Sort

Sharon Christine
Updated on 15-Jun-2020 15:20:04

2K+ Views

Radix sort is a non-comparative sorting algorithm. This sorting algorithm works on the integer keys by grouping digits which share the same position and value. The radix is the base of a number system. As we know that in the decimal system the radix or base is 10. So for sorting some decimal numbers, we need 10 positional boxes to store numbers.The complexity of Radix Sort TechniqueTime Complexity: O(nk)Space Complexity: O(n+k)Input and OutputInput: The unsorted list: 802 630 20 745 52 300 612 932 78 187 Output: Data before Sorting: 802 630 20 745 52 300 612 932 78 187 ... Read More

Quick Sort

Samual Sam
Updated on 15-Jun-2020 15:24:00

3K+ Views

The quicksort technique is done by separating the list into two parts. Initially, a pivot element is chosen by partitioning algorithm. The left part of the pivot holds the smaller values than the pivot, and right part holds the larger value. After partitioning, each separate lists are partitioned using the same procedure.The complexity of Quicksort TechniqueTime Complexity: O(n log n) for best case and average case, O(n^2) for the worst case.Space Complexity: O(log n)Input and OutputInput: The unsorted list: 90 45 22 11 22 50 Output: Array before Sorting: 90 45 22 11 22 50 Array after Sorting: 11 22 ... Read More

Pigeonhole Sort

Sharon Christine
Updated on 15-Jun-2020 15:31:17

722 Views

This is an example of the non-comparison sorting technique. It is used where the number of items and the range of possible key values is approximately the same.To perform this sort, we need to make some holes. The number of holes needed is decided by the range of numbers. In each hole, items are inserted. Finally deleted from the hole and stored into an array for sorted order.The complexity of Pigeon-Hole Sort TechniqueTime Complexity: O(n+2^k)Space Complexity: O(2^k)Input and OutputInput: The unsorted list: 802 630 20 745 52 300 612 932 78 187 Output: Data before Sorting: 802 630 20 745 ... Read More

Merge Sort

Jai Janardhan
Updated on 15-Jun-2020 15:27:06

2K+ Views

The merge sort technique is based on divide and conquers technique. We divide the whole dataset into smaller parts and merge them into a larger piece in sorted order. It is also very effective for worst cases because this algorithm has lower time complexity for the worst case also.The complexity of Merge Sort TechniqueTime Complexity: O(n log n) for all casesSpace Complexity: O(n)Input and OutputInput: The unsorted list: 14 20 78 98 20 45 Output: Array before Sorting: 14 20 78 98 20 45 Array after Sorting: 14 20 20 45 78 98Algorithmmerge(array, left, middle, right)Input − The data set array, left, middle ... Read More

Insertion Sort

Samual Sam
Updated on 15-Jun-2020 15:35:20

2K+ Views

This sorting technique is similar with the card sorting technique, in other words, we sort cards using insertion sort mechanism. For this technique, we pick up one element from the data set and shift the data elements to make a place to insert back the picked up an element into the data set.The complexity of the Insertion Sort TechniqueTime Complexity: O(n) for best case, O(n^2) for average and worst caseSpace Complexity: O(1)Input and OutputInput: The unsorted list: 9 45 23 71 80 55 Output: Array before Sorting: 9 45 23 71 80 55 Array after Sorting: 9 23 45 55 ... Read More

Heap Sort

Paul Richard
Updated on 15-Jun-2020 15:39:25

3K+ Views

Heap sort is performed on the heap data structure. We know that heap is a complete binary tree. Heap tree can be of two types. Min-heap or max heap. For min heap the root element is minimum and for max heap the root is maximum. After forming a heap, we can delete an element from the root and send the last element to the root. After these swapping procedure, we need to re-heap the whole array. By deleting elements from root we can sort the whole array.The complexity of Heap Sort TechniqueTime Complexity: O(n log n)Space Complexity: O(1)Input and OutputInput: A ... Read More

Cycle Sort

Sharon Christine
Updated on 15-Jun-2020 15:43:42

604 Views

Cycle Sort is an in-place sorting algorithm. It is also a comparison based sort and efficient for any other in-place sorting technique. It finds the minimum number of memory write to perform the sorting tasks.The complexity of Cycle Sort TechniqueTime Complexity: O(n^2)Space Complexity: O(1)Input and OutputInput: A list of unsorted data: 23 63 98 74 20 14 36 45 99 78 Output: Array before Sorting: 23 63 98 74 20 14 36 45 99 78 Array after Sorting: 14 20 23 36 45 63 74 78 98 99AlgorithmcycleSort(array, size)Input − An array of data, and the total number in the ... Read More

Counting Sort

Samual Sam
Updated on 15-Jun-2020 15:46:19

2K+ Views

Counting sort is a stable sorting technique, which is used to sort objects according to the keys that are small numbers. It counts the number of keys whose key values are same. This sorting technique is effective when the difference between different keys are not so big, otherwise, it can increase the space complexity.The complexity of counting Sort TechniqueTime Complexity: O(n+r)Space Complexity: O(n+r)Input and OutputInput: A list of unsorted data: 2 5 6 2 3 10 3 6 7 8 Output: Array before Sorting: 2 5 6 2 3 10 3 6 7 8 Array after Sorting: 2 2 3 ... Read More

Comb Sort

Jai Janardhan
Updated on 15-Jun-2020 14:29:38

963 Views

The basic idea of comb sort and the bubble sort is same. In other words, comb sort is an improvement on the bubble sort. In the bubble sorting technique, the items are compared with the next item in each phase. But for the comb sort, the items are sorted in a specific gap. After completing each phase, the gap is decreased. The decreasing factor or the shrink factor for this sort is 1.3. It means that after completing each phase the gap is divided by 1.3.The complexity of Comb Sort TechniqueTime Complexity: O(n log n) for the best case. O(n^2/2^p) (p ... Read More

Bucket Sort

Rishi Raj
Updated on 15-Jun-2020 14:35:08

2K+ Views

In the Bucket Sorting technique, the data items are distributed in a set of buckets. Each bucket can hold a similar type of data. After distributing, each bucket is sorted using another sorting algorithm. After that, all elements are gathered on the main list to get the sorted form.The complexity of the Bucket Sort TechniqueTime Complexity: O(n + k) for best case and average case and O(n^2) for the worst case.Space Complexity: O(nk) for worst caseInput and OutputInput: A list of unsorted data: 0.25 0.36 0.58 0.41 0.29 0.22 0.45 0.79 0.01 0.69 Array before Sorting: 0.25 0.36 0.58 0.41 ... Read More

Advertisements