Category Archives: Searching

Search, insert and delete in a sorted array

In this post search, insert and delete operation in a sorted array is discussed. Search Operation In a sorted array, the search operation can be performed by using binary search. Output: Index: 5 Insert Operation In an unsorted array, the insert operation is faster as compared to sorted array because we don’t have to care… Read More »

Search, insert and delete in an unsorted array

In this post search, insert and delete operation in an unsorted array is discussed. Search Operation In an unsorted array, the search operation can be performed by linear traversal from the first element to the last element. Output: Element Found at Position: 5 Insert Operation In an unsorted array, the insert operation is faster as… Read More »

Make all array elements equal with minimum cost

Given an array which contains integer values, we need to make all values of this array equal to some integer value with minimum cost where the cost of changing an array value x to y is abs(x-y). Examples: Input : arr[] = [1, 100, 101] Output : 100 We can change all its values to… Read More »

Exponential Search

The name of this searching algorithm may be misleading as it works in O(Log n) time. The name comes from the way it searches an element. Given a sorted array an element x to be searched, find position of x in the array. Input: arr[] = {10, 20, 40, 45, 55} x = 45 Output:… Read More »

Minimum time required to produce m items

Consider n machines which produce same type of items but at different rate i.e., machine 1 takes a1 sec to produce an item, machine 2 takes a2 sec to produce an item. Given an array which contains the time required by ith machine to produce an item. Considering all machine are working simultaneously, the task… Read More »