Posts

Transposition Linear Search

Transposition Linear Search: In this algorithm of searching, If the key is found then the key is swapped with the item at (keyIndex - 1) or the item before the search item. The idea behind this algorithm is to move most search item/key to front/head of the array with each search. So that if the same item gets search again then it will take less time to search. Below is the program for this algorithm of searching: # include < iostream > using namespace std ; /** * @brief swap: This function swaps the items. * @param pFirst: First item. * @param pSecond: Second item. */ void swap ( int * pFirst , int * pSecond ) { int iTemp ; iTemp = * pFirst ; * pFirst = * pSecond; * pSecond = iTemp ; } /** * @brief LinearSearch: This methods search the Key in the array passed in first param, * and if item/key is found then, swap it with the item at 1 less index. * @param objArr: object o...

Linear Search

Search an element in an Array: Searching an element in an array is basically searching any number in the given array and if the element is found in the array then return its index in the array. There are multiple algorithms to search an element in an array. I will cover each algorithm one by one. Linear Search:  In Linear search, we have to compare the Key/Element to each element of the array, below is the program for Linear search in c++. # include < iostream > using namespace std ; /** * @brief The Array struct: Structure Which Contains array of size 10 and array's * Length (number of items it contains.) */ struct Array { int A [ 10 ]; int iLength ; }; /** * @brief LinearSearch: This methods search the Key in the array passed in first param. * @param objArr: object of Struct Array, Which contains array and Length of the array, * in which we have to search the key. * @param iKey: K...