This video discusses the Linear Search algorithm in detail.
This video describes Binary search algorithm.
Binary 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.
Linear 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”).
Given an array of integers and a number x. check if there exists two elements in the array whose sum = x.
Given a matrix whose each row and column is sorted as shown below
10 20 30 40 15 25 35 45 27 29 37 48 32 33 39 50
Write an algorithm that will search for the matrix for a value (say 37) and print the index of position where it finds the value. If the value is not present in the array it should print “Not Found”.