Problem Statement
You are given a sorted array. However, there is a problem. Someone just rotated the sorted array by K spaces and we do not know the value of K.
Write a program to find the value of K by which the array is rotated. As the array has millions of numbers, it would be good to have a solution which takes minimal time.
Approach to Find the Point of Rotation
Brute Force
Let us try out my favorite approach, the Brute Force Method. It is quite simple, below are the steps:
Start traversing the array from the beginning
There will be a index in the array where the value sto...

Read More
# Searching

## Understanding Binary Search Algorithm

Introduction
The problem of searching is very trivial. It goes like this:
There is an array of elements A[1..N] and we need to find the index of a given element in the array. In case the element is not present in the array, we can choose to return a specific value (say -1) which suggests that the element doesn't exist in the array.
Binary Search is a very efficient and interesting searching algorithm. Regular searching algorithms take running time proportional to the size of the input. They are called linear time algorithm O(N) to be asymptotically true.
Binary Search on the other ha...

Read More