Category Archives: Algorithms

algorithms interview questions

Find if 2 Rectangles overlap

Given two rectangles with their base parallel to each other . You have to find whether the rectangles overlap or not. Ex Rect1(2,3,5,6) Rect2(1,3,1,10) Where a rectangle is specified by coordinates of it’s TopLeft (x1,y1) and BottomMRight(x2,y2) coordinates in sequence for rect1 TopLeft(2,3) and BottomRight(5,6). The problem is very simple . Since the rectangle have… Read More »

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 »

Balanced Parentheses Algorithm

This is a classic example of how using an appropriate Datastructure can improve the quality of your algorithm. The Balanced Parentheses or Valid Parentheses is like this : Given a string containing ‘(‘, ‘)’, ‘{‘, ‘}’, ‘[‘ and ‘]’, determine if the input string is valid or not. [(a+b)+c] is Valid where as (a+b)+c] is… Read More »