Posts tagged search

Binary Search

1


The binary Search is a very efficient search algorithm applies only on ordered arrays

the main concept of binary search is to break the whole array into two halves and then check the value in the middle, if we’re searching for a value bigger than the value in the middle so it’d be at the right part otherwise it’d be in the left part
we will repeat this step in the resulted part by dividing it into two parts and vice versa.
we should make a stop point and it’d be in two cases

  1. if we ended with no division available in our array then it’ll we will notify that we didn’t find the value
  2. if we found the value we will return with the current index

(more…)

Linear Search

0

The linear Search is the simplest search algorithm
it’s simply checks for every element in an array one by one in order

we can implement this algorithm in a function that takes 3 arguments

  1. A pointer to the array
  2. The size of the array
  3. The value we want to search for

the return value of the function ‘d be the index (order) of the element in that array or -1 if it’s not exist
(more…)

Go to Top