Merge Sorted Arrays – Coding Problem

Given two sorted integer arrays arr1 and arr2, merge arr1 and arr2 as one sorted array. Example Input: arr1 = [1,2,3] arr2 = [2,5,6] Output: [1,2,2,3,5,6] Solution1: we compare the corresponding elements of both arraysWe add the smaller element to a new array and increment the index of the array from which the element was added.Again we compare the elements of … Continue reading Merge Sorted Arrays – Coding Problem

Stooge Sort

The Stooge sort is a recursive sorting algorithm. It is defined as below (for ascending order sorting). Step 1 : If value at index 0 is greater than value at last index, swap them. Step 2: Recursively, a) Stooge sort the initial 2/3rd of the array. b) Stooge sort the last 2/3rd of the array. … Continue reading Stooge Sort

Bitonic Sort

Bitonic Sort is a classic parallel algorithm for sorting. Bitonic sort does O(n Log 2n) comparisons.The number of comparisons done by Bitonic sort are more than popular sorting algorithms like Merge Sort [ does O(nLogn) comparisons], but Bitonice sort is better for parallel implementation because we always compare elements in predefined sequence and the sequence of … Continue reading Bitonic Sort

Cocktail Sort

Cocktail Sort is a variation of Bubble sort. The Bubble sort algorithm always traverses elements from left and moves the largest element to its correct position in first iteration and second largest in second iteration and so on. Cocktail Sort traverses through a given array in both directions alternatively. ALGORITHM: Each iteration of the algorithm … Continue reading Cocktail Sort