Merge sort is defined as a sorting algorithm that works by dividing an array into smaller subarrays, sorting each subarray, and then merging the sorted… Read More
Category Archives: Sorting
Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands. The array is virtually split… Read More
Insertion sort is an algorithm used to sort a collection of elements in ascending or descending order. The basic idea behind the algorithm is to… Read More
We have discussed Pancake Sorting in the previous post. Following is a problem based on Pancake Sorting. Given an unsorted array, sort the given array. You… Read More
Given an unsorted array, sort the given array. You are allowed to do only following operation on array. flip(arr, i): Reverse array from 0 to… Read More
Given an unsorted array, the task is to sort the given array. You are allowed to do only following operation on array. flip(arr, i): Reverse… Read More
Company : Qualcomm Position: Summer Intern(Software) Written Test It was an online MCQ test. Time limit was one hour. There were around 55 question. It… Read More
Given a linked list of 0s, 1s and 2s, The task is to sort and print it. Examples: Input: 1 -> 1 -> 2 ->… Read More
Following is a typical recursive implementation of Quick Sort that uses last element as pivot. C++ // CPP code for recursive function of Quicksort #include… Read More
Java // Java implementation of iterative quick sort import java.io.*; public class IterativeQuickSort { void swap(int arr[], int i, int j) { int t =… Read More
C // An iterative implementation of quick sort #include <stdio.h> // A utility function to swap two elements void swap(int* a, int* b) {… Read More
Given N machines. Each machine contains some numbers in sorted form. But the amount of numbers, each machine has is not fixed. Output the numbers… Read More
Given a number, find the next smallest palindrome larger than this number. For example, if the input number is “2 3 5 4 5”, the… Read More
Given an array of N elements, where each element is at most K away from its target position, devise an algorithm that sorts in O(N… Read More
Given an array of integers, find anyone combination of four elements in the array whose sum is equal to a given value X. For example, … Read More