# Category Archives: Searching

interview questions based on searching

## Find the median of two sorted arrays

Given two sorted arrays A and B containing N elements each. Give an algorithm to ﬁnd the median of two sorted arrays in O(lgN) time. Ex A={1,2,3} B={1,4,5,6} median=3 . The naive algorithm will be to merge the arrays A and B and return the median .But the time complexity will be O(N) and this… Read More »

## Binary Search code

Binary Search finds the position of a specified value (key) in a sorted array.In each step it discards half of the elements to search , thus the worst case running time of binary search is O(log n).Believe it or not 80 out of 100 of the programmers fail to write the correct code for binary… 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 »

## Two Sum (a+b =s) Problem

The Two Sum problem is like this : Given an array of integers A, find two numbers a,b such that they add up to a specific target number s. a+b =s Though this problem looks simple but this problem forms a kind of base for solving other bigger problems like 3sum problem and 4 sum… Read More »