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

String Reversal- Coding Problem

A string is given as input. We have to print the reversed string.For example, the string is "Hi how are you?" and the output should be "?ouy era woh iH" The first solution is we can create a new array and append the characters of the original array, one by one from the end to … Continue reading String Reversal- Coding Problem

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