# Category: Sorting Techniques

## Sort Names by their Last Names.

Objec­tive: Given a list of names ( first name and last name), sort the list by their last names. Exam­ple: List [] = {“Daen­erys Tar­garyen”, “Jon Snow”, ” Tyrion Lan­nis­ter”, ” Jof­frey Baratheon”} Out­put: [Joffrey…

## Merge K Sorted Arrays

Objec­tive: Given k sorted array, write an algo­rithm to merge Them into One sorted array. Exam­ple : int[][] A = new int[5][]; A[0] = new int[] { 1, 5, 8, 9 }; A[1] = new…

## Counting Sort

Count­ing Sort is an sort­ing algo­rithm, which sorts the inte­gers( or Objects) given in a spe­cific range. Algo­rithm: Time Com­plex­ity O(n) Take two arrays, Count[] and Result[] and given array is input[]. Count[] will store the…

## OR use only Max() function.">Sort 3 Integers without using if condition OR use only Max() function.

Objec­tive: — Given three inte­gers, sort them with­out using if con­di­tion. Appraoch: Say 3 inte­gers are, a, b, c. Find the max­i­mum of a, b, c using Max() func­tion. mul­ti­ply all inte­gers by –1. Again…

## Merge Sort in a Linked list

Objec­tive: Given a Linked List, Sort it using merge sort. Exam­ple: ->9->3->4->2->5->1 Sorted List: ->1->2->3->4->5->9 Approach: Ref­er­ence : Merge Sort in array

## Sort an Given Array in the order defined by another array

Objec­tive: Given an array of inte­gers, write an algo­rithm to sort it accord­ing to the order defined by another array. Input: An Array of Inte­gers Exam­ple: Input Array : 2 6 9 1 4…

## Sort an Array such that the odd numbers appear first followed by the even numbers . The odd numbers in ascending order and the even numbers in descending order.

Objec­tive: Given an array of interg­ers, sort it such that the odd num­bers appear first fol­lowed by the even num­bers . The odd num­bers in ascend­ing order and the even num­bers in descend­ing order. Input:…

## Find a pair of numbers from an array whose sum equals k

Objec­tive: Write an algo­rithm to find out whether in a given array there exists or not two num­bers whose sum is exactly equals to a given num­ber. This prob­lem has been asked in Amazon…

## Quick Sort Implementation

Objec­tive: Write an algo­rithm to sort an array in increas­ing or decreas­ing order using Quick Sort. Input:  An Array arrA[] Out­put: A sorted array. Approach: Choose any ele­ment from the array and call it as pivot element,…

## Merge Sort — Updated — Most Efficient ways to Implement

Objec­tive : Write Merge Sort algo­rithm to sort ele­ments in an array Input: A unsorted array, arrA[]. Out­put : A sorted array. Approach: Divide and Con­quer: In this approach we divide the main prob­lems into…