# Category Archives: Sorting

interview questions based on sorting

## Merge Sort Code

Merge Sort belongs to category of divide and conquer algorithms. Which means it divides the problem into  small subproblems, solves them and then combine the solutions of these subproblems to generate solution  of the original problem.Merge Sort compares elements with each other for sorting the list. The steps followed to mergesort are are: Divide the unsorted list… Read More »

## Quick Sort Code

Quick Sort belongs to the category ofdivide and conquer algorithms. Quicksort  divides a large list into two smaller lists around a selected pivot . Quicksort can then recursively sort the sub-lists.It sorts the elements inplace. The steps followed are are: Select an element, called a pivot, from the list. Reorder the list so that all elements with values… Read More »

## Counting Sort

Counting Sort is not a comparison sort.Counting sort assumes that each of the input element is an integer in the range 0 to k, for some integer k. When k=O(n), the sort runs in O(n) time. The basic idea of counting sort is to determine, for each input element x, the number of elements less… Read More »

## 4 sum problem or a+b+c+d=sum

The 4 Sum 🙂 problem is like this : Given an array of integers A, find 4 index of 4 numbers a,b,c,d such that they add up to a specific target number s.The number should not be same. a+b+c+d =s The problem is somewhat similar to the 3 sum problem and the solution is also… Read More »

## 3 sum problem or a+b+c=sum

The 3 Sum 🙂 problem is like this : Given an array of integers A, find 3 numbers a,b,c such that they add up to a specific target number s. a+b+c =s The problem is somewhat similar to the two sum problem . Ex Input : A={4,5,1,2,3} s=8 output :5,2,1 We can take different approaches… Read More »