Showing posts with label Searching Algo.. Show all posts
Showing posts with label Searching Algo.. Show all posts

Binary Search Algorithm Implemented in C++

Binary Search also known as the half-interval search algorithm is a  type of Divide and Conquer Algorithm. It is a fairly simple algorithm in that the key element to be found is searched with a logic that is determined by the element present in the middle of the list of all elements to be found. All the elements have to be arranged in ascending or descending order for this algorithm to work. The simple logic used is checking if the value is greater or lesser than the middle element. If the value is lesser than the key element, then we check the left series of elements. If the middle value is greater than the key element, then it implies that the value to be found must be present in the right series of the list. This case happens in an increasing numbered list i.e. ascending ordered list. In a descending ordered list, the searching changes direction i.e. if lower value is required we go to the right of the series and higher value is present on the left of the series. 

Linear Search Algorithm Implemented in C++

Linear Search is the simplest of searching techniques that can be implemented with a simple array and a for loop. All elements of a particular array are checked one by one to find a given key element. If the element is found, the system returns that the search was successful. Also the user will be presented with a location where the search element was found i.e. the index in the array matched. See the code below followed by the C++ source code: 
Custom Search