Jun 292013
 

watch_videoBinary search is a Divide & Conquer algorithm used to search for an element in the array. It requires the array to be sorted. If array is not sorted then the only way to search in the array is Linear search.

Binary search divide the number of elements to be searched in two halves in each iteration and only one half remains relevant to be searched and the other is ignored. Therefore, even if the element is not present in the array we don’t need to traverse all the element in the list. Continue reading »

Jun 292013
 

watch_videoLinear search or Sequential search is a method for finding a particular value in a linear list of values (Array or Linked List). It is done by checking each of its elements, one at a time in list, until the desired one is found or the list is exhausted.

Problem definition (for array)

Given an Array of numbers a0, a1, a2, …, an. and a number x. Write a function which will return i, such that (ai == x). If x is not in the Array, then return -1 (which means “Not Found”).

Continue reading »