Close

Linear search

Given an array of numbers, how do we search for a given number? For example, given an array [6, 50, 24, 36, 42], the number 36 is present at the index 3 starting with 0. The number 17 is not present any where. The simplest algorithm to solve this problem is to check each element…

Searching for an element in the sorted matrix

Given a row wise and column wise sorted two dimensional array or matrix. How to search for an element efficiently? Example of the array can be int[][] matrix = {                   {1,3,5,7,9},                   {10,12,14,16,18},                   {19,21,23,25,27},                   {28,30,32,34,36},                   {37,39,41,43,45}                }; This can be done using the following algorithm.  We start our search with the top right element.  If it…